summaryrefslogtreecommitdiffstats
path: root/js/src/tests/non262/Intl/ListFormat
diff options
context:
space:
mode:
Diffstat (limited to 'js/src/tests/non262/Intl/ListFormat')
-rw-r--r--js/src/tests/non262/Intl/ListFormat/browser.js0
-rw-r--r--js/src/tests/non262/Intl/ListFormat/conjunction-type.js116
-rw-r--r--js/src/tests/non262/Intl/ListFormat/cross-compartment.js42
-rw-r--r--js/src/tests/non262/Intl/ListFormat/disjunction-type.js108
-rw-r--r--js/src/tests/non262/Intl/ListFormat/same-compartment.js40
-rw-r--r--js/src/tests/non262/Intl/ListFormat/shell.js21
-rw-r--r--js/src/tests/non262/Intl/ListFormat/supported-locales.js18
-rw-r--r--js/src/tests/non262/Intl/ListFormat/unit-type.js149
8 files changed, 494 insertions, 0 deletions
diff --git a/js/src/tests/non262/Intl/ListFormat/browser.js b/js/src/tests/non262/Intl/ListFormat/browser.js
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/js/src/tests/non262/Intl/ListFormat/browser.js
diff --git a/js/src/tests/non262/Intl/ListFormat/conjunction-type.js b/js/src/tests/non262/Intl/ListFormat/conjunction-type.js
new file mode 100644
index 0000000000..320a235271
--- /dev/null
+++ b/js/src/tests/non262/Intl/ListFormat/conjunction-type.js
@@ -0,0 +1,116 @@
+// |reftest| skip-if(!this.hasOwnProperty('Intl'))
+
+// Note: Use the same test locales as used in unit-type.js
+
+const {Element, Literal} = ListFormatParts;
+const styles = ["long", "short", "narrow"];
+
+// Test with zero elements.
+{
+ const list = [];
+ const expected = [];
+ const locales = ["ar", "de", "en", "es", "ja", "nl", "th", "zh"];
+
+ for (let locale of locales) {
+ for (let style of styles) {
+ let lf = new Intl.ListFormat(locale, {type: "conjunction", style});
+ assertParts(lf, list, expected);
+ }
+ }
+}
+
+// Test with one element.
+{
+ const list = ["A"];
+ const expected = [Element(list[0])];
+ const locales = ["ar", "de", "en", "es", "ja", "nl", "th", "zh"];
+
+ for (let locale of locales) {
+ for (let style of styles) {
+ let lf = new Intl.ListFormat(locale, {type: "conjunction", style});
+ assertParts(lf, list, expected);
+ }
+ }
+}
+
+// Test with two elements to cover the [[Template2]] case.
+{
+ const list = ["A", "B"];
+
+ const testData = {
+ "ar": { long: [Element("A"), Literal(" و"), Element("B")] },
+ "de": { long: [Element("A"), Literal(" und "), Element("B")] },
+ "en": {
+ long: [Element("A"), Literal(" and "), Element("B")],
+ short: [Element("A"), Literal(" & "), Element("B")],
+ narrow: [Element("A"), Literal(", "), Element("B")],
+ },
+ "es": { long: [Element("A"), Literal(" y "), Element("B")] },
+ "ja": { long: [Element("A"), Literal("、"), Element("B")] },
+ "nl": { long: [Element("A"), Literal(" en "), Element("B")] },
+ "th": { long: [Element("A"), Literal("และ"), Element("B")] },
+ "zh": {
+ long: [Element("A"), Literal("和"), Element("B")],
+ narrow: [Element("A"), Literal("、"), Element("B")],
+ },
+ };
+
+ for (let [locale, localeData] of Object.entries(testData)) {
+ for (let style of styles) {
+ let lf = new Intl.ListFormat(locale, {type: "conjunction", style});
+ let {[style]: expected = localeData.long} = localeData;
+ assertParts(lf, list, expected);
+ }
+ }
+}
+
+// Test with more than two elements.
+//
+// Use four elements to cover all template parts ([[TemplateStart]], [[TemplateMiddle]], and
+// [[TemplateEnd]]).
+{
+ const list = ["A", "B", "C", "D"];
+
+ const testData = {
+ "ar": {
+ long: [Element("A"), Literal(" و"), Element("B"), Literal(" و"), Element("C"), Literal(" و"), Element("D")],
+ short: [Element("A"), Literal(" و"), Element("B"), Literal(" و"), Element("C"), Literal(" و"), Element("D")],
+ narrow: [Element("A"), Literal(" و"), Element("B"), Literal(" و"), Element("C"), Literal(" و"), Element("D")],
+ },
+ "de": {
+ long: [Element("A"), Literal(", "), Element("B"), Literal(", "), Element("C"), Literal(" und "), Element("D")],
+ },
+ "en": {
+ long: [Element("A"), Literal(", "), Element("B"), Literal(", "), Element("C"), Literal(", and "), Element("D")],
+ short: [Element("A"), Literal(", "), Element("B"), Literal(", "), Element("C"), Literal(", & "), Element("D")],
+ narrow: [Element("A"), Literal(", "), Element("B"), Literal(", "), Element("C"), Literal(", "), Element("D")],
+ },
+ "es": {
+ long: [Element("A"), Literal(", "), Element("B"), Literal(", "), Element("C"), Literal(" y "), Element("D")],
+ },
+ "ja": {
+ long: [Element("A"), Literal("、"), Element("B"), Literal("、"), Element("C"), Literal("、"), Element("D")],
+ },
+ "nl": {
+ long: [Element("A"), Literal(", "), Element("B"), Literal(", "), Element("C"), Literal(" en "), Element("D")],
+ },
+ "th": {
+ long: [Element("A"), Literal(" "), Element("B"), Literal(" "), Element("C"), Literal(" และ"), Element("D")],
+ },
+ "zh": {
+ long: [Element("A"), Literal("、"), Element("B"), Literal("、"), Element("C"), Literal("和"), Element("D")],
+ narrow: [Element("A"), Literal("、"), Element("B"), Literal("、"), Element("C"), Literal("、"), Element("D")],
+ },
+ };
+
+ for (let [locale, localeData] of Object.entries(testData)) {
+ for (let style of styles) {
+ let lf = new Intl.ListFormat(locale, {type: "conjunction", style});
+ let {[style]: expected = localeData.long} = localeData;
+ assertParts(lf, list, expected);
+ }
+ }
+}
+
+if (typeof reportCompare === "function")
+ reportCompare(0, 0);
diff --git a/js/src/tests/non262/Intl/ListFormat/cross-compartment.js b/js/src/tests/non262/Intl/ListFormat/cross-compartment.js
new file mode 100644
index 0000000000..37c45ef75c
--- /dev/null
+++ b/js/src/tests/non262/Intl/ListFormat/cross-compartment.js
@@ -0,0 +1,42 @@
+// |reftest| skip-if(!this.hasOwnProperty('Intl'))
+
+var g = newGlobal();
+
+var locale = "en";
+var list = ["a", "b", "c"];
+
+var listFormat = new Intl.ListFormat(locale);
+var ccwListFormat = new g.Intl.ListFormat(locale);
+
+// Intl.ListFormat.prototype.format
+{
+ var fn = Intl.ListFormat.prototype.format;
+
+ var expectedValue = fn.call(listFormat, list);
+ var actualValue = fn.call(ccwListFormat, list);
+
+ assertEq(actualValue, expectedValue);
+}
+
+// Intl.ListFormat.prototype.formatToParts
+{
+ var fn = Intl.ListFormat.prototype.formatToParts;
+
+ var expectedValue = fn.call(listFormat, list);
+ var actualValue = fn.call(ccwListFormat, list);
+
+ assertDeepEq(actualValue, expectedValue);
+}
+
+// Intl.ListFormat.prototype.resolvedOptions
+{
+ var fn = Intl.ListFormat.prototype.resolvedOptions;
+
+ var expectedValue = fn.call(listFormat);
+ var actualValue = fn.call(ccwListFormat);
+
+ assertDeepEq(actualValue, expectedValue);
+}
+
+if (typeof reportCompare === "function")
+ reportCompare(0, 0);
diff --git a/js/src/tests/non262/Intl/ListFormat/disjunction-type.js b/js/src/tests/non262/Intl/ListFormat/disjunction-type.js
new file mode 100644
index 0000000000..2713a8ae07
--- /dev/null
+++ b/js/src/tests/non262/Intl/ListFormat/disjunction-type.js
@@ -0,0 +1,108 @@
+// |reftest| skip-if(!this.hasOwnProperty('Intl'))
+
+// Note: Use the same test locales as used in unit-type.js
+
+const {Element, Literal} = ListFormatParts;
+const styles = ["long", "short", "narrow"];
+
+// Test with zero elements.
+{
+ const list = [];
+ const expected = [];
+ const locales = ["ar", "de", "en", "es", "ja", "nl", "th", "zh"];
+
+ for (let locale of locales) {
+ for (let style of styles) {
+ let lf = new Intl.ListFormat(locale, {type: "disjunction", style});
+ assertParts(lf, list, expected);
+ }
+ }
+}
+
+// Test with one element.
+{
+ const list = ["A"];
+ const expected = [Element(list[0])];
+ const locales = ["ar", "de", "en", "es", "ja", "nl", "th", "zh"];
+
+ for (let locale of locales) {
+ for (let style of styles) {
+ let lf = new Intl.ListFormat(locale, {type: "disjunction", style});
+ assertParts(lf, list, expected);
+ }
+ }
+}
+
+// Test with two elements to cover the [[Template2]] case.
+{
+ const list = ["A", "B"];
+
+ const testData = {
+ "ar": { long: [Element("A"), Literal(" أو "), Element("B")] },
+ "de": { long: [Element("A"), Literal(" oder "), Element("B")] },
+ "en": { long: [Element("A"), Literal(" or "), Element("B")] },
+ "es": { long: [Element("A"), Literal(" o "), Element("B")] },
+ "ja": { long: [Element("A"), Literal("または"), Element("B")] },
+ "nl": { long: [Element("A"), Literal(" of "), Element("B")] },
+ "th": {
+ long: [Element("A"), Literal(" หรือ "), Element("B")],
+ short: [Element("A"), Literal("หรือ"), Element("B")],
+ narrow: [Element("A"), Literal("หรือ"), Element("B")],
+ },
+ "zh": { long: [Element("A"), Literal("或"), Element("B")] },
+ };
+
+ for (let [locale, localeData] of Object.entries(testData)) {
+ for (let style of styles) {
+ let lf = new Intl.ListFormat(locale, {type: "disjunction", style});
+ let {[style]: expected = localeData.long} = localeData;
+ assertParts(lf, list, expected);
+ }
+ }
+}
+
+// Test with more than two elements.
+//
+// Use four elements to cover all template parts ([[TemplateStart]], [[TemplateMiddle]], and
+// [[TemplateEnd]]).
+{
+ const list = ["A", "B", "C", "D"];
+
+ const testData = {
+ "ar": {
+ long: [Element("A"), Literal(" أو "), Element("B"), Literal(" أو "), Element("C"), Literal(" أو "), Element("D")],
+ },
+ "de": {
+ long: [Element("A"), Literal(", "), Element("B"), Literal(", "), Element("C"), Literal(" oder "), Element("D")],
+ },
+ "en": {
+ long: [Element("A"), Literal(", "), Element("B"), Literal(", "), Element("C"), Literal(", or "), Element("D")],
+ },
+ "es": {
+ long: [Element("A"), Literal(", "), Element("B"), Literal(", "), Element("C"), Literal(" o "), Element("D")],
+ },
+ "ja": {
+ long: [Element("A"), Literal("、"), Element("B"), Literal("、"), Element("C"), Literal("、または"), Element("D")],
+ },
+ "nl": {
+ long: [Element("A"), Literal(", "), Element("B"), Literal(", "), Element("C"), Literal(" of "), Element("D")],
+ },
+ "th": {
+ long: [Element("A"), Literal(", "), Element("B"), Literal(", "), Element("C"), Literal(" หรือ "), Element("D")],
+ },
+ "zh": {
+ long: [Element("A"), Literal("、"), Element("B"), Literal("、"), Element("C"), Literal("或"), Element("D")],
+ },
+ };
+
+ for (let [locale, localeData] of Object.entries(testData)) {
+ for (let style of styles) {
+ let lf = new Intl.ListFormat(locale, {type: "disjunction", style});
+ let {[style]: expected = localeData.long} = localeData;
+ assertParts(lf, list, expected);
+ }
+ }
+}
+
+if (typeof reportCompare === "function")
+ reportCompare(0, 0);
diff --git a/js/src/tests/non262/Intl/ListFormat/same-compartment.js b/js/src/tests/non262/Intl/ListFormat/same-compartment.js
new file mode 100644
index 0000000000..a51a041a08
--- /dev/null
+++ b/js/src/tests/non262/Intl/ListFormat/same-compartment.js
@@ -0,0 +1,40 @@
+// |reftest| skip-if(!this.hasOwnProperty('Intl')||!this.wrapWithProto)
+
+var locale = "en";
+var list = ["a", "b", "c"];
+
+var listFormat = new Intl.ListFormat(locale);
+var scwListFormat = wrapWithProto(listFormat, Intl.ListFormat.prototype);
+
+// Intl.ListFormat.prototype.format
+{
+ var fn = Intl.ListFormat.prototype.format;
+
+ var expectedValue = fn.call(listFormat, list);
+ var actualValue = fn.call(scwListFormat, list);
+
+ assertEq(actualValue, expectedValue);
+}
+
+// Intl.ListFormat.prototype.formatToParts
+{
+ var fn = Intl.ListFormat.prototype.formatToParts;
+
+ var expectedValue = fn.call(listFormat, list);
+ var actualValue = fn.call(scwListFormat, list);
+
+ assertDeepEq(actualValue, expectedValue);
+}
+
+// Intl.ListFormat.prototype.resolvedOptions
+{
+ var fn = Intl.ListFormat.prototype.resolvedOptions;
+
+ var expectedValue = fn.call(listFormat);
+ var actualValue = fn.call(scwListFormat);
+
+ assertDeepEq(actualValue, expectedValue);
+}
+
+if (typeof reportCompare === "function")
+ reportCompare(0, 0);
diff --git a/js/src/tests/non262/Intl/ListFormat/shell.js b/js/src/tests/non262/Intl/ListFormat/shell.js
new file mode 100644
index 0000000000..70056a579e
--- /dev/null
+++ b/js/src/tests/non262/Intl/ListFormat/shell.js
@@ -0,0 +1,21 @@
+function GenericPartCreator(type) {
+ return str => ({ type, value: str });
+}
+
+const ListFormatParts = {
+ Element: GenericPartCreator("element"),
+ Literal: GenericPartCreator("literal"),
+};
+
+function assertParts(lf, x, expected) {
+ var parts = lf.formatToParts(x);
+ assertEq(parts.map(part => part.value).join(""), lf.format(x),
+ "formatToParts and format must agree");
+
+ var len = parts.length;
+ assertEq(len, expected.length, "parts count mismatch");
+ for (var i = 0; i < len; i++) {
+ assertEq(parts[i].type, expected[i].type, "type mismatch at " + i);
+ assertEq(parts[i].value, expected[i].value, "value mismatch at " + i);
+ }
+}
diff --git a/js/src/tests/non262/Intl/ListFormat/supported-locales.js b/js/src/tests/non262/Intl/ListFormat/supported-locales.js
new file mode 100644
index 0000000000..f5d05e2da5
--- /dev/null
+++ b/js/src/tests/non262/Intl/ListFormat/supported-locales.js
@@ -0,0 +1,18 @@
+// |reftest| skip-if(!this.hasOwnProperty('Intl'))
+
+// Intl.ListFormat.supportedLocalesOf returns an empty array for unsupported locales.
+assertEq(Intl.ListFormat.supportedLocalesOf("art-lobjan").length, 0);
+
+// And a non-empty array for supported locales.
+assertEq(Intl.ListFormat.supportedLocalesOf("en").length, 1);
+assertEq(Intl.ListFormat.supportedLocalesOf("en")[0], "en");
+
+// If the locale is supported per |Intl.ListFormat.supportedLocalesOf|, the resolved locale
+// should reflect this.
+for (let locale of Intl.ListFormat.supportedLocalesOf(["en", "de", "th", "ar"])) {
+ let lf = new Intl.ListFormat(locale);
+ assertEq(lf.resolvedOptions().locale, locale);
+}
+
+if (typeof reportCompare === "function")
+ reportCompare(0, 0);
diff --git a/js/src/tests/non262/Intl/ListFormat/unit-type.js b/js/src/tests/non262/Intl/ListFormat/unit-type.js
new file mode 100644
index 0000000000..8c76677865
--- /dev/null
+++ b/js/src/tests/non262/Intl/ListFormat/unit-type.js
@@ -0,0 +1,149 @@
+// |reftest| skip -- "unit" type currently not supported
+
+const {Element, Literal} = ListFormatParts;
+const styles = ["long", "short", "narrow"];
+
+// Test with zero elements.
+{
+ const list = [];
+ const expected = [];
+ const locales = ["ar", "de", "en", "es", "ja", "nl", "th", "zh"];
+
+ for (let locale of locales) {
+ for (let style of styles) {
+ let lf = new Intl.ListFormat(locale, {type: "unit", style});
+ assertParts(lf, list, expected);
+ }
+ }
+}
+
+// Test with one element.
+{
+ const list = ["A"];
+ const expected = [Element(list[0])];
+ const locales = ["ar", "de", "en", "es", "ja", "nl", "th", "zh"];
+
+ for (let locale of locales) {
+ for (let style of styles) {
+ let lf = new Intl.ListFormat(locale, {type: "unit", style});
+ assertParts(lf, list, expected);
+ }
+ }
+}
+
+// Test with two elements to cover the [[Template2]] case.
+{
+ const list = ["A", "B"];
+
+ const testData = {
+ "ar": {
+ long: [Element("A"), Literal(" و"), Element("B")],
+ narrow: [Element("A"), Literal("، "), Element("B")],
+ },
+ "de": {
+ long: [Element("A"), Literal(", "), Element("B")],
+ },
+ "en": {
+ long: [Element("A"), Literal(", "), Element("B")],
+ narrow: [Element("A"), Literal(" "), Element("B")],
+ },
+ "es": {
+ long: [Element("A"), Literal(" y "), Element("B")],
+ narrow: [Element("A"), Literal(" "), Element("B")],
+ },
+ "ja": {
+ long: [Element("A"), Literal(" "), Element("B")],
+ narrow: [Element("A"), Element("B")],
+ },
+ "nl": {
+ long: [Element("A"), Literal(" en "), Element("B")],
+ short: [Element("A"), Literal(", "), Element("B")],
+ narrow: [Element("A"), Literal(", "), Element("B")],
+ },
+ "th": {
+ long: [Element("A"), Literal(" และ "), Element("B")],
+ short: [Element("A"), Literal(" "), Element("B")],
+ narrow: [Element("A"), Literal(" "), Element("B")],
+ },
+ "zh": {
+ long: [Element("A"), Element("B")],
+ },
+ };
+
+ for (let [locale, localeData] of Object.entries(testData)) {
+ for (let style of styles) {
+ let lf = new Intl.ListFormat(locale, {type: "unit", style});
+ let {[style]: expected = localeData.long} = localeData;
+ assertParts(lf, list, expected);
+ }
+ }
+}
+
+// Test with more than two elements.
+//
+// Use four elements to cover all template parts ([[TemplateStart]], [[TemplateMiddle]], and
+// [[TemplateEnd]]).
+{
+ const list = ["A", "B", "C", "D"];
+
+ const testData = {
+ // non-ASCII case
+ "ar": {
+ long: [Element("A"), Literal("، و"), Element("B"), Literal("، و"), Element("C"), Literal("، و"), Element("D")],
+ narrow: [Element("A"), Literal("، "), Element("B"), Literal("، "), Element("C"), Literal("، "), Element("D")],
+ },
+
+ // all values are equal
+ "de": {
+ long: [Element("A"), Literal(", "), Element("B"), Literal(", "), Element("C"), Literal(" und "), Element("D")],
+ },
+
+ // long and short values are equal
+ "en": {
+ long: [Element("A"), Literal(", "), Element("B"), Literal(", "), Element("C"), Literal(", "), Element("D")],
+ narrow: [Element("A"), Literal(" "), Element("B"), Literal(" "), Element("C"), Literal(" "), Element("D")],
+ },
+
+ // all values are different
+ "es": {
+ long: [Element("A"), Literal(", "), Element("B"), Literal(", "), Element("C"), Literal(" y "), Element("D")],
+ short: [Element("A"), Literal(", "), Element("B"), Literal(", "), Element("C"), Literal(", "), Element("D")],
+ narrow: [Element("A"), Literal(" "), Element("B"), Literal(" "), Element("C"), Literal(" "), Element("D")],
+ },
+
+ // no spacing for narrow case
+ "ja": {
+ long: [Element("A"), Literal(" "), Element("B"), Literal(" "), Element("C"), Literal(" "), Element("D")],
+ narrow: [Element("A"), Element("B"), Element("C"), Element("D")],
+ },
+
+ // short and narrow values are equal
+ "nl": {
+ long: [Element("A"), Literal(", "), Element("B"), Literal(", "), Element("C"), Literal(" en "), Element("D")],
+ short: [Element("A"), Literal(", "), Element("B"), Literal(", "), Element("C"), Literal(", "), Element("D")],
+ narrow: [Element("A"), Literal(", "), Element("B"), Literal(", "), Element("C"), Literal(", "), Element("D")],
+ },
+
+ // another non-ASCII case
+ "th": {
+ long: [Element("A"), Literal(" "), Element("B"), Literal(" "), Element("C"), Literal(" และ "), Element("D")],
+ narrow: [Element("A"), Literal(" "), Element("B"), Literal(" "), Element("C"), Literal(" "), Element("D")],
+ },
+
+ // no whitespace at all
+ "zh": {
+ long: [Element("A"), Element("B"), Element("C"), Element("D")],
+ },
+ };
+
+ for (let [locale, localeData] of Object.entries(testData)) {
+ for (let style of styles) {
+ let lf = new Intl.ListFormat(locale, {type: "unit", style});
+ let {[style]: expected = localeData.long} = localeData;
+ assertParts(lf, list, expected);
+ }
+ }
+}
+
+if (typeof reportCompare === "function")
+ reportCompare(0, 0);