source: Dev/trunk/src/client/dojo/tests/currency.js @ 532

Last change on this file since 532 was 483, checked in by hendrikvanantwerpen, 11 years ago

Added Dojo 1.9.3 release.

File size: 3.0 KB
Line 
1define(["doh/main", "require", "../currency", "../i18n"], function(doh, require, currency, i18n){
2
3        var runTest= function(t){
4                doh.is("\u20ac123.45", currency.format(123.45, {currency: "EUR", locale: "en-us"}));
5                doh.is("$123.45", currency.format(123.45, {currency: "USD", locale: "en-us"}));
6                doh.is("$1,234.56", currency.format(1234.56, {currency: "USD", locale: "en-us"}));
7                doh.is("US$123.45", currency.format(123.45, {currency: "USD", locale: "en-ca"}));
8                doh.is("$123.45", currency.format(123.45, {currency: "CAD", locale: "en-ca"}));
9                doh.is("CA$123.45", currency.format(123.45, {currency: "CAD", locale: "en-us"}));
10                doh.is("123,45\xa0\u20ac", currency.format(123.45, {currency: "EUR", locale: "de-de"}));
11                doh.is("1.234,56\xa0\u20ac", currency.format(1234.56, {currency: "EUR", locale: "de-de"}));
12                // There is no special currency symbol for ADP, so expect the ISO code instead
13                doh.is("ADP123", currency.format(123, {currency: "ADP", locale: "en-us"}));
14                doh.is("$1,234", currency.format(1234, {currency: "USD", fractional: false, locale: "en-us"}));
15
16                doh.is(123.45, currency.parse("$123.45", {currency: "USD", locale: "en-us"}));
17                doh.is(1234.56, currency.parse("$1,234.56", {currency: "USD", locale: "en-us"}));
18                doh.is(123.45, currency.parse("123,45 \u20ac", {currency: "EUR", locale: "de-de"}));
19                doh.is(123.45, currency.parse("123,45\xa0\u20ac", {currency: "EUR", locale: "de-de"}));
20                doh.is(1234.56, currency.parse("1.234,56 \u20ac", {currency: "EUR", locale: "de-de"}));
21                doh.is(1234.56, currency.parse("1.234,56\u20ac", {currency: "EUR", locale: "de-de"}));
22
23                doh.is(1234, currency.parse("$1,234", {currency: "USD", locale: "en-us"}));
24                doh.is(1234, currency.parse("$1,234", {currency: "USD", fractional: false, locale: "en-us"}));
25                doh.t(isNaN(currency.parse("$1,234", {currency: "USD", fractional: true, locale: "en-us"})));
26        };
27
28        if(require.async){
29                require(["../_base/array",  "../i18n"], function(array){
30                        doh.register("tests.currency", {
31                                name: "currency",
32                                timeout: 2000,
33                                runTest: function(t){
34                                        var
35                                                def = new doh.Deferred(),
36                                                deps= [];
37                                        array.forEach(["en-us", "en-ca", "de-de"], function(locale){
38                                                deps.push(i18n.getL10nName("dojo/cldr", "currency", locale));
39                                                deps.push(i18n.getL10nName("dojo/cldr", "number", locale));
40                                        });
41                                        require(deps, def.getTestCallback(runTest));
42                                        return def;
43                                }
44                        });
45                });
46        }else{ // tests for the v1.x loader/i18n machinery
47                doh.register("tests.currency", {
48                        // Test formatting and parsing of currencies in various locales pre-built in dojo.cldr
49                        // NOTE: we can't set djConfig.extraLocale before bootstrapping unit tests, so directly
50                        // load resources here for specific locales:
51                        name: "currency",
52                        setUp: function(){
53                                var partLocaleList = ["en-us", "en-ca", "de-de"];
54                                for(var i = 0 ; i < partLocaleList.length; i ++){
55                                        dojo.requireLocalization("dojo.cldr","currency",partLocaleList[i]);
56                                        dojo.requireLocalization("dojo.cldr","number",partLocaleList[i]);
57                                }
58                        },
59                        runTest: runTest
60                });
61        }
62});
Note: See TracBrowser for help on using the repository browser.