Skip to content

Commit 1a42257

Browse files
committed
Migrate Intl tests to ChakraCore.
1 parent 2c363b5 commit 1a42257

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+1854
-347
lines changed

test/Bugs/randombug.baseline

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,10 @@ Test case 30
6363
Passed
6464
Test case 31
6565
Error
66-
at func2 (randombug.js:287:9)
67-
at testlinenumber (randombug.js:293:6)
68-
at test31 (randombug.js:297:5)
69-
at Global code (randombug.js:283:2)
66+
at func2 (randombug.js:285:9)
67+
at testlinenumber (randombug.js:291:6)
68+
at test31 (randombug.js:295:5)
69+
at Global code (randombug.js:281:2)
7070
Passed
7171
Test case 32
7272
arrObj0.length setter
@@ -93,9 +93,9 @@ passed
9393
Test case 40
9494
ReferenceError: 'undefinedFunction' is undefined
9595
at eval code (eval code:1:22)
96-
at testRuntimeError (randombug.js:458:9)
97-
at test31 (randombug.js:462:5)
98-
at Global code (randombug.js:454:2)
96+
at testRuntimeError (randombug.js:456:9)
97+
at test31 (randombug.js:460:5)
98+
at Global code (randombug.js:452:2)
9999
Passed
100100
Test case 41
101101
Passed

test/Bugs/randombug.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
44
//-------------------------------------------------------------------------------------------------------
55

6+
WScript.LoadScriptFile("../UnitTestFramework/TrimStackTracePath.js");
7+
68
function write()
79
{
810
for(var i=0;i<arguments.length;i++)
@@ -11,10 +13,6 @@ function write()
1113
}
1214
}
1315

14-
function TrimStackTracePath(line) {
15-
return line && line.replace(/\(.+\\test.bugs./ig, "(");
16-
}
17-
1816
write("For Win8 934770");
1917
write("Test case 1");
2018

test/Error/NativeErrors.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ function TrimStackTracePath(obj)
1010
}
1111
if (this.WScript && typeof this.WScript.LoadScriptFile === "function")
1212
{
13-
this.WScript.LoadScriptFile("TrimStackTracePath.js");
13+
this.WScript.LoadScriptFile("../UnitTestFramework/TrimStackTracePath.js");
1414
}
1515

1616
function PadString(s, l)

test/Error/errorCtor.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ function TrimStackTracePath(obj)
1010
}
1111
if (this.WScript && typeof this.WScript.LoadScriptFile === "function")
1212
{
13-
this.WScript.LoadScriptFile("TrimStackTracePath.js");
13+
this.WScript.LoadScriptFile("../UnitTestFramework/TrimStackTracePath.js");
1414
}
1515

1616
function PadString(i)

test/Intl/Collator.js

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
//-------------------------------------------------------------------------------------------------------
2+
// Copyright (C) Microsoft. All rights reserved.
3+
// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
4+
//-------------------------------------------------------------------------------------------------------
5+
6+
var passed = true;
7+
8+
function testCollatorOptions(option, value, str1, str2, expected) {
9+
try {
10+
var options = {};
11+
options[option] = value;
12+
var collator = new Intl.Collator("en-US", options);
13+
var actual = collator.compare(str1, str2);
14+
if (actual !== expected) {
15+
passed = false;
16+
WScript.Echo("ERROR: Comparing '" + str1 + "' and '" + str2 + "' with option '" + option + ": " + value + "' resulted in '" + actual + "'; expected '" + expected + "'!");
17+
}
18+
} catch (ex) {
19+
passed = false;
20+
WScript.Echo("Error testCollatorOptions: " + ex.message);
21+
}
22+
}
23+
24+
function arrayEqual(arr1, arr2) {
25+
if (arr1.length !== arr2.length) return false;
26+
for (var i = 0; i < arr1.length; i++) {
27+
if (arr1[i] !== arr2[i]) return false;
28+
}
29+
return true;
30+
}
31+
32+
function testSupportedLocales(locales, expectedResult) {
33+
try {
34+
var actual = Intl.Collator.supportedLocalesOf(locales, { localeMatcher: "best fit" });
35+
if (!arrayEqual(actual, expectedResult)) {
36+
throw new Error("Calling SupportedLocalesOf on '[" + locales.join(",") + "]' doesn't match expected result '[" + expectedResult.join(",") + "]' when using best fit. Actual:[" + actual.join(",") + "]");
37+
}
38+
actual = Intl.Collator.supportedLocalesOf(locales, { localeMatcher: "best fit" });
39+
if (!arrayEqual(actual, expectedResult)) {
40+
throw new Error("Calling SupportedLocalesOf on '[" + locales.join(",") + "]' doesn't match expected result '[" + expectedResult.join(",") + "]' when using lookup. Actual: [" + actual.join(",") + "]");
41+
}
42+
}
43+
catch (ex) {
44+
passed = false;
45+
WScript.Echo("Error testSupportedLocales: " + ex.message);
46+
}
47+
}
48+
49+
testCollatorOptions("sensitivity", "base", "A", "a", 0);
50+
testCollatorOptions("sensitivity", "base", "A", "B", -1);
51+
testCollatorOptions("sensitivity", "base", "a", "\u00E2", 0);
52+
testCollatorOptions("sensitivity", "accent", "A", "a", 0);
53+
testCollatorOptions("sensitivity", "accent", "A", "B", -1);
54+
testCollatorOptions("sensitivity", "accent", "a", "\u00E2", -1);
55+
testCollatorOptions("sensitivity", "case", "A", "a", 1);
56+
testCollatorOptions("sensitivity", "case", "A", "B", -1);
57+
testCollatorOptions("sensitivity", "case", "a", "\u00E2", 0);
58+
testCollatorOptions("sensitivity", "variant", "A", "a", 1);
59+
testCollatorOptions("sensitivity", "variant", "A", "B", -1);
60+
testCollatorOptions("sensitivity", "variant", "a", "\u00E2", -1);
61+
62+
testCollatorOptions("ignorePunctuation", true, ".a", "a", 0);
63+
testCollatorOptions("ignorePunctuation", false, ".a", "a", -1);
64+
65+
testCollatorOptions("numeric", true, "10", "9", 1);
66+
testCollatorOptions("numeric", false, "10", "9", -1);
67+
68+
testSupportedLocales(undefined, []);
69+
testSupportedLocales(["en-US"], ["en-US"]);
70+
testSupportedLocales([], []);
71+
testSupportedLocales(["xxx"], []);
72+
73+
if (new Intl.Collator("es", { collation: "trad" }).resolvedOptions().collation !== "default") {
74+
WScript.Echo("Error: Collation option passed through option affects the value.");
75+
passed = false;
76+
}
77+
78+
if (passed === true) {
79+
WScript.Echo("Pass");
80+
}

test/Intl/CollatorOptions.js

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
//-------------------------------------------------------------------------------------------------------
2+
// Copyright (C) Microsoft. All rights reserved.
3+
// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
4+
//-------------------------------------------------------------------------------------------------------
5+
6+
WScript.LoadScriptFile("..\\UnitTestFramework\\UnitTestFramework.js");
7+
8+
// NOTE: \u00C0 is U+00C0 LATIN CAPITAL LETTER A WITH GRAVE
9+
// NOTE: \u00E4 is U+00E4 LATIN SMALL LETTER A WITH DIAERESIS
10+
var tests = [
11+
{
12+
name: "Test Valid Options Resolution",
13+
body: function () {
14+
assert.areEqual(new Intl.Collator("en-US", { sensitivity: "variant" }).resolvedOptions().sensitivity, "variant", "Ensure that variant sensitivity is interpreted correctly.");
15+
assert.areEqual(new Intl.Collator("en-US", { sensitivity: "case" }).resolvedOptions().sensitivity, "case", "Ensure that case sensitivity is interpreted correctly.");
16+
assert.areEqual(new Intl.Collator("en-US", { sensitivity: "accent" }).resolvedOptions().sensitivity, "accent", "Ensure that accent sensitivity is interpreted correctly.");
17+
assert.areEqual(new Intl.Collator("en-US", { sensitivity: "base" }).resolvedOptions().sensitivity, "base", "Ensure that base sensitivity is interpreted correctly.");
18+
19+
assert.areEqual(new Intl.Collator("de-DE", { collation: "phonebk" }).resolvedOptions().collation, "default", "Ensure that collation option is ignored.");
20+
assert.areEqual(new Intl.Collator("de-DE-u-co-phonebk").resolvedOptions().collation, "phonebk", "Ensure that collation unicode extension is interpreted correctly (with absent options).");
21+
assert.areEqual(new Intl.Collator("de-DE-u-co-phonebk", undefined).resolvedOptions().collation, "phonebk", "Ensure that collation unicode extension is interpreted correctly (with undefined options).");
22+
assert.areEqual(new Intl.Collator("de-DE-u-co-phonebk", {}).resolvedOptions().collation, "phonebk", "Ensure that collation unicode extension is interpreted correctly (with empty options).");
23+
24+
assert.areEqual(new Intl.Collator("de-DE").resolvedOptions().numeric, false, "Ensure numeric set to false implicitly.");
25+
assert.areEqual(new Intl.Collator("de-DE", { numeric: false }).resolvedOptions().numeric, false, "Ensure numeric set to false explicitly.");
26+
assert.areEqual(new Intl.Collator("de-DE", { numeric: true }).resolvedOptions().numeric, true, "Ensure numeric set to true.");
27+
28+
assert.areEqual(new Intl.Collator("de-DE-u-co-phonebk", { numeric: false }).resolvedOptions().collation, "phonebk", "Mixed -u-co-phonebk and numeric option false (collation).");
29+
assert.areEqual(new Intl.Collator("de-DE-u-co-phonebk", { numeric: false }).resolvedOptions().numeric, false, "Mixed -u-co-phonebk and numeric option false (numeric).");
30+
assert.areEqual(new Intl.Collator("de-DE-u-co-phonebk", { numeric: true }).resolvedOptions().collation, "phonebk", "Mixed -u-co-phonebk and numeric option true (collation).");
31+
assert.areEqual(new Intl.Collator("de-DE-u-co-phonebk", { numeric: true }).resolvedOptions().numeric, true, "Mixed -u-co-phonebk and numeric option true (numeric).");
32+
33+
assert.areEqual(new Intl.Collator("de-DE-u-kn-true").resolvedOptions().numeric, true, "Ensure that -u-kn-true is interpreted correctly.");
34+
assert.areEqual(new Intl.Collator("de-DE-u-kn-false").resolvedOptions().numeric, false, "Ensure that -u-kn-false is interpreted correctly.");
35+
assert.areEqual(new Intl.Collator("de-DE-u-kn-true-co-phonebk").resolvedOptions().numeric, true, "Ensure that -u-kn-true-co-phonebk is interpreted correctly (numeric).");
36+
assert.areEqual(new Intl.Collator("de-DE-u-kn-true-co-phonebk").resolvedOptions().collation, "phonebk", "Ensure that -u-kn-true-co-phonebk is interpreted correctly (collation).");
37+
assert.areEqual(new Intl.Collator("de-DE-u-kn-false-co-phonebk").resolvedOptions().numeric, false, "Ensure that -u-kn-false-co-phonebk is interpreted correctly (numeric).");
38+
assert.areEqual(new Intl.Collator("de-DE-u-kn-false-co-phonebk").resolvedOptions().collation, "phonebk", "Ensure that -u-kn-false-co-phonebk is interpreted correctly (collation).");
39+
}
40+
},
41+
{
42+
name: "Test Valid Options Behavior",
43+
body: function () {
44+
assert.areEqual(new Intl.Collator("en-US").compare("a", "A"), -1, "Comparing with default options.");
45+
assert.areEqual(new Intl.Collator("en-US", { sensitivity: "variant" }).compare("a", "A"), -1, "Comparing with variant sensitivity.");
46+
assert.areEqual(new Intl.Collator("en-US", { sensitivity: "variant" }).compare("\u00C0", "A"), 1, "Comparing with variant sensitivity.");
47+
assert.areEqual(new Intl.Collator("en-US", { sensitivity: "variant" }).compare("a", "b"), -1, "Comparing with variant sensitivity.");
48+
assert.areEqual(new Intl.Collator("en-US", { sensitivity: "case" }).compare("a", "A"), -1, "Comparing with case sensitivity.");
49+
assert.areEqual(new Intl.Collator("en-US", { sensitivity: "case" }).compare("a", "b"), -1, "Comparing with case sensitivity.");
50+
assert.areEqual(new Intl.Collator("en-US", { sensitivity: "case" }).compare("\u00C0", "A"), 0, "Comparing with case sensitivity.");
51+
assert.areEqual(new Intl.Collator("en-US", { sensitivity: "accent" }).compare("\u00C0", "A"), 1, "Comparing with accent sensitivity.");
52+
assert.areEqual(new Intl.Collator("en-US", { sensitivity: "accent" }).compare("a", "A"), 0, "Comparing with accent sensitivity.");
53+
assert.areEqual(new Intl.Collator("en-US", { sensitivity: "accent" }).compare("a", "b"), -1, "Comparing with accent sensitivity.");
54+
assert.areEqual(new Intl.Collator("en-US", { sensitivity: "base" }).compare("a", "A"), 0, "Comparing with base sensitivity.");
55+
assert.areEqual(new Intl.Collator("en-US", { sensitivity: "base" }).compare("\u00C0", "A"), 0, "Comparing with base sensitivity.");
56+
assert.areEqual(new Intl.Collator("en-US", { sensitivity: "base" }).compare("a", "b"), -1, "Comparing with base sensitivity.");
57+
58+
assert.areEqual(new Intl.Collator("de-DE", { collation: "phonebk" }).compare("\u00e4b", "ada"), -1, "Comparing with default collation, option ignored.");
59+
assert.areEqual(new Intl.Collator("de-DE", { collation: "phonebk" }).compare("äb", "ada"), -1, "Comparing with default collation, option ignored (using explicit ä character).");
60+
61+
assert.areEqual(new Intl.Collator("de-DE-u-co-phonebk", {}).compare("\u00e4b", "ada"), 1, "Comparing with collation unicode extension phonebk.");
62+
assert.areEqual(new Intl.Collator("de-DE-u-co-phonebk", {}).compare("äb", "ada"), 1, "Comparing with collation unicode extension phonebk (using explicit ä character).");
63+
assert.areEqual(new Intl.Collator("de-DE", {}).compare("\u00e4b", "ada"), -1, "Comparing without collation option of phonebk.");
64+
assert.areEqual(new Intl.Collator("de-DE", {}).compare("äb", "ada"), -1, "Comparing without collation option of phonebk (using explicit ä character).");
65+
66+
assert.areEqual(new Intl.Collator("de-DE", { numeric: true }).compare("21", "100"), -1, "Comparing with numeric option set to true.");
67+
assert.areEqual(new Intl.Collator("de-DE-u-kn-true", {}).compare("21", "100"), -1, "Comparing with numeric unicode extension set to true.");
68+
assert.areEqual(new Intl.Collator("de-DE", { numeric: false }).compare("21", "100"), 1, "Comparing with numeric option set to false.");
69+
assert.areEqual(new Intl.Collator("de-DE-u-kn-false", {}).compare("21", "100"), 1, "Comparing with numeric unicode extension set to false.");
70+
assert.areEqual(new Intl.Collator("de-DE-u-kn-true-co-phonebk", {}).compare("21", "100"), -1, "Comparing with collation set to phonebk and numeric set to true.");
71+
assert.areEqual(new Intl.Collator("de-DE-u-kn-true-co-phonebk", {}).compare("\u00e4b", "ada"), 1, "Comparing with collation set to phonebk and numeric set to true.");
72+
assert.areEqual(new Intl.Collator("de-DE-u-kn-false-co-phonebk", {}).compare("21", "100"), 1, "Comparing with collation set to phonebk and numeric set to false.");
73+
assert.areEqual(new Intl.Collator("de-DE-u-kn-false-co-phonebk", {}).compare("\u00e4b", "ada"), 1, "Comparing with collation set to phonebk and numeric set to false.");
74+
assert.areEqual(new Intl.Collator("en-US", { ignorePunctuation: true }).compare("aa", "a!a"), 0, "Comparing with ignore punctuation set to true.");
75+
assert.areEqual(new Intl.Collator("en-US", { ignorePunctuation: false }).compare("aa", "a!a"), 1, "Comparing with ignore punctuation set to true.");
76+
}
77+
},
78+
{
79+
name: "Test Invalid Options",
80+
body: function () {
81+
function verifyCollatorException(locale, options, expectingInvalidOption, validValuesStr) {
82+
try {
83+
//Since minute and second aren't supported alone; doing this to prevent that exception.
84+
new Intl.Collator(locale, options);
85+
assert.fail("Exception was expected. Option: " + expectingInvalidOption + "; options passed in: " + JSON.stringify(options));
86+
}
87+
catch (e) {
88+
if (!(e instanceof RangeError || e instanceof TypeError)) {
89+
assert.fail("Incorrect exception was thrown.");
90+
}
91+
assert.isTrue(e.message.indexOf(validValuesStr) !== -1,
92+
"Exception didn't have the correct valid values when testing option:" + expectingInvalidOption +
93+
".\nMessage: " + e.message +
94+
"\nSearched For:" + validValuesStr);
95+
}
96+
}
97+
98+
verifyCollatorException("en-US-u-kf-invalid", {}, "caseFirst", "['upper', 'lower', 'false']");
99+
verifyCollatorException("en-US", { caseFirst: "invalid" }, "caseFirst", "['upper', 'lower', 'false']");
100+
101+
assert.areEqual(new Intl.Collator("en-US", { numeric: "blah" }).resolvedOptions().numeric, true, "Testing invalid numeric option.");
102+
assert.areEqual(new Intl.Collator("en-US-u-kn-blah", {}).resolvedOptions().numeric, false, "Testing invalid numeric option.");
103+
assert.areEqual(new Intl.Collator("en-US", { ignorePunctuation: "blah" }).resolvedOptions().ignorePunctuation, true, "Testing invalid ignorePunctuation option.");
104+
assert.areEqual(new Intl.Collator("en-US", { collation: "blah" }).resolvedOptions().collation, "default", "Testing invalid collation option.");
105+
assert.areEqual(new Intl.Collator("en-US-u-co-blah", {}).resolvedOptions().collation, "default", "Testing invalid colation option.");
106+
}
107+
}
108+
];
109+
110+
testRunner.runTests(tests, { verbose: WScript.Arguments[0] != "summary" });

0 commit comments

Comments
 (0)