Debian Codegraph @

closure-library/closure/goog/i18n/currency_test.js

raw
1 // Copyright 2009 The Closure Library Authors. All Rights Reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS-IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15
16 goog.provide('goog.i18n.currencyTest');
17 goog.setTestOnly('goog.i18n.currencyTest');
18
19 goog.require('goog.i18n.NumberFormat');
20 goog.require('goog.i18n.currency');
21 goog.require('goog.i18n.currency.CurrencyInfo');
22 goog.require('goog.object');
23 goog.require('goog.testing.PropertyReplacer');
24 goog.require('goog.testing.jsunit');
25
26 var stubs = new goog.testing.PropertyReplacer();
27
28 function setUp() {
29 stubs.replace(
30 goog.i18n.currency, 'CurrencyInfo',
31 goog.object.clone(goog.i18n.currency.CurrencyInfo));
32 }
33
34 function tearDown() {
35 stubs.reset();
36 }
37
38 function testIsAvailable() {
39 assertTrue(goog.i18n.currency.isAvailable('USD'));
40 assertTrue(goog.i18n.currency.isAvailable('CLP'));
41 assertFalse(goog.i18n.currency.isAvailable('LRD'));
42 assertFalse(goog.i18n.currency.isAvailable('XYZ'));
43 }
44
45 function testAddTier2Support() {
46 assertFalse('LRD' in goog.i18n.currency.CurrencyInfo);
47 assertThrows(function() {
48 goog.i18n.currency.getLocalCurrencyPattern('LRD');
49 });
50
51 goog.i18n.currency.addTier2Support();
52 assertTrue('LRD' in goog.i18n.currency.CurrencyInfo);
53 assertEquals(
54 "'$'#,##0.00", goog.i18n.currency.getLocalCurrencyPattern('LRD'));
55 }
56
57 function testCurrencyPattern() {
58 assertEquals(
59 "'$'#,##0.00", goog.i18n.currency.getLocalCurrencyPattern('USD'));
60 assertEquals(
61 "'US$'#,##0.00", goog.i18n.currency.getPortableCurrencyPattern('USD'));
62 assertEquals(
63 "USD '$'#,##0.00", goog.i18n.currency.getGlobalCurrencyPattern('USD'));
64
65 assertEquals("'¥'#,##0", goog.i18n.currency.getLocalCurrencyPattern('JPY'));
66 assertEquals(
67 "'JP¥'#,##0", goog.i18n.currency.getPortableCurrencyPattern('JPY'));
68 assertEquals(
69 "JPY '¥'#,##0", goog.i18n.currency.getGlobalCurrencyPattern('JPY'));
70
71 assertEquals(
72 "'€'#,##0.00", goog.i18n.currency.getLocalCurrencyPattern('EUR'));
73 assertEquals(
74 "'€'#,##0.00", goog.i18n.currency.getPortableCurrencyPattern('EUR'));
75 assertEquals(
76 "EUR '€'#,##0.00", goog.i18n.currency.getGlobalCurrencyPattern('EUR'));
77
78 assertEquals(
79 "'¥'#,##0.00", goog.i18n.currency.getLocalCurrencyPattern('CNY'));
80 assertEquals(
81 "'RMB¥'#,##0.00", goog.i18n.currency.getPortableCurrencyPattern('CNY'));
82 assertEquals(
83 "CNY '¥'#,##0.00", goog.i18n.currency.getGlobalCurrencyPattern('CNY'));
84
85 assertEquals(
86 "'Rial'#,##0", goog.i18n.currency.getLocalCurrencyPattern('YER'));
87 assertEquals(
88 "'Rial'#,##0", goog.i18n.currency.getPortableCurrencyPattern('YER'));
89 assertEquals(
90 "YER 'Rial'#,##0", goog.i18n.currency.getGlobalCurrencyPattern('YER'));
91
92 assertEquals(
93 "'CHF'#,##0.00", goog.i18n.currency.getLocalCurrencyPattern('CHF'));
94 assertEquals(
95 "'CHF'#,##0.00", goog.i18n.currency.getPortableCurrencyPattern('CHF'));
96 assertEquals(
97 "'CHF'#,##0.00", goog.i18n.currency.getGlobalCurrencyPattern('CHF'));
98 }
99
100 function testCurrencyFormatCHF() {
101 var formatter;
102 var str;
103
104 formatter = new goog.i18n.NumberFormat(
105 goog.i18n.currency.getLocalCurrencyPattern('CHF'));
106 str = formatter.format(123456.7899);
107 assertEquals('CHF123,456.79', str);
108
109 formatter = new goog.i18n.NumberFormat(
110 goog.i18n.currency.getPortableCurrencyPattern('CHF'));
111 str = formatter.format(123456.7899);
112 assertEquals('CHF123,456.79', str);
113
114 formatter = new goog.i18n.NumberFormat(
115 goog.i18n.currency.getGlobalCurrencyPattern('CHF'));
116 str = formatter.format(123456.7899);
117 assertEquals('CHF123,456.79', str);
118 }
119
120 function testCurrencyFormatYER() {
121 var formatter;
122 var str;
123
124 formatter = new goog.i18n.NumberFormat(
125 goog.i18n.currency.getLocalCurrencyPattern('YER'));
126 str = formatter.format(123456.7899);
127 assertEquals('Rial123,457', str);
128
129 formatter = new goog.i18n.NumberFormat(
130 goog.i18n.currency.getPortableCurrencyPattern('YER'));
131 str = formatter.format(123456.7899);
132 assertEquals('Rial123,457', str);
133
134 formatter = new goog.i18n.NumberFormat(
135 goog.i18n.currency.getGlobalCurrencyPattern('YER'));
136 str = formatter.format(123456.7899);
137 assertEquals('YER Rial123,457', str);
138 }
139
140 function testCurrencyFormatCNY() {
141 var formatter;
142 var str;
143
144 formatter = new goog.i18n.NumberFormat(
145 goog.i18n.currency.getLocalCurrencyPattern('CNY'));
146 str = formatter.format(123456.7899);
147 assertEquals('¥123,456.79', str);
148
149 formatter = new goog.i18n.NumberFormat(
150 goog.i18n.currency.getPortableCurrencyPattern('CNY'));
151 str = formatter.format(123456.7899);
152 assertEquals('RMB¥123,456.79', str);
153
154 formatter = new goog.i18n.NumberFormat(
155 goog.i18n.currency.getGlobalCurrencyPattern('CNY'));
156 str = formatter.format(123456.7899);
157 assertEquals('CNY ¥123,456.79', str);
158 }
159
160 function testCurrencyFormatCZK() {
161 var formatter;
162 var str;
163
164 formatter = new goog.i18n.NumberFormat(
165 goog.i18n.currency.getLocalCurrencyPattern('CZK'));
166 str = formatter.format(123456.7899);
167 assertEquals('123,456.79 Kč', str);
168
169 formatter = new goog.i18n.NumberFormat(
170 goog.i18n.currency.getPortableCurrencyPattern('CZK'));
171 str = formatter.format(123456.7899);
172 assertEquals('123,456.79 Kč', str);
173
174 formatter = new goog.i18n.NumberFormat(
175 goog.i18n.currency.getGlobalCurrencyPattern('CZK'));
176 str = formatter.format(123456.7899);
177 assertEquals('CZK 123,456.79 Kč', str);
178 }
179
180 function testCurrencyFormatEUR() {
181 var formatter;
182 var str;
183
184 formatter = new goog.i18n.NumberFormat(
185 goog.i18n.currency.getLocalCurrencyPattern('EUR'));
186 str = formatter.format(123456.7899);
187 assertEquals('€123,456.79', str);
188
189 formatter = new goog.i18n.NumberFormat(
190 goog.i18n.currency.getPortableCurrencyPattern('EUR'));
191 str = formatter.format(123456.7899);
192 assertEquals('€123,456.79', str);
193
194 formatter = new goog.i18n.NumberFormat(
195 goog.i18n.currency.getGlobalCurrencyPattern('EUR'));
196 str = formatter.format(123456.7899);
197 assertEquals('EUR €123,456.79', str);
198 }
199
200 function testCurrencyFormatJPY() {
201 var formatter;
202 var str;
203
204 formatter = new goog.i18n.NumberFormat(
205 goog.i18n.currency.getLocalCurrencyPattern('JPY'));
206 str = formatter.format(123456.7899);
207 assertEquals('¥123,457', str);
208
209 formatter = new goog.i18n.NumberFormat(
210 goog.i18n.currency.getPortableCurrencyPattern('JPY'));
211 str = formatter.format(123456.7899);
212 assertEquals('JP¥123,457', str);
213
214 formatter = new goog.i18n.NumberFormat(
215 goog.i18n.currency.getGlobalCurrencyPattern('JPY'));
216 str = formatter.format(123456.7899);
217 assertEquals('JPY ¥123,457', str);
218 }
219
220 function testCurrencyFormatPLN() {
221 var formatter;
222 var str;
223
224 formatter = new goog.i18n.NumberFormat(
225 goog.i18n.currency.getLocalCurrencyPattern('PLN'));
226 str = formatter.format(123456.7899);
227 assertEquals('123,456.79 zł', str);
228
229 formatter = new goog.i18n.NumberFormat(
230 goog.i18n.currency.getPortableCurrencyPattern('PLN'));
231 str = formatter.format(123456.7899);
232 assertEquals('123,456.79 zł', str);
233
234 formatter = new goog.i18n.NumberFormat(
235 goog.i18n.currency.getGlobalCurrencyPattern('PLN'));
236 str = formatter.format(123456.7899);
237 assertEquals('PLN 123,456.79 zł', str);
238 }
239
240 function testCurrencyFormatUSD() {
241 var formatter;
242 var str;
243
244 formatter = new goog.i18n.NumberFormat(
245 goog.i18n.currency.getLocalCurrencyPattern('USD'));
246 str = formatter.format(123456.7899);
247 assertEquals('$123,456.79', str);
248
249 formatter = new goog.i18n.NumberFormat(
250 goog.i18n.currency.getPortableCurrencyPattern('USD'));
251 str = formatter.format(123456.7899);
252 assertEquals('US$123,456.79', str);
253
254 formatter = new goog.i18n.NumberFormat(
255 goog.i18n.currency.getGlobalCurrencyPattern('USD'));
256 str = formatter.format(123456.7899);
257 assertEquals('USD $123,456.79', str);
258 }
259
260
261 function testIsPrefixSignPosition() {
262 assertTrue(goog.i18n.currency.isPrefixSignPosition('USD'));
263 assertTrue(goog.i18n.currency.isPrefixSignPosition('EUR'));
264 }
265
266 function testGetCurrencySign() {
267 assertEquals('USD $', goog.i18n.currency.getGlobalCurrencySign('USD'));
268 assertEquals('$', goog.i18n.currency.getLocalCurrencySign('USD'));
269 assertEquals('US$', goog.i18n.currency.getPortableCurrencySign('USD'));
270
271 assertEquals('YER Rial', goog.i18n.currency.getGlobalCurrencySign('YER'));
272 assertEquals('Rial', goog.i18n.currency.getLocalCurrencySign('YER'));
273 assertEquals('Rial', goog.i18n.currency.getPortableCurrencySign('YER'));
274 }