diff --git a/test/intl/IntlTests.mjs b/test/intl/IntlTests.mjs new file mode 100644 index 00000000..6fcf5875 --- /dev/null +++ b/test/intl/IntlTests.mjs @@ -0,0 +1,134 @@ +// Generated by ReScript, PLEASE EDIT WITH CARE + +import * as Js_exn from "rescript/lib/es6/js_exn.js"; +import * as Caml_option from "rescript/lib/es6/caml_option.js"; +import * as Core__Option from "../../src/Core__Option.mjs"; +import * as Intl__LocaleTest from "./Intl__LocaleTest.mjs"; +import * as Caml_js_exceptions from "rescript/lib/es6/caml_js_exceptions.js"; +import * as Intl__CollatorTest from "./Intl__CollatorTest.mjs"; +import * as Intl__SegmenterTest from "./Intl__SegmenterTest.mjs"; +import * as Intl__ListFormatTest from "./Intl__ListFormatTest.mjs"; +import * as Intl__PluralRulesTest from "./Intl__PluralRulesTest.mjs"; +import * as Intl__NumberFormatTest from "./Intl__NumberFormatTest.mjs"; +import * as Intl__DateTimeFormatTest from "./Intl__DateTimeFormatTest.mjs"; +import * as Intl__RelativeTimeFormatTest from "./Intl__RelativeTimeFormatTest.mjs"; + +console.log("---"); + +console.log("Intl"); + +console.log(Intl.getCanonicalLocales("EN-US")); + +console.log(Intl.getCanonicalLocales([ + "EN-US", + "Fr" + ])); + +try { + console.log(Intl.getCanonicalLocales("bloop")); +} +catch (raw_e){ + var e = Caml_js_exceptions.internalToOCamlException(raw_e); + if (e.RE_EXN_ID === Js_exn.$$Error) { + console.error(e._1); + } else { + throw e; + } +} + +try { + console.log(Intl.supportedValuesOf("calendar")); + console.log(Intl.supportedValuesOf("collation")); + console.log(Intl.supportedValuesOf("currency")); + console.log(Intl.supportedValuesOf("numberingSystem")); + console.log(Intl.supportedValuesOf("timeZone")); + console.log(Intl.supportedValuesOf("unit")); +} +catch (raw_e$1){ + var e$1 = Caml_js_exceptions.internalToOCamlException(raw_e$1); + if (e$1.RE_EXN_ID === Js_exn.$$Error) { + console.error(e$1._1); + } else { + throw e$1; + } +} + +try { + Intl.supportedValuesOf("someInvalidKey"); + console.error("Shouldn't have been hit"); +} +catch (raw_e$2){ + var e$2 = Caml_js_exceptions.internalToOCamlException(raw_e$2); + if (e$2.RE_EXN_ID === Js_exn.$$Error) { + var e$3 = e$2._1; + var message = Core__Option.map(e$3.message, (function (prim) { + return prim.toLowerCase(); + })); + var exit = 0; + if (message === "invalid key : someinvalidkey") { + console.log("Caught expected error"); + } else { + exit = 1; + } + if (exit === 1) { + console.warn("Unexpected error message: \"" + message + "\""); + throw e$3; + } + + } else { + var e$4 = Caml_js_exceptions.as_js_exn(e$2); + if (e$4 !== undefined) { + throw Caml_option.valFromOption(e$4); + } + console.error("Unexpected error"); + } +} + +var _collator = Intl__CollatorTest._collator; + +var collator = Intl__CollatorTest.collator; + +var resolvedOptions = Intl__DateTimeFormatTest.resolvedOptions; + +var timeZone = Intl__DateTimeFormatTest.timeZone; + +var _locale = Intl__LocaleTest._locale; + +var locale = Intl__LocaleTest.locale; + +var currencyFormatter = Intl__NumberFormatTest.currencyFormatter; + +var roundingFormatter = Intl__NumberFormatTest.roundingFormatter; + +var groupingFormatter1 = Intl__NumberFormatTest.groupingFormatter1; + +var groupingFormatter2 = Intl__NumberFormatTest.groupingFormatter2; + +var sigFormatter = Intl__NumberFormatTest.sigFormatter; + +var options = Intl__NumberFormatTest.options; + +var _formatter = Intl__SegmenterTest._formatter; + +var formatter = Intl__SegmenterTest.formatter; + +var segments = Intl__SegmenterTest.segments; + +export { + _collator , + collator , + resolvedOptions , + timeZone , + _locale , + locale , + currencyFormatter , + roundingFormatter , + groupingFormatter1 , + groupingFormatter2 , + sigFormatter , + options , + _formatter , + formatter , + segments , +} +/* Not a pure module */ diff --git a/test/intl/Intl__CollatorTest.mjs b/test/intl/Intl__CollatorTest.mjs new file mode 100644 index 00000000..3945f3a8 --- /dev/null +++ b/test/intl/Intl__CollatorTest.mjs @@ -0,0 +1,46 @@ +// Generated by ReScript, PLEASE EDIT WITH CARE + + +console.log("---"); + +console.log("Intl.Collator"); + +new Intl.Collator(); + +new Intl.Collator("en-US"); + +var _collator = new Intl.Collator([ + "en-US", + "en-GB" + ]); + +var collator = new Intl.Collator("en-US", { + sensitivity: "base", + ignorePunctuation: true, + numeric: true, + caseFirst: "upper" + }); + +Intl.Collator.supportedLocalesOf([ + "en-US", + "en-GB" + ]); + +Intl.Collator.supportedLocalesOf([ + "en-US", + "en-GB" + ], { + localeMatcher: "lookup" + }); + +console.log(collator.resolvedOptions()); + +console.log(collator.compare("hi", "hï")); + +console.log(Intl.Collator.supportedLocalesOf(["hi"])); + +export { + _collator , + collator , +} +/* Not a pure module */ diff --git a/test/intl/Intl__DateTimeFormatTest.mjs b/test/intl/Intl__DateTimeFormatTest.mjs new file mode 100644 index 00000000..140ae17c --- /dev/null +++ b/test/intl/Intl__DateTimeFormatTest.mjs @@ -0,0 +1,90 @@ +// Generated by ReScript, PLEASE EDIT WITH CARE + +import * as Caml_obj from "rescript/lib/es6/caml_obj.js"; + +console.log("---"); + +console.log("Intl.DateTimeFormat"); + +Intl.DateTimeFormat.supportedLocalesOf([ + "en-US", + "en-GB" + ]); + +Intl.DateTimeFormat.supportedLocalesOf([ + "en-US", + "en-GB" + ], { + localeMatcher: "lookup" + }); + +var formatter = new Intl.DateTimeFormat(undefined, { + dateStyle: "full", + timeStyle: "full" + }); + +console.log(formatter.format(new Date(Date.now()))); + +console.log(formatter.formatRange(new Date(2023, 1, 1), new Date(2023, 12, 31))); + +var options = { + timeZone: "UTC", + hour12: false, + hourCycle: "h24", + weekday: "narrow", + era: "narrow", + year: "2-digit", + month: "2-digit", + day: "2-digit", + hour: "2-digit", + minute: "2-digit", + second: "2-digit", + fractionalSecondDigits: 3, + timeZoneName: "longGeneric" +}; + +var formatter$1 = new Intl.DateTimeFormat(undefined, options); + +console.log(formatter$1.format(new Date(Date.now()))); + +var newrecord = Caml_obj.obj_dup(options); + +var formatter$2 = new Intl.DateTimeFormat(undefined, (newrecord.timeZoneName = "long", newrecord)); + +console.log(formatter$2.format(new Date(Date.now()))); + +var newrecord$1 = Caml_obj.obj_dup(options); + +var formatter$3 = new Intl.DateTimeFormat(undefined, (newrecord$1.timeZoneName = "longOffset", newrecord$1)); + +console.log(formatter$3.format(new Date(Date.now()))); + +var newrecord$2 = Caml_obj.obj_dup(options); + +var formatter$4 = new Intl.DateTimeFormat(undefined, (newrecord$2.timeZoneName = "short", newrecord$2)); + +console.log(formatter$4.format(new Date(Date.now()))); + +var newrecord$3 = Caml_obj.obj_dup(options); + +var formatter$5 = new Intl.DateTimeFormat(undefined, (newrecord$3.timeZoneName = "shortGeneric", newrecord$3)); + +console.log(formatter$5.format(new Date(Date.now()))); + +var newrecord$4 = Caml_obj.obj_dup(options); + +var formatter$6 = new Intl.DateTimeFormat(undefined, (newrecord$4.timeZoneName = "shortOffset", newrecord$4)); + +console.log(formatter$6.format(new Date(Date.now()))); + +var resolvedOptions = new Intl.DateTimeFormat().resolvedOptions(); + +var timeZone = resolvedOptions.timeZone; + +export { + options , + formatter$6 as formatter, + resolvedOptions , + timeZone , +} +/* Not a pure module */ diff --git a/test/intl/Intl__ListFormatTest.mjs b/test/intl/Intl__ListFormatTest.mjs new file mode 100644 index 00000000..592a5eb7 --- /dev/null +++ b/test/intl/Intl__ListFormatTest.mjs @@ -0,0 +1,65 @@ +// Generated by ReScript, PLEASE EDIT WITH CARE + + +console.log("---"); + +console.log("Intl.ListFormat"); + +new Intl.ListFormat(); + +new Intl.ListFormat("en-US"); + +new Intl.ListFormat([ + "en-US", + "en-GB" + ]); + +new Intl.ListFormat("en-US", { + type: "conjunction", + style: "long" + }); + +var _formatter = new Intl.ListFormat([ + "en-US", + "en-GB" + ], { + type: "conjunction", + style: "long" + }); + +Intl.ListFormat.supportedLocalesOf([ + "en-US", + "en-GB" + ]); + +Intl.ListFormat.supportedLocalesOf([ + "en-US", + "en-GB" + ], { + localeMatcher: "lookup" + }); + +var formatter = new Intl.ListFormat(undefined, { + type: "conjunction", + style: "long" + }); + +console.log(formatter.resolvedOptions()); + +console.log(formatter.format([ + "one", + "two", + "three" + ])); + +console.log(formatter.formatToParts([ + "one", + "two", + "three" + ])); + +export { + _formatter , + formatter , +} +/* Not a pure module */ diff --git a/test/intl/Intl__LocaleTest.mjs b/test/intl/Intl__LocaleTest.mjs new file mode 100644 index 00000000..a8349a84 --- /dev/null +++ b/test/intl/Intl__LocaleTest.mjs @@ -0,0 +1,46 @@ +// Generated by ReScript, PLEASE EDIT WITH CARE + + +console.log("---"); + +console.log("Intl.Locale"); + +var _locale = new Intl.Locale("en-US"); + +var locale = new Intl.Locale("en-US", { + calendar: "hebrew", + collation: "compat", + hourCycle: "h24", + caseFirst: "upper", + numeric: true + }); + +console.log(locale.baseName); + +console.log(locale.calendar); + +console.log(locale.caseFirst); + +console.log(locale.collation); + +console.log(locale.hourCycle); + +console.log(locale.language); + +console.log(locale.numberingSystem); + +console.log(locale.numeric); + +console.log(locale.region); + +console.log(locale.script); + +console.log(locale.maximize()); + +console.log(locale.minimize()); + +export { + _locale , + locale , +} +/* Not a pure module */ diff --git a/test/intl/Intl__NumberFormatTest.mjs b/test/intl/Intl__NumberFormatTest.mjs new file mode 100644 index 00000000..d19804e9 --- /dev/null +++ b/test/intl/Intl__NumberFormatTest.mjs @@ -0,0 +1,58 @@ +// Generated by ReScript, PLEASE EDIT WITH CARE + +import * as Caml_option from "rescript/lib/es6/caml_option.js"; +import * as Core__Intl__NumberFormat__Grouping from "../../src/intl/Core__Intl__NumberFormat__Grouping.mjs"; + +console.log("---"); + +console.log("Intl.NumberFormat"); + +var currencyFormatter = new Intl.NumberFormat("fr-FR", { + currency: "EUR", + style: "currency" + }); + +console.log(Intl.NumberFormat.supportedLocalesOf([ + "fr-FR", + "en-US" + ])); + +console.log(currencyFormatter.format(123.23)); + +var roundingFormatter = new Intl.NumberFormat(undefined, { + roundingIncrement: 500, + minimumFractionDigits: 2, + maximumFractionDigits: 2 + }); + +var groupingFormatter1 = new Intl.NumberFormat(undefined, { + useGrouping: Caml_option.some(true) + }); + +var groupingFormatter2 = new Intl.NumberFormat(undefined, { + useGrouping: "auto" + }); + +var sigFormatter = new Intl.NumberFormat(undefined, { + minimumIntegerDigits: 1, + minimumFractionDigits: 1, + maximumFractionDigits: 1, + minimumSignificantDigits: 1, + maximumSignificantDigits: 1 + }); + +var options = sigFormatter.resolvedOptions(); + +console.log(options); + +console.log(Core__Intl__NumberFormat__Grouping.parseJsValue(options.useGrouping)); + +export { + currencyFormatter , + roundingFormatter , + groupingFormatter1 , + groupingFormatter2 , + sigFormatter , + options , +} +/* Not a pure module */ diff --git a/test/intl/Intl__PluralRulesTest.mjs b/test/intl/Intl__PluralRulesTest.mjs new file mode 100644 index 00000000..b4fe8030 --- /dev/null +++ b/test/intl/Intl__PluralRulesTest.mjs @@ -0,0 +1,45 @@ +// Generated by ReScript, PLEASE EDIT WITH CARE + + +console.log("---"); + +console.log("Intl.PluralRules"); + +new Intl.PluralRules(); + +new Intl.PluralRules("en-US"); + +new Intl.PluralRules([ + "en-US", + "en-GB" + ]); + +new Intl.PluralRules(undefined, { + type: "ordinal", + minimumSignificantDigits: 3, + maximumSignificantDigits: 5 + }); + +var _formatter = new Intl.PluralRules("en-US", { + type: "ordinal", + minimumSignificantDigits: 3, + maximumSignificantDigits: 5 + }); + +var formatter = new Intl.PluralRules(["en-US"], { + type: "ordinal", + minimumSignificantDigits: 3, + maximumSignificantDigits: 5 + }); + +console.log(formatter.resolvedOptions()); + +console.log(formatter.select(2.0)); + +console.log(formatter.select(2)); + +export { + _formatter , + formatter , +} +/* Not a pure module */ diff --git a/test/intl/Intl__RelativeTimeFormatTest.mjs b/test/intl/Intl__RelativeTimeFormatTest.mjs new file mode 100644 index 00000000..062d89be --- /dev/null +++ b/test/intl/Intl__RelativeTimeFormatTest.mjs @@ -0,0 +1,54 @@ +// Generated by ReScript, PLEASE EDIT WITH CARE + + +console.log("---"); + +console.log("Intl.RelativeTimeFormat"); + +Intl.RelativeTimeFormat.supportedLocalesOf([ + "en-US", + "en-GB" + ]); + +Intl.RelativeTimeFormat.supportedLocalesOf([ + "en-US", + "en-GB" + ], { + localeMatcher: "lookup" + }); + +new Intl.RelativeTimeFormat(); + +new Intl.RelativeTimeFormat("en-US"); + +new Intl.RelativeTimeFormat([ + "en-US", + "en-GB" + ]); + +new Intl.RelativeTimeFormat(undefined, { + numeric: "always", + style: "narrow" + }); + +var _formatter = new Intl.RelativeTimeFormat("en-US", { + numeric: "always", + style: "narrow" + }); + +var formatter = new Intl.RelativeTimeFormat(["en-US"], { + numeric: "always", + style: "narrow" + }); + +console.log(formatter.resolvedOptions()); + +console.log(formatter.format(3, "hour")); + +console.log(formatter.formatToParts(3, "hour")); + +export { + _formatter , + formatter , +} +/* Not a pure module */ diff --git a/test/intl/Intl__SegmenterTest.mjs b/test/intl/Intl__SegmenterTest.mjs new file mode 100644 index 00000000..757c7c4d --- /dev/null +++ b/test/intl/Intl__SegmenterTest.mjs @@ -0,0 +1,56 @@ +// Generated by ReScript, PLEASE EDIT WITH CARE + + +console.log("---"); + +console.log("Intl.Segmenter"); + +Intl.Segmenter.supportedLocalesOf([ + "en-US", + "en-GB" + ]); + +Intl.Segmenter.supportedLocalesOf([ + "en-US", + "en-GB" + ], { + localeMatcher: "lookup" + }); + +new Intl.Segmenter(); + +new Intl.Segmenter("en-US"); + +new Intl.Segmenter([ + "en-US", + "en-GB" + ]); + +new Intl.Segmenter(undefined, { + granularity: "word" + }); + +var _formatter = new Intl.Segmenter("en-US", { + granularity: "word" + }); + +var formatter = new Intl.Segmenter(["en-US"], { + granularity: "word" + }); + +console.log(formatter.resolvedOptions()); + +var segments = formatter.segment("This is a sentence with several words"); + +console.log(segments); + +console.log(segments.containing()); + +console.log(segments.containing(1)); + +export { + _formatter , + formatter , + segments , +} +/* Not a pure module */