Skip to content

Test removal of default locale fallback in Intl.Locale.p.getCollations - #5092

Closed
ptomato wants to merge 0 commit into
tc39:mainfrom
ptomato:ecma402-1072-collation-no-default-locale-fallback
Closed

Test removal of default locale fallback in Intl.Locale.p.getCollations#5092
ptomato wants to merge 0 commit into
tc39:mainfrom
ptomato:ecma402-1072-collation-no-default-locale-fallback

Conversation

@ptomato

@ptomato ptomato commented Jul 23, 2026

Copy link
Copy Markdown
Member

This PR adds baseline tests for the return value of Intl.Locale.p.getCollations() reflecting the situation before normative PR tc39/ecma402#1072 in the first commit, and in the second commit makes the necessary changes for the normative PR.

Note that because the default locale is out-of-band, und-locale.js might pass or fail if the normative change is not implemented, depending on what the environment's default locale is. It should always pass regardless of the environment's default locale if the normative change is implemented correctly. Try running it with LC_ALL=de in the environment, for example.

@ptomato
ptomato requested a review from a team as a code owner July 23, 2026 00:30
@ptomato
ptomato force-pushed the ecma402-1072-collation-no-default-locale-fallback branch 2 times, most recently from 8e43347 to fc0cf63 Compare July 23, 2026 00:34
@ptomato

ptomato commented Jul 23, 2026

Copy link
Copy Markdown
Member Author

Note JSC fails output-array-sorted.js.

Comment on lines +17 to +37
const testCases = [
["en", "phonebk"],
["de", "phonebk"],
["zh", "stroke"],
["und", "pinyin"],
["und", "emoji"],
];

