summaryrefslogtreecommitdiff
path: root/test/intl402
diff options
context:
space:
mode:
authorAndré Bargull <andre.bargull@gmail.com>2017-12-08 13:20:03 -0800
committerRick Waldron <waldron.rick@gmail.com>2017-12-19 15:42:56 -0500
commit1abd6c6593094e4242a0ba7f44957f3431240168 (patch)
tree64faa200cb44e9bd237a80dcd88fe3bab57c9920 /test/intl402
parent9b54779018ce73c873b727b944264974a62c59b4 (diff)
downloadqtdeclarative-testsuites-1abd6c6593094e4242a0ba7f44957f3431240168.tar.gz
Extend coverage for Intl.getCanonicalLocales
Diffstat (limited to 'test/intl402')
-rw-r--r--test/intl402/Intl/getCanonicalLocales/canonicalized-tags.js69
-rw-r--r--test/intl402/Intl/getCanonicalLocales/canonicalized-unicode-ext-seq.js39
-rw-r--r--test/intl402/Intl/getCanonicalLocales/descriptor.js20
-rw-r--r--test/intl402/Intl/getCanonicalLocales/elements-not-reordered.js27
-rw-r--r--test/intl402/Intl/getCanonicalLocales/error-cases.js1
-rw-r--r--test/intl402/Intl/getCanonicalLocales/invalid-tags.js81
-rw-r--r--test/intl402/Intl/getCanonicalLocales/locales-is-not-a-string.js1
-rw-r--r--test/intl402/Intl/getCanonicalLocales/preferred-grandfathered.js86
-rw-r--r--test/intl402/Intl/getCanonicalLocales/preferred-variant.js58
9 files changed, 382 insertions, 0 deletions
diff --git a/test/intl402/Intl/getCanonicalLocales/canonicalized-tags.js b/test/intl402/Intl/getCanonicalLocales/canonicalized-tags.js
new file mode 100644
index 000000000..cdfd19444
--- /dev/null
+++ b/test/intl402/Intl/getCanonicalLocales/canonicalized-tags.js
@@ -0,0 +1,69 @@
+// Copyright (C) 2017 André Bargull. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+esid: sec-intl.getcanonicallocales
+description: >
+ Call Intl.getCanonicalLocales function with valid language tags.
+info: |
+ 8.2.1 Intl.getCanonicalLocales (locales)
+ 1. Let ll be ? CanonicalizeLocaleList(locales).
+ 2. Return CreateArrayFromList(ll).
+
+ 9.2.1 CanonicalizeLocaleList (locales)
+ ...
+ 7. Repeat, while k < len
+ a. Let Pk be ToString(k).
+ b. Let kPresent be ? HasProperty(O, Pk).
+ c. If kPresent is true, then
+ i. Let kValue be ? Get(O, Pk).
+ ...
+ iii. Let tag be ? ToString(kValue).
+ ...
+ v. Let canonicalizedTag be CanonicalizeLanguageTag(tag).
+ vi. If canonicalizedTag is not an element of seen, append canonicalizedTag as the last element of seen.
+ ...
+includes: [testIntl.js]
+---*/
+
+var canonicalizedTags = {
+ "de": "de",
+ "DE-de": "de-DE",
+ "de-DE": "de-DE",
+ "cmn": "cmn",
+ "CMN-hANS": "cmn-Hans",
+ "cmn-hans-cn": "cmn-Hans-CN",
+ "es-419": "es-419",
+ "es-419-u-nu-latn": "es-419-u-nu-latn",
+ "cmn-hans-cn-u-ca-t-ca-x-t-u": "cmn-Hans-CN-t-ca-u-ca-x-t-u",
+ "de-gregory-u-ca-gregory": "de-gregory-u-ca-gregory",
+ "no-nyn": "nn",
+ "i-klingon": "tlh",
+ "sgn-GR": "gss",
+ "ji": "yi",
+ "de-DD": "de-DE",
+ "zh-hak-CN": "hak-CN",
+ "sgn-ils": "ils",
+ "in": "id",
+ "x-foo": "x-foo",
+ "sr-cyrl-ekavsk": "sr-Cyrl-ekavsk",
+ "en-ca-newfound": "en-CA-newfound",
+ "sl-rozaj-biske-1994": "sl-rozaj-biske-1994",
+ "da-u-attr": "da-u-attr",
+ "da-u-attr-co-search": "da-u-attr-co-search",
+};
+
+// make sure the data above is correct
+Object.getOwnPropertyNames(canonicalizedTags).forEach(function (tag) {
+ var canonicalizedTag = canonicalizedTags[tag];
+ assert(
+ isCanonicalizedStructurallyValidLanguageTag(canonicalizedTag),
+ "Test data \"" + canonicalizedTag + "\" is not canonicalized and structurally valid language tag."
+ );
+});
+
+Object.getOwnPropertyNames(canonicalizedTags).forEach(function (tag) {
+ var canonicalLocales = Intl.getCanonicalLocales(tag);
+ assert.sameValue(canonicalLocales.length, 1);
+ assert.sameValue(canonicalLocales[0], canonicalizedTags[tag]);
+});
diff --git a/test/intl402/Intl/getCanonicalLocales/canonicalized-unicode-ext-seq.js b/test/intl402/Intl/getCanonicalLocales/canonicalized-unicode-ext-seq.js
new file mode 100644
index 000000000..7f4aa16e8
--- /dev/null
+++ b/test/intl402/Intl/getCanonicalLocales/canonicalized-unicode-ext-seq.js
@@ -0,0 +1,39 @@
+// Copyright (C) 2017 André Bargull. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+esid: sec-intl.getcanonicallocales
+description: >
+ Implementations are allowed to canonicalize extension subtag sequences.
+info: |
+ 8.2.1 Intl.getCanonicalLocales (locales)
+ 1. Let ll be ? CanonicalizeLocaleList(locales).
+ 2. Return CreateArrayFromList(ll).
+
+ 9.2.1 CanonicalizeLocaleList (locales)
+ ...
+ 7. Repeat, while k < len
+ ...
+ c. If kPresent is true, then
+ ...
+ v. Let canonicalizedTag be CanonicalizeLanguageTag(tag).
+ ...
+
+ 6.2.3 CanonicalizeLanguageTag (locale)
+ The specifications for extensions to BCP 47 language tags, such as
+ RFC 6067, may include canonicalization rules for the extension subtag
+ sequences they define that go beyond the canonicalization rules of
+ RFC 5646 section 4.5. Implementations are allowed, but not required,
+ to apply these additional rules.
+---*/
+
+var locale = "it-u-nu-latn-ca-gregory";
+
+// RFC 6067: The canonical order of keywords is in US-ASCII order by key.
+var sorted = "it-u-ca-gregory-nu-latn";
+
+var canonicalLocales = Intl.getCanonicalLocales(locale);
+assert.sameValue(canonicalLocales.length, 1);
+
+var canonicalLocale = canonicalLocales[0];
+assert((canonicalLocale === locale) || (canonicalLocale === sorted));
diff --git a/test/intl402/Intl/getCanonicalLocales/descriptor.js b/test/intl402/Intl/getCanonicalLocales/descriptor.js
new file mode 100644
index 000000000..1cf400ce2
--- /dev/null
+++ b/test/intl402/Intl/getCanonicalLocales/descriptor.js
@@ -0,0 +1,20 @@
+// Copyright (C) 2017 André Bargull. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+esid: sec-intl.getcanonicallocales
+description: >
+ Intl.getCanonicalLocales property attributes.
+info: |
+ 8.2.1 Intl.getCanonicalLocales (locales)
+
+ 17 ECMAScript Standard Built-in Objects:
+ Every other data property described in clauses 18 through 26 and in
+ Annex B.2 has the attributes { [[Writable]]: true, [[Enumerable]]: false,
+ [[Configurable]]: true } unless otherwise specified.
+includes: [propertyHelper.js]
+---*/
+
+verifyNotEnumerable(Intl, "getCanonicalLocales");
+verifyWritable(Intl, "getCanonicalLocales");
+verifyConfigurable(Intl, "getCanonicalLocales");
diff --git a/test/intl402/Intl/getCanonicalLocales/elements-not-reordered.js b/test/intl402/Intl/getCanonicalLocales/elements-not-reordered.js
new file mode 100644
index 000000000..3c99efa04
--- /dev/null
+++ b/test/intl402/Intl/getCanonicalLocales/elements-not-reordered.js
@@ -0,0 +1,27 @@
+// Copyright (C) 2017 André Bargull. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+esid: sec-intl.getcanonicallocales
+description: >
+ Language tags are not reordered.
+info: |
+ 8.2.1 Intl.getCanonicalLocales (locales)
+ 1. Let ll be ? CanonicalizeLocaleList(locales).
+ 2. Return CreateArrayFromList(ll).
+
+ 9.2.1 CanonicalizeLocaleList (locales)
+ ...
+ 7. Repeat, while k < len
+ ...
+ c. If kPresent is true, then
+ ...
+ vi. If canonicalizedTag is not an element of seen, append canonicalizedTag as the last element of seen.
+ ...
+---*/
+
+var canonicalLocales = Intl.getCanonicalLocales(["zu", "af"]);
+
+assert.sameValue(canonicalLocales.length, 2);
+assert.sameValue(canonicalLocales[0], "zu");
+assert.sameValue(canonicalLocales[1], "af");
diff --git a/test/intl402/Intl/getCanonicalLocales/error-cases.js b/test/intl402/Intl/getCanonicalLocales/error-cases.js
index 2a68e1e39..046d6d425 100644
--- a/test/intl402/Intl/getCanonicalLocales/error-cases.js
+++ b/test/intl402/Intl/getCanonicalLocales/error-cases.js
@@ -33,6 +33,7 @@ var typeErrorCases =
[
null,
[null],
+ [undefined],
[true],
[NaN],
[2],
diff --git a/test/intl402/Intl/getCanonicalLocales/invalid-tags.js b/test/intl402/Intl/getCanonicalLocales/invalid-tags.js
new file mode 100644
index 000000000..e218f21f1
--- /dev/null
+++ b/test/intl402/Intl/getCanonicalLocales/invalid-tags.js
@@ -0,0 +1,81 @@
+// Copyright (C) 2017 André Bargull. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+esid: sec-intl.getcanonicallocales
+description: >
+ Throws a RangeError if the language tag is invalid.
+info: |
+ 8.2.1 Intl.getCanonicalLocales (locales)
+ 1. Let ll be ? CanonicalizeLocaleList(locales).
+ ...
+
+ 9.2.1 CanonicalizeLocaleList (locales)
+ ...
+ 7. Repeat, while k < len
+ ...
+ c. If kPresent is true, then
+ ...
+ iv. If IsStructurallyValidLanguageTag(tag) is false, throw a RangeError exception.
+ ...
+includes: [testIntl.js]
+---*/
+
+var invalidLanguageTags = [
+ "", // empty tag
+ "i", // singleton alone
+ "x", // private use without subtag
+ "u", // extension singleton in first place
+ "419", // region code in first place
+ "u-nu-latn-cu-bob", // extension sequence without language
+ "hans-cmn-cn", // "hans" could theoretically be a 4-letter language code,
+ // but those can't be followed by extlang codes.
+ "cmn-hans-cn-u-u", // duplicate singleton
+ "cmn-hans-cn-t-u-ca-u", // duplicate singleton
+ "de-gregory-gregory", // duplicate variant
+ "*", // language range
+ "de-*", // language range
+ "中文", // non-ASCII letters
+ "en-ß", // non-ASCII letters
+ "ıd", // non-ASCII letters
+
+ // underscores in different parts of the language tag
+ "de_DE",
+ "DE_de",
+ "cmn_Hans",
+ "cmn-hans_cn",
+ "es_419",
+ "es-419-u-nu-latn-cu_bob",
+ "i_klingon",
+ "cmn-hans-cn-t-ca-u-ca-x_t-u",
+ "enochian_enochian",
+ "de-gregory_u-ca-gregory",
+
+ "en\u0000", // null-terminator sequence
+ " en", // leading whitespace
+ "en ", // trailing whitespace
+ "it-IT-Latn", // country before script tag
+ "de-u", // incomplete Unicode extension sequences
+ "de-u-",
+ "de-u-ca-",
+ "de-u-ca-gregory-",
+ "si-x", // incomplete private-use tags
+ "x-",
+ "x-y-",
+];
+
+// make sure the data above is correct
+for (var i = 0; i < invalidLanguageTags.length; ++i) {
+ var invalidTag = invalidLanguageTags[i];
+ assert(
+ !isCanonicalizedStructurallyValidLanguageTag(invalidTag),
+ "Test data \"" + invalidTag + "\" is a canonicalized and structurally valid language tag."
+ );
+}
+
+for (var i = 0; i < invalidLanguageTags.length; ++i) {
+ var invalidTag = invalidLanguageTags[i];
+ assert.throws(RangeError, function() {
+ Intl.getCanonicalLocales(invalidTag)
+ }, "Language tag: " + invalidTag);
+}
diff --git a/test/intl402/Intl/getCanonicalLocales/locales-is-not-a-string.js b/test/intl402/Intl/getCanonicalLocales/locales-is-not-a-string.js
index 7b100ec26..ee96616d7 100644
--- a/test/intl402/Intl/getCanonicalLocales/locales-is-not-a-string.js
+++ b/test/intl402/Intl/getCanonicalLocales/locales-is-not-a-string.js
@@ -19,6 +19,7 @@ function assertArray(l, r) {
}
assertArray(gCL(), []);
+assertArray(gCL(undefined), []);
assertArray(gCL(false), []);
assertArray(gCL(true), []);
assertArray(gCL(Symbol("foo")), []);
diff --git a/test/intl402/Intl/getCanonicalLocales/preferred-grandfathered.js b/test/intl402/Intl/getCanonicalLocales/preferred-grandfathered.js
new file mode 100644
index 000000000..d140289e3
--- /dev/null
+++ b/test/intl402/Intl/getCanonicalLocales/preferred-grandfathered.js
@@ -0,0 +1,86 @@
+// Copyright (C) 2017 André Bargull. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+esid: sec-intl.getcanonicallocales
+description: >
+ Call Intl.getCanonicalLocales function with grandfathered language tags.
+info: |
+ 8.2.1 Intl.getCanonicalLocales (locales)
+ 1. Let ll be ? CanonicalizeLocaleList(locales).
+ 2. Return CreateArrayFromList(ll).
+
+ 9.2.1 CanonicalizeLocaleList (locales)
+ ...
+ 7. Repeat, while k < len
+ ...
+ c. If kPresent is true, then
+ ...
+ v. Let canonicalizedTag be CanonicalizeLanguageTag(tag).
+ ...
+
+ 6.2.3 CanonicalizeLanguageTag ( locale )
+ The CanonicalizeLanguageTag abstract operation returns the canonical and case-regularized
+ form of the locale argument (which must be a String value that is a structurally valid
+ BCP 47 language tag as verified by the IsStructurallyValidLanguageTag abstract operation).
+ A conforming implementation shall take the steps specified in RFC 5646 section 4.5, or
+ successor, to bring the language tag into canonical form, and to regularize the case of
+ the subtags. Furthermore, a conforming implementation shall not take the steps to bring
+ a language tag into "extlang form", nor shall it reorder variant subtags.
+
+ The specifications for extensions to BCP 47 language tags, such as RFC 6067, may include
+ canonicalization rules for the extension subtag sequences they define that go beyond the
+ canonicalization rules of RFC 5646 section 4.5. Implementations are allowed, but not
+ required, to apply these additional rules.
+
+includes: [testIntl.js]
+---*/
+
+// Generated from http://www.iana.org/assignments/language-subtag-registry/language-subtag-registry
+// File-Date: 2017-08-15
+var canonicalizedTags = {
+ // Irregular tags.
+ "en-gb-oed": "en-GB-oxendict",
+ "i-ami": "ami",
+ "i-bnn": "bnn",
+ "i-default": "i-default",
+ "i-enochian": "i-enochian",
+ "i-hak": "hak",
+ "i-klingon": "tlh",
+ "i-lux": "lb",
+ "i-mingo": "i-mingo",
+ "i-navajo": "nv",
+ "i-pwn": "pwn",
+ "i-tao": "tao",
+ "i-tay": "tay",
+ "i-tsu": "tsu",
+ "sgn-be-fr": "sfb",
+ "sgn-be-nl": "vgt",
+ "sgn-ch-de": "sgg",
+
+ // Regular tags.
+ "art-lojban": "jbo",
+ "cel-gaulish": "cel-gaulish",
+ "no-bok": "nb",
+ "no-nyn": "nn",
+ "zh-guoyu": "cmn",
+ "zh-hakka": "hak",
+ "zh-min": "zh-min",
+ "zh-min-nan": "nan",
+ "zh-xiang": "hsn",
+};
+
+// make sure the data above is correct
+Object.getOwnPropertyNames(canonicalizedTags).forEach(function (tag) {
+ var canonicalizedTag = canonicalizedTags[tag];
+ assert(
+ isCanonicalizedStructurallyValidLanguageTag(canonicalizedTag),
+ "Test data \"" + canonicalizedTag + "\" is not canonicalized and structurally valid language tag."
+ );
+});
+
+Object.getOwnPropertyNames(canonicalizedTags).forEach(function (tag) {
+ var canonicalLocales = Intl.getCanonicalLocales(tag);
+ assert.sameValue(canonicalLocales.length, 1);
+ assert.sameValue(canonicalLocales[0], canonicalizedTags[tag]);
+});
diff --git a/test/intl402/Intl/getCanonicalLocales/preferred-variant.js b/test/intl402/Intl/getCanonicalLocales/preferred-variant.js
new file mode 100644
index 000000000..bb2c4cd9e
--- /dev/null
+++ b/test/intl402/Intl/getCanonicalLocales/preferred-variant.js
@@ -0,0 +1,58 @@
+// Copyright (C) 2017 André Bargull. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+esid: sec-intl.getcanonicallocales
+description: >
+ Call Intl.getCanonicalLocales function with grandfathered language tags.
+info: |
+ 8.2.1 Intl.getCanonicalLocales (locales)
+ 1. Let ll be ? CanonicalizeLocaleList(locales).
+ 2. Return CreateArrayFromList(ll).
+
+ 9.2.1 CanonicalizeLocaleList (locales)
+ ...
+ 7. Repeat, while k < len
+ ...
+ c. If kPresent is true, then
+ ...
+ v. Let canonicalizedTag be CanonicalizeLanguageTag(tag).
+ ...
+
+ 6.2.3 CanonicalizeLanguageTag ( locale )
+ The CanonicalizeLanguageTag abstract operation returns the canonical and case-regularized
+ form of the locale argument (which must be a String value that is a structurally valid
+ BCP 47 language tag as verified by the IsStructurallyValidLanguageTag abstract operation).
+ A conforming implementation shall take the steps specified in RFC 5646 section 4.5, or
+ successor, to bring the language tag into canonical form, and to regularize the case of
+ the subtags. Furthermore, a conforming implementation shall not take the steps to bring
+ a language tag into "extlang form", nor shall it reorder variant subtags.
+
+ The specifications for extensions to BCP 47 language tags, such as RFC 6067, may include
+ canonicalization rules for the extension subtag sequences they define that go beyond the
+ canonicalization rules of RFC 5646 section 4.5. Implementations are allowed, but not
+ required, to apply these additional rules.
+
+includes: [testIntl.js]
+---*/
+
+// Generated from http://www.iana.org/assignments/language-subtag-registry/language-subtag-registry
+// File-Date: 2017-08-15
+var canonicalizedTags = {
+ "ja-latn-hepburn-heploc": "ja-Latn-alalc97",
+};
+
+// make sure the data above is correct
+Object.getOwnPropertyNames(canonicalizedTags).forEach(function (tag) {
+ var canonicalizedTag = canonicalizedTags[tag];
+ assert(
+ isCanonicalizedStructurallyValidLanguageTag(canonicalizedTag),
+ "Test data \"" + canonicalizedTag + "\" is not canonicalized and structurally valid language tag."
+ );
+});
+
+Object.getOwnPropertyNames(canonicalizedTags).forEach(function (tag) {
+ var canonicalLocales = Intl.getCanonicalLocales(tag);
+ assert.sameValue(canonicalLocales.length, 1);
+ assert.sameValue(canonicalLocales[0], canonicalizedTags[tag]);
+});