summaryrefslogtreecommitdiffstats
path: root/js/src/tests/non262/Intl/DisplayNames/weekday.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/src/tests/non262/Intl/DisplayNames/weekday.js')
-rw-r--r--js/src/tests/non262/Intl/DisplayNames/weekday.js77
1 files changed, 77 insertions, 0 deletions
diff --git a/js/src/tests/non262/Intl/DisplayNames/weekday.js b/js/src/tests/non262/Intl/DisplayNames/weekday.js
new file mode 100644
index 0000000000..fd19f24bb1
--- /dev/null
+++ b/js/src/tests/non262/Intl/DisplayNames/weekday.js
@@ -0,0 +1,77 @@
+// |reftest| skip-if(!this.hasOwnProperty('Intl')||!this.hasOwnProperty('addIntlExtras'))
+
+addMozIntlDisplayNames(this);
+
+const tests = {
+ "en": {
+ long: ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"],
+ // short: ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"],
+ short: ["Mo", "Tu", "We", "Th", "Fr", "Sa", "Su"],
+ narrow: ["M", "T", "W", "T", "F", "S", "S"],
+ },
+ "de": {
+ long: ["Montag", "Dienstag", "Mittwoch", "Donnerstag", "Freitag", "Samstag", "Sonntag"],
+ // short: ["Mo", "Di", "Mi", "Do", "Fr", "Sa", "So"],
+ short: ["Mo.", "Di.", "Mi.", "Do.", "Fr.", "Sa.", "So."],
+ narrow: ["M", "D", "M", "D", "F", "S", "S"],
+ },
+ "fr": {
+ long: ["lundi", "mardi", "mercredi", "jeudi", "vendredi", "samedi", "dimanche"],
+ // short: ["lun.", "mar.", "mer.", "jeu.", "ven.", "sam.", "dim."],
+ short: ["lu", "ma", "me", "je", "ve", "sa", "di"],
+ narrow: ["L", "M", "M", "J", "V", "S", "D"],
+ },
+ "zh": {
+ long: ["星期一", "星期二", "星期三", "星期四", "星期五", "星期六", "星期日"],
+ 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: "weekday", style});
+
+ let resolved = dn.resolvedOptions();
+ assertEq(resolved.locale, locale);
+ assertEq(resolved.calendar, defaultCalendar);
+ assertEq(resolved.style, style);
+ assertEq(resolved.type, "weekday");
+ assertEq(resolved.fallback, "code");
+
+ for (let i = 0; i < 7; i++) {
+ assertEq(dn.of(i + 1), styleTests[i]);
+
+ // Also works with strings.
+ assertEq(dn.of(String(i + 1)), styleTests[i]);
+
+ // Also works with objects.
+ assertEq(dn.of(Object(i + 1)), styleTests[i]);
+ }
+ }
+}
+
+{
+ let dn = new Intl.DisplayNames("en", {type: "weekday"});
+
+ // 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);
+
+ // Throws an error if |code| isn't an integer.
+ assertThrowsInstanceOf(() => dn.of(1.5), RangeError);
+ assertThrowsInstanceOf(() => dn.of(-Infinity), RangeError);
+ assertThrowsInstanceOf(() => dn.of(Infinity), RangeError);
+ assertThrowsInstanceOf(() => dn.of(NaN), RangeError);
+
+ // Throws an error if outside of [1, 7].
+ assertThrowsInstanceOf(() => dn.of(-1), RangeError);
+ assertThrowsInstanceOf(() => dn.of(0), RangeError);
+ assertThrowsInstanceOf(() => dn.of(8), RangeError);
+}
+
+if (typeof reportCompare === "function")
+ reportCompare(true, true);