for (const [tag, collation] of testCases) {
assert.compareArray(
new Intl.Locale(`${tag}-u-co-${collation}`).getCollations(),
[collation],
`getCollations() for ${tag}-u-co-${collation} returns only ${collation}`
);

assert.compareArray(
new Intl.Locale(tag, { collation }).getCollations(),
[collation],
`getCollations() for ${tag} with { collation: "${collation}" } returns only ${collation}`
);
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
const testCases = [
["en", "phonebk"],
["de", "phonebk"],
["zh", "stroke"],
["und", "pinyin"],
["und", "emoji"],
];
for (const [tag, collation] of testCases) {
assert.compareArray(
new Intl.Locale(`${tag}-u-co-${collation}`).getCollations(),
[collation],
`getCollations() for ${tag}-u-co-${collation} returns only ${collation}`
);
assert.compareArray(
new Intl.Locale(tag, { collation }).getCollations(),
[collation],
`getCollations() for ${tag} with { collation: "${collation}" } returns only ${collation}`
);
}
var testCases = [
["en", "phonebk"],
["de", "phonebk"],
["zh", "stroke"],
["und", "pinyin"],
["und", "emoji"]
];
for (var i = 0; i < testCases.length; i++) {
var baseName = testCases[i][0];
var collation = testCases[i][1];
var fullTag = baseName + "-u-co-" + collation;
assert.compareArray(
new Intl.Locale(fullTag).getCollations(),
[collation],
"getCollations() for " + fullTag + " returns only " + collation
);
assert.compareArray(
new Intl.Locale(tag, { collation: collation }).getCollations(),
[collation],
"getCollations() for " + tag + " with { collation: " + collation + " } returns only " + collation
);
}

Comment on lines +17 to +24
for (const tag of ["ar", "de", "en", "ja", "ko", "sv", "tr", "zh"]) {
const collations = new Intl.Locale(tag).getCollations();
assert.compareArray(
collations,
collations.toSorted(),
`getCollations() for ${tag} should be sorted in lexicographic code unit order`
);
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
for (const tag of ["ar", "de", "en", "ja", "ko", "sv", "tr", "zh"]) {
const collations = new Intl.Locale(tag).getCollations();
assert.compareArray(
collations,
collations.toSorted(),
`getCollations() for ${tag} should be sorted in lexicographic code unit order`
);
}
var tags = ["ar", "de", "en", "ja", "ko", "sv", "tr", "zh"];
for (var i = 0; i < tags.length; i++) {
var tag = tags[i];
var collations = new Intl.Locale(tag).getCollations();
var sortedCollations = new Intl.Locale(tag).getCollations().sort();
assert.compareArray(
sortedCollations,
collations,
"getCollations() for " + tag + " should be sorted in lexicographic code unit order"
);
}

Comment on lines +16 to +21
for (const tag of ["ar", "de", "en", "ja", "ko", "sv", "tr", "zh"]) {
const output = new Intl.Locale(tag).getCollations();
assert.notSameValue(output.length, 0, `getCollations() for ${tag} has at least one element`);
assert(!output.includes("standard"), `getCollations() for ${tag} should not contain 'standard'`);
assert(!output.includes("search"), `getCollations() for ${tag} should not contain 'search'`);
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
for (const tag of ["ar", "de", "en", "ja", "ko", "sv", "tr", "zh"]) {
const output = new Intl.Locale(tag).getCollations();
assert.notSameValue(output.length, 0, `getCollations() for ${tag} has at least one element`);
assert(!output.includes("standard"), `getCollations() for ${tag} should not contain 'standard'`);
assert(!output.includes("search"), `getCollations() for ${tag} should not contain 'search'`);
}
var tags = ["ar", "de", "en", "ja", "ko", "sv", "tr", "zh"];
for (var i = 0; i < tags.length; i++) {
var tag = tags[i];
var collations = new Intl.Locale(tag).getCollations();
assert.notSameValue(collations.length, 0,
"getCollations() for " + tag + " has at least one element");
for (var j = 0; j < collations.length; j++) {
assert.notSameValue(collations[j], "standard",
"getCollations() for " + tag + " must not contain 'standard'");
assert.notSameValue(collations[j], "search",
"getCollations() for " + tag + " must not contain 'search'");
}
}

Comment on lines +15 to +20
for (const tag of ["ar", "de", "en", "ja", "ko", "sv", "tr", "zh"]) {
assert(
Array.isArray(new Intl.Locale(tag).getCollations()),
`getCollations() for ${tag} should return an array`,
);
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
for (const tag of ["ar", "de", "en", "ja", "ko", "sv", "tr", "zh"]) {
assert(
Array.isArray(new Intl.Locale(tag).getCollations()),
`getCollations() for ${tag} should return an array`,
);
}
var tags = ["ar", "de", "en", "ja", "ko", "sv", "tr", "zh"];
for (var i = 0; i < tags.length; i++) {
var tag = tags[i];
assert(
Array.isArray(new Intl.Locale(tag).getCollations()),
"getCollations() for " + tag + " must return an array"
);
}

Comment on lines +20 to +41
const undLocales = [
"und",
"und-US",
"und-Latn",
"und-Latn-US",
"und-u-ca-gregory",
"und-US-u-nu-latn",
];

for (const tag of undLocales) {
const locale = new Intl.Locale(tag);
assert.sameValue(
locale.language,
"und",
`"${tag}" has language subtag "und"`
);
assert.compareArray(
locale.getCollations(),
["emoji", "eor"],
`getCollations() for "${tag}" returns the root collations`
);
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
const undLocales = [
"und",
"und-US",
"und-Latn",
"und-Latn-US",
"und-u-ca-gregory",
"und-US-u-nu-latn",
];
for (const tag of undLocales) {
const locale = new Intl.Locale(tag);
assert.sameValue(
locale.language,
"und",
`"${tag}" has language subtag "und"`
);
assert.compareArray(
locale.getCollations(),
["emoji", "eor"],
`getCollations() for "${tag}" returns the root collations`
);
}
var undLocales = [
"und",
"und-US",
"und-Latn",
"und-Latn-US",
"und-u-ca-gregory",
"und-US-u-nu-latn",
];
for (var i = 0; i < undLocales.length; i++) {
var tag = undLocales[i];
var locale = new Intl.Locale(tag);
assert.sameValue(
locale.language,
"und",
tag + " must have language subtag 'und'"
);
assert.compareArray(
locale.getCollations(),
["emoji", "eor"],
"getCollations() for " + tag + " must return the root collations"
);
}

Comment on lines +55 to +61
for (const tag of ["qfz", "qga-DE", "qgb-ES", "qgc-KR", "qtz-CN"]) {
assert.compareArray(
new Intl.Locale(tag).getCollations(),
["emoji", "eor"],
`getCollations() for unavailable locale "${tag}" returns the root collations`
);
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
for (const tag of ["qfz", "qga-DE", "qgb-ES", "qgc-KR", "qtz-CN"]) {
assert.compareArray(
new Intl.Locale(tag).getCollations(),
["emoji", "eor"],
`getCollations() for unavailable locale "${tag}" returns the root collations`
);
}
var privateUseTags = ["qfz", "qga-DE", "qgb-ES", "qgc-KR", "qtz-CN"];
for (var i = 0; i < privateUseTags.length; i++) {
var tag = privateUseTags[i];
assert.compareArray(
new Intl.Locale(tag).getCollations(),
["emoji", "eor"],
"getCollations() for unavailable locale " + tag + " must return the root collations"
);
}

@gibson042 gibson042 closed this Jul 23, 2026
@gibson042
gibson042 force-pushed the ecma402-1072-collation-no-default-locale-fallback branch from 1f90090 to 9e61c12 Compare July 23, 2026 18:59
@ptomato
ptomato deleted the ecma402-1072-collation-no-default-locale-fallback branch July 27, 2026 22:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants