Debian Codegraph @

js/src/tests/non262/Intl/DisplayNames/weekday.js

raw
1 // |reftest| skip-if(!this.hasOwnProperty('Intl')||!this.hasOwnProperty('addIntlExtras'))
2
3 addMozIntlDisplayNames(this);
4
5 const tests = {
6 "en": {
7 long: ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"],
8 // short: ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"],
9 short: ["Mo", "Tu", "We", "Th", "Fr", "Sa", "Su"],
10 narrow: ["M", "T", "W", "T", "F", "S", "S"],
11 },
12 "de": {
13 long: ["Montag", "Dienstag", "Mittwoch", "Donnerstag", "Freitag", "Samstag", "Sonntag"],
14 // short: ["Mo", "Di", "Mi", "Do", "Fr", "Sa", "So"],
15 short: ["Mo.", "Di.", "Mi.", "Do.", "Fr.", "Sa.", "So."],
16 narrow: ["M", "D", "M", "D", "F", "S", "S"],
17 },
18 "fr": {
19 long: ["lundi", "mardi", "mercredi", "jeudi", "vendredi", "samedi", "dimanche"],
20 // short: ["lun.", "mar.", "mer.", "jeu.", "ven.", "sam.", "dim."],
21 short: ["lu", "ma", "me", "je", "ve", "sa", "di"],
22 narrow: ["L", "M", "M", "J", "V", "S", "D"],
23 },
24 "zh": {
25 long: ["星期一", "星期二", "星期三", "星期四", "星期五", "星期六", "星期日"],
26 short: ["周一", "周二", "周三", "周四", "周五", "周六", "周日"],
27 narrow: ["一", "二", "三", "四", "五", "六", "日"],
28 },
29 };
30
31 for (let [locale, localeTests] of Object.entries(tests)) {
32 let defaultCalendar = new Intl.DateTimeFormat(locale).resolvedOptions().calendar;
33
34 for (let [style, styleTests] of Object.entries(localeTests)) {
35 let dn = new Intl.DisplayNames(locale, {type: "weekday", style});
36
37 let resolved = dn.resolvedOptions();
38 assertEq(resolved.locale, locale);
39 assertEq(resolved.calendar, defaultCalendar);
40 assertEq(resolved.style, style);
41 assertEq(resolved.type, "weekday");
42 assertEq(resolved.fallback, "code");
43
44 for (let i = 0; i < 7; i++) {
45 assertEq(dn.of(i + 1), styleTests[i]);
46
47 // Also works with strings.
48 assertEq(dn.of(String(i + 1)), styleTests[i]);
49
50 // Also works with objects.
51 assertEq(dn.of(Object(i + 1)), styleTests[i]);
52 }
53 }
54 }
55
56 {
57 let dn = new Intl.DisplayNames("en", {type: "weekday"});
58
59 // Performs ToString on the input and then validates the stringified result.
60 assertThrowsInstanceOf(() => dn.of(), RangeError);
61 assertThrowsInstanceOf(() => dn.of(null), RangeError);
62 assertThrowsInstanceOf(() => dn.of(Symbol()), TypeError);
63
64 // Throws an error if |code| isn't an integer.
65 assertThrowsInstanceOf(() => dn.of(1.5), RangeError);
66 assertThrowsInstanceOf(() => dn.of(-Infinity), RangeError);
67 assertThrowsInstanceOf(() => dn.of(Infinity), RangeError);
68 assertThrowsInstanceOf(() => dn.of(NaN), RangeError);
69
70 // Throws an error if outside of [1, 7].
71 assertThrowsInstanceOf(() => dn.of(-1), RangeError);
72 assertThrowsInstanceOf(() => dn.of(0), RangeError);
73 assertThrowsInstanceOf(() => dn.of(8), RangeError);
74 }
75
76 if (typeof reportCompare === "function")
77 reportCompare(true, true);