From 3f049c4687ceddfab258e5fb7cdf22295d52e63d Mon Sep 17 00:00:00 2001 From: Christoph Knittel Date: Mon, 21 Oct 2024 16:24:02 +0200 Subject: [PATCH 1/7] Add Core tests --- tests/tests/src/core/Core_ArrayTests.mjs | 477 ++++++++++++ tests/tests/src/core/Core_ArrayTests.res | 113 +++ tests/tests/src/core/Core_DictTests.mjs | 57 ++ tests/tests/src/core/Core_DictTests.res | 20 + tests/tests/src/core/Core_ErrorTests.mjs | 39 + tests/tests/src/core/Core_ErrorTests.res | 11 + tests/tests/src/core/Core_FloatTests.mjs | 253 ++++++ tests/tests/src/core/Core_FloatTests.res | 49 ++ tests/tests/src/core/Core_ImportTests.mjs | 23 + tests/tests/src/core/Core_ImportTests.res | 8 + tests/tests/src/core/Core_IntTests.mjs | 565 ++++++++++++++ tests/tests/src/core/Core_IntTests.res | 170 ++++ tests/tests/src/core/Core_IteratorTests.mjs | 113 +++ tests/tests/src/core/Core_IteratorTests.res | 69 ++ tests/tests/src/core/Core_JsonTests.mjs | 47 ++ tests/tests/src/core/Core_JsonTests.res | 22 + tests/tests/src/core/Core_NullableTests.mjs | 55 ++ tests/tests/src/core/Core_NullableTests.res | 39 + tests/tests/src/core/Core_ObjectTests.mjs | 635 +++++++++++++++ tests/tests/src/core/Core_ObjectTests.res | 179 +++++ tests/tests/src/core/Core_PromiseTest.mjs | 724 ++++++++++++++++++ tests/tests/src/core/Core_PromiseTest.res | 451 +++++++++++ tests/tests/src/core/Core_ResultTests.mjs | 96 +++ tests/tests/src/core/Core_ResultTests.res | 34 + tests/tests/src/core/Core_StringTests.mjs | 21 + tests/tests/src/core/Core_StringTests.res | 5 + tests/tests/src/core/Core_TempTests.mjs | 381 +++++++++ tests/tests/src/core/Core_TempTests.res | 198 +++++ tests/tests/src/core/Core_TestSuite.mjs | 121 +++ tests/tests/src/core/Core_TestSuite.res | 13 + tests/tests/src/core/Core_TestTests.mjs | 190 +++++ tests/tests/src/core/Core_TestTests.res | 33 + tests/tests/src/core/Core_TypedArrayTests.mjs | 105 +++ tests/tests/src/core/Core_TypedArrayTests.res | 76 ++ tests/tests/src/core/Test.mjs | 53 ++ tests/tests/src/core/Test.res | 51 ++ tests/tests/src/core/intl/Core_IntlTests.mjs | 134 ++++ tests/tests/src/core/intl/Core_IntlTests.res | 53 ++ .../src/core/intl/Core_Intl_CollatorTest.mjs | 46 ++ .../src/core/intl/Core_Intl_CollatorTest.res | 18 + .../intl/Core_Intl_DateTimeFormatTest.mjs | 90 +++ .../intl/Core_Intl_DateTimeFormatTest.res | 58 ++ .../core/intl/Core_Intl_ListFormatTest.mjs | 58 ++ .../core/intl/Core_Intl_ListFormatTest.res | 19 + .../src/core/intl/Core_Intl_LocaleTest.mjs | 46 ++ .../src/core/intl/Core_Intl_LocaleTest.res | 29 + .../core/intl/Core_Intl_NumberFormatTest.mjs | 58 ++ .../core/intl/Core_Intl_NumberFormatTest.res | 45 ++ .../core/intl/Core_Intl_PluralRulesTest.mjs | 37 + .../core/intl/Core_Intl_PluralRulesTest.res | 35 + .../intl/Core_Intl_RelativeTimeFormatTest.mjs | 47 ++ .../intl/Core_Intl_RelativeTimeFormatTest.res | 31 + .../src/core/intl/Core_Intl_SegmenterTest.mjs | 50 ++ .../src/core/intl/Core_Intl_SegmenterTest.res | 29 + 54 files changed, 6379 insertions(+) create mode 100644 tests/tests/src/core/Core_ArrayTests.mjs create mode 100644 tests/tests/src/core/Core_ArrayTests.res create mode 100644 tests/tests/src/core/Core_DictTests.mjs create mode 100644 tests/tests/src/core/Core_DictTests.res create mode 100644 tests/tests/src/core/Core_ErrorTests.mjs create mode 100644 tests/tests/src/core/Core_ErrorTests.res create mode 100644 tests/tests/src/core/Core_FloatTests.mjs create mode 100644 tests/tests/src/core/Core_FloatTests.res create mode 100644 tests/tests/src/core/Core_ImportTests.mjs create mode 100644 tests/tests/src/core/Core_ImportTests.res create mode 100644 tests/tests/src/core/Core_IntTests.mjs create mode 100644 tests/tests/src/core/Core_IntTests.res create mode 100644 tests/tests/src/core/Core_IteratorTests.mjs create mode 100644 tests/tests/src/core/Core_IteratorTests.res create mode 100644 tests/tests/src/core/Core_JsonTests.mjs create mode 100644 tests/tests/src/core/Core_JsonTests.res create mode 100644 tests/tests/src/core/Core_NullableTests.mjs create mode 100644 tests/tests/src/core/Core_NullableTests.res create mode 100644 tests/tests/src/core/Core_ObjectTests.mjs create mode 100644 tests/tests/src/core/Core_ObjectTests.res create mode 100644 tests/tests/src/core/Core_PromiseTest.mjs create mode 100644 tests/tests/src/core/Core_PromiseTest.res create mode 100644 tests/tests/src/core/Core_ResultTests.mjs create mode 100644 tests/tests/src/core/Core_ResultTests.res create mode 100644 tests/tests/src/core/Core_StringTests.mjs create mode 100644 tests/tests/src/core/Core_StringTests.res create mode 100644 tests/tests/src/core/Core_TempTests.mjs create mode 100644 tests/tests/src/core/Core_TempTests.res create mode 100644 tests/tests/src/core/Core_TestSuite.mjs create mode 100644 tests/tests/src/core/Core_TestSuite.res create mode 100644 tests/tests/src/core/Core_TestTests.mjs create mode 100644 tests/tests/src/core/Core_TestTests.res create mode 100644 tests/tests/src/core/Core_TypedArrayTests.mjs create mode 100644 tests/tests/src/core/Core_TypedArrayTests.res create mode 100644 tests/tests/src/core/Test.mjs create mode 100644 tests/tests/src/core/Test.res create mode 100644 tests/tests/src/core/intl/Core_IntlTests.mjs create mode 100644 tests/tests/src/core/intl/Core_IntlTests.res create mode 100644 tests/tests/src/core/intl/Core_Intl_CollatorTest.mjs create mode 100644 tests/tests/src/core/intl/Core_Intl_CollatorTest.res create mode 100644 tests/tests/src/core/intl/Core_Intl_DateTimeFormatTest.mjs create mode 100644 tests/tests/src/core/intl/Core_Intl_DateTimeFormatTest.res create mode 100644 tests/tests/src/core/intl/Core_Intl_ListFormatTest.mjs create mode 100644 tests/tests/src/core/intl/Core_Intl_ListFormatTest.res create mode 100644 tests/tests/src/core/intl/Core_Intl_LocaleTest.mjs create mode 100644 tests/tests/src/core/intl/Core_Intl_LocaleTest.res create mode 100644 tests/tests/src/core/intl/Core_Intl_NumberFormatTest.mjs create mode 100644 tests/tests/src/core/intl/Core_Intl_NumberFormatTest.res create mode 100644 tests/tests/src/core/intl/Core_Intl_PluralRulesTest.mjs create mode 100644 tests/tests/src/core/intl/Core_Intl_PluralRulesTest.res create mode 100644 tests/tests/src/core/intl/Core_Intl_RelativeTimeFormatTest.mjs create mode 100644 tests/tests/src/core/intl/Core_Intl_RelativeTimeFormatTest.res create mode 100644 tests/tests/src/core/intl/Core_Intl_SegmenterTest.mjs create mode 100644 tests/tests/src/core/intl/Core_Intl_SegmenterTest.res diff --git a/tests/tests/src/core/Core_ArrayTests.mjs b/tests/tests/src/core/Core_ArrayTests.mjs new file mode 100644 index 0000000000..fbce97e866 --- /dev/null +++ b/tests/tests/src/core/Core_ArrayTests.mjs @@ -0,0 +1,477 @@ +// Generated by ReScript, PLEASE EDIT WITH CARE + +import * as Test from "./Test.mjs"; +import * as Caml_obj from "rescript/lib/es6/caml_obj.js"; +import * as Core__List from "../src/Core__List.mjs"; +import * as Core__Array from "../src/Core__Array.mjs"; + +var eq = Caml_obj.equal; + +Test.run([ + [ + "ArrayTests.res", + 5, + 20, + 26 + ], + "make" + ], Core__Array.make(6, 7), eq, [ + 7, + 7, + 7, + 7, + 7, + 7 + ]); + +Test.run([ + [ + "ArrayTests.res", + 7, + 20, + 42 + ], + "getUnsafe - existing" + ], 1, eq, 1); + +Test.run([ + [ + "ArrayTests.res", + 8, + 20, + 41 + ], + "getUnsafe - missing" + ], [ + 0, + 1, + 2 + ][10], eq, undefined); + +Test.run([ + [ + "ArrayTests.res", + 11, + 13, + 30 + ], + "fromInitializer" + ], Core__Array.fromInitializer(7, (function (i) { + return i + 3 | 0; + })), eq, [ + 3, + 4, + 5, + 6, + 7, + 8, + 9 + ]); + +Test.run([ + [ + "ArrayTests.res", + 17, + 20, + 28 + ], + "reduce" + ], Core__Array.reduce([ + 1, + 2, + 3 + ], /* [] */0, Core__List.add), eq, { + hd: 3, + tl: { + hd: 2, + tl: { + hd: 1, + tl: /* [] */0 + } + } + }); + +Test.run([ + [ + "ArrayTests.res", + 18, + 20, + 36 + ], + "reduce - empty" + ], Core__Array.reduce([], /* [] */0, Core__List.add), eq, /* [] */0); + +Test.run([ + [ + "ArrayTests.res", + 21, + 13, + 30 + ], + "reduceWithIndex" + ], Core__Array.reduceWithIndex([ + 1, + 2, + 3 + ], /* [] */0, (function (acc, v, i) { + return { + hd: v + i | 0, + tl: acc + }; + })), eq, { + hd: 5, + tl: { + hd: 3, + tl: { + hd: 1, + tl: /* [] */0 + } + } + }); + +Test.run([ + [ + "ArrayTests.res", + 27, + 13, + 38 + ], + "reduceWithIndex - empty" + ], Core__Array.reduceWithIndex([], /* [] */0, (function (acc, v, i) { + return { + hd: v + i | 0, + tl: acc + }; + })), eq, /* [] */0); + +Test.run([ + [ + "ArrayTests.res", + 34, + 13, + 26 + ], + "reduceRight" + ], Core__Array.reduceRight([ + 1, + 2, + 3 + ], /* [] */0, Core__List.add), eq, { + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }); + +Test.run([ + [ + "ArrayTests.res", + 39, + 20, + 41 + ], + "reduceRight - empty" + ], Core__Array.reduceRight([], /* [] */0, Core__List.add), eq, /* [] */0); + +Test.run([ + [ + "ArrayTests.res", + 42, + 13, + 35 + ], + "reduceEightWithIndex" + ], Core__Array.reduceRightWithIndex([ + 1, + 2, + 3 + ], /* [] */0, (function (acc, v, i) { + return { + hd: v + i | 0, + tl: acc + }; + })), eq, { + hd: 1, + tl: { + hd: 3, + tl: { + hd: 5, + tl: /* [] */0 + } + } + }); + +Test.run([ + [ + "ArrayTests.res", + 48, + 13, + 38 + ], + "reduceWithIndex - empty" + ], Core__Array.reduceRightWithIndex([], /* [] */0, (function (acc, v, i) { + return { + hd: v + i | 0, + tl: acc + }; + })), eq, /* [] */0); + +Test.run([ + [ + "ArrayTests.res", + 54, + 20, + 41 + ], + "toShuffled - length" + ], Core__Array.toShuffled([ + 1, + 2, + 3 + ]).length, eq, 3); + +var arr = [ + 1, + 2, + 3 +]; + +Test.run([ + [ + "ArrayTests.res", + 57, + 13, + 31 + ], + "shuffle - length" + ], (Core__Array.shuffle(arr), arr.length), eq, 3); + +Test.run([ + [ + "ArrayTests.res", + 68, + 13, + 24 + ], + "filterMap" + ], Core__Array.filterMap([ + 1, + 2, + 3, + 4, + 5, + 6 + ], (function (n) { + if (n % 2 === 0) { + return Math.imul(n, n); + } + + })), eq, [ + 4, + 16, + 36 + ]); + +Test.run([ + [ + "ArrayTests.res", + 73, + 20, + 42 + ], + "filterMap - no match" + ], Core__Array.filterMap([ + 1, + 2, + 3, + 4, + 5, + 6 + ], (function (param) { + + })), eq, []); + +Test.run([ + [ + "ArrayTests.res", + 75, + 13, + 32 + ], + "filterMap - empty" + ], Core__Array.filterMap([], (function (n) { + if (n % 2 === 0) { + return Math.imul(n, n); + } + + })), eq, []); + +Test.run([ + [ + "ArrayTests.res", + 81, + 20, + 30 + ], + "keepSome" + ], Core__Array.keepSome([ + 1, + undefined, + 3 + ]), eq, [ + 1, + 3 + ]); + +Test.run([ + [ + "ArrayTests.res", + 83, + 13, + 34 + ], + "keepSome - all Some" + ], Core__Array.keepSome([ + 1, + 2, + 3 + ]), eq, [ + 1, + 2, + 3 + ]); + +Test.run([ + [ + "ArrayTests.res", + 88, + 20, + 41 + ], + "keepSome - all None" + ], Core__Array.keepSome([ + undefined, + undefined, + undefined + ]), eq, []); + +Test.run([ + [ + "ArrayTests.res", + 89, + 20, + 38 + ], + "keepSome - empty" + ], Core__Array.keepSome([]), eq, []); + +Test.run([ + [ + "ArrayTests.res", + 92, + 13, + 22 + ], + "findMap" + ], Core__Array.findMap([ + 1, + 2, + 3, + 4, + 5, + 6 + ], (function (n) { + if (n % 2 === 0) { + return n - 8 | 0; + } + + })), eq, -6); + +Test.run([ + [ + "ArrayTests.res", + 97, + 20, + 40 + ], + "findMap - no match" + ], Core__Array.findMap([ + 1, + 2, + 3, + 4, + 5, + 6 + ], (function (param) { + + })), eq, undefined); + +Test.run([ + [ + "ArrayTests.res", + 99, + 13, + 30 + ], + "findMap - empty" + ], Core__Array.findMap([], (function (n) { + if (n % 2 === 0) { + return Math.imul(n, n); + } + + })), eq, undefined); + +Test.run([ + [ + "ArrayTests.res", + 106, + 13, + 27 + ], + "fromIterator" + ], Array.from(new Map([ + [ + 1, + 3 + ], + [ + 2, + 4 + ] + ]).values()), eq, [ + 3, + 4 + ]); + +Test.run([ + [ + "ArrayTests.res", + 112, + 20, + 39 + ], + "last - with items" + ], Core__Array.last([ + 1, + 2, + 3 + ]), eq, 3); + +Test.run([ + [ + "ArrayTests.res", + 113, + 20, + 34 + ], + "last - empty" + ], Core__Array.last([]), eq, undefined); + +export { + eq , +} +/* Not a pure module */ diff --git a/tests/tests/src/core/Core_ArrayTests.res b/tests/tests/src/core/Core_ArrayTests.res new file mode 100644 index 0000000000..b6fdec2bd1 --- /dev/null +++ b/tests/tests/src/core/Core_ArrayTests.res @@ -0,0 +1,113 @@ +open RescriptCore + +let eq = (a, b) => a == b + +Test.run(__POS_OF__("make"), Array.make(~length=6, 7), eq, [7, 7, 7, 7, 7, 7]) + +Test.run(__POS_OF__("getUnsafe - existing"), [0, 1, 2]->Array.getUnsafe(1), eq, 1) +Test.run(__POS_OF__("getUnsafe - missing"), [0, 1, 2]->Array.getUnsafe(10), eq, %raw(`undefined`)) + +Test.run( + __POS_OF__("fromInitializer"), + Array.fromInitializer(~length=7, i => i + 3), + eq, + [3, 4, 5, 6, 7, 8, 9], +) + +Test.run(__POS_OF__("reduce"), Array.reduce([1, 2, 3], list{}, List.add), eq, list{3, 2, 1}) +Test.run(__POS_OF__("reduce - empty"), Array.reduce([], list{}, List.add), eq, list{}) + +Test.run( + __POS_OF__("reduceWithIndex"), + Array.reduceWithIndex([1, 2, 3], list{}, (acc, v, i) => list{v + i, ...acc}), + eq, + list{5, 3, 1}, +) +Test.run( + __POS_OF__("reduceWithIndex - empty"), + Array.reduceWithIndex([], list{}, (acc, v, i) => list{v + i, ...acc}), + eq, + list{}, +) + +Test.run( + __POS_OF__("reduceRight"), + Array.reduceRight([1, 2, 3], list{}, List.add), + eq, + list{1, 2, 3}, +) +Test.run(__POS_OF__("reduceRight - empty"), Array.reduceRight([], list{}, List.add), eq, list{}) + +Test.run( + __POS_OF__("reduceEightWithIndex"), + Array.reduceRightWithIndex([1, 2, 3], list{}, (acc, v, i) => list{v + i, ...acc}), + eq, + list{1, 3, 5}, +) +Test.run( + __POS_OF__("reduceWithIndex - empty"), + Array.reduceRightWithIndex([], list{}, (acc, v, i) => list{v + i, ...acc}), + eq, + list{}, +) + +Test.run(__POS_OF__("toShuffled - length"), Array.toShuffled([1, 2, 3])->Array.length, eq, 3) + +Test.run( + __POS_OF__("shuffle - length"), + { + let arr = [1, 2, 3] + Array.shuffle(arr) + arr->Array.length + }, + eq, + 3, +) + +Test.run( + __POS_OF__("filterMap"), + Array.filterMap([1, 2, 3, 4, 5, 6], n => mod(n, 2) == 0 ? Some(n * n) : None), + eq, + [4, 16, 36], +) +Test.run(__POS_OF__("filterMap - no match"), Array.filterMap([1, 2, 3, 4, 5, 6], _ => None), eq, []) +Test.run( + __POS_OF__("filterMap - empty"), + Array.filterMap([], n => mod(n, 2) == 0 ? Some(n * n) : None), + eq, + [], +) + +Test.run(__POS_OF__("keepSome"), Array.keepSome([Some(1), None, Some(3)]), eq, [1, 3]) +Test.run( + __POS_OF__("keepSome - all Some"), + Array.keepSome([Some(1), Some(2), Some(3)]), + eq, + [1, 2, 3], +) +Test.run(__POS_OF__("keepSome - all None"), Array.keepSome([None, None, None]), eq, []) +Test.run(__POS_OF__("keepSome - empty"), Array.keepSome([]), eq, []) + +Test.run( + __POS_OF__("findMap"), + Array.findMap([1, 2, 3, 4, 5, 6], n => mod(n, 2) == 0 ? Some(n - 8) : None), + eq, + Some(-6), +) +Test.run(__POS_OF__("findMap - no match"), Array.findMap([1, 2, 3, 4, 5, 6], _ => None), eq, None) +Test.run( + __POS_OF__("findMap - empty"), + Array.findMap([], n => mod(n, 2) == 0 ? Some(n * n) : None), + eq, + None, +) + +Test.run( + __POS_OF__("fromIterator"), + Array.fromIterator(Map.fromArray([(1, 3), (2, 4)])->Map.values), + eq, + [3, 4], +) + +Test.run(__POS_OF__("last - with items"), [1, 2, 3]->Array.last, eq, Some(3)) +Test.run(__POS_OF__("last - empty"), []->Array.last, eq, None) diff --git a/tests/tests/src/core/Core_DictTests.mjs b/tests/tests/src/core/Core_DictTests.mjs new file mode 100644 index 0000000000..3847e1e326 --- /dev/null +++ b/tests/tests/src/core/Core_DictTests.mjs @@ -0,0 +1,57 @@ +// Generated by ReScript, PLEASE EDIT WITH CARE + +import * as Test from "./Test.mjs"; +import * as Caml_obj from "rescript/lib/es6/caml_obj.js"; + +var eq = Caml_obj.equal; + +Test.run([ + [ + "DictTests.res", + 5, + 20, + 26 + ], + "make" + ], {}, eq, {}); + +Test.run([ + [ + "DictTests.res", + 7, + 20, + 31 + ], + "fromArray" + ], Object.fromEntries([[ + "foo", + "bar" + ]]), eq, {foo: "bar"}); + +Test.run([ + [ + "DictTests.res", + 10, + 13, + 35 + ], + "getUnsafe - existing" + ], Object.fromEntries([[ + "foo", + "bar" + ]])["foo"], eq, "bar"); + +Test.run([ + [ + "DictTests.res", + 16, + 13, + 34 + ], + "getUnsafe - missing" + ], ({})["foo"], eq, undefined); + +export { + eq , +} +/* Not a pure module */ diff --git a/tests/tests/src/core/Core_DictTests.res b/tests/tests/src/core/Core_DictTests.res new file mode 100644 index 0000000000..1a66d50424 --- /dev/null +++ b/tests/tests/src/core/Core_DictTests.res @@ -0,0 +1,20 @@ +open RescriptCore + +let eq = (a, b) => a == b + +Test.run(__POS_OF__("make"), Dict.make(), eq, %raw(`{}`)) + +Test.run(__POS_OF__("fromArray"), Dict.fromArray([("foo", "bar")]), eq, %raw(`{foo: "bar"}`)) + +Test.run( + __POS_OF__("getUnsafe - existing"), + Dict.fromArray([("foo", "bar")])->Dict.getUnsafe("foo"), + eq, + "bar", +) +Test.run( + __POS_OF__("getUnsafe - missing"), + Dict.make()->Dict.getUnsafe("foo"), + eq, + %raw(`undefined`), +) diff --git a/tests/tests/src/core/Core_ErrorTests.mjs b/tests/tests/src/core/Core_ErrorTests.mjs new file mode 100644 index 0000000000..dcced1d540 --- /dev/null +++ b/tests/tests/src/core/Core_ErrorTests.mjs @@ -0,0 +1,39 @@ +// Generated by ReScript, PLEASE EDIT WITH CARE + +import * as Test from "./Test.mjs"; +import * as Js_exn from "rescript/lib/es6/js_exn.js"; +import * as RescriptCore from "../src/RescriptCore.mjs"; +import * as Caml_js_exceptions from "rescript/lib/es6/caml_js_exceptions.js"; + +function panicTest() { + var caught; + try { + caught = RescriptCore.panic("uh oh"); + } + catch (raw_err){ + var err = Caml_js_exceptions.internalToOCamlException(raw_err); + if (err.RE_EXN_ID === Js_exn.$$Error) { + caught = err._1.message; + } else { + throw err; + } + } + Test.run([ + [ + "ErrorTests.res", + 8, + 22, + 43 + ], + "Should resolve test" + ], caught, (function (prim0, prim1) { + return prim0 === prim1; + }), "Panic! uh oh"); +} + +panicTest(); + +export { + panicTest , +} +/* Not a pure module */ diff --git a/tests/tests/src/core/Core_ErrorTests.res b/tests/tests/src/core/Core_ErrorTests.res new file mode 100644 index 0000000000..07dcc078bb --- /dev/null +++ b/tests/tests/src/core/Core_ErrorTests.res @@ -0,0 +1,11 @@ +open RescriptCore + +let panicTest = () => { + let caught = try panic("uh oh") catch { + | Exn.Error(err) => Error.message(err) + } + + Test.run(__POS_OF__("Should resolve test"), caught, \"==", Some("Panic! uh oh")) +} + +panicTest() diff --git a/tests/tests/src/core/Core_FloatTests.mjs b/tests/tests/src/core/Core_FloatTests.mjs new file mode 100644 index 0000000000..10d8de3a17 --- /dev/null +++ b/tests/tests/src/core/Core_FloatTests.mjs @@ -0,0 +1,253 @@ +// Generated by ReScript, PLEASE EDIT WITH CARE + +import * as Test from "./Test.mjs"; +import * as Caml_obj from "rescript/lib/es6/caml_obj.js"; +import * as Core__Float from "../src/Core__Float.mjs"; +import * as PervasivesU from "rescript/lib/es6/pervasivesU.js"; + +var eq = Caml_obj.equal; + +Test.run([ + [ + "FloatTests.res", + 5, + 20, + 27 + ], + "clamp" + ], Core__Float.clamp(undefined, undefined, 4.2), eq, 4.2); + +Test.run([ + [ + "FloatTests.res", + 6, + 20, + 35 + ], + "clamp - < min" + ], Core__Float.clamp(4.3, undefined, 4.1), eq, 4.3); + +Test.run([ + [ + "FloatTests.res", + 7, + 20, + 35 + ], + "clamp - > min" + ], Core__Float.clamp(4.1, undefined, 4.2), eq, 4.2); + +Test.run([ + [ + "FloatTests.res", + 8, + 20, + 35 + ], + "clamp - < max" + ], Core__Float.clamp(undefined, 4.3, 4.2), eq, 4.2); + +Test.run([ + [ + "FloatTests.res", + 9, + 20, + 35 + ], + "clamp - > max" + ], Core__Float.clamp(undefined, 4.1, 4.2), eq, 4.1); + +Test.run([ + [ + "FloatTests.res", + 10, + 20, + 42 + ], + "clamp - < min, < max" + ], Core__Float.clamp(4.3, 4.5, 4.2), eq, 4.3); + +Test.run([ + [ + "FloatTests.res", + 11, + 20, + 42 + ], + "clamp - < min, > max" + ], Core__Float.clamp(4.3, 4.1, 4.2), eq, 4.3); + +Test.run([ + [ + "FloatTests.res", + 12, + 20, + 42 + ], + "clamp - > min, < max" + ], Core__Float.clamp(4.1, 4.5, 4.2), eq, 4.2); + +Test.run([ + [ + "FloatTests.res", + 13, + 20, + 42 + ], + "clamp - > min, > max" + ], Core__Float.clamp(4.1, 4.1, 4.2), eq, 4.1); + +Test.run([ + [ + "FloatTests.res", + 14, + 20, + 33 + ], + "clamp - nan" + ], isNaN(Core__Float.clamp(4.1, 4.3, Number.NaN)), eq, true); + +Test.run([ + [ + "FloatTests.res", + 15, + 20, + 38 + ], + "clamp - infinity" + ], Core__Float.clamp(4.1, 4.3, PervasivesU.infinity), eq, 4.3); + +Test.run([ + [ + "FloatTests.res", + 16, + 20, + 39 + ], + "clamp - -infinity" + ], Core__Float.clamp(4.1, 4.3, PervasivesU.neg_infinity), eq, 4.1); + +Test.run([ + [ + "FloatTests.res", + 17, + 20, + 37 + ], + "clamp - min nan" + ], Core__Float.clamp(Number.NaN, undefined, 4.2), eq, 4.2); + +Test.run([ + [ + "FloatTests.res", + 18, + 20, + 37 + ], + "clamp - max nan" + ], Core__Float.clamp(undefined, Number.NaN, 4.2), eq, 4.2); + +Test.run([ + [ + "FloatTests.res", + 19, + 20, + 46 + ], + "clamp - min nan, max nan" + ], Core__Float.clamp(Number.NaN, Number.NaN, 4.2), eq, 4.2); + +Test.run([ + [ + "FloatTests.res", + 20, + 20, + 42 + ], + "clamp - min infinity" + ], Core__Float.clamp(PervasivesU.infinity, undefined, 4.2), eq, PervasivesU.infinity); + +Test.run([ + [ + "FloatTests.res", + 21, + 20, + 42 + ], + "clamp - max infinity" + ], Core__Float.clamp(undefined, PervasivesU.infinity, 4.2), eq, 4.2); + +Test.run([ + [ + "FloatTests.res", + 22, + 20, + 43 + ], + "clamp - min -infinity" + ], Core__Float.clamp(PervasivesU.neg_infinity, undefined, 4.2), eq, 4.2); + +Test.run([ + [ + "FloatTests.res", + 23, + 20, + 43 + ], + "clamp - max -infinity" + ], Core__Float.clamp(undefined, PervasivesU.neg_infinity, 4.2), eq, PervasivesU.neg_infinity); + +Test.run([ + [ + "FloatTests.res", + 25, + 13, + 49 + ], + "clamp - min infinity, max infinity" + ], Core__Float.clamp(PervasivesU.infinity, PervasivesU.infinity, 4.2), eq, PervasivesU.infinity); + +Test.run([ + [ + "FloatTests.res", + 31, + 13, + 50 + ], + "clamp - min -infinity, max infinity" + ], Core__Float.clamp(PervasivesU.neg_infinity, PervasivesU.infinity, 4.2), eq, 4.2); + +Test.run([ + [ + "FloatTests.res", + 37, + 13, + 50 + ], + "clamp - min infinity, max -infinity" + ], Core__Float.clamp(PervasivesU.infinity, PervasivesU.neg_infinity, 4.2), eq, PervasivesU.infinity); + +Test.run([ + [ + "FloatTests.res", + 43, + 13, + 51 + ], + "clamp - min -infinity, max -infinity" + ], Core__Float.clamp(PervasivesU.neg_infinity, PervasivesU.neg_infinity, 4.2), eq, PervasivesU.neg_infinity); + +Test.run([ + [ + "FloatTests.res", + 49, + 20, + 46 + ], + "Float.equal optimization" + ], false, eq, false); + +export { + eq , +} +/* Not a pure module */ diff --git a/tests/tests/src/core/Core_FloatTests.res b/tests/tests/src/core/Core_FloatTests.res new file mode 100644 index 0000000000..8ca2d2011a --- /dev/null +++ b/tests/tests/src/core/Core_FloatTests.res @@ -0,0 +1,49 @@ +open RescriptCore + +let eq = (a, b) => a == b + +Test.run(__POS_OF__("clamp"), Float.clamp(4.2), eq, 4.2) +Test.run(__POS_OF__("clamp - < min"), Float.clamp(~min=4.3, 4.1), eq, 4.3) +Test.run(__POS_OF__("clamp - > min"), Float.clamp(~min=4.1, 4.2), eq, 4.2) +Test.run(__POS_OF__("clamp - < max"), Float.clamp(~max=4.3, 4.2), eq, 4.2) +Test.run(__POS_OF__("clamp - > max"), Float.clamp(~max=4.1, 4.2), eq, 4.1) +Test.run(__POS_OF__("clamp - < min, < max"), Float.clamp(~min=4.3, ~max=4.5, 4.2), eq, 4.3) +Test.run(__POS_OF__("clamp - < min, > max"), Float.clamp(~min=4.3, ~max=4.1, 4.2), eq, 4.3) // min wins +Test.run(__POS_OF__("clamp - > min, < max"), Float.clamp(~min=4.1, ~max=4.5, 4.2), eq, 4.2) +Test.run(__POS_OF__("clamp - > min, > max"), Float.clamp(~min=4.1, ~max=4.1, 4.2), eq, 4.1) +Test.run(__POS_OF__("clamp - nan"), Float.clamp(~min=4.1, ~max=4.3, nan)->Float.isNaN, eq, true) +Test.run(__POS_OF__("clamp - infinity"), Float.clamp(~min=4.1, ~max=4.3, infinity), eq, 4.3) +Test.run(__POS_OF__("clamp - -infinity"), Float.clamp(~min=4.1, ~max=4.3, neg_infinity), eq, 4.1) +Test.run(__POS_OF__("clamp - min nan"), Float.clamp(~min=nan, 4.2), eq, 4.2) +Test.run(__POS_OF__("clamp - max nan"), Float.clamp(~max=nan, 4.2), eq, 4.2) +Test.run(__POS_OF__("clamp - min nan, max nan"), Float.clamp(~min=nan, ~max=nan, 4.2), eq, 4.2) +Test.run(__POS_OF__("clamp - min infinity"), Float.clamp(~min=infinity, 4.2), eq, infinity) +Test.run(__POS_OF__("clamp - max infinity"), Float.clamp(~max=infinity, 4.2), eq, 4.2) +Test.run(__POS_OF__("clamp - min -infinity"), Float.clamp(~min=neg_infinity, 4.2), eq, 4.2) +Test.run(__POS_OF__("clamp - max -infinity"), Float.clamp(~max=neg_infinity, 4.2), eq, neg_infinity) +Test.run( + __POS_OF__("clamp - min infinity, max infinity"), + Float.clamp(~min=infinity, ~max=infinity, 4.2), + eq, + infinity, +) +Test.run( + __POS_OF__("clamp - min -infinity, max infinity"), + Float.clamp(~min=neg_infinity, ~max=infinity, 4.2), + eq, + 4.2, +) +Test.run( + __POS_OF__("clamp - min infinity, max -infinity"), + Float.clamp(~min=infinity, ~max=neg_infinity, 4.2), + eq, + infinity, // min wins +) +Test.run( + __POS_OF__("clamp - min -infinity, max -infinity"), + Float.clamp(~min=neg_infinity, ~max=neg_infinity, 4.2), + eq, + neg_infinity, +) + +Test.run(__POS_OF__("Float.equal optimization"), Float.equal(1., 3.), eq, false) diff --git a/tests/tests/src/core/Core_ImportTests.mjs b/tests/tests/src/core/Core_ImportTests.mjs new file mode 100644 index 0000000000..6a94c12d95 --- /dev/null +++ b/tests/tests/src/core/Core_ImportTests.mjs @@ -0,0 +1,23 @@ +// Generated by ReScript, PLEASE EDIT WITH CARE + +import * as Test from "./Test.mjs"; + +async function main() { + var eq = await import("./IntTests.mjs").then(function (m) { + return m.eq; + }); + return Test.run([ + [ + "ImportTests.res", + 5, + 22, + 55 + ], + "dynamic import - Int tests - eq" + ], 1, eq, 1); +} + +export { + main , +} +/* Test Not a pure module */ diff --git a/tests/tests/src/core/Core_ImportTests.res b/tests/tests/src/core/Core_ImportTests.res new file mode 100644 index 0000000000..961e3ff1dd --- /dev/null +++ b/tests/tests/src/core/Core_ImportTests.res @@ -0,0 +1,8 @@ +open RescriptCore + +let main = async () => { + let eq = await import(IntTests.eq) + Test.run(__POS_OF__("dynamic import - Int tests - eq"), 1, eq, 1) +} + +main->ignore diff --git a/tests/tests/src/core/Core_IntTests.mjs b/tests/tests/src/core/Core_IntTests.mjs new file mode 100644 index 0000000000..2ab9a0ceeb --- /dev/null +++ b/tests/tests/src/core/Core_IntTests.mjs @@ -0,0 +1,565 @@ +// Generated by ReScript, PLEASE EDIT WITH CARE + +import * as Test from "./Test.mjs"; +import * as Js_exn from "rescript/lib/es6/js_exn.js"; +import * as Caml_obj from "rescript/lib/es6/caml_obj.js"; +import * as Core__Int from "../src/Core__Int.mjs"; +import * as PervasivesU from "rescript/lib/es6/pervasivesU.js"; +import * as Caml_js_exceptions from "rescript/lib/es6/caml_js_exceptions.js"; + +var eq = Caml_obj.equal; + +function $$catch(f) { + try { + f(); + return PervasivesU.failwith("no exception raised"); + } + catch (raw_err){ + var err = Caml_js_exceptions.internalToOCamlException(raw_err); + if (err.RE_EXN_ID === Js_exn.$$Error) { + return err._1; + } + throw err; + } +} + +Test.run([ + [ + "IntTests.res", + 13, + 20, + 50 + ], + "range - positive, increasing" + ], Core__Int.range(3, 6, undefined), eq, [ + 3, + 4, + 5 + ]); + +Test.run([ + [ + "IntTests.res", + 14, + 20, + 50 + ], + "range - negative, increasing" + ], Core__Int.range(-3, -1, undefined), eq, [ + -3, + -2 + ]); + +Test.run([ + [ + "IntTests.res", + 15, + 20, + 51 + ], + "range - cross-zero, incresing" + ], Core__Int.range(-1, 2, undefined), eq, [ + -1, + 0, + 1 + ]); + +Test.run([ + [ + "IntTests.res", + 16, + 20, + 42 + ], + "range - start == end" + ], Core__Int.range(3, 3, undefined), eq, []); + +Test.run([ + [ + "IntTests.res", + 17, + 20, + 50 + ], + "range - positive, decreasing" + ], Core__Int.range(3, 1, undefined), eq, [ + 3, + 2 + ]); + +Test.run([ + [ + "IntTests.res", + 18, + 20, + 50 + ], + "range - negative, decreasing" + ], Core__Int.range(-1, -3, undefined), eq, [ + -1, + -2 + ]); + +Test.run([ + [ + "IntTests.res", + 21, + 13, + 51 + ], + "range - positive, increasing, step 2" + ], Core__Int.range(3, 6, { + step: 2 + }), eq, [ + 3, + 5 + ]); + +Test.run([ + [ + "IntTests.res", + 27, + 13, + 51 + ], + "range + positive, increasing, step 2" + ], Core__Int.range(3, 7, { + step: 2 + }), eq, [ + 3, + 5 + ]); + +Test.run([ + [ + "IntTests.res", + 33, + 13, + 51 + ], + "range + positive, increasing, step 2" + ], Core__Int.range(3, 8, { + step: 2 + }), eq, [ + 3, + 5, + 7 + ]); + +Test.run([ + [ + "IntTests.res", + 39, + 13, + 51 + ], + "range - negative, increasing, step 2" + ], Core__Int.range(-6, -3, { + step: 2 + }), eq, [ + -6, + -4 + ]); + +Test.run([ + [ + "IntTests.res", + 45, + 13, + 51 + ], + "range - positive, increasing, step 0" + ], $$catch(function () { + return Core__Int.range(3, 6, { + step: 0 + }); + }), eq, new RangeError("Incorrect range arguments")); + +Test.run([ + [ + "IntTests.res", + 50, + 20, + 50 + ], + "range - start == end, step 0" + ], Core__Int.range(3, 3, { + step: 0 + }), eq, []); + +Test.run([ + [ + "IntTests.res", + 52, + 13, + 52 + ], + "range + positive, increasing, step -1" + ], Core__Int.range(3, 6, { + step: -1 + }), eq, []); + +Test.run([ + [ + "IntTests.res", + 58, + 13, + 51 + ], + "range + positive, decreasing, step 1" + ], Core__Int.range(6, 3, { + step: 1 + }), eq, []); + +Test.run([ + [ + "IntTests.res", + 64, + 13, + 52 + ], + "range + positive, decreasing, step -2" + ], Core__Int.range(6, 3, { + step: -2 + }), eq, [ + 6, + 4 + ]); + +Test.run([ + [ + "IntTests.res", + 70, + 13, + 52 + ], + "range + positive, increasing, step -2" + ], Core__Int.range(6, 2, { + step: -2 + }), eq, [ + 6, + 4 + ]); + +Test.run([ + [ + "IntTests.res", + 76, + 13, + 52 + ], + "range + positive, increasing, step -2" + ], Core__Int.range(6, 1, { + step: -2 + }), eq, [ + 6, + 4, + 2 + ]); + +Test.run([ + [ + "IntTests.res", + 82, + 13, + 52 + ], + "range + negative, decreasing, step -2" + ], Core__Int.range(-3, -6, { + step: -2 + }), eq, [ + -3, + -5 + ]); + +Test.run([ + [ + "IntTests.res", + 88, + 13, + 62 + ], + "range - positive, increasing, step 2, inclusive" + ], Core__Int.range(3, 6, { + step: 2, + inclusive: true + }), eq, [ + 3, + 5 + ]); + +Test.run([ + [ + "IntTests.res", + 94, + 13, + 62 + ], + "range + positive, increasing, step 2, inclusive" + ], Core__Int.range(3, 7, { + step: 2, + inclusive: true + }), eq, [ + 3, + 5, + 7 + ]); + +Test.run([ + [ + "IntTests.res", + 100, + 13, + 62 + ], + "range + positive, increasing, step 2, inclusive" + ], Core__Int.range(3, 8, { + step: 2, + inclusive: true + }), eq, [ + 3, + 5, + 7 + ]); + +Test.run([ + [ + "IntTests.res", + 106, + 13, + 62 + ], + "range - negative, increasing, step 2, inclusive" + ], Core__Int.range(-6, -3, { + step: 2, + inclusive: true + }), eq, [ + -6, + -4 + ]); + +Test.run([ + [ + "IntTests.res", + 112, + 13, + 62 + ], + "range - positive, increasing, step 0, inclusive" + ], $$catch(function () { + return Core__Int.range(3, 6, { + step: 0, + inclusive: true + }); + }), eq, new RangeError("Incorrect range arguments")); + +Test.run([ + [ + "IntTests.res", + 118, + 13, + 54 + ], + "range - start == end, step 0, inclusive" + ], Core__Int.range(3, 3, { + step: 0, + inclusive: true + }), eq, [3]); + +Test.run([ + [ + "IntTests.res", + 124, + 13, + 63 + ], + "range + positive, increasing, step -1, inclusive" + ], Core__Int.range(3, 6, { + step: -1, + inclusive: true + }), eq, []); + +Test.run([ + [ + "IntTests.res", + 130, + 13, + 62 + ], + "range + positive, decreasing, step 1, inclusive" + ], Core__Int.range(6, 3, { + step: 1, + inclusive: true + }), eq, []); + +Test.run([ + [ + "IntTests.res", + 136, + 13, + 63 + ], + "range + positive, decreasing, step -2, inclusive" + ], Core__Int.range(6, 3, { + step: -2, + inclusive: true + }), eq, [ + 6, + 4 + ]); + +Test.run([ + [ + "IntTests.res", + 142, + 13, + 63 + ], + "range + positive, increasing, step -2, inclusive" + ], Core__Int.range(6, 2, { + step: -2, + inclusive: true + }), eq, [ + 6, + 4, + 2 + ]); + +Test.run([ + [ + "IntTests.res", + 148, + 13, + 63 + ], + "range + positive, increasing, step -2, inclusive" + ], Core__Int.range(6, 1, { + step: -2, + inclusive: true + }), eq, [ + 6, + 4, + 2 + ]); + +Test.run([ + [ + "IntTests.res", + 154, + 13, + 63 + ], + "range + negative, decreasing, step -2, inclusive" + ], Core__Int.range(-3, -6, { + step: -2, + inclusive: true + }), eq, [ + -3, + -5 + ]); + +Test.run([ + [ + "IntTests.res", + 160, + 20, + 27 + ], + "clamp" + ], Core__Int.clamp(undefined, undefined, 42), eq, 42); + +Test.run([ + [ + "IntTests.res", + 161, + 20, + 35 + ], + "clamp - < min" + ], Core__Int.clamp(50, undefined, 42), eq, 50); + +Test.run([ + [ + "IntTests.res", + 162, + 20, + 35 + ], + "clamp - > min" + ], Core__Int.clamp(40, undefined, 42), eq, 42); + +Test.run([ + [ + "IntTests.res", + 163, + 20, + 35 + ], + "clamp - < max" + ], Core__Int.clamp(undefined, 50, 42), eq, 42); + +Test.run([ + [ + "IntTests.res", + 164, + 20, + 35 + ], + "clamp - > max" + ], Core__Int.clamp(undefined, 40, 42), eq, 40); + +Test.run([ + [ + "IntTests.res", + 165, + 20, + 42 + ], + "clamp - < min, < max" + ], Core__Int.clamp(50, 60, 42), eq, 50); + +Test.run([ + [ + "IntTests.res", + 166, + 20, + 42 + ], + "clamp - < min, > max" + ], Core__Int.clamp(50, 40, 42), eq, 50); + +Test.run([ + [ + "IntTests.res", + 167, + 20, + 42 + ], + "clamp - > min, < max" + ], Core__Int.clamp(40, 60, 42), eq, 42); + +Test.run([ + [ + "IntTests.res", + 168, + 20, + 42 + ], + "clamp - > min, > max" + ], Core__Int.clamp(40, 40, 42), eq, 40); + +Test.run([ + [ + "IntTests.res", + 170, + 20, + 44 + ], + "Int.equal optimization" + ], false, eq, false); + +export { + eq , + $$catch , +} +/* Not a pure module */ diff --git a/tests/tests/src/core/Core_IntTests.res b/tests/tests/src/core/Core_IntTests.res new file mode 100644 index 0000000000..ebbb7e8c5c --- /dev/null +++ b/tests/tests/src/core/Core_IntTests.res @@ -0,0 +1,170 @@ +open RescriptCore + +let eq = (a, b) => a == b + +let catch = f => + try { + let _ = f() + failwith("no exception raised") + } catch { + | Exn.Error(err) => err + } + +Test.run(__POS_OF__("range - positive, increasing"), Int.range(3, 6), eq, [3, 4, 5]) +Test.run(__POS_OF__("range - negative, increasing"), Int.range(-3, -1), eq, [-3, -2]) +Test.run(__POS_OF__("range - cross-zero, incresing"), Int.range(-1, 2), eq, [-1, 0, 1]) +Test.run(__POS_OF__("range - start == end"), Int.range(3, 3), eq, []) +Test.run(__POS_OF__("range - positive, decreasing"), Int.range(3, 1), eq, [3, 2]) +Test.run(__POS_OF__("range - negative, decreasing"), Int.range(-1, -3), eq, [-1, -2]) + +Test.run( + __POS_OF__("range - positive, increasing, step 2"), + Int.range(3, 6, ~options={step: 2}), + eq, + [3, 5], +) +Test.run( + __POS_OF__("range + positive, increasing, step 2"), + Int.range(3, 7, ~options={step: 2}), + eq, + [3, 5], +) +Test.run( + __POS_OF__("range + positive, increasing, step 2"), + Int.range(3, 8, ~options={step: 2}), + eq, + [3, 5, 7], +) +Test.run( + __POS_OF__("range - negative, increasing, step 2"), + Int.range(-6, -3, ~options={step: 2}), + eq, + [-6, -4], +) +Test.run( + __POS_OF__("range - positive, increasing, step 0"), + catch(() => Int.range(3, 6, ~options={step: 0})), + eq, + Error.RangeError.make("Incorrect range arguments"), +) +Test.run(__POS_OF__("range - start == end, step 0"), Int.range(3, 3, ~options={step: 0}), eq, []) +Test.run( + __POS_OF__("range + positive, increasing, step -1"), + Int.range(3, 6, ~options={step: -1}), + eq, + [], +) +Test.run( + __POS_OF__("range + positive, decreasing, step 1"), + Int.range(6, 3, ~options={step: 1}), + eq, + [], +) +Test.run( + __POS_OF__("range + positive, decreasing, step -2"), + Int.range(6, 3, ~options={step: -2}), + eq, + [6, 4], +) +Test.run( + __POS_OF__("range + positive, increasing, step -2"), + Int.range(6, 2, ~options={step: -2}), + eq, + [6, 4], +) +Test.run( + __POS_OF__("range + positive, increasing, step -2"), + Int.range(6, 1, ~options={step: -2}), + eq, + [6, 4, 2], +) +Test.run( + __POS_OF__("range + negative, decreasing, step -2"), + Int.range(-3, -6, ~options={step: -2}), + eq, + [-3, -5], +) +Test.run( + __POS_OF__("range - positive, increasing, step 2, inclusive"), + Int.range(3, 6, ~options={step: 2, inclusive: true}), + eq, + [3, 5], +) +Test.run( + __POS_OF__("range + positive, increasing, step 2, inclusive"), + Int.range(3, 7, ~options={step: 2, inclusive: true}), + eq, + [3, 5, 7], +) +Test.run( + __POS_OF__("range + positive, increasing, step 2, inclusive"), + Int.range(3, 8, ~options={step: 2, inclusive: true}), + eq, + [3, 5, 7], +) +Test.run( + __POS_OF__("range - negative, increasing, step 2, inclusive"), + Int.range(-6, -3, ~options={step: 2, inclusive: true}), + eq, + [-6, -4], +) +Test.run( + __POS_OF__("range - positive, increasing, step 0, inclusive"), + catch(() => Int.range(3, 6, ~options={step: 0, inclusive: true})), + eq, + Error.RangeError.make("Incorrect range arguments"), +) +Test.run( + __POS_OF__("range - start == end, step 0, inclusive"), + Int.range(3, 3, ~options={step: 0, inclusive: true}), + eq, + [3], +) +Test.run( + __POS_OF__("range + positive, increasing, step -1, inclusive"), + Int.range(3, 6, ~options={step: -1, inclusive: true}), + eq, + [], +) +Test.run( + __POS_OF__("range + positive, decreasing, step 1, inclusive"), + Int.range(6, 3, ~options={step: 1, inclusive: true}), + eq, + [], +) +Test.run( + __POS_OF__("range + positive, decreasing, step -2, inclusive"), + Int.range(6, 3, ~options={step: -2, inclusive: true}), + eq, + [6, 4], +) +Test.run( + __POS_OF__("range + positive, increasing, step -2, inclusive"), + Int.range(6, 2, ~options={step: -2, inclusive: true}), + eq, + [6, 4, 2], +) +Test.run( + __POS_OF__("range + positive, increasing, step -2, inclusive"), + Int.range(6, 1, ~options={step: -2, inclusive: true}), + eq, + [6, 4, 2], +) +Test.run( + __POS_OF__("range + negative, decreasing, step -2, inclusive"), + Int.range(-3, -6, ~options={step: -2, inclusive: true}), + eq, + [-3, -5], +) + +Test.run(__POS_OF__("clamp"), Int.clamp(42), eq, 42) +Test.run(__POS_OF__("clamp - < min"), Int.clamp(~min=50, 42), eq, 50) +Test.run(__POS_OF__("clamp - > min"), Int.clamp(~min=40, 42), eq, 42) +Test.run(__POS_OF__("clamp - < max"), Int.clamp(~max=50, 42), eq, 42) +Test.run(__POS_OF__("clamp - > max"), Int.clamp(~max=40, 42), eq, 40) +Test.run(__POS_OF__("clamp - < min, < max"), Int.clamp(~min=50, ~max=60, 42), eq, 50) +Test.run(__POS_OF__("clamp - < min, > max"), Int.clamp(~min=50, ~max=40, 42), eq, 50) // min wins +Test.run(__POS_OF__("clamp - > min, < max"), Int.clamp(~min=40, ~max=60, 42), eq, 42) +Test.run(__POS_OF__("clamp - > min, > max"), Int.clamp(~min=40, ~max=40, 42), eq, 40) + +Test.run(__POS_OF__("Int.equal optimization"), Int.equal(1, 3), eq, false) diff --git a/tests/tests/src/core/Core_IteratorTests.mjs b/tests/tests/src/core/Core_IteratorTests.mjs new file mode 100644 index 0000000000..c40b973923 --- /dev/null +++ b/tests/tests/src/core/Core_IteratorTests.mjs @@ -0,0 +1,113 @@ +// Generated by ReScript, PLEASE EDIT WITH CARE + +import * as Test from "./Test.mjs"; +import * as Caml_obj from "rescript/lib/es6/caml_obj.js"; +import * as Core__Iterator from "../src/Core__Iterator.mjs"; +import * as Core__AsyncIterator from "../src/Core__AsyncIterator.mjs"; + +var eq = Caml_obj.equal; + +var iterator = ((() => { + var array1 = ['a', 'b', 'c']; + var iterator1 = array1[Symbol.iterator](); + return iterator1 + })()); + +var syncResult = { + contents: undefined +}; + +Core__Iterator.forEach(iterator, (function (v) { + if (v === "b") { + syncResult.contents = "b"; + return ; + } + + })); + +Test.run([ + [ + "IteratorTests.res", + 21, + 20, + 34 + ], + "Sync forEach" + ], syncResult.contents, eq, "b"); + +var asyncIterator = ((() => { + var map1 = new Map(); + + map1.set('first', '1'); + map1.set('second', '2'); + + var iterator1 = map1[Symbol.iterator](); + return iterator1; + })()); + +var asyncResult = { + contents: undefined +}; + +await Core__AsyncIterator.forEach(asyncIterator, (function (v) { + if (v !== undefined && v[0] === "second") { + asyncResult.contents = "second"; + return ; + } + + })); + +Test.run([ + [ + "IteratorTests.res", + 44, + 20, + 35 + ], + "Async forEach" + ], asyncResult.contents, eq, "second"); + +var asyncResult$1 = { + contents: undefined +}; + +var count = { + contents: 0 +}; + +var asyncIterator$1 = Core__AsyncIterator.make(async function () { + var currentCount = count.contents; + count.contents = currentCount + 1 | 0; + if (currentCount === 3) { + return Core__AsyncIterator.done(currentCount); + } else { + return Core__AsyncIterator.value(currentCount); + } + }); + +await Core__AsyncIterator.forEach(asyncIterator$1, (function (v) { + if (v === 3) { + asyncResult$1.contents = "done"; + } else { + console.log("next.."); + } + })); + +Test.run([ + [ + "IteratorTests.res", + 69, + 20, + 54 + ], + "Creating your own async iterator" + ], asyncResult$1.contents, eq, "done"); + +export { + eq , + iterator , + syncResult , + asyncResult , + asyncIterator$1 as asyncIterator, +} +/* iterator Not a pure module */ diff --git a/tests/tests/src/core/Core_IteratorTests.res b/tests/tests/src/core/Core_IteratorTests.res new file mode 100644 index 0000000000..902df8ae3f --- /dev/null +++ b/tests/tests/src/core/Core_IteratorTests.res @@ -0,0 +1,69 @@ +open RescriptCore + +let eq = (a, b) => a == b + +let iterator: Iterator.t = %raw(` + (() => { + var array1 = ['a', 'b', 'c']; + var iterator1 = array1[Symbol.iterator](); + return iterator1 + })() +`) + +let syncResult = ref(None) + +iterator->Iterator.forEach(v => { + if v === Some("b") { + syncResult.contents = Some("b") + } +}) + +Test.run(__POS_OF__("Sync forEach"), syncResult.contents, eq, Some("b")) + +let asyncIterator: AsyncIterator.t<(string, string)> = %raw(` + (() => { + var map1 = new Map(); + + map1.set('first', '1'); + map1.set('second', '2'); + + var iterator1 = map1[Symbol.iterator](); + return iterator1; + })() +`) + +let asyncResult = ref(None) + +await asyncIterator->AsyncIterator.forEach(v => { + switch v { + | Some(("second", _value)) => asyncResult.contents = Some("second") + | _ => () + } +}) + +Test.run(__POS_OF__("Async forEach"), asyncResult.contents, eq, Some("second")) + +%%private( + let asyncResult = ref(None) + let count = ref(0) +) + +let asyncIterator = AsyncIterator.make(async () => { + let currentCount = count.contents + count := currentCount + 1 + + if currentCount === 3 { + AsyncIterator.done(~finalValue=currentCount) + } else { + AsyncIterator.value(currentCount) + } +}) + +await asyncIterator->AsyncIterator.forEach(v => { + switch v { + | Some(3) => asyncResult.contents = Some("done") + | _ => Console.log("next..") + } +}) + +Test.run(__POS_OF__("Creating your own async iterator"), asyncResult.contents, eq, Some("done")) diff --git a/tests/tests/src/core/Core_JsonTests.mjs b/tests/tests/src/core/Core_JsonTests.mjs new file mode 100644 index 0000000000..ab1b95c9ef --- /dev/null +++ b/tests/tests/src/core/Core_JsonTests.mjs @@ -0,0 +1,47 @@ +// Generated by ReScript, PLEASE EDIT WITH CARE + +import * as Test from "./Test.mjs"; + +function decodeJsonTest() { + var json = {"someProp":{"otherProp": null, "thirdProp": [true, false]}}; + var decodedCorrectly; + if (!Array.isArray(json) && (json === null || typeof json !== "object") && typeof json !== "number" && typeof json !== "string" && typeof json !== "boolean" || !(typeof json === "object" && !Array.isArray(json))) { + decodedCorrectly = false; + } else { + var match = json["someProp"]; + if (match !== undefined && !(!Array.isArray(match) && (match === null || typeof match !== "object") && typeof match !== "number" && typeof match !== "string" && typeof match !== "boolean" || !(typeof match === "object" && !Array.isArray(match)))) { + var match$1 = match["thirdProp"]; + if (match$1 !== undefined && !(!Array.isArray(match$1) && (match$1 === null || typeof match$1 !== "object") && typeof match$1 !== "number" && typeof match$1 !== "string" && typeof match$1 !== "boolean" || !(Array.isArray(match$1) && match$1.length === 2))) { + var match$2 = match$1[0]; + if (!Array.isArray(match$2) && (match$2 === null || typeof match$2 !== "object") && typeof match$2 !== "number" && typeof match$2 !== "string" && typeof match$2 !== "boolean" || !(typeof match$2 === "boolean" && match$2)) { + decodedCorrectly = false; + } else { + var match$3 = match$1[1]; + decodedCorrectly = !Array.isArray(match$3) && (match$3 === null || typeof match$3 !== "object") && typeof match$3 !== "number" && typeof match$3 !== "string" && typeof match$3 !== "boolean" || !(typeof match$3 === "boolean" && !match$3) ? false : true; + } + } else { + decodedCorrectly = false; + } + } else { + decodedCorrectly = false; + } + } + Test.run([ + [ + "JsonTests.res", + 19, + 22, + 55 + ], + "Should decode JSON successfully" + ], decodedCorrectly, (function (prim0, prim1) { + return prim0 === prim1; + }), true); +} + +decodeJsonTest(); + +export { + decodeJsonTest , +} +/* Not a pure module */ diff --git a/tests/tests/src/core/Core_JsonTests.res b/tests/tests/src/core/Core_JsonTests.res new file mode 100644 index 0000000000..03b907209a --- /dev/null +++ b/tests/tests/src/core/Core_JsonTests.res @@ -0,0 +1,22 @@ +open RescriptCore + +let decodeJsonTest = () => { + let json: JSON.t = %raw(`{"someProp":{"otherProp": null, "thirdProp": [true, false]}}`) + + let decodedCorrectly = switch json { + | Object(dict) => + switch dict->Dict.get("someProp") { + | Some(Object(dict)) => + switch dict->Dict.get("thirdProp") { + | Some(Array([Boolean(true), Boolean(false)])) => true + | _ => false + } + | _ => false + } + | _ => false + } + + Test.run(__POS_OF__("Should decode JSON successfully"), decodedCorrectly, \"==", true) +} + +decodeJsonTest() diff --git a/tests/tests/src/core/Core_NullableTests.mjs b/tests/tests/src/core/Core_NullableTests.mjs new file mode 100644 index 0000000000..70100f2425 --- /dev/null +++ b/tests/tests/src/core/Core_NullableTests.mjs @@ -0,0 +1,55 @@ +// Generated by ReScript, PLEASE EDIT WITH CARE + +import * as Test from "./Test.mjs"; + +function shouldHandleNullableValues() { + var tNull = null; + var tUndefined = undefined; + var tValue = "hello"; + var tmp; + tmp = (tNull === null || tNull === undefined) && tNull === null ? true : false; + Test.run([ + [ + "NullableTests.res", + 9, + 15, + 35 + ], + "Should handle null" + ], tmp, (function (prim0, prim1) { + return prim0 === prim1; + }), true); + var tmp$1; + tmp$1 = (tUndefined === null || tUndefined === undefined) && tUndefined !== null ? true : false; + Test.run([ + [ + "NullableTests.res", + 19, + 15, + 40 + ], + "Should handle undefined" + ], tmp$1, (function (prim0, prim1) { + return prim0 === prim1; + }), true); + var tmp$2; + tmp$2 = tValue === null || tValue === undefined || tValue !== "hello" ? false : true; + Test.run([ + [ + "NullableTests.res", + 29, + 15, + 36 + ], + "Should handle value" + ], tmp$2, (function (prim0, prim1) { + return prim0 === prim1; + }), true); +} + +shouldHandleNullableValues(); + +export { + shouldHandleNullableValues , +} +/* Not a pure module */ diff --git a/tests/tests/src/core/Core_NullableTests.res b/tests/tests/src/core/Core_NullableTests.res new file mode 100644 index 0000000000..ca97174d9a --- /dev/null +++ b/tests/tests/src/core/Core_NullableTests.res @@ -0,0 +1,39 @@ +open RescriptCore + +let shouldHandleNullableValues = () => { + let tNull: Nullable.t = %raw("null") + let tUndefined: Nullable.t = %raw("undefined") + let tValue: Nullable.t = %raw(`"hello"`) + + Test.run( + __POS_OF__("Should handle null"), + switch tNull { + | Null => true + | Value(_) | Undefined => false + }, + \"==", + true, + ) + + Test.run( + __POS_OF__("Should handle undefined"), + switch tUndefined { + | Undefined => true + | Value(_) | Null => false + }, + \"==", + true, + ) + + Test.run( + __POS_OF__("Should handle value"), + switch tValue { + | Value("hello") => true + | _ => false + }, + \"==", + true, + ) +} + +shouldHandleNullableValues() diff --git a/tests/tests/src/core/Core_ObjectTests.mjs b/tests/tests/src/core/Core_ObjectTests.mjs new file mode 100644 index 0000000000..fd6355a2ef --- /dev/null +++ b/tests/tests/src/core/Core_ObjectTests.mjs @@ -0,0 +1,635 @@ +// Generated by ReScript, PLEASE EDIT WITH CARE + +import * as Test from "./Test.mjs"; +import * as Caml_obj from "rescript/lib/es6/caml_obj.js"; +import * as Core__Option from "../src/Core__Option.mjs"; + +var eq = Caml_obj.equal; + +Test.run([ + [ + "ObjectTests.res", + 12, + 20, + 30 + ], + "is: ints" + ], Object.is(25, 25), eq, true); + +Test.run([ + [ + "ObjectTests.res", + 14, + 20, + 33 + ], + "is: strings" + ], Object.is("abc", "abc"), eq, true); + +Test.run([ + [ + "ObjectTests.res", + 15, + 20, + 33 + ], + "is: strings" + ], Object.is("abc", "ABC"), eq, false); + +Test.run([ + [ + "ObjectTests.res", + 17, + 20, + 44 + ], + "is: null and undefined" + ], Object.is(null, undefined), eq, false); + +Test.run([ + [ + "ObjectTests.res", + 18, + 20, + 44 + ], + "is: null and undefined" + ], Object.is(undefined, undefined), eq, true); + +Test.run([ + [ + "ObjectTests.res", + 19, + 20, + 44 + ], + "is: null and undefined" + ], Object.is(null, null), eq, true); + +var nums = [ + 1, + 2, + 3 +]; + +Test.run([ + [ + "ObjectTests.res", + 22, + 20, + 32 + ], + "is: arrays" + ], Object.is([ + 1, + 2, + 3 + ], [ + 1, + 2, + 3 + ]), eq, false); + +Test.run([ + [ + "ObjectTests.res", + 23, + 20, + 32 + ], + "is: arrays" + ], Object.is(nums, nums), eq, true); + +Test.run([ + [ + "ObjectTests.res", + 24, + 20, + 32 + ], + "is: arrays" + ], Caml_obj.equal([ + 1, + 2, + 3 + ], [ + 1, + 2, + 3 + ]), eq, true); + +Test.run([ + [ + "ObjectTests.res", + 25, + 20, + 32 + ], + "is: arrays" + ], [ + 1, + 2, + 3 + ] === [ + 1, + 2, + 3 + ], eq, false); + +Test.run([ + [ + "ObjectTests.res", + 27, + 20, + 30 + ], + "is: list" + ], Object.is({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }, { + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }), eq, false); + +Test.run([ + [ + "ObjectTests.res", + 28, + 20, + 30 + ], + "is: list" + ], Caml_obj.equal({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }, { + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }), eq, true); + +Test.run([ + [ + "ObjectTests.res", + 29, + 20, + 30 + ], + "is: list" + ], ({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }) === ({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }), eq, false); + +var d = new Date(2000, 1); + +Test.run([ + [ + "ObjectTests.res", + 33, + 13, + 23 + ], + "is: date" + ], Object.is(new Date(2000, 1), new Date(2000, 1)), eq, false); + +Test.run([ + [ + "ObjectTests.res", + 38, + 20, + 30 + ], + "is: date" + ], Object.is(d, d), eq, true); + +var x = { + a: 1 +}; + +Test.run([ + [ + "ObjectTests.res", + 41, + 20, + 33 + ], + "is: objects" + ], Object.is(x, x), eq, true); + +Test.run([ + [ + "ObjectTests.res", + 42, + 20, + 33 + ], + "is: objects" + ], Object.is({ + a: 1 + }, { + a: 1 + }), eq, false); + +Test.run([ + [ + "ObjectTests.res", + 43, + 20, + 33 + ], + "is: objects" + ], Object.is({}, {}), eq, false); + +Test.run([ + [ + "ObjectTests.res", + 44, + 20, + 45 + ], + "is: === and == operator" + ], x === x, eq, true); + +Test.run([ + [ + "ObjectTests.res", + 45, + 20, + 45 + ], + "is: === and == operator" + ], Caml_obj.equal(x, x), eq, true); + +Test.run([ + [ + "ObjectTests.res", + 46, + 20, + 45 + ], + "is: === and == operator" + ], Caml_obj.equal({ + a: 1 + }, { + a: 1 + }), eq, true); + +Test.run([ + [ + "ObjectTests.res", + 48, + 20, + 31 + ], + "is: zeros" + ], Object.is(0, 0), eq, true); + +Test.run([ + [ + "ObjectTests.res", + 49, + 20, + 31 + ], + "is: zeros" + ], Object.is(-0.0, -0.0), eq, true); + +Test.run([ + [ + "ObjectTests.res", + 50, + 20, + 31 + ], + "is: zeros" + ], Object.is(0.0, -0.0), eq, false); + +function mkBig(s) { + return BigInt(s); +} + +Test.run([ + [ + "ObjectTests.res", + 53, + 20, + 32 + ], + "is: bigint" + ], Object.is(BigInt("123456789"), BigInt("123456789")), eq, true); + +Test.run([ + [ + "ObjectTests.res", + 54, + 20, + 32 + ], + "is: bigint" + ], Object.is(BigInt("123489"), BigInt("123456789")), eq, false); + +Test.run([ + [ + "ObjectTests.res", + 55, + 20, + 32 + ], + "is: bigint" + ], Object.is(BigInt("000000000"), BigInt("0")), eq, true); + +Test.run([ + [ + "ObjectTests.res", + 56, + 20, + 32 + ], + "is: bigint" + ], BigInt("123") === BigInt("123"), eq, true); + +Test.run([ + [ + "ObjectTests.res", + 57, + 20, + 32 + ], + "is: bigint" + ], BigInt("123") === BigInt("123"), eq, true); + +Test.run([ + [ + "ObjectTests.res", + 62, + 13, + 50 + ], + "assign copies from source to target" + ], Object.assign({ + a: 1, + b: 2 + }, { + b: 3, + c: 0 + }), eq, { + a: 1, + b: 3, + c: 0 + }); + +function assignOverwritesTarget(title, source) { + var sourceObj = { + a: source + }; + Test.run([ + [ + "ObjectTests.res", + 70, + 22, + 39 + ], + "assign " + title + ], Object.assign({ + a: 1 + }, sourceObj), eq, sourceObj); + Test.run([ + [ + "ObjectTests.res", + 71, + 22, + 39 + ], + "assign " + title + ], Object.assign({ + a: undefined + }, sourceObj), eq, sourceObj); + Test.run([ + [ + "ObjectTests.res", + 72, + 22, + 39 + ], + "assign " + title + ], Object.assign({ + a: null + }, sourceObj), eq, sourceObj); +} + +assignOverwritesTarget("when source is undefined", undefined); + +assignOverwritesTarget("when source is null", null); + +assignOverwritesTarget("when source is a number", 1); + +assignOverwritesTarget("when source is a string", "abc"); + +function runGetTest(i) { + Test.run([ + [ + "ObjectTests.res", + 90, + 22, + 46 + ], + "Object.get: " + i.title + ], i.get(i.source()), eq, i.expected); +} + +runGetTest({ + title: "prop exists, return Some", + source: (function () { + return { + a: 1 + }; + }), + get: (function (__x) { + return __x["a"]; + }), + expected: 1 + }); + +runGetTest({ + title: "prop NOT exist, return None", + source: (function () { + return { + a: 1 + }; + }), + get: (function (i) { + return i["banana"]; + }), + expected: undefined + }); + +runGetTest({ + title: "prop like toString, return Some", + source: (function () { + return { + a: 1 + }; + }), + get: (function (i) { + return Core__Option.isSome(i["toString"]); + }), + expected: true + }); + +runGetTest({ + title: "prop exist but explicitly undefined, return None", + source: (function () { + return { + a: undefined + }; + }), + get: (function (i) { + return i["a"]; + }), + expected: undefined + }); + +runGetTest({ + title: "prop exist but explicitly null, return None", + source: (function () { + return { + a: null + }; + }), + get: (function (i) { + return i["a"]; + }), + expected: null + }); + +runGetTest({ + title: "prop exists and is an array, can get it", + source: (function () { + return { + a: [ + 1, + 2, + 3 + ] + }; + }), + get: (function (i) { + return Core__Option.getOr(Core__Option.map(i["a"], (function (i) { + return i.concat([ + 4, + 5 + ]); + })), []); + }), + expected: [ + 1, + 2, + 3, + 4, + 5 + ] + }); + +function getSymbolTestWhenExists() { + var obj = {}; + var fruit = Symbol("fruit"); + obj[fruit] = "banana"; + var retrieved = obj[fruit]; + Test.run([ + [ + "ObjectTests.res", + 150, + 15, + 63 + ], + "Object.getSymbol when exists return it as Some" + ], retrieved, eq, "banana"); +} + +getSymbolTestWhenExists(); + +Test.run([ + [ + "ObjectTests.res", + 159, + 13, + 65 + ], + "Object.getSymbol when not exists return it as None" + ], ({})[Symbol("fruit")], eq, undefined); + +Test.run([ + [ + "ObjectTests.res", + 168, + 13, + 46 + ], + "Object.create clones properties" + ], Object.create({ + a: 1 + })["a"], eq, 1); + +Test.run([ + [ + "ObjectTests.res", + 175, + 13, + 46 + ], + "Object.create clones properties" + ], Object.create({ + a: 1 + })["b"], eq, undefined); + +export { + eq , + nums , + d , + x , + mkBig , + assignOverwritesTarget , + runGetTest , + getSymbolTestWhenExists , +} +/* Not a pure module */ diff --git a/tests/tests/src/core/Core_ObjectTests.res b/tests/tests/src/core/Core_ObjectTests.res new file mode 100644 index 0000000000..5b0cd7ac9f --- /dev/null +++ b/tests/tests/src/core/Core_ObjectTests.res @@ -0,0 +1,179 @@ +open RescriptCore + +let eq = (a, b) => a == b + +// ===== is ===== + +// == Removed when argument types were changed to be the same == +// Test.run(__POS_OF__("is: different types"), Object.is("abc", false), eq, false) +// Test.run(__POS_OF__("is: null and undefined"), Object.is(null, None), eq, false) +// Test.run(__POS_OF__("is: undefined and None"), Object.is(undefined, None), eq, true) + +Test.run(__POS_OF__("is: ints"), Object.is(25, 25), eq, true) + +Test.run(__POS_OF__("is: strings"), Object.is("abc", "abc"), eq, true) +Test.run(__POS_OF__("is: strings"), Object.is("abc", "ABC"), eq, false) + +Test.run(__POS_OF__("is: null and undefined"), Object.is(null, undefined), eq, false) +Test.run(__POS_OF__("is: null and undefined"), Object.is(undefined, undefined), eq, true) +Test.run(__POS_OF__("is: null and undefined"), Object.is(null, null), eq, true) + +let nums = [1, 2, 3] +Test.run(__POS_OF__("is: arrays"), Object.is([1, 2, 3], [1, 2, 3]), eq, false) +Test.run(__POS_OF__("is: arrays"), Object.is(nums, nums), eq, true) +Test.run(__POS_OF__("is: arrays"), [1, 2, 3] == [1, 2, 3], eq, true) +Test.run(__POS_OF__("is: arrays"), [1, 2, 3] === [1, 2, 3], eq, false) + +Test.run(__POS_OF__("is: list"), Object.is(list{1, 2, 3}, list{1, 2, 3}), eq, false) +Test.run(__POS_OF__("is: list"), list{1, 2, 3} == list{1, 2, 3}, eq, true) +Test.run(__POS_OF__("is: list"), list{1, 2, 3} === list{1, 2, 3}, eq, false) + +let d = Date.makeWithYM(~year=2000, ~month=1) +Test.run( + __POS_OF__("is: date"), + Object.is(Date.makeWithYM(~year=2000, ~month=1), Date.makeWithYM(~year=2000, ~month=1)), + eq, + false, +) +Test.run(__POS_OF__("is: date"), Object.is(d, d), eq, true) + +let x = {"a": 1} +Test.run(__POS_OF__("is: objects"), Object.is(x, x), eq, true) +Test.run(__POS_OF__("is: objects"), Object.is({"a": 1}, {"a": 1}), eq, false) +Test.run(__POS_OF__("is: objects"), Object.is(Object.make(), Object.make()), eq, false) // hmm... +Test.run(__POS_OF__("is: === and == operator"), x === x, eq, true) +Test.run(__POS_OF__("is: === and == operator"), x == x, eq, true) +Test.run(__POS_OF__("is: === and == operator"), {"a": 1} == {"a": 1}, eq, true) + +Test.run(__POS_OF__("is: zeros"), Object.is(-0, -0), eq, true) +Test.run(__POS_OF__("is: zeros"), Object.is(-0.0, -0.0), eq, true) +Test.run(__POS_OF__("is: zeros"), Object.is(0.0, -0.0), eq, false) + +let mkBig = s => BigInt.fromString(s) +Test.run(__POS_OF__("is: bigint"), Object.is(mkBig("123456789"), mkBig("123456789")), eq, true) +Test.run(__POS_OF__("is: bigint"), Object.is(mkBig("123489"), mkBig("123456789")), eq, false) +Test.run(__POS_OF__("is: bigint"), Object.is(mkBig("000000000"), mkBig("0")), eq, true) +Test.run(__POS_OF__("is: bigint"), mkBig("123") == mkBig("123"), eq, true) +Test.run(__POS_OF__("is: bigint"), mkBig("123") === mkBig("123"), eq, true) + +// ====== assign ====== + +Test.run( + __POS_OF__("assign copies from source to target"), + Object.assign({"a": 1, "b": 2}, {"b": 3, "c": 0}), + eq, + {"a": 1, "b": 3, "c": 0}, +) + +let assignOverwritesTarget = (~title, ~source) => { + let sourceObj = {"a": source} + Test.run(__POS_OF__(`assign ${title}`), Object.assign({"a": 1}, sourceObj), eq, sourceObj) + Test.run(__POS_OF__(`assign ${title}`), Object.assign({"a": undefined}, sourceObj), eq, sourceObj) + Test.run(__POS_OF__(`assign ${title}`), Object.assign({"a": null}, sourceObj), eq, sourceObj) +} + +assignOverwritesTarget(~title="when source is undefined", ~source=undefined) +assignOverwritesTarget(~title="when source is null", ~source=null) +assignOverwritesTarget(~title="when source is a number", ~source=1) +assignOverwritesTarget(~title="when source is a string", ~source="abc") + +// ===== get ===== + +type getTestData<'obj, 'res, 'expected> = { + title: string, + source: unit => 'obj, + get: 'obj => 'res, + expected: 'expected, +} + +let runGetTest = i => + Test.run(__POS_OF__(`Object.get: ${i.title}`), i.source()->i.get, eq, i.expected) + +{ + title: "prop exists, return Some", + source: () => {"a": 1}, + get: Object.get(_, "a"), + expected: Some(1), +}->runGetTest + +{ + title: "prop NOT exist, return None", + source: () => {"a": 1}, + get: i => i->Object.get("banana"), + expected: None, +}->runGetTest + +{ + title: "prop like toString, return Some", + source: () => {"a": 1}, + get: i => i->Object.get("toString")->Option.isSome, + expected: true, +}->runGetTest + +{ + title: "prop exist but explicitly undefined, return None", + source: () => {"a": undefined}, + get: i => i->Object.get("a"), + expected: None, +}->runGetTest + +{ + title: "prop exist but explicitly null, return None", + source: () => {"a": null}, + get: i => i->Object.get("a"), + expected: Some(null), +}->runGetTest + +{ + title: "prop exists and is an array, can get it", + source: () => {"a": [1, 2, 3]}, + get: i => i->Object.get("a")->Option.map(i => i->Array.concat([4, 5]))->Option.getOr([]), + expected: [1, 2, 3, 4, 5], +}->runGetTest + +// This throws an exception +// { +// title: "prop exists but casted wrong on get", +// source: () => {"a": 34}, +// get: i => i->Object.get("a")->Option.map(i => i->Array.concat([4, 5]))->Option.getWithDefault([]), +// expected: [], +// }->runGetTest + +// ===== getSymbol ===== + +let getSymbolTestWhenExists = () => { + let obj = Object.make() + let fruit = Symbol.make("fruit") + obj->Object.setSymbol(fruit, "banana") + let retrieved = obj->Object.getSymbol(fruit) + Test.run( + __POS_OF__(`Object.getSymbol when exists return it as Some`), + retrieved, + eq, + Some("banana"), + ) +} +getSymbolTestWhenExists() + +Test.run( + __POS_OF__(`Object.getSymbol when not exists return it as None`), + Object.make()->Object.getSymbol(Symbol.make("fruit")), + eq, + None, +) + +// ===== create ===== + +Test.run( + __POS_OF__(`Object.create clones properties`), + {"a": 1}->Object.create->Object.get("a"), + eq, + Some(1), +) + +Test.run( + __POS_OF__(`Object.create clones properties`), + {"a": 1}->Object.create->Object.get("b"), + eq, + None, +) diff --git a/tests/tests/src/core/Core_PromiseTest.mjs b/tests/tests/src/core/Core_PromiseTest.mjs new file mode 100644 index 0000000000..ffdb1df1d2 --- /dev/null +++ b/tests/tests/src/core/Core_PromiseTest.mjs @@ -0,0 +1,724 @@ +// Generated by ReScript, PLEASE EDIT WITH CARE + +import * as Test from "./Test.mjs"; +import * as Js_exn from "rescript/lib/es6/js_exn.js"; +import * as Caml_obj from "rescript/lib/es6/caml_obj.js"; +import * as Core__Promise from "../src/Core__Promise.mjs"; +import * as Caml_exceptions from "rescript/lib/es6/caml_exceptions.js"; + +var TestError = /* @__PURE__ */Caml_exceptions.create("PromiseTest.TestError"); + +var fail = Js_exn.raiseError; + +var equal = Caml_obj.equal; + +function resolveTest() { + Promise.resolve("test").then(function (str) { + Test.run([ + [ + "PromiseTest.res", + 19, + 26, + 47 + ], + "Should resolve test" + ], str, equal, "test"); + return Promise.resolve(); + }); +} + +function runTests() { + resolveTest(); +} + +var Creation = { + resolveTest: resolveTest, + runTests: runTests +}; + +function testThen() { + return Promise.resolve(1).then(function (first) { + return Promise.resolve(first + 1 | 0); + }).then(function (value) { + Test.run([ + [ + "PromiseTest.res", + 41, + 26, + 39 + ], + "Should be 2" + ], value, equal, 2); + return Promise.resolve(); + }); +} + +function testInvalidThen() { + return Promise.resolve(1).then(function (first) { + return Promise.resolve(Promise.resolve(first + 1 | 0)); + }).then(function (p) { + var isPromise = typeof p === "object"; + Test.run([ + [ + "PromiseTest.res", + 56, + 26, + 51 + ], + "Should not be a promise" + ], isPromise, equal, false); + return Promise.resolve(); + }); +} + +function testThenResolve() { + return Promise.resolve(1).then(function (num) { + return num + 1 | 0; + }).then(function (ret) { + Test.run([ + [ + "PromiseTest.res", + 69, + 26, + 39 + ], + "Should be 2" + ], ret, equal, 2); + }); +} + +function testInvalidThenResolve() { + return Promise.resolve(1).then(function (num) { + return Promise.resolve(num); + }).then(function (p) { + var isPromise = typeof p === "object"; + Test.run([ + [ + "PromiseTest.res", + 83, + 26, + 51 + ], + "Should not be a promise" + ], isPromise, equal, false); + return Promise.resolve(); + }); +} + +function runTests$1() { + testThen(); + testInvalidThen(); + testThenResolve(); + testInvalidThenResolve(); +} + +var ThenChaining = { + testThen: testThen, + testInvalidThen: testInvalidThen, + testThenResolve: testThenResolve, + testInvalidThenResolve: testInvalidThenResolve, + runTests: runTests$1 +}; + +function testExnRejection() { + Core__Promise.$$catch(Promise.reject({ + RE_EXN_ID: TestError, + _1: "oops" + }), (function (e) { + Test.run([ + [ + "PromiseTest.res", + 105, + 26, + 30 + ], + "Expect rejection to contain a TestError" + ], e, equal, { + RE_EXN_ID: TestError, + _1: "oops" + }); + return Promise.resolve(); + })); +} + +function runTests$2() { + testExnRejection(); +} + +var Rejection = { + testExnRejection: testExnRejection, + runTests: runTests$2 +}; + +var asyncParseFail = (function() { + return new Promise((resolve) => { + var result = JSON.parse("{.."); + return resolve(result); + }) + }); + +function testExternalPromiseThrow() { + return Core__Promise.$$catch(asyncParseFail().then(function (param) { + return Promise.resolve(); + }), (function (e) { + var success = e.RE_EXN_ID === Js_exn.$$Error ? Caml_obj.equal(e._1.name, "SyntaxError") : false; + Test.run([ + [ + "PromiseTest.res", + 139, + 26, + 76 + ], + "Should be a parser error with Unexpected token ." + ], success, equal, true); + return Promise.resolve(); + })); +} + +function testExnThrow() { + return Core__Promise.$$catch(Promise.resolve().then(function () { + throw { + RE_EXN_ID: TestError, + _1: "Thrown exn", + Error: new Error() + }; + }), (function (e) { + var isTestErr = e.RE_EXN_ID === TestError && e._1 === "Thrown exn" ? true : false; + Test.run([ + [ + "PromiseTest.res", + 158, + 26, + 49 + ], + "Should be a TestError" + ], isTestErr, equal, true); + return Promise.resolve(); + })); +} + +function testRaiseErrorThrow() { + return Core__Promise.$$catch(Promise.resolve().then(function () { + return Js_exn.raiseError("Some JS error"); + }), (function (e) { + var isTestErr = e.RE_EXN_ID === Js_exn.$$Error ? Caml_obj.equal(e._1.message, "Some JS error") : false; + Test.run([ + [ + "PromiseTest.res", + 181, + 26, + 51 + ], + "Should be some JS error" + ], isTestErr, equal, true); + return Promise.resolve(); + })); +} + +function thenAfterCatch() { + return Core__Promise.$$catch(Promise.resolve().then(function () { + return Promise.reject({ + RE_EXN_ID: TestError, + _1: "some rejected value" + }); + }), (function (e) { + var tmp; + tmp = e.RE_EXN_ID === TestError && e._1 === "some rejected value" ? "success" : "not a test error"; + return Promise.resolve(tmp); + })).then(function (msg) { + Test.run([ + [ + "PromiseTest.res", + 204, + 26, + 45 + ], + "Should be success" + ], msg, equal, "success"); + return Promise.resolve(); + }); +} + +function testCatchFinally() { + var wasCalled = { + contents: false + }; + Core__Promise.$$catch(Promise.resolve(5).then(function (param) { + return Promise.reject({ + RE_EXN_ID: TestError, + _1: "test" + }); + }).then(function (v) { + return Promise.resolve(v); + }), (function (param) { + return Promise.resolve(); + })).finally(function () { + wasCalled.contents = true; + }).then(function (v) { + Test.run([ + [ + "PromiseTest.res", + 226, + 26, + 48 + ], + "value should be unit" + ], v, equal, undefined); + Test.run([ + [ + "PromiseTest.res", + 227, + 26, + 59 + ], + "finally should have been called" + ], wasCalled.contents, equal, true); + return Promise.resolve(); + }); +} + +function testResolveFinally() { + var wasCalled = { + contents: false + }; + Promise.resolve(5).then(function (v) { + return Promise.resolve(v + 5 | 0); + }).finally(function () { + wasCalled.contents = true; + }).then(function (v) { + Test.run([ + [ + "PromiseTest.res", + 244, + 26, + 45 + ], + "value should be 5" + ], v, equal, 10); + Test.run([ + [ + "PromiseTest.res", + 245, + 26, + 59 + ], + "finally should have been called" + ], wasCalled.contents, equal, true); + return Promise.resolve(); + }); +} + +function runTests$3() { + testExternalPromiseThrow(); + testExnThrow(); + testRaiseErrorThrow(); + thenAfterCatch(); + testCatchFinally(); + testResolveFinally(); +} + +var Catching = { + asyncParseFail: asyncParseFail, + testExternalPromiseThrow: testExternalPromiseThrow, + testExnThrow: testExnThrow, + testRaiseErrorThrow: testRaiseErrorThrow, + thenAfterCatch: thenAfterCatch, + testCatchFinally: testCatchFinally, + testResolveFinally: testResolveFinally, + runTests: runTests$3 +}; + +function testParallel() { + var place = { + contents: 0 + }; + var delayedMsg = function (ms, msg) { + return new Promise((function (resolve, param) { + setTimeout((function () { + place.contents = place.contents + 1 | 0; + resolve([ + place.contents, + msg + ]); + }), ms); + })); + }; + var p1 = delayedMsg(1000, "is Anna"); + var p2 = delayedMsg(500, "myName"); + var p3 = delayedMsg(100, "Hi"); + return Promise.all([ + p1, + p2, + p3 + ]).then(function (arr) { + var exp = [ + [ + 3, + "is Anna" + ], + [ + 2, + "myName" + ], + [ + 1, + "Hi" + ] + ]; + Test.run([ + [ + "PromiseTest.res", + 282, + 26, + 55 + ], + "Should have correct placing" + ], arr, equal, exp); + return Promise.resolve(); + }); +} + +function testRace() { + var racer = function (ms, name) { + return new Promise((function (resolve, param) { + setTimeout((function () { + resolve(name); + }), ms); + })); + }; + var promises = [ + racer(1000, "Turtle"), + racer(500, "Hare"), + racer(100, "Eagle") + ]; + return Promise.race(promises).then(function (winner) { + Test.run([ + [ + "PromiseTest.res", + 301, + 26, + 44 + ], + "Eagle should win" + ], winner, equal, "Eagle"); + return Promise.resolve(); + }); +} + +function testParallel2() { + var place = { + contents: 0 + }; + var delayedMsg = function (ms, msg) { + return new Promise((function (resolve, param) { + setTimeout((function () { + place.contents = place.contents + 1 | 0; + resolve([ + place.contents, + msg + ]); + }), ms); + })); + }; + var p1 = delayedMsg(1000, "is Anna"); + var p2 = delayedMsg(500, "myName"); + return Promise.all([ + p1, + p2 + ]).then(function (arr) { + Test.run([ + [ + "PromiseTest.res", + 325, + 26, + 55 + ], + "Should have correct placing" + ], arr, equal, [ + [ + 2, + "is Anna" + ], + [ + 1, + "myName" + ] + ]); + return Promise.resolve(); + }); +} + +function testParallel3() { + var place = { + contents: 0 + }; + var delayedMsg = function (ms, msg) { + return new Promise((function (resolve, param) { + setTimeout((function () { + place.contents = place.contents + 1 | 0; + resolve([ + place.contents, + msg + ]); + }), ms); + })); + }; + var p1 = delayedMsg(1000, "is Anna"); + var p2 = delayedMsg(500, "myName"); + var p3 = delayedMsg(100, "Hi"); + return Promise.all([ + p1, + p2, + p3 + ]).then(function (arr) { + Test.run([ + [ + "PromiseTest.res", + 350, + 26, + 55 + ], + "Should have correct placing" + ], arr, equal, [ + [ + 3, + "is Anna" + ], + [ + 2, + "myName" + ], + [ + 1, + "Hi" + ] + ]); + return Promise.resolve(); + }); +} + +function testParallel4() { + var place = { + contents: 0 + }; + var delayedMsg = function (ms, msg) { + return new Promise((function (resolve, param) { + setTimeout((function () { + place.contents = place.contents + 1 | 0; + resolve([ + place.contents, + msg + ]); + }), ms); + })); + }; + var p1 = delayedMsg(1500, "Anna"); + var p2 = delayedMsg(1000, "is"); + var p3 = delayedMsg(500, "my name"); + var p4 = delayedMsg(100, "Hi"); + return Promise.all([ + p1, + p2, + p3, + p4 + ]).then(function (arr) { + Test.run([ + [ + "PromiseTest.res", + 376, + 26, + 55 + ], + "Should have correct placing" + ], arr, equal, [ + [ + 4, + "Anna" + ], + [ + 3, + "is" + ], + [ + 2, + "my name" + ], + [ + 1, + "Hi" + ] + ]); + return Promise.resolve(); + }); +} + +function testParallel5() { + var place = { + contents: 0 + }; + var delayedMsg = function (ms, msg) { + return new Promise((function (resolve, param) { + setTimeout((function () { + place.contents = place.contents + 1 | 0; + resolve([ + place.contents, + msg + ]); + }), ms); + })); + }; + var p1 = delayedMsg(1500, "Anna"); + var p2 = delayedMsg(1000, "is"); + var p3 = delayedMsg(500, "name"); + var p4 = delayedMsg(100, "my"); + var p5 = delayedMsg(50, "Hi"); + return Promise.all([ + p1, + p2, + p3, + p4, + p5 + ]).then(function (arr) { + Test.run([ + [ + "PromiseTest.res", + 403, + 26, + 55 + ], + "Should have correct placing" + ], arr, equal, [ + [ + 5, + "Anna" + ], + [ + 4, + "is" + ], + [ + 3, + "name" + ], + [ + 2, + "my" + ], + [ + 1, + "Hi" + ] + ]); + return Promise.resolve(); + }); +} + +function testParallel6() { + var place = { + contents: 0 + }; + var delayedMsg = function (ms, msg) { + return new Promise((function (resolve, param) { + setTimeout((function () { + place.contents = place.contents + 1 | 0; + resolve([ + place.contents, + msg + ]); + }), ms); + })); + }; + var p1 = delayedMsg(1500, "Anna"); + var p2 = delayedMsg(1000, "is"); + var p3 = delayedMsg(500, "name"); + var p4 = delayedMsg(100, "my"); + var p5 = delayedMsg(50, ", "); + var p6 = delayedMsg(10, "Hi"); + return Promise.all([ + p1, + p2, + p3, + p4, + p5, + p6 + ]).then(function (arr) { + Test.run([ + [ + "PromiseTest.res", + 431, + 26, + 55 + ], + "Should have correct placing" + ], arr, equal, [ + [ + 6, + "Anna" + ], + [ + 5, + "is" + ], + [ + 4, + "name" + ], + [ + 3, + "my" + ], + [ + 2, + ", " + ], + [ + 1, + "Hi" + ] + ]); + return Promise.resolve(); + }); +} + +function runTests$4() { + testParallel(); + testRace(); + testParallel2(); + testParallel3(); + testParallel4(); + testParallel5(); + testParallel6(); +} + +var Concurrently = { + testParallel: testParallel, + testRace: testRace, + testParallel2: testParallel2, + testParallel3: testParallel3, + testParallel4: testParallel4, + testParallel5: testParallel5, + testParallel6: testParallel6, + runTests: runTests$4 +}; + +resolveTest(); + +runTests$1(); + +testExnRejection(); + +runTests$3(); + +runTests$4(); + +export { + TestError , + fail , + equal , + Creation , + ThenChaining , + Rejection , + Catching , + Concurrently , +} +/* Not a pure module */ diff --git a/tests/tests/src/core/Core_PromiseTest.res b/tests/tests/src/core/Core_PromiseTest.res new file mode 100644 index 0000000000..35197feae3 --- /dev/null +++ b/tests/tests/src/core/Core_PromiseTest.res @@ -0,0 +1,451 @@ +open RescriptCore + +exception TestError(string) + +let fail = msg => { + Exn.raiseError(msg) +} + +let equal = (a, b) => { + a == b +} + +module Creation = { + let resolveTest = () => { + open Promise + + Promise.resolve("test") + ->then(str => { + Test.run(__POS_OF__("Should resolve test"), str, equal, "test") + resolve() + }) + ->ignore + } + + let runTests = () => { + resolveTest() + } +} + +module ThenChaining = { + // A promise should be able to return a nested + // Promise and also flatten it for another then call + // to the actual value + let testThen = () => { + open Promise + resolve(1) + ->then(first => { + resolve(first + 1) + }) + ->then(value => { + Test.run(__POS_OF__("Should be 2"), value, equal, 2) + resolve() + }) + } + + // It's not allowed to return a promise> value + // within a then. This operation will throw an error + let testInvalidThen = () => { + open Promise + resolve(1) + ->then(first => { + resolve(resolve(first + 1)) + }) + ->then(p => { + let isPromise = Type.typeof((p: promise<_>)) == #object + Test.run(__POS_OF__("Should not be a promise"), isPromise, equal, false) + resolve() + }) + } + + let testThenResolve = () => { + open Promise + + resolve(1) + ->thenResolve(num => { + num + 1 + }) + ->thenResolve(ret => { + Test.run(__POS_OF__("Should be 2"), ret, equal, 2) + }) + } + + let testInvalidThenResolve = () => { + open Promise + + resolve(1) + ->thenResolve(num => { + // This is against the law + resolve(num) + }) + ->then(p => { + let isPromise = Type.typeof((p: promise<_>)) == #object + Test.run(__POS_OF__("Should not be a promise"), isPromise, equal, false) + resolve() + }) + } + + let runTests = () => { + testThen()->ignore + testInvalidThen()->ignore + testThenResolve()->ignore + testInvalidThenResolve()->ignore + } +} + +module Rejection = { + // Should gracefully handle a exn passed via reject() + let testExnRejection = () => { + let cond = "Expect rejection to contain a TestError" + open Promise + + TestError("oops") + ->reject + ->catch(e => { + Test.run(__POS_OF__(cond), e, equal, TestError("oops")) + resolve() + }) + ->ignore + } + + let runTests = () => { + testExnRejection()->ignore + } +} + +module Catching = { + let asyncParseFail: unit => promise = %raw(` + function() { + return new Promise((resolve) => { + var result = JSON.parse("{.."); + return resolve(result); + }) + } + `) + + // Should correctly capture an JS error thrown within + // a Promise `then` function + let testExternalPromiseThrow = () => { + open Promise + + asyncParseFail() + ->then(_ => resolve()) // Since our asyncParse will fail anyways, we convert to promise for our catch later + ->catch(e => { + let success = switch e { + | Exn.Error(err) => Exn.name(err) == Some("SyntaxError") + | _ => false + } + + Test.run(__POS_OF__("Should be a parser error with Unexpected token ."), success, equal, true) + resolve() + }) + } + + // Should correctly capture an exn thrown in a Promise + // `then` function + let testExnThrow = () => { + open Promise + + resolve() + ->then(_ => { + raise(TestError("Thrown exn")) + }) + ->catch(e => { + let isTestErr = switch e { + | TestError("Thrown exn") => true + | _ => false + } + Test.run(__POS_OF__("Should be a TestError"), isTestErr, equal, true) + resolve() + }) + } + + // Should correctly capture a JS error raised with Exn.raiseError + // within a Promise then function + let testRaiseErrorThrow = () => { + open Promise + + let causeErr = () => { + Exn.raiseError("Some JS error") + } + + resolve() + ->then(_ => { + causeErr() + }) + ->catch(e => { + let isTestErr = switch e { + | Exn.Error(err) => Exn.message(err) == Some("Some JS error") + | _ => false + } + Test.run(__POS_OF__("Should be some JS error"), isTestErr, equal, true) + resolve() + }) + } + + // Should recover a rejection and use then to + // access the value + let thenAfterCatch = () => { + open Promise + resolve() + ->then(_ => { + // NOTE: if then is used, there will be an uncaught + // error + reject(TestError("some rejected value")) + }) + ->catch(e => { + let s = switch e { + | TestError("some rejected value") => "success" + | _ => "not a test error" + } + resolve(s) + }) + ->then(msg => { + Test.run(__POS_OF__("Should be success"), msg, equal, "success") + resolve() + }) + } + + let testCatchFinally = () => { + open Promise + let wasCalled = ref(false) + resolve(5) + ->then(_ => { + reject(TestError("test")) + }) + ->then(v => { + v->resolve + }) + ->catch(_ => { + resolve() + }) + ->finally(() => { + wasCalled := true + }) + ->then(v => { + Test.run(__POS_OF__("value should be unit"), v, equal, ()) + Test.run(__POS_OF__("finally should have been called"), wasCalled.contents, equal, true) + resolve() + }) + ->ignore + } + + let testResolveFinally = () => { + open Promise + let wasCalled = ref(false) + resolve(5) + ->then(v => { + resolve(v + 5) + }) + ->finally(() => { + wasCalled := true + }) + ->then(v => { + Test.run(__POS_OF__("value should be 5"), v, equal, 10) + Test.run(__POS_OF__("finally should have been called"), wasCalled.contents, equal, true) + resolve() + }) + ->ignore + } + + let runTests = () => { + testExternalPromiseThrow()->ignore + testExnThrow()->ignore + testRaiseErrorThrow()->ignore + thenAfterCatch()->ignore + testCatchFinally()->ignore + testResolveFinally()->ignore + } +} + +module Concurrently = { + let testParallel = () => { + open Promise + + let place = ref(0) + + let delayedMsg = (ms, msg) => { + Promise.make((resolve, _) => { + setTimeout(() => { + place := place.contents + 1 + resolve((place.contents, msg)) + }, ms)->ignore + }) + } + + let p1 = delayedMsg(1000, "is Anna") + let p2 = delayedMsg(500, "myName") + let p3 = delayedMsg(100, "Hi") + + all([p1, p2, p3])->then(arr => { + let exp = [(3, "is Anna"), (2, "myName"), (1, "Hi")] + Test.run(__POS_OF__("Should have correct placing"), arr, equal, exp) + resolve() + }) + } + + let testRace = () => { + open Promise + + let racer = (ms, name) => { + Promise.make((resolve, _) => { + setTimeout(() => { + resolve(name) + }, ms)->ignore + }) + } + + let promises = [racer(1000, "Turtle"), racer(500, "Hare"), racer(100, "Eagle")] + + race(promises)->then(winner => { + Test.run(__POS_OF__("Eagle should win"), winner, equal, "Eagle") + resolve() + }) + } + + let testParallel2 = () => { + open Promise + + let place = ref(0) + + let delayedMsg = (ms, msg) => { + Promise.make((resolve, _) => { + setTimeout(() => { + place := place.contents + 1 + resolve((place.contents, msg)) + }, ms)->ignore + }) + } + + let p1 = delayedMsg(1000, "is Anna") + let p2 = delayedMsg(500, "myName") + + all2((p1, p2))->then(arr => { + let exp = ((2, "is Anna"), (1, "myName")) + Test.run(__POS_OF__("Should have correct placing"), arr, equal, exp) + resolve() + }) + } + + let testParallel3 = () => { + open Promise + + let place = ref(0) + + let delayedMsg = (ms, msg) => { + Promise.make((resolve, _) => { + setTimeout(() => { + place := place.contents + 1 + resolve((place.contents, msg)) + }, ms)->ignore + }) + } + + let p1 = delayedMsg(1000, "is Anna") + let p2 = delayedMsg(500, "myName") + let p3 = delayedMsg(100, "Hi") + + all3((p1, p2, p3))->then(arr => { + let exp = ((3, "is Anna"), (2, "myName"), (1, "Hi")) + Test.run(__POS_OF__("Should have correct placing"), arr, equal, exp) + resolve() + }) + } + + let testParallel4 = () => { + open Promise + + let place = ref(0) + + let delayedMsg = (ms, msg) => { + Promise.make((resolve, _) => { + setTimeout(() => { + place := place.contents + 1 + resolve((place.contents, msg)) + }, ms)->ignore + }) + } + + let p1 = delayedMsg(1500, "Anna") + let p2 = delayedMsg(1000, "is") + let p3 = delayedMsg(500, "my name") + let p4 = delayedMsg(100, "Hi") + + all4((p1, p2, p3, p4))->then(arr => { + let exp = ((4, "Anna"), (3, "is"), (2, "my name"), (1, "Hi")) + Test.run(__POS_OF__("Should have correct placing"), arr, equal, exp) + resolve() + }) + } + + let testParallel5 = () => { + open Promise + + let place = ref(0) + + let delayedMsg = (ms, msg) => { + Promise.make((resolve, _) => { + setTimeout(() => { + place := place.contents + 1 + resolve((place.contents, msg)) + }, ms)->ignore + }) + } + + let p1 = delayedMsg(1500, "Anna") + let p2 = delayedMsg(1000, "is") + let p3 = delayedMsg(500, "name") + let p4 = delayedMsg(100, "my") + let p5 = delayedMsg(50, "Hi") + + all5((p1, p2, p3, p4, p5))->then(arr => { + let exp = ((5, "Anna"), (4, "is"), (3, "name"), (2, "my"), (1, "Hi")) + Test.run(__POS_OF__("Should have correct placing"), arr, equal, exp) + resolve() + }) + } + + let testParallel6 = () => { + open Promise + + let place = ref(0) + + let delayedMsg = (ms, msg) => { + Promise.make((resolve, _) => { + setTimeout(() => { + place := place.contents + 1 + resolve((place.contents, msg)) + }, ms)->ignore + }) + } + + let p1 = delayedMsg(1500, "Anna") + let p2 = delayedMsg(1000, "is") + let p3 = delayedMsg(500, "name") + let p4 = delayedMsg(100, "my") + let p5 = delayedMsg(50, ", ") + let p6 = delayedMsg(10, "Hi") + + all6((p1, p2, p3, p4, p5, p6))->then(arr => { + let exp = ((6, "Anna"), (5, "is"), (4, "name"), (3, "my"), (2, ", "), (1, "Hi")) + Test.run(__POS_OF__("Should have correct placing"), arr, equal, exp) + resolve() + }) + } + + let runTests = () => { + testParallel()->ignore + testRace()->ignore + testParallel2()->ignore + testParallel3()->ignore + testParallel4()->ignore + testParallel5()->ignore + testParallel6()->ignore + } +} + +Creation.runTests() +ThenChaining.runTests() +Rejection.runTests() +Catching.runTests() +Concurrently.runTests() diff --git a/tests/tests/src/core/Core_ResultTests.mjs b/tests/tests/src/core/Core_ResultTests.mjs new file mode 100644 index 0000000000..a191b78440 --- /dev/null +++ b/tests/tests/src/core/Core_ResultTests.mjs @@ -0,0 +1,96 @@ +// Generated by ReScript, PLEASE EDIT WITH CARE + +import * as Test from "./Test.mjs"; +import * as Caml_obj from "rescript/lib/es6/caml_obj.js"; +import * as Core__Result from "../src/Core__Result.mjs"; + +var eq = Caml_obj.equal; + +function forEachIfOkCallFunction() { + var called = { + contents: [] + }; + Core__Result.forEach({ + TAG: "Ok", + _0: 3 + }, (function (i) { + called.contents.push(i); + })); + Test.run([ + [ + "ResultTests.res", + 12, + 22, + 72 + ], + "forEach: if ok, call function with ok value once" + ], called.contents, eq, [3]); +} + +forEachIfOkCallFunction(); + +function forEachIfErrorDoNotCallFunction() { + var called = { + contents: [] + }; + Core__Result.forEach({ + TAG: "Error", + _0: 3 + }, (function (i) { + called.contents.push(i); + })); + Test.run([ + [ + "ResultTests.res", + 19, + 22, + 63 + ], + "forEach: if error, do not call function" + ], called.contents, eq, []); +} + +forEachIfErrorDoNotCallFunction(); + +Test.run([ + [ + "ResultTests.res", + 27, + 20, + 48 + ], + "mapError: if ok, return it" + ], Core__Result.mapError({ + TAG: "Ok", + _0: 5 + }, (function (i) { + return Math.imul(i, 3); + })), eq, { + TAG: "Ok", + _0: 5 + }); + +Test.run([ + [ + "ResultTests.res", + 30, + 13, + 42 + ], + "mapError: if error, apply f" + ], Core__Result.mapError({ + TAG: "Error", + _0: 5 + }, (function (i) { + return Math.imul(i, 3); + })), eq, { + TAG: "Error", + _0: 15 + }); + +export { + eq , + forEachIfOkCallFunction , + forEachIfErrorDoNotCallFunction , +} +/* Not a pure module */ diff --git a/tests/tests/src/core/Core_ResultTests.res b/tests/tests/src/core/Core_ResultTests.res new file mode 100644 index 0000000000..040028c6ba --- /dev/null +++ b/tests/tests/src/core/Core_ResultTests.res @@ -0,0 +1,34 @@ +open RescriptCore + +let eq = (a, b) => a == b + +// ======= +// forEach +// ======= + +let forEachIfOkCallFunction = () => { + let called = ref([]) + Ok(3)->Result.forEach(i => called.contents->Array.push(i)) + Test.run(__POS_OF__("forEach: if ok, call function with ok value once"), called.contents, eq, [3]) +} +forEachIfOkCallFunction() + +let forEachIfErrorDoNotCallFunction = () => { + let called = ref([]) + Error(3)->Result.forEach(i => called.contents->Array.push(i)) + Test.run(__POS_OF__("forEach: if error, do not call function"), called.contents, eq, []) +} +forEachIfErrorDoNotCallFunction() + +// ======== +// mapError +// ======== + +Test.run(__POS_OF__("mapError: if ok, return it"), Ok(5)->Result.mapError(i => i * 3), eq, Ok(5)) + +Test.run( + __POS_OF__("mapError: if error, apply f"), + Error(5)->Result.mapError(i => i * 3), + eq, + Error(15), +) diff --git a/tests/tests/src/core/Core_StringTests.mjs b/tests/tests/src/core/Core_StringTests.mjs new file mode 100644 index 0000000000..9bb621669b --- /dev/null +++ b/tests/tests/src/core/Core_StringTests.mjs @@ -0,0 +1,21 @@ +// Generated by ReScript, PLEASE EDIT WITH CARE + +import * as Test from "./Test.mjs"; +import * as Caml_obj from "rescript/lib/es6/caml_obj.js"; + +var eq = Caml_obj.equal; + +Test.run([ + [ + "StringTests.res", + 5, + 20, + 47 + ], + "String.equal optimization" + ], false, eq, false); + +export { + eq , +} +/* Not a pure module */ diff --git a/tests/tests/src/core/Core_StringTests.res b/tests/tests/src/core/Core_StringTests.res new file mode 100644 index 0000000000..a476d408f8 --- /dev/null +++ b/tests/tests/src/core/Core_StringTests.res @@ -0,0 +1,5 @@ +open RescriptCore + +let eq = (a, b) => a == b + +Test.run(__POS_OF__("String.equal optimization"), String.equal("one", "three"), eq, false) diff --git a/tests/tests/src/core/Core_TempTests.mjs b/tests/tests/src/core/Core_TempTests.mjs new file mode 100644 index 0000000000..2506594be3 --- /dev/null +++ b/tests/tests/src/core/Core_TempTests.mjs @@ -0,0 +1,381 @@ +// Generated by ReScript, PLEASE EDIT WITH CARE + +import * as Core__Int from "../src/Core__Int.mjs"; +import * as IntlTests from "./intl/IntlTests.mjs"; +import * as Core__Dict from "../src/Core__Dict.mjs"; +import * as Core__JSON from "../src/Core__JSON.mjs"; +import * as Caml_bigint from "rescript/lib/es6/caml_bigint.js"; +import * as Caml_option from "rescript/lib/es6/caml_option.js"; +import * as Core__Array from "../src/Core__Array.mjs"; +import * as Core__Float from "../src/Core__Float.mjs"; +import * as Core__BigInt from "../src/Core__BigInt.mjs"; +import * as Core__Option from "../src/Core__Option.mjs"; + +console.info(""); + +console.info("Array"); + +console.info("---"); + +var array = [ + 1, + 2, + 3, + 4 +]; + +console.info(Core__Array.reduce(array.map(function (x) { + return (x << 1); + }), 0, (function (a, b) { + return a + b | 0; + }))); + +console.info(typeof array); + +console.info(""); + +console.info("Date"); + +console.info("---"); + +var date = new Date(Date.UTC(2020, 11)); + +console.log(date.toUTCString()); + +console.info(""); + +console.info("Dict"); + +console.info("---"); + +var dict = {}; + +dict["foo"] = "bar"; + +var dict2 = Object.assign({}, dict); + +Core__Dict.$$delete(dict2, "foo"); + +console.log(dict, dict2); + +console.info(""); + +console.info("Error"); + +console.info("---"); + +function f() { + var error = new Error("hello"); + var typeError = new TypeError("error"); + var g = function () { + throw error; + }; + var h = function () { + throw typeError; + }; + return [ + g, + h + ]; +} + +console.info(""); + +console.info("Float/Int"); + +console.info("---"); + +console.log((10.2).toFixed(2)); + +console.log((10).toFixed(2)); + +console.log(Core__Int.fromString("0", undefined)); + +console.log(Core__Float.fromString("0.1")); + +console.info(""); + +console.info("JSON"); + +console.info("---"); + +var json = JSON.parse("{\"foo\": \"bar\"}"); + +var json$1 = Core__JSON.Classify.classify(json); + +var tmp; + +if (typeof json$1 !== "object" || json$1.TAG !== "Object") { + tmp = undefined; +} else { + var value = Core__JSON.Classify.classify(json$1._0["foo"]); + tmp = typeof value !== "object" || value.TAG !== "String" ? undefined : value._0; +} + +console.log(tmp); + +console.info(""); + +console.info("Map"); + +console.info("---"); + +var map = new Map(); + +map.set(1, 1); + +map.set(2, 2); + +map.delete(1); + +console.log(map); + +console.info(""); + +console.info("Math"); + +console.info("---"); + +console.log(Math.ceil(Math.PI / 2.0)); + +console.info(""); + +console.info("BigInt"); + +console.info("---"); + +console.log(Caml_bigint.div(BigInt(1), BigInt(12.0))); + +console.info(""); + +console.info("Object"); + +console.info("---"); + +var myObject = { + foo: "bar" +}; + +console.log(Object.create(myObject)); + +console.log(Object.create(myObject, { + foo: { + value: "bar" + } + })); + +console.log(Object.create(null)); + +console.log(Object.create(null, { + foo: { + value: "bar" + } + })); + +var copy = Object.assign({}, myObject); + +var withNewProp = Object.assign(copy, { + bar: "baz" + }); + +console.info(""); + +console.info("Promise"); + +console.info("---"); + +var promise = new Promise((function (resolve, _reject) { + setTimeout((function () { + resolve(1); + }), 100); + })); + +promise.then(function (x) { + return Promise.resolve(x + 1 | 0); + }).then(function (x) { + return Promise.resolve(x + 2 | 0); + }).then(function (x) { + console.log(x); + return Promise.resolve(); + }).finally(function () { + console.log("Promise finally"); + }); + +console.info(""); + +console.info("RegExp"); + +console.info("---"); + +var regex = new RegExp("hello(\\w+)"); + +var string = "helloworld"; + +console.log(regex.test(string)); + +var result = regex.exec(string); + +var result$1 = (result == null) ? undefined : Caml_option.some(result); + +console.log(Core__Option.map(result$1, (function (prim) { + return prim.input; + }))); + +console.log(Core__Option.map(result$1, (function (prim) { + return prim.index; + }))); + +console.log(Core__Option.map(result$1, (function (prim) { + return prim.slice(1); + }))); + +console.info(""); + +console.info("Set"); + +console.info("---"); + +var set = new Set(); + +set.add(1); + +set.add(2); + +set.delete(2); + +console.log(set); + +console.info(""); + +console.info("String"); + +console.info("---"); + +var regexp = new RegExp("(hello )(world)"); + +console.log(" Hello world ".toLowerCase().trim().replace(regexp, (function (param, group1, group2, param$1, param$2) { + return group1 + group2.toUpperCase(); + }))); + +console.info(""); + +console.info("Symbol"); + +console.info("---"); + +var x = Symbol.for("Foo"); + +console.log(x); + +var array$1 = Array.from("foo"[Symbol.iterator]()); + +console.log(array$1); + +console.info(""); + +console.info("Global namespace"); + +console.info("---"); + +console.log("number"); + +var timeout = setTimeout((function () { + console.log("Hello!"); + }), 100); + +clearTimeout(timeout); + +if (globalThis.hello !== undefined) { + console.log(globalThis.hello.bar); + console.log("hello"); +} + +var z = 1.2 % 1.4; + +var intFromBigInt = Core__BigInt.toInt(BigInt("10000000000")); + +console.log({ + bar: "1" + }); + +var Bugfix = {}; + +console.log(Core__Int.fromString("1231231", undefined)); + +console.log(Core__Int.fromString("12.22", undefined)); + +console.log(Core__Int.fromString("99999999999999999", undefined)); + +console.log(Core__Int.fromString("99999999999999999", undefined)); + +console.log(Core__Int.fromString("010101", 2)); + +var _collator = IntlTests._collator; + +var collator = IntlTests.collator; + +var resolvedOptions = IntlTests.resolvedOptions; + +var timeZone = IntlTests.timeZone; + +var _locale = IntlTests._locale; + +var locale = IntlTests.locale; + +var currencyFormatter = IntlTests.currencyFormatter; + +var roundingFormatter = IntlTests.roundingFormatter; + +var groupingFormatter1 = IntlTests.groupingFormatter1; + +var groupingFormatter2 = IntlTests.groupingFormatter2; + +var sigFormatter = IntlTests.sigFormatter; + +var options = IntlTests.options; + +var _formatter = IntlTests._formatter; + +var formatter = IntlTests.formatter; + +var segments = IntlTests.segments; + +export { + _collator , + collator , + resolvedOptions , + timeZone , + _locale , + locale , + currencyFormatter , + roundingFormatter , + groupingFormatter1 , + groupingFormatter2 , + sigFormatter , + options , + _formatter , + formatter , + segments , + date , + dict , + dict2 , + f , + json , + map , + myObject , + copy , + withNewProp , + promise , + regex , + string , + result$1 as result, + set , + regexp , + x , + array$1 as array, + timeout , + z , + intFromBigInt , + Bugfix , +} +/* Not a pure module */ diff --git a/tests/tests/src/core/Core_TempTests.res b/tests/tests/src/core/Core_TempTests.res new file mode 100644 index 0000000000..7fc39d1c4d --- /dev/null +++ b/tests/tests/src/core/Core_TempTests.res @@ -0,0 +1,198 @@ +open RescriptCore + +include IntlTests + +Console.info("") +Console.info("Array") +Console.info("---") +let array = [1, 2, 3, 4] +Console.info(array->Array.map(x => x * 2)->Array.reduce(0, (a, b) => a + b)) +Console.info(typeof(array)) + +Console.info("") +Console.info("Date") +Console.info("---") +let date = Date.fromTime(Date.UTC.makeWithYM(~year=2020, ~month=11)) +Console.log(date->Date.toUTCString) + +Console.info("") +Console.info("Dict") +Console.info("---") +let dict = Dict.make() +dict->Dict.set("foo", "bar") +let dict2 = dict->Dict.copy +dict2->Dict.delete("foo") +Console.log2(dict, dict2) + +Console.info("") +Console.info("Error") +Console.info("---") +let f = () => { + let error = Error.make("hello") + let typeError = Error.TypeError.make("error") + let g = () => Error.raise(error) + let h = () => Error.raise(typeError) + (g, h) +} + +Console.info("") +Console.info("Float/Int") +Console.info("---") +Console.log(10.2->Float.toFixed(~digits=2)) +Console.log(10->Int.toFixed(~digits=2)) +Console.log("0"->Int.fromString) +Console.log("0.1"->Float.fromString) + +Console.info("") +Console.info("JSON") +Console.info("---") +let json = JSON.parseExn(`{"foo": "bar"}`) +Console.log( + switch JSON.Classify.classify(json) { + | Object(json) => + switch JSON.Classify.classify(json->Dict.get("foo")) { + | String(value) => Some(value) + | _ => None + } + | _ => None + }, +) + +Console.info("") +Console.info("Map") +Console.info("---") +let map = Map.make() +let _ = map->Map.set(1, 1) +let _ = map->Map.set(2, 2) +let _ = map->Map.delete(1) +Console.log(map) + +Console.info("") +Console.info("Math") +Console.info("---") +Console.log(Math.ceil(Math.Constants.pi /. 2.0)) + +Console.info("") +Console.info("BigInt") +Console.info("---") + +@warning("-44") +Console.log({ + open BigInt + fromInt(1) / fromFloat(12.0) +}) + +Console.info("") +Console.info("Object") +Console.info("---") +let myObject = { + "foo": "bar", +} + +Console.log(Object.create(myObject)) +Console.log(Object.createWithProperties(myObject, {"foo": {"value": "bar"}})) +Console.log(Object.createWithNull()) +Console.log(Object.createWithNullAndProperties({"foo": {"value": "bar"}})) + +let copy = Object.copy(myObject) +let withNewProp = Object.assign(copy, {"bar": "baz"}) + +Console.info("") +Console.info("Promise") +Console.info("---") +let promise: promise = Promise.make((resolve, _reject) => { + let _ = setTimeout(() => { + resolve(1) + }, 100) +}) + +let _ = + promise + ->Promise.then(x => Promise.resolve(x + 1)) + ->Promise.then(x => Promise.resolve(x + 2)) + ->Promise.then(x => { + Console.log(x) + Promise.resolve() + }) + ->Promise.finally(() => { + Console.log("Promise finally") + }) + +Console.info("") +Console.info("RegExp") +Console.info("---") +let regex = RegExp.fromString("hello(\\w+)") +let string = "helloworld" +Console.log(regex->RegExp.test(string)) +let result = regex->RegExp.exec(string) +Console.log(result->Option.map(RegExp.Result.input)) +Console.log(result->Option.map(RegExp.Result.index)) +Console.log(result->Option.map(RegExp.Result.matches)) + +Console.info("") +Console.info("Set") +Console.info("---") +let set = Set.make() +set->Set.add(1) +set->Set.add(2) +let _ = set->Set.delete(2) +Console.log(set) + +Console.info("") +Console.info("String") +Console.info("---") +let regexp = RegExp.fromString("(hello )(world)") +Console.log( + " Hello world " + ->String.toLowerCase + ->String.trim + ->String.unsafeReplaceRegExpBy2(regexp, ( + ~match as _, + ~group1, + ~group2, + ~offset as _, + ~input as _, + ) => { + group1 ++ group2->String.toUpperCase + }), +) + +Console.info("") +Console.info("Symbol") +Console.info("---") +let x = Symbol.getFor("Foo") +Console.log(x) +let array: array = String.getSymbolUnsafe("foo", Symbol.iterator)()->Iterator.toArray +Console.log(array) + +Console.info("") +Console.info("Global namespace") +Console.info("---") + +Console.log(typeof(1)) + +let timeout = setTimeout(() => { + Console.log("Hello!") +}, 100) + +clearTimeout(timeout) + +if globalThis["hello"] !== undefined { + Console.log(globalThis["hello"]["bar"]) + Console.log("hello") +} + +let z = Float.mod(1.2, 1.4) + +let intFromBigInt = BigInt.fromString("10000000000")->BigInt.toInt + +module Bugfix = { + @obj external foo: (~bar: string=?, unit) => _ = "" + Console.log(foo(~bar="1", ())) +} + +Console.log(Int.fromString("1231231")) +Console.log(Int.fromString("12.22")) +Console.log(Int.fromString("99999999999999999")) +Console.log(Int.fromString("99999999999999999")) +Console.log(Int.fromString(~radix=2, "010101")) diff --git a/tests/tests/src/core/Core_TestSuite.mjs b/tests/tests/src/core/Core_TestSuite.mjs new file mode 100644 index 0000000000..00c9cb7d58 --- /dev/null +++ b/tests/tests/src/core/Core_TestSuite.mjs @@ -0,0 +1,121 @@ +// Generated by ReScript, PLEASE EDIT WITH CARE + +import * as IntTests from "./IntTests.mjs"; +import * as DictTests from "./DictTests.mjs"; +import * as JsonTests from "./JsonTests.mjs"; +import * as TestTests from "./TestTests.mjs"; +import * as ArrayTests from "./ArrayTests.mjs"; +import * as ErrorTests from "./ErrorTests.mjs"; +import * as FloatTests from "./FloatTests.mjs"; +import * as ObjectTests from "./ObjectTests.mjs"; +import * as PromiseTest from "./PromiseTest.mjs"; +import * as ResultTests from "./ResultTests.mjs"; +import * as IteratorTests from "./IteratorTests.mjs"; +import * as NullableTests from "./NullableTests.mjs"; +import * as TypedArrayTests from "./TypedArrayTests.mjs"; + +var bign = TestTests.bign; + +var TestError = PromiseTest.TestError; + +var fail = PromiseTest.fail; + +var equal = PromiseTest.equal; + +var Creation = PromiseTest.Creation; + +var ThenChaining = PromiseTest.ThenChaining; + +var Rejection = PromiseTest.Rejection; + +var Catching = PromiseTest.Catching; + +var Concurrently = PromiseTest.Concurrently; + +var panicTest = ErrorTests.panicTest; + +var $$catch = IntTests.$$catch; + +var nums = ObjectTests.nums; + +var d = ObjectTests.d; + +var x = ObjectTests.x; + +var mkBig = ObjectTests.mkBig; + +var assignOverwritesTarget = ObjectTests.assignOverwritesTarget; + +var runGetTest = ObjectTests.runGetTest; + +var getSymbolTestWhenExists = ObjectTests.getSymbolTestWhenExists; + +var forEachIfOkCallFunction = ResultTests.forEachIfOkCallFunction; + +var forEachIfErrorDoNotCallFunction = ResultTests.forEachIfErrorDoNotCallFunction; + +var num1 = TypedArrayTests.num1; + +var num2 = TypedArrayTests.num2; + +var num3 = TypedArrayTests.num3; + +var assertTrue = TypedArrayTests.assertTrue; + +var assertWillThrow = TypedArrayTests.assertWillThrow; + +var areSame = TypedArrayTests.areSame; + +var o = TypedArrayTests.o; + +var decodeJsonTest = JsonTests.decodeJsonTest; + +var shouldHandleNullableValues = NullableTests.shouldHandleNullableValues; + +var eq = IteratorTests.eq; + +var iterator = IteratorTests.iterator; + +var syncResult = IteratorTests.syncResult; + +var asyncResult = IteratorTests.asyncResult; + +var asyncIterator = IteratorTests.asyncIterator; + +export { + bign , + TestError , + fail , + equal , + Creation , + ThenChaining , + Rejection , + Catching , + Concurrently , + panicTest , + $$catch , + nums , + d , + x , + mkBig , + assignOverwritesTarget , + runGetTest , + getSymbolTestWhenExists , + forEachIfOkCallFunction , + forEachIfErrorDoNotCallFunction , + num1 , + num2 , + num3 , + assertTrue , + assertWillThrow , + areSame , + o , + decodeJsonTest , + shouldHandleNullableValues , + eq , + iterator , + syncResult , + asyncResult , + asyncIterator , +} +/* IntTests Not a pure module */ diff --git a/tests/tests/src/core/Core_TestSuite.res b/tests/tests/src/core/Core_TestSuite.res new file mode 100644 index 0000000000..4b3496ea18 --- /dev/null +++ b/tests/tests/src/core/Core_TestSuite.res @@ -0,0 +1,13 @@ +include TestTests +include PromiseTest +include ErrorTests +include ArrayTests +include IntTests +include ObjectTests +include ResultTests +include TypedArrayTests +include FloatTests +include JsonTests +include NullableTests +include DictTests +include IteratorTests diff --git a/tests/tests/src/core/Core_TestTests.mjs b/tests/tests/src/core/Core_TestTests.mjs new file mode 100644 index 0000000000..f33f478cfc --- /dev/null +++ b/tests/tests/src/core/Core_TestTests.mjs @@ -0,0 +1,190 @@ +// Generated by ReScript, PLEASE EDIT WITH CARE + +import * as Test from "./Test.mjs"; +import * as Caml_obj from "rescript/lib/es6/caml_obj.js"; +import * as PervasivesU from "rescript/lib/es6/pervasivesU.js"; + +var eq = Caml_obj.equal; + +var bign = BigInt(Number.MAX_VALUE); + +var bign$1 = bign + bign; + +Test.run([ + [ + "TestTests.res", + 8, + 20, + 32 + ], + "print null" + ], Test.print(null), eq, "null"); + +Test.run([ + [ + "TestTests.res", + 9, + 20, + 37 + ], + "print undefined" + ], Test.print(undefined), eq, "undefined"); + +Test.run([ + [ + "TestTests.res", + 10, + 20, + 31 + ], + "print NaN" + ], Test.print(Number.NaN), eq, "NaN"); + +Test.run([ + [ + "TestTests.res", + 11, + 20, + 36 + ], + "print infinity" + ], Test.print(PervasivesU.infinity), eq, "Infinity"); + +Test.run([ + [ + "TestTests.res", + 12, + 20, + 29 + ], + "print 0" + ], Test.print(0), eq, "0"); + +Test.run([ + [ + "TestTests.res", + 13, + 20, + 31 + ], + "print int" + ], Test.print(42), eq, "42"); + +Test.run([ + [ + "TestTests.res", + 14, + 20, + 33 + ], + "print float" + ], Test.print(4.2), eq, "4.2"); + +Test.run([ + [ + "TestTests.res", + 15, + 20, + 34 + ], + "print string" + ], Test.print("foo"), eq, "\"foo\""); + +Test.run([ + [ + "TestTests.res", + 16, + 20, + 32 + ], + "print bool" + ], Test.print(true), eq, "true"); + +Test.run([ + [ + "TestTests.res", + 17, + 20, + 34 + ], + "print object" + ], Test.print({ + x: 42 + }), eq, "{ x: 42 }"); + +Test.run([ + [ + "TestTests.res", + 18, + 20, + 33 + ], + "print array" + ], Test.print([ + 1, + 2, + 3 + ]), eq, "[ 1, 2, 3 ]"); + +Test.run([ + [ + "TestTests.res", + 19, + 20, + 34 + ], + "print symbol" + ], Test.print(Symbol("foo")), eq, "Symbol(foo)"); + +Test.run([ + [ + "TestTests.res", + 21, + 13, + 29 + ], + "print function" + ], Test.print(function () { + return 42; + }), eq, "function () {\n return 42;\n }"); + +Test.run([ + [ + "TestTests.res", + 26, + 20, + 40 + ], + "print es6 function" + ], Test.print((() => 42)), eq, "() => 42"); + +Test.run([ + [ + "TestTests.res", + 28, + 13, + 27 + ], + "print bigint" + ], Test.print(bign$1), eq, "359538626972463141629054847463408713596141135051689993197834953606314521560057077521179117265533756343080917907028764928468642653778928365536935093407075033972099821153102564152490980180778657888151737016910267884609166473806445896331617118664246696549595652408289446337476354361838599762500808052368249716736n"); + +Test.run([ + [ + "TestTests.res", + 33, + 20, + 31 + ], + "print set" + ], Test.print(new Set([ + 1, + 2, + 2, + 3 + ])), eq, "Set(3) { 1, 2, 3 }"); + +export { + eq , + bign$1 as bign, +} +/* bign Not a pure module */ diff --git a/tests/tests/src/core/Core_TestTests.res b/tests/tests/src/core/Core_TestTests.res new file mode 100644 index 0000000000..97a35c956c --- /dev/null +++ b/tests/tests/src/core/Core_TestTests.res @@ -0,0 +1,33 @@ +open RescriptCore + +let eq = (a, b) => a == b + +let bign = BigInt.fromFloat(Float.Constants.maxValue) +let bign = BigInt.add(bign, bign) + +Test.run(__POS_OF__("print null"), Test.print(null), eq, "null") +Test.run(__POS_OF__("print undefined"), Test.print(undefined), eq, "undefined") +Test.run(__POS_OF__("print NaN"), Test.print(nan), eq, "NaN") +Test.run(__POS_OF__("print infinity"), Test.print(infinity), eq, "Infinity") +Test.run(__POS_OF__("print 0"), Test.print(0), eq, "0") +Test.run(__POS_OF__("print int"), Test.print(42), eq, "42") +Test.run(__POS_OF__("print float"), Test.print(4.2), eq, "4.2") +Test.run(__POS_OF__("print string"), Test.print("foo"), eq, `"foo"`) +Test.run(__POS_OF__("print bool"), Test.print(true), eq, "true") +Test.run(__POS_OF__("print object"), Test.print({"x": 42}), eq, `{ x: 42 }`) +Test.run(__POS_OF__("print array"), Test.print([1, 2, 3]), eq, "[ 1, 2, 3 ]") +Test.run(__POS_OF__("print symbol"), Test.print(Symbol.make("foo")), eq, "Symbol(foo)") +Test.run( + __POS_OF__("print function"), + Test.print(() => 42), + eq, + "function () {\n return 42;\n }", +) +Test.run(__POS_OF__("print es6 function"), Test.print(%raw("() => 42")), eq, "() => 42") +Test.run( + __POS_OF__("print bigint"), + Test.print(bign), + eq, + "359538626972463141629054847463408713596141135051689993197834953606314521560057077521179117265533756343080917907028764928468642653778928365536935093407075033972099821153102564152490980180778657888151737016910267884609166473806445896331617118664246696549595652408289446337476354361838599762500808052368249716736n", +) +Test.run(__POS_OF__("print set"), Test.print(Set.fromArray([1, 2, 2, 3])), eq, "Set(3) { 1, 2, 3 }") diff --git a/tests/tests/src/core/Core_TypedArrayTests.mjs b/tests/tests/src/core/Core_TypedArrayTests.mjs new file mode 100644 index 0000000000..91adb709af --- /dev/null +++ b/tests/tests/src/core/Core_TypedArrayTests.mjs @@ -0,0 +1,105 @@ +// Generated by ReScript, PLEASE EDIT WITH CARE + +import * as Test from "./Test.mjs"; +import * as Caml_obj from "rescript/lib/es6/caml_obj.js"; +import * as Core__Option from "../src/Core__Option.mjs"; + +var eq = Caml_obj.equal; + +Test.run([ + [ + "TypedArrayTests.res", + 7, + 20, + 44 + ], + "bytes per element is 8" + ], BigInt64Array.BYTES_PER_ELEMENT, eq, 8); + +var num1 = BigInt("123456789"); + +var num2 = BigInt("987654321"); + +var num3 = BigInt("555555555"); + +function assertTrue(message, predicate) { + try { + if (predicate()) { + return ; + } + throw new Error(message); + } + catch (exn){ + throw new Error(message); + } +} + +function assertWillThrow(message, f) { + var didThrow = false; + try { + f(); + } + catch (exn){ + didThrow = true; + } + if (didThrow !== false) { + return ; + } + throw new Error(message); +} + +function areSame(x, y) { + return x.toString() === y.toString(); +} + +assertTrue("fromArray", (function () { + return areSame(Core__Option.getExn(new BigInt64Array([ + num1, + num2 + ])[1], undefined), num2); + })); + +assertTrue("fromBuffer", (function () { + var x = new BigInt64Array(new ArrayBuffer(16)); + x[1] = num2; + return areSame(Core__Option.getExn(x[1], undefined), num2); + })); + +assertWillThrow("fromBuffer when too short can throw when used", (function () { + var x = new BigInt64Array(new ArrayBuffer(1)); + x[0] = num1; + areSame(Core__Option.getExn(x[0], undefined), num1); + })); + +assertTrue("fromBufferWithRange", (function () { + var x = new BigInt64Array(new ArrayBuffer(16), 0, 1); + x[0] = num1; + return areSame(Core__Option.getExn(x[0], undefined), num1); + })); + +assertWillThrow("fromBufferWithRange is unsafe, out of range", (function () { + var x = new BigInt64Array(new ArrayBuffer(16), 13, 1); + x[0] = num1; + areSame(Core__Option.getExn(x[0], undefined), num1); + })); + +assertTrue("fromLength is NOT in bytes", (function () { + var x = new BigInt64Array(1); + return x.byteLength === 8; + })); + +function o(prim0, prim1) { + return BigInt64Array.from(prim0, prim1); +} + +export { + eq , + num1 , + num2 , + num3 , + assertTrue , + assertWillThrow , + areSame , + o , +} +/* Not a pure module */ diff --git a/tests/tests/src/core/Core_TypedArrayTests.res b/tests/tests/src/core/Core_TypedArrayTests.res new file mode 100644 index 0000000000..746a18c207 --- /dev/null +++ b/tests/tests/src/core/Core_TypedArrayTests.res @@ -0,0 +1,76 @@ +open RescriptCore + +let eq = (a, b) => a == b + +// ===== BigInt64Array Tests ===== + +Test.run(__POS_OF__("bytes per element is 8"), BigInt64Array.Constants.bytesPerElement, eq, 8) + +let num1 = BigInt.fromString("123456789") +let num2 = BigInt.fromString("987654321") +let num3 = BigInt.fromString("555555555") + +let assertTrue = (message, predicate) => { + try { + if !predicate() { + message->Error.make->Error.raise + } + } catch { + | _ => message->Error.make->Error.raise + } +} + +let assertWillThrow = (message, f) => { + let didThrow = ref(false) + try { + f() + } catch { + | _ => didThrow := true + } + if didThrow.contents == false { + message->Error.make->Error.raise + } +} + +let areSame = (x: bigint, y: bigint) => BigInt.toString(x) == BigInt.toString(y) + +// What's going on here? +// assertTrue("big ints if different then not equal", () => num1 != num2) +// assertTrue("big ints if same then equal", () => num1 == num1) + +assertTrue("fromArray", () => + [num1, num2]->BigInt64Array.fromArray->TypedArray.get(1)->Option.getExn->areSame(num2) +) + +assertTrue("fromBuffer", () => { + let x = ArrayBuffer.make(16)->BigInt64Array.fromBuffer + x->TypedArray.set(1, num2) + x->TypedArray.get(1)->Option.getExn->areSame(num2) +}) + +assertWillThrow("fromBuffer when too short can throw when used", () => { + let x = ArrayBuffer.make(1)->BigInt64Array.fromBuffer + x->TypedArray.set(0, num1) + x->TypedArray.get(0)->Option.getExn->areSame(num1)->ignore +}) + +assertTrue("fromBufferWithRange", () => { + let x = ArrayBuffer.make(16)->BigInt64Array.fromBufferWithRange(~byteOffset=0, ~length=1) + x->TypedArray.set(0, num1) + x->TypedArray.get(0)->Option.getExn->areSame(num1) +}) + +// assertWillThrow("testing", () => {"a"->Error.make->Error.raise}) +// assertWillThrow("testing", () => {Console.log("f")}) + +assertWillThrow("fromBufferWithRange is unsafe, out of range", () => { + let x = ArrayBuffer.make(16)->BigInt64Array.fromBufferWithRange(~byteOffset=13, ~length=1) + x->TypedArray.set(0, num1) + x->TypedArray.get(0)->Option.getExn->areSame(num1)->ignore +}) + +assertTrue("fromLength is NOT in bytes", () => { + let x = BigInt64Array.fromLength(1) + TypedArray.byteLength(x) == 8 +}) +let o = BigInt64Array.fromArrayLikeOrIterableWithMap diff --git a/tests/tests/src/core/Test.mjs b/tests/tests/src/core/Test.mjs new file mode 100644 index 0000000000..1824f710e2 --- /dev/null +++ b/tests/tests/src/core/Test.mjs @@ -0,0 +1,53 @@ +// Generated by ReScript, PLEASE EDIT WITH CARE + +import * as Fs from "fs"; +import * as Path from "path"; +import * as Util from "util"; +import * as Core__Option from "../src/Core__Option.mjs"; +import * as CodeFrame from "@babel/code-frame"; + +var dirname = (new URL('.', import.meta.url).pathname); + +function print(value) { + var match = typeof value; + if (match === "object" || match === "bigint") { + return Util.inspect(value); + } else if (match === "string") { + return Core__Option.getExn(JSON.stringify(value), undefined); + } else { + return String(value); + } +} + +function run(loc, left, comparator, right) { + if (comparator(left, right)) { + return ; + } + var match = loc[0]; + var line = match[1]; + var file = match[0]; + var fileContent = Fs.readFileSync(Path.join(dirname, file), { + encoding: "utf-8" + }); + var left$1 = print(left); + var right$1 = print(right); + var codeFrame = CodeFrame.codeFrameColumns(fileContent, { + start: { + line: line + } + }, { + highlightCode: true + }); + var errorMessage = "\n \u001b[31mTest Failure!\n \u001b[36m" + file + "\u001b[0m:\u001b[2m" + String(line) + "\n" + codeFrame + "\n \u001b[39mLeft: \u001b[31m" + left$1 + "\n \u001b[39mRight: \u001b[31m" + right$1 + "\u001b[0m\n"; + console.log(errorMessage); + var obj = {}; + Error.captureStackTrace(obj); + console.log(obj.stack.replace(/\n /g, "\n ").replace(/^Error\n/, "").replace(/^.+\n/, "").replace(/\n at .+\(node:internal.+\n?/g, "")); +} + +export { + dirname , + print , + run , +} +/* dirname Not a pure module */ diff --git a/tests/tests/src/core/Test.res b/tests/tests/src/core/Test.res new file mode 100644 index 0000000000..7c6f4d8ae3 --- /dev/null +++ b/tests/tests/src/core/Test.res @@ -0,0 +1,51 @@ +// Test "framework" + + +@scope("process") @val external exit: int => unit = "exit" +@scope("Error") @val external captureStackTrace: {..} => unit = "captureStackTrace" +@module("@babel/code-frame") @val +external codeFrameColumns: (string, {..}, {..}) => string = "codeFrameColumns" +@module("fs") @val external readFileSync: (string, {..}) => string = "readFileSync" +@module("path") @val external join: (string, string) => string = "join" + +let dirname = %raw("new URL('.', import.meta.url).pathname") + +@val @module("util") external inspect: _ => string = "inspect" +let print = value => + switch Type.typeof(value) { + | #string => JSON.stringifyAny(value)->Option.getExn // uses " instead of ' + | #object | #bigint => inspect(value) + | _ => String.make(value) + } + +let run = (loc, left, comparator, right) => { + if !comparator(left, right) { + let ((file, line, _, _), _) = loc + let fileContent = readFileSync(join(dirname, file), {"encoding": "utf-8"}) + let left = print(left) + let right = print(right) + let codeFrame = codeFrameColumns( + fileContent, + {"start": {"line": line}}, + {"highlightCode": true}, + ) + let errorMessage = ` + \u001b[31mTest Failure! + \u001b[36m${file}\u001b[0m:\u001b[2m${string_of_int(line)} +${codeFrame} + \u001b[39mLeft: \u001b[31m${left} + \u001b[39mRight: \u001b[31m${right}\u001b[0m +` + Console.log(errorMessage) + // API: https://nodejs.org/api/errors.html#errors_error_capturestacktrace_targetobject_constructoropt + let obj = Object.make() + captureStackTrace(obj) + // clean up stack trace! Stack format: https://nodejs.org/api/errors.html#errors_error_stack + obj["stack"] + ->String.replaceRegExp(/\n /g, "\n ") // indent 2 spaces instead of 4, to align with code frame + ->String.replaceRegExp(/^Error\n/, "") // first line is just the word "Error" + ->String.replaceRegExp(/^.+\n/, "") // second line (now first) is this Test module's own stack frame + ->String.replaceRegExp(/\n at .+\(node:internal.+\n?/g, "") // remove internal lines like " at ModuleJob.run (node:internal/modules/esm/module_job:193:25)" + ->Console.log + } +} diff --git a/tests/tests/src/core/intl/Core_IntlTests.mjs b/tests/tests/src/core/intl/Core_IntlTests.mjs new file mode 100644 index 0000000000..6fcf587553 --- /dev/null +++ b/tests/tests/src/core/intl/Core_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/tests/tests/src/core/intl/Core_IntlTests.res b/tests/tests/src/core/intl/Core_IntlTests.res new file mode 100644 index 0000000000..d5fa1c6d47 --- /dev/null +++ b/tests/tests/src/core/intl/Core_IntlTests.res @@ -0,0 +1,53 @@ +include Intl__CollatorTest +include Intl__DateTimeFormatTest +include Intl__ListFormatTest +include Intl__LocaleTest +include Intl__NumberFormatTest +include Intl__PluralRulesTest +include Intl__RelativeTimeFormatTest +include Intl__SegmenterTest + +open RescriptCore + +Console.log("---") +Console.log("Intl") + +Intl.getCanonicalLocalesExn("EN-US")->Console.log +Intl.getCanonicalLocalesManyExn(["EN-US", "Fr"])->Console.log + +try { + Intl.getCanonicalLocalesExn("bloop")->Console.log +} catch { +| Exn.Error(e) => Console.error(e) +} + +try { + Intl.supportedValuesOfExn("calendar")->Console.log + Intl.supportedValuesOfExn("collation")->Console.log + Intl.supportedValuesOfExn("currency")->Console.log + Intl.supportedValuesOfExn("numberingSystem")->Console.log + Intl.supportedValuesOfExn("timeZone")->Console.log + Intl.supportedValuesOfExn("unit")->Console.log +} catch { +| Exn.Error(e) => Console.error(e) +} + +try { + Intl.supportedValuesOfExn("someInvalidKey")->ignore + + Console.error("Shouldn't have been hit") +} catch { +| Exn.Error(e) => + switch Error.message(e)->Option.map(String.toLowerCase) { + | Some("invalid key : someinvalidkey") => Console.log("Caught expected error") + | message => { + Console.warn(`Unexpected error message: "${message->Option.getUnsafe}"`) + Error.raise(e) + } + } +| e => + switch Error.fromException(e) { + | Some(e) => Error.raise(e) + | None => Console.error("Unexpected error") + } +} diff --git a/tests/tests/src/core/intl/Core_Intl_CollatorTest.mjs b/tests/tests/src/core/intl/Core_Intl_CollatorTest.mjs new file mode 100644 index 0000000000..bbff943d27 --- /dev/null +++ b/tests/tests/src/core/intl/Core_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/tests/tests/src/core/intl/Core_Intl_CollatorTest.res b/tests/tests/src/core/intl/Core_Intl_CollatorTest.res new file mode 100644 index 0000000000..abba374f51 --- /dev/null +++ b/tests/tests/src/core/intl/Core_Intl_CollatorTest.res @@ -0,0 +1,18 @@ +open RescriptCore + +Console.log("---") +Console.log("Intl.Collator") + +let _collator = Intl.Collator.make() +let _collator = Intl.Collator.make(~locales=["en-US"]) +let _collator = Intl.Collator.make(~locales=["en-US", "en-GB"]) +let collator = Intl.Collator.make( + ~locales=["en-US"], + ~options={caseFirst: #upper, sensitivity: #base, ignorePunctuation: true, numeric: true}, +) +Intl.Collator.supportedLocalesOf(["en-US", "en-GB"])->ignore +Intl.Collator.supportedLocalesOf(["en-US", "en-GB"], ~options={localeMatcher: #lookup})->ignore + +collator->Intl.Collator.resolvedOptions->Console.log +collator->Intl.Collator.compare("hi", "hï")->Console.log +Intl.Collator.supportedLocalesOf(["hi"])->Console.log diff --git a/tests/tests/src/core/intl/Core_Intl_DateTimeFormatTest.mjs b/tests/tests/src/core/intl/Core_Intl_DateTimeFormatTest.mjs new file mode 100644 index 0000000000..140ae17c45 --- /dev/null +++ b/tests/tests/src/core/intl/Core_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/tests/tests/src/core/intl/Core_Intl_DateTimeFormatTest.res b/tests/tests/src/core/intl/Core_Intl_DateTimeFormatTest.res new file mode 100644 index 0000000000..20e77d581e --- /dev/null +++ b/tests/tests/src/core/intl/Core_Intl_DateTimeFormatTest.res @@ -0,0 +1,58 @@ +open RescriptCore + +Console.log("---") +Console.log("Intl.DateTimeFormat") + +Intl.DateTimeFormat.supportedLocalesOf(["en-US", "en-GB"])->ignore +Intl.DateTimeFormat.supportedLocalesOf( + ["en-US", "en-GB"], + ~options={localeMatcher: #lookup}, +)->ignore + +let formatter = Intl.DateTimeFormat.make(~options={dateStyle: #full, timeStyle: #full}) + +Console.log(formatter->Intl.DateTimeFormat.format(Date.fromTime(Date.now()))) + +Console.log( + formatter->Intl.DateTimeFormat.formatRange( + ~startDate=Date.makeWithYMD(~year=2023, ~date=1, ~month=1), + ~endDate=Date.makeWithYMD(~year=2023, ~date=31, ~month=12), + ), +) + +let options: Intl.DateTimeFormat.options = { + hour12: false, + hourCycle: #h24, + timeZone: "UTC", + 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, +} +let formatter = Intl.DateTimeFormat.make(~options) + +Console.log(formatter->Intl.DateTimeFormat.format(Date.fromTime(Date.now()))) + +let formatter = Intl.DateTimeFormat.make(~options={...options, timeZoneName: #long}) +Console.log(formatter->Intl.DateTimeFormat.format(Date.fromTime(Date.now()))) + +let formatter = Intl.DateTimeFormat.make(~options={...options, timeZoneName: #longOffset}) +Console.log(formatter->Intl.DateTimeFormat.format(Date.fromTime(Date.now()))) + +let formatter = Intl.DateTimeFormat.make(~options={...options, timeZoneName: #short}) +Console.log(formatter->Intl.DateTimeFormat.format(Date.fromTime(Date.now()))) + +let formatter = Intl.DateTimeFormat.make(~options={...options, timeZoneName: #shortGeneric}) +Console.log(formatter->Intl.DateTimeFormat.format(Date.fromTime(Date.now()))) + +let formatter = Intl.DateTimeFormat.make(~options={...options, timeZoneName: #shortOffset}) +Console.log(formatter->Intl.DateTimeFormat.format(Date.fromTime(Date.now()))) + +let resolvedOptions = Intl.DateTimeFormat.make()->Intl.DateTimeFormat.resolvedOptions +let {Intl.DateTimeFormat.timeZone: timeZone, _} = resolvedOptions diff --git a/tests/tests/src/core/intl/Core_Intl_ListFormatTest.mjs b/tests/tests/src/core/intl/Core_Intl_ListFormatTest.mjs new file mode 100644 index 0000000000..32cc1d4849 --- /dev/null +++ b/tests/tests/src/core/intl/Core_Intl_ListFormatTest.mjs @@ -0,0 +1,58 @@ +// Generated by ReScript, PLEASE EDIT WITH CARE + + +console.log("---"); + +console.log("Intl.ListFormat"); + +new Intl.ListFormat(); + +new Intl.ListFormat([ + "en-US", + "en-GB" + ]); + +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/tests/tests/src/core/intl/Core_Intl_ListFormatTest.res b/tests/tests/src/core/intl/Core_Intl_ListFormatTest.res new file mode 100644 index 0000000000..ec5fae7d84 --- /dev/null +++ b/tests/tests/src/core/intl/Core_Intl_ListFormatTest.res @@ -0,0 +1,19 @@ +open RescriptCore + +Console.log("---") +Console.log("Intl.ListFormat") + +let _formatter = Intl.ListFormat.make() +let _formatter = Intl.ListFormat.make(~locales=["en-US", "en-GB"]) +let _formatter = Intl.ListFormat.make( + ~locales=["en-US", "en-GB"], + ~options={style: #long, \"type": #conjunction}, +) +Intl.ListFormat.supportedLocalesOf(["en-US", "en-GB"])->ignore +Intl.ListFormat.supportedLocalesOf(["en-US", "en-GB"], ~options={localeMatcher: #lookup})->ignore + +let formatter = Intl.ListFormat.make(~options={style: #long, \"type": #conjunction}) + +formatter->Intl.ListFormat.resolvedOptions->Console.log +formatter->Intl.ListFormat.format(["one", "two", "three"])->Console.log +formatter->Intl.ListFormat.formatToParts(["one", "two", "three"])->Console.log diff --git a/tests/tests/src/core/intl/Core_Intl_LocaleTest.mjs b/tests/tests/src/core/intl/Core_Intl_LocaleTest.mjs new file mode 100644 index 0000000000..a8349a845c --- /dev/null +++ b/tests/tests/src/core/intl/Core_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/tests/tests/src/core/intl/Core_Intl_LocaleTest.res b/tests/tests/src/core/intl/Core_Intl_LocaleTest.res new file mode 100644 index 0000000000..b91e5001a9 --- /dev/null +++ b/tests/tests/src/core/intl/Core_Intl_LocaleTest.res @@ -0,0 +1,29 @@ +open RescriptCore + +Console.log("---") +Console.log("Intl.Locale") + +let _locale = Intl.Locale.make("en-US") +let locale = Intl.Locale.make( + "en-US", + ~options={ + calendar: #hebrew, + collation: #compat, + hourCycle: #h24, + caseFirst: #upper, + numeric: true, + }, +) + +locale->Intl.Locale.baseName->Console.log +locale->Intl.Locale.calendar->Console.log +locale->Intl.Locale.caseFirst->Console.log +locale->Intl.Locale.collation->Console.log +locale->Intl.Locale.hourCycle->Console.log +locale->Intl.Locale.language->Console.log +locale->Intl.Locale.numberingSystem->Console.log +locale->Intl.Locale.numeric->Console.log +locale->Intl.Locale.region->Console.log +locale->Intl.Locale.script->Console.log +locale->Intl.Locale.maximize->Console.log +locale->Intl.Locale.minimize->Console.log diff --git a/tests/tests/src/core/intl/Core_Intl_NumberFormatTest.mjs b/tests/tests/src/core/intl/Core_Intl_NumberFormatTest.mjs new file mode 100644 index 0000000000..dfde813858 --- /dev/null +++ b/tests/tests/src/core/intl/Core_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/tests/tests/src/core/intl/Core_Intl_NumberFormatTest.res b/tests/tests/src/core/intl/Core_Intl_NumberFormatTest.res new file mode 100644 index 0000000000..b6c1595f80 --- /dev/null +++ b/tests/tests/src/core/intl/Core_Intl_NumberFormatTest.res @@ -0,0 +1,45 @@ +open RescriptCore + +Console.log("---") +Console.log("Intl.NumberFormat") + +let currencyFormatter = Intl.NumberFormat.make( + ~locales=["fr-FR"], + ~options={currency: "EUR", style: #currency}, +) + +Console.log(Intl.NumberFormat.supportedLocalesOf(["fr-FR", "en-US"])) +Console.log(currencyFormatter->Intl.NumberFormat.format(123.23)) + +let roundingFormatter = Intl.NumberFormat.make( + ~options={ + roundingIncrement: #500, + minimumFractionDigits: #2, + maximumFractionDigits: #2, + }, +) + +let groupingFormatter1 = Intl.NumberFormat.make( + ~options={ + useGrouping: Intl.NumberFormat.Grouping.fromBool(true), + }, +) +let groupingFormatter2 = Intl.NumberFormat.make( + ~options={ + useGrouping: Intl.NumberFormat.Grouping.fromString(#auto), + }, +) + +let sigFormatter = Intl.NumberFormat.make( + ~options={ + minimumIntegerDigits: #1, + minimumFractionDigits: #1, + maximumFractionDigits: #1, + minimumSignificantDigits: #1, + maximumSignificantDigits: #1, + }, +) + +let options = sigFormatter->Intl.NumberFormat.resolvedOptions +Console.log(options) +options.useGrouping->Core__Intl__NumberFormat.Grouping.parseJsValue->Console.log diff --git a/tests/tests/src/core/intl/Core_Intl_PluralRulesTest.mjs b/tests/tests/src/core/intl/Core_Intl_PluralRulesTest.mjs new file mode 100644 index 0000000000..3ad44723de --- /dev/null +++ b/tests/tests/src/core/intl/Core_Intl_PluralRulesTest.mjs @@ -0,0 +1,37 @@ +// Generated by ReScript, PLEASE EDIT WITH CARE + + +console.log("---"); + +console.log("Intl.PluralRules"); + +new Intl.PluralRules(); + +new Intl.PluralRules([ + "en-US", + "en-GB" + ]); + +var _formatter = new Intl.PluralRules(undefined, { + 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/tests/tests/src/core/intl/Core_Intl_PluralRulesTest.res b/tests/tests/src/core/intl/Core_Intl_PluralRulesTest.res new file mode 100644 index 0000000000..3071041472 --- /dev/null +++ b/tests/tests/src/core/intl/Core_Intl_PluralRulesTest.res @@ -0,0 +1,35 @@ +open RescriptCore + +Console.log("---") +Console.log("Intl.PluralRules") + +let _formatter = Intl.PluralRules.make() +let _formatter = Intl.PluralRules.make(~locales=["en-US", "en-GB"]) +let _formatter = Intl.PluralRules.make( + ~options={ + \"type": #ordinal, + maximumSignificantDigits: #5, + minimumSignificantDigits: #3, + }, +) +let formatter = Intl.PluralRules.make( + ~locales=["en-US"], + ~options={ + \"type": #ordinal, + maximumSignificantDigits: #5, + minimumSignificantDigits: #3, + }, +) + +formatter->Intl.PluralRules.resolvedOptions->Console.log + +formatter->Intl.PluralRules.select(2.0)->Console.log +formatter->Intl.PluralRules.selectInt(2)->Console.log + +// doesn't appear to work in node v16 +// formatter->Intl.PluralRules.selectBigInt(BigInt.fromInt(2))->Console.log +// formatter +// ->Intl.PluralRules.selectRangeBigInt(~start=BigInt.fromInt(1), ~end=BigInt.fromInt(3)) +// ->Console.log +// formatter->Intl.PluralRules.selectRange(~start=1., ~end=3.)->Console.log +// formatter->Intl.PluralRules.selectRangeInt(~start=1, ~end=3)->Console.log diff --git a/tests/tests/src/core/intl/Core_Intl_RelativeTimeFormatTest.mjs b/tests/tests/src/core/intl/Core_Intl_RelativeTimeFormatTest.mjs new file mode 100644 index 0000000000..1bfd262739 --- /dev/null +++ b/tests/tests/src/core/intl/Core_Intl_RelativeTimeFormatTest.mjs @@ -0,0 +1,47 @@ +// 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", + "en-GB" + ]); + +var _formatter = new Intl.RelativeTimeFormat(undefined, { + 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/tests/tests/src/core/intl/Core_Intl_RelativeTimeFormatTest.res b/tests/tests/src/core/intl/Core_Intl_RelativeTimeFormatTest.res new file mode 100644 index 0000000000..6f53ad7e7f --- /dev/null +++ b/tests/tests/src/core/intl/Core_Intl_RelativeTimeFormatTest.res @@ -0,0 +1,31 @@ +open RescriptCore + +Console.log("---") +Console.log("Intl.RelativeTimeFormat") + +Intl.RelativeTimeFormat.supportedLocalesOf(["en-US", "en-GB"])->ignore +Intl.RelativeTimeFormat.supportedLocalesOf( + ["en-US", "en-GB"], + ~options={localeMatcher: #lookup}, +)->ignore + +let _formatter = Intl.RelativeTimeFormat.make() +let _formatter = Intl.RelativeTimeFormat.make(~locales=["en-US", "en-GB"]) +let _formatter = Intl.RelativeTimeFormat.make( + ~options={ + numeric: #always, + style: #narrow, + }, +) +let formatter = Intl.RelativeTimeFormat.make( + ~locales=["en-US"], + ~options={ + numeric: #always, + style: #narrow, + }, +) + +formatter->Intl.RelativeTimeFormat.resolvedOptions->Console.log + +formatter->Intl.RelativeTimeFormat.format(3, #hour)->Console.log +formatter->Intl.RelativeTimeFormat.formatToParts(3, #hour)->Console.log diff --git a/tests/tests/src/core/intl/Core_Intl_SegmenterTest.mjs b/tests/tests/src/core/intl/Core_Intl_SegmenterTest.mjs new file mode 100644 index 0000000000..841c4ef621 --- /dev/null +++ b/tests/tests/src/core/intl/Core_Intl_SegmenterTest.mjs @@ -0,0 +1,50 @@ +// 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", + "en-GB" + ]); + +var _formatter = new Intl.Segmenter(undefined, { + 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 */ diff --git a/tests/tests/src/core/intl/Core_Intl_SegmenterTest.res b/tests/tests/src/core/intl/Core_Intl_SegmenterTest.res new file mode 100644 index 0000000000..ed32293926 --- /dev/null +++ b/tests/tests/src/core/intl/Core_Intl_SegmenterTest.res @@ -0,0 +1,29 @@ +open RescriptCore + +Console.log("---") +Console.log("Intl.Segmenter") + +Intl.Segmenter.supportedLocalesOf(["en-US", "en-GB"])->ignore +Intl.Segmenter.supportedLocalesOf(["en-US", "en-GB"], ~options={localeMatcher: #lookup})->ignore + +let _formatter = Intl.Segmenter.make() +let _formatter = Intl.Segmenter.make(~locales=["en-US", "en-GB"]) +let _formatter = Intl.Segmenter.make( + ~options={ + granularity: #word, + }, +) +let formatter = Intl.Segmenter.make( + ~locales=["en-US"], + ~options={ + granularity: #word, + }, +) + +formatter->Intl.Segmenter.resolvedOptions->Console.log +let segments = formatter->Intl.Segmenter.segment("This is a sentence with several words") + +Console.log(segments) + +Intl.Segments.containing(segments)->Console.log +Intl.Segments.containingWithIndex(segments, 1)->Console.log From 2a4370678c1a0a526a05e5afb1d1419c2d915d65 Mon Sep 17 00:00:00 2001 From: Christoph Knittel Date: Mon, 21 Oct 2024 16:32:26 +0200 Subject: [PATCH 2/7] No open RescriptCore --- tests/tests/src/core/Core_ArrayTests.res | 2 -- tests/tests/src/core/Core_DictTests.res | 2 -- tests/tests/src/core/Core_ErrorTests.res | 2 -- tests/tests/src/core/Core_FloatTests.res | 2 -- tests/tests/src/core/Core_ImportTests.res | 2 -- tests/tests/src/core/Core_IntTests.res | 2 -- tests/tests/src/core/Core_IteratorTests.res | 2 -- tests/tests/src/core/Core_JsonTests.res | 2 -- tests/tests/src/core/Core_NullableTests.res | 2 -- tests/tests/src/core/Core_ObjectTests.res | 2 -- tests/tests/src/core/Core_PromiseTest.res | 2 -- tests/tests/src/core/Core_ResultTests.res | 2 -- tests/tests/src/core/Core_StringTests.res | 2 -- tests/tests/src/core/Core_TempTests.res | 2 -- tests/tests/src/core/Core_TestTests.res | 2 -- tests/tests/src/core/Core_TypedArrayTests.res | 2 -- tests/tests/src/core/Test.res | 1 - tests/tests/src/core/intl/Core_IntlTests.res | 2 -- tests/tests/src/core/intl/Core_Intl_CollatorTest.res | 2 -- tests/tests/src/core/intl/Core_Intl_DateTimeFormatTest.res | 2 -- tests/tests/src/core/intl/Core_Intl_ListFormatTest.res | 2 -- tests/tests/src/core/intl/Core_Intl_LocaleTest.res | 2 -- tests/tests/src/core/intl/Core_Intl_NumberFormatTest.res | 2 -- tests/tests/src/core/intl/Core_Intl_PluralRulesTest.res | 2 -- tests/tests/src/core/intl/Core_Intl_RelativeTimeFormatTest.res | 2 -- tests/tests/src/core/intl/Core_Intl_SegmenterTest.res | 2 -- 26 files changed, 51 deletions(-) diff --git a/tests/tests/src/core/Core_ArrayTests.res b/tests/tests/src/core/Core_ArrayTests.res index b6fdec2bd1..01fdf39c34 100644 --- a/tests/tests/src/core/Core_ArrayTests.res +++ b/tests/tests/src/core/Core_ArrayTests.res @@ -1,5 +1,3 @@ -open RescriptCore - let eq = (a, b) => a == b Test.run(__POS_OF__("make"), Array.make(~length=6, 7), eq, [7, 7, 7, 7, 7, 7]) diff --git a/tests/tests/src/core/Core_DictTests.res b/tests/tests/src/core/Core_DictTests.res index 1a66d50424..968dbab9ad 100644 --- a/tests/tests/src/core/Core_DictTests.res +++ b/tests/tests/src/core/Core_DictTests.res @@ -1,5 +1,3 @@ -open RescriptCore - let eq = (a, b) => a == b Test.run(__POS_OF__("make"), Dict.make(), eq, %raw(`{}`)) diff --git a/tests/tests/src/core/Core_ErrorTests.res b/tests/tests/src/core/Core_ErrorTests.res index 07dcc078bb..3113346495 100644 --- a/tests/tests/src/core/Core_ErrorTests.res +++ b/tests/tests/src/core/Core_ErrorTests.res @@ -1,5 +1,3 @@ -open RescriptCore - let panicTest = () => { let caught = try panic("uh oh") catch { | Exn.Error(err) => Error.message(err) diff --git a/tests/tests/src/core/Core_FloatTests.res b/tests/tests/src/core/Core_FloatTests.res index 8ca2d2011a..1632c2dffa 100644 --- a/tests/tests/src/core/Core_FloatTests.res +++ b/tests/tests/src/core/Core_FloatTests.res @@ -1,5 +1,3 @@ -open RescriptCore - let eq = (a, b) => a == b Test.run(__POS_OF__("clamp"), Float.clamp(4.2), eq, 4.2) diff --git a/tests/tests/src/core/Core_ImportTests.res b/tests/tests/src/core/Core_ImportTests.res index 961e3ff1dd..baf6c32360 100644 --- a/tests/tests/src/core/Core_ImportTests.res +++ b/tests/tests/src/core/Core_ImportTests.res @@ -1,5 +1,3 @@ -open RescriptCore - let main = async () => { let eq = await import(IntTests.eq) Test.run(__POS_OF__("dynamic import - Int tests - eq"), 1, eq, 1) diff --git a/tests/tests/src/core/Core_IntTests.res b/tests/tests/src/core/Core_IntTests.res index ebbb7e8c5c..b9d88125a3 100644 --- a/tests/tests/src/core/Core_IntTests.res +++ b/tests/tests/src/core/Core_IntTests.res @@ -1,5 +1,3 @@ -open RescriptCore - let eq = (a, b) => a == b let catch = f => diff --git a/tests/tests/src/core/Core_IteratorTests.res b/tests/tests/src/core/Core_IteratorTests.res index 902df8ae3f..5c5d302297 100644 --- a/tests/tests/src/core/Core_IteratorTests.res +++ b/tests/tests/src/core/Core_IteratorTests.res @@ -1,5 +1,3 @@ -open RescriptCore - let eq = (a, b) => a == b let iterator: Iterator.t = %raw(` diff --git a/tests/tests/src/core/Core_JsonTests.res b/tests/tests/src/core/Core_JsonTests.res index 03b907209a..09d6d85661 100644 --- a/tests/tests/src/core/Core_JsonTests.res +++ b/tests/tests/src/core/Core_JsonTests.res @@ -1,5 +1,3 @@ -open RescriptCore - let decodeJsonTest = () => { let json: JSON.t = %raw(`{"someProp":{"otherProp": null, "thirdProp": [true, false]}}`) diff --git a/tests/tests/src/core/Core_NullableTests.res b/tests/tests/src/core/Core_NullableTests.res index ca97174d9a..3fefa8dfff 100644 --- a/tests/tests/src/core/Core_NullableTests.res +++ b/tests/tests/src/core/Core_NullableTests.res @@ -1,5 +1,3 @@ -open RescriptCore - let shouldHandleNullableValues = () => { let tNull: Nullable.t = %raw("null") let tUndefined: Nullable.t = %raw("undefined") diff --git a/tests/tests/src/core/Core_ObjectTests.res b/tests/tests/src/core/Core_ObjectTests.res index 5b0cd7ac9f..ee139d805e 100644 --- a/tests/tests/src/core/Core_ObjectTests.res +++ b/tests/tests/src/core/Core_ObjectTests.res @@ -1,5 +1,3 @@ -open RescriptCore - let eq = (a, b) => a == b // ===== is ===== diff --git a/tests/tests/src/core/Core_PromiseTest.res b/tests/tests/src/core/Core_PromiseTest.res index 35197feae3..6a5ad72b8c 100644 --- a/tests/tests/src/core/Core_PromiseTest.res +++ b/tests/tests/src/core/Core_PromiseTest.res @@ -1,5 +1,3 @@ -open RescriptCore - exception TestError(string) let fail = msg => { diff --git a/tests/tests/src/core/Core_ResultTests.res b/tests/tests/src/core/Core_ResultTests.res index 040028c6ba..54395a5a3b 100644 --- a/tests/tests/src/core/Core_ResultTests.res +++ b/tests/tests/src/core/Core_ResultTests.res @@ -1,5 +1,3 @@ -open RescriptCore - let eq = (a, b) => a == b // ======= diff --git a/tests/tests/src/core/Core_StringTests.res b/tests/tests/src/core/Core_StringTests.res index a476d408f8..ad1010a310 100644 --- a/tests/tests/src/core/Core_StringTests.res +++ b/tests/tests/src/core/Core_StringTests.res @@ -1,5 +1,3 @@ -open RescriptCore - let eq = (a, b) => a == b Test.run(__POS_OF__("String.equal optimization"), String.equal("one", "three"), eq, false) diff --git a/tests/tests/src/core/Core_TempTests.res b/tests/tests/src/core/Core_TempTests.res index 7fc39d1c4d..9bae00939a 100644 --- a/tests/tests/src/core/Core_TempTests.res +++ b/tests/tests/src/core/Core_TempTests.res @@ -1,5 +1,3 @@ -open RescriptCore - include IntlTests Console.info("") diff --git a/tests/tests/src/core/Core_TestTests.res b/tests/tests/src/core/Core_TestTests.res index 97a35c956c..df2a441d48 100644 --- a/tests/tests/src/core/Core_TestTests.res +++ b/tests/tests/src/core/Core_TestTests.res @@ -1,5 +1,3 @@ -open RescriptCore - let eq = (a, b) => a == b let bign = BigInt.fromFloat(Float.Constants.maxValue) diff --git a/tests/tests/src/core/Core_TypedArrayTests.res b/tests/tests/src/core/Core_TypedArrayTests.res index 746a18c207..b0719a1f62 100644 --- a/tests/tests/src/core/Core_TypedArrayTests.res +++ b/tests/tests/src/core/Core_TypedArrayTests.res @@ -1,5 +1,3 @@ -open RescriptCore - let eq = (a, b) => a == b // ===== BigInt64Array Tests ===== diff --git a/tests/tests/src/core/Test.res b/tests/tests/src/core/Test.res index 7c6f4d8ae3..d62638c910 100644 --- a/tests/tests/src/core/Test.res +++ b/tests/tests/src/core/Test.res @@ -1,6 +1,5 @@ // Test "framework" - @scope("process") @val external exit: int => unit = "exit" @scope("Error") @val external captureStackTrace: {..} => unit = "captureStackTrace" @module("@babel/code-frame") @val diff --git a/tests/tests/src/core/intl/Core_IntlTests.res b/tests/tests/src/core/intl/Core_IntlTests.res index d5fa1c6d47..0e9f8ec2ac 100644 --- a/tests/tests/src/core/intl/Core_IntlTests.res +++ b/tests/tests/src/core/intl/Core_IntlTests.res @@ -7,8 +7,6 @@ include Intl__PluralRulesTest include Intl__RelativeTimeFormatTest include Intl__SegmenterTest -open RescriptCore - Console.log("---") Console.log("Intl") diff --git a/tests/tests/src/core/intl/Core_Intl_CollatorTest.res b/tests/tests/src/core/intl/Core_Intl_CollatorTest.res index abba374f51..1983bdc416 100644 --- a/tests/tests/src/core/intl/Core_Intl_CollatorTest.res +++ b/tests/tests/src/core/intl/Core_Intl_CollatorTest.res @@ -1,5 +1,3 @@ -open RescriptCore - Console.log("---") Console.log("Intl.Collator") diff --git a/tests/tests/src/core/intl/Core_Intl_DateTimeFormatTest.res b/tests/tests/src/core/intl/Core_Intl_DateTimeFormatTest.res index 20e77d581e..b35ff9333d 100644 --- a/tests/tests/src/core/intl/Core_Intl_DateTimeFormatTest.res +++ b/tests/tests/src/core/intl/Core_Intl_DateTimeFormatTest.res @@ -1,5 +1,3 @@ -open RescriptCore - Console.log("---") Console.log("Intl.DateTimeFormat") diff --git a/tests/tests/src/core/intl/Core_Intl_ListFormatTest.res b/tests/tests/src/core/intl/Core_Intl_ListFormatTest.res index ec5fae7d84..d925c00ccd 100644 --- a/tests/tests/src/core/intl/Core_Intl_ListFormatTest.res +++ b/tests/tests/src/core/intl/Core_Intl_ListFormatTest.res @@ -1,5 +1,3 @@ -open RescriptCore - Console.log("---") Console.log("Intl.ListFormat") diff --git a/tests/tests/src/core/intl/Core_Intl_LocaleTest.res b/tests/tests/src/core/intl/Core_Intl_LocaleTest.res index b91e5001a9..fe9b0537b3 100644 --- a/tests/tests/src/core/intl/Core_Intl_LocaleTest.res +++ b/tests/tests/src/core/intl/Core_Intl_LocaleTest.res @@ -1,5 +1,3 @@ -open RescriptCore - Console.log("---") Console.log("Intl.Locale") diff --git a/tests/tests/src/core/intl/Core_Intl_NumberFormatTest.res b/tests/tests/src/core/intl/Core_Intl_NumberFormatTest.res index b6c1595f80..9dd84f265c 100644 --- a/tests/tests/src/core/intl/Core_Intl_NumberFormatTest.res +++ b/tests/tests/src/core/intl/Core_Intl_NumberFormatTest.res @@ -1,5 +1,3 @@ -open RescriptCore - Console.log("---") Console.log("Intl.NumberFormat") diff --git a/tests/tests/src/core/intl/Core_Intl_PluralRulesTest.res b/tests/tests/src/core/intl/Core_Intl_PluralRulesTest.res index 3071041472..3262ee5b61 100644 --- a/tests/tests/src/core/intl/Core_Intl_PluralRulesTest.res +++ b/tests/tests/src/core/intl/Core_Intl_PluralRulesTest.res @@ -1,5 +1,3 @@ -open RescriptCore - Console.log("---") Console.log("Intl.PluralRules") diff --git a/tests/tests/src/core/intl/Core_Intl_RelativeTimeFormatTest.res b/tests/tests/src/core/intl/Core_Intl_RelativeTimeFormatTest.res index 6f53ad7e7f..e246525df9 100644 --- a/tests/tests/src/core/intl/Core_Intl_RelativeTimeFormatTest.res +++ b/tests/tests/src/core/intl/Core_Intl_RelativeTimeFormatTest.res @@ -1,5 +1,3 @@ -open RescriptCore - Console.log("---") Console.log("Intl.RelativeTimeFormat") diff --git a/tests/tests/src/core/intl/Core_Intl_SegmenterTest.res b/tests/tests/src/core/intl/Core_Intl_SegmenterTest.res index ed32293926..a95819a649 100644 --- a/tests/tests/src/core/intl/Core_Intl_SegmenterTest.res +++ b/tests/tests/src/core/intl/Core_Intl_SegmenterTest.res @@ -1,5 +1,3 @@ -open RescriptCore - Console.log("---") Console.log("Intl.Segmenter") From ed10b039cc6f35cd60c2b19f87091d5861cf832e Mon Sep 17 00:00:00 2001 From: Christoph Knittel Date: Tue, 22 Oct 2024 08:51:56 +0200 Subject: [PATCH 3/7] Fix imports --- tests/tests/src/core/Core_ImportTests.res | 2 +- tests/tests/src/core/Core_TempTests.res | 2 +- tests/tests/src/core/Core_TestSuite.res | 26 +++++++++---------- tests/tests/src/core/intl/Core_IntlTests.res | 16 ++++++------ .../core/intl/Core_Intl_NumberFormatTest.res | 2 +- 5 files changed, 24 insertions(+), 24 deletions(-) diff --git a/tests/tests/src/core/Core_ImportTests.res b/tests/tests/src/core/Core_ImportTests.res index baf6c32360..e9e2049aff 100644 --- a/tests/tests/src/core/Core_ImportTests.res +++ b/tests/tests/src/core/Core_ImportTests.res @@ -1,5 +1,5 @@ let main = async () => { - let eq = await import(IntTests.eq) + let eq = await import(Core_IntTests.eq) Test.run(__POS_OF__("dynamic import - Int tests - eq"), 1, eq, 1) } diff --git a/tests/tests/src/core/Core_TempTests.res b/tests/tests/src/core/Core_TempTests.res index 9bae00939a..a3fe866caa 100644 --- a/tests/tests/src/core/Core_TempTests.res +++ b/tests/tests/src/core/Core_TempTests.res @@ -1,4 +1,4 @@ -include IntlTests +include Core_IntlTests Console.info("") Console.info("Array") diff --git a/tests/tests/src/core/Core_TestSuite.res b/tests/tests/src/core/Core_TestSuite.res index 4b3496ea18..e048a3bd56 100644 --- a/tests/tests/src/core/Core_TestSuite.res +++ b/tests/tests/src/core/Core_TestSuite.res @@ -1,13 +1,13 @@ -include TestTests -include PromiseTest -include ErrorTests -include ArrayTests -include IntTests -include ObjectTests -include ResultTests -include TypedArrayTests -include FloatTests -include JsonTests -include NullableTests -include DictTests -include IteratorTests +include Core_TestTests +include Core_PromiseTest +include Core_ErrorTests +include Core_ArrayTests +include Core_IntTests +include Core_ObjectTests +include Core_ResultTests +include Core_TypedArrayTests +include Core_FloatTests +include Core_JsonTests +include Core_NullableTests +include Core_DictTests +include Core_IteratorTests diff --git a/tests/tests/src/core/intl/Core_IntlTests.res b/tests/tests/src/core/intl/Core_IntlTests.res index 0e9f8ec2ac..7b1f45d75e 100644 --- a/tests/tests/src/core/intl/Core_IntlTests.res +++ b/tests/tests/src/core/intl/Core_IntlTests.res @@ -1,11 +1,11 @@ -include Intl__CollatorTest -include Intl__DateTimeFormatTest -include Intl__ListFormatTest -include Intl__LocaleTest -include Intl__NumberFormatTest -include Intl__PluralRulesTest -include Intl__RelativeTimeFormatTest -include Intl__SegmenterTest +include Core_Intl_CollatorTest +include Core_Intl_DateTimeFormatTest +include Core_Intl_ListFormatTest +include Core_Intl_LocaleTest +include Core_Intl_NumberFormatTest +include Core_Intl_PluralRulesTest +include Core_Intl_RelativeTimeFormatTest +include Core_Intl_SegmenterTest Console.log("---") Console.log("Intl") diff --git a/tests/tests/src/core/intl/Core_Intl_NumberFormatTest.res b/tests/tests/src/core/intl/Core_Intl_NumberFormatTest.res index 9dd84f265c..8a126cec88 100644 --- a/tests/tests/src/core/intl/Core_Intl_NumberFormatTest.res +++ b/tests/tests/src/core/intl/Core_Intl_NumberFormatTest.res @@ -40,4 +40,4 @@ let sigFormatter = Intl.NumberFormat.make( let options = sigFormatter->Intl.NumberFormat.resolvedOptions Console.log(options) -options.useGrouping->Core__Intl__NumberFormat.Grouping.parseJsValue->Console.log +options.useGrouping->Intl_NumberFormat.Grouping.parseJsValue->Console.log From 6e7a5c254b20b0fb6f09d7c91a4f984148e25566 Mon Sep 17 00:00:00 2001 From: Christoph Knittel Date: Tue, 22 Oct 2024 08:54:10 +0200 Subject: [PATCH 4/7] Build Core tests --- tests/tests/src/core/Core_ArrayTests.mjs | 806 ++++++------ tests/tests/src/core/Core_DictTests.mjs | 82 +- tests/tests/src/core/Core_ErrorTests.mjs | 37 +- tests/tests/src/core/Core_FloatTests.mjs | 492 ++++---- tests/tests/src/core/Core_ImportTests.mjs | 22 +- tests/tests/src/core/Core_IntTests.mjs | 1087 ++++++++-------- tests/tests/src/core/Core_IteratorTests.mjs | 142 +-- tests/tests/src/core/Core_JsonTests.mjs | 32 +- tests/tests/src/core/Core_NullableTests.mjs | 68 +- tests/tests/src/core/Core_ObjectTests.mjs | 1116 ++++++++--------- tests/tests/src/core/Core_PromiseTest.mjs | 1052 ++++++++-------- tests/tests/src/core/Core_ResultTests.mjs | 132 +- tests/tests/src/core/Core_StringTests.mjs | 22 +- tests/tests/src/core/Core_TempTests.mjs | 274 ++-- tests/tests/src/core/Core_TestSuite.mjs | 164 +-- tests/tests/src/core/Core_TestTests.mjs | 362 +++--- tests/tests/src/core/Core_TypedArrayTests.mjs | 124 +- tests/tests/src/core/Test.mjs | 50 +- tests/tests/src/core/intl/Core_IntlTests.mjs | 124 +- .../src/core/intl/Core_Intl_CollatorTest.mjs | 42 +- .../intl/Core_Intl_DateTimeFormatTest.mjs | 59 +- .../core/intl/Core_Intl_ListFormatTest.mjs | 66 +- .../src/core/intl/Core_Intl_LocaleTest.mjs | 20 +- .../core/intl/Core_Intl_NumberFormatTest.mjs | 70 +- .../core/intl/Core_Intl_PluralRulesTest.mjs | 34 +- .../intl/Core_Intl_RelativeTimeFormatTest.mjs | 42 +- .../src/core/intl/Core_Intl_SegmenterTest.mjs | 42 +- 27 files changed, 3216 insertions(+), 3347 deletions(-) diff --git a/tests/tests/src/core/Core_ArrayTests.mjs b/tests/tests/src/core/Core_ArrayTests.mjs index fbce97e866..5f48457d79 100644 --- a/tests/tests/src/core/Core_ArrayTests.mjs +++ b/tests/tests/src/core/Core_ArrayTests.mjs @@ -1,477 +1,463 @@ // Generated by ReScript, PLEASE EDIT WITH CARE +import * as List from "rescript/lib/es6/List.js"; import * as Test from "./Test.mjs"; -import * as Caml_obj from "rescript/lib/es6/caml_obj.js"; -import * as Core__List from "../src/Core__List.mjs"; -import * as Core__Array from "../src/Core__Array.mjs"; +import * as $$Array from "rescript/lib/es6/Array.js"; +import * as Primitive_object from "rescript/lib/es6/Primitive_object.js"; -var eq = Caml_obj.equal; +let eq = Primitive_object.equal; Test.run([ - [ - "ArrayTests.res", - 5, - 20, - 26 - ], - "make" - ], Core__Array.make(6, 7), eq, [ - 7, - 7, - 7, - 7, - 7, - 7 - ]); + [ + "Core_ArrayTests.res", + 3, + 20, + 26 + ], + "make" +], $$Array.make(6, 7), eq, [ + 7, + 7, + 7, + 7, + 7, + 7 +]); Test.run([ - [ - "ArrayTests.res", - 7, - 20, - 42 - ], - "getUnsafe - existing" - ], 1, eq, 1); + [ + "Core_ArrayTests.res", + 5, + 20, + 42 + ], + "getUnsafe - existing" +], 1, eq, 1); Test.run([ - [ - "ArrayTests.res", - 8, - 20, - 41 - ], - "getUnsafe - missing" - ], [ - 0, - 1, - 2 - ][10], eq, undefined); + [ + "Core_ArrayTests.res", + 6, + 20, + 41 + ], + "getUnsafe - missing" +], [ + 0, + 1, + 2 + ][10], eq, undefined); Test.run([ - [ - "ArrayTests.res", - 11, - 13, - 30 - ], - "fromInitializer" - ], Core__Array.fromInitializer(7, (function (i) { - return i + 3 | 0; - })), eq, [ - 3, - 4, - 5, - 6, - 7, - 8, - 9 - ]); + [ + "Core_ArrayTests.res", + 9, + 13, + 30 + ], + "fromInitializer" +], $$Array.fromInitializer(7, i => i + 3 | 0), eq, [ + 3, + 4, + 5, + 6, + 7, + 8, + 9 +]); Test.run([ - [ - "ArrayTests.res", - 17, - 20, - 28 - ], - "reduce" - ], Core__Array.reduce([ - 1, - 2, - 3 - ], /* [] */0, Core__List.add), eq, { - hd: 3, - tl: { - hd: 2, - tl: { - hd: 1, - tl: /* [] */0 - } - } - }); + [ + "Core_ArrayTests.res", + 15, + 20, + 28 + ], + "reduce" +], $$Array.reduce([ + 1, + 2, + 3 +], /* [] */0, List.add), eq, { + hd: 3, + tl: { + hd: 2, + tl: { + hd: 1, + tl: /* [] */0 + } + } +}); Test.run([ - [ - "ArrayTests.res", - 18, - 20, - 36 - ], - "reduce - empty" - ], Core__Array.reduce([], /* [] */0, Core__List.add), eq, /* [] */0); + [ + "Core_ArrayTests.res", + 16, + 20, + 36 + ], + "reduce - empty" +], $$Array.reduce([], /* [] */0, List.add), eq, /* [] */0); Test.run([ - [ - "ArrayTests.res", - 21, - 13, - 30 - ], - "reduceWithIndex" - ], Core__Array.reduceWithIndex([ - 1, - 2, - 3 - ], /* [] */0, (function (acc, v, i) { - return { - hd: v + i | 0, - tl: acc - }; - })), eq, { - hd: 5, - tl: { - hd: 3, - tl: { - hd: 1, - tl: /* [] */0 - } - } - }); + [ + "Core_ArrayTests.res", + 19, + 13, + 30 + ], + "reduceWithIndex" +], $$Array.reduceWithIndex([ + 1, + 2, + 3 +], /* [] */0, (acc, v, i) => ({ + hd: v + i | 0, + tl: acc +})), eq, { + hd: 5, + tl: { + hd: 3, + tl: { + hd: 1, + tl: /* [] */0 + } + } +}); Test.run([ - [ - "ArrayTests.res", - 27, - 13, - 38 - ], - "reduceWithIndex - empty" - ], Core__Array.reduceWithIndex([], /* [] */0, (function (acc, v, i) { - return { - hd: v + i | 0, - tl: acc - }; - })), eq, /* [] */0); + [ + "Core_ArrayTests.res", + 25, + 13, + 38 + ], + "reduceWithIndex - empty" +], $$Array.reduceWithIndex([], /* [] */0, (acc, v, i) => ({ + hd: v + i | 0, + tl: acc +})), eq, /* [] */0); Test.run([ - [ - "ArrayTests.res", - 34, - 13, - 26 - ], - "reduceRight" - ], Core__Array.reduceRight([ - 1, - 2, - 3 - ], /* [] */0, Core__List.add), eq, { - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }); + [ + "Core_ArrayTests.res", + 32, + 13, + 26 + ], + "reduceRight" +], $$Array.reduceRight([ + 1, + 2, + 3 +], /* [] */0, List.add), eq, { + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } +}); Test.run([ - [ - "ArrayTests.res", - 39, - 20, - 41 - ], - "reduceRight - empty" - ], Core__Array.reduceRight([], /* [] */0, Core__List.add), eq, /* [] */0); + [ + "Core_ArrayTests.res", + 37, + 20, + 41 + ], + "reduceRight - empty" +], $$Array.reduceRight([], /* [] */0, List.add), eq, /* [] */0); Test.run([ - [ - "ArrayTests.res", - 42, - 13, - 35 - ], - "reduceEightWithIndex" - ], Core__Array.reduceRightWithIndex([ - 1, - 2, - 3 - ], /* [] */0, (function (acc, v, i) { - return { - hd: v + i | 0, - tl: acc - }; - })), eq, { - hd: 1, - tl: { - hd: 3, - tl: { - hd: 5, - tl: /* [] */0 - } - } - }); + [ + "Core_ArrayTests.res", + 40, + 13, + 35 + ], + "reduceEightWithIndex" +], $$Array.reduceRightWithIndex([ + 1, + 2, + 3 +], /* [] */0, (acc, v, i) => ({ + hd: v + i | 0, + tl: acc +})), eq, { + hd: 1, + tl: { + hd: 3, + tl: { + hd: 5, + tl: /* [] */0 + } + } +}); Test.run([ - [ - "ArrayTests.res", - 48, - 13, - 38 - ], - "reduceWithIndex - empty" - ], Core__Array.reduceRightWithIndex([], /* [] */0, (function (acc, v, i) { - return { - hd: v + i | 0, - tl: acc - }; - })), eq, /* [] */0); + [ + "Core_ArrayTests.res", + 46, + 13, + 38 + ], + "reduceWithIndex - empty" +], $$Array.reduceRightWithIndex([], /* [] */0, (acc, v, i) => ({ + hd: v + i | 0, + tl: acc +})), eq, /* [] */0); Test.run([ - [ - "ArrayTests.res", - 54, - 20, - 41 - ], - "toShuffled - length" - ], Core__Array.toShuffled([ - 1, - 2, - 3 - ]).length, eq, 3); + [ + "Core_ArrayTests.res", + 52, + 20, + 41 + ], + "toShuffled - length" +], $$Array.toShuffled([ + 1, + 2, + 3 +]).length, eq, 3); -var arr = [ +let arr = [ 1, 2, 3 ]; Test.run([ - [ - "ArrayTests.res", - 57, - 13, - 31 - ], - "shuffle - length" - ], (Core__Array.shuffle(arr), arr.length), eq, 3); + [ + "Core_ArrayTests.res", + 55, + 13, + 31 + ], + "shuffle - length" +], ($$Array.shuffle(arr), arr.length), eq, 3); Test.run([ - [ - "ArrayTests.res", - 68, - 13, - 24 - ], - "filterMap" - ], Core__Array.filterMap([ - 1, - 2, - 3, - 4, - 5, - 6 - ], (function (n) { - if (n % 2 === 0) { - return Math.imul(n, n); - } - - })), eq, [ - 4, - 16, - 36 - ]); + [ + "Core_ArrayTests.res", + 66, + 13, + 24 + ], + "filterMap" +], $$Array.filterMap([ + 1, + 2, + 3, + 4, + 5, + 6 +], n => { + if (n % 2 === 0) { + return Math.imul(n, n); + } + +}), eq, [ + 4, + 16, + 36 +]); Test.run([ - [ - "ArrayTests.res", - 73, - 20, - 42 - ], - "filterMap - no match" - ], Core__Array.filterMap([ - 1, - 2, - 3, - 4, - 5, - 6 - ], (function (param) { - - })), eq, []); + [ + "Core_ArrayTests.res", + 71, + 20, + 42 + ], + "filterMap - no match" +], $$Array.filterMap([ + 1, + 2, + 3, + 4, + 5, + 6 +], param => {}), eq, []); Test.run([ - [ - "ArrayTests.res", - 75, - 13, - 32 - ], - "filterMap - empty" - ], Core__Array.filterMap([], (function (n) { - if (n % 2 === 0) { - return Math.imul(n, n); - } - - })), eq, []); + [ + "Core_ArrayTests.res", + 73, + 13, + 32 + ], + "filterMap - empty" +], $$Array.filterMap([], n => { + if (n % 2 === 0) { + return Math.imul(n, n); + } + +}), eq, []); Test.run([ - [ - "ArrayTests.res", - 81, - 20, - 30 - ], - "keepSome" - ], Core__Array.keepSome([ - 1, - undefined, - 3 - ]), eq, [ - 1, - 3 - ]); + [ + "Core_ArrayTests.res", + 79, + 20, + 30 + ], + "keepSome" +], $$Array.keepSome([ + 1, + undefined, + 3 +]), eq, [ + 1, + 3 +]); Test.run([ - [ - "ArrayTests.res", - 83, - 13, - 34 - ], - "keepSome - all Some" - ], Core__Array.keepSome([ - 1, - 2, - 3 - ]), eq, [ - 1, - 2, - 3 - ]); + [ + "Core_ArrayTests.res", + 81, + 13, + 34 + ], + "keepSome - all Some" +], $$Array.keepSome([ + 1, + 2, + 3 +]), eq, [ + 1, + 2, + 3 +]); Test.run([ - [ - "ArrayTests.res", - 88, - 20, - 41 - ], - "keepSome - all None" - ], Core__Array.keepSome([ - undefined, - undefined, - undefined - ]), eq, []); + [ + "Core_ArrayTests.res", + 86, + 20, + 41 + ], + "keepSome - all None" +], $$Array.keepSome([ + undefined, + undefined, + undefined +]), eq, []); Test.run([ - [ - "ArrayTests.res", - 89, - 20, - 38 - ], - "keepSome - empty" - ], Core__Array.keepSome([]), eq, []); + [ + "Core_ArrayTests.res", + 87, + 20, + 38 + ], + "keepSome - empty" +], $$Array.keepSome([]), eq, []); Test.run([ - [ - "ArrayTests.res", - 92, - 13, - 22 - ], - "findMap" - ], Core__Array.findMap([ - 1, - 2, - 3, - 4, - 5, - 6 - ], (function (n) { - if (n % 2 === 0) { - return n - 8 | 0; - } - - })), eq, -6); + [ + "Core_ArrayTests.res", + 90, + 13, + 22 + ], + "findMap" +], $$Array.findMap([ + 1, + 2, + 3, + 4, + 5, + 6 +], n => { + if (n % 2 === 0) { + return n - 8 | 0; + } + +}), eq, -6); Test.run([ - [ - "ArrayTests.res", - 97, - 20, - 40 - ], - "findMap - no match" - ], Core__Array.findMap([ - 1, - 2, - 3, - 4, - 5, - 6 - ], (function (param) { - - })), eq, undefined); + [ + "Core_ArrayTests.res", + 95, + 20, + 40 + ], + "findMap - no match" +], $$Array.findMap([ + 1, + 2, + 3, + 4, + 5, + 6 +], param => {}), eq, undefined); Test.run([ - [ - "ArrayTests.res", - 99, - 13, - 30 - ], - "findMap - empty" - ], Core__Array.findMap([], (function (n) { - if (n % 2 === 0) { - return Math.imul(n, n); - } - - })), eq, undefined); + [ + "Core_ArrayTests.res", + 97, + 13, + 30 + ], + "findMap - empty" +], $$Array.findMap([], n => { + if (n % 2 === 0) { + return Math.imul(n, n); + } + +}), eq, undefined); Test.run([ - [ - "ArrayTests.res", - 106, - 13, - 27 - ], - "fromIterator" - ], Array.from(new Map([ - [ - 1, - 3 - ], - [ - 2, - 4 - ] - ]).values()), eq, [ - 3, - 4 - ]); + [ + "Core_ArrayTests.res", + 104, + 13, + 27 + ], + "fromIterator" +], Array.from(new Map([ + [ + 1, + 3 + ], + [ + 2, + 4 + ] +]).values()), eq, [ + 3, + 4 +]); Test.run([ - [ - "ArrayTests.res", - 112, - 20, - 39 - ], - "last - with items" - ], Core__Array.last([ - 1, - 2, - 3 - ]), eq, 3); + [ + "Core_ArrayTests.res", + 110, + 20, + 39 + ], + "last - with items" +], $$Array.last([ + 1, + 2, + 3 +]), eq, 3); Test.run([ - [ - "ArrayTests.res", - 113, - 20, - 34 - ], - "last - empty" - ], Core__Array.last([]), eq, undefined); + [ + "Core_ArrayTests.res", + 111, + 20, + 34 + ], + "last - empty" +], $$Array.last([]), eq, undefined); export { - eq , + eq, } /* Not a pure module */ diff --git a/tests/tests/src/core/Core_DictTests.mjs b/tests/tests/src/core/Core_DictTests.mjs index 3847e1e326..8efe14aada 100644 --- a/tests/tests/src/core/Core_DictTests.mjs +++ b/tests/tests/src/core/Core_DictTests.mjs @@ -1,57 +1,57 @@ // Generated by ReScript, PLEASE EDIT WITH CARE import * as Test from "./Test.mjs"; -import * as Caml_obj from "rescript/lib/es6/caml_obj.js"; +import * as Primitive_object from "rescript/lib/es6/Primitive_object.js"; -var eq = Caml_obj.equal; +let eq = Primitive_object.equal; Test.run([ - [ - "DictTests.res", - 5, - 20, - 26 - ], - "make" - ], {}, eq, {}); + [ + "Core_DictTests.res", + 3, + 20, + 26 + ], + "make" +], {}, eq, {}); Test.run([ - [ - "DictTests.res", - 7, - 20, - 31 - ], - "fromArray" - ], Object.fromEntries([[ - "foo", - "bar" - ]]), eq, {foo: "bar"}); + [ + "Core_DictTests.res", + 5, + 20, + 31 + ], + "fromArray" +], Object.fromEntries([[ + "foo", + "bar" + ]]), eq, {foo: "bar"}); Test.run([ - [ - "DictTests.res", - 10, - 13, - 35 - ], - "getUnsafe - existing" - ], Object.fromEntries([[ - "foo", - "bar" - ]])["foo"], eq, "bar"); + [ + "Core_DictTests.res", + 8, + 13, + 35 + ], + "getUnsafe - existing" +], Object.fromEntries([[ + "foo", + "bar" + ]])["foo"], eq, "bar"); Test.run([ - [ - "DictTests.res", - 16, - 13, - 34 - ], - "getUnsafe - missing" - ], ({})["foo"], eq, undefined); + [ + "Core_DictTests.res", + 14, + 13, + 34 + ], + "getUnsafe - missing" +], ({})["foo"], eq, undefined); export { - eq , + eq, } /* Not a pure module */ diff --git a/tests/tests/src/core/Core_ErrorTests.mjs b/tests/tests/src/core/Core_ErrorTests.mjs index dcced1d540..ce1cb6e63e 100644 --- a/tests/tests/src/core/Core_ErrorTests.mjs +++ b/tests/tests/src/core/Core_ErrorTests.mjs @@ -1,39 +1,36 @@ // Generated by ReScript, PLEASE EDIT WITH CARE +import * as Exn from "rescript/lib/es6/Exn.js"; import * as Test from "./Test.mjs"; -import * as Js_exn from "rescript/lib/es6/js_exn.js"; -import * as RescriptCore from "../src/RescriptCore.mjs"; -import * as Caml_js_exceptions from "rescript/lib/es6/caml_js_exceptions.js"; +import * as Pervasives from "rescript/lib/es6/Pervasives.js"; +import * as Primitive_exceptions from "rescript/lib/es6/Primitive_exceptions.js"; function panicTest() { - var caught; + let caught; try { - caught = RescriptCore.panic("uh oh"); - } - catch (raw_err){ - var err = Caml_js_exceptions.internalToOCamlException(raw_err); - if (err.RE_EXN_ID === Js_exn.$$Error) { + caught = Pervasives.panic("uh oh"); + } catch (raw_err) { + let err = Primitive_exceptions.internalToException(raw_err); + if (err.RE_EXN_ID === Exn.$$Error) { caught = err._1.message; } else { throw err; } } Test.run([ - [ - "ErrorTests.res", - 8, - 22, - 43 - ], - "Should resolve test" - ], caught, (function (prim0, prim1) { - return prim0 === prim1; - }), "Panic! uh oh"); + [ + "Core_ErrorTests.res", + 6, + 22, + 43 + ], + "Should resolve test" + ], caught, (prim0, prim1) => prim0 === prim1, "Panic! uh oh"); } panicTest(); export { - panicTest , + panicTest, } /* Not a pure module */ diff --git a/tests/tests/src/core/Core_FloatTests.mjs b/tests/tests/src/core/Core_FloatTests.mjs index 10d8de3a17..f58ad653a9 100644 --- a/tests/tests/src/core/Core_FloatTests.mjs +++ b/tests/tests/src/core/Core_FloatTests.mjs @@ -1,253 +1,253 @@ // Generated by ReScript, PLEASE EDIT WITH CARE import * as Test from "./Test.mjs"; -import * as Caml_obj from "rescript/lib/es6/caml_obj.js"; -import * as Core__Float from "../src/Core__Float.mjs"; -import * as PervasivesU from "rescript/lib/es6/pervasivesU.js"; - -var eq = Caml_obj.equal; - -Test.run([ - [ - "FloatTests.res", - 5, - 20, - 27 - ], - "clamp" - ], Core__Float.clamp(undefined, undefined, 4.2), eq, 4.2); - -Test.run([ - [ - "FloatTests.res", - 6, - 20, - 35 - ], - "clamp - < min" - ], Core__Float.clamp(4.3, undefined, 4.1), eq, 4.3); - -Test.run([ - [ - "FloatTests.res", - 7, - 20, - 35 - ], - "clamp - > min" - ], Core__Float.clamp(4.1, undefined, 4.2), eq, 4.2); - -Test.run([ - [ - "FloatTests.res", - 8, - 20, - 35 - ], - "clamp - < max" - ], Core__Float.clamp(undefined, 4.3, 4.2), eq, 4.2); - -Test.run([ - [ - "FloatTests.res", - 9, - 20, - 35 - ], - "clamp - > max" - ], Core__Float.clamp(undefined, 4.1, 4.2), eq, 4.1); - -Test.run([ - [ - "FloatTests.res", - 10, - 20, - 42 - ], - "clamp - < min, < max" - ], Core__Float.clamp(4.3, 4.5, 4.2), eq, 4.3); - -Test.run([ - [ - "FloatTests.res", - 11, - 20, - 42 - ], - "clamp - < min, > max" - ], Core__Float.clamp(4.3, 4.1, 4.2), eq, 4.3); - -Test.run([ - [ - "FloatTests.res", - 12, - 20, - 42 - ], - "clamp - > min, < max" - ], Core__Float.clamp(4.1, 4.5, 4.2), eq, 4.2); - -Test.run([ - [ - "FloatTests.res", - 13, - 20, - 42 - ], - "clamp - > min, > max" - ], Core__Float.clamp(4.1, 4.1, 4.2), eq, 4.1); - -Test.run([ - [ - "FloatTests.res", - 14, - 20, - 33 - ], - "clamp - nan" - ], isNaN(Core__Float.clamp(4.1, 4.3, Number.NaN)), eq, true); - -Test.run([ - [ - "FloatTests.res", - 15, - 20, - 38 - ], - "clamp - infinity" - ], Core__Float.clamp(4.1, 4.3, PervasivesU.infinity), eq, 4.3); - -Test.run([ - [ - "FloatTests.res", - 16, - 20, - 39 - ], - "clamp - -infinity" - ], Core__Float.clamp(4.1, 4.3, PervasivesU.neg_infinity), eq, 4.1); - -Test.run([ - [ - "FloatTests.res", - 17, - 20, - 37 - ], - "clamp - min nan" - ], Core__Float.clamp(Number.NaN, undefined, 4.2), eq, 4.2); - -Test.run([ - [ - "FloatTests.res", - 18, - 20, - 37 - ], - "clamp - max nan" - ], Core__Float.clamp(undefined, Number.NaN, 4.2), eq, 4.2); - -Test.run([ - [ - "FloatTests.res", - 19, - 20, - 46 - ], - "clamp - min nan, max nan" - ], Core__Float.clamp(Number.NaN, Number.NaN, 4.2), eq, 4.2); - -Test.run([ - [ - "FloatTests.res", - 20, - 20, - 42 - ], - "clamp - min infinity" - ], Core__Float.clamp(PervasivesU.infinity, undefined, 4.2), eq, PervasivesU.infinity); - -Test.run([ - [ - "FloatTests.res", - 21, - 20, - 42 - ], - "clamp - max infinity" - ], Core__Float.clamp(undefined, PervasivesU.infinity, 4.2), eq, 4.2); - -Test.run([ - [ - "FloatTests.res", - 22, - 20, - 43 - ], - "clamp - min -infinity" - ], Core__Float.clamp(PervasivesU.neg_infinity, undefined, 4.2), eq, 4.2); - -Test.run([ - [ - "FloatTests.res", - 23, - 20, - 43 - ], - "clamp - max -infinity" - ], Core__Float.clamp(undefined, PervasivesU.neg_infinity, 4.2), eq, PervasivesU.neg_infinity); - -Test.run([ - [ - "FloatTests.res", - 25, - 13, - 49 - ], - "clamp - min infinity, max infinity" - ], Core__Float.clamp(PervasivesU.infinity, PervasivesU.infinity, 4.2), eq, PervasivesU.infinity); - -Test.run([ - [ - "FloatTests.res", - 31, - 13, - 50 - ], - "clamp - min -infinity, max infinity" - ], Core__Float.clamp(PervasivesU.neg_infinity, PervasivesU.infinity, 4.2), eq, 4.2); - -Test.run([ - [ - "FloatTests.res", - 37, - 13, - 50 - ], - "clamp - min infinity, max -infinity" - ], Core__Float.clamp(PervasivesU.infinity, PervasivesU.neg_infinity, 4.2), eq, PervasivesU.infinity); - -Test.run([ - [ - "FloatTests.res", - 43, - 13, - 51 - ], - "clamp - min -infinity, max -infinity" - ], Core__Float.clamp(PervasivesU.neg_infinity, PervasivesU.neg_infinity, 4.2), eq, PervasivesU.neg_infinity); - -Test.run([ - [ - "FloatTests.res", - 49, - 20, - 46 - ], - "Float.equal optimization" - ], false, eq, false); +import * as Float from "rescript/lib/es6/Float.js"; +import * as Pervasives from "rescript/lib/es6/Pervasives.js"; +import * as Primitive_object from "rescript/lib/es6/Primitive_object.js"; + +let eq = Primitive_object.equal; + +Test.run([ + [ + "Core_FloatTests.res", + 3, + 20, + 27 + ], + "clamp" +], Float.clamp(undefined, undefined, 4.2), eq, 4.2); + +Test.run([ + [ + "Core_FloatTests.res", + 4, + 20, + 35 + ], + "clamp - < min" +], Float.clamp(4.3, undefined, 4.1), eq, 4.3); + +Test.run([ + [ + "Core_FloatTests.res", + 5, + 20, + 35 + ], + "clamp - > min" +], Float.clamp(4.1, undefined, 4.2), eq, 4.2); + +Test.run([ + [ + "Core_FloatTests.res", + 6, + 20, + 35 + ], + "clamp - < max" +], Float.clamp(undefined, 4.3, 4.2), eq, 4.2); + +Test.run([ + [ + "Core_FloatTests.res", + 7, + 20, + 35 + ], + "clamp - > max" +], Float.clamp(undefined, 4.1, 4.2), eq, 4.1); + +Test.run([ + [ + "Core_FloatTests.res", + 8, + 20, + 42 + ], + "clamp - < min, < max" +], Float.clamp(4.3, 4.5, 4.2), eq, 4.3); + +Test.run([ + [ + "Core_FloatTests.res", + 9, + 20, + 42 + ], + "clamp - < min, > max" +], Float.clamp(4.3, 4.1, 4.2), eq, 4.3); + +Test.run([ + [ + "Core_FloatTests.res", + 10, + 20, + 42 + ], + "clamp - > min, < max" +], Float.clamp(4.1, 4.5, 4.2), eq, 4.2); + +Test.run([ + [ + "Core_FloatTests.res", + 11, + 20, + 42 + ], + "clamp - > min, > max" +], Float.clamp(4.1, 4.1, 4.2), eq, 4.1); + +Test.run([ + [ + "Core_FloatTests.res", + 12, + 20, + 33 + ], + "clamp - nan" +], isNaN(Float.clamp(4.1, 4.3, Number.NaN)), eq, true); + +Test.run([ + [ + "Core_FloatTests.res", + 13, + 20, + 38 + ], + "clamp - infinity" +], Float.clamp(4.1, 4.3, Pervasives.infinity), eq, 4.3); + +Test.run([ + [ + "Core_FloatTests.res", + 14, + 20, + 39 + ], + "clamp - -infinity" +], Float.clamp(4.1, 4.3, Pervasives.neg_infinity), eq, 4.1); + +Test.run([ + [ + "Core_FloatTests.res", + 15, + 20, + 37 + ], + "clamp - min nan" +], Float.clamp(Number.NaN, undefined, 4.2), eq, 4.2); + +Test.run([ + [ + "Core_FloatTests.res", + 16, + 20, + 37 + ], + "clamp - max nan" +], Float.clamp(undefined, Number.NaN, 4.2), eq, 4.2); + +Test.run([ + [ + "Core_FloatTests.res", + 17, + 20, + 46 + ], + "clamp - min nan, max nan" +], Float.clamp(Number.NaN, Number.NaN, 4.2), eq, 4.2); + +Test.run([ + [ + "Core_FloatTests.res", + 18, + 20, + 42 + ], + "clamp - min infinity" +], Float.clamp(Pervasives.infinity, undefined, 4.2), eq, Pervasives.infinity); + +Test.run([ + [ + "Core_FloatTests.res", + 19, + 20, + 42 + ], + "clamp - max infinity" +], Float.clamp(undefined, Pervasives.infinity, 4.2), eq, 4.2); + +Test.run([ + [ + "Core_FloatTests.res", + 20, + 20, + 43 + ], + "clamp - min -infinity" +], Float.clamp(Pervasives.neg_infinity, undefined, 4.2), eq, 4.2); + +Test.run([ + [ + "Core_FloatTests.res", + 21, + 20, + 43 + ], + "clamp - max -infinity" +], Float.clamp(undefined, Pervasives.neg_infinity, 4.2), eq, Pervasives.neg_infinity); + +Test.run([ + [ + "Core_FloatTests.res", + 23, + 13, + 49 + ], + "clamp - min infinity, max infinity" +], Float.clamp(Pervasives.infinity, Pervasives.infinity, 4.2), eq, Pervasives.infinity); + +Test.run([ + [ + "Core_FloatTests.res", + 29, + 13, + 50 + ], + "clamp - min -infinity, max infinity" +], Float.clamp(Pervasives.neg_infinity, Pervasives.infinity, 4.2), eq, 4.2); + +Test.run([ + [ + "Core_FloatTests.res", + 35, + 13, + 50 + ], + "clamp - min infinity, max -infinity" +], Float.clamp(Pervasives.infinity, Pervasives.neg_infinity, 4.2), eq, Pervasives.infinity); + +Test.run([ + [ + "Core_FloatTests.res", + 41, + 13, + 51 + ], + "clamp - min -infinity, max -infinity" +], Float.clamp(Pervasives.neg_infinity, Pervasives.neg_infinity, 4.2), eq, Pervasives.neg_infinity); + +Test.run([ + [ + "Core_FloatTests.res", + 47, + 20, + 46 + ], + "Float.equal optimization" +], false, eq, false); export { - eq , + eq, } /* Not a pure module */ diff --git a/tests/tests/src/core/Core_ImportTests.mjs b/tests/tests/src/core/Core_ImportTests.mjs index 6a94c12d95..bdfc1180c3 100644 --- a/tests/tests/src/core/Core_ImportTests.mjs +++ b/tests/tests/src/core/Core_ImportTests.mjs @@ -3,21 +3,19 @@ import * as Test from "./Test.mjs"; async function main() { - var eq = await import("./IntTests.mjs").then(function (m) { - return m.eq; - }); + let eq = await import("./Core_IntTests.mjs").then(m => m.eq); return Test.run([ - [ - "ImportTests.res", - 5, - 22, - 55 - ], - "dynamic import - Int tests - eq" - ], 1, eq, 1); + [ + "Core_ImportTests.res", + 3, + 22, + 55 + ], + "dynamic import - Int tests - eq" + ], 1, eq, 1); } export { - main , + main, } /* Test Not a pure module */ diff --git a/tests/tests/src/core/Core_IntTests.mjs b/tests/tests/src/core/Core_IntTests.mjs index 2ab9a0ceeb..6935d883e3 100644 --- a/tests/tests/src/core/Core_IntTests.mjs +++ b/tests/tests/src/core/Core_IntTests.mjs @@ -1,22 +1,21 @@ // Generated by ReScript, PLEASE EDIT WITH CARE +import * as Exn from "rescript/lib/es6/Exn.js"; +import * as Int from "rescript/lib/es6/Int.js"; import * as Test from "./Test.mjs"; -import * as Js_exn from "rescript/lib/es6/js_exn.js"; -import * as Caml_obj from "rescript/lib/es6/caml_obj.js"; -import * as Core__Int from "../src/Core__Int.mjs"; -import * as PervasivesU from "rescript/lib/es6/pervasivesU.js"; -import * as Caml_js_exceptions from "rescript/lib/es6/caml_js_exceptions.js"; +import * as Pervasives from "rescript/lib/es6/Pervasives.js"; +import * as Primitive_object from "rescript/lib/es6/Primitive_object.js"; +import * as Primitive_exceptions from "rescript/lib/es6/Primitive_exceptions.js"; -var eq = Caml_obj.equal; +let eq = Primitive_object.equal; function $$catch(f) { try { f(); - return PervasivesU.failwith("no exception raised"); - } - catch (raw_err){ - var err = Caml_js_exceptions.internalToOCamlException(raw_err); - if (err.RE_EXN_ID === Js_exn.$$Error) { + return Pervasives.failwith("no exception raised"); + } catch (raw_err) { + let err = Primitive_exceptions.internalToException(raw_err); + if (err.RE_EXN_ID === Exn.$$Error) { return err._1; } throw err; @@ -24,542 +23,538 @@ function $$catch(f) { } Test.run([ - [ - "IntTests.res", - 13, - 20, - 50 - ], - "range - positive, increasing" - ], Core__Int.range(3, 6, undefined), eq, [ - 3, - 4, - 5 - ]); - -Test.run([ - [ - "IntTests.res", - 14, - 20, - 50 - ], - "range - negative, increasing" - ], Core__Int.range(-3, -1, undefined), eq, [ - -3, - -2 - ]); - -Test.run([ - [ - "IntTests.res", - 15, - 20, - 51 - ], - "range - cross-zero, incresing" - ], Core__Int.range(-1, 2, undefined), eq, [ - -1, - 0, - 1 - ]); - -Test.run([ - [ - "IntTests.res", - 16, - 20, - 42 - ], - "range - start == end" - ], Core__Int.range(3, 3, undefined), eq, []); - -Test.run([ - [ - "IntTests.res", - 17, - 20, - 50 - ], - "range - positive, decreasing" - ], Core__Int.range(3, 1, undefined), eq, [ - 3, - 2 - ]); - -Test.run([ - [ - "IntTests.res", - 18, - 20, - 50 - ], - "range - negative, decreasing" - ], Core__Int.range(-1, -3, undefined), eq, [ - -1, - -2 - ]); - -Test.run([ - [ - "IntTests.res", - 21, - 13, - 51 - ], - "range - positive, increasing, step 2" - ], Core__Int.range(3, 6, { - step: 2 - }), eq, [ - 3, - 5 - ]); - -Test.run([ - [ - "IntTests.res", - 27, - 13, - 51 - ], - "range + positive, increasing, step 2" - ], Core__Int.range(3, 7, { - step: 2 - }), eq, [ - 3, - 5 - ]); - -Test.run([ - [ - "IntTests.res", - 33, - 13, - 51 - ], - "range + positive, increasing, step 2" - ], Core__Int.range(3, 8, { - step: 2 - }), eq, [ - 3, - 5, - 7 - ]); - -Test.run([ - [ - "IntTests.res", - 39, - 13, - 51 - ], - "range - negative, increasing, step 2" - ], Core__Int.range(-6, -3, { - step: 2 - }), eq, [ - -6, - -4 - ]); - -Test.run([ - [ - "IntTests.res", - 45, - 13, - 51 - ], - "range - positive, increasing, step 0" - ], $$catch(function () { - return Core__Int.range(3, 6, { - step: 0 - }); - }), eq, new RangeError("Incorrect range arguments")); - -Test.run([ - [ - "IntTests.res", - 50, - 20, - 50 - ], - "range - start == end, step 0" - ], Core__Int.range(3, 3, { - step: 0 - }), eq, []); - -Test.run([ - [ - "IntTests.res", - 52, - 13, - 52 - ], - "range + positive, increasing, step -1" - ], Core__Int.range(3, 6, { - step: -1 - }), eq, []); - -Test.run([ - [ - "IntTests.res", - 58, - 13, - 51 - ], - "range + positive, decreasing, step 1" - ], Core__Int.range(6, 3, { - step: 1 - }), eq, []); - -Test.run([ - [ - "IntTests.res", - 64, - 13, - 52 - ], - "range + positive, decreasing, step -2" - ], Core__Int.range(6, 3, { - step: -2 - }), eq, [ - 6, - 4 - ]); - -Test.run([ - [ - "IntTests.res", - 70, - 13, - 52 - ], - "range + positive, increasing, step -2" - ], Core__Int.range(6, 2, { - step: -2 - }), eq, [ - 6, - 4 - ]); - -Test.run([ - [ - "IntTests.res", - 76, - 13, - 52 - ], - "range + positive, increasing, step -2" - ], Core__Int.range(6, 1, { - step: -2 - }), eq, [ - 6, - 4, - 2 - ]); - -Test.run([ - [ - "IntTests.res", - 82, - 13, - 52 - ], - "range + negative, decreasing, step -2" - ], Core__Int.range(-3, -6, { - step: -2 - }), eq, [ - -3, - -5 - ]); - -Test.run([ - [ - "IntTests.res", - 88, - 13, - 62 - ], - "range - positive, increasing, step 2, inclusive" - ], Core__Int.range(3, 6, { - step: 2, - inclusive: true - }), eq, [ - 3, - 5 - ]); - -Test.run([ - [ - "IntTests.res", - 94, - 13, - 62 - ], - "range + positive, increasing, step 2, inclusive" - ], Core__Int.range(3, 7, { - step: 2, - inclusive: true - }), eq, [ - 3, - 5, - 7 - ]); - -Test.run([ - [ - "IntTests.res", - 100, - 13, - 62 - ], - "range + positive, increasing, step 2, inclusive" - ], Core__Int.range(3, 8, { - step: 2, - inclusive: true - }), eq, [ - 3, - 5, - 7 - ]); - -Test.run([ - [ - "IntTests.res", - 106, - 13, - 62 - ], - "range - negative, increasing, step 2, inclusive" - ], Core__Int.range(-6, -3, { - step: 2, - inclusive: true - }), eq, [ - -6, - -4 - ]); - -Test.run([ - [ - "IntTests.res", - 112, - 13, - 62 - ], - "range - positive, increasing, step 0, inclusive" - ], $$catch(function () { - return Core__Int.range(3, 6, { - step: 0, - inclusive: true - }); - }), eq, new RangeError("Incorrect range arguments")); - -Test.run([ - [ - "IntTests.res", - 118, - 13, - 54 - ], - "range - start == end, step 0, inclusive" - ], Core__Int.range(3, 3, { - step: 0, - inclusive: true - }), eq, [3]); - -Test.run([ - [ - "IntTests.res", - 124, - 13, - 63 - ], - "range + positive, increasing, step -1, inclusive" - ], Core__Int.range(3, 6, { - step: -1, - inclusive: true - }), eq, []); - -Test.run([ - [ - "IntTests.res", - 130, - 13, - 62 - ], - "range + positive, decreasing, step 1, inclusive" - ], Core__Int.range(6, 3, { - step: 1, - inclusive: true - }), eq, []); - -Test.run([ - [ - "IntTests.res", - 136, - 13, - 63 - ], - "range + positive, decreasing, step -2, inclusive" - ], Core__Int.range(6, 3, { - step: -2, - inclusive: true - }), eq, [ - 6, - 4 - ]); - -Test.run([ - [ - "IntTests.res", - 142, - 13, - 63 - ], - "range + positive, increasing, step -2, inclusive" - ], Core__Int.range(6, 2, { - step: -2, - inclusive: true - }), eq, [ - 6, - 4, - 2 - ]); - -Test.run([ - [ - "IntTests.res", - 148, - 13, - 63 - ], - "range + positive, increasing, step -2, inclusive" - ], Core__Int.range(6, 1, { - step: -2, - inclusive: true - }), eq, [ - 6, - 4, - 2 - ]); - -Test.run([ - [ - "IntTests.res", - 154, - 13, - 63 - ], - "range + negative, decreasing, step -2, inclusive" - ], Core__Int.range(-3, -6, { - step: -2, - inclusive: true - }), eq, [ - -3, - -5 - ]); - -Test.run([ - [ - "IntTests.res", - 160, - 20, - 27 - ], - "clamp" - ], Core__Int.clamp(undefined, undefined, 42), eq, 42); - -Test.run([ - [ - "IntTests.res", - 161, - 20, - 35 - ], - "clamp - < min" - ], Core__Int.clamp(50, undefined, 42), eq, 50); - -Test.run([ - [ - "IntTests.res", - 162, - 20, - 35 - ], - "clamp - > min" - ], Core__Int.clamp(40, undefined, 42), eq, 42); - -Test.run([ - [ - "IntTests.res", - 163, - 20, - 35 - ], - "clamp - < max" - ], Core__Int.clamp(undefined, 50, 42), eq, 42); - -Test.run([ - [ - "IntTests.res", - 164, - 20, - 35 - ], - "clamp - > max" - ], Core__Int.clamp(undefined, 40, 42), eq, 40); - -Test.run([ - [ - "IntTests.res", - 165, - 20, - 42 - ], - "clamp - < min, < max" - ], Core__Int.clamp(50, 60, 42), eq, 50); - -Test.run([ - [ - "IntTests.res", - 166, - 20, - 42 - ], - "clamp - < min, > max" - ], Core__Int.clamp(50, 40, 42), eq, 50); - -Test.run([ - [ - "IntTests.res", - 167, - 20, - 42 - ], - "clamp - > min, < max" - ], Core__Int.clamp(40, 60, 42), eq, 42); - -Test.run([ - [ - "IntTests.res", - 168, - 20, - 42 - ], - "clamp - > min, > max" - ], Core__Int.clamp(40, 40, 42), eq, 40); - -Test.run([ - [ - "IntTests.res", - 170, - 20, - 44 - ], - "Int.equal optimization" - ], false, eq, false); + [ + "Core_IntTests.res", + 11, + 20, + 50 + ], + "range - positive, increasing" +], Int.range(3, 6, undefined), eq, [ + 3, + 4, + 5 +]); + +Test.run([ + [ + "Core_IntTests.res", + 12, + 20, + 50 + ], + "range - negative, increasing" +], Int.range(-3, -1, undefined), eq, [ + -3, + -2 +]); + +Test.run([ + [ + "Core_IntTests.res", + 13, + 20, + 51 + ], + "range - cross-zero, incresing" +], Int.range(-1, 2, undefined), eq, [ + -1, + 0, + 1 +]); + +Test.run([ + [ + "Core_IntTests.res", + 14, + 20, + 42 + ], + "range - start == end" +], Int.range(3, 3, undefined), eq, []); + +Test.run([ + [ + "Core_IntTests.res", + 15, + 20, + 50 + ], + "range - positive, decreasing" +], Int.range(3, 1, undefined), eq, [ + 3, + 2 +]); + +Test.run([ + [ + "Core_IntTests.res", + 16, + 20, + 50 + ], + "range - negative, decreasing" +], Int.range(-1, -3, undefined), eq, [ + -1, + -2 +]); + +Test.run([ + [ + "Core_IntTests.res", + 19, + 13, + 51 + ], + "range - positive, increasing, step 2" +], Int.range(3, 6, { + step: 2 +}), eq, [ + 3, + 5 +]); + +Test.run([ + [ + "Core_IntTests.res", + 25, + 13, + 51 + ], + "range + positive, increasing, step 2" +], Int.range(3, 7, { + step: 2 +}), eq, [ + 3, + 5 +]); + +Test.run([ + [ + "Core_IntTests.res", + 31, + 13, + 51 + ], + "range + positive, increasing, step 2" +], Int.range(3, 8, { + step: 2 +}), eq, [ + 3, + 5, + 7 +]); + +Test.run([ + [ + "Core_IntTests.res", + 37, + 13, + 51 + ], + "range - negative, increasing, step 2" +], Int.range(-6, -3, { + step: 2 +}), eq, [ + -6, + -4 +]); + +Test.run([ + [ + "Core_IntTests.res", + 43, + 13, + 51 + ], + "range - positive, increasing, step 0" +], $$catch(() => Int.range(3, 6, { + step: 0 +})), eq, new RangeError("Incorrect range arguments")); + +Test.run([ + [ + "Core_IntTests.res", + 48, + 20, + 50 + ], + "range - start == end, step 0" +], Int.range(3, 3, { + step: 0 +}), eq, []); + +Test.run([ + [ + "Core_IntTests.res", + 50, + 13, + 52 + ], + "range + positive, increasing, step -1" +], Int.range(3, 6, { + step: -1 +}), eq, []); + +Test.run([ + [ + "Core_IntTests.res", + 56, + 13, + 51 + ], + "range + positive, decreasing, step 1" +], Int.range(6, 3, { + step: 1 +}), eq, []); + +Test.run([ + [ + "Core_IntTests.res", + 62, + 13, + 52 + ], + "range + positive, decreasing, step -2" +], Int.range(6, 3, { + step: -2 +}), eq, [ + 6, + 4 +]); + +Test.run([ + [ + "Core_IntTests.res", + 68, + 13, + 52 + ], + "range + positive, increasing, step -2" +], Int.range(6, 2, { + step: -2 +}), eq, [ + 6, + 4 +]); + +Test.run([ + [ + "Core_IntTests.res", + 74, + 13, + 52 + ], + "range + positive, increasing, step -2" +], Int.range(6, 1, { + step: -2 +}), eq, [ + 6, + 4, + 2 +]); + +Test.run([ + [ + "Core_IntTests.res", + 80, + 13, + 52 + ], + "range + negative, decreasing, step -2" +], Int.range(-3, -6, { + step: -2 +}), eq, [ + -3, + -5 +]); + +Test.run([ + [ + "Core_IntTests.res", + 86, + 13, + 62 + ], + "range - positive, increasing, step 2, inclusive" +], Int.range(3, 6, { + step: 2, + inclusive: true +}), eq, [ + 3, + 5 +]); + +Test.run([ + [ + "Core_IntTests.res", + 92, + 13, + 62 + ], + "range + positive, increasing, step 2, inclusive" +], Int.range(3, 7, { + step: 2, + inclusive: true +}), eq, [ + 3, + 5, + 7 +]); + +Test.run([ + [ + "Core_IntTests.res", + 98, + 13, + 62 + ], + "range + positive, increasing, step 2, inclusive" +], Int.range(3, 8, { + step: 2, + inclusive: true +}), eq, [ + 3, + 5, + 7 +]); + +Test.run([ + [ + "Core_IntTests.res", + 104, + 13, + 62 + ], + "range - negative, increasing, step 2, inclusive" +], Int.range(-6, -3, { + step: 2, + inclusive: true +}), eq, [ + -6, + -4 +]); + +Test.run([ + [ + "Core_IntTests.res", + 110, + 13, + 62 + ], + "range - positive, increasing, step 0, inclusive" +], $$catch(() => Int.range(3, 6, { + step: 0, + inclusive: true +})), eq, new RangeError("Incorrect range arguments")); + +Test.run([ + [ + "Core_IntTests.res", + 116, + 13, + 54 + ], + "range - start == end, step 0, inclusive" +], Int.range(3, 3, { + step: 0, + inclusive: true +}), eq, [3]); + +Test.run([ + [ + "Core_IntTests.res", + 122, + 13, + 63 + ], + "range + positive, increasing, step -1, inclusive" +], Int.range(3, 6, { + step: -1, + inclusive: true +}), eq, []); + +Test.run([ + [ + "Core_IntTests.res", + 128, + 13, + 62 + ], + "range + positive, decreasing, step 1, inclusive" +], Int.range(6, 3, { + step: 1, + inclusive: true +}), eq, []); + +Test.run([ + [ + "Core_IntTests.res", + 134, + 13, + 63 + ], + "range + positive, decreasing, step -2, inclusive" +], Int.range(6, 3, { + step: -2, + inclusive: true +}), eq, [ + 6, + 4 +]); + +Test.run([ + [ + "Core_IntTests.res", + 140, + 13, + 63 + ], + "range + positive, increasing, step -2, inclusive" +], Int.range(6, 2, { + step: -2, + inclusive: true +}), eq, [ + 6, + 4, + 2 +]); + +Test.run([ + [ + "Core_IntTests.res", + 146, + 13, + 63 + ], + "range + positive, increasing, step -2, inclusive" +], Int.range(6, 1, { + step: -2, + inclusive: true +}), eq, [ + 6, + 4, + 2 +]); + +Test.run([ + [ + "Core_IntTests.res", + 152, + 13, + 63 + ], + "range + negative, decreasing, step -2, inclusive" +], Int.range(-3, -6, { + step: -2, + inclusive: true +}), eq, [ + -3, + -5 +]); + +Test.run([ + [ + "Core_IntTests.res", + 158, + 20, + 27 + ], + "clamp" +], Int.clamp(undefined, undefined, 42), eq, 42); + +Test.run([ + [ + "Core_IntTests.res", + 159, + 20, + 35 + ], + "clamp - < min" +], Int.clamp(50, undefined, 42), eq, 50); + +Test.run([ + [ + "Core_IntTests.res", + 160, + 20, + 35 + ], + "clamp - > min" +], Int.clamp(40, undefined, 42), eq, 42); + +Test.run([ + [ + "Core_IntTests.res", + 161, + 20, + 35 + ], + "clamp - < max" +], Int.clamp(undefined, 50, 42), eq, 42); + +Test.run([ + [ + "Core_IntTests.res", + 162, + 20, + 35 + ], + "clamp - > max" +], Int.clamp(undefined, 40, 42), eq, 40); + +Test.run([ + [ + "Core_IntTests.res", + 163, + 20, + 42 + ], + "clamp - < min, < max" +], Int.clamp(50, 60, 42), eq, 50); + +Test.run([ + [ + "Core_IntTests.res", + 164, + 20, + 42 + ], + "clamp - < min, > max" +], Int.clamp(50, 40, 42), eq, 50); + +Test.run([ + [ + "Core_IntTests.res", + 165, + 20, + 42 + ], + "clamp - > min, < max" +], Int.clamp(40, 60, 42), eq, 42); + +Test.run([ + [ + "Core_IntTests.res", + 166, + 20, + 42 + ], + "clamp - > min, > max" +], Int.clamp(40, 40, 42), eq, 40); + +Test.run([ + [ + "Core_IntTests.res", + 168, + 20, + 44 + ], + "Int.equal optimization" +], false, eq, false); export { - eq , - $$catch , + eq, + $$catch, } /* Not a pure module */ diff --git a/tests/tests/src/core/Core_IteratorTests.mjs b/tests/tests/src/core/Core_IteratorTests.mjs index c40b973923..f79c9cefe1 100644 --- a/tests/tests/src/core/Core_IteratorTests.mjs +++ b/tests/tests/src/core/Core_IteratorTests.mjs @@ -1,41 +1,41 @@ // Generated by ReScript, PLEASE EDIT WITH CARE import * as Test from "./Test.mjs"; -import * as Caml_obj from "rescript/lib/es6/caml_obj.js"; -import * as Core__Iterator from "../src/Core__Iterator.mjs"; -import * as Core__AsyncIterator from "../src/Core__AsyncIterator.mjs"; +import * as $$Iterator from "rescript/lib/es6/Iterator.js"; +import * as $$AsyncIterator from "rescript/lib/es6/AsyncIterator.js"; +import * as Primitive_object from "rescript/lib/es6/Primitive_object.js"; -var eq = Caml_obj.equal; +let eq = Primitive_object.equal; -var iterator = ((() => { +let iterator = ((() => { var array1 = ['a', 'b', 'c']; var iterator1 = array1[Symbol.iterator](); return iterator1 })()); -var syncResult = { +let syncResult = { contents: undefined }; -Core__Iterator.forEach(iterator, (function (v) { - if (v === "b") { - syncResult.contents = "b"; - return ; - } - - })); +$$Iterator.forEach(iterator, v => { + if (v === "b") { + syncResult.contents = "b"; + return; + } + +}); Test.run([ - [ - "IteratorTests.res", - 21, - 20, - 34 - ], - "Sync forEach" - ], syncResult.contents, eq, "b"); - -var asyncIterator = ((() => { + [ + "Core_IteratorTests.res", + 19, + 20, + 34 + ], + "Sync forEach" +], syncResult.contents, eq, "b"); + +let asyncIterator = ((() => { var map1 = new Map(); map1.set('first', '1'); @@ -45,69 +45,69 @@ var asyncIterator = ((() => { return iterator1; })()); -var asyncResult = { +let asyncResult = { contents: undefined }; -await Core__AsyncIterator.forEach(asyncIterator, (function (v) { - if (v !== undefined && v[0] === "second") { - asyncResult.contents = "second"; - return ; - } - - })); +await $$AsyncIterator.forEach(asyncIterator, v => { + if (v !== undefined && v[0] === "second") { + asyncResult.contents = "second"; + return; + } + +}); Test.run([ - [ - "IteratorTests.res", - 44, - 20, - 35 - ], - "Async forEach" - ], asyncResult.contents, eq, "second"); - -var asyncResult$1 = { + [ + "Core_IteratorTests.res", + 42, + 20, + 35 + ], + "Async forEach" +], asyncResult.contents, eq, "second"); + +let asyncResult$1 = { contents: undefined }; -var count = { +let count = { contents: 0 }; -var asyncIterator$1 = Core__AsyncIterator.make(async function () { - var currentCount = count.contents; - count.contents = currentCount + 1 | 0; - if (currentCount === 3) { - return Core__AsyncIterator.done(currentCount); - } else { - return Core__AsyncIterator.value(currentCount); - } - }); - -await Core__AsyncIterator.forEach(asyncIterator$1, (function (v) { - if (v === 3) { - asyncResult$1.contents = "done"; - } else { - console.log("next.."); - } - })); +let asyncIterator$1 = $$AsyncIterator.make(async () => { + let currentCount = count.contents; + count.contents = currentCount + 1 | 0; + if (currentCount === 3) { + return $$AsyncIterator.done(currentCount); + } else { + return $$AsyncIterator.value(currentCount); + } +}); + +await $$AsyncIterator.forEach(asyncIterator$1, v => { + if (v === 3) { + asyncResult$1.contents = "done"; + } else { + console.log("next.."); + } +}); Test.run([ - [ - "IteratorTests.res", - 69, - 20, - 54 - ], - "Creating your own async iterator" - ], asyncResult$1.contents, eq, "done"); + [ + "Core_IteratorTests.res", + 67, + 20, + 54 + ], + "Creating your own async iterator" +], asyncResult$1.contents, eq, "done"); export { - eq , - iterator , - syncResult , - asyncResult , + eq, + iterator, + syncResult, + asyncResult, asyncIterator$1 as asyncIterator, } /* iterator Not a pure module */ diff --git a/tests/tests/src/core/Core_JsonTests.mjs b/tests/tests/src/core/Core_JsonTests.mjs index ab1b95c9ef..8898a2d2b0 100644 --- a/tests/tests/src/core/Core_JsonTests.mjs +++ b/tests/tests/src/core/Core_JsonTests.mjs @@ -3,20 +3,20 @@ import * as Test from "./Test.mjs"; function decodeJsonTest() { - var json = {"someProp":{"otherProp": null, "thirdProp": [true, false]}}; - var decodedCorrectly; + let json = {"someProp":{"otherProp": null, "thirdProp": [true, false]}}; + let decodedCorrectly; if (!Array.isArray(json) && (json === null || typeof json !== "object") && typeof json !== "number" && typeof json !== "string" && typeof json !== "boolean" || !(typeof json === "object" && !Array.isArray(json))) { decodedCorrectly = false; } else { - var match = json["someProp"]; + let match = json["someProp"]; if (match !== undefined && !(!Array.isArray(match) && (match === null || typeof match !== "object") && typeof match !== "number" && typeof match !== "string" && typeof match !== "boolean" || !(typeof match === "object" && !Array.isArray(match)))) { - var match$1 = match["thirdProp"]; + let match$1 = match["thirdProp"]; if (match$1 !== undefined && !(!Array.isArray(match$1) && (match$1 === null || typeof match$1 !== "object") && typeof match$1 !== "number" && typeof match$1 !== "string" && typeof match$1 !== "boolean" || !(Array.isArray(match$1) && match$1.length === 2))) { - var match$2 = match$1[0]; + let match$2 = match$1[0]; if (!Array.isArray(match$2) && (match$2 === null || typeof match$2 !== "object") && typeof match$2 !== "number" && typeof match$2 !== "string" && typeof match$2 !== "boolean" || !(typeof match$2 === "boolean" && match$2)) { decodedCorrectly = false; } else { - var match$3 = match$1[1]; + let match$3 = match$1[1]; decodedCorrectly = !Array.isArray(match$3) && (match$3 === null || typeof match$3 !== "object") && typeof match$3 !== "number" && typeof match$3 !== "string" && typeof match$3 !== "boolean" || !(typeof match$3 === "boolean" && !match$3) ? false : true; } } else { @@ -27,21 +27,19 @@ function decodeJsonTest() { } } Test.run([ - [ - "JsonTests.res", - 19, - 22, - 55 - ], - "Should decode JSON successfully" - ], decodedCorrectly, (function (prim0, prim1) { - return prim0 === prim1; - }), true); + [ + "Core_JsonTests.res", + 17, + 22, + 55 + ], + "Should decode JSON successfully" + ], decodedCorrectly, (prim0, prim1) => prim0 === prim1, true); } decodeJsonTest(); export { - decodeJsonTest , + decodeJsonTest, } /* Not a pure module */ diff --git a/tests/tests/src/core/Core_NullableTests.mjs b/tests/tests/src/core/Core_NullableTests.mjs index 70100f2425..072aa64f28 100644 --- a/tests/tests/src/core/Core_NullableTests.mjs +++ b/tests/tests/src/core/Core_NullableTests.mjs @@ -3,53 +3,47 @@ import * as Test from "./Test.mjs"; function shouldHandleNullableValues() { - var tNull = null; - var tUndefined = undefined; - var tValue = "hello"; - var tmp; + let tNull = null; + let tUndefined = undefined; + let tValue = "hello"; + let tmp; tmp = (tNull === null || tNull === undefined) && tNull === null ? true : false; Test.run([ - [ - "NullableTests.res", - 9, - 15, - 35 - ], - "Should handle null" - ], tmp, (function (prim0, prim1) { - return prim0 === prim1; - }), true); - var tmp$1; + [ + "Core_NullableTests.res", + 7, + 15, + 35 + ], + "Should handle null" + ], tmp, (prim0, prim1) => prim0 === prim1, true); + let tmp$1; tmp$1 = (tUndefined === null || tUndefined === undefined) && tUndefined !== null ? true : false; Test.run([ - [ - "NullableTests.res", - 19, - 15, - 40 - ], - "Should handle undefined" - ], tmp$1, (function (prim0, prim1) { - return prim0 === prim1; - }), true); - var tmp$2; + [ + "Core_NullableTests.res", + 17, + 15, + 40 + ], + "Should handle undefined" + ], tmp$1, (prim0, prim1) => prim0 === prim1, true); + let tmp$2; tmp$2 = tValue === null || tValue === undefined || tValue !== "hello" ? false : true; Test.run([ - [ - "NullableTests.res", - 29, - 15, - 36 - ], - "Should handle value" - ], tmp$2, (function (prim0, prim1) { - return prim0 === prim1; - }), true); + [ + "Core_NullableTests.res", + 27, + 15, + 36 + ], + "Should handle value" + ], tmp$2, (prim0, prim1) => prim0 === prim1, true); } shouldHandleNullableValues(); export { - shouldHandleNullableValues , + shouldHandleNullableValues, } /* Not a pure module */ diff --git a/tests/tests/src/core/Core_ObjectTests.mjs b/tests/tests/src/core/Core_ObjectTests.mjs index fd6355a2ef..78b3c4fb32 100644 --- a/tests/tests/src/core/Core_ObjectTests.mjs +++ b/tests/tests/src/core/Core_ObjectTests.mjs @@ -1,460 +1,460 @@ // Generated by ReScript, PLEASE EDIT WITH CARE import * as Test from "./Test.mjs"; -import * as Caml_obj from "rescript/lib/es6/caml_obj.js"; -import * as Core__Option from "../src/Core__Option.mjs"; - -var eq = Caml_obj.equal; - -Test.run([ - [ - "ObjectTests.res", - 12, - 20, - 30 - ], - "is: ints" - ], Object.is(25, 25), eq, true); - -Test.run([ - [ - "ObjectTests.res", - 14, - 20, - 33 - ], - "is: strings" - ], Object.is("abc", "abc"), eq, true); - -Test.run([ - [ - "ObjectTests.res", - 15, - 20, - 33 - ], - "is: strings" - ], Object.is("abc", "ABC"), eq, false); - -Test.run([ - [ - "ObjectTests.res", - 17, - 20, - 44 - ], - "is: null and undefined" - ], Object.is(null, undefined), eq, false); - -Test.run([ - [ - "ObjectTests.res", - 18, - 20, - 44 - ], - "is: null and undefined" - ], Object.is(undefined, undefined), eq, true); - -Test.run([ - [ - "ObjectTests.res", - 19, - 20, - 44 - ], - "is: null and undefined" - ], Object.is(null, null), eq, true); - -var nums = [ +import * as Option from "rescript/lib/es6/Option.js"; +import * as Primitive_object from "rescript/lib/es6/Primitive_object.js"; + +let eq = Primitive_object.equal; + +Test.run([ + [ + "Core_ObjectTests.res", + 10, + 20, + 30 + ], + "is: ints" +], Object.is(25, 25), eq, true); + +Test.run([ + [ + "Core_ObjectTests.res", + 12, + 20, + 33 + ], + "is: strings" +], Object.is("abc", "abc"), eq, true); + +Test.run([ + [ + "Core_ObjectTests.res", + 13, + 20, + 33 + ], + "is: strings" +], Object.is("abc", "ABC"), eq, false); + +Test.run([ + [ + "Core_ObjectTests.res", + 15, + 20, + 44 + ], + "is: null and undefined" +], Object.is(null, undefined), eq, false); + +Test.run([ + [ + "Core_ObjectTests.res", + 16, + 20, + 44 + ], + "is: null and undefined" +], Object.is(undefined, undefined), eq, true); + +Test.run([ + [ + "Core_ObjectTests.res", + 17, + 20, + 44 + ], + "is: null and undefined" +], Object.is(null, null), eq, true); + +let nums = [ 1, 2, 3 ]; Test.run([ - [ - "ObjectTests.res", - 22, - 20, - 32 - ], - "is: arrays" - ], Object.is([ - 1, - 2, - 3 - ], [ - 1, - 2, - 3 - ]), eq, false); - -Test.run([ - [ - "ObjectTests.res", - 23, - 20, - 32 - ], - "is: arrays" - ], Object.is(nums, nums), eq, true); - -Test.run([ - [ - "ObjectTests.res", - 24, - 20, - 32 - ], - "is: arrays" - ], Caml_obj.equal([ - 1, - 2, - 3 - ], [ - 1, - 2, - 3 - ]), eq, true); - -Test.run([ - [ - "ObjectTests.res", - 25, - 20, - 32 - ], - "is: arrays" - ], [ - 1, - 2, - 3 - ] === [ - 1, - 2, - 3 - ], eq, false); - -Test.run([ - [ - "ObjectTests.res", - 27, - 20, - 30 - ], - "is: list" - ], Object.is({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }, { - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }), eq, false); - -Test.run([ - [ - "ObjectTests.res", - 28, - 20, - 30 - ], - "is: list" - ], Caml_obj.equal({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }, { - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }), eq, true); - -Test.run([ - [ - "ObjectTests.res", - 29, - 20, - 30 - ], - "is: list" - ], ({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }) === ({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }), eq, false); - -var d = new Date(2000, 1); - -Test.run([ - [ - "ObjectTests.res", - 33, - 13, - 23 - ], - "is: date" - ], Object.is(new Date(2000, 1), new Date(2000, 1)), eq, false); - -Test.run([ - [ - "ObjectTests.res", - 38, - 20, - 30 - ], - "is: date" - ], Object.is(d, d), eq, true); - -var x = { + [ + "Core_ObjectTests.res", + 20, + 20, + 32 + ], + "is: arrays" +], Object.is([ + 1, + 2, + 3 +], [ + 1, + 2, + 3 +]), eq, false); + +Test.run([ + [ + "Core_ObjectTests.res", + 21, + 20, + 32 + ], + "is: arrays" +], Object.is(nums, nums), eq, true); + +Test.run([ + [ + "Core_ObjectTests.res", + 22, + 20, + 32 + ], + "is: arrays" +], Primitive_object.equal([ + 1, + 2, + 3 +], [ + 1, + 2, + 3 +]), eq, true); + +Test.run([ + [ + "Core_ObjectTests.res", + 23, + 20, + 32 + ], + "is: arrays" +], [ + 1, + 2, + 3 +] === [ + 1, + 2, + 3 +], eq, false); + +Test.run([ + [ + "Core_ObjectTests.res", + 25, + 20, + 30 + ], + "is: list" +], Object.is({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } +}, { + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } +}), eq, false); + +Test.run([ + [ + "Core_ObjectTests.res", + 26, + 20, + 30 + ], + "is: list" +], Primitive_object.equal({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } +}, { + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } +}), eq, true); + +Test.run([ + [ + "Core_ObjectTests.res", + 27, + 20, + 30 + ], + "is: list" +], ({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } +}) === ({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } +}), eq, false); + +let d = new Date(2000, 1); + +Test.run([ + [ + "Core_ObjectTests.res", + 31, + 13, + 23 + ], + "is: date" +], Object.is(new Date(2000, 1), new Date(2000, 1)), eq, false); + +Test.run([ + [ + "Core_ObjectTests.res", + 36, + 20, + 30 + ], + "is: date" +], Object.is(d, d), eq, true); + +let x = { a: 1 }; Test.run([ - [ - "ObjectTests.res", - 41, - 20, - 33 - ], - "is: objects" - ], Object.is(x, x), eq, true); - -Test.run([ - [ - "ObjectTests.res", - 42, - 20, - 33 - ], - "is: objects" - ], Object.is({ - a: 1 - }, { - a: 1 - }), eq, false); - -Test.run([ - [ - "ObjectTests.res", - 43, - 20, - 33 - ], - "is: objects" - ], Object.is({}, {}), eq, false); - -Test.run([ - [ - "ObjectTests.res", - 44, - 20, - 45 - ], - "is: === and == operator" - ], x === x, eq, true); - -Test.run([ - [ - "ObjectTests.res", - 45, - 20, - 45 - ], - "is: === and == operator" - ], Caml_obj.equal(x, x), eq, true); - -Test.run([ - [ - "ObjectTests.res", - 46, - 20, - 45 - ], - "is: === and == operator" - ], Caml_obj.equal({ - a: 1 - }, { - a: 1 - }), eq, true); - -Test.run([ - [ - "ObjectTests.res", - 48, - 20, - 31 - ], - "is: zeros" - ], Object.is(0, 0), eq, true); - -Test.run([ - [ - "ObjectTests.res", - 49, - 20, - 31 - ], - "is: zeros" - ], Object.is(-0.0, -0.0), eq, true); - -Test.run([ - [ - "ObjectTests.res", - 50, - 20, - 31 - ], - "is: zeros" - ], Object.is(0.0, -0.0), eq, false); + [ + "Core_ObjectTests.res", + 39, + 20, + 33 + ], + "is: objects" +], Object.is(x, x), eq, true); + +Test.run([ + [ + "Core_ObjectTests.res", + 40, + 20, + 33 + ], + "is: objects" +], Object.is({ + a: 1 +}, { + a: 1 +}), eq, false); + +Test.run([ + [ + "Core_ObjectTests.res", + 41, + 20, + 33 + ], + "is: objects" +], Object.is({}, {}), eq, false); + +Test.run([ + [ + "Core_ObjectTests.res", + 42, + 20, + 45 + ], + "is: === and == operator" +], x === x, eq, true); + +Test.run([ + [ + "Core_ObjectTests.res", + 43, + 20, + 45 + ], + "is: === and == operator" +], Primitive_object.equal(x, x), eq, true); + +Test.run([ + [ + "Core_ObjectTests.res", + 44, + 20, + 45 + ], + "is: === and == operator" +], Primitive_object.equal({ + a: 1 +}, { + a: 1 +}), eq, true); + +Test.run([ + [ + "Core_ObjectTests.res", + 46, + 20, + 31 + ], + "is: zeros" +], Object.is(0, 0), eq, true); + +Test.run([ + [ + "Core_ObjectTests.res", + 47, + 20, + 31 + ], + "is: zeros" +], Object.is(-0.0, -0.0), eq, true); + +Test.run([ + [ + "Core_ObjectTests.res", + 48, + 20, + 31 + ], + "is: zeros" +], Object.is(0.0, -0.0), eq, false); function mkBig(s) { return BigInt(s); } Test.run([ - [ - "ObjectTests.res", - 53, - 20, - 32 - ], - "is: bigint" - ], Object.is(BigInt("123456789"), BigInt("123456789")), eq, true); - -Test.run([ - [ - "ObjectTests.res", - 54, - 20, - 32 - ], - "is: bigint" - ], Object.is(BigInt("123489"), BigInt("123456789")), eq, false); - -Test.run([ - [ - "ObjectTests.res", - 55, - 20, - 32 - ], - "is: bigint" - ], Object.is(BigInt("000000000"), BigInt("0")), eq, true); - -Test.run([ - [ - "ObjectTests.res", - 56, - 20, - 32 - ], - "is: bigint" - ], BigInt("123") === BigInt("123"), eq, true); - -Test.run([ - [ - "ObjectTests.res", - 57, - 20, - 32 - ], - "is: bigint" - ], BigInt("123") === BigInt("123"), eq, true); - -Test.run([ - [ - "ObjectTests.res", - 62, - 13, - 50 - ], - "assign copies from source to target" - ], Object.assign({ - a: 1, - b: 2 - }, { - b: 3, - c: 0 - }), eq, { - a: 1, - b: 3, - c: 0 - }); + [ + "Core_ObjectTests.res", + 51, + 20, + 32 + ], + "is: bigint" +], Object.is(BigInt("123456789"), BigInt("123456789")), eq, true); + +Test.run([ + [ + "Core_ObjectTests.res", + 52, + 20, + 32 + ], + "is: bigint" +], Object.is(BigInt("123489"), BigInt("123456789")), eq, false); + +Test.run([ + [ + "Core_ObjectTests.res", + 53, + 20, + 32 + ], + "is: bigint" +], Object.is(BigInt("000000000"), BigInt("0")), eq, true); + +Test.run([ + [ + "Core_ObjectTests.res", + 54, + 20, + 32 + ], + "is: bigint" +], BigInt("123") === BigInt("123"), eq, true); + +Test.run([ + [ + "Core_ObjectTests.res", + 55, + 20, + 32 + ], + "is: bigint" +], BigInt("123") === BigInt("123"), eq, true); + +Test.run([ + [ + "Core_ObjectTests.res", + 60, + 13, + 50 + ], + "assign copies from source to target" +], Object.assign({ + a: 1, + b: 2 +}, { + b: 3, + c: 0 +}), eq, { + a: 1, + b: 3, + c: 0 +}); function assignOverwritesTarget(title, source) { - var sourceObj = { + let sourceObj = { a: source }; Test.run([ - [ - "ObjectTests.res", - 70, - 22, - 39 - ], - "assign " + title - ], Object.assign({ - a: 1 - }, sourceObj), eq, sourceObj); + [ + "Core_ObjectTests.res", + 68, + 22, + 39 + ], + "assign " + title + ], Object.assign({ + a: 1 + }, sourceObj), eq, sourceObj); Test.run([ - [ - "ObjectTests.res", - 71, - 22, - 39 - ], - "assign " + title - ], Object.assign({ - a: undefined - }, sourceObj), eq, sourceObj); + [ + "Core_ObjectTests.res", + 69, + 22, + 39 + ], + "assign " + title + ], Object.assign({ + a: undefined + }, sourceObj), eq, sourceObj); Test.run([ - [ - "ObjectTests.res", - 72, - 22, - 39 - ], - "assign " + title - ], Object.assign({ - a: null - }, sourceObj), eq, sourceObj); + [ + "Core_ObjectTests.res", + 70, + 22, + 39 + ], + "assign " + title + ], Object.assign({ + a: null + }, sourceObj), eq, sourceObj); } assignOverwritesTarget("when source is undefined", undefined); @@ -467,169 +467,143 @@ assignOverwritesTarget("when source is a string", "abc"); function runGetTest(i) { Test.run([ - [ - "ObjectTests.res", - 90, - 22, - 46 - ], - "Object.get: " + i.title - ], i.get(i.source()), eq, i.expected); + [ + "Core_ObjectTests.res", + 88, + 22, + 46 + ], + "Object.get: " + i.title + ], i.get(i.source()), eq, i.expected); } runGetTest({ - title: "prop exists, return Some", - source: (function () { - return { - a: 1 - }; - }), - get: (function (__x) { - return __x["a"]; - }), - expected: 1 - }); + title: "prop exists, return Some", + source: () => ({ + a: 1 + }), + get: __x => __x["a"], + expected: 1 +}); runGetTest({ - title: "prop NOT exist, return None", - source: (function () { - return { - a: 1 - }; - }), - get: (function (i) { - return i["banana"]; - }), - expected: undefined - }); + title: "prop NOT exist, return None", + source: () => ({ + a: 1 + }), + get: i => i["banana"], + expected: undefined +}); runGetTest({ - title: "prop like toString, return Some", - source: (function () { - return { - a: 1 - }; - }), - get: (function (i) { - return Core__Option.isSome(i["toString"]); - }), - expected: true - }); + title: "prop like toString, return Some", + source: () => ({ + a: 1 + }), + get: i => Option.isSome(i["toString"]), + expected: true +}); runGetTest({ - title: "prop exist but explicitly undefined, return None", - source: (function () { - return { - a: undefined - }; - }), - get: (function (i) { - return i["a"]; - }), - expected: undefined - }); + title: "prop exist but explicitly undefined, return None", + source: () => ({ + a: undefined + }), + get: i => i["a"], + expected: undefined +}); runGetTest({ - title: "prop exist but explicitly null, return None", - source: (function () { - return { - a: null - }; - }), - get: (function (i) { - return i["a"]; - }), - expected: null - }); + title: "prop exist but explicitly null, return None", + source: () => ({ + a: null + }), + get: i => i["a"], + expected: null +}); runGetTest({ - title: "prop exists and is an array, can get it", - source: (function () { - return { - a: [ - 1, - 2, - 3 - ] - }; - }), - get: (function (i) { - return Core__Option.getOr(Core__Option.map(i["a"], (function (i) { - return i.concat([ - 4, - 5 - ]); - })), []); - }), - expected: [ - 1, - 2, - 3, - 4, - 5 - ] - }); + title: "prop exists and is an array, can get it", + source: () => ({ + a: [ + 1, + 2, + 3 + ] + }), + get: i => Option.getOr(Option.map(i["a"], i => i.concat([ + 4, + 5 + ])), []), + expected: [ + 1, + 2, + 3, + 4, + 5 + ] +}); function getSymbolTestWhenExists() { - var obj = {}; - var fruit = Symbol("fruit"); + let obj = {}; + let fruit = Symbol("fruit"); obj[fruit] = "banana"; - var retrieved = obj[fruit]; + let retrieved = obj[fruit]; Test.run([ - [ - "ObjectTests.res", - 150, - 15, - 63 - ], - "Object.getSymbol when exists return it as Some" - ], retrieved, eq, "banana"); + [ + "Core_ObjectTests.res", + 148, + 15, + 63 + ], + "Object.getSymbol when exists return it as Some" + ], retrieved, eq, "banana"); } getSymbolTestWhenExists(); Test.run([ - [ - "ObjectTests.res", - 159, - 13, - 65 - ], - "Object.getSymbol when not exists return it as None" - ], ({})[Symbol("fruit")], eq, undefined); - -Test.run([ - [ - "ObjectTests.res", - 168, - 13, - 46 - ], - "Object.create clones properties" - ], Object.create({ - a: 1 - })["a"], eq, 1); - -Test.run([ - [ - "ObjectTests.res", - 175, - 13, - 46 - ], - "Object.create clones properties" - ], Object.create({ - a: 1 - })["b"], eq, undefined); + [ + "Core_ObjectTests.res", + 157, + 13, + 65 + ], + "Object.getSymbol when not exists return it as None" +], ({})[Symbol("fruit")], eq, undefined); + +Test.run([ + [ + "Core_ObjectTests.res", + 166, + 13, + 46 + ], + "Object.create clones properties" +], Object.create({ + a: 1 + })["a"], eq, 1); + +Test.run([ + [ + "Core_ObjectTests.res", + 173, + 13, + 46 + ], + "Object.create clones properties" +], Object.create({ + a: 1 + })["b"], eq, undefined); export { - eq , - nums , - d , - x , - mkBig , - assignOverwritesTarget , - runGetTest , - getSymbolTestWhenExists , + eq, + nums, + d, + x, + mkBig, + assignOverwritesTarget, + runGetTest, + getSymbolTestWhenExists, } /* Not a pure module */ diff --git a/tests/tests/src/core/Core_PromiseTest.mjs b/tests/tests/src/core/Core_PromiseTest.mjs index ffdb1df1d2..f054f6895c 100644 --- a/tests/tests/src/core/Core_PromiseTest.mjs +++ b/tests/tests/src/core/Core_PromiseTest.mjs @@ -1,108 +1,98 @@ // Generated by ReScript, PLEASE EDIT WITH CARE +import * as Exn from "rescript/lib/es6/Exn.js"; import * as Test from "./Test.mjs"; -import * as Js_exn from "rescript/lib/es6/js_exn.js"; -import * as Caml_obj from "rescript/lib/es6/caml_obj.js"; -import * as Core__Promise from "../src/Core__Promise.mjs"; -import * as Caml_exceptions from "rescript/lib/es6/caml_exceptions.js"; +import * as $$Promise from "rescript/lib/es6/Promise.js"; +import * as Primitive_object from "rescript/lib/es6/Primitive_object.js"; +import * as Primitive_exceptions from "rescript/lib/es6/Primitive_exceptions.js"; -var TestError = /* @__PURE__ */Caml_exceptions.create("PromiseTest.TestError"); +let TestError = /* @__PURE__ */Primitive_exceptions.create("Core_PromiseTest.TestError"); -var fail = Js_exn.raiseError; +let fail = Exn.raiseError; -var equal = Caml_obj.equal; +let equal = Primitive_object.equal; function resolveTest() { - Promise.resolve("test").then(function (str) { - Test.run([ - [ - "PromiseTest.res", - 19, - 26, - 47 - ], - "Should resolve test" - ], str, equal, "test"); - return Promise.resolve(); - }); + Promise.resolve("test").then(str => { + Test.run([ + [ + "Core_PromiseTest.res", + 17, + 26, + 47 + ], + "Should resolve test" + ], str, equal, "test"); + return Promise.resolve(); + }); } function runTests() { resolveTest(); } -var Creation = { +let Creation = { resolveTest: resolveTest, runTests: runTests }; function testThen() { - return Promise.resolve(1).then(function (first) { - return Promise.resolve(first + 1 | 0); - }).then(function (value) { - Test.run([ - [ - "PromiseTest.res", - 41, - 26, - 39 - ], - "Should be 2" - ], value, equal, 2); - return Promise.resolve(); - }); + return Promise.resolve(1).then(first => Promise.resolve(first + 1 | 0)).then(value => { + Test.run([ + [ + "Core_PromiseTest.res", + 39, + 26, + 39 + ], + "Should be 2" + ], value, equal, 2); + return Promise.resolve(); + }); } function testInvalidThen() { - return Promise.resolve(1).then(function (first) { - return Promise.resolve(Promise.resolve(first + 1 | 0)); - }).then(function (p) { - var isPromise = typeof p === "object"; - Test.run([ - [ - "PromiseTest.res", - 56, - 26, - 51 - ], - "Should not be a promise" - ], isPromise, equal, false); - return Promise.resolve(); - }); + return Promise.resolve(1).then(first => Promise.resolve(Promise.resolve(first + 1 | 0))).then(p => { + let isPromise = typeof p === "object"; + Test.run([ + [ + "Core_PromiseTest.res", + 54, + 26, + 51 + ], + "Should not be a promise" + ], isPromise, equal, false); + return Promise.resolve(); + }); } function testThenResolve() { - return Promise.resolve(1).then(function (num) { - return num + 1 | 0; - }).then(function (ret) { - Test.run([ - [ - "PromiseTest.res", - 69, - 26, - 39 - ], - "Should be 2" - ], ret, equal, 2); - }); + return Promise.resolve(1).then(num => num + 1 | 0).then(ret => Test.run([ + [ + "Core_PromiseTest.res", + 67, + 26, + 39 + ], + "Should be 2" + ], ret, equal, 2)); } function testInvalidThenResolve() { - return Promise.resolve(1).then(function (num) { - return Promise.resolve(num); - }).then(function (p) { - var isPromise = typeof p === "object"; - Test.run([ - [ - "PromiseTest.res", - 83, - 26, - 51 - ], - "Should not be a promise" - ], isPromise, equal, false); - return Promise.resolve(); - }); + return Promise.resolve(1).then(num => Promise.resolve(num)).then(p => { + let isPromise = typeof p === "object"; + Test.run([ + [ + "Core_PromiseTest.res", + 81, + 26, + 51 + ], + "Should not be a promise" + ], isPromise, equal, false); + return Promise.resolve(); + }); } function runTests$1() { @@ -112,7 +102,7 @@ function runTests$1() { testInvalidThenResolve(); } -var ThenChaining = { +let ThenChaining = { testThen: testThen, testInvalidThen: testInvalidThen, testThenResolve: testThenResolve, @@ -121,36 +111,36 @@ var ThenChaining = { }; function testExnRejection() { - Core__Promise.$$catch(Promise.reject({ - RE_EXN_ID: TestError, - _1: "oops" - }), (function (e) { - Test.run([ - [ - "PromiseTest.res", - 105, - 26, - 30 - ], - "Expect rejection to contain a TestError" - ], e, equal, { - RE_EXN_ID: TestError, - _1: "oops" - }); - return Promise.resolve(); - })); + $$Promise.$$catch(Promise.reject({ + RE_EXN_ID: TestError, + _1: "oops" + }), e => { + Test.run([ + [ + "Core_PromiseTest.res", + 103, + 26, + 30 + ], + "Expect rejection to contain a TestError" + ], e, equal, { + RE_EXN_ID: TestError, + _1: "oops" + }); + return Promise.resolve(); + }); } function runTests$2() { testExnRejection(); } -var Rejection = { +let Rejection = { testExnRejection: testExnRejection, runTests: runTests$2 }; -var asyncParseFail = (function() { +let asyncParseFail = (function() { return new Promise((resolve) => { var result = JSON.parse("{.."); return resolve(result); @@ -158,154 +148,140 @@ var asyncParseFail = (function() { }); function testExternalPromiseThrow() { - return Core__Promise.$$catch(asyncParseFail().then(function (param) { - return Promise.resolve(); - }), (function (e) { - var success = e.RE_EXN_ID === Js_exn.$$Error ? Caml_obj.equal(e._1.name, "SyntaxError") : false; - Test.run([ - [ - "PromiseTest.res", - 139, - 26, - 76 - ], - "Should be a parser error with Unexpected token ." - ], success, equal, true); - return Promise.resolve(); - })); + return $$Promise.$$catch(asyncParseFail().then(param => Promise.resolve()), e => { + let success = e.RE_EXN_ID === Exn.$$Error ? Primitive_object.equal(e._1.name, "SyntaxError") : false; + Test.run([ + [ + "Core_PromiseTest.res", + 137, + 26, + 76 + ], + "Should be a parser error with Unexpected token ." + ], success, equal, true); + return Promise.resolve(); + }); } function testExnThrow() { - return Core__Promise.$$catch(Promise.resolve().then(function () { - throw { - RE_EXN_ID: TestError, - _1: "Thrown exn", - Error: new Error() - }; - }), (function (e) { - var isTestErr = e.RE_EXN_ID === TestError && e._1 === "Thrown exn" ? true : false; - Test.run([ - [ - "PromiseTest.res", - 158, - 26, - 49 - ], - "Should be a TestError" - ], isTestErr, equal, true); - return Promise.resolve(); - })); + return $$Promise.$$catch(Promise.resolve().then(() => { + throw { + RE_EXN_ID: TestError, + _1: "Thrown exn", + Error: new Error() + }; + }), e => { + let isTestErr = e.RE_EXN_ID === TestError && e._1 === "Thrown exn" ? true : false; + Test.run([ + [ + "Core_PromiseTest.res", + 156, + 26, + 49 + ], + "Should be a TestError" + ], isTestErr, equal, true); + return Promise.resolve(); + }); } function testRaiseErrorThrow() { - return Core__Promise.$$catch(Promise.resolve().then(function () { - return Js_exn.raiseError("Some JS error"); - }), (function (e) { - var isTestErr = e.RE_EXN_ID === Js_exn.$$Error ? Caml_obj.equal(e._1.message, "Some JS error") : false; - Test.run([ - [ - "PromiseTest.res", - 181, - 26, - 51 - ], - "Should be some JS error" - ], isTestErr, equal, true); - return Promise.resolve(); - })); + return $$Promise.$$catch(Promise.resolve().then(() => Exn.raiseError("Some JS error")), e => { + let isTestErr = e.RE_EXN_ID === Exn.$$Error ? Primitive_object.equal(e._1.message, "Some JS error") : false; + Test.run([ + [ + "Core_PromiseTest.res", + 179, + 26, + 51 + ], + "Should be some JS error" + ], isTestErr, equal, true); + return Promise.resolve(); + }); } function thenAfterCatch() { - return Core__Promise.$$catch(Promise.resolve().then(function () { - return Promise.reject({ - RE_EXN_ID: TestError, - _1: "some rejected value" - }); - }), (function (e) { - var tmp; - tmp = e.RE_EXN_ID === TestError && e._1 === "some rejected value" ? "success" : "not a test error"; - return Promise.resolve(tmp); - })).then(function (msg) { - Test.run([ - [ - "PromiseTest.res", - 204, - 26, - 45 - ], - "Should be success" - ], msg, equal, "success"); - return Promise.resolve(); - }); + return $$Promise.$$catch(Promise.resolve().then(() => Promise.reject({ + RE_EXN_ID: TestError, + _1: "some rejected value" + })), e => { + let tmp; + tmp = e.RE_EXN_ID === TestError && e._1 === "some rejected value" ? "success" : "not a test error"; + return Promise.resolve(tmp); + }).then(msg => { + Test.run([ + [ + "Core_PromiseTest.res", + 202, + 26, + 45 + ], + "Should be success" + ], msg, equal, "success"); + return Promise.resolve(); + }); } function testCatchFinally() { - var wasCalled = { + let wasCalled = { contents: false }; - Core__Promise.$$catch(Promise.resolve(5).then(function (param) { - return Promise.reject({ - RE_EXN_ID: TestError, - _1: "test" - }); - }).then(function (v) { - return Promise.resolve(v); - }), (function (param) { - return Promise.resolve(); - })).finally(function () { - wasCalled.contents = true; - }).then(function (v) { - Test.run([ - [ - "PromiseTest.res", - 226, - 26, - 48 - ], - "value should be unit" - ], v, equal, undefined); - Test.run([ - [ - "PromiseTest.res", - 227, - 26, - 59 - ], - "finally should have been called" - ], wasCalled.contents, equal, true); - return Promise.resolve(); - }); + $$Promise.$$catch(Promise.resolve(5).then(param => Promise.reject({ + RE_EXN_ID: TestError, + _1: "test" + })).then(v => Promise.resolve(v)), param => Promise.resolve()).finally(() => { + wasCalled.contents = true; + }).then(v => { + Test.run([ + [ + "Core_PromiseTest.res", + 224, + 26, + 48 + ], + "value should be unit" + ], v, equal, undefined); + Test.run([ + [ + "Core_PromiseTest.res", + 225, + 26, + 59 + ], + "finally should have been called" + ], wasCalled.contents, equal, true); + return Promise.resolve(); + }); } function testResolveFinally() { - var wasCalled = { + let wasCalled = { contents: false }; - Promise.resolve(5).then(function (v) { - return Promise.resolve(v + 5 | 0); - }).finally(function () { - wasCalled.contents = true; - }).then(function (v) { - Test.run([ - [ - "PromiseTest.res", - 244, - 26, - 45 - ], - "value should be 5" - ], v, equal, 10); - Test.run([ - [ - "PromiseTest.res", - 245, - 26, - 59 - ], - "finally should have been called" - ], wasCalled.contents, equal, true); - return Promise.resolve(); - }); + Promise.resolve(5).then(v => Promise.resolve(v + 5 | 0)).finally(() => { + wasCalled.contents = true; + }).then(v => { + Test.run([ + [ + "Core_PromiseTest.res", + 242, + 26, + 45 + ], + "value should be 5" + ], v, equal, 10); + Test.run([ + [ + "Core_PromiseTest.res", + 243, + 26, + 59 + ], + "finally should have been called" + ], wasCalled.contents, equal, true); + return Promise.resolve(); + }); } function runTests$3() { @@ -317,7 +293,7 @@ function runTests$3() { testResolveFinally(); } -var Catching = { +let Catching = { asyncParseFail: asyncParseFail, testExternalPromiseThrow: testExternalPromiseThrow, testExnThrow: testExnThrow, @@ -329,355 +305,339 @@ var Catching = { }; function testParallel() { - var place = { + let place = { contents: 0 }; - var delayedMsg = function (ms, msg) { - return new Promise((function (resolve, param) { - setTimeout((function () { - place.contents = place.contents + 1 | 0; - resolve([ - place.contents, - msg - ]); - }), ms); - })); - }; - var p1 = delayedMsg(1000, "is Anna"); - var p2 = delayedMsg(500, "myName"); - var p3 = delayedMsg(100, "Hi"); + let delayedMsg = (ms, msg) => new Promise((resolve, param) => { + setTimeout(() => { + place.contents = place.contents + 1 | 0; + resolve([ + place.contents, + msg + ]); + }, ms); + }); + let p1 = delayedMsg(1000, "is Anna"); + let p2 = delayedMsg(500, "myName"); + let p3 = delayedMsg(100, "Hi"); return Promise.all([ - p1, - p2, - p3 - ]).then(function (arr) { - var exp = [ - [ - 3, - "is Anna" - ], - [ - 2, - "myName" - ], - [ - 1, - "Hi" - ] - ]; - Test.run([ - [ - "PromiseTest.res", - 282, - 26, - 55 - ], - "Should have correct placing" - ], arr, equal, exp); - return Promise.resolve(); - }); + p1, + p2, + p3 + ]).then(arr => { + let exp = [ + [ + 3, + "is Anna" + ], + [ + 2, + "myName" + ], + [ + 1, + "Hi" + ] + ]; + Test.run([ + [ + "Core_PromiseTest.res", + 280, + 26, + 55 + ], + "Should have correct placing" + ], arr, equal, exp); + return Promise.resolve(); + }); } function testRace() { - var racer = function (ms, name) { - return new Promise((function (resolve, param) { - setTimeout((function () { - resolve(name); - }), ms); - })); - }; - var promises = [ + let racer = (ms, name) => new Promise((resolve, param) => { + setTimeout(() => resolve(name), ms); + }); + let promises = [ racer(1000, "Turtle"), racer(500, "Hare"), racer(100, "Eagle") ]; - return Promise.race(promises).then(function (winner) { - Test.run([ - [ - "PromiseTest.res", - 301, - 26, - 44 - ], - "Eagle should win" - ], winner, equal, "Eagle"); - return Promise.resolve(); - }); + return Promise.race(promises).then(winner => { + Test.run([ + [ + "Core_PromiseTest.res", + 299, + 26, + 44 + ], + "Eagle should win" + ], winner, equal, "Eagle"); + return Promise.resolve(); + }); } function testParallel2() { - var place = { + let place = { contents: 0 }; - var delayedMsg = function (ms, msg) { - return new Promise((function (resolve, param) { - setTimeout((function () { - place.contents = place.contents + 1 | 0; - resolve([ - place.contents, - msg - ]); - }), ms); - })); - }; - var p1 = delayedMsg(1000, "is Anna"); - var p2 = delayedMsg(500, "myName"); + let delayedMsg = (ms, msg) => new Promise((resolve, param) => { + setTimeout(() => { + place.contents = place.contents + 1 | 0; + resolve([ + place.contents, + msg + ]); + }, ms); + }); + let p1 = delayedMsg(1000, "is Anna"); + let p2 = delayedMsg(500, "myName"); return Promise.all([ - p1, - p2 - ]).then(function (arr) { - Test.run([ - [ - "PromiseTest.res", - 325, - 26, - 55 - ], - "Should have correct placing" - ], arr, equal, [ - [ - 2, - "is Anna" - ], - [ - 1, - "myName" - ] - ]); - return Promise.resolve(); - }); + p1, + p2 + ]).then(arr => { + Test.run([ + [ + "Core_PromiseTest.res", + 323, + 26, + 55 + ], + "Should have correct placing" + ], arr, equal, [ + [ + 2, + "is Anna" + ], + [ + 1, + "myName" + ] + ]); + return Promise.resolve(); + }); } function testParallel3() { - var place = { + let place = { contents: 0 }; - var delayedMsg = function (ms, msg) { - return new Promise((function (resolve, param) { - setTimeout((function () { - place.contents = place.contents + 1 | 0; - resolve([ - place.contents, - msg - ]); - }), ms); - })); - }; - var p1 = delayedMsg(1000, "is Anna"); - var p2 = delayedMsg(500, "myName"); - var p3 = delayedMsg(100, "Hi"); + let delayedMsg = (ms, msg) => new Promise((resolve, param) => { + setTimeout(() => { + place.contents = place.contents + 1 | 0; + resolve([ + place.contents, + msg + ]); + }, ms); + }); + let p1 = delayedMsg(1000, "is Anna"); + let p2 = delayedMsg(500, "myName"); + let p3 = delayedMsg(100, "Hi"); return Promise.all([ - p1, - p2, - p3 - ]).then(function (arr) { - Test.run([ - [ - "PromiseTest.res", - 350, - 26, - 55 - ], - "Should have correct placing" - ], arr, equal, [ - [ - 3, - "is Anna" - ], - [ - 2, - "myName" - ], - [ - 1, - "Hi" - ] - ]); - return Promise.resolve(); - }); + p1, + p2, + p3 + ]).then(arr => { + Test.run([ + [ + "Core_PromiseTest.res", + 348, + 26, + 55 + ], + "Should have correct placing" + ], arr, equal, [ + [ + 3, + "is Anna" + ], + [ + 2, + "myName" + ], + [ + 1, + "Hi" + ] + ]); + return Promise.resolve(); + }); } function testParallel4() { - var place = { + let place = { contents: 0 }; - var delayedMsg = function (ms, msg) { - return new Promise((function (resolve, param) { - setTimeout((function () { - place.contents = place.contents + 1 | 0; - resolve([ - place.contents, - msg - ]); - }), ms); - })); - }; - var p1 = delayedMsg(1500, "Anna"); - var p2 = delayedMsg(1000, "is"); - var p3 = delayedMsg(500, "my name"); - var p4 = delayedMsg(100, "Hi"); + let delayedMsg = (ms, msg) => new Promise((resolve, param) => { + setTimeout(() => { + place.contents = place.contents + 1 | 0; + resolve([ + place.contents, + msg + ]); + }, ms); + }); + let p1 = delayedMsg(1500, "Anna"); + let p2 = delayedMsg(1000, "is"); + let p3 = delayedMsg(500, "my name"); + let p4 = delayedMsg(100, "Hi"); return Promise.all([ - p1, - p2, - p3, - p4 - ]).then(function (arr) { - Test.run([ - [ - "PromiseTest.res", - 376, - 26, - 55 - ], - "Should have correct placing" - ], arr, equal, [ - [ - 4, - "Anna" - ], - [ - 3, - "is" - ], - [ - 2, - "my name" - ], - [ - 1, - "Hi" - ] - ]); - return Promise.resolve(); - }); + p1, + p2, + p3, + p4 + ]).then(arr => { + Test.run([ + [ + "Core_PromiseTest.res", + 374, + 26, + 55 + ], + "Should have correct placing" + ], arr, equal, [ + [ + 4, + "Anna" + ], + [ + 3, + "is" + ], + [ + 2, + "my name" + ], + [ + 1, + "Hi" + ] + ]); + return Promise.resolve(); + }); } function testParallel5() { - var place = { + let place = { contents: 0 }; - var delayedMsg = function (ms, msg) { - return new Promise((function (resolve, param) { - setTimeout((function () { - place.contents = place.contents + 1 | 0; - resolve([ - place.contents, - msg - ]); - }), ms); - })); - }; - var p1 = delayedMsg(1500, "Anna"); - var p2 = delayedMsg(1000, "is"); - var p3 = delayedMsg(500, "name"); - var p4 = delayedMsg(100, "my"); - var p5 = delayedMsg(50, "Hi"); + let delayedMsg = (ms, msg) => new Promise((resolve, param) => { + setTimeout(() => { + place.contents = place.contents + 1 | 0; + resolve([ + place.contents, + msg + ]); + }, ms); + }); + let p1 = delayedMsg(1500, "Anna"); + let p2 = delayedMsg(1000, "is"); + let p3 = delayedMsg(500, "name"); + let p4 = delayedMsg(100, "my"); + let p5 = delayedMsg(50, "Hi"); return Promise.all([ - p1, - p2, - p3, - p4, - p5 - ]).then(function (arr) { - Test.run([ - [ - "PromiseTest.res", - 403, - 26, - 55 - ], - "Should have correct placing" - ], arr, equal, [ - [ - 5, - "Anna" - ], - [ - 4, - "is" - ], - [ - 3, - "name" - ], - [ - 2, - "my" - ], - [ - 1, - "Hi" - ] - ]); - return Promise.resolve(); - }); + p1, + p2, + p3, + p4, + p5 + ]).then(arr => { + Test.run([ + [ + "Core_PromiseTest.res", + 401, + 26, + 55 + ], + "Should have correct placing" + ], arr, equal, [ + [ + 5, + "Anna" + ], + [ + 4, + "is" + ], + [ + 3, + "name" + ], + [ + 2, + "my" + ], + [ + 1, + "Hi" + ] + ]); + return Promise.resolve(); + }); } function testParallel6() { - var place = { + let place = { contents: 0 }; - var delayedMsg = function (ms, msg) { - return new Promise((function (resolve, param) { - setTimeout((function () { - place.contents = place.contents + 1 | 0; - resolve([ - place.contents, - msg - ]); - }), ms); - })); - }; - var p1 = delayedMsg(1500, "Anna"); - var p2 = delayedMsg(1000, "is"); - var p3 = delayedMsg(500, "name"); - var p4 = delayedMsg(100, "my"); - var p5 = delayedMsg(50, ", "); - var p6 = delayedMsg(10, "Hi"); + let delayedMsg = (ms, msg) => new Promise((resolve, param) => { + setTimeout(() => { + place.contents = place.contents + 1 | 0; + resolve([ + place.contents, + msg + ]); + }, ms); + }); + let p1 = delayedMsg(1500, "Anna"); + let p2 = delayedMsg(1000, "is"); + let p3 = delayedMsg(500, "name"); + let p4 = delayedMsg(100, "my"); + let p5 = delayedMsg(50, ", "); + let p6 = delayedMsg(10, "Hi"); return Promise.all([ - p1, - p2, - p3, - p4, - p5, - p6 - ]).then(function (arr) { - Test.run([ - [ - "PromiseTest.res", - 431, - 26, - 55 - ], - "Should have correct placing" - ], arr, equal, [ - [ - 6, - "Anna" - ], - [ - 5, - "is" - ], - [ - 4, - "name" - ], - [ - 3, - "my" - ], - [ - 2, - ", " - ], - [ - 1, - "Hi" - ] - ]); - return Promise.resolve(); - }); + p1, + p2, + p3, + p4, + p5, + p6 + ]).then(arr => { + Test.run([ + [ + "Core_PromiseTest.res", + 429, + 26, + 55 + ], + "Should have correct placing" + ], arr, equal, [ + [ + 6, + "Anna" + ], + [ + 5, + "is" + ], + [ + 4, + "name" + ], + [ + 3, + "my" + ], + [ + 2, + ", " + ], + [ + 1, + "Hi" + ] + ]); + return Promise.resolve(); + }); } function runTests$4() { @@ -690,7 +650,7 @@ function runTests$4() { testParallel6(); } -var Concurrently = { +let Concurrently = { testParallel: testParallel, testRace: testRace, testParallel2: testParallel2, @@ -712,13 +672,13 @@ runTests$3(); runTests$4(); export { - TestError , - fail , - equal , - Creation , - ThenChaining , - Rejection , - Catching , - Concurrently , + TestError, + fail, + equal, + Creation, + ThenChaining, + Rejection, + Catching, + Concurrently, } /* Not a pure module */ diff --git a/tests/tests/src/core/Core_ResultTests.mjs b/tests/tests/src/core/Core_ResultTests.mjs index a191b78440..1179e2210e 100644 --- a/tests/tests/src/core/Core_ResultTests.mjs +++ b/tests/tests/src/core/Core_ResultTests.mjs @@ -1,96 +1,92 @@ // Generated by ReScript, PLEASE EDIT WITH CARE import * as Test from "./Test.mjs"; -import * as Caml_obj from "rescript/lib/es6/caml_obj.js"; -import * as Core__Result from "../src/Core__Result.mjs"; +import * as Result from "rescript/lib/es6/Result.js"; +import * as Primitive_object from "rescript/lib/es6/Primitive_object.js"; -var eq = Caml_obj.equal; +let eq = Primitive_object.equal; function forEachIfOkCallFunction() { - var called = { + let called = { contents: [] }; - Core__Result.forEach({ - TAG: "Ok", - _0: 3 - }, (function (i) { - called.contents.push(i); - })); + Result.forEach({ + TAG: "Ok", + _0: 3 + }, i => { + called.contents.push(i); + }); Test.run([ - [ - "ResultTests.res", - 12, - 22, - 72 - ], - "forEach: if ok, call function with ok value once" - ], called.contents, eq, [3]); + [ + "Core_ResultTests.res", + 10, + 22, + 72 + ], + "forEach: if ok, call function with ok value once" + ], called.contents, eq, [3]); } forEachIfOkCallFunction(); function forEachIfErrorDoNotCallFunction() { - var called = { + let called = { contents: [] }; - Core__Result.forEach({ - TAG: "Error", - _0: 3 - }, (function (i) { - called.contents.push(i); - })); + Result.forEach({ + TAG: "Error", + _0: 3 + }, i => { + called.contents.push(i); + }); Test.run([ - [ - "ResultTests.res", - 19, - 22, - 63 - ], - "forEach: if error, do not call function" - ], called.contents, eq, []); + [ + "Core_ResultTests.res", + 17, + 22, + 63 + ], + "forEach: if error, do not call function" + ], called.contents, eq, []); } forEachIfErrorDoNotCallFunction(); Test.run([ - [ - "ResultTests.res", - 27, - 20, - 48 - ], - "mapError: if ok, return it" - ], Core__Result.mapError({ - TAG: "Ok", - _0: 5 - }, (function (i) { - return Math.imul(i, 3); - })), eq, { - TAG: "Ok", - _0: 5 - }); + [ + "Core_ResultTests.res", + 25, + 20, + 48 + ], + "mapError: if ok, return it" +], Result.mapError({ + TAG: "Ok", + _0: 5 +}, i => Math.imul(i, 3)), eq, { + TAG: "Ok", + _0: 5 +}); Test.run([ - [ - "ResultTests.res", - 30, - 13, - 42 - ], - "mapError: if error, apply f" - ], Core__Result.mapError({ - TAG: "Error", - _0: 5 - }, (function (i) { - return Math.imul(i, 3); - })), eq, { - TAG: "Error", - _0: 15 - }); + [ + "Core_ResultTests.res", + 28, + 13, + 42 + ], + "mapError: if error, apply f" +], Result.mapError({ + TAG: "Error", + _0: 5 +}, i => Math.imul(i, 3)), eq, { + TAG: "Error", + _0: 15 +}); export { - eq , - forEachIfOkCallFunction , - forEachIfErrorDoNotCallFunction , + eq, + forEachIfOkCallFunction, + forEachIfErrorDoNotCallFunction, } /* Not a pure module */ diff --git a/tests/tests/src/core/Core_StringTests.mjs b/tests/tests/src/core/Core_StringTests.mjs index 9bb621669b..bbdcc0fa0b 100644 --- a/tests/tests/src/core/Core_StringTests.mjs +++ b/tests/tests/src/core/Core_StringTests.mjs @@ -1,21 +1,21 @@ // Generated by ReScript, PLEASE EDIT WITH CARE import * as Test from "./Test.mjs"; -import * as Caml_obj from "rescript/lib/es6/caml_obj.js"; +import * as Primitive_object from "rescript/lib/es6/Primitive_object.js"; -var eq = Caml_obj.equal; +let eq = Primitive_object.equal; Test.run([ - [ - "StringTests.res", - 5, - 20, - 47 - ], - "String.equal optimization" - ], false, eq, false); + [ + "Core_StringTests.res", + 3, + 20, + 47 + ], + "String.equal optimization" +], false, eq, false); export { - eq , + eq, } /* Not a pure module */ diff --git a/tests/tests/src/core/Core_TempTests.mjs b/tests/tests/src/core/Core_TempTests.mjs index 2506594be3..4478b1d59e 100644 --- a/tests/tests/src/core/Core_TempTests.mjs +++ b/tests/tests/src/core/Core_TempTests.mjs @@ -1,15 +1,15 @@ // Generated by ReScript, PLEASE EDIT WITH CARE -import * as Core__Int from "../src/Core__Int.mjs"; -import * as IntlTests from "./intl/IntlTests.mjs"; -import * as Core__Dict from "../src/Core__Dict.mjs"; -import * as Core__JSON from "../src/Core__JSON.mjs"; -import * as Caml_bigint from "rescript/lib/es6/caml_bigint.js"; -import * as Caml_option from "rescript/lib/es6/caml_option.js"; -import * as Core__Array from "../src/Core__Array.mjs"; -import * as Core__Float from "../src/Core__Float.mjs"; -import * as Core__BigInt from "../src/Core__BigInt.mjs"; -import * as Core__Option from "../src/Core__Option.mjs"; +import * as Int from "rescript/lib/es6/Int.js"; +import * as Dict from "rescript/lib/es6/Dict.js"; +import * as $$JSON from "rescript/lib/es6/JSON.js"; +import * as $$Array from "rescript/lib/es6/Array.js"; +import * as Float from "rescript/lib/es6/Float.js"; +import * as $$BigInt from "rescript/lib/es6/BigInt.js"; +import * as Option from "rescript/lib/es6/Option.js"; +import * as Core_IntlTests from "./intl/Core_IntlTests.mjs"; +import * as Primitive_bigint from "rescript/lib/es6/Primitive_bigint.js"; +import * as Primitive_option from "rescript/lib/es6/Primitive_option.js"; console.info(""); @@ -17,18 +17,14 @@ console.info("Array"); console.info("---"); -var array = [ +let array = [ 1, 2, 3, 4 ]; -console.info(Core__Array.reduce(array.map(function (x) { - return (x << 1); - }), 0, (function (a, b) { - return a + b | 0; - }))); +console.info($$Array.reduce(array.map(x => (x << 1)), 0, (a, b) => a + b | 0)); console.info(typeof array); @@ -38,7 +34,7 @@ console.info("Date"); console.info("---"); -var date = new Date(Date.UTC(2020, 11)); +let date = new Date(Date.UTC(2020, 11)); console.log(date.toUTCString()); @@ -48,13 +44,13 @@ console.info("Dict"); console.info("---"); -var dict = {}; +let dict = {}; dict["foo"] = "bar"; -var dict2 = Object.assign({}, dict); +let dict2 = Object.assign({}, dict); -Core__Dict.$$delete(dict2, "foo"); +Dict.$$delete(dict2, "foo"); console.log(dict, dict2); @@ -65,18 +61,18 @@ console.info("Error"); console.info("---"); function f() { - var error = new Error("hello"); - var typeError = new TypeError("error"); - var g = function () { + let error = new Error("hello"); + let typeError = new TypeError("error"); + let g = () => { throw error; }; - var h = function () { + let h = () => { throw typeError; }; return [ - g, - h - ]; + g, + h + ]; } console.info(""); @@ -89,9 +85,9 @@ console.log((10.2).toFixed(2)); console.log((10).toFixed(2)); -console.log(Core__Int.fromString("0", undefined)); +console.log(Int.fromString("0", undefined)); -console.log(Core__Float.fromString("0.1")); +console.log(Float.fromString("0.1")); console.info(""); @@ -99,16 +95,16 @@ console.info("JSON"); console.info("---"); -var json = JSON.parse("{\"foo\": \"bar\"}"); +let json = JSON.parse("{\"foo\": \"bar\"}"); -var json$1 = Core__JSON.Classify.classify(json); +let json$1 = $$JSON.Classify.classify(json); -var tmp; +let tmp; if (typeof json$1 !== "object" || json$1.TAG !== "Object") { tmp = undefined; } else { - var value = Core__JSON.Classify.classify(json$1._0["foo"]); + let value = $$JSON.Classify.classify(json$1._0["foo"]); tmp = typeof value !== "object" || value.TAG !== "String" ? undefined : value._0; } @@ -120,7 +116,7 @@ console.info("Map"); console.info("---"); -var map = new Map(); +let map = new Map(); map.set(1, 1); @@ -144,7 +140,7 @@ console.info("BigInt"); console.info("---"); -console.log(Caml_bigint.div(BigInt(1), BigInt(12.0))); +console.log(Primitive_bigint.div(BigInt(1), BigInt(12.0))); console.info(""); @@ -152,31 +148,31 @@ console.info("Object"); console.info("---"); -var myObject = { +let myObject = { foo: "bar" }; console.log(Object.create(myObject)); console.log(Object.create(myObject, { - foo: { - value: "bar" - } - })); + foo: { + value: "bar" + } +})); console.log(Object.create(null)); console.log(Object.create(null, { - foo: { - value: "bar" - } - })); + foo: { + value: "bar" + } +})); -var copy = Object.assign({}, myObject); +let copy = Object.assign({}, myObject); -var withNewProp = Object.assign(copy, { - bar: "baz" - }); +let withNewProp = Object.assign(copy, { + bar: "baz" +}); console.info(""); @@ -184,22 +180,16 @@ console.info("Promise"); console.info("---"); -var promise = new Promise((function (resolve, _reject) { - setTimeout((function () { - resolve(1); - }), 100); - })); - -promise.then(function (x) { - return Promise.resolve(x + 1 | 0); - }).then(function (x) { - return Promise.resolve(x + 2 | 0); - }).then(function (x) { - console.log(x); - return Promise.resolve(); - }).finally(function () { - console.log("Promise finally"); - }); +let promise = new Promise((resolve, _reject) => { + setTimeout(() => resolve(1), 100); +}); + +promise.then(x => Promise.resolve(x + 1 | 0)).then(x => Promise.resolve(x + 2 | 0)).then(x => { + console.log(x); + return Promise.resolve(); +}).finally(() => { + console.log("Promise finally"); +}); console.info(""); @@ -207,27 +197,21 @@ console.info("RegExp"); console.info("---"); -var regex = new RegExp("hello(\\w+)"); +let regex = new RegExp("hello(\\w+)"); -var string = "helloworld"; +let string = "helloworld"; console.log(regex.test(string)); -var result = regex.exec(string); +let result = regex.exec(string); -var result$1 = (result == null) ? undefined : Caml_option.some(result); +let result$1 = (result == null) ? undefined : Primitive_option.some(result); -console.log(Core__Option.map(result$1, (function (prim) { - return prim.input; - }))); +console.log(Option.map(result$1, prim => prim.input)); -console.log(Core__Option.map(result$1, (function (prim) { - return prim.index; - }))); +console.log(Option.map(result$1, prim => prim.index)); -console.log(Core__Option.map(result$1, (function (prim) { - return prim.slice(1); - }))); +console.log(Option.map(result$1, prim => prim.slice(1))); console.info(""); @@ -235,7 +219,7 @@ console.info("Set"); console.info("---"); -var set = new Set(); +let set = new Set(); set.add(1); @@ -251,11 +235,9 @@ console.info("String"); console.info("---"); -var regexp = new RegExp("(hello )(world)"); +let regexp = new RegExp("(hello )(world)"); -console.log(" Hello world ".toLowerCase().trim().replace(regexp, (function (param, group1, group2, param$1, param$2) { - return group1 + group2.toUpperCase(); - }))); +console.log(" Hello world ".toLowerCase().trim().replace(regexp, (param, group1, group2, param$1, param$2) => group1 + group2.toUpperCase())); console.info(""); @@ -263,11 +245,11 @@ console.info("Symbol"); console.info("---"); -var x = Symbol.for("Foo"); +let x = Symbol.for("Foo"); console.log(x); -var array$1 = Array.from("foo"[Symbol.iterator]()); +let array$1 = Array.from("foo"[Symbol.iterator]()); console.log(array$1); @@ -279,9 +261,9 @@ console.info("---"); console.log("number"); -var timeout = setTimeout((function () { - console.log("Hello!"); - }), 100); +let timeout = setTimeout(() => { + console.log("Hello!"); +}, 100); clearTimeout(timeout); @@ -290,92 +272,92 @@ if (globalThis.hello !== undefined) { console.log("hello"); } -var z = 1.2 % 1.4; +let z = 1.2 % 1.4; -var intFromBigInt = Core__BigInt.toInt(BigInt("10000000000")); +let intFromBigInt = $$BigInt.toInt(BigInt("10000000000")); console.log({ - bar: "1" - }); + bar: "1" +}); -var Bugfix = {}; +let Bugfix = {}; -console.log(Core__Int.fromString("1231231", undefined)); +console.log(Int.fromString("1231231", undefined)); -console.log(Core__Int.fromString("12.22", undefined)); +console.log(Int.fromString("12.22", undefined)); -console.log(Core__Int.fromString("99999999999999999", undefined)); +console.log(Int.fromString("99999999999999999", undefined)); -console.log(Core__Int.fromString("99999999999999999", undefined)); +console.log(Int.fromString("99999999999999999", undefined)); -console.log(Core__Int.fromString("010101", 2)); +console.log(Int.fromString("010101", 2)); -var _collator = IntlTests._collator; +let _collator = Core_IntlTests._collator; -var collator = IntlTests.collator; +let collator = Core_IntlTests.collator; -var resolvedOptions = IntlTests.resolvedOptions; +let resolvedOptions = Core_IntlTests.resolvedOptions; -var timeZone = IntlTests.timeZone; +let timeZone = Core_IntlTests.timeZone; -var _locale = IntlTests._locale; +let _locale = Core_IntlTests._locale; -var locale = IntlTests.locale; +let locale = Core_IntlTests.locale; -var currencyFormatter = IntlTests.currencyFormatter; +let currencyFormatter = Core_IntlTests.currencyFormatter; -var roundingFormatter = IntlTests.roundingFormatter; +let roundingFormatter = Core_IntlTests.roundingFormatter; -var groupingFormatter1 = IntlTests.groupingFormatter1; +let groupingFormatter1 = Core_IntlTests.groupingFormatter1; -var groupingFormatter2 = IntlTests.groupingFormatter2; +let groupingFormatter2 = Core_IntlTests.groupingFormatter2; -var sigFormatter = IntlTests.sigFormatter; +let sigFormatter = Core_IntlTests.sigFormatter; -var options = IntlTests.options; +let options = Core_IntlTests.options; -var _formatter = IntlTests._formatter; +let _formatter = Core_IntlTests._formatter; -var formatter = IntlTests.formatter; +let formatter = Core_IntlTests.formatter; -var segments = IntlTests.segments; +let segments = Core_IntlTests.segments; export { - _collator , - collator , - resolvedOptions , - timeZone , - _locale , - locale , - currencyFormatter , - roundingFormatter , - groupingFormatter1 , - groupingFormatter2 , - sigFormatter , - options , - _formatter , - formatter , - segments , - date , - dict , - dict2 , - f , - json , - map , - myObject , - copy , - withNewProp , - promise , - regex , - string , + _collator, + collator, + resolvedOptions, + timeZone, + _locale, + locale, + currencyFormatter, + roundingFormatter, + groupingFormatter1, + groupingFormatter2, + sigFormatter, + options, + _formatter, + formatter, + segments, + date, + dict, + dict2, + f, + json, + map, + myObject, + copy, + withNewProp, + promise, + regex, + string, result$1 as result, - set , - regexp , - x , + set, + regexp, + x, array$1 as array, - timeout , - z , - intFromBigInt , - Bugfix , + timeout, + z, + intFromBigInt, + Bugfix, } /* Not a pure module */ diff --git a/tests/tests/src/core/Core_TestSuite.mjs b/tests/tests/src/core/Core_TestSuite.mjs index 00c9cb7d58..5cdea30649 100644 --- a/tests/tests/src/core/Core_TestSuite.mjs +++ b/tests/tests/src/core/Core_TestSuite.mjs @@ -1,121 +1,121 @@ // Generated by ReScript, PLEASE EDIT WITH CARE -import * as IntTests from "./IntTests.mjs"; -import * as DictTests from "./DictTests.mjs"; -import * as JsonTests from "./JsonTests.mjs"; -import * as TestTests from "./TestTests.mjs"; -import * as ArrayTests from "./ArrayTests.mjs"; -import * as ErrorTests from "./ErrorTests.mjs"; -import * as FloatTests from "./FloatTests.mjs"; -import * as ObjectTests from "./ObjectTests.mjs"; -import * as PromiseTest from "./PromiseTest.mjs"; -import * as ResultTests from "./ResultTests.mjs"; -import * as IteratorTests from "./IteratorTests.mjs"; -import * as NullableTests from "./NullableTests.mjs"; -import * as TypedArrayTests from "./TypedArrayTests.mjs"; +import * as Core_IntTests from "./Core_IntTests.mjs"; +import * as Core_DictTests from "./Core_DictTests.mjs"; +import * as Core_JsonTests from "./Core_JsonTests.mjs"; +import * as Core_TestTests from "./Core_TestTests.mjs"; +import * as Core_ArrayTests from "./Core_ArrayTests.mjs"; +import * as Core_ErrorTests from "./Core_ErrorTests.mjs"; +import * as Core_FloatTests from "./Core_FloatTests.mjs"; +import * as Core_ObjectTests from "./Core_ObjectTests.mjs"; +import * as Core_PromiseTest from "./Core_PromiseTest.mjs"; +import * as Core_ResultTests from "./Core_ResultTests.mjs"; +import * as Core_IteratorTests from "./Core_IteratorTests.mjs"; +import * as Core_NullableTests from "./Core_NullableTests.mjs"; +import * as Core_TypedArrayTests from "./Core_TypedArrayTests.mjs"; -var bign = TestTests.bign; +let bign = Core_TestTests.bign; -var TestError = PromiseTest.TestError; +let TestError = Core_PromiseTest.TestError; -var fail = PromiseTest.fail; +let fail = Core_PromiseTest.fail; -var equal = PromiseTest.equal; +let equal = Core_PromiseTest.equal; -var Creation = PromiseTest.Creation; +let Creation = Core_PromiseTest.Creation; -var ThenChaining = PromiseTest.ThenChaining; +let ThenChaining = Core_PromiseTest.ThenChaining; -var Rejection = PromiseTest.Rejection; +let Rejection = Core_PromiseTest.Rejection; -var Catching = PromiseTest.Catching; +let Catching = Core_PromiseTest.Catching; -var Concurrently = PromiseTest.Concurrently; +let Concurrently = Core_PromiseTest.Concurrently; -var panicTest = ErrorTests.panicTest; +let panicTest = Core_ErrorTests.panicTest; -var $$catch = IntTests.$$catch; +let $$catch = Core_IntTests.$$catch; -var nums = ObjectTests.nums; +let nums = Core_ObjectTests.nums; -var d = ObjectTests.d; +let d = Core_ObjectTests.d; -var x = ObjectTests.x; +let x = Core_ObjectTests.x; -var mkBig = ObjectTests.mkBig; +let mkBig = Core_ObjectTests.mkBig; -var assignOverwritesTarget = ObjectTests.assignOverwritesTarget; +let assignOverwritesTarget = Core_ObjectTests.assignOverwritesTarget; -var runGetTest = ObjectTests.runGetTest; +let runGetTest = Core_ObjectTests.runGetTest; -var getSymbolTestWhenExists = ObjectTests.getSymbolTestWhenExists; +let getSymbolTestWhenExists = Core_ObjectTests.getSymbolTestWhenExists; -var forEachIfOkCallFunction = ResultTests.forEachIfOkCallFunction; +let forEachIfOkCallFunction = Core_ResultTests.forEachIfOkCallFunction; -var forEachIfErrorDoNotCallFunction = ResultTests.forEachIfErrorDoNotCallFunction; +let forEachIfErrorDoNotCallFunction = Core_ResultTests.forEachIfErrorDoNotCallFunction; -var num1 = TypedArrayTests.num1; +let num1 = Core_TypedArrayTests.num1; -var num2 = TypedArrayTests.num2; +let num2 = Core_TypedArrayTests.num2; -var num3 = TypedArrayTests.num3; +let num3 = Core_TypedArrayTests.num3; -var assertTrue = TypedArrayTests.assertTrue; +let assertTrue = Core_TypedArrayTests.assertTrue; -var assertWillThrow = TypedArrayTests.assertWillThrow; +let assertWillThrow = Core_TypedArrayTests.assertWillThrow; -var areSame = TypedArrayTests.areSame; +let areSame = Core_TypedArrayTests.areSame; -var o = TypedArrayTests.o; +let o = Core_TypedArrayTests.o; -var decodeJsonTest = JsonTests.decodeJsonTest; +let decodeJsonTest = Core_JsonTests.decodeJsonTest; -var shouldHandleNullableValues = NullableTests.shouldHandleNullableValues; +let shouldHandleNullableValues = Core_NullableTests.shouldHandleNullableValues; -var eq = IteratorTests.eq; +let eq = Core_IteratorTests.eq; -var iterator = IteratorTests.iterator; +let iterator = Core_IteratorTests.iterator; -var syncResult = IteratorTests.syncResult; +let syncResult = Core_IteratorTests.syncResult; -var asyncResult = IteratorTests.asyncResult; +let asyncResult = Core_IteratorTests.asyncResult; -var asyncIterator = IteratorTests.asyncIterator; +let asyncIterator = Core_IteratorTests.asyncIterator; export { - bign , - TestError , - fail , - equal , - Creation , - ThenChaining , - Rejection , - Catching , - Concurrently , - panicTest , - $$catch , - nums , - d , - x , - mkBig , - assignOverwritesTarget , - runGetTest , - getSymbolTestWhenExists , - forEachIfOkCallFunction , - forEachIfErrorDoNotCallFunction , - num1 , - num2 , - num3 , - assertTrue , - assertWillThrow , - areSame , - o , - decodeJsonTest , - shouldHandleNullableValues , - eq , - iterator , - syncResult , - asyncResult , - asyncIterator , + bign, + TestError, + fail, + equal, + Creation, + ThenChaining, + Rejection, + Catching, + Concurrently, + panicTest, + $$catch, + nums, + d, + x, + mkBig, + assignOverwritesTarget, + runGetTest, + getSymbolTestWhenExists, + forEachIfOkCallFunction, + forEachIfErrorDoNotCallFunction, + num1, + num2, + num3, + assertTrue, + assertWillThrow, + areSame, + o, + decodeJsonTest, + shouldHandleNullableValues, + eq, + iterator, + syncResult, + asyncResult, + asyncIterator, } -/* IntTests Not a pure module */ +/* Core_IntTests Not a pure module */ diff --git a/tests/tests/src/core/Core_TestTests.mjs b/tests/tests/src/core/Core_TestTests.mjs index f33f478cfc..958424a90d 100644 --- a/tests/tests/src/core/Core_TestTests.mjs +++ b/tests/tests/src/core/Core_TestTests.mjs @@ -1,190 +1,188 @@ // Generated by ReScript, PLEASE EDIT WITH CARE import * as Test from "./Test.mjs"; -import * as Caml_obj from "rescript/lib/es6/caml_obj.js"; -import * as PervasivesU from "rescript/lib/es6/pervasivesU.js"; - -var eq = Caml_obj.equal; - -var bign = BigInt(Number.MAX_VALUE); - -var bign$1 = bign + bign; - -Test.run([ - [ - "TestTests.res", - 8, - 20, - 32 - ], - "print null" - ], Test.print(null), eq, "null"); - -Test.run([ - [ - "TestTests.res", - 9, - 20, - 37 - ], - "print undefined" - ], Test.print(undefined), eq, "undefined"); - -Test.run([ - [ - "TestTests.res", - 10, - 20, - 31 - ], - "print NaN" - ], Test.print(Number.NaN), eq, "NaN"); - -Test.run([ - [ - "TestTests.res", - 11, - 20, - 36 - ], - "print infinity" - ], Test.print(PervasivesU.infinity), eq, "Infinity"); - -Test.run([ - [ - "TestTests.res", - 12, - 20, - 29 - ], - "print 0" - ], Test.print(0), eq, "0"); - -Test.run([ - [ - "TestTests.res", - 13, - 20, - 31 - ], - "print int" - ], Test.print(42), eq, "42"); - -Test.run([ - [ - "TestTests.res", - 14, - 20, - 33 - ], - "print float" - ], Test.print(4.2), eq, "4.2"); - -Test.run([ - [ - "TestTests.res", - 15, - 20, - 34 - ], - "print string" - ], Test.print("foo"), eq, "\"foo\""); - -Test.run([ - [ - "TestTests.res", - 16, - 20, - 32 - ], - "print bool" - ], Test.print(true), eq, "true"); - -Test.run([ - [ - "TestTests.res", - 17, - 20, - 34 - ], - "print object" - ], Test.print({ - x: 42 - }), eq, "{ x: 42 }"); - -Test.run([ - [ - "TestTests.res", - 18, - 20, - 33 - ], - "print array" - ], Test.print([ - 1, - 2, - 3 - ]), eq, "[ 1, 2, 3 ]"); - -Test.run([ - [ - "TestTests.res", - 19, - 20, - 34 - ], - "print symbol" - ], Test.print(Symbol("foo")), eq, "Symbol(foo)"); - -Test.run([ - [ - "TestTests.res", - 21, - 13, - 29 - ], - "print function" - ], Test.print(function () { - return 42; - }), eq, "function () {\n return 42;\n }"); - -Test.run([ - [ - "TestTests.res", - 26, - 20, - 40 - ], - "print es6 function" - ], Test.print((() => 42)), eq, "() => 42"); - -Test.run([ - [ - "TestTests.res", - 28, - 13, - 27 - ], - "print bigint" - ], Test.print(bign$1), eq, "359538626972463141629054847463408713596141135051689993197834953606314521560057077521179117265533756343080917907028764928468642653778928365536935093407075033972099821153102564152490980180778657888151737016910267884609166473806445896331617118664246696549595652408289446337476354361838599762500808052368249716736n"); - -Test.run([ - [ - "TestTests.res", - 33, - 20, - 31 - ], - "print set" - ], Test.print(new Set([ - 1, - 2, - 2, - 3 - ])), eq, "Set(3) { 1, 2, 3 }"); +import * as Pervasives from "rescript/lib/es6/Pervasives.js"; +import * as Primitive_object from "rescript/lib/es6/Primitive_object.js"; + +let eq = Primitive_object.equal; + +let bign = BigInt(Number.MAX_VALUE); + +let bign$1 = bign + bign; + +Test.run([ + [ + "Core_TestTests.res", + 6, + 20, + 32 + ], + "print null" +], Test.print(null), eq, "null"); + +Test.run([ + [ + "Core_TestTests.res", + 7, + 20, + 37 + ], + "print undefined" +], Test.print(undefined), eq, "undefined"); + +Test.run([ + [ + "Core_TestTests.res", + 8, + 20, + 31 + ], + "print NaN" +], Test.print(Number.NaN), eq, "NaN"); + +Test.run([ + [ + "Core_TestTests.res", + 9, + 20, + 36 + ], + "print infinity" +], Test.print(Pervasives.infinity), eq, "Infinity"); + +Test.run([ + [ + "Core_TestTests.res", + 10, + 20, + 29 + ], + "print 0" +], Test.print(0), eq, "0"); + +Test.run([ + [ + "Core_TestTests.res", + 11, + 20, + 31 + ], + "print int" +], Test.print(42), eq, "42"); + +Test.run([ + [ + "Core_TestTests.res", + 12, + 20, + 33 + ], + "print float" +], Test.print(4.2), eq, "4.2"); + +Test.run([ + [ + "Core_TestTests.res", + 13, + 20, + 34 + ], + "print string" +], Test.print("foo"), eq, "\"foo\""); + +Test.run([ + [ + "Core_TestTests.res", + 14, + 20, + 32 + ], + "print bool" +], Test.print(true), eq, "true"); + +Test.run([ + [ + "Core_TestTests.res", + 15, + 20, + 34 + ], + "print object" +], Test.print({ + x: 42 +}), eq, "{ x: 42 }"); + +Test.run([ + [ + "Core_TestTests.res", + 16, + 20, + 33 + ], + "print array" +], Test.print([ + 1, + 2, + 3 +]), eq, "[ 1, 2, 3 ]"); + +Test.run([ + [ + "Core_TestTests.res", + 17, + 20, + 34 + ], + "print symbol" +], Test.print(Symbol("foo")), eq, "Symbol(foo)"); + +Test.run([ + [ + "Core_TestTests.res", + 19, + 13, + 29 + ], + "print function" +], Test.print(() => 42), eq, "function () {\n return 42;\n }"); + +Test.run([ + [ + "Core_TestTests.res", + 24, + 20, + 40 + ], + "print es6 function" +], Test.print((() => 42)), eq, "() => 42"); + +Test.run([ + [ + "Core_TestTests.res", + 26, + 13, + 27 + ], + "print bigint" +], Test.print(bign$1), eq, "359538626972463141629054847463408713596141135051689993197834953606314521560057077521179117265533756343080917907028764928468642653778928365536935093407075033972099821153102564152490980180778657888151737016910267884609166473806445896331617118664246696549595652408289446337476354361838599762500808052368249716736n"); + +Test.run([ + [ + "Core_TestTests.res", + 31, + 20, + 31 + ], + "print set" +], Test.print(new Set([ + 1, + 2, + 2, + 3 +])), eq, "Set(3) { 1, 2, 3 }"); export { - eq , + eq, bign$1 as bign, } /* bign Not a pure module */ diff --git a/tests/tests/src/core/Core_TypedArrayTests.mjs b/tests/tests/src/core/Core_TypedArrayTests.mjs index 91adb709af..fd7fce21da 100644 --- a/tests/tests/src/core/Core_TypedArrayTests.mjs +++ b/tests/tests/src/core/Core_TypedArrayTests.mjs @@ -1,49 +1,47 @@ // Generated by ReScript, PLEASE EDIT WITH CARE import * as Test from "./Test.mjs"; -import * as Caml_obj from "rescript/lib/es6/caml_obj.js"; -import * as Core__Option from "../src/Core__Option.mjs"; +import * as Option from "rescript/lib/es6/Option.js"; +import * as Primitive_object from "rescript/lib/es6/Primitive_object.js"; -var eq = Caml_obj.equal; +let eq = Primitive_object.equal; Test.run([ - [ - "TypedArrayTests.res", - 7, - 20, - 44 - ], - "bytes per element is 8" - ], BigInt64Array.BYTES_PER_ELEMENT, eq, 8); + [ + "Core_TypedArrayTests.res", + 5, + 20, + 44 + ], + "bytes per element is 8" +], BigInt64Array.BYTES_PER_ELEMENT, eq, 8); -var num1 = BigInt("123456789"); +let num1 = BigInt("123456789"); -var num2 = BigInt("987654321"); +let num2 = BigInt("987654321"); -var num3 = BigInt("555555555"); +let num3 = BigInt("555555555"); function assertTrue(message, predicate) { try { if (predicate()) { - return ; + return; } throw new Error(message); - } - catch (exn){ + } catch (exn) { throw new Error(message); } } function assertWillThrow(message, f) { - var didThrow = false; + let didThrow = false; try { f(); - } - catch (exn){ + } catch (exn) { didThrow = true; } if (didThrow !== false) { - return ; + return; } throw new Error(message); } @@ -52,54 +50,52 @@ function areSame(x, y) { return x.toString() === y.toString(); } -assertTrue("fromArray", (function () { - return areSame(Core__Option.getExn(new BigInt64Array([ - num1, - num2 - ])[1], undefined), num2); - })); - -assertTrue("fromBuffer", (function () { - var x = new BigInt64Array(new ArrayBuffer(16)); - x[1] = num2; - return areSame(Core__Option.getExn(x[1], undefined), num2); - })); - -assertWillThrow("fromBuffer when too short can throw when used", (function () { - var x = new BigInt64Array(new ArrayBuffer(1)); - x[0] = num1; - areSame(Core__Option.getExn(x[0], undefined), num1); - })); - -assertTrue("fromBufferWithRange", (function () { - var x = new BigInt64Array(new ArrayBuffer(16), 0, 1); - x[0] = num1; - return areSame(Core__Option.getExn(x[0], undefined), num1); - })); - -assertWillThrow("fromBufferWithRange is unsafe, out of range", (function () { - var x = new BigInt64Array(new ArrayBuffer(16), 13, 1); - x[0] = num1; - areSame(Core__Option.getExn(x[0], undefined), num1); - })); - -assertTrue("fromLength is NOT in bytes", (function () { - var x = new BigInt64Array(1); - return x.byteLength === 8; - })); +assertTrue("fromArray", () => areSame(Option.getExn(new BigInt64Array([ + num1, + num2 + ])[1], undefined), num2)); + +assertTrue("fromBuffer", () => { + let x = new BigInt64Array(new ArrayBuffer(16)); + x[1] = num2; + return areSame(Option.getExn(x[1], undefined), num2); +}); + +assertWillThrow("fromBuffer when too short can throw when used", () => { + let x = new BigInt64Array(new ArrayBuffer(1)); + x[0] = num1; + areSame(Option.getExn(x[0], undefined), num1); +}); + +assertTrue("fromBufferWithRange", () => { + let x = new BigInt64Array(new ArrayBuffer(16), 0, 1); + x[0] = num1; + return areSame(Option.getExn(x[0], undefined), num1); +}); + +assertWillThrow("fromBufferWithRange is unsafe, out of range", () => { + let x = new BigInt64Array(new ArrayBuffer(16), 13, 1); + x[0] = num1; + areSame(Option.getExn(x[0], undefined), num1); +}); + +assertTrue("fromLength is NOT in bytes", () => { + let x = new BigInt64Array(1); + return x.byteLength === 8; +}); function o(prim0, prim1) { return BigInt64Array.from(prim0, prim1); } export { - eq , - num1 , - num2 , - num3 , - assertTrue , - assertWillThrow , - areSame , - o , + eq, + num1, + num2, + num3, + assertTrue, + assertWillThrow, + areSame, + o, } /* Not a pure module */ diff --git a/tests/tests/src/core/Test.mjs b/tests/tests/src/core/Test.mjs index 1824f710e2..c24abc1c99 100644 --- a/tests/tests/src/core/Test.mjs +++ b/tests/tests/src/core/Test.mjs @@ -3,17 +3,17 @@ import * as Fs from "fs"; import * as Path from "path"; import * as Util from "util"; -import * as Core__Option from "../src/Core__Option.mjs"; +import * as Option from "rescript/lib/es6/Option.js"; import * as CodeFrame from "@babel/code-frame"; -var dirname = (new URL('.', import.meta.url).pathname); +let dirname = (new URL('.', import.meta.url).pathname); function print(value) { - var match = typeof value; + let match = typeof value; if (match === "object" || match === "bigint") { return Util.inspect(value); } else if (match === "string") { - return Core__Option.getExn(JSON.stringify(value), undefined); + return Option.getExn(JSON.stringify(value), undefined); } else { return String(value); } @@ -21,33 +21,33 @@ function print(value) { function run(loc, left, comparator, right) { if (comparator(left, right)) { - return ; + return; } - var match = loc[0]; - var line = match[1]; - var file = match[0]; - var fileContent = Fs.readFileSync(Path.join(dirname, file), { - encoding: "utf-8" - }); - var left$1 = print(left); - var right$1 = print(right); - var codeFrame = CodeFrame.codeFrameColumns(fileContent, { - start: { - line: line - } - }, { - highlightCode: true - }); - var errorMessage = "\n \u001b[31mTest Failure!\n \u001b[36m" + file + "\u001b[0m:\u001b[2m" + String(line) + "\n" + codeFrame + "\n \u001b[39mLeft: \u001b[31m" + left$1 + "\n \u001b[39mRight: \u001b[31m" + right$1 + "\u001b[0m\n"; + let match = loc[0]; + let line = match[1]; + let file = match[0]; + let fileContent = Fs.readFileSync(Path.join(dirname, file), { + encoding: "utf-8" + }); + let left$1 = print(left); + let right$1 = print(right); + let codeFrame = CodeFrame.codeFrameColumns(fileContent, { + start: { + line: line + } + }, { + highlightCode: true + }); + let errorMessage = "\n \u001b[31mTest Failure!\n \u001b[36m" + file + "\u001b[0m:\u001b[2m" + String(line) + "\n" + codeFrame + "\n \u001b[39mLeft: \u001b[31m" + left$1 + "\n \u001b[39mRight: \u001b[31m" + right$1 + "\u001b[0m\n"; console.log(errorMessage); - var obj = {}; + let obj = {}; Error.captureStackTrace(obj); console.log(obj.stack.replace(/\n /g, "\n ").replace(/^Error\n/, "").replace(/^.+\n/, "").replace(/\n at .+\(node:internal.+\n?/g, "")); } export { - dirname , - print , - run , + dirname, + print, + run, } /* dirname Not a pure module */ diff --git a/tests/tests/src/core/intl/Core_IntlTests.mjs b/tests/tests/src/core/intl/Core_IntlTests.mjs index 6fcf587553..3929756a37 100644 --- a/tests/tests/src/core/intl/Core_IntlTests.mjs +++ b/tests/tests/src/core/intl/Core_IntlTests.mjs @@ -1,17 +1,18 @@ // 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"; +import * as Exn from "rescript/lib/es6/Exn.js"; +import * as $$Error from "rescript/lib/es6/Error.js"; +import * as Option from "rescript/lib/es6/Option.js"; +import * as Primitive_option from "rescript/lib/es6/Primitive_option.js"; +import * as Core_Intl_LocaleTest from "./Core_Intl_LocaleTest.mjs"; +import * as Primitive_exceptions from "rescript/lib/es6/Primitive_exceptions.js"; +import * as Core_Intl_CollatorTest from "./Core_Intl_CollatorTest.mjs"; +import * as Core_Intl_SegmenterTest from "./Core_Intl_SegmenterTest.mjs"; +import * as Core_Intl_ListFormatTest from "./Core_Intl_ListFormatTest.mjs"; +import * as Core_Intl_PluralRulesTest from "./Core_Intl_PluralRulesTest.mjs"; +import * as Core_Intl_NumberFormatTest from "./Core_Intl_NumberFormatTest.mjs"; +import * as Core_Intl_DateTimeFormatTest from "./Core_Intl_DateTimeFormatTest.mjs"; +import * as Core_Intl_RelativeTimeFormatTest from "./Core_Intl_RelativeTimeFormatTest.mjs"; console.log("---"); @@ -20,16 +21,15 @@ console.log("Intl"); console.log(Intl.getCanonicalLocales("EN-US")); console.log(Intl.getCanonicalLocales([ - "EN-US", - "Fr" - ])); + "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) { +} catch (raw_e) { + let e = Primitive_exceptions.internalToException(raw_e); + if (e.RE_EXN_ID === Exn.$$Error) { console.error(e._1); } else { throw e; @@ -43,10 +43,9 @@ try { 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) { +} catch (raw_e$1) { + let e$1 = Primitive_exceptions.internalToException(raw_e$1); + if (e$1.RE_EXN_ID === Exn.$$Error) { console.error(e$1._1); } else { throw e$1; @@ -56,15 +55,12 @@ catch (raw_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; +} catch (raw_e$2) { + let e$2 = Primitive_exceptions.internalToException(raw_e$2); + if (e$2.RE_EXN_ID === Exn.$$Error) { + let e$3 = e$2._1; + let message = Option.map(e$3.message, prim => prim.toLowerCase()); + let exit = 0; if (message === "invalid key : someinvalidkey") { console.log("Caught expected error"); } else { @@ -76,59 +72,59 @@ catch (raw_e$2){ } } else { - var e$4 = Caml_js_exceptions.as_js_exn(e$2); + let e$4 = $$Error.fromException(e$2); if (e$4 !== undefined) { - throw Caml_option.valFromOption(e$4); + throw Primitive_option.valFromOption(e$4); } console.error("Unexpected error"); } } -var _collator = Intl__CollatorTest._collator; +let _collator = Core_Intl_CollatorTest._collator; -var collator = Intl__CollatorTest.collator; +let collator = Core_Intl_CollatorTest.collator; -var resolvedOptions = Intl__DateTimeFormatTest.resolvedOptions; +let resolvedOptions = Core_Intl_DateTimeFormatTest.resolvedOptions; -var timeZone = Intl__DateTimeFormatTest.timeZone; +let timeZone = Core_Intl_DateTimeFormatTest.timeZone; -var _locale = Intl__LocaleTest._locale; +let _locale = Core_Intl_LocaleTest._locale; -var locale = Intl__LocaleTest.locale; +let locale = Core_Intl_LocaleTest.locale; -var currencyFormatter = Intl__NumberFormatTest.currencyFormatter; +let currencyFormatter = Core_Intl_NumberFormatTest.currencyFormatter; -var roundingFormatter = Intl__NumberFormatTest.roundingFormatter; +let roundingFormatter = Core_Intl_NumberFormatTest.roundingFormatter; -var groupingFormatter1 = Intl__NumberFormatTest.groupingFormatter1; +let groupingFormatter1 = Core_Intl_NumberFormatTest.groupingFormatter1; -var groupingFormatter2 = Intl__NumberFormatTest.groupingFormatter2; +let groupingFormatter2 = Core_Intl_NumberFormatTest.groupingFormatter2; -var sigFormatter = Intl__NumberFormatTest.sigFormatter; +let sigFormatter = Core_Intl_NumberFormatTest.sigFormatter; -var options = Intl__NumberFormatTest.options; +let options = Core_Intl_NumberFormatTest.options; -var _formatter = Intl__SegmenterTest._formatter; +let _formatter = Core_Intl_SegmenterTest._formatter; -var formatter = Intl__SegmenterTest.formatter; +let formatter = Core_Intl_SegmenterTest.formatter; -var segments = Intl__SegmenterTest.segments; +let segments = Core_Intl_SegmenterTest.segments; export { - _collator , - collator , - resolvedOptions , - timeZone , - _locale , - locale , - currencyFormatter , - roundingFormatter , - groupingFormatter1 , - groupingFormatter2 , - sigFormatter , - options , - _formatter , - formatter , - segments , + _collator, + collator, + resolvedOptions, + timeZone, + _locale, + locale, + currencyFormatter, + roundingFormatter, + groupingFormatter1, + groupingFormatter2, + sigFormatter, + options, + _formatter, + formatter, + segments, } /* Not a pure module */ diff --git a/tests/tests/src/core/intl/Core_Intl_CollatorTest.mjs b/tests/tests/src/core/intl/Core_Intl_CollatorTest.mjs index bbff943d27..b40e6e76ac 100644 --- a/tests/tests/src/core/intl/Core_Intl_CollatorTest.mjs +++ b/tests/tests/src/core/intl/Core_Intl_CollatorTest.mjs @@ -9,29 +9,29 @@ 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" - }); +let _collator = new Intl.Collator([ + "en-US", + "en-GB" +]); + +let collator = new Intl.Collator(["en-US"], { + sensitivity: "base", + ignorePunctuation: true, + numeric: true, + caseFirst: "upper" +}); Intl.Collator.supportedLocalesOf([ - "en-US", - "en-GB" - ]); + "en-US", + "en-GB" +]); Intl.Collator.supportedLocalesOf([ - "en-US", - "en-GB" - ], { - localeMatcher: "lookup" - }); + "en-US", + "en-GB" +], { + localeMatcher: "lookup" +}); console.log(collator.resolvedOptions()); @@ -40,7 +40,7 @@ console.log(collator.compare("hi", "hï")); console.log(Intl.Collator.supportedLocalesOf(["hi"])); export { - _collator , - collator , + _collator, + collator, } /* Not a pure module */ diff --git a/tests/tests/src/core/intl/Core_Intl_DateTimeFormatTest.mjs b/tests/tests/src/core/intl/Core_Intl_DateTimeFormatTest.mjs index 140ae17c45..c7008f5c7e 100644 --- a/tests/tests/src/core/intl/Core_Intl_DateTimeFormatTest.mjs +++ b/tests/tests/src/core/intl/Core_Intl_DateTimeFormatTest.mjs @@ -1,33 +1,32 @@ // 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" - ]); + "en-US", + "en-GB" +]); Intl.DateTimeFormat.supportedLocalesOf([ - "en-US", - "en-GB" - ], { - localeMatcher: "lookup" - }); + "en-US", + "en-GB" +], { + localeMatcher: "lookup" +}); -var formatter = new Intl.DateTimeFormat(undefined, { - dateStyle: "full", - timeStyle: "full" - }); +let 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 = { +let options = { timeZone: "UTC", hour12: false, hourCycle: "h24", @@ -43,48 +42,48 @@ var options = { timeZoneName: "longGeneric" }; -var formatter$1 = new Intl.DateTimeFormat(undefined, options); +let formatter$1 = new Intl.DateTimeFormat(undefined, options); console.log(formatter$1.format(new Date(Date.now()))); -var newrecord = Caml_obj.obj_dup(options); +let newrecord = {...options}; -var formatter$2 = new Intl.DateTimeFormat(undefined, (newrecord.timeZoneName = "long", newrecord)); +let 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); +let newrecord$1 = {...options}; -var formatter$3 = new Intl.DateTimeFormat(undefined, (newrecord$1.timeZoneName = "longOffset", newrecord$1)); +let 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); +let newrecord$2 = {...options}; -var formatter$4 = new Intl.DateTimeFormat(undefined, (newrecord$2.timeZoneName = "short", newrecord$2)); +let 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); +let newrecord$3 = {...options}; -var formatter$5 = new Intl.DateTimeFormat(undefined, (newrecord$3.timeZoneName = "shortGeneric", newrecord$3)); +let 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); +let newrecord$4 = {...options}; -var formatter$6 = new Intl.DateTimeFormat(undefined, (newrecord$4.timeZoneName = "shortOffset", newrecord$4)); +let 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(); +let resolvedOptions = new Intl.DateTimeFormat().resolvedOptions(); -var timeZone = resolvedOptions.timeZone; +let timeZone = resolvedOptions.timeZone; export { - options , + options, formatter$6 as formatter, - resolvedOptions , - timeZone , + resolvedOptions, + timeZone, } /* Not a pure module */ diff --git a/tests/tests/src/core/intl/Core_Intl_ListFormatTest.mjs b/tests/tests/src/core/intl/Core_Intl_ListFormatTest.mjs index 32cc1d4849..67d33f2b50 100644 --- a/tests/tests/src/core/intl/Core_Intl_ListFormatTest.mjs +++ b/tests/tests/src/core/intl/Core_Intl_ListFormatTest.mjs @@ -8,51 +8,51 @@ console.log("Intl.ListFormat"); new Intl.ListFormat(); new Intl.ListFormat([ - "en-US", - "en-GB" - ]); - -var _formatter = new Intl.ListFormat([ - "en-US", - "en-GB" - ], { - type: "conjunction", - style: "long" - }); + "en-US", + "en-GB" +]); + +let _formatter = new Intl.ListFormat([ + "en-US", + "en-GB" +], { + type: "conjunction", + style: "long" +}); Intl.ListFormat.supportedLocalesOf([ - "en-US", - "en-GB" - ]); + "en-US", + "en-GB" +]); Intl.ListFormat.supportedLocalesOf([ - "en-US", - "en-GB" - ], { - localeMatcher: "lookup" - }); + "en-US", + "en-GB" +], { + localeMatcher: "lookup" +}); -var formatter = new Intl.ListFormat(undefined, { - type: "conjunction", - style: "long" - }); +let formatter = new Intl.ListFormat(undefined, { + type: "conjunction", + style: "long" +}); console.log(formatter.resolvedOptions()); console.log(formatter.format([ - "one", - "two", - "three" - ])); + "one", + "two", + "three" +])); console.log(formatter.formatToParts([ - "one", - "two", - "three" - ])); + "one", + "two", + "three" +])); export { - _formatter , - formatter , + _formatter, + formatter, } /* Not a pure module */ diff --git a/tests/tests/src/core/intl/Core_Intl_LocaleTest.mjs b/tests/tests/src/core/intl/Core_Intl_LocaleTest.mjs index a8349a845c..240ab30896 100644 --- a/tests/tests/src/core/intl/Core_Intl_LocaleTest.mjs +++ b/tests/tests/src/core/intl/Core_Intl_LocaleTest.mjs @@ -5,15 +5,15 @@ console.log("---"); console.log("Intl.Locale"); -var _locale = new Intl.Locale("en-US"); +let _locale = new Intl.Locale("en-US"); -var locale = new Intl.Locale("en-US", { - calendar: "hebrew", - collation: "compat", - hourCycle: "h24", - caseFirst: "upper", - numeric: true - }); +let locale = new Intl.Locale("en-US", { + calendar: "hebrew", + collation: "compat", + hourCycle: "h24", + caseFirst: "upper", + numeric: true +}); console.log(locale.baseName); @@ -40,7 +40,7 @@ console.log(locale.maximize()); console.log(locale.minimize()); export { - _locale , - locale , + _locale, + locale, } /* Not a pure module */ diff --git a/tests/tests/src/core/intl/Core_Intl_NumberFormatTest.mjs b/tests/tests/src/core/intl/Core_Intl_NumberFormatTest.mjs index dfde813858..63c1f22d6a 100644 --- a/tests/tests/src/core/intl/Core_Intl_NumberFormatTest.mjs +++ b/tests/tests/src/core/intl/Core_Intl_NumberFormatTest.mjs @@ -1,58 +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"; +import * as Primitive_option from "rescript/lib/es6/Primitive_option.js"; +import * as Intl_NumberFormat_Grouping from "rescript/lib/es6/Intl_NumberFormat_Grouping.js"; console.log("---"); console.log("Intl.NumberFormat"); -var currencyFormatter = new Intl.NumberFormat(["fr-FR"], { - currency: "EUR", - style: "currency" - }); +let currencyFormatter = new Intl.NumberFormat(["fr-FR"], { + currency: "EUR", + style: "currency" +}); console.log(Intl.NumberFormat.supportedLocalesOf([ - "fr-FR", - "en-US" - ])); + "fr-FR", + "en-US" +])); console.log(currencyFormatter.format(123.23)); -var roundingFormatter = new Intl.NumberFormat(undefined, { - roundingIncrement: 500, - minimumFractionDigits: 2, - maximumFractionDigits: 2 - }); +let roundingFormatter = new Intl.NumberFormat(undefined, { + roundingIncrement: 500, + minimumFractionDigits: 2, + maximumFractionDigits: 2 +}); -var groupingFormatter1 = new Intl.NumberFormat(undefined, { - useGrouping: Caml_option.some(true) - }); +let groupingFormatter1 = new Intl.NumberFormat(undefined, { + useGrouping: Primitive_option.some(true) +}); -var groupingFormatter2 = new Intl.NumberFormat(undefined, { - useGrouping: "auto" - }); +let groupingFormatter2 = new Intl.NumberFormat(undefined, { + useGrouping: "auto" +}); -var sigFormatter = new Intl.NumberFormat(undefined, { - minimumIntegerDigits: 1, - minimumFractionDigits: 1, - maximumFractionDigits: 1, - minimumSignificantDigits: 1, - maximumSignificantDigits: 1 - }); +let sigFormatter = new Intl.NumberFormat(undefined, { + minimumIntegerDigits: 1, + minimumFractionDigits: 1, + maximumFractionDigits: 1, + minimumSignificantDigits: 1, + maximumSignificantDigits: 1 +}); -var options = sigFormatter.resolvedOptions(); +let options = sigFormatter.resolvedOptions(); console.log(options); -console.log(Core__Intl__NumberFormat__Grouping.parseJsValue(options.useGrouping)); +console.log(Intl_NumberFormat_Grouping.parseJsValue(options.useGrouping)); export { - currencyFormatter , - roundingFormatter , - groupingFormatter1 , - groupingFormatter2 , - sigFormatter , - options , + currencyFormatter, + roundingFormatter, + groupingFormatter1, + groupingFormatter2, + sigFormatter, + options, } /* Not a pure module */ diff --git a/tests/tests/src/core/intl/Core_Intl_PluralRulesTest.mjs b/tests/tests/src/core/intl/Core_Intl_PluralRulesTest.mjs index 3ad44723de..222817ddfc 100644 --- a/tests/tests/src/core/intl/Core_Intl_PluralRulesTest.mjs +++ b/tests/tests/src/core/intl/Core_Intl_PluralRulesTest.mjs @@ -8,21 +8,21 @@ console.log("Intl.PluralRules"); new Intl.PluralRules(); new Intl.PluralRules([ - "en-US", - "en-GB" - ]); - -var _formatter = new Intl.PluralRules(undefined, { - type: "ordinal", - minimumSignificantDigits: 3, - maximumSignificantDigits: 5 - }); - -var formatter = new Intl.PluralRules(["en-US"], { - type: "ordinal", - minimumSignificantDigits: 3, - maximumSignificantDigits: 5 - }); + "en-US", + "en-GB" +]); + +let _formatter = new Intl.PluralRules(undefined, { + type: "ordinal", + minimumSignificantDigits: 3, + maximumSignificantDigits: 5 +}); + +let formatter = new Intl.PluralRules(["en-US"], { + type: "ordinal", + minimumSignificantDigits: 3, + maximumSignificantDigits: 5 +}); console.log(formatter.resolvedOptions()); @@ -31,7 +31,7 @@ console.log(formatter.select(2.0)); console.log(formatter.select(2)); export { - _formatter , - formatter , + _formatter, + formatter, } /* Not a pure module */ diff --git a/tests/tests/src/core/intl/Core_Intl_RelativeTimeFormatTest.mjs b/tests/tests/src/core/intl/Core_Intl_RelativeTimeFormatTest.mjs index 1bfd262739..54d732a0ca 100644 --- a/tests/tests/src/core/intl/Core_Intl_RelativeTimeFormatTest.mjs +++ b/tests/tests/src/core/intl/Core_Intl_RelativeTimeFormatTest.mjs @@ -6,33 +6,33 @@ console.log("---"); console.log("Intl.RelativeTimeFormat"); Intl.RelativeTimeFormat.supportedLocalesOf([ - "en-US", - "en-GB" - ]); + "en-US", + "en-GB" +]); Intl.RelativeTimeFormat.supportedLocalesOf([ - "en-US", - "en-GB" - ], { - localeMatcher: "lookup" - }); + "en-US", + "en-GB" +], { + localeMatcher: "lookup" +}); new Intl.RelativeTimeFormat(); new Intl.RelativeTimeFormat([ - "en-US", - "en-GB" - ]); + "en-US", + "en-GB" +]); -var _formatter = new Intl.RelativeTimeFormat(undefined, { - numeric: "always", - style: "narrow" - }); +let _formatter = new Intl.RelativeTimeFormat(undefined, { + numeric: "always", + style: "narrow" +}); -var formatter = new Intl.RelativeTimeFormat(["en-US"], { - numeric: "always", - style: "narrow" - }); +let formatter = new Intl.RelativeTimeFormat(["en-US"], { + numeric: "always", + style: "narrow" +}); console.log(formatter.resolvedOptions()); @@ -41,7 +41,7 @@ console.log(formatter.format(3, "hour")); console.log(formatter.formatToParts(3, "hour")); export { - _formatter , - formatter , + _formatter, + formatter, } /* Not a pure module */ diff --git a/tests/tests/src/core/intl/Core_Intl_SegmenterTest.mjs b/tests/tests/src/core/intl/Core_Intl_SegmenterTest.mjs index 841c4ef621..f44116a73e 100644 --- a/tests/tests/src/core/intl/Core_Intl_SegmenterTest.mjs +++ b/tests/tests/src/core/intl/Core_Intl_SegmenterTest.mjs @@ -6,35 +6,35 @@ console.log("---"); console.log("Intl.Segmenter"); Intl.Segmenter.supportedLocalesOf([ - "en-US", - "en-GB" - ]); + "en-US", + "en-GB" +]); Intl.Segmenter.supportedLocalesOf([ - "en-US", - "en-GB" - ], { - localeMatcher: "lookup" - }); + "en-US", + "en-GB" +], { + localeMatcher: "lookup" +}); new Intl.Segmenter(); new Intl.Segmenter([ - "en-US", - "en-GB" - ]); + "en-US", + "en-GB" +]); -var _formatter = new Intl.Segmenter(undefined, { - granularity: "word" - }); +let _formatter = new Intl.Segmenter(undefined, { + granularity: "word" +}); -var formatter = new Intl.Segmenter(["en-US"], { - granularity: "word" - }); +let formatter = new Intl.Segmenter(["en-US"], { + granularity: "word" +}); console.log(formatter.resolvedOptions()); -var segments = formatter.segment("This is a sentence with several words"); +let segments = formatter.segment("This is a sentence with several words"); console.log(segments); @@ -43,8 +43,8 @@ console.log(segments.containing()); console.log(segments.containing(1)); export { - _formatter , - formatter , - segments , + _formatter, + formatter, + segments, } /* Not a pure module */ From 9a9e68749da581ead9b984364336acb9e0e9a1c9 Mon Sep 17 00:00:00 2001 From: Christoph Knittel Date: Tue, 22 Oct 2024 08:58:24 +0200 Subject: [PATCH 5/7] Fix test --- tests/tests/src/core/Core_TestTests.mjs | 14 +++++++------- tests/tests/src/core/Core_TestTests.res | 7 +------ 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/tests/tests/src/core/Core_TestTests.mjs b/tests/tests/src/core/Core_TestTests.mjs index 958424a90d..f39a4dce04 100644 --- a/tests/tests/src/core/Core_TestTests.mjs +++ b/tests/tests/src/core/Core_TestTests.mjs @@ -139,17 +139,17 @@ Test.run([ Test.run([ [ "Core_TestTests.res", - 19, - 13, - 29 + 18, + 20, + 36 ], "print function" -], Test.print(() => 42), eq, "function () {\n return 42;\n }"); +], Test.print(() => 42), eq, "() => 42"); Test.run([ [ "Core_TestTests.res", - 24, + 19, 20, 40 ], @@ -159,7 +159,7 @@ Test.run([ Test.run([ [ "Core_TestTests.res", - 26, + 21, 13, 27 ], @@ -169,7 +169,7 @@ Test.run([ Test.run([ [ "Core_TestTests.res", - 31, + 26, 20, 31 ], diff --git a/tests/tests/src/core/Core_TestTests.res b/tests/tests/src/core/Core_TestTests.res index df2a441d48..f2f0dcad99 100644 --- a/tests/tests/src/core/Core_TestTests.res +++ b/tests/tests/src/core/Core_TestTests.res @@ -15,12 +15,7 @@ Test.run(__POS_OF__("print bool"), Test.print(true), eq, "true") Test.run(__POS_OF__("print object"), Test.print({"x": 42}), eq, `{ x: 42 }`) Test.run(__POS_OF__("print array"), Test.print([1, 2, 3]), eq, "[ 1, 2, 3 ]") Test.run(__POS_OF__("print symbol"), Test.print(Symbol.make("foo")), eq, "Symbol(foo)") -Test.run( - __POS_OF__("print function"), - Test.print(() => 42), - eq, - "function () {\n return 42;\n }", -) +Test.run(__POS_OF__("print function"), Test.print(() => 42), eq, "() => 42") Test.run(__POS_OF__("print es6 function"), Test.print(%raw("() => 42")), eq, "() => 42") Test.run( __POS_OF__("print bigint"), From a6d9b40366ac20708d71e6653185d03b2aa26e72 Mon Sep 17 00:00:00 2001 From: Christoph Knittel Date: Tue, 22 Oct 2024 09:01:30 +0200 Subject: [PATCH 6/7] Run Core tests in CI --- scripts/test.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/scripts/test.js b/scripts/test.js index f55482b211..f9f10465f0 100644 --- a/scripts/test.js +++ b/scripts/test.js @@ -65,7 +65,17 @@ async function runTests() { stdio: [0, 1, 2], }); - cp.execSync(`npx mocha -t 10000 tests/tests/**/*_test.mjs`, { + cp.execSync("npx mocha -t 10000 tests/tests/**/*_test.mjs", { + cwd: path.join(__dirname, ".."), + stdio: [0, 1, 2], + }); + + cp.execSync("node tests/tests/src/core/Core_TestSuite.mjs", { + cwd: path.join(__dirname, ".."), + stdio: [0, 1, 2], + }); + + cp.execSync("node tests/tests/src/core/Core_TempTests.mjs", { cwd: path.join(__dirname, ".."), stdio: [0, 1, 2], }); From 1a71d1455c2342e50820e5402f5ae93ef7cd5b04 Mon Sep 17 00:00:00 2001 From: Christoph Knittel Date: Tue, 22 Oct 2024 17:01:51 +0200 Subject: [PATCH 7/7] CHANGELOG --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3c4d4ed6b9..197676323f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,7 +24,7 @@ - Allow spreads of variants in patterns (`| ...someVariant as v => `) when the variant spread is a subtype of the variant matched on. https://github.com/rescript-lang/rescript-compiler/pull/6721 - Fix the issue where dynamic imports are not working for function-defined externals. https://github.com/rescript-lang/rescript-compiler/pull/7060 - Allow pattern matching on dicts. `switch someDict { | dict{"one": 1} => Js.log("one is one") }`. https://github.com/rescript-lang/rescript-compiler/pull/7059 -- "ReScript Core" standard library is now included in the `rescript` npm package. https://github.com/rescript-lang/rescript-compiler/pull/7108 +- "ReScript Core" standard library is now included in the `rescript` npm package. https://github.com/rescript-lang/rescript-compiler/pull/7108 https://github.com/rescript-lang/rescript-compiler/pull/7116 - Handle absolute filepaths in gentype. https://github.com/rescript-lang/rescript-compiler/pull/7104 #### :bug: Bug fix