Skip to content

Commit 9389955

Browse files
nkovacsrxaviers
authored andcommitted
Test: add tests for compiler
Closes #721
1 parent 0f6b5b9 commit 9389955

12 files changed

+501
-2
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ dist/.build/
44
external/
55
node_modules/
66
tmp/
7+
test/compiler/_compiled/

Gruntfile.js

+12-2
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ module.exports = function( grunt ) {
7979
},
8080
test: {
8181
src: [ "test/*.js", "test/functional/**/*.js", "test/unit/**/*.js",
82-
"!test/config.js" ],
82+
"test/compiler/**/*.js", "!test/config.js", "!test/compiler/_compiled/**" ],
8383
options: {
8484
jshintrc: "test/.jshintrc"
8585
}
@@ -94,9 +94,18 @@ module.exports = function( grunt ) {
9494
jscs: {
9595
source: [ "src/**/*.js", "!src/build/**" ],
9696
grunt: "Gruntfile.js",
97-
test: [ "test/*.js", "test/functional/**/*.js", "test/unit/**/*.js" ],
97+
test: [ "test/*.js", "test/functional/**/*.js", "test/unit/**/*.js",
98+
"test/compiler/**/*.js", "!test/compiler/_compiled/**" ],
9899
dist: [ "dist/globalize*.js", "dist/globalize/*.js" ]
99100
},
101+
mochaTest: {
102+
test: {
103+
options: {
104+
reporter: "spec"
105+
},
106+
src: [ "test/compiler/*.js" ]
107+
}
108+
},
100109
qunit: {
101110
functional: {
102111
options: {
@@ -675,6 +684,7 @@ module.exports = function( grunt ) {
675684
// TODO fix issues, enable
676685
// "jscs:dist",
677686
"test:functional",
687+
"mochaTest",
678688
"uglify",
679689
"compare_size",
680690
"commitplease"

package.json

+4
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@
7474
},
7575
"devDependencies": {
7676
"cldr-data-downloader": "^0.2.5",
77+
"glob": "^7.1.1",
78+
"globalize-compiler": "^0.3.0-alpha.3",
7779
"grunt": "0.4.5",
7880
"grunt-check-dependencies": "0.6.0",
7981
"grunt-commitplease": "0.0.5",
@@ -88,9 +90,11 @@
8890
"grunt-contrib-watch": "0.6.1",
8991
"grunt-git-authors": "^3.1.0",
9092
"grunt-jscs": "1.8.0",
93+
"grunt-mocha-test": "^0.13.2",
9194
"gzip-js": "0.3.2",
9295
"iana-tz-data": "0.0.4",
9396
"matchdep": "0.3.0",
97+
"mocha": "^3.3.0",
9498
"zoned-date-time": "0.0.4"
9599
},
96100
"commitplease": {

test/.jshintrc

+4
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@
1616
"globals": {
1717
"define": false,
1818
"require": false,
19+
"module": false,
20+
"__dirname": false,
21+
"describe": false,
22+
"it": false,
1923
"QUnit": false
2024
}
2125
}

test/compiler/cases/currency.js

+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
module.exports = {
2+
dependencies: function() {
3+
var Globalize = require( "../../../dist/node-main.js" );
4+
5+
Globalize.load(
6+
// core
7+
require( "../../../external/cldr-data/supplemental/likelySubtags.json" ),
8+
// currency
9+
require( "../../../external/cldr-data/main/en/currencies.json" ),
10+
require( "../../../external/cldr-data/main/de/currencies.json" ),
11+
require( "../../../external/cldr-data/main/zh/currencies.json" ),
12+
require( "../../../external/cldr-data/supplemental/currencyData.json" ),
13+
// number
14+
require( "../../../external/cldr-data/main/en/numbers.json" ),
15+
require( "../../../external/cldr-data/main/de/numbers.json" ),
16+
require( "../../../external/cldr-data/main/zh/numbers.json" ),
17+
require( "../../../external/cldr-data/supplemental/numberingSystems.json" ),
18+
// plural
19+
require( "../../../external/cldr-data/supplemental/plurals.json" ),
20+
require( "../../../external/cldr-data/supplemental/ordinals.json" )
21+
);
22+
23+
return Globalize;
24+
},
25+
cases: function( Globalize ) {
26+
var accounting = { style: "accounting" },
27+
code = { style: "code" },
28+
name = { style: "name" },
29+
teslaS = 69900;
30+
31+
var de, zh;
32+
33+
de = Globalize( "de" );
34+
zh = Globalize( "zh" );
35+
Globalize.locale( "en" );
36+
37+
return [
38+
{ formatter: Globalize.currencyFormatter( "USD" ), args: [ teslaS ] },
39+
{ formatter: de.currencyFormatter( "USD" ), args: [ teslaS ] },
40+
{ formatter: zh.currencyFormatter( "USD" ), args: [ teslaS ] },
41+
42+
{ formatter: Globalize.currencyFormatter( "USD" ), args: [ -teslaS ] },
43+
{ formatter: de.currencyFormatter( "USD" ), args: [ -teslaS ] },
44+
{ formatter: zh.currencyFormatter( "USD" ), args: [ -teslaS ] },
45+
46+
{ formatter: Globalize.currencyFormatter( "USD", code ), args: [ teslaS ] },
47+
{ formatter: de.currencyFormatter( "USD", code ), args: [ teslaS ] },
48+
{ formatter: zh.currencyFormatter( "USD", code ), args: [ teslaS ] },
49+
50+
{ formatter: Globalize.currencyFormatter( "USD", name ), args: [ teslaS ] },
51+
{ formatter: de.currencyFormatter( "USD", name ), args: [ teslaS ] },
52+
{ formatter: zh.currencyFormatter( "USD", name ), args: [ teslaS ] },
53+
54+
{ formatter: Globalize.currencyFormatter( "USD", accounting ), args: [ -1 ] },
55+
56+
{ formatter: Globalize.currencyFormatter( "CLF" ), args: [ 12345 ] },
57+
{ formatter: Globalize.currencyFormatter( "CLF" ), args: [ 12345.67 ] },
58+
{ formatter: Globalize.currencyFormatter( "ZWD" ), args: [ 12345 ] },
59+
{ formatter: Globalize.currencyFormatter( "ZWD" ), args: [ 12345.67 ] },
60+
{ formatter: Globalize.currencyFormatter( "JPY" ), args: [ 12345.67 ] },
61+
{ formatter: Globalize.currencyFormatter( "CLF", code ), args: [ 12345.67 ] },
62+
{ formatter: Globalize.currencyFormatter( "CLF", name ), args: [ 12345.67 ] },
63+
64+
{ formatter: Globalize.currencyFormatter( "CLF", {
65+
minimumFractionDigits: 0
66+
}), args: [ 12345 ] },
67+
{ formatter: Globalize.currencyFormatter( "CLF", {
68+
style: "code",
69+
minimumFractionDigits: 0
70+
}), args: [ 12345 ] },
71+
{ formatter: Globalize.currencyFormatter( "CLF", {
72+
style: "name",
73+
minimumFractionDigits: 0
74+
}), args: [ 12345 ] }
75+
];
76+
}
77+
};

test/compiler/cases/date.js

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
module.exports = {
2+
dependencies: function() {
3+
var Globalize = require( "../../../dist/node-main.js" );
4+
5+
Globalize.load(
6+
// core
7+
require( "../../../external/cldr-data/supplemental/likelySubtags.json" ),
8+
// date
9+
require( "../../../external/cldr-data/main/en/ca-gregorian.json" ),
10+
require( "../../../external/cldr-data/main/en/timeZoneNames.json" ),
11+
require( "../../../external/cldr-data/supplemental/timeData.json" ),
12+
require( "../../../external/cldr-data/supplemental/weekData.json" ),
13+
// number
14+
require( "../../../external/cldr-data/main/en/numbers.json" ),
15+
require( "../../../external/cldr-data/supplemental/numberingSystems.json" )
16+
);
17+
18+
return Globalize;
19+
},
20+
cases: function( Globalize ) {
21+
var date = new Date( 2010, 8, 15, 17, 35, 7, 369 );
22+
Globalize.locale( "en" );
23+
return [
24+
{ formatter: Globalize.dateFormatter({ skeleton: "GyMMMEd" }), args: [ date ] },
25+
{ formatter: Globalize.dateFormatter({ skeleton: "dhms" }), args: [ date ] },
26+
{ formatter: Globalize.dateFormatter({ skeleton: "GyMMMEdhms" }), args: [ date ] },
27+
{ formatter: Globalize.dateFormatter({ skeleton: "Ems" }), args: [ date ] },
28+
{ formatter: Globalize.dateFormatter({ skeleton: "yQQQhm" }), args: [ date ] },
29+
30+
{ formatter: Globalize.dateFormatter({ skeleton: "yMMMMd" }), args: [ date ] },
31+
{ formatter: Globalize.dateFormatter({ skeleton: "MMMMd" }), args: [ date ] },
32+
{ formatter: Globalize.dateFormatter({ skeleton: "MMMM" }), args: [ date ] },
33+
{ formatter: Globalize.dateFormatter({ skeleton: "EEEE" }), args: [ date ] }
34+
];
35+
}
36+
};

test/compiler/cases/message.js

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
module.exports = {
2+
dependencies: function() {
3+
var Globalize = require( "../../../dist/node-main.js" );
4+
5+
Globalize.load(
6+
// core
7+
require( "../../../external/cldr-data/supplemental/likelySubtags.json" )
8+
);
9+
10+
Globalize.loadMessages({
11+
en: {
12+
greetings: {
13+
hello: "Hello, {name}"
14+
}
15+
}
16+
});
17+
18+
return Globalize;
19+
},
20+
cases: function( Globalize ) {
21+
Globalize.locale( "en" );
22+
return [
23+
{ formatter: Globalize( "en" ).messageFormatter( "greetings/hello" ), args: [ {
24+
name: "Beethoven"
25+
} ] }
26+
];
27+
}
28+
};

test/compiler/cases/number.js

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
module.exports = {
2+
dependencies: function() {
3+
var Globalize = require( "../../../dist/node-main.js" );
4+
5+
Globalize.load(
6+
// core
7+
require( "../../../external/cldr-data/supplemental/likelySubtags.json" ),
8+
// number
9+
require( "../../../external/cldr-data/main/ar/numbers.json" ),
10+
require( "../../../external/cldr-data/main/en/numbers.json" ),
11+
require( "../../../external/cldr-data/main/es/numbers.json" ),
12+
require( "../../../external/cldr-data/main/zh/numbers.json" ),
13+
require( "../../../external/cldr-data/supplemental/numberingSystems.json" )
14+
);
15+
16+
return Globalize;
17+
},
18+
cases: function( Globalize ) {
19+
var pi = 3.14159265359;
20+
Globalize.locale( "en" );
21+
return [
22+
{ formatter: Globalize.numberFormatter(), args: [ pi ] },
23+
{ formatter: Globalize( "es" ).numberFormatter(), args: [ pi ] },
24+
{ formatter: Globalize( "ar" ).numberFormatter(), args: [ pi ] },
25+
{ formatter: Globalize( "zh-u-nu-native" ).numberFormatter(), args: [ pi ] },
26+
{ formatter: Globalize.numberFormatter(), args: [ 99999999.99 ] },
27+
28+
{ formatter: Globalize.numberFormatter( {
29+
minimumIntegerDigits: 2,
30+
minimumFractionDigits: 2,
31+
maximumFractionDigits: 2
32+
} ), args: [ pi ] },
33+
{ formatter: Globalize.numberFormatter( {
34+
maximumFractionDigits: 0
35+
} ), args: [ pi ] },
36+
{ formatter: Globalize.numberFormatter( {
37+
minimumFractionDigits: 3
38+
} ), args: [ 1.1 ] },
39+
{ formatter: Globalize.numberFormatter( {
40+
minimumSignificantDigits: 1,
41+
maximumSignificantDigits: 3
42+
} ), args: [ pi ] },
43+
{ formatter: Globalize.numberFormatter( {
44+
minimumSignificantDigits: 1,
45+
maximumSignificantDigits: 3
46+
} ), args: [ 12345 ] },
47+
{ formatter: Globalize.numberFormatter( {
48+
minimumSignificantDigits: 1,
49+
maximumSignificantDigits: 3
50+
} ), args: [ 0.00012345 ] },
51+
{ formatter: Globalize.numberFormatter( {
52+
minimumSignificantDigits: 1,
53+
maximumSignificantDigits: 3
54+
} ), args: [ 0.00010001 ] },
55+
{ formatter: Globalize.numberFormatter( { useGrouping: false } ), args: [ 99999999.99 ] },
56+
57+
{ formatter: Globalize.numberFormatter( { style: "percent" } ), args: [ pi ] },
58+
{ formatter: Globalize( "ar" ).numberFormatter( { style: "percent" } ), args: [ pi ] }
59+
];
60+
}
61+
};

test/compiler/cases/plural.js

+102
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
module.exports = {
2+
dependencies: function() {
3+
var Globalize = require( "../../../dist/node-main.js" );
4+
5+
Globalize.load(
6+
// core
7+
require( "../../../external/cldr-data/supplemental/likelySubtags.json" ),
8+
// plural
9+
require( "../../../external/cldr-data/supplemental/plurals.json" ),
10+
require( "../../../external/cldr-data/supplemental/ordinals.json" )
11+
);
12+
13+
return Globalize;
14+
},
15+
cases: function( Globalize ) {
16+
Globalize.locale( "en" );
17+
return [
18+
{ formatter: Globalize.pluralGenerator(), args: [ 0 ] },
19+
{ formatter: Globalize.pluralGenerator(), args: [ 0.14 ] },
20+
21+
{ formatter: Globalize( "en" ).pluralGenerator(), args: [ 0 ] },
22+
{ formatter: Globalize( "en" ).pluralGenerator(), args: [ 1 ] },
23+
{ formatter: Globalize( "en" ).pluralGenerator(), args: [ 2 ] },
24+
{ formatter: Globalize( "en" ).pluralGenerator(), args: [ 1412 ] },
25+
{ formatter: Globalize( "en" ).pluralGenerator(), args: [ 0.14 ] },
26+
{ formatter: Globalize( "en" ).pluralGenerator(), args: [ 3.14 ] },
27+
28+
{ formatter: Globalize( "en" ).pluralGenerator( { type: "ordinal" } ), args: [ 0 ] },
29+
{ formatter: Globalize( "en" ).pluralGenerator( { type: "ordinal" } ), args: [ 1 ] },
30+
{ formatter: Globalize( "en" ).pluralGenerator( { type: "ordinal" } ), args: [ 2 ] },
31+
{ formatter: Globalize( "en" ).pluralGenerator( { type: "ordinal" } ), args: [ 3 ] },
32+
{ formatter: Globalize( "en" ).pluralGenerator( { type: "ordinal" } ), args: [ 1412 ] },
33+
{ formatter: Globalize( "en" ).pluralGenerator( { type: "ordinal" } ), args: [ 0.14 ] },
34+
{ formatter: Globalize( "en" ).pluralGenerator( { type: "ordinal" } ), args: [ 3.14 ] },
35+
36+
{ formatter: Globalize( "ar" ).pluralGenerator(), args: [ 0 ] },
37+
{ formatter: Globalize( "ar" ).pluralGenerator(), args: [ 1 ] },
38+
{ formatter: Globalize( "ar" ).pluralGenerator(), args: [ 2 ] },
39+
{ formatter: Globalize( "ar" ).pluralGenerator(), args: [ 3 ] },
40+
{ formatter: Globalize( "ar" ).pluralGenerator(), args: [ 6 ] },
41+
{ formatter: Globalize( "ar" ).pluralGenerator(), args: [ 9 ] },
42+
{ formatter: Globalize( "ar" ).pluralGenerator(), args: [ 10 ] },
43+
{ formatter: Globalize( "ar" ).pluralGenerator(), args: [ 11 ] },
44+
{ formatter: Globalize( "ar" ).pluralGenerator(), args: [ 15 ] },
45+
{ formatter: Globalize( "ar" ).pluralGenerator(), args: [ 21 ] },
46+
{ formatter: Globalize( "ar" ).pluralGenerator(), args: [ 70 ] },
47+
{ formatter: Globalize( "ar" ).pluralGenerator(), args: [ 99 ] },
48+
{ formatter: Globalize( "ar" ).pluralGenerator(), args: [ 100 ] },
49+
{ formatter: Globalize( "ar" ).pluralGenerator(), args: [ 101 ] },
50+
{ formatter: Globalize( "ar" ).pluralGenerator(), args: [ 102 ] },
51+
{ formatter: Globalize( "ar" ).pluralGenerator(), args: [ 103 ] },
52+
{ formatter: Globalize( "ar" ).pluralGenerator(), args: [ 111 ] },
53+
{ formatter: Globalize( "ar" ).pluralGenerator(), args: [ 199 ] },
54+
{ formatter: Globalize( "ar" ).pluralGenerator(), args: [ 3.14 ] },
55+
56+
{ formatter: Globalize( "ar" ).pluralGenerator( { type: "ordinal" } ), args: [ 0 ] },
57+
{ formatter: Globalize( "ar" ).pluralGenerator( { type: "ordinal" } ), args: [ 1 ] },
58+
{ formatter: Globalize( "ar" ).pluralGenerator( { type: "ordinal" } ), args: [ 2 ] },
59+
{ formatter: Globalize( "ar" ).pluralGenerator( { type: "ordinal" } ), args: [ 3 ] },
60+
{ formatter: Globalize( "ar" ).pluralGenerator( { type: "ordinal" } ), args: [ 9 ] },
61+
{ formatter: Globalize( "ar" ).pluralGenerator( { type: "ordinal" } ), args: [ 10 ] },
62+
{ formatter: Globalize( "ar" ).pluralGenerator( { type: "ordinal" } ), args: [ 11 ] },
63+
{ formatter: Globalize( "ar" ).pluralGenerator( { type: "ordinal" } ), args: [ 99 ] },
64+
{ formatter: Globalize( "ar" ).pluralGenerator( { type: "ordinal" } ), args: [ 100 ] },
65+
{ formatter: Globalize( "ar" ).pluralGenerator( { type: "ordinal" } ), args: [ 101 ] },
66+
{ formatter: Globalize( "ar" ).pluralGenerator( { type: "ordinal" } ), args: [ 3.14 ] },
67+
68+
69+
{ formatter: Globalize( "ja" ).pluralGenerator(), args: [ 0 ] },
70+
{ formatter: Globalize( "ja" ).pluralGenerator(), args: [ 1 ] },
71+
{ formatter: Globalize( "ja" ).pluralGenerator(), args: [ 2 ] },
72+
{ formatter: Globalize( "ja" ).pluralGenerator(), args: [ 3.14 ] },
73+
74+
{ formatter: Globalize( "pt" ).pluralGenerator(), args: [ 0 ] },
75+
{ formatter: Globalize( "pt" ).pluralGenerator(), args: [ 1 ] },
76+
{ formatter: Globalize( "pt" ).pluralGenerator(), args: [ 2 ] },
77+
{ formatter: Globalize( "pt" ).pluralGenerator(), args: [ 0.1 ] },
78+
{ formatter: Globalize( "pt" ).pluralGenerator(), args: [ 3.14 ] },
79+
80+
{ formatter: Globalize( "ru" ).pluralGenerator(), args: [ 0 ] },
81+
{ formatter: Globalize( "ru" ).pluralGenerator(), args: [ 1 ] },
82+
{ formatter: Globalize( "ru" ).pluralGenerator(), args: [ 2 ] },
83+
{ formatter: Globalize( "ru" ).pluralGenerator(), args: [ 3 ] },
84+
{ formatter: Globalize( "ru" ).pluralGenerator(), args: [ 4 ] },
85+
{ formatter: Globalize( "ru" ).pluralGenerator(), args: [ 5 ] },
86+
{ formatter: Globalize( "ru" ).pluralGenerator(), args: [ 6 ] },
87+
{ formatter: Globalize( "ru" ).pluralGenerator(), args: [ 9 ] },
88+
{ formatter: Globalize( "ru" ).pluralGenerator(), args: [ 11 ] },
89+
{ formatter: Globalize( "ru" ).pluralGenerator(), args: [ 12 ] },
90+
{ formatter: Globalize( "ru" ).pluralGenerator(), args: [ 19 ] },
91+
{ formatter: Globalize( "ru" ).pluralGenerator(), args: [ 21 ] },
92+
{ formatter: Globalize( "ru" ).pluralGenerator(), args: [ 22 ] },
93+
{ formatter: Globalize( "ru" ).pluralGenerator(), args: [ 29 ] },
94+
{ formatter: Globalize( "ru" ).pluralGenerator(), args: [ 3.14 ] },
95+
96+
{ formatter: Globalize( "zh" ).pluralGenerator(), args: [ 0 ] },
97+
{ formatter: Globalize( "zh" ).pluralGenerator(), args: [ 1 ] },
98+
{ formatter: Globalize( "zh" ).pluralGenerator(), args: [ 2 ] },
99+
{ formatter: Globalize( "zh" ).pluralGenerator(), args: [ 3.14 ] }
100+
];
101+
}
102+
};

0 commit comments

Comments
 (0)