summaryrefslogtreecommitdiff
path: root/test/suite/intl402/ch06/6.2
diff options
context:
space:
mode:
Diffstat (limited to 'test/suite/intl402/ch06/6.2')
-rw-r--r--test/suite/intl402/ch06/6.2/6.2.2_a.js34
-rw-r--r--test/suite/intl402/ch06/6.2/6.2.2_b.js41
-rw-r--r--test/suite/intl402/ch06/6.2/6.2.2_c.js45
-rw-r--r--test/suite/intl402/ch06/6.2/6.2.3.js68
-rw-r--r--test/suite/intl402/ch06/6.2/6.2.4.js19
5 files changed, 207 insertions, 0 deletions
diff --git a/test/suite/intl402/ch06/6.2/6.2.2_a.js b/test/suite/intl402/ch06/6.2/6.2.2_a.js
new file mode 100644
index 000000000..144a1e7c9
--- /dev/null
+++ b/test/suite/intl402/ch06/6.2/6.2.2_a.js
@@ -0,0 +1,34 @@
+// Copyright 2012 Mozilla Corporation. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/**
+ * @description Tests that structurally valid language tags are accepted.
+ * @author Norbert Lindenberg
+ */
+
+$INCLUDE("testIntl.js");
+
+var validLanguageTags = [
+ "de", // ISO 639 language code
+ "de-DE", // + ISO 3166-1 country code
+ "DE-de", // tags are case-insensitive
+ "cmn", // ISO 639 language code
+ "cmn-Hans", // + script code
+ "CMN-hANS", // tags are case-insensitive
+ "cmn-hans-cn", // + ISO 3166-1 country code
+ "es-419", // + UN M.49 region code
+ "es-419-u-nu-latn-cu-bob", // + Unicode locale extension sequence
+ "i-klingon", // grandfathered tag
+ "cmn-hans-cn-t-ca-u-ca-x-t-u", // singleton subtags can also be used as private use subtags
+ "enochian-enochian", // language and variant subtags may be the same
+ "de-gregory-u-ca-gregory" // variant and extension subtags may be the same
+];
+
+testWithIntlConstructors(function (Constructor) {
+ validLanguageTags.forEach(function (tag) {
+ // this must not throw an exception for a valid language tag
+ var obj = new Constructor([tag]);
+ });
+ return true;
+});
+
diff --git a/test/suite/intl402/ch06/6.2/6.2.2_b.js b/test/suite/intl402/ch06/6.2/6.2.2_b.js
new file mode 100644
index 000000000..42d69e7c2
--- /dev/null
+++ b/test/suite/intl402/ch06/6.2/6.2.2_b.js
@@ -0,0 +1,41 @@
+// Copyright 2012 Mozilla Corporation. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/**
+ * @description Tests that language tags with "_" are not accepted.
+ * @author Norbert Lindenberg
+ */
+
+$INCLUDE("testIntl.js");
+
+var invalidLanguageTags = [
+ "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"
+];
+
+testWithIntlConstructors(function (Constructor) {
+ invalidLanguageTags.forEach(function (tag) {
+ var error;
+ try {
+ // this must throw an exception for an invalid language tag
+ var obj = new Constructor([tag]);
+ } catch (e) {
+ error = e;
+ }
+ if (error === undefined) {
+ $ERROR("Invalid language tag " + tag + " was not rejected.");
+ } else if (error.name !== "RangeError") {
+ $ERROR("Invalid language tag " + tag + " was rejected with wrong error " + error.name + ".");
+ }
+ });
+ return true;
+});
+
diff --git a/test/suite/intl402/ch06/6.2/6.2.2_c.js b/test/suite/intl402/ch06/6.2/6.2.2_c.js
new file mode 100644
index 000000000..ff2f9ae95
--- /dev/null
+++ b/test/suite/intl402/ch06/6.2/6.2.2_c.js
@@ -0,0 +1,45 @@
+// Copyright 2012 Mozilla Corporation. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/**
+ * @description Tests that language tags with invalid subtag sequences are not accepted.
+ * @author Norbert Lindenberg
+ */
+
+$INCLUDE("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
+ "中文", // non-ASCII letters
+ "en-ß", // non-ASCII letters
+ "ıd" // non-ASCII letters
+];
+
+testWithIntlConstructors(function (Constructor) {
+ invalidLanguageTags.forEach(function (tag) {
+ var error;
+ try {
+ // this must throw an exception for an invalid language tag
+ var obj = new Constructor([tag]);
+ } catch (e) {
+ error = e;
+ }
+ if (error === undefined) {
+ $ERROR("Invalid language tag " + tag + " was not rejected.");
+ } else if (error.name !== "RangeError") {
+ $ERROR("Invalid language tag " + tag + " was rejected with wrong error " + error.name + ".");
+ }
+ });
+ return true;
+});
+
diff --git a/test/suite/intl402/ch06/6.2/6.2.3.js b/test/suite/intl402/ch06/6.2/6.2.3.js
new file mode 100644
index 000000000..ce273e198
--- /dev/null
+++ b/test/suite/intl402/ch06/6.2/6.2.3.js
@@ -0,0 +1,68 @@
+// Copyright 2011-2012 Norbert Lindenberg. All rights reserved.
+// Copyright 2012 Mozilla Corporation. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/**
+ * @description Tests that language tags are canonicalized in return values.
+ * @author Norbert Lindenberg
+ */
+
+$INCLUDE("testIntl.js");
+
+var canonicalizedTags = {
+ "de": ["de"],
+ "de-DE": ["de-DE", "de"],
+ "DE-de": ["de-DE", "de"],
+ "cmn": ["cmn"],
+ "CMN-hANS": ["cmn-Hans", "cmn"],
+ "cmn-hans-cn": ["cmn-Hans-CN", "cmn-Hans", "cmn"],
+ "es-419": ["es-419", "es"],
+ "es-419-u-nu-latn": ["es-419-u-nu-latn", "es-419", "es", "es-u-nu-latn"],
+ // -u-ca is incomplete, so it will not show up in resolvedOptions().locale
+ "cmn-hans-cn-u-ca-t-ca-x-t-u": ["cmn-Hans-CN-t-ca-u-ca-x-t-u", "cmn-Hans-CN-t-ca-x-t-u", "cmn-Hans-CN-t-ca-x-t", "cmn-Hans-CN-t-ca", "cmn-Hans-CN", "cmn-Hans", "cmn"],
+ "enochian-enochian": ["enochian-enochian", "enochian"],
+ "de-gregory-u-ca-gregory": ["de-gregory-u-ca-gregory", "de-gregory", "de-u-ca-gregory", "de"],
+ "no-nyn": ["nn"],
+ "i-klingon": ["tlh"],
+ "sgn-GR": ["gss"],
+ "ji": ["yi"],
+ "de-DD": ["de-DE", "de"],
+ "zh-hak-CN": ["hak-CN", "hak"],
+ "sgn-ils": ["ils"],
+ "in": ["id"]
+};
+
+// make sure the data above is correct
+Object.getOwnPropertyNames(canonicalizedTags).forEach(function (tag) {
+ canonicalizedTags[tag].forEach(function (canonicalTag) {
+ if (!isCanonicalizedStructurallyValidLanguageTag(canonicalTag)) {
+ $ERROR("Test data \"" + canonicalTag + "\" is not canonicalized and structurally valid language tag.");
+ }
+ });
+});
+
+// now the actual test
+testWithIntlConstructors(function (Constructor) {
+ var defaultLocale = new Constructor().resolvedOptions().locale;
+ Object.getOwnPropertyNames(canonicalizedTags).forEach(function (tag) {
+ // use lookup locale matcher to keep the set of possible return values predictable
+
+ // Variant 1: construct an object and see whether its locale is canonicalized.
+ // In this variant, shortened forms or the default locale may be returned
+ var object = new Constructor([tag], {localeMatcher: "lookup"});
+ var locale = object.resolvedOptions().locale;
+ if (canonicalizedTags[tag].indexOf(locale) === -1 && locale !== defaultLocale) {
+ $ERROR("For " + tag + " got " + locale + "; expected one of " +
+ canonicalizedTags[tag].join(", ") + ".");
+ }
+
+ // Variant 2: get the supported locales. If the tag is supported, it should be returned canonicalized but unshortened
+ var supported = Constructor.supportedLocalesOf([tag]);
+ if (supported.length > 0 && supported[0] !== canonicalizedTags[tag][0]) {
+ $ERROR("For " + tag + " got " + supported[0] + "; expected " +
+ canonicalizedTags[tag][0] + ".");
+ }
+ });
+ return true;
+});
+
diff --git a/test/suite/intl402/ch06/6.2/6.2.4.js b/test/suite/intl402/ch06/6.2/6.2.4.js
new file mode 100644
index 000000000..6ca47af14
--- /dev/null
+++ b/test/suite/intl402/ch06/6.2/6.2.4.js
@@ -0,0 +1,19 @@
+// Copyright 2012 Mozilla Corporation. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/**
+ * @description Tests that the default locale is a String value representing the
+ * structurally valid and canonicalized BCP 47 language tag.
+ * @author Norbert Lindenberg
+ */
+
+$INCLUDE("testIntl.js");
+
+testWithIntlConstructors(function (Constructor) {
+ var defaultLocale = new Constructor().resolvedOptions().locale;
+ if (!isCanonicalizedStructurallyValidLanguageTag(defaultLocale)) {
+ $ERROR("Default locale \"" + defaultLocale + "\" is not canonicalized and structurally valid language tag.");
+ }
+ return true;
+});
+