Debian Codegraph @

js/src/tests/test262/intl402/Intl/supportedValuesOf/calendars.js

raw
1 // Copyright (C) 2021 André Bargull. All rights reserved.
2 // This code is governed by the BSD license found in the LICENSE file.
3
4 /*---
5 esid: sec-intl.supportedvaluesof
6 description: >
7 The returned "calendar" values are sorted, unique, and match the type production.
8 info: |
9 Intl.supportedValuesOf ( key )
10
11 1. Let key be ? ToString(key).
12 2. If key is "calendar", then
13 a. Let list be ! AvailableCalendars( ).
14 ...
15 9. Return ! CreateArrayFromList( list ).
16
17 AvailableCalendars ( )
18 The AvailableCalendars abstract operation returns a List, ordered as if an
19 Array of the same values had been sorted using %Array.prototype.sort% using
20 undefined as comparefn, that contains unique calendar types identifying the
21 calendars for which the implementation provides the functionality of
22 Intl.DateTimeFormat objects. The list must include "gregory".
23 includes: [compareArray.js]
24 features: [Intl-enumeration, Intl.Locale, Array.prototype.includes]
25 ---*/
26
27 const calendars = Intl.supportedValuesOf("calendar");
28
29 assert(Array.isArray(calendars), "Returns an Array object.");
30 assert.sameValue(Object.getPrototypeOf(calendars), Array.prototype,
31 "The array prototype is Array.prototype");
32
33 const otherCalendars = Intl.supportedValuesOf("calendar");
34 assert.notSameValue(otherCalendars, calendars,
35 "Returns a new array object for each call.");
36
37 assert.compareArray(calendars, otherCalendars.sort(),
38 "The array is sorted.");
39
40 assert.sameValue(new Set(calendars).size, calendars.length,
41 "The array doesn't contain duplicates.");
42
43 // https://unicode.org/reports/tr35/tr35.html#Unicode_locale_identifier
44 const typeRE = /^[a-z0-9]{3,8}(-[a-z0-9]{3,8})*$/;
45 for (let calendar of calendars) {
46 assert(typeRE.test(calendar), `${calendar} matches the 'type' production`);
47 }
48
49 for (let calendar of calendars) {
50 assert.sameValue(new Intl.Locale("und", {calendar}).calendar, calendar,
51 `${calendar} is canonicalised`);
52 }
53
54 assert(calendars.includes("gregory"), "Includes the Gregorian calendar.");
55
56 reportCompare(0, 0);