Skip to content
Snippets Groups Projects
Commit faed4fb0 authored by André Bargull's avatar André Bargull
Browse files

Fix various test issues

parent 2ac5f176
No related branches found
No related tags found
No related merge requests found
Showing
with 74 additions and 77 deletions
...@@ -36,6 +36,7 @@ var o = { ...@@ -36,6 +36,7 @@ var o = {
return { return {
toString() { toString() {
calls.push('flags toString'); calls.push('flags toString');
return "";
} }
}; };
}, },
...@@ -50,7 +51,7 @@ RegExp.prototype[Symbol.matchAll].call(o, { ...@@ -50,7 +51,7 @@ RegExp.prototype[Symbol.matchAll].call(o, {
assert.sameValue(0, internalCount); assert.sameValue(0, internalCount);
assert.sameValue(calls.length, 4); assert.sameValue(calls.length, 4);
assert.sameValue(calls[0], 'get @@match'); assert.sameValue(calls[0], 'arg toString');
assert.sameValue(calls[1], 'arg toString'); assert.sameValue(calls[1], 'get flags');
assert.sameValue(calls[2], 'get flags'); assert.sameValue(calls[2], 'flags toString');
assert.sameValue(calls[3], 'flags toString'); assert.sameValue(calls[3], 'get @@match');
...@@ -18,14 +18,16 @@ const tests = [ ...@@ -18,14 +18,16 @@ const tests = [
["EN", "en", "Single value"], ["EN", "en", "Single value"],
[[], defaultLocale, "Empty array"], [[], defaultLocale, "Empty array"],
[["en-GB-oed"], "en-GB", "Grandfathered"], [["en-GB-oed"], "en-GB", "Grandfathered"],
[["x-private"], defaultLocale, "Private"], [["x-private"], defaultLocale, "Private", ["lookup"]],
[["en", "EN"], "en", "Duplicate value (canonical first)"], [["en", "EN"], "en", "Duplicate value (canonical first)"],
[["EN", "en"], "en", "Duplicate value (canonical last)"], [["EN", "en"], "en", "Duplicate value (canonical last)"],
[{ 0: "DE", length: 0 }, defaultLocale, "Object with zero length"], [{ 0: "DE", length: 0 }, defaultLocale, "Object with zero length"],
[{ 0: "DE", length: 1 }, "de", "Object with length"], [{ 0: "DE", length: 1 }, "de", "Object with length"],
]; ];
for (const [locales, expected, name] of tests) { for (const [locales, expected, name, matchers = ["lookup", "best fit"]] of tests) {
const rtf = new Intl.ListFormat(locales); for (const matcher of matchers) {
assert.sameValue(rtf.resolvedOptions().locale, expected, name); const rtf = new Intl.ListFormat(locales, {localeMatcher: matcher});
assert.sameValue(rtf.resolvedOptions().locale, expected, name);
}
} }
...@@ -43,12 +43,12 @@ assert.sameValue( ...@@ -43,12 +43,12 @@ assert.sameValue(
assert.sameValue( assert.sameValue(
new Intl.Locale('en-u-kn-true', options).toString(), new Intl.Locale('en-u-kn-true', options).toString(),
"en-u-kn-true", "en-u-kn",
'new Intl.Locale("en-u-kn-true", {numeric: undefined}).toString() returns "en-u-kn-true"' 'new Intl.Locale("en-u-kn-true", {numeric: undefined}).toString() returns "en-u-kn"'
); );
assert.sameValue( assert.sameValue(
new Intl.Locale('en-u-kf-lower', options).numeric, new Intl.Locale('en-u-kf-lower', options).numeric,
undefined, false,
'The value of new Intl.Locale("en-u-kf-lower", {numeric: undefined}).numeric equals `undefined`' 'The value of new Intl.Locale("en-u-kf-lower", {numeric: undefined}).numeric equals `false`'
); );
...@@ -46,7 +46,7 @@ const validNumericOptions = [ ...@@ -46,7 +46,7 @@ const validNumericOptions = [
[{ valueOf() { return false; } }, true], [{ valueOf() { return false; } }, true],
]; ];
for (const [numeric, expected] of validNumericOptions) { for (const [numeric, expected] of validNumericOptions) {
let expect = `en-u-kn-${expected}`; let expect = expected ? "en-u-kn" : "en-u-kn-false";
assert.sameValue( assert.sameValue(
new Intl.Locale('en', {numeric}).toString(), new Intl.Locale('en', {numeric}).toString(),
......
...@@ -22,17 +22,17 @@ const testData = [ ...@@ -22,17 +22,17 @@ const testData = [
// Irregular grandfathered tags. // Irregular grandfathered tags.
// "en-GB-oed" is a grandfathered tag, so we can't add "US". After it is // "en-GB-oed" is a grandfathered tag, so we can't add "US". After it is
// canonicalized to "en-GB-oxendict" we can append "u-ca-gregory". // canonicalized to "en-GB-oxendict" we can append "US" and "u-ca-gregory".
{ {
tag: "en-GB-oed", tag: "en-GB-oed",
options: { options: {
region: "US", region: "US",
calendar: "gregory", calendar: "gregory",
}, },
canonical: "en-GB-oxendict-u-ca-gregory", canonical: "en-US-oxendict-u-ca-gregory",
}, },
// Canonicalized version of the above, which we can add "US" to. // Canonicalized version of the above, which we can add "US" to right away.
{ {
tag: "en-GB-oxendict", tag: "en-GB-oxendict",
options: { options: {
...@@ -45,14 +45,14 @@ const testData = [ ...@@ -45,14 +45,14 @@ const testData = [
// Regular grandfathered tags. // Regular grandfathered tags.
// "no-bok" is a grandfathered, so "NO"/"SE" isn't added. After // "no-bok" is a grandfathered, so "NO"/"SE" isn't added. After
// canonicalization we can append "u-ca-gregory". // canonicalization we can append "NO"/"SE" and "u-ca-gregory".
{ {
tag: "no-bok", tag: "no-bok",
options: { options: {
region: "NO", region: "NO",
calendar: "gregory", calendar: "gregory",
}, },
canonical: "nb-u-ca-gregory", canonical: "nb-NO-u-ca-gregory",
}, },
{ {
...@@ -61,7 +61,7 @@ const testData = [ ...@@ -61,7 +61,7 @@ const testData = [
region: "SE", region: "SE",
calendar: "gregory", calendar: "gregory",
}, },
canonical: "nb-u-ca-gregory", canonical: "nb-SE-u-ca-gregory",
}, },
// "no-bok-NO" isn't a grandfathered tag, so we can replace "NO" with "SE" // "no-bok-NO" isn't a grandfathered tag, so we can replace "NO" with "SE"
......
...@@ -33,6 +33,5 @@ const errors = [ ...@@ -33,6 +33,5 @@ const errors = [
for (const input of errors) { for (const input of errors) {
assert.throws(CustomError, function() { assert.throws(CustomError, function() {
new Intl.Locale(input); new Intl.Locale(input);
}, });
`new Intl.Locale(${input}) throws CustomError`);
} }
...@@ -43,13 +43,7 @@ const testData = [ ...@@ -43,13 +43,7 @@ const testData = [
region: "DE", region: "DE",
numberingSystem: "latn", numberingSystem: "latn",
}, },
canonical: "i-default", canonical: "fr-Cyrl-DE-u-nu-latn",
extensions: {
language: undefined,
script: undefined,
region: undefined,
numberingSystem: undefined,
},
}, },
// Irregular grandfathered with modern replacement. // Irregular grandfathered with modern replacement.
...@@ -61,13 +55,7 @@ const testData = [ ...@@ -61,13 +55,7 @@ const testData = [
region: "US", region: "US",
numberingSystem: "latn", numberingSystem: "latn",
}, },
canonical: "en-GB-oxendict-u-nu-latn", canonical: "fr-Cyrl-US-oxendict-u-nu-latn",
extensions: {
language: "en",
script: undefined,
region: "GB",
numberingSystem: "latn",
},
}, },
// Regular grandfathered without modern replacement. // Regular grandfathered without modern replacement.
...@@ -79,13 +67,7 @@ const testData = [ ...@@ -79,13 +67,7 @@ const testData = [
region: "FR", region: "FR",
numberingSystem: "latn", numberingSystem: "latn",
}, },
canonical: "cel-gaulish", canonical: "fr-Cyrl-FR-u-nu-latn",
extensions: {
language: undefined,
script: undefined,
region: undefined,
numberingSystem: undefined,
},
}, },
// Regular grandfathered with modern replacement. // Regular grandfathered with modern replacement.
...@@ -97,21 +79,15 @@ const testData = [ ...@@ -97,21 +79,15 @@ const testData = [
region: "ZZ", region: "ZZ",
numberingSystem: "latn", numberingSystem: "latn",
}, },
canonical: "jbo-u-nu-latn", canonical: "fr-Cyrl-ZZ-u-nu-latn",
extensions: {
language: "jbo",
script: undefined,
region: undefined,
numberingSystem: "latn",
},
}, },
]; ];
for (const {tag, options, canonical, extensions} of testData) { for (const {tag, options, canonical} of testData) {
const loc = new Intl.Locale(tag, options); const loc = new Intl.Locale(tag, options);
assert.sameValue(loc.toString(), canonical); assert.sameValue(loc.toString(), canonical);
for (const [name, value] of Object.entries(extensions)) { for (const [name, value] of Object.entries(options)) {
assert.sameValue(loc[name], value); assert.sameValue(loc[name], value);
} }
} }
...@@ -39,8 +39,8 @@ const loc = new Intl.Locale("x-default", { ...@@ -39,8 +39,8 @@ const loc = new Intl.Locale("x-default", {
region: "DE", region: "DE",
numberingSystem: "latn", numberingSystem: "latn",
}); });
assert.sameValue(loc.toString(), "x-default"); assert.sameValue(loc.toString(), "fr-Cyrl-DE-u-nu-latn");
assert.sameValue(loc.language, undefined); assert.sameValue(loc.language, "fr");
assert.sameValue(loc.script, undefined); assert.sameValue(loc.script, "Cyrl");
assert.sameValue(loc.region, undefined); assert.sameValue(loc.region, "DE");
assert.sameValue(loc.numberingSystem, undefined); assert.sameValue(loc.numberingSystem, "latn");
...@@ -13,7 +13,7 @@ info: | ...@@ -13,7 +13,7 @@ info: |
subsequence of the langtag grammar. subsequence of the langtag grammar.
get Intl.Locale.prototype.language get Intl.Locale.prototype.language
4. If locale matches the privateuse or the grandfathered production, return undefined. 4. If locale matches the privateuse or the grandfathered production, return locale.
get Intl.Locale.prototype.script get Intl.Locale.prototype.script
4. If locale matches the privateuse or the grandfathered production, return undefined. 4. If locale matches the privateuse or the grandfathered production, return undefined.
...@@ -26,20 +26,20 @@ features: [Intl.Locale] ...@@ -26,20 +26,20 @@ features: [Intl.Locale]
// Irregular grandfathered language tag. // Irregular grandfathered language tag.
var loc = new Intl.Locale("i-default"); var loc = new Intl.Locale("i-default");
assert.sameValue(loc.baseName, "i-default"); // Step 4. assert.sameValue(loc.baseName, "i-default"); // Step 4.
assert.sameValue(loc.language, undefined); assert.sameValue(loc.language, "i-default");
assert.sameValue(loc.script, undefined); assert.sameValue(loc.script, undefined);
assert.sameValue(loc.region, undefined); assert.sameValue(loc.region, undefined);
// Regular grandfathered language tag. // Regular grandfathered language tag.
var loc = new Intl.Locale("cel-gaulish"); var loc = new Intl.Locale("cel-gaulish");
assert.sameValue(loc.baseName, "cel-gaulish"); // Step 5. assert.sameValue(loc.baseName, "cel-gaulish"); // Step 5.
assert.sameValue(loc.language, undefined); assert.sameValue(loc.language, "cel-gaulish");
assert.sameValue(loc.script, undefined); assert.sameValue(loc.script, undefined);
assert.sameValue(loc.region, undefined); assert.sameValue(loc.region, undefined);
// Regular grandfathered language tag. // Regular grandfathered language tag.
var loc = new Intl.Locale("zh-min"); var loc = new Intl.Locale("zh-min");
assert.sameValue(loc.baseName, "zh-min"); // Step 5. assert.sameValue(loc.baseName, "zh-min"); // Step 5.
assert.sameValue(loc.language, undefined); assert.sameValue(loc.language, "zh-min");
assert.sameValue(loc.script, undefined); assert.sameValue(loc.script, undefined);
assert.sameValue(loc.region, undefined); assert.sameValue(loc.region, undefined);
...@@ -10,7 +10,7 @@ info: | ...@@ -10,7 +10,7 @@ info: |
4. If locale does not match the langtag production, return locale. 4. If locale does not match the langtag production, return locale.
get Intl.Locale.prototype.language get Intl.Locale.prototype.language
4. If locale matches the privateuse or the grandfathered production, return undefined. 4. If locale matches the privateuse or the grandfathered production, return locale.
get Intl.Locale.prototype.script get Intl.Locale.prototype.script
4. If locale matches the privateuse or the grandfathered production, return undefined. 4. If locale matches the privateuse or the grandfathered production, return undefined.
...@@ -23,6 +23,6 @@ features: [Intl.Locale] ...@@ -23,6 +23,6 @@ features: [Intl.Locale]
// Privateuse only language tag. // Privateuse only language tag.
var loc = new Intl.Locale("x-private"); var loc = new Intl.Locale("x-private");
assert.sameValue(loc.baseName, "x-private"); assert.sameValue(loc.baseName, "x-private");
assert.sameValue(loc.language, undefined); assert.sameValue(loc.language, "x-private");
assert.sameValue(loc.script, undefined); assert.sameValue(loc.script, undefined);
assert.sameValue(loc.region, undefined); assert.sameValue(loc.region, undefined);
...@@ -50,7 +50,7 @@ features: [Intl.Locale] ...@@ -50,7 +50,7 @@ features: [Intl.Locale]
var langtag = "de-latn-de-u-ca-gregory-co-phonebk-hc-h23-kf-true-kn-false-nu-latn"; var langtag = "de-latn-de-u-ca-gregory-co-phonebk-hc-h23-kf-true-kn-false-nu-latn";
var loc = new Intl.Locale(langtag); var loc = new Intl.Locale(langtag);
assert.sameValue(loc.toString(), "de-Latn-DE-u-ca-gregory-co-phonebk-hc-h23-kf-true-kn-false-nu-latn"); assert.sameValue(loc.toString(), "de-Latn-DE-u-ca-gregory-co-phonebk-hc-h23-kf-kn-false-nu-latn");
assert.sameValue(loc.baseName, "de-Latn-DE"); assert.sameValue(loc.baseName, "de-Latn-DE");
assert.sameValue(loc.language, "de"); assert.sameValue(loc.language, "de");
assert.sameValue(loc.script, "Latn"); assert.sameValue(loc.script, "Latn");
...@@ -80,7 +80,7 @@ var loc = new Intl.Locale(langtag, { ...@@ -80,7 +80,7 @@ var loc = new Intl.Locale(langtag, {
numberingSystem: "jpanfin", numberingSystem: "jpanfin",
}); });
assert.sameValue(loc.toString(), "ja-Jpan-JP-u-ca-japanese-co-search-hc-h24-kf-false-kn-true-nu-jpanfin"); assert.sameValue(loc.toString(), "ja-Jpan-JP-u-ca-japanese-co-search-hc-h24-kf-false-kn-nu-jpanfin");
assert.sameValue(loc.baseName, "ja-Jpan-JP"); assert.sameValue(loc.baseName, "ja-Jpan-JP");
assert.sameValue(loc.language, "ja"); assert.sameValue(loc.language, "ja");
assert.sameValue(loc.script, "Jpan"); assert.sameValue(loc.script, "Jpan");
...@@ -105,7 +105,7 @@ var loc = new Intl.Locale(langtag, { ...@@ -105,7 +105,7 @@ var loc = new Intl.Locale(langtag, {
hourCycle: "h11", hourCycle: "h11",
}); });
assert.sameValue(loc.toString(), "fr-Latn-CA-u-ca-gregory-co-standard-hc-h11-kf-true-kn-false-nu-latn"); assert.sameValue(loc.toString(), "fr-Latn-CA-u-ca-gregory-co-standard-hc-h11-kf-kn-false-nu-latn");
assert.sameValue(loc.baseName, "fr-Latn-CA"); assert.sameValue(loc.baseName, "fr-Latn-CA");
assert.sameValue(loc.language, "fr"); assert.sameValue(loc.language, "fr");
assert.sameValue(loc.script, "Latn"); assert.sameValue(loc.script, "Latn");
......
...@@ -9,7 +9,7 @@ description: > ...@@ -9,7 +9,7 @@ description: >
---*/ ---*/
const actual = new Intl.NumberFormat().resolvedOptions(); const actual = new Intl.NumberFormat().resolvedOptions();
const expected = new Intl.NumberFormat([], { __proto__: null }).resolvedOptions(); const expected = new Intl.NumberFormat([], Object.create(null)).resolvedOptions();
assert.sameValue(actual.locale, expected.locale); assert.sameValue(actual.locale, expected.locale);
assert.sameValue(actual.minimumIntegerDigits, expected.minimumIntegerDigits); assert.sameValue(actual.minimumIntegerDigits, expected.minimumIntegerDigits);
......
...@@ -14,7 +14,11 @@ var nf = new Intl.NumberFormat(); ...@@ -14,7 +14,11 @@ var nf = new Intl.NumberFormat();
const implicit = nf.formatToParts(); const implicit = nf.formatToParts();
const explicit = nf.formatToParts(undefined); const explicit = nf.formatToParts(undefined);
const result = [{ type: 'nan', value: 'NaN' }];
// In most locales this is string "NaN", but there are exceptions, cf. "ليس رقم"
// in Arabic, "epäluku" in Finnish, "не число" in Russian, "son emas" in Uzbek etc.
const resultNaN = nf.format(NaN);
const result = [{ type: 'nan', value: resultNaN }];
assert( assert(
partsEquals(implicit, explicit), partsEquals(implicit, explicit),
......
...@@ -24,15 +24,23 @@ const toNumberResults = [ ...@@ -24,15 +24,23 @@ const toNumberResults = [
const nf = new Intl.NumberFormat(); const nf = new Intl.NumberFormat();
function assertSameParts(actual, expected) {
assert.sameValue(actual.length, expected.length);
for (let i = 0; i < expected.length; ++i) {
assert.sameValue(actual[i].type, expected[i].type);
assert.sameValue(actual[i].value, expected[i].value);
}
}
toNumberResults.forEach(pair => { toNumberResults.forEach(pair => {
const [value, result] = pair; const [value, result] = pair;
assert.sameValue(nf.formatToParts(value), nf.formatToParts(result)); assertSameParts(nf.formatToParts(value), nf.formatToParts(result));
}); });
let count = 0; let count = 0;
const dummy = {}; const dummy = {};
dummy[Symbol.toPrimitive] = hint => (hint === 'number' ? ++count : NaN); dummy[Symbol.toPrimitive] = hint => (hint === 'number' ? ++count : NaN);
assert.sameValue(nf.formatToParts(dummy), nf.formatToParts(count)); assertSameParts(nf.formatToParts(dummy), nf.formatToParts(count));
assert.sameValue(count, 1); assert.sameValue(count, 1);
assert.throws( assert.throws(
......
...@@ -18,14 +18,16 @@ const tests = [ ...@@ -18,14 +18,16 @@ const tests = [
["EN", "en", "Single value"], ["EN", "en", "Single value"],
[[], defaultLocale, "Empty array"], [[], defaultLocale, "Empty array"],
[["en-GB-oed"], "en-GB", "Grandfathered"], [["en-GB-oed"], "en-GB", "Grandfathered"],
[["x-private"], defaultLocale, "Private"], [["x-private"], defaultLocale, "Private", ["lookup"]],
[["en", "EN"], "en", "Duplicate value (canonical first)"], [["en", "EN"], "en", "Duplicate value (canonical first)"],
[["EN", "en"], "en", "Duplicate value (canonical last)"], [["EN", "en"], "en", "Duplicate value (canonical last)"],
[{ 0: "DE", length: 0 }, defaultLocale, "Object with zero length"], [{ 0: "DE", length: 0 }, defaultLocale, "Object with zero length"],
[{ 0: "DE", length: 1 }, "de", "Object with length"], [{ 0: "DE", length: 1 }, "de", "Object with length"],
]; ];
for (const [locales, expected, name] of tests) { for (const [locales, expected, name, matchers = ["best fit", "lookup"]] of tests) {
const rtf = new Intl.RelativeTimeFormat(locales); for (const matcher of matchers) {
assert.sameValue(rtf.resolvedOptions().locale, expected, name); const rtf = new Intl.RelativeTimeFormat(locales, {localeMatcher: matcher});
assert.sameValue(rtf.resolvedOptions().locale, expected, name);
}
} }
...@@ -20,13 +20,14 @@ features: [dynamic-import] ...@@ -20,13 +20,14 @@ features: [dynamic-import]
var global = fnGlobalObject(); var global = fnGlobalObject();
if (typeof global.evaluated === 'undefined') { var isFirstScript = typeof global.evaluated === 'undefined';
if (isFirstScript) {
global.evaluated = 0; global.evaluated = 0;
} }
global.evaluated++; global.evaluated++;
Promise.all([ var p = Promise.all([
import('./eval-self-once-script.js'), import('./eval-self-once-script.js'),
import('./eval-self-once-script.js'), import('./eval-self-once-script.js'),
]).then(async () => { ]).then(async () => {
...@@ -34,5 +35,9 @@ Promise.all([ ...@@ -34,5 +35,9 @@ Promise.all([
await import('./eval-self-once-script.js'); await import('./eval-self-once-script.js');
await import('./eval-self-once-script.js'); await import('./eval-self-once-script.js');
assert.sameValue(global.evaluated, 2, 'global property was defined and incremented only once'); assert.sameValue(global.evaluated, 2, 'global property was defined once and incremented twice');
}).then($DONE, $DONE); });
if (isFirstScript) {
p.then($DONE, $DONE);
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment