From 36d22d82aa202bb199967e9512281e9a53db42c9 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 21:33:14 +0200 Subject: Adding upstream version 115.7.0esr. Signed-off-by: Daniel Baumann --- js/src/tests/non262/Intl/Collator/collation.js | 90 ++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 js/src/tests/non262/Intl/Collator/collation.js (limited to 'js/src/tests/non262/Intl/Collator/collation.js') diff --git a/js/src/tests/non262/Intl/Collator/collation.js b/js/src/tests/non262/Intl/Collator/collation.js new file mode 100644 index 0000000000..f73728b876 --- /dev/null +++ b/js/src/tests/non262/Intl/Collator/collation.js @@ -0,0 +1,90 @@ +// |reftest| skip-if(!this.hasOwnProperty("Intl")) + +// Collation can be set as Unicode locale extension or as a property. +{ + let c1 = new Intl.Collator("de", {usage: "sort"}); + let c2 = new Intl.Collator("de", {usage: "sort", collation: "phonebk"}); + let c3 = new Intl.Collator("de-u-co-phonebk", {usage: "sort"}); + + assertEq(c1.resolvedOptions().locale, "de"); + assertEq(c2.resolvedOptions().locale, "de"); + assertEq(c3.resolvedOptions().locale, "de-u-co-phonebk"); + + assertEq(c1.resolvedOptions().collation, "default"); + assertEq(c2.resolvedOptions().collation, "phonebk"); + assertEq(c3.resolvedOptions().collation, "phonebk"); + + assertEq(c1.compare("ä", "ae"), -1); + assertEq(c2.compare("ä", "ae"), 1); + assertEq(c3.compare("ä", "ae"), 1); +} + +// Collation property overrides any Unicode locale extension. +{ + let c1 = new Intl.Collator("de-u-co-eor", {usage: "sort"}); + let c2 = new Intl.Collator("de-u-co-eor", {usage: "sort", collation: "phonebk"}); + + // Ensure "eor" collation is supported. + assertEq(c1.resolvedOptions().locale, "de-u-co-eor"); + assertEq(c1.resolvedOptions().collation, "eor"); + + // "phonebk" property overrides the Unicode locale extension. + assertEq(c2.resolvedOptions().locale, "de"); + assertEq(c2.resolvedOptions().collation, "phonebk"); + + assertEq(c1.compare("ä", "ae"), -1); + assertEq(c2.compare("ä", "ae"), 1); +} + +// The default sort collation can't be requested. +{ + // The default sort collation for Swedish (sv) was "reformed" before CLDR 42. + // It wasn't possible to override this and select the default root sort + // collation. Use English (en) as a locale which uses the root sort collation + // for comparison. + let c1 = new Intl.Collator("sv", {usage: "sort"}); + let c2 = new Intl.Collator("sv-u-co-reformed", {usage: "sort"}); + let c3 = new Intl.Collator("sv-u-co-standard", {usage: "sort"}); + let c4 = new Intl.Collator("sv-u-co-default", {usage: "sort"}); + let c5 = new Intl.Collator("en", {usage: "sort"}); + + assertEq(c1.resolvedOptions().locale, "sv"); + assertEq(c2.resolvedOptions().locale, "sv"); + assertEq(c3.resolvedOptions().locale, "sv"); + assertEq(c4.resolvedOptions().locale, "sv"); + assertEq(c5.resolvedOptions().locale, "en"); + + assertEq(c1.resolvedOptions().collation, "default"); + assertEq(c2.resolvedOptions().collation, "default"); + assertEq(c3.resolvedOptions().collation, "default"); + assertEq(c4.resolvedOptions().collation, "default"); + assertEq(c5.resolvedOptions().collation, "default"); + + assertEq(c1.compare("y", "ü"), -1); + assertEq(c2.compare("y", "ü"), -1); + assertEq(c3.compare("y", "ü"), -1); + assertEq(c4.compare("y", "ü"), -1); + assertEq(c5.compare("y", "ü"), 1); +} + +// Search collations ignore any collation overrides. +{ + let c1 = new Intl.Collator("de", {usage: "search"}); + let c2 = new Intl.Collator("de", {usage: "search", collation: "phonebk"}); + let c3 = new Intl.Collator("de-u-co-phonebk", {usage: "search"}); + + assertEq(c1.resolvedOptions().locale, "de"); + assertEq(c2.resolvedOptions().locale, "de"); + assertEq(c3.resolvedOptions().locale, "de"); + + assertEq(c1.resolvedOptions().collation, "default"); + assertEq(c2.resolvedOptions().collation, "default"); + assertEq(c3.resolvedOptions().collation, "default"); + + assertEq(c1.compare("ä", "ae"), 1); + assertEq(c2.compare("ä", "ae"), 1); + assertEq(c3.compare("ä", "ae"), 1); +} + +if (typeof reportCompare === "function") + reportCompare(0, 0, "ok"); -- cgit v1.2.3