2150 |
mathias |
1 |
if(!dojo._hasResource["tests.currency"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
|
|
|
2 |
dojo._hasResource["tests.currency"] = true;
|
|
|
3 |
dojo.provide("tests.currency");
|
|
|
4 |
|
|
|
5 |
dojo.require("dojo.currency");
|
|
|
6 |
|
|
|
7 |
tests.register("tests.currency",
|
|
|
8 |
[
|
|
|
9 |
{
|
|
|
10 |
// Test formatting and parsing of currencies in various locales pre-built in dojo.cldr
|
|
|
11 |
// NOTE: we can't set djConfig.extraLocale before bootstrapping unit tests, so directly
|
|
|
12 |
// load resources here for specific locales:
|
|
|
13 |
|
|
|
14 |
name: "currency",
|
|
|
15 |
setUp: function(){
|
|
|
16 |
var partLocaleList = ["en-us", "en-ca", "de-de"];
|
|
|
17 |
for(var i = 0 ; i < partLocaleList.length; i ++){
|
|
|
18 |
dojo.requireLocalization("dojo.cldr","currency",partLocaleList[i], "ko,zh,ja,en,en-ca,en-au,ROOT,en-us,it,fr,pt,es,de");
|
|
|
19 |
dojo.requireLocalization("dojo.cldr","number",partLocaleList[i], "zh-cn,en,en-ca,zh-tw,en-us,it,ja-jp,ROOT,de-de,es-es,fr,pt,ko-kr,es,de");
|
|
|
20 |
}
|
|
|
21 |
},
|
|
|
22 |
runTest: function(t){
|
|
|
23 |
t.is("\u20ac123.45", dojo.currency.format(123.45, {currency: "EUR", locale: "en-us"}));
|
|
|
24 |
t.is("$123.45", dojo.currency.format(123.45, {currency: "USD", locale: "en-us"}));
|
|
|
25 |
t.is("$1,234.56", dojo.currency.format(1234.56, {currency: "USD", locale: "en-us"}));
|
|
|
26 |
t.is("US$123.45", dojo.currency.format(123.45, {currency: "USD", locale: "en-ca"}));
|
|
|
27 |
t.is("$123.45", dojo.currency.format(123.45, {currency: "CAD", locale: "en-ca"}));
|
|
|
28 |
t.is("Can$123.45", dojo.currency.format(123.45, {currency: "CAD", locale: "en-us"}));
|
|
|
29 |
t.is("123,45 \u20ac", dojo.currency.format(123.45, {currency: "EUR", locale: "de-de"}));
|
|
|
30 |
t.is("1.234,56 \u20ac", dojo.currency.format(1234.56, {currency: "EUR", locale: "de-de"}));
|
|
|
31 |
// There is no special currency symbol for ADP, so expect the ISO code instead
|
|
|
32 |
t.is("ADP123", dojo.currency.format(123, {currency: "ADP", locale: "en-us"}));
|
|
|
33 |
|
|
|
34 |
t.is(123.45, dojo.currency.parse("$123.45", {currency: "USD", locale: "en-us"}));
|
|
|
35 |
t.is(1234.56, dojo.currency.parse("$1,234.56", {currency: "USD", locale: "en-us"}));
|
|
|
36 |
t.is(123.45, dojo.currency.parse("123,45 \u20ac", {currency: "EUR", locale: "de-de"}));
|
|
|
37 |
t.is(1234.56, dojo.currency.parse("1.234,56 \u20ac", {currency: "EUR", locale: "de-de"}));
|
|
|
38 |
t.is(1234.56, dojo.currency.parse("1.234,56\u20ac", {currency: "EUR", locale: "de-de"}));
|
|
|
39 |
|
|
|
40 |
t.is(1234, dojo.currency.parse("$1,234", {currency: "USD", locale: "en-us"}));
|
|
|
41 |
t.is(1234, dojo.currency.parse("$1,234", {currency: "USD", fractional: false, locale: "en-us"}));
|
|
|
42 |
t.t(isNaN(dojo.currency.parse("$1,234", {currency: "USD", fractional: true, locale: "en-us"})));
|
|
|
43 |
}
|
|
|
44 |
}
|
|
|
45 |
]
|
|
|
46 |
);
|
|
|
47 |
|
|
|
48 |
}
|