Skip to content
Snippets Groups Projects
Unverified Commit ef1d3a4e authored by Rick Waldron's avatar Rick Waldron Committed by GitHub
Browse files

Merge pull request #1553 from Ms2ger/Locale

Add some more Locale tests.
parents 7ff8d481 ce8d0520
No related branches found
No related tags found
No related merge requests found
Showing
with 1154 additions and 0 deletions
// Copyright 2018 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-intl.locale
description: >
Checks the order of evaluations of arguments and options for the Locale
constructor.
features: [Intl.Locale]
includes: [compareArray.js]
---*/
const order = [];
new Intl.Locale(
{ toString() { order.push("tag toString"); return "en"; } },
{
get language() {
order.push("get language");
return {
toString() {
order.push("toString language");
return "de";
}
}
},
get script() {
order.push("get script");
return {
toString() {
order.push("toString script");
return "Latn";
}
}
},
get region() {
order.push("get region");
return {
toString() {
order.push("toString region");
return "DE";
}
}
},
get calendar() {
order.push("get calendar");
return {
toString() {
order.push("toString calendar");
return "gregory";
}
}
},
get collation() {
order.push("get collation");
return {
toString() {
order.push("toString collation");
return "zhuyin";
}
}
},
get hourCycle() {
order.push("get hourCycle");
return {
toString() {
order.push("toString hourCycle");
return "h24";
}
}
},
get caseFirst() {
order.push("get caseFirst");
return {
toString() {
order.push("toString caseFirst");
return "upper";
}
}
},
get numeric() {
order.push("get numeric");
return false;
},
get numberingSystem() {
order.push("get numberingSystem");
return {
toString() {
order.push("toString numberingSystem");
return "latn";
}
}
},
}
);
const expected_order = [
"tag toString",
"get language",
"toString language",
"get script",
"toString script",
"get region",
"toString region",
"get calendar",
"toString calendar",
"get collation",
"toString collation",
"get hourCycle",
"toString hourCycle",
"get caseFirst",
"toString caseFirst",
"get numeric",
"get numberingSystem",
"toString numberingSystem"
];
assert.compareArray(order, expected_order);
// Copyright 2018 André Bargull; Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-intl.locale
description: >
Verifies canonicalization of specific tags.
info: |
ApplyOptionsToTag( tag, options )
10. Return CanonicalizeLanguageTag(tag).
features: [Intl.Locale]
---*/
// Pass Intl.Locale object and replace subtag.
const enUS = new Intl.Locale("en-US");
const enGB = new Intl.Locale(enUS, {region: "GB"});
assert.sameValue(enUS.toString(), "en-US");
assert.sameValue(enGB.toString(), "en-GB");
// Pass Intl.Locale object and replace Unicode extension keyword.
const zhUnihan = new Intl.Locale("zh-u-co-unihan");
const zhZhuyin = new Intl.Locale(zhUnihan, {collation: "zhuyin"});
assert.sameValue(zhUnihan.toString(), "zh-u-co-unihan");
assert.sameValue(zhZhuyin.toString(), "zh-u-co-zhuyin");
assert.sameValue(zhUnihan.collation, "unihan");
assert.sameValue(zhZhuyin.collation, "zhuyin");
// Copyright 2018 André Bargull; Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-intl.locale
description: >
Verifies canonicalization, minimization and maximization of specific tags.
info: |
ApplyOptionsToTag( tag, options )
10. Return CanonicalizeLanguageTag(tag).
Intl.Locale.prototype.maximize ()
3. Let maximal be the result of the Add Likely Subtags algorithm applied to loc.[[Locale]].
Intl.Locale.prototype.minimize ()
3. Let minimal be the result of the Remove Likely Subtags algorithm applied to loc.[[Locale]].
features: [Intl.Locale]
---*/
// Test some language tags where we know that either CLDR or ICU produce
// different results compared to the canonicalization specified in RFC 5646.
var testData = [
{
tag: "mo",
canonical: "ro",
maximized: "ro-Latn-RO",
},
{
tag: "es-ES-preeuro",
maximized: "es-Latn-ES-preeuro",
minimized: "es-preeuro",
},
{
tag: "uz-UZ-cyrillic",
maximized: "uz-Latn-UZ-cyrillic",
minimized: "uz-cyrillic",
},
{
tag: "posix",
},
{
tag: "hi-direct",
maximized: "hi-Deva-IN-direct",
},
{
tag: "zh-pinyin",
maximized: "zh-Hans-CN-pinyin",
},
{
tag: "zh-stroke",
maximized: "zh-Hans-CN-stroke",
},
{
tag: "aar-x-private",
},
{
tag: "heb-x-private",
},
{
tag: "und-ita",
// canonical: "und" or "ita" ?
maximized: "en-Latn-US",
minimized: "und",
},
{
tag: "de-u-kf",
maximized: "de-Latn-DE-u-kf",
},
{
tag: "ces",
},
{
tag: "hy-arevela",
canonical: "hy",
maximized: "hy-Armn-AM",
},
{
tag: "hy-arevmda",
canonical: "hyw",
},
];
for (const {tag, canonical = tag, maximized = canonical, minimized = canonical} of testData) {
assert.sameValue(Intl.getCanonicalLocales(tag)[0], canonical);
const loc = new Intl.Locale(tag);
assert.sameValue(loc.toString(), canonical);
assert.sameValue(loc.maximize().toString(), maximized);
assert.sameValue(loc.minimize().toString(), minimized);
}
// Copyright 2018 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-intl.locale
description: >
Checks error cases for the options argument to the Locale constructor.
info: |
Intl.Locale( tag [, options] )
...
22. Let kf be ? GetOption(options, "caseFirst", "string", « "upper", "lower", "false" », undefined).
...
GetOption ( options, property, type, values, fallback )
...
2. d. If values is not undefined, then
i. If values does not contain an element equal to value, throw a RangeError exception.
...
features: [Intl.Locale]
---*/
const invalidCaseFirstOptions = [
"",
"u",
"Upper",
"upper\0",
"uppercase",
"true",
{ valueOf() { return false; } },
];
for (const invalidCaseFirstOption of invalidCaseFirstOptions) {
assert.throws(RangeError, function() {
new Intl.Locale("en", {caseFirst: invalidCaseFirstOption});
}, `${invalidCaseFirstOption} is an invalid caseFirst option value`);
}
// Copyright 2018 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-intl.locale
description: >
Checks valid cases for the options argument to the Locale constructor.
info: |
Intl.Locale( tag [, options] )
...
22. Let kf be ? GetOption(options, "caseFirst", "string", « "upper", "lower", "false" », undefined).
23. Set opt.[[kf]] to kf.
...
30. Let r be ! ApplyUnicodeExtensionToTag(tag, opt, relevantExtensionKeys).
...
ApplyUnicodeExtensionToTag( tag, options, relevantExtensionKeys )
...
8. Let locale be the String value that is tag with all Unicode locale extension sequences removed.
9. Let newExtension be ! CanonicalizeUnicodeExtension(attributes, keywords).
10. If newExtension is not the empty String, then
a. Let locale be ! InsertUnicodeExtension(locale, newExtension).
...
CanonicalizeUnicodeExtension( attributes, keywords )
...
4. Repeat for each element entry of keywords in List order,
a. Let keyword be entry.[[Key]].
b. If entry.[[Value]] is not the empty String, then
i. Let keyword be the string-concatenation of keyword, "-", and entry.[[Value]].
c. Append keyword to fullKeywords.
...
features: [Intl.Locale]
---*/
const validCaseFirstOptions = [
"upper",
"lower",
"false",
false,
{ toString() { return false; } },
];
for (const caseFirst of validCaseFirstOptions) {
const options = { caseFirst };
const expected = String(caseFirst);
assert.sameValue(
new Intl.Locale('en', options).toString(),
"en-u-kf-" + expected,
);
assert.sameValue(
new Intl.Locale('en-u-kf-lower', options).toString(),
"en-u-kf-" + expected,
);
if ("caseFirst" in Intl.Locale.prototype) {
assert.sameValue(
new Intl.Locale('en-u-kf-lower', options).caseFirst,
expected,
);
}
}
// Copyright 2018 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-intl.locale
description: >
Checks error cases for the options argument to the Locale constructor.
info: |
Intl.Locale( tag [, options] )
...
18. If collation is not undefined, then
a. If collation does not match the [(3*8alphanum) *("-" (3*8alphanum))] sequence, throw a RangeError exception.
features: [Intl.Locale]
---*/
/*
alphanum = (ALPHA / DIGIT) ; letters and numbers
collation = [(3*8alphanum) *("-" (3*8alphanum))]
*/
const invalidCollationOptions = [
"a",
"ab",
"abcdefghi",
"abc-abcdefghi",
];
for (const invalidCollationOption of invalidCollationOptions) {
assert.throws(RangeError, function() {
new Intl.Locale("en", {collation: invalidCollationOption});
}, `${invalidCollationOption} is an invalid collation option value`);
}
// Copyright 2018 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-intl.locale
description: >
Checks valid cases for the options argument to the Locale constructor.
info: |
Intl.Locale( tag [, options] )
...
17. Let collation be ? GetOption(options, "collation", "string", undefined, undefined).
...
19. Set opt.[[co]] to collation.
...
30. Let r be ! ApplyUnicodeExtensionToTag(tag, opt, relevantExtensionKeys).
...
ApplyUnicodeExtensionToTag( tag, options, relevantExtensionKeys )
...
8. Let locale be the String value that is tag with all Unicode locale extension sequences removed.
9. Let newExtension be ! CanonicalizeUnicodeExtension(attributes, keywords).
10. If newExtension is not the empty String, then
a. Let locale be ! InsertUnicodeExtension(locale, newExtension).
...
CanonicalizeUnicodeExtension( attributes, keywords )
...
4. Repeat for each element entry of keywords in List order,
a. Let keyword be entry.[[Key]].
b. If entry.[[Value]] is not the empty String, then
i. Let keyword be the string-concatenation of keyword, "-", and entry.[[Value]].
c. Append keyword to fullKeywords.
...
features: [Intl.Locale]
---*/
const validCollationOptions = [
["", "en-u-co"],
["abc", "en-u-co-abc"],
["abcd", "en-u-co-abcd"],
["abcde", "en-u-co-abcde"],
["abcdef", "en-u-co-abcdef"],
["abcdefg", "en-u-co-abcdefg"],
["abcdefgh", "en-u-co-abcdefgh"],
["12345678", "en-u-co-12345678"],
["1234abcd", "en-u-co-1234abcd"],
["1234abcd-abc123", "en-u-co-1234abcd-abc123"],
];
for (const [collation, expected] of validCollationOptions) {
let options = { collation };
assert.sameValue(
new Intl.Locale('en', options).toString(),
expected,
`new Intl.Locale('en', options).toString() equals the value of ${expected}`
);
assert.sameValue(
new Intl.Locale('en-u-co-gregory', options).toString(),
expected,
`new Intl.Locale('en-u-co-gregory', options).toString() equals the value of ${expected}`
);
}
// Copyright 2018 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-intl.locale
description: >
Checks error cases for the options argument to the Locale constructor.
info: |
Intl.Locale( tag [, options] )
...
20. Let hc be ? GetOption(options, "hourCycle", "string", « "h11", "h12", "h23", "h24" », undefined).
...
GetOption ( options, property, type, values, fallback )
...
2. d. If values is not undefined, then
i. If values does not contain an element equal to value, throw a RangeError exception.
...
features: [Intl.Locale]
---*/
const invalidHourCycleOptions = [
"",
"h",
"h00",
"h01",
"h10",
"h13",
"h22",
"h25",
"h48",
"h012",
"h120",
"h12\0",
"H12",
];
for (const invalidHourCycleOption of invalidHourCycleOptions) {
assert.throws(RangeError, function() {
new Intl.Locale("en", {hourCycle: invalidHourCycleOption});
}, `${invalidHourCycleOption} is an invalid hourCycle option value`);
}
// Copyright 2018 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-intl.locale
description: >
Checks valid cases for the options argument to the Locale constructor.
info: |
Intl.Locale( tag [, options] )
...
20. Let hc be ? GetOption(options, "hourCycle", "string", « "h11", "h12", "h23", "h24" », undefined).
21. Set opt.[[hc]] to hc.
...
30. Let r be ! ApplyUnicodeExtensionToTag(tag, opt, relevantExtensionKeys).
...
ApplyUnicodeExtensionToTag( tag, options, relevantExtensionKeys )
...
8. Let locale be the String value that is tag with all Unicode locale extension sequences removed.
9. Let newExtension be ! CanonicalizeUnicodeExtension(attributes, keywords).
10. If newExtension is not the empty String, then
a. Let locale be ! InsertUnicodeExtension(locale, newExtension).
...
CanonicalizeUnicodeExtension( attributes, keywords )
...
4. Repeat for each element entry of keywords in List order,
a. Let keyword be entry.[[Key]].
b. If entry.[[Value]] is not the empty String, then
i. Let keyword be the string-concatenation of keyword, "-", and entry.[[Value]].
c. Append keyword to fullKeywords.
...
features: [Intl.Locale]
---*/
const validHourCycleOptions = [
"h11",
"h12",
"h23",
"h24",
{ toString() { return "h24"; } },
];
for (const hourCycle of validHourCycleOptions) {
const options = { hourCycle };
const expected = String(hourCycle);
assert.sameValue(
new Intl.Locale('en', options).toString(),
"en-u-hc-" + expected,
);
assert.sameValue(
new Intl.Locale('en-u-hc-h00', options).toString(),
"en-u-hc-" + expected,
);
assert.sameValue(
new Intl.Locale('en-u-hc-h12', options).toString(),
"en-u-hc-" + expected,
);
assert.sameValue(
new Intl.Locale('en-u-hc-h00', options).hourCycle,
expected,
);
}
// Copyright 2018 André Bargull; Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-intl.locale
description: >
Checks error cases for the options argument to the Locale
constructor.
info: |
ApplyOptionsToTag( tag, options )
...
3. Let language be ? GetOption(options, "language", "string", undefined, undefined).
4. If language is not undefined, then
a. If language does not match the language production, throw a RangeError exception.
b. If language matches the grandfathered production, throw a RangeError exception.
...
features: [Intl.Locale]
---*/
const testData = [
{
tag: "nb",
options: {
language: "no-bok",
},
},
{
tag: "nb",
options: {
language: "no-bok",
region: "NO",
},
},
];
for (const {tag, options} of testData) {
assert.throws(RangeError, function() {
new Intl.Locale(tag, options);
});
}
// Copyright 2018 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-intl.locale
description: >
Checks error cases for the options argument to the Locale constructor.
info: |
Intl.Locale( tag [, options] )
...
28. If numberingSystem is not undefined, then
a. If numberingSystem does not match the [(3*8alphanum) *("-" (3*8alphanum))] sequence, throw a RangeError exception.
features: [Intl.Locale]
---*/
/*
alphanum = (ALPHA / DIGIT) ; letters and numbers
numberingSystem = [(3*8alphanum) *("-" (3*8alphanum))]
*/
const invalidNumberingSystemOptions = [
"a",
"ab",
"abcdefghi",
"abc-abcdefghi",
];
for (const invalidNumberingSystemOption of invalidNumberingSystemOptions) {
assert.throws(RangeError, function() {
new Intl.Locale("en", {numberingSystem: invalidNumberingSystemOption});
}, `${invalidNumberingSystemOption} is an invalid numberingSystem option value`);
}
// Copyright 2018 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-intl.locale
description: >
Checks valid cases for the options argument to the Locale constructor.
info: |
Intl.Locale( tag [, options] )
...
27. Let numberingSystem be ? GetOption(options, "numberingSystem", "string", undefined, undefined).
...
29. Set opt.[[nu]] to numberingSystem.
...
30. Let r be ! ApplyUnicodeExtensionToTag(tag, opt, relevantExtensionKeys).
...
ApplyUnicodeExtensionToTag( tag, options, relevantExtensionKeys )
...
8. Let locale be the String value that is tag with all Unicode locale extension sequences removed.
9. Let newExtension be ! CanonicalizeUnicodeExtension(attributes, keywords).
10. If newExtension is not the empty String, then
a. Let locale be ! InsertUnicodeExtension(locale, newExtension).
...
CanonicalizeUnicodeExtension( attributes, keywords )
...
4. Repeat for each element entry of keywords in List order,
a. Let keyword be entry.[[Key]].
b. If entry.[[Value]] is not the empty String, then
i. Let keyword be the string-concatenation of keyword, "-", and entry.[[Value]].
c. Append keyword to fullKeywords.
...
features: [Intl.Locale]
---*/
const validNumberingSystemOptions = [
["", "en-u-nu"],
["abc", "en-u-nu-abc"],
["abcd", "en-u-nu-abcd"],
["abcde", "en-u-nu-abcde"],
["abcdef", "en-u-nu-abcdef"],
["abcdefg", "en-u-nu-abcdefg"],
["abcdefgh", "en-u-nu-abcdefgh"],
["12345678", "en-u-nu-12345678"],
["1234abcd", "en-u-nu-1234abcd"],
["1234abcd-abc123", "en-u-nu-1234abcd-abc123"],
];
for (const [numberingSystem, expected] of validNumberingSystemOptions) {
let options = { numberingSystem };
assert.sameValue(
new Intl.Locale('en', options).toString(),
expected,
`new Intl.Locale('en', options).toString() equals the value of ${expected}`
);
assert.sameValue(
new Intl.Locale('en-u-nu-latn', options).toString(),
expected,
`new Intl.Locale('en-u-nu-latn', options).toString() equals the value of ${expected}`
);
}
// Copyright 2018 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-intl.locale
description: >
Checks valid cases for the options argument to the Locale constructor.
info: |
Intl.Locale( tag [, options] )
...
24. Let kn be ? GetOption(options, "numeric", "boolean", undefined, undefined).
25. If kn is not undefined, set kn to ! ToString(kn).
...
30. Let r be ! ApplyUnicodeExtensionToTag(tag, opt, relevantExtensionKeys).
...
ApplyUnicodeExtensionToTag( tag, options, relevantExtensionKeys )
...
8. Let locale be the String value that is tag with all Unicode locale extension sequences removed.
9. Let newExtension be ! CanonicalizeUnicodeExtension(attributes, keywords).
10. If newExtension is not the empty String, then
a. Let locale be ! InsertUnicodeExtension(locale, newExtension).
...
CanonicalizeUnicodeExtension( attributes, keywords )
...
4. Repeat for each element entry of keywords in List order,
a. Let keyword be entry.[[Key]].
b. If entry.[[Value]] is not the empty String, then
i. Let keyword be the string-concatenation of keyword, "-", and entry.[[Value]].
c. Append keyword to fullKeywords.
...
features: [Intl.Locale]
---*/
const validNumericOptions = [
[undefined, undefined],
[false, "false"],
[true, "true"],
[null, "false"],
[0, "false"],
[0.5, "true"],
[{ valueOf() { return false; } }, "true"],
];
for (const [numeric, expected] of validNumericOptions) {
const options = { numeric };
assert.sameValue(
new Intl.Locale('en', options).toString(),
expected ? ("en-u-kn-" + expected) : "en",
);
assert.sameValue(
new Intl.Locale('en-u-kn-true', options).toString(),
"en-u-kn-" + (expected || "true"),
);
if ("numeric" in Intl.Locale.prototype) {
assert.sameValue(
new Intl.Locale('en-u-kf-lower', options).numeric,
expected,
);
}
}
// Copyright 2018 André Bargull; Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-intl.locale
description: >
Verifies the handling of options with grandfathered tags.
info: |
Intl.Locale( tag [, options] )
12. Set tag to ? ApplyOptionsToTag(tag, options).
14. Let calendar be ? GetOption(options, "calendar", "string", undefined, undefined).
16. Set opt.[[ca]] to calendar.
30. Let r be ! ApplyUnicodeExtensionToTag(tag, opt, relevantExtensionKeys).
ApplyOptionsToTag( tag, options )
9. If tag matches neither the privateuse nor the grandfathered production, then
10. Return CanonicalizeLanguageTag(tag).
features: [Intl.Locale]
---*/
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".
{
tag: "en-GB-oed",
options: {
region: "US",
calendar: "gregory",
},
canonical: "en-GB-oxendict-u-ca-gregory",
},
// Canonicalized version of the above, which we can add "US" to.
{
tag: "en-GB-oxendict",
options: {
region: "US",
calendar: "gregory",
},
canonical: "en-US-oxendict-u-ca-gregory",
},
// Regular grandfathered tags.
// "no-bok" is a grandfathered, so "NO"/"SE" isn't added. After
// canonicalization we can append "u-ca-gregory".
{
tag: "no-bok",
options: {
region: "NO",
calendar: "gregory",
},
canonical: "nb-u-ca-gregory",
},
{
tag: "no-bok",
options: {
region: "SE",
calendar: "gregory",
},
canonical: "nb-u-ca-gregory",
},
// "no-bok-NO" isn't a grandfathered tag, so we can replace "NO" with "SE"
// and can also append "u-ca-gregory".
{
tag: "no-bok-NO",
options: {
region: "SE",
calendar: "gregory",
},
canonical: "no-bok-SE-u-ca-gregory",
},
// "no-bok-SE" isn't a grandfathered tag, so we can replace "SE" with "NO"
// and can also append "u-ca-gregory".
{
tag: "no-bok-SE",
options: {
region: "NO",
calendar: "gregory",
},
canonical: "no-bok-NO-u-ca-gregory",
},
];
for (const {tag, options, canonical} of testData) {
const loc = new Intl.Locale(tag, options);
assert.sameValue(loc.toString(), canonical);
}
// Copyright 2018 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-intl.locale
description: >
Checks error cases for the string conversion of the locale argument to the
Locale constructor.
info: |
Intl.Locale( tag [, options] )
...
8. If Type(tag) is Object and tag has an [[InitializedLocale]] internal slot, then
9. Else,
a. Let tag be ? ToString(tag).
features: [Intl.Locale]
---*/
function CustomError() {}
function WrongCustomError() {}
const errors = [
{ get [Symbol.toPrimitive]() { throw new CustomError(); } },
{ [Symbol.toPrimitive](hint) { assert.sameValue(hint, "string"); throw new CustomError(); } },
{ get toString() { throw new CustomError(); }, get valueOf() { throw new WrongCustomError(); } },
{ toString() { throw new CustomError(); }, get valueOf() { throw new WrongCustomError(); } },
{ toString: undefined, get valueOf() { throw new CustomError(); } },
{ toString: undefined, valueOf() { throw new CustomError(); } },
{ toString() { return {} }, get valueOf() { throw new CustomError(); } },
{ toString() { return {} }, valueOf() { throw new CustomError(); } },
];
for (const input of errors) {
assert.throws(CustomError, function() { new Intl.Locale(input) });
}
// Copyright 2018 André Bargull; Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-intl.locale
description: >
Verifies treatment of specific structurally invalid tags.
info: |
ApplyOptionsToTag( tag, options )
2. If IsStructurallyValidLanguageTag(tag) is false, throw a RangeError exception.
features: [Intl.Locale]
---*/
const invalidLanguageTags = [
// Unicode extension sequence is incomplete.
"da-u",
"da-u-",
"da-u--",
"da-u-t-latn",
"da-u-x-priv",
// Duplicate 'u' singleton.
"da-u-ca-gregory-u-ca-buddhist"
];
for (const langtag of invalidLanguageTags) {
assert.throws(RangeError, function() {
new Intl.Locale(langtag)
});
}
// Copyright 2018 André Bargull; Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-intl.locale
description: >
Verifies canonicalization of specific tags.
info: |
ApplyOptionsToTag( tag, options )
10. Return CanonicalizeLanguageTag(tag).
features: [Intl.Locale]
---*/
const validLanguageTags = {
// Duplicate keywords are removed.
"da-u-ca-gregory-ca-buddhist": "da-u-ca-gregory",
// Keywords currently used in Intl specs are reordered in US-ASCII order.
"zh-u-nu-hans-ca-chinese": "zh-u-ca-chinese-nu-hans",
"zh-u-ca-chinese-nu-hans": "zh-u-ca-chinese-nu-hans",
// Even keywords currently not used in Intl specs are reordered in US-ASCII order.
"de-u-cu-eur-nu-latn": "de-u-cu-eur-nu-latn",
"de-u-nu-latn-cu-eur": "de-u-cu-eur-nu-latn",
// Attributes in Unicode extensions are reordered in US-ASCII order.
"pt-u-attr-ca-gregory": "pt-u-attr-ca-gregory",
"pt-u-attr1-attr2-ca-gregory": "pt-u-attr1-attr2-ca-gregory",
"pt-u-attr2-attr1-ca-gregory": "pt-u-attr1-attr2-ca-gregory",
};
for (const [langtag, canonical] of Object.entries(validLanguageTags)) {
assert.sameValue(new Intl.Locale(langtag).toString(), canonical);
}
// Copyright 2018 André Bargull; Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-intl.locale
description: >
Verifies handling of options with grandfathered tags.
info: |
ApplyOptionsToTag( tag, options )
...
9. If tag matches neither the privateuse nor the grandfathered production, then
...
ApplyUnicodeExtensionToTag( tag, options, relevantExtensionKeys )
...
2. If tag matches the privateuse or the grandfathered production, then
a. Let result be a new Record.
b. Repeat for each element key of relevantExtensionKeys in List order,
i. Set result.[[<key>]] to undefined.
c. Set result.[[locale]] to tag.
d. Return result.
...
7. Repeat for each element key of relevantExtensionKeys in List order,
e. Let optionsValue be options.[[<key>]].
f. If optionsValue is not undefined, then
ii. Let value be optionsValue.
iv. Else,
1. Append the Record{[[Key]]: key, [[Value]]: value} to keywords.
...
features: [Intl.Locale]
---*/
const testData = [
// Irregular grandfathered without modern replacement.
{
tag: "i-default",
options: {
language: "fr",
script: "Cyrl",
region: "DE",
numberingSystem: "latn",
},
canonical: "i-default",
extensions: {
language: undefined,
script: undefined,
region: undefined,
numberingSystem: undefined,
},
},
// Irregular grandfathered with modern replacement.
{
tag: "en-gb-oed",
options: {
language: "fr",
script: "Cyrl",
region: "US",
numberingSystem: "latn",
},
canonical: "en-GB-oxendict-u-nu-latn",
extensions: {
language: "en",
script: undefined,
region: "GB",
numberingSystem: "latn",
},
},
// Regular grandfathered without modern replacement.
{
tag: "cel-gaulish",
options: {
language: "fr",
script: "Cyrl",
region: "FR",
numberingSystem: "latn",
},
canonical: "cel-gaulish",
extensions: {
language: undefined,
script: undefined,
region: undefined,
numberingSystem: undefined,
},
},
// Regular grandfathered with modern replacement.
{
tag: "art-lojban",
options: {
language: "fr",
script: "Cyrl",
region: "ZZ",
numberingSystem: "latn",
},
canonical: "jbo-u-nu-latn",
extensions: {
language: "jbo",
script: undefined,
region: undefined,
numberingSystem: "latn",
},
},
];
for (const {tag, options, canonical, extensions} of testData) {
const loc = new Intl.Locale(tag, options);
assert.sameValue(loc.toString(), canonical);
for (const [name, value] of Object.entries(extensions)) {
assert.sameValue(loc[name], value);
}
}
// Copyright 2018 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-intl.locale
description: >
Verifies handling of options with privateuse tags.
info: |
ApplyOptionsToTag( tag, options )
...
9. If tag matches neither the privateuse nor the grandfathered production, then
...
ApplyUnicodeExtensionToTag( tag, options, relevantExtensionKeys )
...
2. If tag matches the privateuse or the grandfathered production, then
a. Let result be a new Record.
b. Repeat for each element key of relevantExtensionKeys in List order,
i. Set result.[[<key>]] to undefined.
c. Set result.[[locale]] to tag.
d. Return result.
...
7. Repeat for each element key of relevantExtensionKeys in List order,
e. Let optionsValue be options.[[<key>]].
f. If optionsValue is not undefined, then
ii. Let value be optionsValue.
iv. Else,
1. Append the Record{[[Key]]: key, [[Value]]: value} to keywords.
...
features: [Intl.Locale]
---*/
const loc = new Intl.Locale("x-default", {
language: "fr",
script: "Cyrl",
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);
// Copyright 2018 André Bargull; Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-intl.locale
description: >
Verifies getters with grandfathered tags.
info: |
get Intl.Locale.prototype.baseName
4. If locale does not match the langtag production, return locale.
5. Return the substring of locale corresponding to the
language ["-" script] ["-" region] *("-" variant)
subsequence of the langtag grammar.
get Intl.Locale.prototype.language
4. If locale matches the privateuse or the grandfathered production, return undefined.
get Intl.Locale.prototype.script
4. If locale matches the privateuse or the grandfathered production, return undefined.
get Intl.Locale.prototype.region
4. If locale matches the privateuse or the grandfathered production, return undefined.
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.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.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.script, undefined);
assert.sameValue(loc.region, undefined);
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