Skip to content

Commit

Permalink
Fix various test issues
Browse files Browse the repository at this point in the history
  • Loading branch information
anba committed Oct 17, 2018
1 parent 2ac5f17 commit faed4fb
Show file tree
Hide file tree
Showing 16 changed files with 74 additions and 77 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ var o = {
return {
toString() {
calls.push('flags toString');
return "";
}
};
},
Expand All @@ -50,7 +51,7 @@ RegExp.prototype[Symbol.matchAll].call(o, {
assert.sameValue(0, internalCount);

assert.sameValue(calls.length, 4);
assert.sameValue(calls[0], 'get @@match');
assert.sameValue(calls[1], 'arg toString');
assert.sameValue(calls[2], 'get flags');
assert.sameValue(calls[3], 'flags toString');
assert.sameValue(calls[0], 'arg toString');
assert.sameValue(calls[1], 'get flags');
assert.sameValue(calls[2], 'flags toString');
assert.sameValue(calls[3], 'get @@match');
10 changes: 6 additions & 4 deletions test/intl402/ListFormat/constructor/constructor/locales-valid.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,16 @@ const tests = [
["EN", "en", "Single value"],
[[], defaultLocale, "Empty array"],
[["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 last)"],
[{ 0: "DE", length: 0 }, defaultLocale, "Object with zero length"],
[{ 0: "DE", length: 1 }, "de", "Object with length"],
];

for (const [locales, expected, name] of tests) {
const rtf = new Intl.ListFormat(locales);
assert.sameValue(rtf.resolvedOptions().locale, expected, name);
for (const [locales, expected, name, matchers = ["lookup", "best fit"]] of tests) {
for (const matcher of matchers) {
const rtf = new Intl.ListFormat(locales, {localeMatcher: matcher});
assert.sameValue(rtf.resolvedOptions().locale, expected, name);
}
}
8 changes: 4 additions & 4 deletions test/intl402/Locale/constructor-options-numeric-undefined.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ assert.sameValue(

assert.sameValue(
new Intl.Locale('en-u-kn-true', options).toString(),
"en-u-kn-true",
'new Intl.Locale("en-u-kn-true", {numeric: undefined}).toString() returns "en-u-kn-true"'
"en-u-kn",
'new Intl.Locale("en-u-kn-true", {numeric: undefined}).toString() returns "en-u-kn"'
);

assert.sameValue(
new Intl.Locale('en-u-kf-lower', options).numeric,
undefined,
'The value of new Intl.Locale("en-u-kf-lower", {numeric: undefined}).numeric equals `undefined`'
false,
'The value of new Intl.Locale("en-u-kf-lower", {numeric: undefined}).numeric equals `false`'
);
2 changes: 1 addition & 1 deletion test/intl402/Locale/constructor-options-numeric-valid.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const validNumericOptions = [
[{ valueOf() { return false; } }, true],
];
for (const [numeric, expected] of validNumericOptions) {
let expect = `en-u-kn-${expected}`;
let expect = expected ? "en-u-kn" : "en-u-kn-false";

assert.sameValue(
new Intl.Locale('en', {numeric}).toString(),
Expand Down
12 changes: 6 additions & 6 deletions test/intl402/Locale/constructor-parse-twice.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,17 @@ const testData = [
// Irregular grandfathered tags.

// "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",
options: {
region: "US",
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",
options: {
Expand All @@ -45,14 +45,14 @@ const testData = [
// Regular grandfathered tags.

// "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",
options: {
region: "NO",
calendar: "gregory",
},
canonical: "nb-u-ca-gregory",
canonical: "nb-NO-u-ca-gregory",
},

{
Expand All @@ -61,7 +61,7 @@ const testData = [
region: "SE",
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"
Expand Down
3 changes: 1 addition & 2 deletions test/intl402/Locale/constructor-tag-tostring.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,5 @@ const errors = [
for (const input of errors) {
assert.throws(CustomError, function() {
new Intl.Locale(input);
},
`new Intl.Locale(${input}) throws CustomError`);
});
}
36 changes: 6 additions & 30 deletions test/intl402/Locale/extensions-grandfathered.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,7 @@ const testData = [
region: "DE",
numberingSystem: "latn",
},
canonical: "i-default",
extensions: {
language: undefined,
script: undefined,
region: undefined,
numberingSystem: undefined,
},
canonical: "fr-Cyrl-DE-u-nu-latn",
},

// Irregular grandfathered with modern replacement.
Expand All @@ -61,13 +55,7 @@ const testData = [
region: "US",
numberingSystem: "latn",
},
canonical: "en-GB-oxendict-u-nu-latn",
extensions: {
language: "en",
script: undefined,
region: "GB",
numberingSystem: "latn",
},
canonical: "fr-Cyrl-US-oxendict-u-nu-latn",
},

// Regular grandfathered without modern replacement.
Expand All @@ -79,13 +67,7 @@ const testData = [
region: "FR",
numberingSystem: "latn",
},
canonical: "cel-gaulish",
extensions: {
language: undefined,
script: undefined,
region: undefined,
numberingSystem: undefined,
},
canonical: "fr-Cyrl-FR-u-nu-latn",
},

// Regular grandfathered with modern replacement.
Expand All @@ -97,21 +79,15 @@ const testData = [
region: "ZZ",
numberingSystem: "latn",
},
canonical: "jbo-u-nu-latn",
extensions: {
language: "jbo",
script: undefined,
region: undefined,
numberingSystem: "latn",
},
canonical: "fr-Cyrl-ZZ-u-nu-latn",
},
];

for (const {tag, options, canonical, extensions} of testData) {
for (const {tag, options, canonical} of testData) {
const loc = new Intl.Locale(tag, options);
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);
}
}
10 changes: 5 additions & 5 deletions test/intl402/Locale/extensions-private.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ const loc = new Intl.Locale("x-default", {
region: "DE",
numberingSystem: "latn",
});
assert.sameValue(loc.toString(), "x-default");
assert.sameValue(loc.language, undefined);
assert.sameValue(loc.script, undefined);
assert.sameValue(loc.region, undefined);
assert.sameValue(loc.numberingSystem, undefined);
assert.sameValue(loc.toString(), "fr-Cyrl-DE-u-nu-latn");
assert.sameValue(loc.language, "fr");
assert.sameValue(loc.script, "Cyrl");
assert.sameValue(loc.region, "DE");
assert.sameValue(loc.numberingSystem, "latn");
8 changes: 4 additions & 4 deletions test/intl402/Locale/getters-grandfathered.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ info: |
subsequence of the langtag grammar.
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
4. If locale matches the privateuse or the grandfathered production, return undefined.
Expand All @@ -26,20 +26,20 @@ features: [Intl.Locale]
// Irregular grandfathered language tag.
var loc = new Intl.Locale("i-default");
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.region, undefined);

// Regular grandfathered language tag.
var loc = new Intl.Locale("cel-gaulish");
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.region, undefined);

// Regular grandfathered language tag.
var loc = new Intl.Locale("zh-min");
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.region, undefined);
4 changes: 2 additions & 2 deletions test/intl402/Locale/getters-privateuse.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ info: |
4. If locale does not match the langtag production, return locale.
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
4. If locale matches the privateuse or the grandfathered production, return undefined.
Expand All @@ -23,6 +23,6 @@ features: [Intl.Locale]
// Privateuse only language tag.
var loc = new Intl.Locale("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.region, undefined);
6 changes: 3 additions & 3 deletions test/intl402/Locale/getters.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 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.language, "de");
assert.sameValue(loc.script, "Latn");
Expand Down Expand Up @@ -80,7 +80,7 @@ var loc = new Intl.Locale(langtag, {
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.language, "ja");
assert.sameValue(loc.script, "Jpan");
Expand All @@ -105,7 +105,7 @@ var loc = new Intl.Locale(langtag, {
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.language, "fr");
assert.sameValue(loc.script, "Latn");
Expand Down
2 changes: 1 addition & 1 deletion test/intl402/NumberFormat/constructor-default-value.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ description: >
---*/

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.minimumIntegerDigits, expected.minimumIntegerDigits);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ var nf = new Intl.NumberFormat();

const implicit = nf.formatToParts();
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(
partsEquals(implicit, explicit),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,23 @@ const toNumberResults = [

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 => {
const [value, result] = pair;
assert.sameValue(nf.formatToParts(value), nf.formatToParts(result));
assertSameParts(nf.formatToParts(value), nf.formatToParts(result));
});

let count = 0;
const dummy = {};
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.throws(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,16 @@ const tests = [
["EN", "en", "Single value"],
[[], defaultLocale, "Empty array"],
[["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 last)"],
[{ 0: "DE", length: 0 }, defaultLocale, "Object with zero length"],
[{ 0: "DE", length: 1 }, "de", "Object with length"],
];

for (const [locales, expected, name] of tests) {
const rtf = new Intl.RelativeTimeFormat(locales);
assert.sameValue(rtf.resolvedOptions().locale, expected, name);
for (const [locales, expected, name, matchers = ["best fit", "lookup"]] of tests) {
for (const matcher of matchers) {
const rtf = new Intl.RelativeTimeFormat(locales, {localeMatcher: matcher});
assert.sameValue(rtf.resolvedOptions().locale, expected, name);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,24 @@ features: [dynamic-import]

var global = fnGlobalObject();

if (typeof global.evaluated === 'undefined') {
var isFirstScript = typeof global.evaluated === 'undefined';
if (isFirstScript) {
global.evaluated = 0;
}

global.evaluated++;

Promise.all([
var p = Promise.all([
import('./eval-self-once-script.js'),
import('./eval-self-once-script.js'),
]).then(async () => {
// Use await to serialize imports
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');
}).then($DONE, $DONE);
assert.sameValue(global.evaluated, 2, 'global property was defined once and incremented twice');
});

if (isFirstScript) {
p.then($DONE, $DONE);
}

1 comment on commit faed4fb

@FrankYFTang
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I disagree the change in
test/intl402/Locale/getters.js
test/intl402/Locale/constructor-options-numeric-valid.js
test/intl402/Locale/constructor-options-numeric-undefined.js
"kf-true" => "kf"
"kn-true" => "kn"

Please sign in to comment.