Skip to content

Commit 675bec4

Browse files
feat: tests
1 parent d9add51 commit 675bec4

27 files changed

+755
-54
lines changed

src/Core__Intl.mjs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ var Collator;
55

66
var DateTimeFormat;
77

8+
var ListFormat;
9+
810
var Locale;
911

1012
var NumberFormat;
@@ -13,12 +15,19 @@ var PluralRules;
1315

1416
var RelativeTimeFormat;
1517

18+
var Segmenter;
19+
20+
var Segments;
21+
1622
export {
1723
Collator ,
1824
DateTimeFormat ,
25+
ListFormat ,
1926
Locale ,
2027
NumberFormat ,
2128
PluralRules ,
2229
RelativeTimeFormat ,
30+
Segmenter ,
31+
Segments ,
2332
}
2433
/* No side effect */

src/Core__Intl.res

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
module Collator = Core__Intl__Collator
22
module DateTimeFormat = Core__Intl__DateTimeFormat
3+
module ListFormat = Core__Intl__ListFormat
34
module Locale = Core__Intl__Locale
45
module NumberFormat = Core__Intl__NumberFormat
56
module PluralRules = Core__Intl__PluralRules
67
module RelativeTimeFormat = Core__Intl__RelativeTimeFormat
8+
module Segmenter = Core__Intl__Segmenter
9+
module Segments = Core__Intl__Segments
710

811
/**
912
@throws RangeError

src/intl/Core__Intl__Collator.res

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,6 @@ type t
33
type usage = [#sort | #search]
44
type sensitivity = [#base | #accent | #case | #variant]
55
type caseFirst = [#upper | #lower | #"false"]
6-
type collation = [
7-
| #big5han // (Chinese; do not use; not available in Firefox, Chrome or Edge)
8-
| #compat // (Arabic)
9-
| #dict // (Sinhala)
10-
| #direct // (deprecated, do not use)
11-
| #ducet // (not available, do not use)
12-
| #emoji // (root)
13-
| #eor // (root)
14-
| #gb2312 // (Chinese; do not use; not available in Chrome or Edge)
15-
| #phonebk // (German)
16-
| #phonetic // (Lingala)
17-
| #pinyin // (Chinese)
18-
| #reformed // (formerly Swedish; do not specify explicitly as this was the old name for the default for Swedish)
19-
| #searchjl // (Korean; do not use as this is for searching rather than sorting, and the API covers only sorting)
20-
| #stroke // (Chinese)
21-
| #trad
22-
| #unihan // (Chinese, Japanese, and Korean; not available in Chrome or Edge)
23-
| #zhuyin
24-
] // (Chinese)
256

267
type options = {
278
localeMatcher?: Core__Intl__Common.localeMatcher,
@@ -37,7 +18,7 @@ type resolvedOptions = {
3718
usage: usage,
3819
sensitivity: sensitivity,
3920
ignorePunctuation: bool,
40-
collation: [collation | #default],
21+
collation: [Core__Intl__Common.collation | #default],
4122
numeric?: bool,
4223
caseFirst?: caseFirst,
4324
}

src/intl/Core__Intl__Common.res

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,40 @@
11
type localeMatcher = [#lookup | @as("best fit") #bestFit]
22

3+
type calendar = [
4+
| #buddhist
5+
| #chinese
6+
| #coptic
7+
| #dangi
8+
| #ethioaa
9+
| #ethiopic
10+
| #gregory
11+
| #hebrew
12+
| #indian
13+
| #islamic
14+
| #"islamic-umalqura"
15+
| #"islamic-tbla"
16+
| #"islamic-civil"
17+
| #"islamic-rgsa"
18+
| #iso8601
19+
| #japanese
20+
| #persian
21+
| #roc
22+
]
23+
24+
type collation = [
25+
| #compat // (Arabic)
26+
| #dict // (Sinhala)
27+
| #emoji // (root)
28+
| #eor // (root)
29+
| #phonebk // (German)
30+
| #phonetic // (Lingala)
31+
| #pinyin // (Chinese)
32+
| #stroke // (Chinese)
33+
| #trad
34+
| #unihan // (Chinese, Japanese, and Korean; not available in Chrome or Edge)
35+
| #zhuyin
36+
] // (Chinese)
37+
338
type numberingSystem = [
439
| #adlm
540
| #ahom

src/intl/Core__Intl__DateTimeFormat.res

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,6 @@ type t
22

33
type dateStyle = [#full | #long | #medium | #short]
44
type timeStyle = [#full | #long | #medium | #short]
5-
type calendar = [
6-
| #buddhist
7-
| #chinese
8-
| #coptic
9-
| #dangi
10-
| #ethioaa
11-
| #ethiopic
12-
| #gregory
13-
| #hebrew
14-
| #indian
15-
| #islamic
16-
| #"islamic-umalqura"
17-
| #"islamic-tbla"
18-
| #"islamic-civil"
19-
| #"islamic-rgsa"
20-
| #iso8601
21-
| #japanese
22-
| #persian
23-
| #roc
24-
]
255
type dayPeriod = [#narrow | #short | #long]
266
type weekday = [#narrow | #short | #long]
277
type era = [#narrow | #short | #long]
@@ -49,7 +29,7 @@ type fractionalSecondDigits = [#0 | #1 | #2 | #3]
4929
type options = {
5030
dateStyle?: dateStyle, // can be used with timeStyle, but not other options
5131
timeStyle?: timeStyle, // can be used with dateStyle, but not other options
52-
calendar?: calendar,
32+
calendar?: Core__Intl__Common.calendar,
5333
dayPeriod?: dayPeriod, // only has an effect if a 12-hour clock is used
5434
numberingSystem?: Core__Intl__Common.numberingSystem,
5535
localeMatcher?: Core__Intl__Common.localeMatcher,
@@ -83,7 +63,7 @@ type resolvedOptions = {
8363
second?: second,
8464
fractionalSecondDigits?: fractionalSecondDigits,
8565
timeZoneName?: timeZoneName,
86-
calendar: calendar,
66+
calendar: Core__Intl__Common.calendar,
8767
hour12: bool,
8868
hourCycle: hourCycle,
8969
locale: string,

src/intl/Core__Intl__Locale.res

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ type t
22

33
type options = {
44
baseName?: string,
5-
calendar?: string, // TODO: probably the same as Core__Intl__DateTimeFormat.calendar?
6-
collation?: string, // TODO: probably the same as Core__Intl__Collator.collation?
5+
calendar?: Core__Intl__Common.calendar,
6+
collation?: Core__Intl__Common.collation,
77
hourCycle?: [#h11 | #h12 | #h23 | #h24],
88
caseFirst?: [#upper | #lower | #"false"],
99
numberingSystem?: Core__Intl__Common.numberingSystem,

src/intl/Core__Intl__Segments.res

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ type segmentData = {
1212
}
1313

1414
@send
15-
external containing: unit => segmentData = "containing"
15+
external containing: t => segmentData = "containing"
1616

1717
@send
18-
external containingWithIndex: int => segmentData = "containing"
18+
external containingWithIndex: (t, int) => segmentData = "containing"

test/Intl/IntlTests.mjs

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
// Generated by ReScript, PLEASE EDIT WITH CARE
2+
3+
import * as Js_exn from "rescript/lib/es6/js_exn.js";
4+
import * as Intl__LocaleTest from "./Intl__LocaleTest.mjs";
5+
import * as Caml_js_exceptions from "rescript/lib/es6/caml_js_exceptions.js";
6+
import * as Intl__CollatorTest from "./Intl__CollatorTest.mjs";
7+
import * as Intl__SegmenterTest from "./Intl__SegmenterTest.mjs";
8+
import * as Intl__ListFormatTest from "./Intl__ListFormatTest.mjs";
9+
import * as Intl__PluralRulesTest from "./Intl__PluralRulesTest.mjs";
10+
import * as Intl__NumberFormatTest from "./Intl__NumberFormatTest.mjs";
11+
import * as Intl__DateTimeFormatTest from "./Intl__DateTimeFormatTest.mjs";
12+
import * as Intl__RelativeTimeFormatTest from "./Intl__RelativeTimeFormatTest.mjs";
13+
14+
console.log("---");
15+
16+
console.log("Intl");
17+
18+
console.log(Intl.getCanonicalLocales("EN-US"));
19+
20+
console.log(Intl.getCanonicalLocales([
21+
"EN-US",
22+
"Fr"
23+
]));
24+
25+
try {
26+
console.log(Intl.getCanonicalLocales("bloop"));
27+
}
28+
catch (raw_e){
29+
var e = Caml_js_exceptions.internalToOCamlException(raw_e);
30+
if (e.RE_EXN_ID === Js_exn.$$Error) {
31+
console.error(e._1);
32+
} else {
33+
throw e;
34+
}
35+
}
36+
37+
try {
38+
console.log(Intl.supportedValuesOf("calendar"));
39+
console.log(Intl.supportedValuesOf("collation"));
40+
console.log(Intl.supportedValuesOf("currency"));
41+
console.log(Intl.supportedValuesOf("numberingSystem"));
42+
console.log(Intl.supportedValuesOf("timeZone"));
43+
console.log(Intl.supportedValuesOf("unit"));
44+
}
45+
catch (raw_e$1){
46+
var e$1 = Caml_js_exceptions.internalToOCamlException(raw_e$1);
47+
if (e$1.RE_EXN_ID === Js_exn.$$Error) {
48+
console.error(e$1._1);
49+
} else {
50+
throw e$1;
51+
}
52+
}
53+
54+
try {
55+
Intl.supportedValuesOf("someInvalidKey");
56+
console.error("Shouldn't have been hit");
57+
}
58+
catch (raw_e$2){
59+
var e$2 = Caml_js_exceptions.internalToOCamlException(raw_e$2);
60+
if (e$2.RE_EXN_ID === Js_exn.$$Error) {
61+
console.error(e$2._1);
62+
} else {
63+
throw e$2;
64+
}
65+
}
66+
67+
var collator = Intl__CollatorTest.collator;
68+
69+
var resolvedOptions = Intl__DateTimeFormatTest.resolvedOptions;
70+
71+
var timeZone = Intl__DateTimeFormatTest.timeZone;
72+
73+
var locale = Intl__LocaleTest.locale;
74+
75+
var currencyFormatter = Intl__NumberFormatTest.currencyFormatter;
76+
77+
var roundingFormatter = Intl__NumberFormatTest.roundingFormatter;
78+
79+
var groupingFormatter1 = Intl__NumberFormatTest.groupingFormatter1;
80+
81+
var groupingFormatter2 = Intl__NumberFormatTest.groupingFormatter2;
82+
83+
var sigFormatter = Intl__NumberFormatTest.sigFormatter;
84+
85+
var formatter = Intl__SegmenterTest.formatter;
86+
87+
var segments = Intl__SegmenterTest.segments;
88+
89+
export {
90+
collator ,
91+
resolvedOptions ,
92+
timeZone ,
93+
locale ,
94+
currencyFormatter ,
95+
roundingFormatter ,
96+
groupingFormatter1 ,
97+
groupingFormatter2 ,
98+
sigFormatter ,
99+
formatter ,
100+
segments ,
101+
}
102+
/* Not a pure module */

test/Intl/IntlTests.res

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
include Intl__CollatorTest
2+
include Intl__DateTimeFormatTest
3+
include Intl__ListFormatTest
4+
include Intl__LocaleTest
5+
include Intl__NumberFormatTest
6+
include Intl__PluralRulesTest
7+
include Intl__RelativeTimeFormatTest
8+
include Intl__SegmenterTest
9+
10+
open RescriptCore
11+
12+
Console.log("---")
13+
Console.log("Intl")
14+
15+
Intl.getCanonicalLocalesExn("EN-US")->Console.log
16+
Intl.getCanonicalLocalesManyExn(["EN-US", "Fr"])->Console.log
17+
18+
try {
19+
Intl.getCanonicalLocalesExn("bloop")->Console.log
20+
} catch {
21+
| Exn.Error(e) => Console.error(e)
22+
}
23+
24+
try {
25+
Intl.supportedValuesOfExn("calendar")->Console.log
26+
Intl.supportedValuesOfExn("collation")->Console.log
27+
Intl.supportedValuesOfExn("currency")->Console.log
28+
Intl.supportedValuesOfExn("numberingSystem")->Console.log
29+
Intl.supportedValuesOfExn("timeZone")->Console.log
30+
Intl.supportedValuesOfExn("unit")->Console.log
31+
} catch {
32+
| Exn.Error(e) => Console.error(e)
33+
}
34+
35+
try {
36+
Intl.supportedValuesOfExn("someInvalidKey")->ignore
37+
38+
Console.error("Shouldn't have been hit")
39+
} catch {
40+
| Exn.Error(e) => Console.error(e)
41+
// Expected output: RangeError: invalid key: "someInvalidKey"
42+
}

test/Intl/Intl__CollatorTest.mjs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// Generated by ReScript, PLEASE EDIT WITH CARE
2+
3+
4+
console.log("---");
5+
6+
console.log("Intl.Collator");
7+
8+
new Intl.Collator();
9+
10+
new Intl.Collator("en-US");
11+
12+
new Intl.Collator([
13+
"en-US",
14+
"en-GB"
15+
]);
16+
17+
var collator = new Intl.Collator("en-US", {
18+
sensitivity: "base",
19+
ignorePunctuation: true,
20+
numeric: true,
21+
caseFirst: "upper"
22+
});
23+
24+
Intl.Collator.supportedLocalesOf([
25+
"en-US",
26+
"en-GB"
27+
]);
28+
29+
Intl.Collator.supportedLocalesOf([
30+
"en-US",
31+
"en-GB"
32+
], {
33+
localeMatcher: "lookup"
34+
});
35+
36+
console.log(collator.resolvedOptions());
37+
38+
console.log(collator.compare("hi", "hï"));
39+
40+
console.log(Intl.Collator.supportedLocalesOf(["hi"]));
41+
42+
export {
43+
collator ,
44+
}
45+
/* Not a pure module */

test/Intl/Intl__CollatorTest.res

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
open RescriptCore
2+
3+
Console.log("---")
4+
Console.log("Intl.Collator")
5+
6+
let collator = Intl.Collator.make()
7+
let collator = Intl.Collator.makeWithLocale("en-US")
8+
let collator = Intl.Collator.makeWithLocales(["en-US", "en-GB"])
9+
let collator = Intl.Collator.makeWithLocaleAndOptions(
10+
"en-US",
11+
{caseFirst: #upper, sensitivity: #base, ignorePunctuation: true, numeric: true},
12+
)
13+
Intl.Collator.supportedLocalesOf(["en-US", "en-GB"])->ignore
14+
Intl.Collator.supportedLocalesOfWithOptions(["en-US", "en-GB"], {localeMatcher: #lookup})->ignore
15+
16+
collator->Intl.Collator.resolvedOptions->Console.log
17+
collator->Intl.Collator.compare("hi", "hï")->Console.log
18+
Intl.Collator.supportedLocalesOf(["hi"])->Console.log

0 commit comments

Comments
 (0)