123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274 |
- // Copyright 2009 The Closure Library Authors. All Rights Reserved.
- //
- // Licensed under the Apache License, Version 2.0 (the "License");
- // you may not use this file except in compliance with the License.
- // You may obtain a copy of the License at
- //
- // http://www.apache.org/licenses/LICENSE-2.0
- //
- // Unless required by applicable law or agreed to in writing, software
- // distributed under the License is distributed on an "AS-IS" BASIS,
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- // See the License for the specific language governing permissions and
- // limitations under the License.
- goog.provide('goog.i18n.currencyTest');
- goog.setTestOnly('goog.i18n.currencyTest');
- goog.require('goog.i18n.NumberFormat');
- goog.require('goog.i18n.currency');
- goog.require('goog.i18n.currency.CurrencyInfo');
- goog.require('goog.object');
- goog.require('goog.testing.PropertyReplacer');
- goog.require('goog.testing.jsunit');
- var stubs = new goog.testing.PropertyReplacer();
- function setUp() {
- stubs.replace(
- goog.i18n.currency, 'CurrencyInfo',
- goog.object.clone(goog.i18n.currency.CurrencyInfo));
- }
- function tearDown() {
- stubs.reset();
- }
- function testIsAvailable() {
- assertTrue(goog.i18n.currency.isAvailable('USD'));
- assertTrue(goog.i18n.currency.isAvailable('CLP'));
- assertFalse(goog.i18n.currency.isAvailable('LRD'));
- assertFalse(goog.i18n.currency.isAvailable('XYZ'));
- }
- function testAddTier2Support() {
- assertFalse('LRD' in goog.i18n.currency.CurrencyInfo);
- assertThrows(function() {
- goog.i18n.currency.getLocalCurrencyPattern('LRD');
- });
- goog.i18n.currency.addTier2Support();
- assertTrue('LRD' in goog.i18n.currency.CurrencyInfo);
- assertEquals(
- "'$'#,##0.00", goog.i18n.currency.getLocalCurrencyPattern('LRD'));
- }
- function testCurrencyPattern() {
- assertEquals(
- "'$'#,##0.00", goog.i18n.currency.getLocalCurrencyPattern('USD'));
- assertEquals(
- "'US$'#,##0.00", goog.i18n.currency.getPortableCurrencyPattern('USD'));
- assertEquals(
- "USD '$'#,##0.00", goog.i18n.currency.getGlobalCurrencyPattern('USD'));
- assertEquals("'¥'#,##0", goog.i18n.currency.getLocalCurrencyPattern('JPY'));
- assertEquals(
- "'JP¥'#,##0", goog.i18n.currency.getPortableCurrencyPattern('JPY'));
- assertEquals(
- "JPY '¥'#,##0", goog.i18n.currency.getGlobalCurrencyPattern('JPY'));
- assertEquals(
- "'€'#,##0.00", goog.i18n.currency.getLocalCurrencyPattern('EUR'));
- assertEquals(
- "'€'#,##0.00", goog.i18n.currency.getPortableCurrencyPattern('EUR'));
- assertEquals(
- "EUR '€'#,##0.00", goog.i18n.currency.getGlobalCurrencyPattern('EUR'));
- assertEquals(
- "'¥'#,##0.00", goog.i18n.currency.getLocalCurrencyPattern('CNY'));
- assertEquals(
- "'RMB¥'#,##0.00", goog.i18n.currency.getPortableCurrencyPattern('CNY'));
- assertEquals(
- "CNY '¥'#,##0.00", goog.i18n.currency.getGlobalCurrencyPattern('CNY'));
- assertEquals(
- "'Rial'#,##0", goog.i18n.currency.getLocalCurrencyPattern('YER'));
- assertEquals(
- "'Rial'#,##0", goog.i18n.currency.getPortableCurrencyPattern('YER'));
- assertEquals(
- "YER 'Rial'#,##0", goog.i18n.currency.getGlobalCurrencyPattern('YER'));
- assertEquals(
- "'CHF'#,##0.00", goog.i18n.currency.getLocalCurrencyPattern('CHF'));
- assertEquals(
- "'CHF'#,##0.00", goog.i18n.currency.getPortableCurrencyPattern('CHF'));
- assertEquals(
- "'CHF'#,##0.00", goog.i18n.currency.getGlobalCurrencyPattern('CHF'));
- }
- function testCurrencyFormatCHF() {
- var formatter;
- var str;
- formatter = new goog.i18n.NumberFormat(
- goog.i18n.currency.getLocalCurrencyPattern('CHF'));
- str = formatter.format(123456.7899);
- assertEquals('CHF123,456.79', str);
- formatter = new goog.i18n.NumberFormat(
- goog.i18n.currency.getPortableCurrencyPattern('CHF'));
- str = formatter.format(123456.7899);
- assertEquals('CHF123,456.79', str);
- formatter = new goog.i18n.NumberFormat(
- goog.i18n.currency.getGlobalCurrencyPattern('CHF'));
- str = formatter.format(123456.7899);
- assertEquals('CHF123,456.79', str);
- }
- function testCurrencyFormatYER() {
- var formatter;
- var str;
- formatter = new goog.i18n.NumberFormat(
- goog.i18n.currency.getLocalCurrencyPattern('YER'));
- str = formatter.format(123456.7899);
- assertEquals('Rial123,457', str);
- formatter = new goog.i18n.NumberFormat(
- goog.i18n.currency.getPortableCurrencyPattern('YER'));
- str = formatter.format(123456.7899);
- assertEquals('Rial123,457', str);
- formatter = new goog.i18n.NumberFormat(
- goog.i18n.currency.getGlobalCurrencyPattern('YER'));
- str = formatter.format(123456.7899);
- assertEquals('YER Rial123,457', str);
- }
- function testCurrencyFormatCNY() {
- var formatter;
- var str;
- formatter = new goog.i18n.NumberFormat(
- goog.i18n.currency.getLocalCurrencyPattern('CNY'));
- str = formatter.format(123456.7899);
- assertEquals('¥123,456.79', str);
- formatter = new goog.i18n.NumberFormat(
- goog.i18n.currency.getPortableCurrencyPattern('CNY'));
- str = formatter.format(123456.7899);
- assertEquals('RMB¥123,456.79', str);
- formatter = new goog.i18n.NumberFormat(
- goog.i18n.currency.getGlobalCurrencyPattern('CNY'));
- str = formatter.format(123456.7899);
- assertEquals('CNY ¥123,456.79', str);
- }
- function testCurrencyFormatCZK() {
- var formatter;
- var str;
- formatter = new goog.i18n.NumberFormat(
- goog.i18n.currency.getLocalCurrencyPattern('CZK'));
- str = formatter.format(123456.7899);
- assertEquals('123,456.79 Kč', str);
- formatter = new goog.i18n.NumberFormat(
- goog.i18n.currency.getPortableCurrencyPattern('CZK'));
- str = formatter.format(123456.7899);
- assertEquals('123,456.79 Kč', str);
- formatter = new goog.i18n.NumberFormat(
- goog.i18n.currency.getGlobalCurrencyPattern('CZK'));
- str = formatter.format(123456.7899);
- assertEquals('CZK 123,456.79 Kč', str);
- }
- function testCurrencyFormatEUR() {
- var formatter;
- var str;
- formatter = new goog.i18n.NumberFormat(
- goog.i18n.currency.getLocalCurrencyPattern('EUR'));
- str = formatter.format(123456.7899);
- assertEquals('€123,456.79', str);
- formatter = new goog.i18n.NumberFormat(
- goog.i18n.currency.getPortableCurrencyPattern('EUR'));
- str = formatter.format(123456.7899);
- assertEquals('€123,456.79', str);
- formatter = new goog.i18n.NumberFormat(
- goog.i18n.currency.getGlobalCurrencyPattern('EUR'));
- str = formatter.format(123456.7899);
- assertEquals('EUR €123,456.79', str);
- }
- function testCurrencyFormatJPY() {
- var formatter;
- var str;
- formatter = new goog.i18n.NumberFormat(
- goog.i18n.currency.getLocalCurrencyPattern('JPY'));
- str = formatter.format(123456.7899);
- assertEquals('¥123,457', str);
- formatter = new goog.i18n.NumberFormat(
- goog.i18n.currency.getPortableCurrencyPattern('JPY'));
- str = formatter.format(123456.7899);
- assertEquals('JP¥123,457', str);
- formatter = new goog.i18n.NumberFormat(
- goog.i18n.currency.getGlobalCurrencyPattern('JPY'));
- str = formatter.format(123456.7899);
- assertEquals('JPY ¥123,457', str);
- }
- function testCurrencyFormatPLN() {
- var formatter;
- var str;
- formatter = new goog.i18n.NumberFormat(
- goog.i18n.currency.getLocalCurrencyPattern('PLN'));
- str = formatter.format(123456.7899);
- assertEquals('123,456.79 zł', str);
- formatter = new goog.i18n.NumberFormat(
- goog.i18n.currency.getPortableCurrencyPattern('PLN'));
- str = formatter.format(123456.7899);
- assertEquals('123,456.79 zł', str);
- formatter = new goog.i18n.NumberFormat(
- goog.i18n.currency.getGlobalCurrencyPattern('PLN'));
- str = formatter.format(123456.7899);
- assertEquals('PLN 123,456.79 zł', str);
- }
- function testCurrencyFormatUSD() {
- var formatter;
- var str;
- formatter = new goog.i18n.NumberFormat(
- goog.i18n.currency.getLocalCurrencyPattern('USD'));
- str = formatter.format(123456.7899);
- assertEquals('$123,456.79', str);
- formatter = new goog.i18n.NumberFormat(
- goog.i18n.currency.getPortableCurrencyPattern('USD'));
- str = formatter.format(123456.7899);
- assertEquals('US$123,456.79', str);
- formatter = new goog.i18n.NumberFormat(
- goog.i18n.currency.getGlobalCurrencyPattern('USD'));
- str = formatter.format(123456.7899);
- assertEquals('USD $123,456.79', str);
- }
- function testIsPrefixSignPosition() {
- assertTrue(goog.i18n.currency.isPrefixSignPosition('USD'));
- assertTrue(goog.i18n.currency.isPrefixSignPosition('EUR'));
- }
- function testGetCurrencySign() {
- assertEquals('USD $', goog.i18n.currency.getGlobalCurrencySign('USD'));
- assertEquals('$', goog.i18n.currency.getLocalCurrencySign('USD'));
- assertEquals('US$', goog.i18n.currency.getPortableCurrencySign('USD'));
- assertEquals('YER Rial', goog.i18n.currency.getGlobalCurrencySign('YER'));
- assertEquals('Rial', goog.i18n.currency.getLocalCurrencySign('YER'));
- assertEquals('Rial', goog.i18n.currency.getPortableCurrencySign('YER'));
- }
|