Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Copyright 2026 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-Intl.Locale.prototype.getCollations
description: >
u-co extension keyword and collation option override language lookup
info: |
CollationsOfLocale ( loc )

1. If _loc_.[[Collation]] is not *undefined*, then
a. Return CreateArrayFromList(« _loc_.[[Collation]] »).
features: [Intl.Locale,Intl.Locale-info]
locale: [en, de, zh]
---*/

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(baseName, { collation: collation }).getCollations(),
[collation],
"getCollations() for " + baseName + " with { collation: " + collation + " } returns only " + collation
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright 2026 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-Intl.Locale.prototype.getCollations
description: The returned array is sorted in lexicographic code unit order
info: |
CollationsOfLocale ( loc )

5. Let _sorted_ be a copy of _list_, sorted according to lexicographic code
unit order.
6. Return CreateArrayFromList(_sorted_).
features: [Intl.Locale,Intl.Locale-info]
locale: [ar, de, en, ja, ko, sv, tr, zh]
---*/

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 = [].concat(new Intl.Locale(tag).getCollations()).sort();
assert.compareArray(
collations,
sortedCollations,
"getCollations() for " + tag + " should be sorted in lexicographic code unit order"
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,27 @@

/*---
esid: sec-intl.locale.prototype.collations
description: >
Checks that the return value of Intl.Locale.prototype.collations is an Array
that does not contain invalid values.
description: The return value does not contain invalid values
info: |
CollationsOfLocale ( loc )
...
4. Let list be a List of 1 or more unique collation identifiers, which must
be lower case String values conforming to the type sequence from UTS 35
Unicode Locale Identifier, section 3.2, sorted in descending preference of
those in common use for string comparison in locale. The values "standard"
and "search" must be excluded from list.
10.2.3 Internal Slots
- The values *"standard"* and *"search"* must not be used as elements in any
[[SortLocaleData]].[[<locale>]].[[co]] and
[[SearchLocaleData]].[[<locale>]].[[co]] List.
features: [Intl.Locale, Intl.Locale-info, Array.prototype.includes]
locale: [ar, de, en, ja, ko, sv, tr, zh]
---*/

const output = new Intl.Locale('en').getCollations();
assert(output.length > 0, 'array has at least one element');
output.forEach(c => {
if(['standard', 'search'].includes(c))
throw new Test262Error();
});
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'");
}
}
16 changes: 12 additions & 4 deletions test/intl402/Locale/prototype/getCollations/output-array.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,21 @@

/*---
esid: sec-intl.locale.prototype.getCollations
description: >
Checks that the return value of Intl.Locale.prototype.getCollations is an Array.
description: The return value is an Array
info: |
CollationsOfLocale ( loc )
...
5. Return ! CreateArrayFromListAndPreferred( list, preferred ).
6. Return CreateArrayFromList(_sorted_).
features: [Intl.Locale,Intl.Locale-info]
locale: [ar, de, en, ja, ko, sv, tr, zh]
---*/

assert(Array.isArray(new Intl.Locale('en').getCollations()));
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"
);
}
65 changes: 65 additions & 0 deletions test/intl402/Locale/prototype/getCollations/und-language.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// Copyright 2026 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-Intl.Locale.prototype.getCollations
description: >
Return value for tags not matching any available locale is hardcoded in spec
info: |
CollationsOfLocale ( loc )

2. Let _match_ be LookupMatchingLocaleByPrefix(
%Intl.Collator%.[[AvailableLocales]], « _loc_.[[Locale]] »).
3. If _match_ is not *undefined*, then
...
4. Else,
a. Let _list_ be « *"emoji"*, *"eor"* ».
features: [Intl.Locale,Intl.Locale-info]
---*/

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"
);
}

// Unreserved private-use language subtags (qfz..qtz) are guaranteed to have no
// semantics in any CLDR release, so we assume they will fall back to the
// hardcoded root collations.
// https://www.unicode.org/reports/tr35/tr35.html#Private_Use_Codes
//
// Note regarding normative change https://github.com/tc39/ecma402/pull/1072:
// this test 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.

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"
);
}
Loading