Intl.Locale: ensure that the expect value is correctly printed in the assertion message

This commit is contained in:
Rick Waldron 2018-05-17 17:30:48 -04:00
parent a33ccf6bf1
commit 50de5f98ab
4 changed files with 69 additions and 50 deletions

View File

@ -36,32 +36,38 @@ features: [Intl.Locale]
---*/
const validHourCycleOptions = [
"h11",
"h12",
"h23",
"h24",
{ toString() { return "h24"; } },
'h11',
'h12',
'h23',
'h24',
{ toString() { return 'h24'; } },
];
for (const hourCycle of validHourCycleOptions) {
const options = { hourCycle };
const expected = String(hourCycle);
let expect = 'en-u-hc-' + expected;
assert.sameValue(
new Intl.Locale('en', options).toString(),
"en-u-hc-" + expected,
expect,
`new Intl.Locale('en', options).toString() equals the value of ${expect}`
);
assert.sameValue(
new Intl.Locale('en-u-hc-h00', options).toString(),
"en-u-hc-" + expected,
expect,
`new Intl.Locale('en-u-hc-h00', options).toString() equals the value of ${expect}`
);
assert.sameValue(
new Intl.Locale('en-u-hc-h12', options).toString(),
"en-u-hc-" + expected,
expect,
`new Intl.Locale('en-u-hc-h12', options).toString() equals the value of ${expect}`
);
assert.sameValue(
new Intl.Locale('en-u-hc-h00', options).hourCycle,
expected,
`new Intl.Locale('en-u-hc-h00', options).hourCycle equals the value of ${expect}`
);
}

View File

@ -24,33 +24,37 @@ features: [Intl.Locale]
const validLanguageOptions = [
[undefined, undefined],
[null, "null"],
["zh-cmn", "cmn"],
["ZH-CMN", "cmn"],
["abcd", "abcd"],
["abcde", "abcde"],
["abcdef", "abcdef"],
["abcdefg", "abcdefg"],
["abcdefgh", "abcdefgh"],
[{ toString() { return "de" } }, "de"],
[null, 'null'],
['zh-cmn', 'cmn'],
['ZH-CMN', 'cmn'],
['abcd', 'abcd'],
['abcde', 'abcde'],
['abcdef', 'abcdef'],
['abcdefg', 'abcdefg'],
['abcdefgh', 'abcdefgh'],
[{ toString() { return 'de' } }, 'de'],
];
for (const [language, expected] of validLanguageOptions) {
let options = { language };
let expect = expected || 'en';
assert.sameValue(
new Intl.Locale('en', options).toString(),
expected || 'en',
`new Intl.Locale('en', options).toString() equals the value of ${expected}`
expect,
`new Intl.Locale('en', options).toString() equals the value of ${expect}`
);
expect = (expected || 'en') + '-US';
assert.sameValue(
new Intl.Locale('en-US', options).toString(),
(expected || "en") + "-US",
`new Intl.Locale('en-US', options).toString() equals the value of ${expected}-US`
expected,
`new Intl.Locale('en-US', options).toString() equals the value of ${expect}`
);
expect = expected || 'en-els';
assert.sameValue(
new Intl.Locale('en-els', options).toString(),
expected || "en-els",
`new Intl.Locale('en-els', options).toString() equals the value of ${expected}`
expect,
`new Intl.Locale('en-els', options).toString() equals the value of ${expect}`
);
}

View File

@ -30,33 +30,38 @@ features: [Intl.Locale]
const validRegionOptions = [
[undefined, undefined],
["FR", "en-FR"],
["554", "en-554"],
[554, "en-554"],
['FR', 'en-FR'],
['554', 'en-554'],
[554, 'en-554'],
];
for (const [region, expected] of validRegionOptions) {
let options = { region };
let expect = expected || 'en';
assert.sameValue(
new Intl.Locale('en', options).toString(),
expected || "en",
`new Intl.Locale('en', options).toString() equals the value of ${expected}`
expect,
`new Intl.Locale('en', options).toString() equals the value of ${expect}`
);
expect = expected || 'en-US';
assert.sameValue(
new Intl.Locale('en-US', options).toString(),
expected || "en-US",
`new Intl.Locale('en-US', options).toString() equals the value of ${expected}`
expect,
`new Intl.Locale('en-US', options).toString() equals the value of ${expect}`
);
expect = (expected || 'en') + '-u-ca-gregory';
assert.sameValue(
new Intl.Locale('en-u-ca-gregory', options).toString(),
(expected || "en") + "-u-ca-gregory",
`new Intl.Locale('en-u-ca-gregory', options).toString() equals the value of ${expected}`
expect,
`new Intl.Locale('en-u-ca-gregory', options).toString() equals the value of ${expect}`
);
expect = (expected || 'en-US') + '-u-ca-gregory';
assert.sameValue(
new Intl.Locale('en-US-u-ca-gregory', options).toString(),
(expected || "en-US") + "-u-ca-gregory",
`new Intl.Locale('en-US-u-ca-gregory', options).toString() equals the value of ${expected}`
expect,
`new Intl.Locale('en-US-u-ca-gregory', options).toString() equals the value of ${expect}`
);
}

View File

@ -31,29 +31,33 @@ features: [Intl.Locale]
const validScriptOptions = [
[undefined, undefined],
[null, "Null"],
["bali", "Bali"],
["Bali", "Bali"],
["bALI", "BALI"], // TODO REVIEW: is this the correct case regularization?
[{ toString() { return "Brai" } }, "Brai"],
[null, 'Null'],
['bali', 'Bali'],
['Bali', 'Bali'],
['bALI', 'BALI'], // TODO REVIEW: is this the correct case regularization?
[{ toString() { return 'Brai' } }, 'Brai'],
];
for (const [script, expected] of validScriptOptions) {
let options = { script };
assert.sameValue(
new Intl.Locale("en", options).toString(),
expected ? ("en-" + expected) : "en",
`new Intl.Locale("en", options).toString() equals the value of ${expected}`
);
let expect = expected ? 'en-' + expected : 'en';
assert.sameValue(
new Intl.Locale("en-DK", options).toString(),
(expected ? ("en-" + expected) : "en") + "-DK",
`new Intl.Locale("en", options).toString() equals the value of ${expected}`
new Intl.Locale('en', options).toString(),
expect,
`new Intl.Locale('en', options).toString() equals the value of ${expect}`
);
expect = (expected ? ('en-' + expected) : 'en') + '-DK';
assert.sameValue(
new Intl.Locale("en-Cyrl", options).toString(),
expected ? ("en-" + expected) : "en-Cyrl",
`new Intl.Locale("en-Cyrl", options).toString() equals the value of ${expected}`
new Intl.Locale('en-DK', options).toString(),
expect,
`new Intl.Locale('en', options).toString() equals the value of ${expect}`
);
expect = expected ? ('en-' + expected) : 'en-Cyrl';
assert.sameValue(
new Intl.Locale('en-Cyrl', options).toString(),
expect,
`new Intl.Locale('en-Cyrl', options).toString() equals the value of ${expect}`
);
}