summaryrefslogtreecommitdiffstats
path: root/js/src/tests/test262/intl402/ch06
diff options
context:
space:
mode:
Diffstat (limited to 'js/src/tests/test262/intl402/ch06')
-rw-r--r--js/src/tests/test262/intl402/ch06/6.2/6.2.2_a.js40
-rw-r--r--js/src/tests/test262/intl402/ch06/6.2/6.2.2_b.js41
-rw-r--r--js/src/tests/test262/intl402/ch06/6.2/6.2.2_c.js47
-rw-r--r--js/src/tests/test262/intl402/ch06/6.2/6.2.3.js69
-rw-r--r--js/src/tests/test262/intl402/ch06/6.2/6.2.4.js19
-rw-r--r--js/src/tests/test262/intl402/ch06/6.2/browser.js0
-rw-r--r--js/src/tests/test262/intl402/ch06/6.2/shell.js0
-rw-r--r--js/src/tests/test262/intl402/ch06/6.3/6.3.1_a.js25
-rw-r--r--js/src/tests/test262/intl402/ch06/6.3/6.3.1_b.js35
-rw-r--r--js/src/tests/test262/intl402/ch06/6.3/browser.js0
-rw-r--r--js/src/tests/test262/intl402/ch06/6.3/shell.js0
-rw-r--r--js/src/tests/test262/intl402/ch06/6.4/6.4_a.js22
-rw-r--r--js/src/tests/test262/intl402/ch06/6.4/6.4_b.js34
-rw-r--r--js/src/tests/test262/intl402/ch06/6.4/6.4_c.js36
-rw-r--r--js/src/tests/test262/intl402/ch06/6.4/browser.js0
-rw-r--r--js/src/tests/test262/intl402/ch06/6.4/shell.js0
-rw-r--r--js/src/tests/test262/intl402/ch06/browser.js0
-rw-r--r--js/src/tests/test262/intl402/ch06/shell.js0
18 files changed, 368 insertions, 0 deletions
diff --git a/js/src/tests/test262/intl402/ch06/6.2/6.2.2_a.js b/js/src/tests/test262/intl402/ch06/6.2/6.2.2_a.js
new file mode 100644
index 000000000..a56894570
--- /dev/null
+++ b/js/src/tests/test262/intl402/ch06/6.2/6.2.2_a.js
@@ -0,0 +1,40 @@
+// 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
+ "aa-a-foo-x-a-foo-bar", // variant subtags can also be used as private use subtags
+ "x-en-US-12345", // anything goes in private use tags
+ "x-12345-12345-en-US",
+ "x-en-US-12345-12345",
+ "x-en-u-foo",
+ "x-en-u-foo-u-bar"
+];
+
+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/js/src/tests/test262/intl402/ch06/6.2/6.2.2_b.js b/js/src/tests/test262/intl402/ch06/6.2/6.2.2_b.js
new file mode 100644
index 000000000..42d69e7c2
--- /dev/null
+++ b/js/src/tests/test262/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/js/src/tests/test262/intl402/ch06/6.2/6.2.2_c.js b/js/src/tests/test262/intl402/ch06/6.2/6.2.2_c.js
new file mode 100644
index 000000000..6d669ebef
--- /dev/null
+++ b/js/src/tests/test262/intl402/ch06/6.2/6.2.2_c.js
@@ -0,0 +1,47 @@
+// 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
+ "*", // language range
+ "de-*", // language range
+ "中文", // 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/js/src/tests/test262/intl402/ch06/6.2/6.2.3.js b/js/src/tests/test262/intl402/ch06/6.2/6.2.3.js
new file mode 100644
index 000000000..4ae15ab27
--- /dev/null
+++ b/js/src/tests/test262/intl402/ch06/6.2/6.2.3.js
@@ -0,0 +1,69 @@
+// 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"],
+ "x-foo": ["x-foo"]
+};
+
+// 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/js/src/tests/test262/intl402/ch06/6.2/6.2.4.js b/js/src/tests/test262/intl402/ch06/6.2/6.2.4.js
new file mode 100644
index 000000000..6ca47af14
--- /dev/null
+++ b/js/src/tests/test262/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;
+});
+
diff --git a/js/src/tests/test262/intl402/ch06/6.2/browser.js b/js/src/tests/test262/intl402/ch06/6.2/browser.js
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/js/src/tests/test262/intl402/ch06/6.2/browser.js
diff --git a/js/src/tests/test262/intl402/ch06/6.2/shell.js b/js/src/tests/test262/intl402/ch06/6.2/shell.js
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/js/src/tests/test262/intl402/ch06/6.2/shell.js
diff --git a/js/src/tests/test262/intl402/ch06/6.3/6.3.1_a.js b/js/src/tests/test262/intl402/ch06/6.3/6.3.1_a.js
new file mode 100644
index 000000000..01cc18b03
--- /dev/null
+++ b/js/src/tests/test262/intl402/ch06/6.3/6.3.1_a.js
@@ -0,0 +1,25 @@
+// Copyright 2012 Mozilla Corporation. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/**
+ * @description Tests that well-formed currency codes are accepted.
+ * @author Norbert Lindenberg
+ */
+
+var wellFormedCurrencyCodes = [
+ "BOB",
+ "EUR",
+ "usd", // currency codes are case-insensitive
+ "XdR",
+ "xTs"
+];
+
+wellFormedCurrencyCodes.forEach(function (code) {
+ // this must not throw an exception for a valid currency code
+ var format = new Intl.NumberFormat(["de-de"], {style: "currency", currency: code});
+ if (format.resolvedOptions().currency !== code.toUpperCase()) {
+ $ERROR("Currency " + code + " was not correctly accepted; turned into " +
+ format.resolvedOptions().currency + ".");
+ }
+});
+
diff --git a/js/src/tests/test262/intl402/ch06/6.3/6.3.1_b.js b/js/src/tests/test262/intl402/ch06/6.3/6.3.1_b.js
new file mode 100644
index 000000000..038dd1fc4
--- /dev/null
+++ b/js/src/tests/test262/intl402/ch06/6.3/6.3.1_b.js
@@ -0,0 +1,35 @@
+// Copyright 2012 Mozilla Corporation. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/**
+ * @description Tests that invalid currency codes are not accepted.
+ * @author Norbert Lindenberg
+ */
+
+var invalidCurrencyCodes = [
+ "",
+ "€",
+ "$",
+ "SFr.",
+ "DM",
+ "KR₩",
+ "702",
+ "ßP",
+ "ınr"
+];
+
+invalidCurrencyCodes.forEach(function (code) {
+ var error;
+ try {
+ // this must throw an exception for an invalid currency code
+ var format = new Intl.NumberFormat(["de-de"], {style: "currency", currency: code});
+ } catch (e) {
+ error = e;
+ }
+ if (error === undefined) {
+ $ERROR("Invalid currency code '" + code + "' was not rejected.");
+ } else if (error.name !== "RangeError") {
+ $ERROR("Invalid currency code '" + code + "' was rejected with wrong error " + error.name + ".");
+ }
+});
+
diff --git a/js/src/tests/test262/intl402/ch06/6.3/browser.js b/js/src/tests/test262/intl402/ch06/6.3/browser.js
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/js/src/tests/test262/intl402/ch06/6.3/browser.js
diff --git a/js/src/tests/test262/intl402/ch06/6.3/shell.js b/js/src/tests/test262/intl402/ch06/6.3/shell.js
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/js/src/tests/test262/intl402/ch06/6.3/shell.js
diff --git a/js/src/tests/test262/intl402/ch06/6.4/6.4_a.js b/js/src/tests/test262/intl402/ch06/6.4/6.4_a.js
new file mode 100644
index 000000000..05202353c
--- /dev/null
+++ b/js/src/tests/test262/intl402/ch06/6.4/6.4_a.js
@@ -0,0 +1,22 @@
+// Copyright 2012 Mozilla Corporation. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/**
+ * @description Tests that valid time zone names are accepted.
+ * @author Norbert Lindenberg
+ */
+
+var validTimeZoneNames = [
+ "UTC",
+ "utc" // time zone names are case-insensitive
+];
+
+validTimeZoneNames.forEach(function (name) {
+ // this must not throw an exception for a valid time zone name
+ var format = new Intl.DateTimeFormat(["de-de"], {timeZone: name});
+ if (format.resolvedOptions().timeZone !== name.toUpperCase()) {
+ $ERROR("Time zone name " + name + " was not correctly accepted; turned into " +
+ format.resolvedOptions().timeZone + ".");
+ }
+});
+
diff --git a/js/src/tests/test262/intl402/ch06/6.4/6.4_b.js b/js/src/tests/test262/intl402/ch06/6.4/6.4_b.js
new file mode 100644
index 000000000..847d804e3
--- /dev/null
+++ b/js/src/tests/test262/intl402/ch06/6.4/6.4_b.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 invalid time zone names are not accepted.
+ * @author Norbert Lindenberg
+ */
+
+var invalidTimeZoneNames = [
+ "",
+ "MEZ", // localized abbreviation
+ "Pacific Time", // localized long form
+ "cnsha", // BCP 47 time zone code
+ "invalid", // as the name says
+ "Europe/İstanbul", // non-ASCII letter
+ "asıa/baku", // non-ASCII letter
+ "europe/brußels" // non-ASCII letter
+];
+
+invalidTimeZoneNames.forEach(function (name) {
+ var error;
+ try {
+ // this must throw an exception for an invalid time zone name
+ var format = new Intl.DateTimeFormat(["de-de"], {timeZone: name});
+ } catch (e) {
+ error = e;
+ }
+ if (error === undefined) {
+ $ERROR("Invalid time zone name " + name + " was not rejected.");
+ } else if (error.name !== "RangeError") {
+ $ERROR("Invalid time zone name " + name + " was rejected with wrong error " + error.name + ".");
+ }
+});
+
diff --git a/js/src/tests/test262/intl402/ch06/6.4/6.4_c.js b/js/src/tests/test262/intl402/ch06/6.4/6.4_c.js
new file mode 100644
index 000000000..a9969b648
--- /dev/null
+++ b/js/src/tests/test262/intl402/ch06/6.4/6.4_c.js
@@ -0,0 +1,36 @@
+// Copyright 2012 Mozilla Corporation. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/**
+ * @description Tests that additional time zone names, if accepted, are handled correctly.
+ * @author Norbert Lindenberg
+ */
+
+// canonicalization specified in conformance clause
+var additionalTimeZoneNames = {
+ "Etc/GMT": "UTC",
+ "Greenwich": "UTC",
+ "PRC": "Asia/Shanghai",
+ "AmErIcA/LoS_aNgElEs": "America/Los_Angeles",
+ "etc/gmt+7": "Etc/GMT+7"
+};
+
+Object.getOwnPropertyNames(additionalTimeZoneNames).forEach(function (name) {
+ var format, error;
+ try {
+ format = new Intl.DateTimeFormat([], {timeZone: name});
+ } catch (e) {
+ error = e;
+ }
+ if (error === undefined) {
+ var actual = format.resolvedOptions().timeZone;
+ var expected = additionalTimeZoneNames[name];
+ if (actual !== expected) {
+ $ERROR("Time zone name " + name + " was accepted, but incorrectly canonicalized to " +
+ actual + "; expected " + expected + ".");
+ }
+ } else if (error.name !== "RangeError") {
+ $ERROR("Time zone name " + name + " was rejected with wrong error " + error.name + ".");
+ }
+});
+
diff --git a/js/src/tests/test262/intl402/ch06/6.4/browser.js b/js/src/tests/test262/intl402/ch06/6.4/browser.js
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/js/src/tests/test262/intl402/ch06/6.4/browser.js
diff --git a/js/src/tests/test262/intl402/ch06/6.4/shell.js b/js/src/tests/test262/intl402/ch06/6.4/shell.js
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/js/src/tests/test262/intl402/ch06/6.4/shell.js
diff --git a/js/src/tests/test262/intl402/ch06/browser.js b/js/src/tests/test262/intl402/ch06/browser.js
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/js/src/tests/test262/intl402/ch06/browser.js
diff --git a/js/src/tests/test262/intl402/ch06/shell.js b/js/src/tests/test262/intl402/ch06/shell.js
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/js/src/tests/test262/intl402/ch06/shell.js