summaryrefslogtreecommitdiffstats
path: root/js/src/tests/non262/Intl/DisplayNames/dayPeriod.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
commit36d22d82aa202bb199967e9512281e9a53db42c9 (patch)
tree105e8c98ddea1c1e4784a60a5a6410fa416be2de /js/src/tests/non262/Intl/DisplayNames/dayPeriod.js
parentInitial commit. (diff)
downloadfirefox-esr-upstream.tar.xz
firefox-esr-upstream.zip
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'js/src/tests/non262/Intl/DisplayNames/dayPeriod.js')
-rw-r--r--js/src/tests/non262/Intl/DisplayNames/dayPeriod.js80
1 files changed, 80 insertions, 0 deletions
diff --git a/js/src/tests/non262/Intl/DisplayNames/dayPeriod.js b/js/src/tests/non262/Intl/DisplayNames/dayPeriod.js
new file mode 100644
index 0000000000..cfeafdf5ee
--- /dev/null
+++ b/js/src/tests/non262/Intl/DisplayNames/dayPeriod.js
@@ -0,0 +1,80 @@
+// |reftest| skip-if(!this.hasOwnProperty('Intl')||!this.hasOwnProperty('addIntlExtras'))
+
+addMozIntlDisplayNames(this);
+
+const tests = {
+ "en": {
+ long: {
+ "am": "AM",
+ "pm": "PM",
+ },
+ short: {},
+ narrow: {},
+ },
+ "de": {
+ long: {
+ "am": "AM",
+ "pm": "PM",
+ },
+ short: {},
+ narrow: {},
+ },
+ "fr": {
+ long: {
+ "am": "AM",
+ "pm": "PM",
+ },
+ short: {},
+ narrow: {},
+ },
+ "zh": {
+ long: {
+ "am": "上午",
+ "pm": "下午",
+ },
+ short: {},
+ narrow: {},
+ },
+};
+
+for (let [locale, localeTests] of Object.entries(tests)) {
+ let defaultCalendar = new Intl.DateTimeFormat(locale).resolvedOptions().calendar;
+
+ for (let [style, styleTests] of Object.entries(localeTests)) {
+ let dn = new Intl.DisplayNames(locale, {type: "dayPeriod", style});
+
+ let resolved = dn.resolvedOptions();
+ assertEq(resolved.locale, locale);
+ assertEq(resolved.calendar, defaultCalendar);
+ assertEq(resolved.style, style);
+ assertEq(resolved.type, "dayPeriod");
+ assertEq(resolved.fallback, "code");
+
+ let inheritedTests = {...localeTests.long, ...localeTests.short, ...localeTests.narrow};
+ for (let [dayPeriod, expected] of Object.entries({...inheritedTests, ...styleTests})) {
+ assertEq(dn.of(dayPeriod), expected);
+
+ // Also works with objects.
+ assertEq(dn.of(Object(dayPeriod)), expected);
+ }
+ }
+}
+
+{
+ let dn = new Intl.DisplayNames("en", {type: "dayPeriod"});
+
+ // Performs ToString on the input and then validates the stringified result.
+ assertThrowsInstanceOf(() => dn.of(), RangeError);
+ assertThrowsInstanceOf(() => dn.of(null), RangeError);
+ assertThrowsInstanceOf(() => dn.of(Symbol()), TypeError);
+ assertThrowsInstanceOf(() => dn.of(0), RangeError);
+ assertThrowsInstanceOf(() => dn.of(1), RangeError);
+
+ // Throws an error if not one of ["am", "pm"].
+ assertThrowsInstanceOf(() => dn.of(""), RangeError);
+ assertThrowsInstanceOf(() => dn.of("AM"), RangeError);
+ assertThrowsInstanceOf(() => dn.of("PM"), RangeError);
+}
+
+if (typeof reportCompare === "function")
+ reportCompare(true, true);