diff --git a/CHANGELOG.md b/CHANGELOG.md index 255f8b8463..afa8aceb45 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -34,6 +34,7 @@ #### :house: Internal - Playground: Add config options for experimental features and jsx preserve mode. https://github.com/rescript-lang/rescript/pull/7865 +- Clean up tests. https://github.com/rescript-lang/rescript/pull/7861 https://github.com/rescript-lang/rescript/pull/7871 # 12.0.0-beta.10 diff --git a/tests/tests/src/alias_test.mjs b/tests/tests/src/alias_test.mjs index 0b97f7bb6c..6acee1073b 100644 --- a/tests/tests/src/alias_test.mjs +++ b/tests/tests/src/alias_test.mjs @@ -5,7 +5,7 @@ let a10 = "hello world"; let a20 = a10 + "not"; -let v = a20.codePointAt(0) === /* 'h' */104 ? 1 : 2; +let v = a20[0] === "h" ? 1 : 2; let a21 = a20 + a20; diff --git a/tests/tests/src/alias_test.res b/tests/tests/src/alias_test.res index 40b333461e..4dda168b12 100644 --- a/tests/tests/src/alias_test.res +++ b/tests/tests/src/alias_test.res @@ -1,5 +1,3 @@ -module String = Ocaml_String - let a0 = "hello " let a1 = a0 @@ -41,7 +39,7 @@ let a18 = a17 let a19 = a18 let a20 = a19 ++ "not" -let v = if String.get(a20, 0) == 'h' { +let v = if String.getUnsafe(a20, 0) == "h" { 1 } else { 2 diff --git a/tests/tests/src/array_safe_get.mjs b/tests/tests/src/array_safe_get.mjs index 0259f4b0d5..c1e07489b5 100644 --- a/tests/tests/src/array_safe_get.mjs +++ b/tests/tests/src/array_safe_get.mjs @@ -1,6 +1,5 @@ // Generated by ReScript, PLEASE EDIT WITH CARE -import * as Primitive_array from "@rescript/runtime/lib/es6/Primitive_array.js"; import * as Primitive_exceptions from "@rescript/runtime/lib/es6/Primitive_exceptions.js"; let x = [ @@ -11,7 +10,7 @@ let x = [ let y; try { - y = Primitive_array.get(x, 3); + y = x[3]; } catch (raw_msg) { let msg = Primitive_exceptions.internalToException(raw_msg); if (msg.RE_EXN_ID === "Invalid_argument") { @@ -22,10 +21,7 @@ try { } } -let $$Array; - export { - $$Array, x, y, } diff --git a/tests/tests/src/array_safe_get.res b/tests/tests/src/array_safe_get.res index 50113f5b9d..46b1c891ea 100644 --- a/tests/tests/src/array_safe_get.res +++ b/tests/tests/src/array_safe_get.res @@ -1,7 +1,5 @@ -module Array = Ocaml_Array - let x = [1, 2] -let y = try x[3] catch { +let y = try x->Array.getUnsafe(3) catch { | Invalid_argument(msg) => Js.log(msg) 0 diff --git a/tests/tests/src/array_subtle_test.mjs b/tests/tests/src/array_subtle_test.mjs index acdef49cf2..d8e279257c 100644 --- a/tests/tests/src/array_subtle_test.mjs +++ b/tests/tests/src/array_subtle_test.mjs @@ -2,7 +2,6 @@ import * as Mocha from "mocha"; import * as Test_utils from "./test_utils.mjs"; -import * as Primitive_array from "@rescript/runtime/lib/es6/Primitive_array.js"; let v = [ 1, @@ -22,7 +21,7 @@ function f(v) { } function fff(x) { - return true; + return x.length >= 0; } function fff2(x) { @@ -34,11 +33,15 @@ function fff2(x) { } function fff3(x) { - return 1; + if (x.length >= 0) { + return 1; + } else { + return 2; + } } function fff4(x) { - if (x.length !== 0) { + if (x.length > 0) { return 1; } else { return 2; @@ -53,7 +56,7 @@ Mocha.describe("Array_subtle_test", () => { 3, 3 ]; - Test_utils.eq("File \"array_subtle_test.res\", line 40, characters 7-14", 4, v.length); + Test_utils.eq("File \"array_subtle_test.res\", line 38, characters 7-14", 4, v.length); }); Mocha.test("array_push_test", () => { let v = [ @@ -62,9 +65,9 @@ Mocha.describe("Array_subtle_test", () => { 3, 3 ]; - Test_utils.eq("File \"array_subtle_test.res\", line 45, characters 7-14", 5, v.push(3)); - Test_utils.eq("File \"array_subtle_test.res\", line 46, characters 7-14", 5, v.length); - Test_utils.eq("File \"array_subtle_test.res\", line 47, characters 7-14", 5, v.length); + Test_utils.eq("File \"array_subtle_test.res\", line 43, characters 7-14", 5, v.push(3)); + Test_utils.eq("File \"array_subtle_test.res\", line 44, characters 7-14", 5, v.length); + Test_utils.eq("File \"array_subtle_test.res\", line 45, characters 7-14", 5, v.length); }); Mocha.test("array_mutation_test", () => { let v = [ @@ -73,9 +76,9 @@ Mocha.describe("Array_subtle_test", () => { 3, 3 ]; - Test_utils.eq("File \"array_subtle_test.res\", line 52, characters 7-14", 3, Primitive_array.get(v, 2)); - Primitive_array.set(v, 2, 4); - Test_utils.eq("File \"array_subtle_test.res\", line 54, characters 7-14", 4, Primitive_array.get(v, 2)); + Test_utils.eq("File \"array_subtle_test.res\", line 50, characters 7-14", 3, v[2]); + v[2] = 4; + Test_utils.eq("File \"array_subtle_test.res\", line 52, characters 7-14", 4, v[2]); }); Mocha.test("array_pop_test", () => { let v = [ @@ -87,19 +90,16 @@ Mocha.describe("Array_subtle_test", () => { while (v.length > 0) { v.pop(); }; - Test_utils.eq("File \"array_subtle_test.res\", line 62, characters 7-14", 0, v.length); + Test_utils.eq("File \"array_subtle_test.res\", line 60, characters 7-14", 0, v.length); }); Mocha.test("array_function_tests", () => { - Test_utils.eq("File \"array_subtle_test.res\", line 66, characters 7-14", 1, fff3([])); - Test_utils.eq("File \"array_subtle_test.res\", line 67, characters 7-14", 2, fff4([])); - Test_utils.eq("File \"array_subtle_test.res\", line 68, characters 7-14", 1, fff4([1])); + Test_utils.eq("File \"array_subtle_test.res\", line 64, characters 7-14", 1, fff3([])); + Test_utils.eq("File \"array_subtle_test.res\", line 65, characters 7-14", 2, fff4([])); + Test_utils.eq("File \"array_subtle_test.res\", line 66, characters 7-14", 1, fff4([1])); }); }); -let $$Array; - export { - $$Array, v, f, fff, diff --git a/tests/tests/src/array_subtle_test.res b/tests/tests/src/array_subtle_test.res index c71af5b726..b23871eff3 100644 --- a/tests/tests/src/array_subtle_test.res +++ b/tests/tests/src/array_subtle_test.res @@ -1,8 +1,6 @@ open Mocha open Test_utils -module Array = Ocaml_Array - let v = [1, 2, 3, 3] let f = v => { @@ -49,9 +47,9 @@ describe(__MODULE__, () => { test("array_mutation_test", () => { let v = [1, 2, 3, 3] - eq(__LOC__, 3, v[2]) - v[2] = 4 - eq(__LOC__, 4, v[2]) + eq(__LOC__, 3, v->Array.getUnsafe(2)) + v->Array.setUnsafe(2, 4) + eq(__LOC__, 4, v->Array.getUnsafe(2)) }) test("array_pop_test", () => { diff --git a/tests/tests/src/bdd.mjs b/tests/tests/src/bdd.mjs index d31a0d5d43..f98ef56946 100644 --- a/tests/tests/src/bdd.mjs +++ b/tests/tests/src/bdd.mjs @@ -1,7 +1,6 @@ // Generated by ReScript, PLEASE EDIT WITH CARE import * as Belt_Array from "@rescript/runtime/lib/es6/Belt_Array.js"; -import * as Primitive_array from "@rescript/runtime/lib/es6/Primitive_array.js"; function $$eval(_bdd, vars) { while (true) { @@ -9,7 +8,7 @@ function $$eval(_bdd, vars) { if (typeof bdd !== "object") { return bdd === "One"; } - if (Primitive_array.get(vars, bdd._1)) { + if (vars[bdd._1]) { _bdd = bdd._3; continue; } @@ -67,7 +66,7 @@ function resize(newSize) { RE_EXN_ID: "Assert_failure", _1: [ "bdd.res", - 62, + 60, 13 ], Error: new Error() @@ -77,24 +76,24 @@ function resize(newSize) { RE_EXN_ID: "Assert_failure", _1: [ "bdd.res", - 62, + 60, 13 ], Error: new Error() }; } else { let ind = hashVal(getId(n._0), getId(n._3), n._1) & newSz_1; - Primitive_array.set(newArr, ind, { + newArr[ind] = { hd: n, - tl: Primitive_array.get(newArr, ind) - }); + tl: newArr[ind] + }; _bucket = bucket.tl; continue; } }; }; for (let n = 0, n_finish = sz_1.contents; n <= n_finish; ++n) { - copyBucket(Primitive_array.get(arr, n)); + copyBucket(arr[n]); } htab.contents = newArr; sz_1.contents = newSz_1; @@ -102,19 +101,19 @@ function resize(newSize) { function insert(idl, idh, v, ind, bucket, newNode) { if (n_items.contents <= sz_1.contents) { - Primitive_array.set(htab.contents, ind, { + htab.contents[ind] = { hd: newNode, tl: bucket - }); + }; n_items.contents = n_items.contents + 1 | 0; return; } resize((sz_1.contents + sz_1.contents | 0) + 2 | 0); let ind$1 = hashVal(idl, idh, v) & sz_1.contents; - Primitive_array.set(htab.contents, ind$1, { + htab.contents[ind$1] = { hd: newNode, - tl: Primitive_array.get(htab.contents, ind$1) - }); + tl: htab.contents[ind$1] + }; } function resetUnique() { @@ -131,7 +130,7 @@ function mkNode(low, v, high) { return low; } let ind = hashVal(idl, idh, v) & sz_1.contents; - let bucket = Primitive_array.get(htab.contents, ind); + let bucket = htab.contents[ind]; let _b = bucket; while (true) { let b = _b; @@ -143,7 +142,7 @@ function mkNode(low, v, high) { RE_EXN_ID: "Assert_failure", _1: [ "bdd.res", - 123, + 121, 15 ], Error: new Error() @@ -153,7 +152,7 @@ function mkNode(low, v, high) { RE_EXN_ID: "Assert_failure", _1: [ "bdd.res", - 123, + 121, 15 ], Error: new Error() @@ -224,12 +223,12 @@ function not(n) { } let id = n._2; let h = id % 1999; - if (id === Primitive_array.get(notslot1, h)) { - return Primitive_array.get(notslot2, h); + if (id === notslot1[h]) { + return notslot2[h]; } let f = mkNode(not(n._0), n._1, not(n._3)); - Primitive_array.set(notslot1, h, id); - Primitive_array.set(notslot2, h, f); + notslot1[h] = id; + notslot2[h] = f; return f; } @@ -257,8 +256,8 @@ function and2(n1, n2) { let v2 = n2._1; let l2 = n2._0; let h = hash(i1, i2); - if (i1 === Primitive_array.get(andslot1, h) && i2 === Primitive_array.get(andslot2, h)) { - return Primitive_array.get(andslot3, h); + if (i1 === andslot1[h] && i2 === andslot2[h]) { + return andslot3[h]; } let match = cmpVar(v1, v2); let f; @@ -273,9 +272,9 @@ function and2(n1, n2) { f = mkNode(and2(n1, l2), v2, and2(n1, r2)); break; } - Primitive_array.set(andslot1, h, i1); - Primitive_array.set(andslot2, h, i2); - Primitive_array.set(andslot3, h, f); + andslot1[h] = i1; + andslot2[h] = i2; + andslot3[h] = f; return f; } @@ -303,8 +302,8 @@ function xor(n1, n2) { let v2 = n2._1; let l2 = n2._0; let h = hash(i1, i2); - if (i1 === Primitive_array.get(andslot1, h) && i2 === Primitive_array.get(andslot2, h)) { - return Primitive_array.get(andslot3, h); + if (i1 === andslot1[h] && i2 === andslot2[h]) { + return andslot3[h]; } let match = cmpVar(v1, v2); let f; @@ -319,9 +318,9 @@ function xor(n1, n2) { f = mkNode(xor(n1, l2), v2, xor(n1, r2)); break; } - Primitive_array.set(andslot1, h, i1); - Primitive_array.set(andslot2, h, i2); - Primitive_array.set(andslot3, h, f); + andslot1[h] = i1; + andslot2[h] = i2; + andslot3[h] = f; return f; } @@ -355,7 +354,7 @@ function random() { function random_vars(n) { let vars = Belt_Array.make(n, false); for (let i = 0; i < n; ++i) { - Primitive_array.set(vars, i, random()); + vars[i] = random(); } return vars; } @@ -371,12 +370,12 @@ function bool_equal(a, b) { function test_hwb(bdd, vars) { let ntrue = 0; for (let i = 0, i_finish = vars.length; i < i_finish; ++i) { - if (Primitive_array.get(vars, i)) { + if (vars[i]) { ntrue = ntrue + 1 | 0; } } - return bool_equal($$eval(bdd, vars), ntrue > 0 ? Primitive_array.get(vars, ntrue - 1 | 0) : false); + return bool_equal($$eval(bdd, vars), ntrue > 0 ? vars[ntrue - 1 | 0] : false); } function main() { @@ -392,7 +391,7 @@ function main() { RE_EXN_ID: "Assert_failure", _1: [ "bdd.res", - 304, + 302, 2 ], Error: new Error() @@ -401,8 +400,6 @@ function main() { main(); -let $$Array; - let initSize_1 = 8191; let zero = "Zero"; @@ -412,7 +409,6 @@ let one = "One"; let cacheSize = 1999; export { - $$Array, $$eval, getId, initSize_1, diff --git a/tests/tests/src/bdd.res b/tests/tests/src/bdd.res index e956cf2050..32a89c26f6 100644 --- a/tests/tests/src/bdd.res +++ b/tests/tests/src/bdd.res @@ -15,8 +15,6 @@ /* Translated to Caml by Xavier Leroy */ /* Original code written in SML by ... */ -module Array = Ocaml_Array - type rec bdd = One | Zero | Node(bdd, int, int, bdd) let rec eval = (bdd, vars) => @@ -24,7 +22,7 @@ let rec eval = (bdd, vars) => | Zero => false | One => true | Node(l, v, _, h) => - if vars[v] { + if vars->Array.getUnsafe(v) { eval(h, vars) } else { eval(l, vars) @@ -57,14 +55,14 @@ let resize = newSize => { | Node(l, v, _, h) => let ind = land(hashVal(getId(l), getId(h), v), newSz_1) - newArr[ind] = list{n, ...newArr[ind]} + newArr->Array.setUnsafe(ind, list{n, ...newArr->Array.getUnsafe(ind)}) copyBucket(ns) | _ => assert(false) } } for n in 0 to sz_1.contents { - copyBucket(arr[n]) + copyBucket(arr->Array.getUnsafe(n)) } htab := newArr sz_1 := newSz_1 @@ -72,13 +70,13 @@ let resize = newSize => { let rec insert = (idl, idh, v, ind, bucket, newNode) => if n_items.contents <= sz_1.contents { - htab.contents[ind] = list{newNode, ...bucket} + htab.contents->Array.setUnsafe(ind, list{newNode, ...bucket}) incr(n_items) } else { resize(sz_1.contents + sz_1.contents + 2) let ind = land(hashVal(idl, idh, v), sz_1.contents) - htab.contents[ind] = list{newNode, ...htab.contents[ind]} + htab.contents->Array.setUnsafe(ind, list{newNode, ...htab.contents->Array.getUnsafe(ind)}) } let resetUnique = () => { @@ -96,7 +94,7 @@ let mkNode = (low, v, high) => { low } else { let ind = land(hashVal(idl, idh, v), sz_1.contents) - let bucket = htab.contents[ind] + let bucket = htab.contents->Array.getUnsafe(ind) let rec lookup = b => switch b { | list{} => @@ -163,13 +161,13 @@ let rec not = n => | Node(l, v, id, r) => let h = mod(id, cacheSize) - if id == notslot1[h] { - notslot2[h] + if id == notslot1->Array.getUnsafe(h) { + notslot2->Array.getUnsafe(h) } else { let f = mkNode(!l, v, !r) - notslot1[h] = id - notslot2[h] = f + notslot1->Array.setUnsafe(h, id) + notslot2->Array.setUnsafe(h, f) f } } @@ -181,8 +179,8 @@ let rec and2 = (n1, n2) => | Node(l2, v2, i2, r2) => let h = hash(i1, i2) - if i1 == andslot1[h] && i2 == andslot2[h] { - andslot3[h] + if i1 == andslot1->Array.getUnsafe(h) && i2 == andslot2->Array.getUnsafe(h) { + andslot3->Array.getUnsafe(h) } else { let f = switch cmpVar(v1, v2) { | EQUAL => mkNode(and2(l1, l2), v1, and2(r1, r2)) @@ -190,9 +188,9 @@ let rec and2 = (n1, n2) => | GREATER => mkNode(and2(n1, l2), v2, and2(n1, r2)) } - andslot1[h] = i1 - andslot2[h] = i2 - andslot3[h] = f + andslot1->Array.setUnsafe(h, i1) + andslot2->Array.setUnsafe(h, i2) + andslot3->Array.setUnsafe(h, f) f } | Zero => Zero @@ -209,8 +207,8 @@ let rec xor = (n1, n2) => | Node(l2, v2, i2, r2) => let h = hash(i1, i2) - if i1 == andslot1[h] && i2 == andslot2[h] { - andslot3[h] + if i1 == andslot1->Array.getUnsafe(h) && i2 == andslot2->Array.getUnsafe(h) { + andslot3->Array.getUnsafe(h) } else { let f = switch cmpVar(v1, v2) { | EQUAL => mkNode(xor(l1, l2), v1, xor(r1, r2)) @@ -218,9 +216,9 @@ let rec xor = (n1, n2) => | GREATER => mkNode(xor(n1, l2), v2, xor(n1, r2)) } - andslot1[h] = i1 - andslot2[h] = i2 - andslot3[h] = f + andslot1->Array.setUnsafe(h, i1) + andslot2->Array.setUnsafe(h, i2) + andslot3->Array.setUnsafe(h, f) f } | Zero => n1 @@ -258,7 +256,7 @@ let random = () => { let random_vars = n => { let vars = Belt.Array.make(n, false) for i in 0 to n - 1 { - vars[i] = random() + vars->Array.setUnsafe(i, random()) } vars } @@ -277,14 +275,14 @@ let test_hwb = (bdd, vars) => { where n is the number of "true" elements in vars. */ let ntrue = ref(0) for i in 0 to Belt.Array.length(vars) - 1 { - if vars[i] { + if vars->Array.getUnsafe(i) { incr(ntrue) } } bool_equal( eval(bdd, vars), if ntrue.contents > 0 { - vars[ntrue.contents - 1] + vars->Array.getUnsafe(ntrue.contents - 1) } else { false }, diff --git a/tests/tests/src/belt_hashmap_test.mjs b/tests/tests/src/belt_hashmap_test.mjs index 059ba2ad4f..d25b6a19c9 100644 --- a/tests/tests/src/belt_hashmap_test.mjs +++ b/tests/tests/src/belt_hashmap_test.mjs @@ -3,9 +3,9 @@ import * as Mocha from "mocha"; import * as Belt_Id from "@rescript/runtime/lib/es6/Belt_Id.js"; import * as Belt_Array from "@rescript/runtime/lib/es6/Belt_Array.js"; +import * as Hash_utils from "./hash_utils.mjs"; import * as Test_utils from "./test_utils.mjs"; import * as Belt_HashMap from "@rescript/runtime/lib/es6/Belt_HashMap.js"; -import * as Ocaml_Hashtbl from "./ocaml_compat/Ocaml_Hashtbl.mjs"; import * as Primitive_int from "@rescript/runtime/lib/es6/Primitive_int.js"; import * as Belt_SortArray from "@rescript/runtime/lib/es6/Belt_SortArray.js"; import * as Array_data_util from "./array_data_util.mjs"; @@ -14,7 +14,7 @@ function intEq(x, y) { return x === y; } -let intHash = Ocaml_Hashtbl.hash; +let intHash = Hash_utils.hash; let cmp = Primitive_int.compare; @@ -27,8 +27,8 @@ Mocha.describe("Belt_hashmap_test", () => { let u = Belt_Array.concat(Array_data_util.randomRange(30, 100), Array_data_util.randomRange(40, 120)); let v = Belt_Array.zip(u, u); let xx = Belt_HashMap.fromArray(v, Y); - Test_utils.eq("File \"belt_hashmap_test.res\", line 22, characters 7-14", Belt_HashMap.size(xx), 91); - Test_utils.eq("File \"belt_hashmap_test.res\", line 23, characters 7-14", Belt_SortArray.stableSortBy(Belt_HashMap.keysToArray(xx), cmp), Array_data_util.range(30, 120)); + Test_utils.eq("File \"belt_hashmap_test.res\", line 21, characters 7-14", Belt_HashMap.size(xx), 91); + Test_utils.eq("File \"belt_hashmap_test.res\", line 22, characters 7-14", Belt_SortArray.stableSortBy(Belt_HashMap.keysToArray(xx), cmp), Array_data_util.range(30, 120)); }); Mocha.test("mergeMany", () => { Belt_HashMap.mergeMany(empty, [ @@ -49,28 +49,26 @@ Mocha.describe("Belt_hashmap_test", () => { 2 ] ]); - Test_utils.eq("File \"belt_hashmap_test.res\", line 28, characters 7-14", Belt_HashMap.get(empty, 2), 2); - Test_utils.eq("File \"belt_hashmap_test.res\", line 29, characters 7-14", Belt_HashMap.size(empty), 3); + Test_utils.eq("File \"belt_hashmap_test.res\", line 27, characters 7-14", Belt_HashMap.get(empty, 2), 2); + Test_utils.eq("File \"belt_hashmap_test.res\", line 28, characters 7-14", Belt_HashMap.size(empty), 3); }); Mocha.test("remove", () => { let u = Belt_Array.concat(Array_data_util.randomRange(0, 100000), Array_data_util.randomRange(0, 100)); let v = Belt_HashMap.make(40, Y); Belt_HashMap.mergeMany(v, Belt_Array.zip(u, u)); - Test_utils.eq("File \"belt_hashmap_test.res\", line 36, characters 7-14", Belt_HashMap.size(v), 100001); + Test_utils.eq("File \"belt_hashmap_test.res\", line 35, characters 7-14", Belt_HashMap.size(v), 100001); for (let i = 0; i <= 1000; ++i) { Belt_HashMap.remove(v, i); } - Test_utils.eq("File \"belt_hashmap_test.res\", line 40, characters 7-14", Belt_HashMap.size(v), 99000); + Test_utils.eq("File \"belt_hashmap_test.res\", line 39, characters 7-14", Belt_HashMap.size(v), 99000); for (let i$1 = 0; i$1 <= 2000; ++i$1) { Belt_HashMap.remove(v, i$1); } - Test_utils.eq("File \"belt_hashmap_test.res\", line 44, characters 7-14", Belt_HashMap.size(v), 98000); - Test_utils.ok("File \"belt_hashmap_test.res\", line 45, characters 7-14", Belt_Array.every(Array_data_util.range(2001, 100000), x => Belt_HashMap.has(v, x))); + Test_utils.eq("File \"belt_hashmap_test.res\", line 43, characters 7-14", Belt_HashMap.size(v), 98000); + Test_utils.ok("File \"belt_hashmap_test.res\", line 44, characters 7-14", Belt_Array.every(Array_data_util.range(2001, 100000), x => Belt_HashMap.has(v, x))); }); }); -let Hashtbl; - let N; let S; @@ -82,7 +80,6 @@ let A; let So; export { - Hashtbl, N, S, I, diff --git a/tests/tests/src/belt_hashmap_test.res b/tests/tests/src/belt_hashmap_test.res index d9253f3f46..da9f599ff5 100644 --- a/tests/tests/src/belt_hashmap_test.res +++ b/tests/tests/src/belt_hashmap_test.res @@ -1,7 +1,6 @@ open Mocha open Test_utils -module Hashtbl = Ocaml_Hashtbl module N = Belt.HashMap module S = Belt.Map.Int module I = Array_data_util @@ -9,7 +8,7 @@ module A = Belt.Array module So = Belt.SortArray let intEq = (x: int, y) => x == y -let intHash = (x: int) => Hashtbl.hash(x) +let intHash = (x: int) => Hash_utils.hash(x) let cmp = (x: int, y) => compare(x, y) module Y = unpack(Belt.Id.hashable(~eq=intEq, ~hash=intHash)) let empty: N.t = N.make(~id=module(Y), ~hintSize=30) diff --git a/tests/tests/src/bs_mutable_set_test.mjs b/tests/tests/src/bs_mutable_set_test.mjs index 40af29df5e..d55a5bedcf 100644 --- a/tests/tests/src/bs_mutable_set_test.mjs +++ b/tests/tests/src/bs_mutable_set_test.mjs @@ -6,51 +6,50 @@ import * as Belt_Array from "@rescript/runtime/lib/es6/Belt_Array.js"; import * as Belt_Range from "@rescript/runtime/lib/es6/Belt_Range.js"; import * as Test_utils from "./test_utils.mjs"; import * as Array_data_util from "./array_data_util.mjs"; -import * as Primitive_array from "@rescript/runtime/lib/es6/Primitive_array.js"; import * as Belt_MutableSetInt from "@rescript/runtime/lib/es6/Belt_MutableSetInt.js"; Mocha.describe("Bs_mutable_set_test", () => { Mocha.test("mutable set basic operations", () => { let u = Belt_MutableSetInt.fromArray(Array_data_util.range(0, 30)); - Test_utils.ok("File \"bs_mutable_set_test.res\", line 17, characters 7-14", Belt_MutableSetInt.removeCheck(u, 0)); - Test_utils.ok("File \"bs_mutable_set_test.res\", line 18, characters 7-14", !Belt_MutableSetInt.removeCheck(u, 0)); - Test_utils.ok("File \"bs_mutable_set_test.res\", line 19, characters 7-14", Belt_MutableSetInt.removeCheck(u, 30)); - Test_utils.ok("File \"bs_mutable_set_test.res\", line 20, characters 7-14", Belt_MutableSetInt.removeCheck(u, 20)); - Test_utils.eq("File \"bs_mutable_set_test.res\", line 21, characters 7-14", Belt_MutableSetInt.size(u), 28); + Test_utils.ok("File \"bs_mutable_set_test.res\", line 16, characters 7-14", Belt_MutableSetInt.removeCheck(u, 0)); + Test_utils.ok("File \"bs_mutable_set_test.res\", line 17, characters 7-14", !Belt_MutableSetInt.removeCheck(u, 0)); + Test_utils.ok("File \"bs_mutable_set_test.res\", line 18, characters 7-14", Belt_MutableSetInt.removeCheck(u, 30)); + Test_utils.ok("File \"bs_mutable_set_test.res\", line 19, characters 7-14", Belt_MutableSetInt.removeCheck(u, 20)); + Test_utils.eq("File \"bs_mutable_set_test.res\", line 20, characters 7-14", Belt_MutableSetInt.size(u), 28); let r = Array_data_util.randomRange(0, 30); - Test_utils.ok("File \"bs_mutable_set_test.res\", line 23, characters 7-14", 29 === Belt_MutableSetInt.maxUndefined(u)); - Test_utils.ok("File \"bs_mutable_set_test.res\", line 24, characters 7-14", 1 === Belt_MutableSetInt.minUndefined(u)); + Test_utils.ok("File \"bs_mutable_set_test.res\", line 22, characters 7-14", 29 === Belt_MutableSetInt.maxUndefined(u)); + Test_utils.ok("File \"bs_mutable_set_test.res\", line 23, characters 7-14", 1 === Belt_MutableSetInt.minUndefined(u)); Belt_MutableSetInt.add(u, 3); for (let i = 0, i_finish = r.length; i < i_finish; ++i) { Belt_MutableSetInt.remove(u, r[i]); } - Test_utils.ok("File \"bs_mutable_set_test.res\", line 29, characters 7-14", Belt_MutableSetInt.isEmpty(u)); + Test_utils.ok("File \"bs_mutable_set_test.res\", line 28, characters 7-14", Belt_MutableSetInt.isEmpty(u)); Belt_MutableSetInt.add(u, 0); Belt_MutableSetInt.add(u, 1); Belt_MutableSetInt.add(u, 2); Belt_MutableSetInt.add(u, 0); - Test_utils.eq("File \"bs_mutable_set_test.res\", line 34, characters 7-14", Belt_MutableSetInt.size(u), 3); - Test_utils.ok("File \"bs_mutable_set_test.res\", line 35, characters 7-14", !Belt_MutableSetInt.isEmpty(u)); + Test_utils.eq("File \"bs_mutable_set_test.res\", line 33, characters 7-14", Belt_MutableSetInt.size(u), 3); + Test_utils.ok("File \"bs_mutable_set_test.res\", line 34, characters 7-14", !Belt_MutableSetInt.isEmpty(u)); for (let i$1 = 0; i$1 <= 3; ++i$1) { Belt_MutableSetInt.remove(u, i$1); } - Test_utils.ok("File \"bs_mutable_set_test.res\", line 39, characters 7-14", Belt_MutableSetInt.isEmpty(u)); + Test_utils.ok("File \"bs_mutable_set_test.res\", line 38, characters 7-14", Belt_MutableSetInt.isEmpty(u)); Belt_MutableSetInt.mergeMany(u, Array_data_util.randomRange(0, 20000)); Belt_MutableSetInt.mergeMany(u, Array_data_util.randomRange(0, 200)); - Test_utils.eq("File \"bs_mutable_set_test.res\", line 42, characters 7-14", Belt_MutableSetInt.size(u), 20001); + Test_utils.eq("File \"bs_mutable_set_test.res\", line 41, characters 7-14", Belt_MutableSetInt.size(u), 20001); Belt_MutableSetInt.removeMany(u, Array_data_util.randomRange(0, 200)); - Test_utils.eq("File \"bs_mutable_set_test.res\", line 44, characters 7-14", Belt_MutableSetInt.size(u), 19800); + Test_utils.eq("File \"bs_mutable_set_test.res\", line 43, characters 7-14", Belt_MutableSetInt.size(u), 19800); Belt_MutableSetInt.removeMany(u, Array_data_util.randomRange(0, 1000)); - Test_utils.eq("File \"bs_mutable_set_test.res\", line 46, characters 7-14", Belt_MutableSetInt.size(u), 19000); + Test_utils.eq("File \"bs_mutable_set_test.res\", line 45, characters 7-14", Belt_MutableSetInt.size(u), 19000); Belt_MutableSetInt.removeMany(u, Array_data_util.randomRange(0, 1000)); - Test_utils.eq("File \"bs_mutable_set_test.res\", line 48, characters 7-14", Belt_MutableSetInt.size(u), 19000); + Test_utils.eq("File \"bs_mutable_set_test.res\", line 47, characters 7-14", Belt_MutableSetInt.size(u), 19000); Belt_MutableSetInt.removeMany(u, Array_data_util.randomRange(1000, 10000)); - Test_utils.eq("File \"bs_mutable_set_test.res\", line 50, characters 7-14", Belt_MutableSetInt.size(u), 10000); + Test_utils.eq("File \"bs_mutable_set_test.res\", line 49, characters 7-14", Belt_MutableSetInt.size(u), 10000); Belt_MutableSetInt.removeMany(u, Array_data_util.randomRange(10000, 19999)); - Test_utils.eq("File \"bs_mutable_set_test.res\", line 52, characters 7-14", Belt_MutableSetInt.size(u), 1); - Test_utils.ok("File \"bs_mutable_set_test.res\", line 53, characters 7-14", Belt_MutableSetInt.has(u, 20000)); + Test_utils.eq("File \"bs_mutable_set_test.res\", line 51, characters 7-14", Belt_MutableSetInt.size(u), 1); + Test_utils.ok("File \"bs_mutable_set_test.res\", line 52, characters 7-14", Belt_MutableSetInt.has(u, 20000)); Belt_MutableSetInt.removeMany(u, Array_data_util.randomRange(10000, 30000)); - Test_utils.ok("File \"bs_mutable_set_test.res\", line 55, characters 7-14", Belt_MutableSetInt.isEmpty(u)); + Test_utils.ok("File \"bs_mutable_set_test.res\", line 54, characters 7-14", Belt_MutableSetInt.isEmpty(u)); }); Mocha.test("mutable set add/remove operations", () => { let v = Belt_MutableSetInt.fromArray(Array_data_util.randomRange(1000, 2000)); @@ -62,8 +61,8 @@ Mocha.describe("Bs_mutable_set_test", () => { return acc; } }); - Test_utils.eq("File \"bs_mutable_set_test.res\", line 71, characters 7-14", indeedRemoved, 500); - Test_utils.eq("File \"bs_mutable_set_test.res\", line 72, characters 7-14", Belt_MutableSetInt.size(v), 501); + Test_utils.eq("File \"bs_mutable_set_test.res\", line 70, characters 7-14", indeedRemoved, 500); + Test_utils.eq("File \"bs_mutable_set_test.res\", line 71, characters 7-14", Belt_MutableSetInt.size(v), 501); let cs = Belt_Array.map(Array_data_util.randomRange(500, 2000), x => Belt_MutableSetInt.addCheck(v, x)); let indeedAded = Belt_Array.reduce(cs, 0, (acc, x) => { if (x) { @@ -72,53 +71,53 @@ Mocha.describe("Bs_mutable_set_test", () => { return acc; } }); - Test_utils.eq("File \"bs_mutable_set_test.res\", line 84, characters 7-14", indeedAded, 1000); - Test_utils.eq("File \"bs_mutable_set_test.res\", line 85, characters 7-14", Belt_MutableSetInt.size(v), 1501); - Test_utils.ok("File \"bs_mutable_set_test.res\", line 86, characters 7-14", Belt_MutableSetInt.isEmpty(Belt_MutableSetInt.make())); - Test_utils.eq("File \"bs_mutable_set_test.res\", line 87, characters 7-14", Belt_MutableSetInt.minimum(v), 500); - Test_utils.eq("File \"bs_mutable_set_test.res\", line 88, characters 7-14", Belt_MutableSetInt.maximum(v), 2000); - Test_utils.eq("File \"bs_mutable_set_test.res\", line 89, characters 7-14", Belt_MutableSetInt.minUndefined(v), 500); - Test_utils.eq("File \"bs_mutable_set_test.res\", line 90, characters 7-14", Belt_MutableSetInt.maxUndefined(v), 2000); - Test_utils.eq("File \"bs_mutable_set_test.res\", line 91, characters 7-14", Belt_MutableSetInt.reduce(v, 0, (x, y) => x + y | 0), 1876250); - Test_utils.ok("File \"bs_mutable_set_test.res\", line 92, characters 7-14", Belt_List.eq(Belt_MutableSetInt.toList(v), Belt_List.makeBy(1501, i => i + 500 | 0), (x, y) => x === y)); - Test_utils.eq("File \"bs_mutable_set_test.res\", line 93, characters 7-14", Belt_MutableSetInt.toArray(v), Array_data_util.range(500, 2000)); + Test_utils.eq("File \"bs_mutable_set_test.res\", line 83, characters 7-14", indeedAded, 1000); + Test_utils.eq("File \"bs_mutable_set_test.res\", line 84, characters 7-14", Belt_MutableSetInt.size(v), 1501); + Test_utils.ok("File \"bs_mutable_set_test.res\", line 85, characters 7-14", Belt_MutableSetInt.isEmpty(Belt_MutableSetInt.make())); + Test_utils.eq("File \"bs_mutable_set_test.res\", line 86, characters 7-14", Belt_MutableSetInt.minimum(v), 500); + Test_utils.eq("File \"bs_mutable_set_test.res\", line 87, characters 7-14", Belt_MutableSetInt.maximum(v), 2000); + Test_utils.eq("File \"bs_mutable_set_test.res\", line 88, characters 7-14", Belt_MutableSetInt.minUndefined(v), 500); + Test_utils.eq("File \"bs_mutable_set_test.res\", line 89, characters 7-14", Belt_MutableSetInt.maxUndefined(v), 2000); + Test_utils.eq("File \"bs_mutable_set_test.res\", line 90, characters 7-14", Belt_MutableSetInt.reduce(v, 0, (x, y) => x + y | 0), 1876250); + Test_utils.ok("File \"bs_mutable_set_test.res\", line 91, characters 7-14", Belt_List.eq(Belt_MutableSetInt.toList(v), Belt_List.makeBy(1501, i => i + 500 | 0), (x, y) => x === y)); + Test_utils.eq("File \"bs_mutable_set_test.res\", line 92, characters 7-14", Belt_MutableSetInt.toArray(v), Array_data_util.range(500, 2000)); Belt_MutableSetInt.checkInvariantInternal(v); - Test_utils.eq("File \"bs_mutable_set_test.res\", line 95, characters 7-14", Belt_MutableSetInt.get(v, 3), undefined); - Test_utils.eq("File \"bs_mutable_set_test.res\", line 96, characters 7-14", Belt_MutableSetInt.get(v, 1200), 1200); + Test_utils.eq("File \"bs_mutable_set_test.res\", line 94, characters 7-14", Belt_MutableSetInt.get(v, 3), undefined); + Test_utils.eq("File \"bs_mutable_set_test.res\", line 95, characters 7-14", Belt_MutableSetInt.get(v, 1200), 1200); let match = Belt_MutableSetInt.split(v, 1000); let match$1 = match[0]; let bb = match$1[1]; let aa = match$1[0]; - Test_utils.ok("File \"bs_mutable_set_test.res\", line 98, characters 7-14", match[1]); - Test_utils.ok("File \"bs_mutable_set_test.res\", line 99, characters 7-14", Belt_Array.eq(Belt_MutableSetInt.toArray(aa), Array_data_util.range(500, 999), (x, y) => x === y)); - Test_utils.ok("File \"bs_mutable_set_test.res\", line 100, characters 7-14", Belt_Array.eq(Belt_MutableSetInt.toArray(bb), Array_data_util.range(1001, 2000), (x, y) => x === y)); - Test_utils.ok("File \"bs_mutable_set_test.res\", line 101, characters 7-14", Belt_MutableSetInt.subset(aa, v)); - Test_utils.ok("File \"bs_mutable_set_test.res\", line 102, characters 7-14", Belt_MutableSetInt.subset(bb, v)); - Test_utils.ok("File \"bs_mutable_set_test.res\", line 103, characters 7-14", Belt_MutableSetInt.isEmpty(Belt_MutableSetInt.intersect(aa, bb))); + Test_utils.ok("File \"bs_mutable_set_test.res\", line 97, characters 7-14", match[1]); + Test_utils.ok("File \"bs_mutable_set_test.res\", line 98, characters 7-14", Belt_Array.eq(Belt_MutableSetInt.toArray(aa), Array_data_util.range(500, 999), (x, y) => x === y)); + Test_utils.ok("File \"bs_mutable_set_test.res\", line 99, characters 7-14", Belt_Array.eq(Belt_MutableSetInt.toArray(bb), Array_data_util.range(1001, 2000), (x, y) => x === y)); + Test_utils.ok("File \"bs_mutable_set_test.res\", line 100, characters 7-14", Belt_MutableSetInt.subset(aa, v)); + Test_utils.ok("File \"bs_mutable_set_test.res\", line 101, characters 7-14", Belt_MutableSetInt.subset(bb, v)); + Test_utils.ok("File \"bs_mutable_set_test.res\", line 102, characters 7-14", Belt_MutableSetInt.isEmpty(Belt_MutableSetInt.intersect(aa, bb))); let c = Belt_MutableSetInt.removeCheck(v, 1000); - Test_utils.ok("File \"bs_mutable_set_test.res\", line 105, characters 7-14", c); + Test_utils.ok("File \"bs_mutable_set_test.res\", line 104, characters 7-14", c); let match$2 = Belt_MutableSetInt.split(v, 1000); let match$3 = match$2[0]; let bb$1 = match$3[1]; let aa$1 = match$3[0]; - Test_utils.ok("File \"bs_mutable_set_test.res\", line 107, characters 7-14", !match$2[1]); - Test_utils.ok("File \"bs_mutable_set_test.res\", line 108, characters 7-14", Belt_Array.eq(Belt_MutableSetInt.toArray(aa$1), Array_data_util.range(500, 999), (x, y) => x === y)); - Test_utils.ok("File \"bs_mutable_set_test.res\", line 109, characters 7-14", Belt_Array.eq(Belt_MutableSetInt.toArray(bb$1), Array_data_util.range(1001, 2000), (x, y) => x === y)); - Test_utils.ok("File \"bs_mutable_set_test.res\", line 110, characters 7-14", Belt_MutableSetInt.subset(aa$1, v)); - Test_utils.ok("File \"bs_mutable_set_test.res\", line 111, characters 7-14", Belt_MutableSetInt.subset(bb$1, v)); - Test_utils.ok("File \"bs_mutable_set_test.res\", line 112, characters 7-14", Belt_MutableSetInt.isEmpty(Belt_MutableSetInt.intersect(aa$1, bb$1))); + Test_utils.ok("File \"bs_mutable_set_test.res\", line 106, characters 7-14", !match$2[1]); + Test_utils.ok("File \"bs_mutable_set_test.res\", line 107, characters 7-14", Belt_Array.eq(Belt_MutableSetInt.toArray(aa$1), Array_data_util.range(500, 999), (x, y) => x === y)); + Test_utils.ok("File \"bs_mutable_set_test.res\", line 108, characters 7-14", Belt_Array.eq(Belt_MutableSetInt.toArray(bb$1), Array_data_util.range(1001, 2000), (x, y) => x === y)); + Test_utils.ok("File \"bs_mutable_set_test.res\", line 109, characters 7-14", Belt_MutableSetInt.subset(aa$1, v)); + Test_utils.ok("File \"bs_mutable_set_test.res\", line 110, characters 7-14", Belt_MutableSetInt.subset(bb$1, v)); + Test_utils.ok("File \"bs_mutable_set_test.res\", line 111, characters 7-14", Belt_MutableSetInt.isEmpty(Belt_MutableSetInt.intersect(aa$1, bb$1))); }); Mocha.test("mutable set union operations", () => { let aa = Belt_MutableSetInt.fromArray(Array_data_util.randomRange(0, 100)); let bb = Belt_MutableSetInt.fromArray(Array_data_util.randomRange(40, 120)); let cc = Belt_MutableSetInt.union(aa, bb); - Test_utils.ok("File \"bs_mutable_set_test.res\", line 122, characters 7-14", Belt_MutableSetInt.eq(cc, Belt_MutableSetInt.fromArray(Array_data_util.randomRange(0, 120)))); - Test_utils.ok("File \"bs_mutable_set_test.res\", line 125, characters 6-13", Belt_MutableSetInt.eq(Belt_MutableSetInt.union(Belt_MutableSetInt.fromArray(Array_data_util.randomRange(0, 20)), Belt_MutableSetInt.fromArray(Array_data_util.randomRange(21, 40))), Belt_MutableSetInt.fromArray(Array_data_util.randomRange(0, 40)))); + Test_utils.ok("File \"bs_mutable_set_test.res\", line 121, characters 7-14", Belt_MutableSetInt.eq(cc, Belt_MutableSetInt.fromArray(Array_data_util.randomRange(0, 120)))); + Test_utils.ok("File \"bs_mutable_set_test.res\", line 124, characters 6-13", Belt_MutableSetInt.eq(Belt_MutableSetInt.union(Belt_MutableSetInt.fromArray(Array_data_util.randomRange(0, 20)), Belt_MutableSetInt.fromArray(Array_data_util.randomRange(21, 40))), Belt_MutableSetInt.fromArray(Array_data_util.randomRange(0, 40)))); let dd = Belt_MutableSetInt.intersect(aa, bb); - Test_utils.ok("File \"bs_mutable_set_test.res\", line 129, characters 7-14", Belt_MutableSetInt.eq(dd, Belt_MutableSetInt.fromArray(Array_data_util.randomRange(40, 100)))); - Test_utils.ok("File \"bs_mutable_set_test.res\", line 130, characters 7-14", Belt_MutableSetInt.eq(Belt_MutableSetInt.intersect(Belt_MutableSetInt.fromArray(Array_data_util.randomRange(0, 20)), Belt_MutableSetInt.fromArray(Array_data_util.randomRange(21, 40))), Belt_MutableSetInt.make())); - Test_utils.ok("File \"bs_mutable_set_test.res\", line 131, characters 7-14", Belt_MutableSetInt.eq(Belt_MutableSetInt.intersect(Belt_MutableSetInt.fromArray(Array_data_util.randomRange(21, 40)), Belt_MutableSetInt.fromArray(Array_data_util.randomRange(0, 20))), Belt_MutableSetInt.make())); - Test_utils.ok("File \"bs_mutable_set_test.res\", line 132, characters 7-14", Belt_MutableSetInt.eq(Belt_MutableSetInt.intersect(Belt_MutableSetInt.fromArray([ + Test_utils.ok("File \"bs_mutable_set_test.res\", line 128, characters 7-14", Belt_MutableSetInt.eq(dd, Belt_MutableSetInt.fromArray(Array_data_util.randomRange(40, 100)))); + Test_utils.ok("File \"bs_mutable_set_test.res\", line 129, characters 7-14", Belt_MutableSetInt.eq(Belt_MutableSetInt.intersect(Belt_MutableSetInt.fromArray(Array_data_util.randomRange(0, 20)), Belt_MutableSetInt.fromArray(Array_data_util.randomRange(21, 40))), Belt_MutableSetInt.make())); + Test_utils.ok("File \"bs_mutable_set_test.res\", line 130, characters 7-14", Belt_MutableSetInt.eq(Belt_MutableSetInt.intersect(Belt_MutableSetInt.fromArray(Array_data_util.randomRange(21, 40)), Belt_MutableSetInt.fromArray(Array_data_util.randomRange(0, 20))), Belt_MutableSetInt.make())); + Test_utils.ok("File \"bs_mutable_set_test.res\", line 131, characters 7-14", Belt_MutableSetInt.eq(Belt_MutableSetInt.intersect(Belt_MutableSetInt.fromArray([ 1, 3, 4, @@ -136,11 +135,11 @@ Mocha.describe("Bs_mutable_set_test", () => { 4, 5 ]))); - Test_utils.ok("File \"bs_mutable_set_test.res\", line 133, characters 7-14", Belt_MutableSetInt.eq(Belt_MutableSetInt.diff(aa, bb), Belt_MutableSetInt.fromArray(Array_data_util.randomRange(0, 39)))); - Test_utils.ok("File \"bs_mutable_set_test.res\", line 134, characters 7-14", Belt_MutableSetInt.eq(Belt_MutableSetInt.diff(bb, aa), Belt_MutableSetInt.fromArray(Array_data_util.randomRange(101, 120)))); - Test_utils.ok("File \"bs_mutable_set_test.res\", line 136, characters 6-13", Belt_MutableSetInt.eq(Belt_MutableSetInt.diff(Belt_MutableSetInt.fromArray(Array_data_util.randomRange(21, 40)), Belt_MutableSetInt.fromArray(Array_data_util.randomRange(0, 20))), Belt_MutableSetInt.fromArray(Array_data_util.randomRange(21, 40)))); - Test_utils.ok("File \"bs_mutable_set_test.res\", line 140, characters 6-13", Belt_MutableSetInt.eq(Belt_MutableSetInt.diff(Belt_MutableSetInt.fromArray(Array_data_util.randomRange(0, 20)), Belt_MutableSetInt.fromArray(Array_data_util.randomRange(21, 40))), Belt_MutableSetInt.fromArray(Array_data_util.randomRange(0, 20)))); - Test_utils.ok("File \"bs_mutable_set_test.res\", line 145, characters 6-13", Belt_MutableSetInt.eq(Belt_MutableSetInt.diff(Belt_MutableSetInt.fromArray(Array_data_util.randomRange(0, 20)), Belt_MutableSetInt.fromArray(Array_data_util.randomRange(0, 40))), Belt_MutableSetInt.fromArray(Array_data_util.randomRange(0, -1)))); + Test_utils.ok("File \"bs_mutable_set_test.res\", line 132, characters 7-14", Belt_MutableSetInt.eq(Belt_MutableSetInt.diff(aa, bb), Belt_MutableSetInt.fromArray(Array_data_util.randomRange(0, 39)))); + Test_utils.ok("File \"bs_mutable_set_test.res\", line 133, characters 7-14", Belt_MutableSetInt.eq(Belt_MutableSetInt.diff(bb, aa), Belt_MutableSetInt.fromArray(Array_data_util.randomRange(101, 120)))); + Test_utils.ok("File \"bs_mutable_set_test.res\", line 135, characters 6-13", Belt_MutableSetInt.eq(Belt_MutableSetInt.diff(Belt_MutableSetInt.fromArray(Array_data_util.randomRange(21, 40)), Belt_MutableSetInt.fromArray(Array_data_util.randomRange(0, 20))), Belt_MutableSetInt.fromArray(Array_data_util.randomRange(21, 40)))); + Test_utils.ok("File \"bs_mutable_set_test.res\", line 139, characters 6-13", Belt_MutableSetInt.eq(Belt_MutableSetInt.diff(Belt_MutableSetInt.fromArray(Array_data_util.randomRange(0, 20)), Belt_MutableSetInt.fromArray(Array_data_util.randomRange(21, 40))), Belt_MutableSetInt.fromArray(Array_data_util.randomRange(0, 20)))); + Test_utils.ok("File \"bs_mutable_set_test.res\", line 144, characters 6-13", Belt_MutableSetInt.eq(Belt_MutableSetInt.diff(Belt_MutableSetInt.fromArray(Array_data_util.randomRange(0, 20)), Belt_MutableSetInt.fromArray(Array_data_util.randomRange(0, 40))), Belt_MutableSetInt.fromArray(Array_data_util.randomRange(0, -1)))); }); Mocha.test("mutable set keep/partition operations", () => { let a0 = Belt_MutableSetInt.fromArray(Array_data_util.randomRange(0, 1000)); @@ -149,8 +148,8 @@ Mocha.describe("Bs_mutable_set_test", () => { let match = Belt_MutableSetInt.partition(a0, x => x % 2 === 0); let a4 = match[1]; let a3 = match[0]; - Test_utils.ok("File \"bs_mutable_set_test.res\", line 154, characters 7-14", Belt_MutableSetInt.eq(a1, a3)); - Test_utils.ok("File \"bs_mutable_set_test.res\", line 155, characters 7-14", Belt_MutableSetInt.eq(a2, a4)); + Test_utils.ok("File \"bs_mutable_set_test.res\", line 153, characters 7-14", Belt_MutableSetInt.eq(a1, a3)); + Test_utils.ok("File \"bs_mutable_set_test.res\", line 154, characters 7-14", Belt_MutableSetInt.eq(a2, a4)); Belt_List.forEach({ hd: a0, tl: { @@ -174,45 +173,45 @@ Mocha.describe("Bs_mutable_set_test", () => { Belt_MutableSetInt.add(v, i); } Belt_MutableSetInt.checkInvariantInternal(v); - Test_utils.ok("File \"bs_mutable_set_test.res\", line 165, characters 7-14", Belt_Range.every(0, 100000, i => Belt_MutableSetInt.has(v, i))); - Test_utils.eq("File \"bs_mutable_set_test.res\", line 166, characters 7-14", Belt_MutableSetInt.size(v), 100001); + Test_utils.ok("File \"bs_mutable_set_test.res\", line 164, characters 7-14", Belt_Range.every(0, 100000, i => Belt_MutableSetInt.has(v, i))); + Test_utils.eq("File \"bs_mutable_set_test.res\", line 165, characters 7-14", Belt_MutableSetInt.size(v), 100001); }); Mocha.test("mutable set merge operations", () => { let u = Belt_Array.concat(Array_data_util.randomRange(30, 100), Array_data_util.randomRange(40, 120)); let v = Belt_MutableSetInt.make(); Belt_MutableSetInt.mergeMany(v, u); - Test_utils.eq("File \"bs_mutable_set_test.res\", line 173, characters 7-14", Belt_MutableSetInt.size(v), 91); - Test_utils.eq("File \"bs_mutable_set_test.res\", line 174, characters 7-14", Belt_MutableSetInt.toArray(v), Array_data_util.range(30, 120)); + Test_utils.eq("File \"bs_mutable_set_test.res\", line 172, characters 7-14", Belt_MutableSetInt.size(v), 91); + Test_utils.eq("File \"bs_mutable_set_test.res\", line 173, characters 7-14", Belt_MutableSetInt.toArray(v), Array_data_util.range(30, 120)); }); Mocha.test("mutable set remove many operations", () => { let u = Belt_Array.concat(Array_data_util.randomRange(0, 100000), Array_data_util.randomRange(0, 100)); let v = Belt_MutableSetInt.fromArray(u); - Test_utils.eq("File \"bs_mutable_set_test.res\", line 180, characters 7-14", Belt_MutableSetInt.size(v), 100001); + Test_utils.eq("File \"bs_mutable_set_test.res\", line 179, characters 7-14", Belt_MutableSetInt.size(v), 100001); let u$1 = Array_data_util.randomRange(50000, 80000); for (let i = 0, i_finish = u$1.length; i < i_finish; ++i) { Belt_MutableSetInt.remove(v, i); } - Test_utils.eq("File \"bs_mutable_set_test.res\", line 187, characters 7-14", Belt_MutableSetInt.size(v), 70000); + Test_utils.eq("File \"bs_mutable_set_test.res\", line 186, characters 7-14", Belt_MutableSetInt.size(v), 70000); let vv = Array_data_util.randomRange(0, 100000); for (let i$1 = 0, i_finish$1 = vv.length; i$1 < i_finish$1; ++i$1) { - Belt_MutableSetInt.remove(v, Primitive_array.get(vv, i$1)); + Belt_MutableSetInt.remove(v, vv[i$1]); } - Test_utils.eq("File \"bs_mutable_set_test.res\", line 193, characters 7-14", Belt_MutableSetInt.size(v), 0); - Test_utils.ok("File \"bs_mutable_set_test.res\", line 194, characters 7-14", Belt_MutableSetInt.isEmpty(v)); + Test_utils.eq("File \"bs_mutable_set_test.res\", line 192, characters 7-14", Belt_MutableSetInt.size(v), 0); + Test_utils.ok("File \"bs_mutable_set_test.res\", line 193, characters 7-14", Belt_MutableSetInt.isEmpty(v)); }); Mocha.test("mutable set min/max operations", () => { let v = Belt_MutableSetInt.fromArray(Belt_Array.makeBy(30, i => i)); Belt_MutableSetInt.remove(v, 30); Belt_MutableSetInt.remove(v, 29); - Test_utils.ok("File \"bs_mutable_set_test.res\", line 201, characters 7-14", 28 === Belt_MutableSetInt.maxUndefined(v)); + Test_utils.ok("File \"bs_mutable_set_test.res\", line 200, characters 7-14", 28 === Belt_MutableSetInt.maxUndefined(v)); Belt_MutableSetInt.remove(v, 0); - Test_utils.ok("File \"bs_mutable_set_test.res\", line 203, characters 7-14", 1 === Belt_MutableSetInt.minUndefined(v)); - Test_utils.eq("File \"bs_mutable_set_test.res\", line 204, characters 7-14", Belt_MutableSetInt.size(v), 28); + Test_utils.ok("File \"bs_mutable_set_test.res\", line 202, characters 7-14", 1 === Belt_MutableSetInt.minUndefined(v)); + Test_utils.eq("File \"bs_mutable_set_test.res\", line 203, characters 7-14", Belt_MutableSetInt.size(v), 28); let vv = Array_data_util.randomRange(1, 28); for (let i = 0, i_finish = vv.length; i < i_finish; ++i) { - Belt_MutableSetInt.remove(v, Primitive_array.get(vv, i)); + Belt_MutableSetInt.remove(v, vv[i]); } - Test_utils.eq("File \"bs_mutable_set_test.res\", line 209, characters 7-14", Belt_MutableSetInt.size(v), 0); + Test_utils.eq("File \"bs_mutable_set_test.res\", line 208, characters 7-14", Belt_MutableSetInt.size(v), 0); }); Mocha.test("mutable set fromSortedArrayUnsafe", () => { let id = (loc, x) => { @@ -220,31 +219,31 @@ Mocha.describe("Bs_mutable_set_test", () => { Belt_MutableSetInt.checkInvariantInternal(u); Test_utils.ok(loc, Belt_Array.every2(Belt_MutableSetInt.toArray(u), x, (x, y) => x === y)); }; - id("File \"bs_mutable_set_test.res\", line 219, characters 7-14", []); - id("File \"bs_mutable_set_test.res\", line 220, characters 7-14", [0]); - id("File \"bs_mutable_set_test.res\", line 221, characters 7-14", [ + id("File \"bs_mutable_set_test.res\", line 218, characters 7-14", []); + id("File \"bs_mutable_set_test.res\", line 219, characters 7-14", [0]); + id("File \"bs_mutable_set_test.res\", line 220, characters 7-14", [ 0, 1 ]); - id("File \"bs_mutable_set_test.res\", line 222, characters 7-14", [ + id("File \"bs_mutable_set_test.res\", line 221, characters 7-14", [ 0, 1, 2 ]); - id("File \"bs_mutable_set_test.res\", line 223, characters 7-14", [ + id("File \"bs_mutable_set_test.res\", line 222, characters 7-14", [ 0, 1, 2, 3 ]); - id("File \"bs_mutable_set_test.res\", line 224, characters 7-14", [ + id("File \"bs_mutable_set_test.res\", line 223, characters 7-14", [ 0, 1, 2, 3, 4 ]); - id("File \"bs_mutable_set_test.res\", line 225, characters 7-14", [ + id("File \"bs_mutable_set_test.res\", line 224, characters 7-14", [ 0, 1, 2, @@ -252,7 +251,7 @@ Mocha.describe("Bs_mutable_set_test", () => { 4, 5 ]); - id("File \"bs_mutable_set_test.res\", line 226, characters 7-14", [ + id("File \"bs_mutable_set_test.res\", line 225, characters 7-14", [ 0, 1, 2, @@ -260,7 +259,7 @@ Mocha.describe("Bs_mutable_set_test", () => { 4, 6 ]); - id("File \"bs_mutable_set_test.res\", line 227, characters 7-14", [ + id("File \"bs_mutable_set_test.res\", line 226, characters 7-14", [ 0, 1, 2, @@ -269,7 +268,7 @@ Mocha.describe("Bs_mutable_set_test", () => { 6, 7 ]); - id("File \"bs_mutable_set_test.res\", line 228, characters 7-14", [ + id("File \"bs_mutable_set_test.res\", line 227, characters 7-14", [ 0, 1, 2, @@ -279,7 +278,7 @@ Mocha.describe("Bs_mutable_set_test", () => { 7, 8 ]); - id("File \"bs_mutable_set_test.res\", line 229, characters 7-14", [ + id("File \"bs_mutable_set_test.res\", line 228, characters 7-14", [ 0, 1, 2, @@ -290,7 +289,7 @@ Mocha.describe("Bs_mutable_set_test", () => { 8, 9 ]); - id("File \"bs_mutable_set_test.res\", line 230, characters 7-14", Array_data_util.range(0, 1000)); + id("File \"bs_mutable_set_test.res\", line 229, characters 7-14", Array_data_util.range(0, 1000)); }); Mocha.test("mutable set keep/partition with mod 8", () => { let v = Belt_MutableSetInt.fromArray(Array_data_util.randomRange(0, 1000)); @@ -300,35 +299,35 @@ Mocha.describe("Bs_mutable_set_test", () => { for (let i = 0; i <= 200; ++i) { Belt_MutableSetInt.remove(v, i); } - Test_utils.eq("File \"bs_mutable_set_test.res\", line 241, characters 7-14", Belt_MutableSetInt.size(copyV), 126); - Test_utils.eq("File \"bs_mutable_set_test.res\", line 242, characters 7-14", Belt_MutableSetInt.toArray(copyV), Belt_Array.makeBy(126, i => (i << 3))); - Test_utils.eq("File \"bs_mutable_set_test.res\", line 243, characters 7-14", Belt_MutableSetInt.size(v), 800); - Test_utils.ok("File \"bs_mutable_set_test.res\", line 244, characters 7-14", Belt_MutableSetInt.eq(copyV, match[0])); - Test_utils.ok("File \"bs_mutable_set_test.res\", line 245, characters 7-14", Belt_MutableSetInt.eq(cc, match[1])); + Test_utils.eq("File \"bs_mutable_set_test.res\", line 240, characters 7-14", Belt_MutableSetInt.size(copyV), 126); + Test_utils.eq("File \"bs_mutable_set_test.res\", line 241, characters 7-14", Belt_MutableSetInt.toArray(copyV), Belt_Array.makeBy(126, i => (i << 3))); + Test_utils.eq("File \"bs_mutable_set_test.res\", line 242, characters 7-14", Belt_MutableSetInt.size(v), 800); + Test_utils.ok("File \"bs_mutable_set_test.res\", line 243, characters 7-14", Belt_MutableSetInt.eq(copyV, match[0])); + Test_utils.ok("File \"bs_mutable_set_test.res\", line 244, characters 7-14", Belt_MutableSetInt.eq(cc, match[1])); }); Mocha.test("mutable set split operations", () => { let v = Belt_MutableSetInt.fromArray(Array_data_util.randomRange(0, 1000)); let match = Belt_MutableSetInt.split(v, 400); let match$1 = match[0]; - Test_utils.ok("File \"bs_mutable_set_test.res\", line 251, characters 7-14", Belt_MutableSetInt.eq(match$1[0], Belt_MutableSetInt.fromArray(Array_data_util.randomRange(0, 399)))); - Test_utils.ok("File \"bs_mutable_set_test.res\", line 252, characters 7-14", Belt_MutableSetInt.eq(match$1[1], Belt_MutableSetInt.fromArray(Array_data_util.randomRange(401, 1000)))); + Test_utils.ok("File \"bs_mutable_set_test.res\", line 250, characters 7-14", Belt_MutableSetInt.eq(match$1[0], Belt_MutableSetInt.fromArray(Array_data_util.randomRange(0, 399)))); + Test_utils.ok("File \"bs_mutable_set_test.res\", line 251, characters 7-14", Belt_MutableSetInt.eq(match$1[1], Belt_MutableSetInt.fromArray(Array_data_util.randomRange(401, 1000)))); let d = Belt_MutableSetInt.fromArray(Belt_Array.map(Array_data_util.randomRange(0, 1000), x => (x << 1))); let match$2 = Belt_MutableSetInt.split(d, 1001); let match$3 = match$2[0]; - Test_utils.ok("File \"bs_mutable_set_test.res\", line 255, characters 7-14", Belt_MutableSetInt.eq(match$3[0], Belt_MutableSetInt.fromArray(Belt_Array.makeBy(501, x => (x << 1))))); - Test_utils.ok("File \"bs_mutable_set_test.res\", line 256, characters 7-14", Belt_MutableSetInt.eq(match$3[1], Belt_MutableSetInt.fromArray(Belt_Array.makeBy(500, x => 1002 + (x << 1) | 0)))); + Test_utils.ok("File \"bs_mutable_set_test.res\", line 254, characters 7-14", Belt_MutableSetInt.eq(match$3[0], Belt_MutableSetInt.fromArray(Belt_Array.makeBy(501, x => (x << 1))))); + Test_utils.ok("File \"bs_mutable_set_test.res\", line 255, characters 7-14", Belt_MutableSetInt.eq(match$3[1], Belt_MutableSetInt.fromArray(Belt_Array.makeBy(500, x => 1002 + (x << 1) | 0)))); }); Mocha.test("mutable set final union operations", () => { let aa = Belt_MutableSetInt.fromArray(Array_data_util.randomRange(0, 100)); let bb = Belt_MutableSetInt.fromArray(Array_data_util.randomRange(40, 120)); let cc = Belt_MutableSetInt.union(aa, bb); - Test_utils.ok("File \"bs_mutable_set_test.res\", line 266, characters 7-14", Belt_MutableSetInt.eq(cc, Belt_MutableSetInt.fromArray(Array_data_util.randomRange(0, 120)))); - Test_utils.ok("File \"bs_mutable_set_test.res\", line 269, characters 6-13", Belt_MutableSetInt.eq(Belt_MutableSetInt.union(Belt_MutableSetInt.fromArray(Array_data_util.randomRange(0, 20)), Belt_MutableSetInt.fromArray(Array_data_util.randomRange(21, 40))), Belt_MutableSetInt.fromArray(Array_data_util.randomRange(0, 40)))); + Test_utils.ok("File \"bs_mutable_set_test.res\", line 265, characters 7-14", Belt_MutableSetInt.eq(cc, Belt_MutableSetInt.fromArray(Array_data_util.randomRange(0, 120)))); + Test_utils.ok("File \"bs_mutable_set_test.res\", line 268, characters 6-13", Belt_MutableSetInt.eq(Belt_MutableSetInt.union(Belt_MutableSetInt.fromArray(Array_data_util.randomRange(0, 20)), Belt_MutableSetInt.fromArray(Array_data_util.randomRange(21, 40))), Belt_MutableSetInt.fromArray(Array_data_util.randomRange(0, 40)))); let dd = Belt_MutableSetInt.intersect(aa, bb); - Test_utils.ok("File \"bs_mutable_set_test.res\", line 273, characters 7-14", Belt_MutableSetInt.eq(dd, Belt_MutableSetInt.fromArray(Array_data_util.randomRange(40, 100)))); - Test_utils.ok("File \"bs_mutable_set_test.res\", line 274, characters 7-14", Belt_MutableSetInt.eq(Belt_MutableSetInt.intersect(Belt_MutableSetInt.fromArray(Array_data_util.randomRange(0, 20)), Belt_MutableSetInt.fromArray(Array_data_util.randomRange(21, 40))), Belt_MutableSetInt.make())); - Test_utils.ok("File \"bs_mutable_set_test.res\", line 275, characters 7-14", Belt_MutableSetInt.eq(Belt_MutableSetInt.intersect(Belt_MutableSetInt.fromArray(Array_data_util.randomRange(21, 40)), Belt_MutableSetInt.fromArray(Array_data_util.randomRange(0, 20))), Belt_MutableSetInt.make())); - Test_utils.ok("File \"bs_mutable_set_test.res\", line 276, characters 7-14", Belt_MutableSetInt.eq(Belt_MutableSetInt.intersect(Belt_MutableSetInt.fromArray([ + Test_utils.ok("File \"bs_mutable_set_test.res\", line 272, characters 7-14", Belt_MutableSetInt.eq(dd, Belt_MutableSetInt.fromArray(Array_data_util.randomRange(40, 100)))); + Test_utils.ok("File \"bs_mutable_set_test.res\", line 273, characters 7-14", Belt_MutableSetInt.eq(Belt_MutableSetInt.intersect(Belt_MutableSetInt.fromArray(Array_data_util.randomRange(0, 20)), Belt_MutableSetInt.fromArray(Array_data_util.randomRange(21, 40))), Belt_MutableSetInt.make())); + Test_utils.ok("File \"bs_mutable_set_test.res\", line 274, characters 7-14", Belt_MutableSetInt.eq(Belt_MutableSetInt.intersect(Belt_MutableSetInt.fromArray(Array_data_util.randomRange(21, 40)), Belt_MutableSetInt.fromArray(Array_data_util.randomRange(0, 20))), Belt_MutableSetInt.make())); + Test_utils.ok("File \"bs_mutable_set_test.res\", line 275, characters 7-14", Belt_MutableSetInt.eq(Belt_MutableSetInt.intersect(Belt_MutableSetInt.fromArray([ 1, 3, 4, @@ -346,18 +345,16 @@ Mocha.describe("Bs_mutable_set_test", () => { 4, 5 ]))); - Test_utils.ok("File \"bs_mutable_set_test.res\", line 277, characters 7-14", Belt_MutableSetInt.eq(Belt_MutableSetInt.diff(aa, bb), Belt_MutableSetInt.fromArray(Array_data_util.randomRange(0, 39)))); - Test_utils.ok("File \"bs_mutable_set_test.res\", line 278, characters 7-14", Belt_MutableSetInt.eq(Belt_MutableSetInt.diff(bb, aa), Belt_MutableSetInt.fromArray(Array_data_util.randomRange(101, 120)))); - Test_utils.ok("File \"bs_mutable_set_test.res\", line 280, characters 6-13", Belt_MutableSetInt.eq(Belt_MutableSetInt.diff(Belt_MutableSetInt.fromArray(Array_data_util.randomRange(21, 40)), Belt_MutableSetInt.fromArray(Array_data_util.randomRange(0, 20))), Belt_MutableSetInt.fromArray(Array_data_util.randomRange(21, 40)))); - Test_utils.ok("File \"bs_mutable_set_test.res\", line 284, characters 6-13", Belt_MutableSetInt.eq(Belt_MutableSetInt.diff(Belt_MutableSetInt.fromArray(Array_data_util.randomRange(0, 20)), Belt_MutableSetInt.fromArray(Array_data_util.randomRange(21, 40))), Belt_MutableSetInt.fromArray(Array_data_util.randomRange(0, 20)))); - Test_utils.ok("File \"bs_mutable_set_test.res\", line 289, characters 6-13", Belt_MutableSetInt.eq(Belt_MutableSetInt.diff(Belt_MutableSetInt.fromArray(Array_data_util.randomRange(0, 20)), Belt_MutableSetInt.fromArray(Array_data_util.randomRange(0, 40))), Belt_MutableSetInt.fromArray(Array_data_util.randomRange(0, -1)))); + Test_utils.ok("File \"bs_mutable_set_test.res\", line 276, characters 7-14", Belt_MutableSetInt.eq(Belt_MutableSetInt.diff(aa, bb), Belt_MutableSetInt.fromArray(Array_data_util.randomRange(0, 39)))); + Test_utils.ok("File \"bs_mutable_set_test.res\", line 277, characters 7-14", Belt_MutableSetInt.eq(Belt_MutableSetInt.diff(bb, aa), Belt_MutableSetInt.fromArray(Array_data_util.randomRange(101, 120)))); + Test_utils.ok("File \"bs_mutable_set_test.res\", line 279, characters 6-13", Belt_MutableSetInt.eq(Belt_MutableSetInt.diff(Belt_MutableSetInt.fromArray(Array_data_util.randomRange(21, 40)), Belt_MutableSetInt.fromArray(Array_data_util.randomRange(0, 20))), Belt_MutableSetInt.fromArray(Array_data_util.randomRange(21, 40)))); + Test_utils.ok("File \"bs_mutable_set_test.res\", line 283, characters 6-13", Belt_MutableSetInt.eq(Belt_MutableSetInt.diff(Belt_MutableSetInt.fromArray(Array_data_util.randomRange(0, 20)), Belt_MutableSetInt.fromArray(Array_data_util.randomRange(21, 40))), Belt_MutableSetInt.fromArray(Array_data_util.randomRange(0, 20)))); + Test_utils.ok("File \"bs_mutable_set_test.res\", line 288, characters 6-13", Belt_MutableSetInt.eq(Belt_MutableSetInt.diff(Belt_MutableSetInt.fromArray(Array_data_util.randomRange(0, 20)), Belt_MutableSetInt.fromArray(Array_data_util.randomRange(0, 40))), Belt_MutableSetInt.fromArray(Array_data_util.randomRange(0, -1)))); }); }); let N; -let $$Array; - let I; let R; @@ -372,7 +369,6 @@ let fromArray = Belt_MutableSetInt.fromArray; export { N, - $$Array, I, R, A, diff --git a/tests/tests/src/bs_mutable_set_test.res b/tests/tests/src/bs_mutable_set_test.res index 80a0be6d8f..11a8375bfa 100644 --- a/tests/tests/src/bs_mutable_set_test.res +++ b/tests/tests/src/bs_mutable_set_test.res @@ -2,7 +2,6 @@ open Mocha open Test_utils module N = Belt.MutableSet.Int -module Array = Ocaml_Array module I = Array_data_util module R = Belt.Range @@ -188,7 +187,7 @@ describe(__MODULE__, () => { let count = 100_000 let vv = I.randomRange(0, count) for i in 0 to A.length(vv) - 1 { - N.remove(v, vv[i]) + N.remove(v, vv->Array.getUnsafe(i)) } eq(__LOC__, N.size(v), 0) ok(__LOC__, N.isEmpty(v)) @@ -204,7 +203,7 @@ describe(__MODULE__, () => { eq(__LOC__, N.size(v), 28) let vv = I.randomRange(1, 28) for i in 0 to A.length(vv) - 1 { - N.remove(v, vv[i]) + N.remove(v, vv->Array.getUnsafe(i)) } eq(__LOC__, N.size(v), 0) }) diff --git a/tests/tests/src/chn_test.mjs b/tests/tests/src/chn_test.mjs index f69c6be6a5..11ccd193c9 100644 --- a/tests/tests/src/chn_test.mjs +++ b/tests/tests/src/chn_test.mjs @@ -19,7 +19,7 @@ function convert(s) { RE_EXN_ID: "Assert_failure", _1: [ "chn_test.res", - 15, + 14, 16 ], Error: new Error() @@ -28,9 +28,9 @@ function convert(s) { } Mocha.describe("Chn_test", () => { - Mocha.test("Chinese string newline", () => Test_utils.eq("File \"chn_test.res\", line 24, characters 6-13", `你好, + Mocha.test("Chinese string newline", () => Test_utils.eq("File \"chn_test.res\", line 23, characters 6-13", `你好, 世界`, `你好,\n世界`)); - Mocha.test("Convert Chinese characters", () => Test_utils.eq("File \"chn_test.res\", line 33, characters 6-13", convert(`汉字是世界上最美丽的character`), { + Mocha.test("Convert Chinese characters", () => Test_utils.eq("File \"chn_test.res\", line 32, characters 6-13", convert(`汉字是世界上最美丽的character`), { hd: 27721, tl: { hd: 23383, @@ -88,7 +88,7 @@ Mocha.describe("Chn_test", () => { } } })); - Mocha.test("Convert hex escape", () => Test_utils.eq("File \"chn_test.res\", line 59, characters 38-45", convert(`\x3f\x3fa`), { + Mocha.test("Convert hex escape", () => Test_utils.eq("File \"chn_test.res\", line 58, characters 38-45", convert(`\x3f\x3fa`), { hd: 63, tl: { hd: 63, @@ -98,7 +98,7 @@ Mocha.describe("Chn_test", () => { } } })); - Mocha.test("Convert question marks", () => Test_utils.eq("File \"chn_test.res\", line 60, characters 42-49", convert(`??a`), { + Mocha.test("Convert question marks", () => Test_utils.eq("File \"chn_test.res\", line 59, characters 42-49", convert(`??a`), { hd: 63, tl: { hd: 63, @@ -108,7 +108,7 @@ Mocha.describe("Chn_test", () => { } } })); - Mocha.test("Convert unicode escape", () => Test_utils.eq("File \"chn_test.res\", line 61, characters 42-49", convert(`\u003f\x3fa`), { + Mocha.test("Convert unicode escape", () => Test_utils.eq("File \"chn_test.res\", line 60, characters 42-49", convert(`\u003f\x3fa`), { hd: 63, tl: { hd: 63, @@ -118,7 +118,7 @@ Mocha.describe("Chn_test", () => { } } })); - Mocha.test("Convert rocket emoji with a", () => Test_utils.eq("File \"chn_test.res\", line 63, characters 7-14", convert(`🚀🚀a`), { + Mocha.test("Convert rocket emoji with a", () => Test_utils.eq("File \"chn_test.res\", line 62, characters 7-14", convert(`🚀🚀a`), { hd: 128640, tl: { hd: 128640, @@ -128,21 +128,21 @@ Mocha.describe("Chn_test", () => { } } })); - Mocha.test("Convert rocket emoji surrogate with a", () => Test_utils.eq("File \"chn_test.res\", line 66, characters 7-14", convert(`\uD83D\uDE80a`), { + Mocha.test("Convert rocket emoji surrogate with a", () => Test_utils.eq("File \"chn_test.res\", line 65, characters 7-14", convert(`\uD83D\uDE80a`), { hd: 128640, tl: { hd: 97, tl: /* [] */0 } })); - Mocha.test("Convert rocket emoji surrogate with question", () => Test_utils.eq("File \"chn_test.res\", line 69, characters 7-14", convert(`\uD83D\uDE80\x3f`), { + Mocha.test("Convert rocket emoji surrogate with question", () => Test_utils.eq("File \"chn_test.res\", line 68, characters 7-14", convert(`\uD83D\uDE80\x3f`), { hd: 128640, tl: { hd: 63, tl: /* [] */0 } })); - Mocha.test("Convert double rocket emoji with a", () => Test_utils.eq("File \"chn_test.res\", line 73, characters 7-14", convert(`\uD83D\uDE80\uD83D\uDE80a`), { + Mocha.test("Convert double rocket emoji with a", () => Test_utils.eq("File \"chn_test.res\", line 72, characters 7-14", convert(`\uD83D\uDE80\uD83D\uDE80a`), { hd: 128640, tl: { hd: 128640, @@ -152,21 +152,21 @@ Mocha.describe("Chn_test", () => { } } })); - Mocha.test("String length with emoji", () => Test_utils.eq("File \"chn_test.res\", line 76, characters 44-51", `\uD83D\uDE80\0`.length, 3)); - Mocha.test("String get emoji with null", () => Test_utils.eq("File \"chn_test.res\", line 79, characters 7-14", `\uD83D\uDE80\0`.codePointAt(0), 128640)); - Mocha.test("String get rocket emoji", () => Test_utils.eq("File \"chn_test.res\", line 81, characters 43-50", `🚀`.codePointAt(0), 128640)); - Mocha.test("Convert rocket emoji", () => Test_utils.eq("File \"chn_test.res\", line 83, characters 40-47", convert(`\uD83D\uDE80`), { + Mocha.test("String length with emoji", () => Test_utils.eq("File \"chn_test.res\", line 75, characters 44-51", `\uD83D\uDE80\0`.length, 3)); + Mocha.test("String get emoji with null", () => Test_utils.eq("File \"chn_test.res\", line 78, characters 7-14", `\uD83D\uDE80\0`.codePointAt(0), 128640)); + Mocha.test("String get rocket emoji", () => Test_utils.eq("File \"chn_test.res\", line 80, characters 43-50", `🚀`.codePointAt(0), 128640)); + Mocha.test("Convert rocket emoji", () => Test_utils.eq("File \"chn_test.res\", line 82, characters 40-47", convert(`\uD83D\uDE80`), { hd: 128640, tl: /* [] */0 })); - Mocha.test("Convert double rocket emoji", () => Test_utils.eq("File \"chn_test.res\", line 85, characters 7-14", convert(`\uD83D\uDE80\uD83D\uDE80`), { + Mocha.test("Convert double rocket emoji", () => Test_utils.eq("File \"chn_test.res\", line 84, characters 7-14", convert(`\uD83D\uDE80\uD83D\uDE80`), { hd: 128640, tl: { hd: 128640, tl: /* [] */0 } })); - Mocha.test("Convert whitespace chars", () => Test_utils.eq("File \"chn_test.res\", line 88, characters 7-14", convert(` \b\t\n\v\f\ra`), { + Mocha.test("Convert whitespace chars", () => Test_utils.eq("File \"chn_test.res\", line 87, characters 7-14", convert(` \b\t\n\v\f\ra`), { hd: 32, tl: { hd: 8, @@ -191,7 +191,7 @@ Mocha.describe("Chn_test", () => { } } })); - Mocha.test("Convert escaped chars", () => Test_utils.eq("File \"chn_test.res\", line 91, characters 7-14", convert(` \b\t\n\v\f\r"'\\\0a`), { + Mocha.test("Convert escaped chars", () => Test_utils.eq("File \"chn_test.res\", line 90, characters 7-14", convert(` \b\t\n\v\f\r"'\\\0a`), { hd: 32, tl: { hd: 8, @@ -230,10 +230,7 @@ Mocha.describe("Chn_test", () => { })); }); -let $$String; - export { - $$String, convert, } /* Not a pure module */ diff --git a/tests/tests/src/chn_test.res b/tests/tests/src/chn_test.res index 1112136e5d..d95c9c9608 100644 --- a/tests/tests/src/chn_test.res +++ b/tests/tests/src/chn_test.res @@ -1,7 +1,6 @@ open Mocha open Test_utils open Belt -module String = Ocaml_String Js.log(`你好, 世界`) @@ -76,9 +75,9 @@ describe(__MODULE__, () => { test("String length with emoji", () => eq(__LOC__, String.length(`\uD83D\uDE80\0`), 3)) test("String get emoji with null", () => - eq(__LOC__, (String.get(`\uD83D\uDE80\0`, 0) :> int), 128640) + eq(__LOC__, String.codePointAt(`\uD83D\uDE80\0`, 0), Some(128640)) ) - test("String get rocket emoji", () => eq(__LOC__, (String.get(`🚀`, 0) :> int), 128640)) + test("String get rocket emoji", () => eq(__LOC__, String.codePointAt(`🚀`, 0), Some(128640))) test("Convert rocket emoji", () => eq(__LOC__, convert(`\uD83D\uDE80`), list{128640})) test("Convert double rocket emoji", () => diff --git a/tests/tests/src/const_block_test.mjs b/tests/tests/src/const_block_test.mjs index 43c59c35c6..7c25d4aa96 100644 --- a/tests/tests/src/const_block_test.mjs +++ b/tests/tests/src/const_block_test.mjs @@ -2,7 +2,6 @@ import * as Mocha from "mocha"; import * as Test_utils from "./test_utils.mjs"; -import * as Primitive_array from "@rescript/runtime/lib/es6/Primitive_array.js"; let a = [ 0, @@ -26,8 +25,8 @@ let c = [ ]; function f() { - Primitive_array.set(a, 0, 3.0); - Primitive_array.set(b, 0, 3); + a[0] = 3.0; + b[0] = 3; } function h() { @@ -36,9 +35,9 @@ function h() { function g() { f(); - Test_utils.eq("File \"const_block_test.res\", line 26, characters 5-12", [ - Primitive_array.get(a, 0), - Primitive_array.get(b, 0) + Test_utils.eq("File \"const_block_test.res\", line 25, characters 5-12", [ + a[0], + b[0] ], [ 3.0, 3 @@ -48,9 +47,9 @@ function g() { Mocha.describe("Const_block_test", () => { Mocha.test("const_block_test", () => g()); Mocha.test("avoid_mutable_inline_test", () => { - Primitive_array.set(c, 0, 3); - Primitive_array.set(c, 1, 4); - Test_utils.eq("File \"const_block_test.res\", line 41, characters 7-14", [ + c[0] = 3; + c[1] = 4; + Test_utils.eq("File \"const_block_test.res\", line 40, characters 7-14", [ 3, 4, 2, diff --git a/tests/tests/src/const_block_test.res b/tests/tests/src/const_block_test.res index 9b3e15cfb8..4b80c76bf0 100644 --- a/tests/tests/src/const_block_test.res +++ b/tests/tests/src/const_block_test.res @@ -1,14 +1,13 @@ open Mocha open Test_utils -module Array = Ocaml_Array let a = [0., 1., 2.] let b = [0, 1, 2] let c = [0, 1, 2, 3, 4, 5] let v = (0, 1, 2, 3, 4, 5) let f = () => { - a[0] = 3.0 - b[0] = 3 + a->Array.setUnsafe(0, 3.0) + b->Array.setUnsafe(0, 3) } /** should not be inlined here @@ -23,7 +22,7 @@ let h = () => c */ let g = () => { f() - eq(__LOC__, (a[0], b[0]), (3.0, 3)) + eq(__LOC__, (a->Array.getUnsafe(0), b->Array.getUnsafe(0)), (3.0, 3)) } describe(__MODULE__, () => { @@ -35,8 +34,8 @@ describe(__MODULE__, () => { let v = h() let v2 = h() let () = { - v[0] = 3 - v2[1] = 4 + v->Array.setUnsafe(0, 3) + v2->Array.setUnsafe(1, 4) } eq(__LOC__, [3, 4, 2, 3, 4, 5], v) }) diff --git a/tests/tests/src/equal_exception_test.mjs b/tests/tests/src/equal_exception_test.mjs index e1b1c04172..dafa512dd5 100644 --- a/tests/tests/src/equal_exception_test.mjs +++ b/tests/tests/src/equal_exception_test.mjs @@ -68,7 +68,7 @@ if (Primitive_object.equal(e, { RE_EXN_ID: "Assert_failure", _1: [ "equal_exception_test.res", - 40, + 38, 0 ], Error: new Error() @@ -80,17 +80,14 @@ if (Not_found === "Not_found" !== false) { RE_EXN_ID: "Assert_failure", _1: [ "equal_exception_test.res", - 41, + 39, 0 ], Error: new Error() }; } -let $$String; - export { - $$String, e, eq, Not_found, diff --git a/tests/tests/src/equal_exception_test.res b/tests/tests/src/equal_exception_test.res index 8193f44fd3..f930d06fd2 100644 --- a/tests/tests/src/equal_exception_test.res +++ b/tests/tests/src/equal_exception_test.res @@ -1,8 +1,6 @@ open Mocha open Test_utils -module String = Ocaml_String - describe(__MODULE__, () => { test("exception", () => { try throw(Not_found) catch { diff --git a/tests/tests/src/ext_pervasives_test.res b/tests/tests/src/ext_pervasives_test.res index a70b890a87..18459aaa9e 100644 --- a/tests/tests/src/ext_pervasives_test.res +++ b/tests/tests/src/ext_pervasives_test.res @@ -22,8 +22,6 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -module String = Ocaml_String - external reraise: exn => 'a = "%raise" let finally = (v, action, f) => @@ -39,7 +37,7 @@ let finally = (v, action, f) => let hash_variant = s => { let accu = ref(0) for i in 0 to String.length(s) - 1 { - accu := 223 * accu.contents + Char.code(String.get(s, i)) + accu := 223 * accu.contents + String.codePointAt(s, i)->Option.getUnsafe } /* reduce to 31 bits */ accu := land(accu.contents, lsl(1, 31) - 1) diff --git a/tests/tests/src/flexible_array_test.mjs b/tests/tests/src/flexible_array_test.mjs index ed7b70bba0..8340514210 100644 --- a/tests/tests/src/flexible_array_test.mjs +++ b/tests/tests/src/flexible_array_test.mjs @@ -2,7 +2,6 @@ import * as Belt_Array from "@rescript/runtime/lib/es6/Belt_Array.js"; import * as Pervasives from "@rescript/runtime/lib/es6/Pervasives.js"; -import * as Primitive_array from "@rescript/runtime/lib/es6/Primitive_array.js"; import * as Primitive_object from "@rescript/runtime/lib/es6/Primitive_object.js"; function sub(_tr, _k) { @@ -144,7 +143,7 @@ function lorem(tr) { RE_EXN_ID: "Assert_failure", _1: [ "flexible_array_test.res", - 82, + 80, 9 ], Error: new Error() @@ -256,7 +255,7 @@ function sort(s) { function of_array(arr) { let v = empty; for (let i = 0, i_finish = arr.length; i < i_finish; ++i) { - v = push_back(v, Primitive_array.get(arr, i)); + v = push_back(v, arr[i]); } return v; } @@ -302,7 +301,7 @@ if (!$eq$tilde(sort(u), [ RE_EXN_ID: "Assert_failure", _1: [ "flexible_array_test.res", - 186, + 184, 2 ], Error: new Error() @@ -313,10 +312,7 @@ let v = Belt_Array.init(500, i => 500 - i | 0); $eq$tilde(sort(of_array(v)), Belt_Array.init(500, i => i + 1 | 0)); -let $$Array; - export { - $$Array, sub, update, $$delete, diff --git a/tests/tests/src/flexible_array_test.res b/tests/tests/src/flexible_array_test.res index 019c6ac092..87360e6160 100644 --- a/tests/tests/src/flexible_array_test.res +++ b/tests/tests/src/flexible_array_test.res @@ -1,5 +1,3 @@ -module Array = Ocaml_Array - type rec tree<'a> = | Lf | Br('a, tree<'a>, tree<'a>) @@ -171,7 +169,7 @@ module Int_array: { let of_array = arr => { let v = ref(empty) for i in 0 to Belt.Array.length(arr) - 1 { - v := push_back(v.contents, arr[i]) + v := push_back(v.contents, arr->Array.getUnsafe(i)) } v.contents } diff --git a/tests/tests/src/hash_test.mjs b/tests/tests/src/hash_test.mjs index cedaecb883..e0cc7ddcd2 100644 --- a/tests/tests/src/hash_test.mjs +++ b/tests/tests/src/hash_test.mjs @@ -2,8 +2,8 @@ import * as Mocha from "mocha"; import * as Belt_Array from "@rescript/runtime/lib/es6/Belt_Array.js"; +import * as Hash_utils from "./hash_utils.mjs"; import * as Test_utils from "./test_utils.mjs"; -import * as Ocaml_Hashtbl from "./ocaml_compat/Ocaml_Hashtbl.mjs"; let test_strings = Belt_Array.init(32, i => String.fromCodePoint(i).repeat(i)); @@ -47,20 +47,17 @@ function normalize(x) { } function caml_hash(x) { - return Ocaml_Hashtbl.hash(x) & 1073741823; + return Hash_utils.hash(x) & 1073741823; } Mocha.describe("Hash_test", () => { - Mocha.test("test strings hash results", () => Test_utils.eq("File \"hash_test.res\", line 49, characters 7-14", Belt_Array.map(test_strings, caml_hash), test_strings_hash_results)); - Mocha.test("hash 0", () => Test_utils.eq("File \"hash_test.res\", line 53, characters 7-14", Ocaml_Hashtbl.hash(0) & 1073741823, 129913994)); - Mocha.test("hash x", () => Test_utils.eq("File \"hash_test.res\", line 57, characters 7-14", Ocaml_Hashtbl.hash("x") & 1073741823, 780510073)); - Mocha.test("hash xy", () => Test_utils.eq("File \"hash_test.res\", line 61, characters 7-14", Ocaml_Hashtbl.hash("xy") & 1073741823, 194127723)); + Mocha.test("test strings hash results", () => Test_utils.eq("File \"hash_test.res\", line 47, characters 7-14", Belt_Array.map(test_strings, caml_hash), test_strings_hash_results)); + Mocha.test("hash 0", () => Test_utils.eq("File \"hash_test.res\", line 51, characters 7-14", Hash_utils.hash(0) & 1073741823, 129913994)); + Mocha.test("hash x", () => Test_utils.eq("File \"hash_test.res\", line 55, characters 7-14", Hash_utils.hash("x") & 1073741823, 780510073)); + Mocha.test("hash xy", () => Test_utils.eq("File \"hash_test.res\", line 59, characters 7-14", Hash_utils.hash("xy") & 1073741823, 194127723)); }); -let Hashtbl; - export { - Hashtbl, test_strings, test_strings_hash_results, normalize, diff --git a/tests/tests/src/hash_test.res b/tests/tests/src/hash_test.res index d4e6a1e14c..4a8e2cae13 100644 --- a/tests/tests/src/hash_test.res +++ b/tests/tests/src/hash_test.res @@ -2,8 +2,6 @@ open Belt open Mocha open Test_utils -module Hashtbl = Ocaml_Hashtbl - let test_strings = Array.init(32, i => Js.String2.fromCodePoint(i)->Js.String2.repeat(i)) let test_strings_hash_results = [ @@ -42,7 +40,7 @@ let test_strings_hash_results = [ ] let normalize = x => land(x, 0x3FFFFFFF) -let caml_hash = x => normalize(Hashtbl.hash(x)) +let caml_hash = x => normalize(Hash_utils.hash(x)) describe(__MODULE__, () => { test("test strings hash results", () => { @@ -50,14 +48,14 @@ describe(__MODULE__, () => { }) test("hash 0", () => { - eq(__LOC__, normalize(Hashtbl.hash(0)), 129913994) + eq(__LOC__, normalize(Hash_utils.hash(0)), 129913994) }) test("hash x", () => { - eq(__LOC__, normalize(Hashtbl.hash("x")), 780510073) + eq(__LOC__, normalize(Hash_utils.hash("x")), 780510073) }) test("hash xy", () => { - eq(__LOC__, normalize(Hashtbl.hash("xy")), 194127723) + eq(__LOC__, normalize(Hash_utils.hash("xy")), 194127723) }) }) diff --git a/tests/tests/src/ocaml_compat/Ocaml_Hashtbl.mjs b/tests/tests/src/hash_utils.mjs similarity index 100% rename from tests/tests/src/ocaml_compat/Ocaml_Hashtbl.mjs rename to tests/tests/src/hash_utils.mjs diff --git a/tests/tests/src/hash_utils.res b/tests/tests/src/hash_utils.res new file mode 100644 index 0000000000..b153dfb074 --- /dev/null +++ b/tests/tests/src/hash_utils.res @@ -0,0 +1,3 @@ +external seeded_hash_param: (int, int, int, 'a) => int = "%hash" + +let hash = x => seeded_hash_param(10, 100, 0, x) diff --git a/tests/tests/src/hash_utils.resi b/tests/tests/src/hash_utils.resi new file mode 100644 index 0000000000..af06a67914 --- /dev/null +++ b/tests/tests/src/hash_utils.resi @@ -0,0 +1 @@ +let hash: 'a => int diff --git a/tests/tests/src/inline_regression_test.mjs b/tests/tests/src/inline_regression_test.mjs index 1fd5a2f325..ffad8dab58 100644 --- a/tests/tests/src/inline_regression_test.mjs +++ b/tests/tests/src/inline_regression_test.mjs @@ -35,17 +35,14 @@ function generic_basename(is_dir_sep, current_dir_name, name) { } function basename(extra) { - return generic_basename((s, i) => s.codePointAt(i) === /* '/' */47, "", extra); + return generic_basename((s, i) => s[i] === "/", "", extra); } Mocha.describe("Inline_regression_test", () => { - Mocha.test("basename", () => Test_utils.eq("File \"inline_regression_test.res\", line 35, characters 7-14", basename("b/c/a.b"), "a.b")); + Mocha.test("basename", () => Test_utils.eq("File \"inline_regression_test.res\", line 33, characters 7-14", basename("b/c/a.b"), "a.b")); }); -let $$String; - export { - $$String, generic_basename, basename, } diff --git a/tests/tests/src/inline_regression_test.res b/tests/tests/src/inline_regression_test.res index ca039ea343..3f07acd79d 100644 --- a/tests/tests/src/inline_regression_test.res +++ b/tests/tests/src/inline_regression_test.res @@ -1,8 +1,6 @@ open Mocha open Test_utils -module String = Ocaml_String - let generic_basename = (is_dir_sep, current_dir_name, name) => { let rec find_end = n => if n < 0 { @@ -28,7 +26,7 @@ let generic_basename = (is_dir_sep, current_dir_name, name) => { } } -let basename = generic_basename((s, i) => String.get(s, i) == '/', "", ...) +let basename = generic_basename((s, i) => String.getUnsafe(s, i) == "/", "", ...) describe(__MODULE__, () => { test("basename", () => { diff --git a/tests/tests/src/int_overflow_test.mjs b/tests/tests/src/int_overflow_test.mjs index 2b9238536f..7d95eb0932 100644 --- a/tests/tests/src/int_overflow_test.mjs +++ b/tests/tests/src/int_overflow_test.mjs @@ -37,28 +37,25 @@ function fib(x) { } Mocha.describe("Int_overflow_test", () => { - Mocha.test("plus_overflow", () => Test_utils.eq("File \"int_overflow_test.res\", line 53, characters 33-40", true, true)); - Mocha.test("minus_overflow", () => Test_utils.eq("File \"int_overflow_test.res\", line 54, characters 34-41", true, true)); - Mocha.test("flow_again1", () => Test_utils.eq("File \"int_overflow_test.res\", line 55, characters 31-38", 2147483646, 2147483646)); - Mocha.test("flow_again2", () => Test_utils.eq("File \"int_overflow_test.res\", line 56, characters 31-38", -2, -2)); - Mocha.test("hash_test", () => Test_utils.eq("File \"int_overflow_test.res\", line 57, characters 29-36", hash_variant("xxyyzzuuxxzzyy00112233"), 544087776)); - Mocha.test("hash_test2", () => Test_utils.eq("File \"int_overflow_test.res\", line 58, characters 30-37", hash_variant("xxyyzxzzyy"), -449896130)); - Mocha.test("hash_variant_test1", () => Test_utils.eq("File \"int_overflow_test.res\", line 59, characters 38-45", hash_variant2("xxyyzzuuxxzzyy00112233"), 544087776)); - Mocha.test("hash_variant_test2", () => Test_utils.eq("File \"int_overflow_test.res\", line 60, characters 38-45", hash_variant2("xxyyzxzzyy"), -449896130)); - Mocha.test("int_literal_flow", () => Test_utils.eq("File \"int_overflow_test.res\", line 61, characters 36-43", -1, -1)); - Mocha.test("int_literal_flow2", () => Test_utils.eq("File \"int_overflow_test.res\", line 62, characters 37-44", -1, -1)); - Mocha.test("float_conversion_test1", () => Test_utils.eq("File \"int_overflow_test.res\", line 63, characters 42-49", Number("3") | 0, 3)); - Mocha.test("float_conversion_test2", () => Test_utils.eq("File \"int_overflow_test.res\", line 64, characters 42-49", Number("3.2") | 0, 3)); + Mocha.test("plus_overflow", () => Test_utils.eq("File \"int_overflow_test.res\", line 51, characters 33-40", true, true)); + Mocha.test("minus_overflow", () => Test_utils.eq("File \"int_overflow_test.res\", line 52, characters 34-41", true, true)); + Mocha.test("flow_again1", () => Test_utils.eq("File \"int_overflow_test.res\", line 53, characters 31-38", 2147483646, 2147483646)); + Mocha.test("flow_again2", () => Test_utils.eq("File \"int_overflow_test.res\", line 54, characters 31-38", -2, -2)); + Mocha.test("hash_test", () => Test_utils.eq("File \"int_overflow_test.res\", line 55, characters 29-36", hash_variant("xxyyzzuuxxzzyy00112233"), 544087776)); + Mocha.test("hash_test2", () => Test_utils.eq("File \"int_overflow_test.res\", line 56, characters 30-37", hash_variant("xxyyzxzzyy"), -449896130)); + Mocha.test("hash_variant_test1", () => Test_utils.eq("File \"int_overflow_test.res\", line 57, characters 38-45", hash_variant2("xxyyzzuuxxzzyy00112233"), 544087776)); + Mocha.test("hash_variant_test2", () => Test_utils.eq("File \"int_overflow_test.res\", line 58, characters 38-45", hash_variant2("xxyyzxzzyy"), -449896130)); + Mocha.test("int_literal_flow", () => Test_utils.eq("File \"int_overflow_test.res\", line 59, characters 36-43", -1, -1)); + Mocha.test("int_literal_flow2", () => Test_utils.eq("File \"int_overflow_test.res\", line 60, characters 37-44", -1, -1)); + Mocha.test("float_conversion_test1", () => Test_utils.eq("File \"int_overflow_test.res\", line 61, characters 42-49", Number("3") | 0, 3)); + Mocha.test("float_conversion_test2", () => Test_utils.eq("File \"int_overflow_test.res\", line 62, characters 42-49", Number("3.2") | 0, 3)); }); -let $$String; - let max_int = 2147483647; let min_int = -2147483648; export { - $$String, max_int, min_int, hash_variant, diff --git a/tests/tests/src/int_overflow_test.res b/tests/tests/src/int_overflow_test.res index 6e5af23773..279c850e8c 100644 --- a/tests/tests/src/int_overflow_test.res +++ b/tests/tests/src/int_overflow_test.res @@ -3,15 +3,13 @@ open Test_utils @@warning("-107") -module String = Ocaml_String - let max_int = 2147483647 // 0x80000000 let min_int = -2147483648 // 0x7FFFFFFF let hash_variant = s => { let accu = ref(0) for i in 0 to String.length(s) - 1 { - accu := land(223 * accu.contents + Char.code(String.get(s, i)), lsl(1, 31) - 1) + accu := land(223 * accu.contents + String.codePointAt(s, i)->Option.getUnsafe, lsl(1, 31) - 1) /* Here accu is 31 bits, times 223 will not be than 53 bits.. TODO: we can use `Sys.backend_type` for patching */ @@ -30,7 +28,7 @@ let hash_variant = s => { let hash_variant2 = s => { let accu = ref(0) for i in 0 to String.length(s) - 1 { - accu := 223 * accu.contents + Char.code(String.get(s, i)) + accu := 223 * accu.contents + String.codePointAt(s, i)->Option.getUnsafe } /* reduce to 31 bits */ accu := land(accu.contents, lsl(1, 31) - 1) diff --git a/tests/tests/src/js_json_test.mjs b/tests/tests/src/js_json_test.mjs index 1cf8ad8d05..45917593c8 100644 --- a/tests/tests/src/js_json_test.mjs +++ b/tests/tests/src/js_json_test.mjs @@ -6,7 +6,6 @@ import * as Js_json from "@rescript/runtime/lib/es6/Js_json.js"; import * as Belt_List from "@rescript/runtime/lib/es6/Belt_List.js"; import * as Belt_Array from "@rescript/runtime/lib/es6/Belt_Array.js"; import * as Test_utils from "./test_utils.mjs"; -import * as Primitive_array from "@rescript/runtime/lib/es6/Primitive_array.js"; import * as Primitive_option from "@rescript/runtime/lib/es6/Primitive_option.js"; Mocha.describe("Js_json_test", () => { @@ -14,13 +13,13 @@ Mocha.describe("Js_json_test", () => { let v = JSON.parse(` { "x" : [1, 2, 3 ] } `); let ty = Js_json.classify(v); if (typeof ty !== "object" || ty.TAG !== "JSONObject") { - Test_utils.ok("File \"js_json_test.res\", line 36, characters 14-21", false); + Test_utils.ok("File \"js_json_test.res\", line 35, characters 14-21", false); } else { let v$1 = Js_dict.get(ty._0, "x"); if (v$1 !== undefined) { let ty2 = Js_json.classify(v$1); if (typeof ty2 !== "object" || ty2.TAG !== "JSONArray") { - Test_utils.ok("File \"js_json_test.res\", line 32, characters 18-25", false); + Test_utils.ok("File \"js_json_test.res\", line 31, characters 18-25", false); } else { ty2._0.forEach(x => { let ty3 = Js_json.classify(x); @@ -29,7 +28,7 @@ Mocha.describe("Js_json_test", () => { RE_EXN_ID: "Assert_failure", _1: [ "js_json_test.res", - 27, + 26, 21 ], Error: new Error() @@ -42,59 +41,59 @@ Mocha.describe("Js_json_test", () => { RE_EXN_ID: "Assert_failure", _1: [ "js_json_test.res", - 27, + 26, 21 ], Error: new Error() }; }); - Test_utils.ok("File \"js_json_test.res\", line 31, characters 13-20", true); + Test_utils.ok("File \"js_json_test.res\", line 30, characters 13-20", true); } } else { - Test_utils.ok("File \"js_json_test.res\", line 34, characters 19-26", false); + Test_utils.ok("File \"js_json_test.res\", line 33, characters 19-26", false); } } - Test_utils.eq("File \"js_json_test.res\", line 39, characters 7-14", Js_json.test(v, "Object"), true); + Test_utils.eq("File \"js_json_test.res\", line 38, characters 7-14", Js_json.test(v, "Object"), true); }); Mocha.test("JSON null parsing", () => { let json = JSON.parse(JSON.stringify(null)); let ty = Js_json.classify(json); if (typeof ty !== "object") { if (ty === "JSONNull") { - return Test_utils.ok("File \"js_json_test.res\", line 46, characters 23-30", true); + return Test_utils.ok("File \"js_json_test.res\", line 45, characters 23-30", true); } console.log(ty); - return Test_utils.ok("File \"js_json_test.res\", line 49, characters 9-16", false); + return Test_utils.ok("File \"js_json_test.res\", line 48, characters 9-16", false); } else { console.log(ty); - return Test_utils.ok("File \"js_json_test.res\", line 49, characters 9-16", false); + return Test_utils.ok("File \"js_json_test.res\", line 48, characters 9-16", false); } }); Mocha.test("JSON string parsing", () => { let json = JSON.parse(JSON.stringify("test string")); let ty = Js_json.classify(json); if (typeof ty !== "object" || ty.TAG !== "JSONString") { - return Test_utils.ok("File \"js_json_test.res\", line 58, characters 14-21", false); + return Test_utils.ok("File \"js_json_test.res\", line 57, characters 14-21", false); } else { - return Test_utils.eq("File \"js_json_test.res\", line 57, characters 28-35", ty._0, "test string"); + return Test_utils.eq("File \"js_json_test.res\", line 56, characters 28-35", ty._0, "test string"); } }); Mocha.test("JSON number parsing", () => { let json = JSON.parse(JSON.stringify(1.23456789)); let ty = Js_json.classify(json); if (typeof ty !== "object" || ty.TAG !== "JSONNumber") { - return Test_utils.ok("File \"js_json_test.res\", line 67, characters 14-21", false); + return Test_utils.ok("File \"js_json_test.res\", line 66, characters 14-21", false); } else { - return Test_utils.eq("File \"js_json_test.res\", line 66, characters 28-35", ty._0, 1.23456789); + return Test_utils.eq("File \"js_json_test.res\", line 65, characters 28-35", ty._0, 1.23456789); } }); Mocha.test("JSON large integer parsing", () => { let json = JSON.parse(JSON.stringify(-1347440721)); let ty = Js_json.classify(json); if (typeof ty !== "object" || ty.TAG !== "JSONNumber") { - return Test_utils.ok("File \"js_json_test.res\", line 76, characters 14-21", false); + return Test_utils.ok("File \"js_json_test.res\", line 75, characters 14-21", false); } else { - return Test_utils.eq("File \"js_json_test.res\", line 75, characters 28-35", ty._0 | 0, -1347440721); + return Test_utils.eq("File \"js_json_test.res\", line 74, characters 28-35", ty._0 | 0, -1347440721); } }); Mocha.test("JSON boolean parsing", () => { @@ -102,15 +101,15 @@ Mocha.describe("Js_json_test", () => { let json = JSON.parse(JSON.stringify(v)); let ty = Js_json.classify(json); if (typeof ty === "object") { - return Test_utils.ok("File \"js_json_test.res\", line 87, characters 16-23", false); + return Test_utils.ok("File \"js_json_test.res\", line 86, characters 16-23", false); } switch (ty) { case "JSONFalse" : - return Test_utils.eq("File \"js_json_test.res\", line 86, characters 26-33", false, v); + return Test_utils.eq("File \"js_json_test.res\", line 85, characters 26-33", false, v); case "JSONTrue" : - return Test_utils.eq("File \"js_json_test.res\", line 85, characters 25-32", true, v); + return Test_utils.eq("File \"js_json_test.res\", line 84, characters 25-32", true, v); default: - return Test_utils.ok("File \"js_json_test.res\", line 87, characters 16-23", false); + return Test_utils.ok("File \"js_json_test.res\", line 86, characters 16-23", false); } }; test(true); @@ -125,7 +124,7 @@ Mocha.describe("Js_json_test", () => { RE_EXN_ID: "Assert_failure", _1: [ "js_json_test.res", - 98, + 97, 16 ], Error: new Error() @@ -137,27 +136,27 @@ Mocha.describe("Js_json_test", () => { let json = JSON.parse(JSON.stringify(dict)); let ty = Js_json.classify(json); if (typeof ty !== "object") { - return Test_utils.ok("File \"js_json_test.res\", line 128, characters 14-21", false); + return Test_utils.ok("File \"js_json_test.res\", line 127, characters 14-21", false); } if (ty.TAG !== "JSONObject") { - return Test_utils.ok("File \"js_json_test.res\", line 128, characters 14-21", false); + return Test_utils.ok("File \"js_json_test.res\", line 127, characters 14-21", false); } let x = ty._0; let ta = Js_json.classify(option_get(Js_dict.get(x, "a"))); if (typeof ta !== "object") { - return Test_utils.ok("File \"js_json_test.res\", line 126, characters 16-23", false); + return Test_utils.ok("File \"js_json_test.res\", line 125, characters 16-23", false); } if (ta.TAG !== "JSONString") { - return Test_utils.ok("File \"js_json_test.res\", line 126, characters 16-23", false); + return Test_utils.ok("File \"js_json_test.res\", line 125, characters 16-23", false); } if (ta._0 !== "test string") { - return Test_utils.ok("File \"js_json_test.res\", line 117, characters 13-20", false); + return Test_utils.ok("File \"js_json_test.res\", line 116, characters 13-20", false); } let ty$1 = Js_json.classify(option_get(Js_dict.get(x, "b"))); if (typeof ty$1 !== "object" || ty$1.TAG !== "JSONNumber") { - return Test_utils.ok("File \"js_json_test.res\", line 123, characters 20-27", false); + return Test_utils.ok("File \"js_json_test.res\", line 122, characters 20-27", false); } else { - return Test_utils.approxEq("File \"js_json_test.res\", line 122, characters 40-47", 0.001, 123.0, ty$1._0); + return Test_utils.approxEq("File \"js_json_test.res\", line 121, characters 40-47", 0.001, 123.0, ty$1._0); } }); let eq_at_i = (loc, json, i, kind, expected) => { @@ -168,7 +167,7 @@ Mocha.describe("Js_json_test", () => { if (ty.TAG !== "JSONArray") { return Test_utils.ok(loc, false); } - let ty$1 = Js_json.classify(Primitive_array.get(ty._0, i)); + let ty$1 = Js_json.classify(ty._0[i]); switch (kind) { case "String" : if (typeof ty$1 !== "object" || ty$1.TAG !== "JSONString") { @@ -220,9 +219,9 @@ Mocha.describe("Js_json_test", () => { "string 1", "string 2" ], prim => prim))); - eq_at_i("File \"js_json_test.res\", line 181, characters 12-19", json, 0, "String", "string 0"); - eq_at_i("File \"js_json_test.res\", line 182, characters 12-19", json, 1, "String", "string 1"); - eq_at_i("File \"js_json_test.res\", line 183, characters 12-19", json, 2, "String", "string 2"); + eq_at_i("File \"js_json_test.res\", line 180, characters 12-19", json, 0, "String", "string 0"); + eq_at_i("File \"js_json_test.res\", line 181, characters 12-19", json, 1, "String", "string 1"); + eq_at_i("File \"js_json_test.res\", line 182, characters 12-19", json, 2, "String", "string 2"); }); Mocha.test("JSON stringArray parsing", () => { let json = JSON.parse(JSON.stringify([ @@ -230,9 +229,9 @@ Mocha.describe("Js_json_test", () => { "string 1", "string 2" ])); - eq_at_i("File \"js_json_test.res\", line 189, characters 12-19", json, 0, "String", "string 0"); - eq_at_i("File \"js_json_test.res\", line 190, characters 12-19", json, 1, "String", "string 1"); - eq_at_i("File \"js_json_test.res\", line 191, characters 12-19", json, 2, "String", "string 2"); + eq_at_i("File \"js_json_test.res\", line 188, characters 12-19", json, 0, "String", "string 0"); + eq_at_i("File \"js_json_test.res\", line 189, characters 12-19", json, 1, "String", "string 1"); + eq_at_i("File \"js_json_test.res\", line 190, characters 12-19", json, 2, "String", "string 2"); }); Mocha.test("JSON number array parsing", () => { let a = [ @@ -241,9 +240,9 @@ Mocha.describe("Js_json_test", () => { 123.0 ]; let json = JSON.parse(JSON.stringify(a)); - eq_at_i("File \"js_json_test.res\", line 199, characters 12-19", json, 0, "Number", Primitive_array.get(a, 0)); - eq_at_i("File \"js_json_test.res\", line 200, characters 12-19", json, 1, "Number", Primitive_array.get(a, 1)); - eq_at_i("File \"js_json_test.res\", line 201, characters 12-19", json, 2, "Number", Primitive_array.get(a, 2)); + eq_at_i("File \"js_json_test.res\", line 198, characters 12-19", json, 0, "Number", a[0]); + eq_at_i("File \"js_json_test.res\", line 199, characters 12-19", json, 1, "Number", a[1]); + eq_at_i("File \"js_json_test.res\", line 200, characters 12-19", json, 2, "Number", a[2]); }); Mocha.test("JSON integer array parsing", () => { let a = [ @@ -252,9 +251,9 @@ Mocha.describe("Js_json_test", () => { -268391749 ]; let json = JSON.parse(JSON.stringify(Belt_Array.map(a, prim => prim))); - eq_at_i("File \"js_json_test.res\", line 209, characters 12-19", json, 0, "Number", Primitive_array.get(a, 0)); - eq_at_i("File \"js_json_test.res\", line 210, characters 12-19", json, 1, "Number", Primitive_array.get(a, 1)); - eq_at_i("File \"js_json_test.res\", line 211, characters 12-19", json, 2, "Number", Primitive_array.get(a, 2)); + eq_at_i("File \"js_json_test.res\", line 208, characters 12-19", json, 0, "Number", a[0]); + eq_at_i("File \"js_json_test.res\", line 209, characters 12-19", json, 1, "Number", a[1]); + eq_at_i("File \"js_json_test.res\", line 210, characters 12-19", json, 2, "Number", a[2]); }); Mocha.test("JSON boolean array parsing", () => { let a = [ @@ -263,9 +262,9 @@ Mocha.describe("Js_json_test", () => { true ]; let json = JSON.parse(JSON.stringify(a)); - eq_at_i("File \"js_json_test.res\", line 219, characters 12-19", json, 0, "Boolean", Primitive_array.get(a, 0)); - eq_at_i("File \"js_json_test.res\", line 220, characters 12-19", json, 1, "Boolean", Primitive_array.get(a, 1)); - eq_at_i("File \"js_json_test.res\", line 221, characters 12-19", json, 2, "Boolean", Primitive_array.get(a, 2)); + eq_at_i("File \"js_json_test.res\", line 218, characters 12-19", json, 0, "Boolean", a[0]); + eq_at_i("File \"js_json_test.res\", line 219, characters 12-19", json, 1, "Boolean", a[1]); + eq_at_i("File \"js_json_test.res\", line 220, characters 12-19", json, 2, "Boolean", a[2]); }); Mocha.test("JSON object array parsing", () => { let option_get = x => { @@ -276,7 +275,7 @@ Mocha.describe("Js_json_test", () => { RE_EXN_ID: "Assert_failure", _1: [ "js_json_test.res", - 227, + 226, 16 ], Error: new Error() @@ -295,97 +294,97 @@ Mocha.describe("Js_json_test", () => { let json = JSON.parse(JSON.stringify(a)); let ty = Js_json.classify(json); if (typeof ty !== "object") { - return Test_utils.ok("File \"js_json_test.res\", line 254, characters 14-21", false); + return Test_utils.ok("File \"js_json_test.res\", line 253, characters 14-21", false); } if (ty.TAG !== "JSONArray") { - return Test_utils.ok("File \"js_json_test.res\", line 254, characters 14-21", false); + return Test_utils.ok("File \"js_json_test.res\", line 253, characters 14-21", false); } - let ty$1 = Js_json.classify(Primitive_array.get(ty._0, 1)); + let ty$1 = Js_json.classify(ty._0[1]); if (typeof ty$1 !== "object") { - return Test_utils.ok("File \"js_json_test.res\", line 252, characters 16-23", false); + return Test_utils.ok("File \"js_json_test.res\", line 251, characters 16-23", false); } if (ty$1.TAG !== "JSONObject") { - return Test_utils.ok("File \"js_json_test.res\", line 252, characters 16-23", false); + return Test_utils.ok("File \"js_json_test.res\", line 251, characters 16-23", false); } let ty$2 = Js_json.classify(option_get(Js_dict.get(ty$1._0, "a"))); if (typeof ty$2 !== "object" || ty$2.TAG !== "JSONString") { - return Test_utils.ok("File \"js_json_test.res\", line 250, characters 18-25", false); + return Test_utils.ok("File \"js_json_test.res\", line 249, characters 18-25", false); } else { - return Test_utils.eq("File \"js_json_test.res\", line 249, characters 37-44", ty$2._0, "bbb"); + return Test_utils.eq("File \"js_json_test.res\", line 248, characters 37-44", ty$2._0, "bbb"); } }); Mocha.test("JSON invalid parsing", () => { try { JSON.parse("{{ A}"); - return Test_utils.ok("File \"js_json_test.res\", line 262, characters 9-16", false); + return Test_utils.ok("File \"js_json_test.res\", line 261, characters 9-16", false); } catch (exn) { - return Test_utils.ok("File \"js_json_test.res\", line 264, characters 16-23", true); + return Test_utils.ok("File \"js_json_test.res\", line 263, characters 16-23", true); } }); - Mocha.test("JSON stringifyAny array", () => Test_utils.eq("File \"js_json_test.res\", line 269, characters 43-50", JSON.stringify([ + Mocha.test("JSON stringifyAny array", () => Test_utils.eq("File \"js_json_test.res\", line 268, characters 43-50", JSON.stringify([ 1, 2, 3 ]), "[1,2,3]")); - Mocha.test("JSON stringifyAny object", () => Test_utils.eq("File \"js_json_test.res\", line 273, characters 6-13", JSON.stringify({ + Mocha.test("JSON stringifyAny object", () => Test_utils.eq("File \"js_json_test.res\", line 272, characters 6-13", JSON.stringify({ foo: 1, bar: "hello", baz: { baaz: 10 } }), `{"foo":1,"bar":"hello","baz":{"baaz":10}}`)); - Mocha.test("JSON stringifyAny null", () => Test_utils.eq("File \"js_json_test.res\", line 279, characters 42-49", JSON.stringify(null), "null")); - Mocha.test("JSON stringifyAny undefined", () => Test_utils.eq("File \"js_json_test.res\", line 281, characters 47-54", JSON.stringify(undefined), undefined)); + Mocha.test("JSON stringifyAny null", () => Test_utils.eq("File \"js_json_test.res\", line 278, characters 42-49", JSON.stringify(null), "null")); + Mocha.test("JSON stringifyAny undefined", () => Test_utils.eq("File \"js_json_test.res\", line 280, characters 47-54", JSON.stringify(undefined), undefined)); Mocha.test("JSON decodeString", () => { - Test_utils.eq("File \"js_json_test.res\", line 284, characters 7-14", Js_json.decodeString("test"), "test"); - Test_utils.eq("File \"js_json_test.res\", line 285, characters 7-14", Js_json.decodeString(true), undefined); - Test_utils.eq("File \"js_json_test.res\", line 286, characters 7-14", Js_json.decodeString([]), undefined); - Test_utils.eq("File \"js_json_test.res\", line 287, characters 7-14", Js_json.decodeString(null), undefined); - Test_utils.eq("File \"js_json_test.res\", line 288, characters 7-14", Js_json.decodeString({}), undefined); - Test_utils.eq("File \"js_json_test.res\", line 289, characters 7-14", Js_json.decodeString(1.23), undefined); + Test_utils.eq("File \"js_json_test.res\", line 283, characters 7-14", Js_json.decodeString("test"), "test"); + Test_utils.eq("File \"js_json_test.res\", line 284, characters 7-14", Js_json.decodeString(true), undefined); + Test_utils.eq("File \"js_json_test.res\", line 285, characters 7-14", Js_json.decodeString([]), undefined); + Test_utils.eq("File \"js_json_test.res\", line 286, characters 7-14", Js_json.decodeString(null), undefined); + Test_utils.eq("File \"js_json_test.res\", line 287, characters 7-14", Js_json.decodeString({}), undefined); + Test_utils.eq("File \"js_json_test.res\", line 288, characters 7-14", Js_json.decodeString(1.23), undefined); }); Mocha.test("JSON decodeNumber", () => { - Test_utils.eq("File \"js_json_test.res\", line 293, characters 7-14", Js_json.decodeNumber("test"), undefined); - Test_utils.eq("File \"js_json_test.res\", line 294, characters 7-14", Js_json.decodeNumber(true), undefined); - Test_utils.eq("File \"js_json_test.res\", line 295, characters 7-14", Js_json.decodeNumber([]), undefined); - Test_utils.eq("File \"js_json_test.res\", line 296, characters 7-14", Js_json.decodeNumber(null), undefined); - Test_utils.eq("File \"js_json_test.res\", line 297, characters 7-14", Js_json.decodeNumber({}), undefined); - Test_utils.eq("File \"js_json_test.res\", line 298, characters 7-14", Js_json.decodeNumber(1.23), 1.23); + Test_utils.eq("File \"js_json_test.res\", line 292, characters 7-14", Js_json.decodeNumber("test"), undefined); + Test_utils.eq("File \"js_json_test.res\", line 293, characters 7-14", Js_json.decodeNumber(true), undefined); + Test_utils.eq("File \"js_json_test.res\", line 294, characters 7-14", Js_json.decodeNumber([]), undefined); + Test_utils.eq("File \"js_json_test.res\", line 295, characters 7-14", Js_json.decodeNumber(null), undefined); + Test_utils.eq("File \"js_json_test.res\", line 296, characters 7-14", Js_json.decodeNumber({}), undefined); + Test_utils.eq("File \"js_json_test.res\", line 297, characters 7-14", Js_json.decodeNumber(1.23), 1.23); }); Mocha.test("JSON decodeObject", () => { - Test_utils.eq("File \"js_json_test.res\", line 302, characters 7-14", Js_json.decodeObject("test"), undefined); - Test_utils.eq("File \"js_json_test.res\", line 303, characters 7-14", Js_json.decodeObject(true), undefined); - Test_utils.eq("File \"js_json_test.res\", line 304, characters 7-14", Js_json.decodeObject([]), undefined); - Test_utils.eq("File \"js_json_test.res\", line 305, characters 7-14", Js_json.decodeObject(null), undefined); - Test_utils.eq("File \"js_json_test.res\", line 306, characters 7-14", Js_json.decodeObject({}), {}); - Test_utils.eq("File \"js_json_test.res\", line 307, characters 7-14", Js_json.decodeObject(1.23), undefined); + Test_utils.eq("File \"js_json_test.res\", line 301, characters 7-14", Js_json.decodeObject("test"), undefined); + Test_utils.eq("File \"js_json_test.res\", line 302, characters 7-14", Js_json.decodeObject(true), undefined); + Test_utils.eq("File \"js_json_test.res\", line 303, characters 7-14", Js_json.decodeObject([]), undefined); + Test_utils.eq("File \"js_json_test.res\", line 304, characters 7-14", Js_json.decodeObject(null), undefined); + Test_utils.eq("File \"js_json_test.res\", line 305, characters 7-14", Js_json.decodeObject({}), {}); + Test_utils.eq("File \"js_json_test.res\", line 306, characters 7-14", Js_json.decodeObject(1.23), undefined); }); Mocha.test("JSON decodeArray", () => { - Test_utils.eq("File \"js_json_test.res\", line 311, characters 7-14", Js_json.decodeArray("test"), undefined); - Test_utils.eq("File \"js_json_test.res\", line 312, characters 7-14", Js_json.decodeArray(true), undefined); - Test_utils.eq("File \"js_json_test.res\", line 313, characters 7-14", Js_json.decodeArray([]), []); - Test_utils.eq("File \"js_json_test.res\", line 314, characters 7-14", Js_json.decodeArray(null), undefined); - Test_utils.eq("File \"js_json_test.res\", line 315, characters 7-14", Js_json.decodeArray({}), undefined); - Test_utils.eq("File \"js_json_test.res\", line 316, characters 7-14", Js_json.decodeArray(1.23), undefined); + Test_utils.eq("File \"js_json_test.res\", line 310, characters 7-14", Js_json.decodeArray("test"), undefined); + Test_utils.eq("File \"js_json_test.res\", line 311, characters 7-14", Js_json.decodeArray(true), undefined); + Test_utils.eq("File \"js_json_test.res\", line 312, characters 7-14", Js_json.decodeArray([]), []); + Test_utils.eq("File \"js_json_test.res\", line 313, characters 7-14", Js_json.decodeArray(null), undefined); + Test_utils.eq("File \"js_json_test.res\", line 314, characters 7-14", Js_json.decodeArray({}), undefined); + Test_utils.eq("File \"js_json_test.res\", line 315, characters 7-14", Js_json.decodeArray(1.23), undefined); }); Mocha.test("JSON decodeBoolean", () => { - Test_utils.eq("File \"js_json_test.res\", line 320, characters 7-14", Js_json.decodeBoolean("test"), undefined); - Test_utils.eq("File \"js_json_test.res\", line 321, characters 7-14", Js_json.decodeBoolean(true), true); - Test_utils.eq("File \"js_json_test.res\", line 322, characters 7-14", Js_json.decodeBoolean([]), undefined); - Test_utils.eq("File \"js_json_test.res\", line 323, characters 7-14", Js_json.decodeBoolean(null), undefined); - Test_utils.eq("File \"js_json_test.res\", line 324, characters 7-14", Js_json.decodeBoolean({}), undefined); - Test_utils.eq("File \"js_json_test.res\", line 325, characters 7-14", Js_json.decodeBoolean(1.23), undefined); + Test_utils.eq("File \"js_json_test.res\", line 319, characters 7-14", Js_json.decodeBoolean("test"), undefined); + Test_utils.eq("File \"js_json_test.res\", line 320, characters 7-14", Js_json.decodeBoolean(true), true); + Test_utils.eq("File \"js_json_test.res\", line 321, characters 7-14", Js_json.decodeBoolean([]), undefined); + Test_utils.eq("File \"js_json_test.res\", line 322, characters 7-14", Js_json.decodeBoolean(null), undefined); + Test_utils.eq("File \"js_json_test.res\", line 323, characters 7-14", Js_json.decodeBoolean({}), undefined); + Test_utils.eq("File \"js_json_test.res\", line 324, characters 7-14", Js_json.decodeBoolean(1.23), undefined); }); Mocha.test("JSON decodeNull", () => { - Test_utils.eq("File \"js_json_test.res\", line 329, characters 7-14", Js_json.decodeNull("test"), undefined); - Test_utils.eq("File \"js_json_test.res\", line 330, characters 7-14", Js_json.decodeNull(true), undefined); - Test_utils.eq("File \"js_json_test.res\", line 331, characters 7-14", Js_json.decodeNull([]), undefined); - Test_utils.eq("File \"js_json_test.res\", line 332, characters 7-14", Js_json.decodeNull(null), null); - Test_utils.eq("File \"js_json_test.res\", line 333, characters 7-14", Js_json.decodeNull({}), undefined); - Test_utils.eq("File \"js_json_test.res\", line 334, characters 7-14", Js_json.decodeNull(1.23), undefined); + Test_utils.eq("File \"js_json_test.res\", line 328, characters 7-14", Js_json.decodeNull("test"), undefined); + Test_utils.eq("File \"js_json_test.res\", line 329, characters 7-14", Js_json.decodeNull(true), undefined); + Test_utils.eq("File \"js_json_test.res\", line 330, characters 7-14", Js_json.decodeNull([]), undefined); + Test_utils.eq("File \"js_json_test.res\", line 331, characters 7-14", Js_json.decodeNull(null), null); + Test_utils.eq("File \"js_json_test.res\", line 332, characters 7-14", Js_json.decodeNull({}), undefined); + Test_utils.eq("File \"js_json_test.res\", line 333, characters 7-14", Js_json.decodeNull(1.23), undefined); }); Mocha.test("JSON serialize/deserialize identity", () => { - let idtest = obj => Test_utils.eq("File \"js_json_test.res\", line 340, characters 27-34", obj, Js_json.deserializeUnsafe(Js_json.serializeExn(obj))); + let idtest = obj => Test_utils.eq("File \"js_json_test.res\", line 339, characters 27-34", obj, Js_json.deserializeUnsafe(Js_json.serializeExn(obj))); idtest(undefined); idtest({ hd: [ @@ -414,10 +413,7 @@ Mocha.describe("Js_json_test", () => { let J; -let $$Array; - export { J, - $$Array, } /* Not a pure module */ diff --git a/tests/tests/src/js_json_test.res b/tests/tests/src/js_json_test.res index 224a96ff39..4bca0491c8 100644 --- a/tests/tests/src/js_json_test.res +++ b/tests/tests/src/js_json_test.res @@ -2,7 +2,6 @@ open Mocha open Test_utils module J = Js.Json -module Array = Ocaml_Array describe(__MODULE__, () => { test("JSON object parsing and validation", () => { @@ -135,7 +134,7 @@ describe(__MODULE__, () => { let ty = J.classify(json) switch ty { | J.JSONArray(x) => - let ty = J.classify(x[i]) + let ty = J.classify(x->Array.getUnsafe(i)) switch kind { | J.Kind.Boolean => switch ty { @@ -196,9 +195,9 @@ describe(__MODULE__, () => { let json = J.parseExn(J.stringify(J.numberArray(a))) /* Loop is unrolled to keep relevant location information */ - eq_at_i(__LOC__, json, 0, J.Kind.Number, a[0]) - eq_at_i(__LOC__, json, 1, J.Kind.Number, a[1]) - eq_at_i(__LOC__, json, 2, J.Kind.Number, a[2]) + eq_at_i(__LOC__, json, 0, J.Kind.Number, a->Array.getUnsafe(0)) + eq_at_i(__LOC__, json, 1, J.Kind.Number, a->Array.getUnsafe(1)) + eq_at_i(__LOC__, json, 2, J.Kind.Number, a->Array.getUnsafe(2)) }) test("JSON integer array parsing", () => { @@ -206,9 +205,9 @@ describe(__MODULE__, () => { let json = J.parseExn(J.stringify(J.numberArray(a->Belt.Array.map(float_of_int)))) /* Loop is unrolled to keep relevant location information */ - eq_at_i(__LOC__, json, 0, J.Kind.Number, float_of_int(a[0])) - eq_at_i(__LOC__, json, 1, J.Kind.Number, float_of_int(a[1])) - eq_at_i(__LOC__, json, 2, J.Kind.Number, float_of_int(a[2])) + eq_at_i(__LOC__, json, 0, J.Kind.Number, float_of_int(a->Array.getUnsafe(0))) + eq_at_i(__LOC__, json, 1, J.Kind.Number, float_of_int(a->Array.getUnsafe(1))) + eq_at_i(__LOC__, json, 2, J.Kind.Number, float_of_int(a->Array.getUnsafe(2))) }) test("JSON boolean array parsing", () => { @@ -216,9 +215,9 @@ describe(__MODULE__, () => { let json = J.parseExn(J.stringify(J.booleanArray(a))) /* Loop is unrolled to keep relevant location information */ - eq_at_i(__LOC__, json, 0, J.Kind.Boolean, a[0]) - eq_at_i(__LOC__, json, 1, J.Kind.Boolean, a[1]) - eq_at_i(__LOC__, json, 2, J.Kind.Boolean, a[2]) + eq_at_i(__LOC__, json, 0, J.Kind.Boolean, a->Array.getUnsafe(0)) + eq_at_i(__LOC__, json, 1, J.Kind.Boolean, a->Array.getUnsafe(1)) + eq_at_i(__LOC__, json, 2, J.Kind.Boolean, a->Array.getUnsafe(2)) }) test("JSON object array parsing", () => { @@ -241,7 +240,7 @@ describe(__MODULE__, () => { let ty = J.classify(json) switch ty { | J.JSONArray(x) => - let ty = J.classify(x[1]) + let ty = J.classify(x->Array.getUnsafe(1)) switch ty { | J.JSONObject(a1) => let ty = J.classify(option_get(Js_dict.get(a1, "a"))) diff --git a/tests/tests/src/js_re_test.mjs b/tests/tests/src/js_re_test.mjs index 3652e6168b..449a723c14 100644 --- a/tests/tests/src/js_re_test.mjs +++ b/tests/tests/src/js_re_test.mjs @@ -2,7 +2,6 @@ import * as Mocha from "mocha"; import * as Test_utils from "./test_utils.mjs"; -import * as Primitive_array from "@rescript/runtime/lib/es6/Primitive_array.js"; import * as Primitive_option from "@rescript/runtime/lib/es6/Primitive_option.js"; Mocha.describe("Js_re_test", () => { @@ -10,22 +9,22 @@ Mocha.describe("Js_re_test", () => { let contentOf = (tag, xmlString) => { let x = Primitive_option.fromNull(new RegExp("<" + (tag + (">(.*?)<\\/" + (tag + ">")))).exec(xmlString)); if (x !== undefined) { - return Primitive_option.fromNullable(Primitive_array.get(Primitive_option.valFromOption(x), 1)); + return Primitive_option.fromNullable(Primitive_option.valFromOption(x)[1]); } }; - Test_utils.eq("File \"js_re_test.res\", line 33, characters 7-14", "Hi", contentOf("div", "
Hi
")); + Test_utils.eq("File \"js_re_test.res\", line 31, characters 7-14", "Hi", contentOf("div", "
Hi
")); }); Mocha.test("exec_literal", () => { let res = /[^.]+/.exec("http://xxx.domain.com"); if (res !== null) { - return Test_utils.eq("File \"js_re_test.res\", line 37, characters 22-29", "http://xxx", Primitive_array.get(res, 0)); + return Test_utils.eq("File \"js_re_test.res\", line 36, characters 9-16", "http://xxx", res[0]); } throw { RE_EXN_ID: "Assert_failure", _1: [ "js_re_test.res", - 38, + 37, 14 ], Error: new Error() @@ -38,32 +37,32 @@ Mocha.describe("Js_re_test", () => { RE_EXN_ID: "Assert_failure", _1: [ "js_re_test.res", - 43, + 42, 17 ], Error: new Error() }; } - Test_utils.eq("File \"js_re_test.res\", line 44, characters 17-24", true, true); + Test_utils.eq("File \"js_re_test.res\", line 43, characters 17-24", true, true); }); Mocha.test("test_str", () => { let res = new RegExp("foo").test("#foo#"); - Test_utils.eq("File \"js_re_test.res\", line 49, characters 7-14", true, res); + Test_utils.eq("File \"js_re_test.res\", line 48, characters 7-14", true, res); }); Mocha.test("fromStringWithFlags", () => { let res = new RegExp("foo", "g"); - Test_utils.eq("File \"js_re_test.res\", line 53, characters 7-14", true, res.global); + Test_utils.eq("File \"js_re_test.res\", line 52, characters 7-14", true, res.global); }); Mocha.test("result_index", () => { let res = new RegExp("zbar").exec("foobarbazbar"); if (res !== null) { - return Test_utils.eq("File \"js_re_test.res\", line 57, characters 22-29", 8, res.index); + return Test_utils.eq("File \"js_re_test.res\", line 56, characters 22-29", 8, res.index); } throw { RE_EXN_ID: "Assert_failure", _1: [ "js_re_test.res", - 58, + 57, 14 ], Error: new Error() @@ -73,32 +72,32 @@ Mocha.describe("Js_re_test", () => { let input = "foobar"; let res = /foo/g.exec(input); if (res !== null) { - return Test_utils.eq("File \"js_re_test.res\", line 64, characters 22-29", input, res.input); + return Test_utils.eq("File \"js_re_test.res\", line 63, characters 22-29", input, res.input); } throw { RE_EXN_ID: "Assert_failure", _1: [ "js_re_test.res", - 65, + 64, 14 ], Error: new Error() }; }); - Mocha.test("t_flags", () => Test_utils.eq("File \"js_re_test.res\", line 70, characters 7-14", "gi", /./ig.flags)); - Mocha.test("t_global", () => Test_utils.eq("File \"js_re_test.res\", line 73, characters 7-14", true, /./ig.global)); - Mocha.test("t_ignoreCase", () => Test_utils.eq("File \"js_re_test.res\", line 76, characters 7-14", true, /./ig.ignoreCase)); + Mocha.test("t_flags", () => Test_utils.eq("File \"js_re_test.res\", line 69, characters 7-14", "gi", /./ig.flags)); + Mocha.test("t_global", () => Test_utils.eq("File \"js_re_test.res\", line 72, characters 7-14", true, /./ig.global)); + Mocha.test("t_ignoreCase", () => Test_utils.eq("File \"js_re_test.res\", line 75, characters 7-14", true, /./ig.ignoreCase)); Mocha.test("t_lastIndex", () => { let re = /na/g; re.exec("banana"); - Test_utils.eq("File \"js_re_test.res\", line 84, characters 7-14", 4, re.lastIndex); + Test_utils.eq("File \"js_re_test.res\", line 83, characters 7-14", 4, re.lastIndex); }); Mocha.test("t_setLastIndex", () => { let re = /na/g; let before = re.lastIndex; re.lastIndex = 42; let after = re.lastIndex; - Test_utils.eq("File \"js_re_test.res\", line 91, characters 7-14", [ + Test_utils.eq("File \"js_re_test.res\", line 90, characters 7-14", [ 0, 42 ], [ @@ -106,15 +105,10 @@ Mocha.describe("Js_re_test", () => { after ]); }); - Mocha.test("t_multiline", () => Test_utils.eq("File \"js_re_test.res\", line 94, characters 7-14", false, /./ig.multiline)); - Mocha.test("t_source", () => Test_utils.eq("File \"js_re_test.res\", line 97, characters 7-14", "f.+o", /f.+o/ig.source)); - Mocha.test("t_sticky", () => Test_utils.eq("File \"js_re_test.res\", line 101, characters 7-14", true, /./yg.sticky)); - Mocha.test("t_unicode", () => Test_utils.eq("File \"js_re_test.res\", line 104, characters 7-14", false, /./yg.unicode)); + Mocha.test("t_multiline", () => Test_utils.eq("File \"js_re_test.res\", line 93, characters 7-14", false, /./ig.multiline)); + Mocha.test("t_source", () => Test_utils.eq("File \"js_re_test.res\", line 96, characters 7-14", "f.+o", /f.+o/ig.source)); + Mocha.test("t_sticky", () => Test_utils.eq("File \"js_re_test.res\", line 100, characters 7-14", true, /./yg.sticky)); + Mocha.test("t_unicode", () => Test_utils.eq("File \"js_re_test.res\", line 103, characters 7-14", false, /./yg.unicode)); }); -let $$Array; - -export { - $$Array, -} /* Not a pure module */ diff --git a/tests/tests/src/js_re_test.res b/tests/tests/src/js_re_test.res index afde1301b0..5581600821 100644 --- a/tests/tests/src/js_re_test.res +++ b/tests/tests/src/js_re_test.res @@ -1,5 +1,3 @@ -module Array = Ocaml_Array - open Mocha open Test_utils @@ -26,7 +24,7 @@ describe(__MODULE__, () => { ->( x => switch x { - | Some(result) => Js.Nullable.toOption(Js.Re.captures(result)[1]) + | Some(result) => Js.Nullable.toOption(Js.Re.captures(result)->Array.getUnsafe(1)) | None => None } ) @@ -34,7 +32,8 @@ describe(__MODULE__, () => { }) test("exec_literal", () => { switch /[^.]+/->Js.Re.exec_("http://xxx.domain.com") { - | Some(res) => eq(__LOC__, Js.Nullable.return("http://xxx"), Js.Re.captures(res)[0]) + | Some(res) => + eq(__LOC__, Js.Nullable.return("http://xxx"), Js.Re.captures(res)->Array.getUnsafe(0)) | None => assert(false) } }) diff --git a/tests/tests/src/module_missing_conversion.mjs b/tests/tests/src/module_missing_conversion.mjs index 1e701b640a..4c91eb6b29 100644 --- a/tests/tests/src/module_missing_conversion.mjs +++ b/tests/tests/src/module_missing_conversion.mjs @@ -89,10 +89,7 @@ let u = [Stdlib_String]; let hh = "x".length; -let $$Array; - export { - $$Array, XX, u, hh, diff --git a/tests/tests/src/module_missing_conversion.res b/tests/tests/src/module_missing_conversion.res index 1265746701..728fdb345f 100644 --- a/tests/tests/src/module_missing_conversion.res +++ b/tests/tests/src/module_missing_conversion.res @@ -1,5 +1,3 @@ -module Array = Ocaml_Array - module type S = module type of String module XX = { @@ -9,6 +7,6 @@ module XX = { let u = [module(String: S)] let hh = { - let module(String: S) = u[0] + let module(String: S) = u->Array.getUnsafe(0) String.length("x") } diff --git a/tests/tests/src/ocaml_compat/Ocaml_Array.mjs b/tests/tests/src/ocaml_compat/Ocaml_Array.mjs deleted file mode 100644 index 2c05663d5f..0000000000 --- a/tests/tests/src/ocaml_compat/Ocaml_Array.mjs +++ /dev/null @@ -1,481 +0,0 @@ -// Generated by ReScript, PLEASE EDIT WITH CARE - -import * as Ocaml_List from "./Ocaml_List.mjs"; -import * as Pervasives from "@rescript/runtime/lib/es6/Pervasives.js"; -import * as Primitive_array from "@rescript/runtime/lib/es6/Primitive_array.js"; -import * as Primitive_exceptions from "@rescript/runtime/lib/es6/Primitive_exceptions.js"; - -let init = ((length, f) => Array.from({ length }, f)); - -function make(len, x) { - return init(len, param => x); -} - -function unsafe_sub(array, offset, length) { - return array.slice(offset, offset + length | 0); -} - -function concat(list) { - return Ocaml_List.fold_left((arr1, arr2) => arr1.concat(arr2), [], list); -} - -function create_float(len) { - return init(len, param => 0.0); -} - -function make_matrix(sx, sy, init$1) { - let x = []; - let res = init(sx, param => x); - for (let x$1 = 0; x$1 < sx; ++x$1) { - res[x$1] = init(sy, param => init$1); - } - return res; -} - -function append(a1, a2) { - let l1 = a1.length; - if (l1 === 0) { - return a2.slice(); - } else if (a2.length === 0) { - return unsafe_sub(a1, 0, l1); - } else { - return a1.concat(a2); - } -} - -function sub(a, ofs, len) { - if (ofs < 0 || len < 0 || ofs > (a.length - len | 0)) { - return Pervasives.invalid_arg("Array.sub"); - } else { - return unsafe_sub(a, ofs, len); - } -} - -function fill(a, ofs, len, v) { - if (ofs < 0 || len < 0 || ofs > (a.length - len | 0)) { - return Pervasives.invalid_arg("Array.fill"); - } - for (let i = ofs, i_finish = ofs + len | 0; i < i_finish; ++i) { - a[i] = v; - } -} - -function blit(a1, ofs1, a2, ofs2, len) { - if (len < 0 || ofs1 < 0 || ofs1 > (a1.length - len | 0) || ofs2 < 0 || ofs2 > (a2.length - len | 0)) { - return Pervasives.invalid_arg("Array.blit"); - } else { - for (let i = 0; i < len; ++i) { - a2[ofs2 + i | 0] = a1[ofs1 + i | 0]; - } - return; - } -} - -function iter(f, a) { - for (let i = 0, i_finish = a.length; i < i_finish; ++i) { - f(a[i]); - } -} - -function iter2(f, a, b) { - if (a.length !== b.length) { - return Pervasives.invalid_arg("Array.iter2: arrays must have the same length"); - } - for (let i = 0, i_finish = a.length; i < i_finish; ++i) { - f(a[i], b[i]); - } -} - -function map(f, a) { - let l = a.length; - if (l === 0) { - return []; - } - let x = f(a[0]); - let r = init(l, param => x); - for (let i = 1; i < l; ++i) { - r[i] = f(a[i]); - } - return r; -} - -function map2(f, a, b) { - let la = a.length; - let lb = b.length; - if (la !== lb) { - return Pervasives.invalid_arg("Array.map2: arrays must have the same length"); - } - if (la === 0) { - return []; - } - let x = f(a[0], b[0]); - let r = init(la, param => x); - for (let i = 1; i < la; ++i) { - r[i] = f(a[i], b[i]); - } - return r; -} - -function iteri(f, a) { - for (let i = 0, i_finish = a.length; i < i_finish; ++i) { - f(i, a[i]); - } -} - -function mapi(f, a) { - let l = a.length; - if (l === 0) { - return []; - } - let x = f(0, a[0]); - let r = init(l, param => x); - for (let i = 1; i < l; ++i) { - r[i] = f(i, a[i]); - } - return r; -} - -function to_list(a) { - let _i = a.length - 1 | 0; - let _res = /* [] */0; - while (true) { - let res = _res; - let i = _i; - if (i < 0) { - return res; - } - _res = { - hd: a[i], - tl: res - }; - _i = i - 1 | 0; - continue; - }; -} - -function list_length(_accu, _param) { - while (true) { - let param = _param; - let accu = _accu; - if (param === 0) { - return accu; - } - _param = param.tl; - _accu = accu + 1 | 0; - continue; - }; -} - -function of_list(param) { - if (param === 0) { - return []; - } - let hd = param.hd; - let len = list_length(0, param); - let a = init(len, param => hd); - let _i = 1; - let _param = param.tl; - while (true) { - let param$1 = _param; - let i = _i; - if (param$1 === 0) { - return a; - } - a[i] = param$1.hd; - _param = param$1.tl; - _i = i + 1 | 0; - continue; - }; -} - -function fold_left(f, x, a) { - let r = x; - for (let i = 0, i_finish = a.length; i < i_finish; ++i) { - r = f(r, a[i]); - } - return r; -} - -function fold_right(f, a, x) { - let r = x; - for (let i = a.length - 1 | 0; i >= 0; --i) { - r = f(a[i], r); - } - return r; -} - -function exists(p, a) { - let n = a.length; - let _i = 0; - while (true) { - let i = _i; - if (i === n) { - return false; - } - if (p(a[i])) { - return true; - } - _i = i + 1 | 0; - continue; - }; -} - -function for_all(p, a) { - let n = a.length; - let _i = 0; - while (true) { - let i = _i; - if (i === n) { - return true; - } - if (!p(a[i])) { - return false; - } - _i = i + 1 | 0; - continue; - }; -} - -function mem(x, a) { - let n = a.length; - let _i = 0; - while (true) { - let i = _i; - if (i === n) { - return false; - } - if (a[i] === x) { - return true; - } - _i = i + 1 | 0; - continue; - }; -} - -function memq(x, a) { - let n = a.length; - let _i = 0; - while (true) { - let i = _i; - if (i === n) { - return false; - } - if (x === a[i]) { - return true; - } - _i = i + 1 | 0; - continue; - }; -} - -let Bottom = /* @__PURE__ */Primitive_exceptions.create("Ocaml_Array.Bottom"); - -function sort(cmp, a) { - let maxson = (l, i) => { - let i31 = ((i + i | 0) + i | 0) + 1 | 0; - let x = i31; - if ((i31 + 2 | 0) < l) { - if (cmp(Primitive_array.get(a, i31), Primitive_array.get(a, i31 + 1 | 0)) < 0) { - x = i31 + 1 | 0; - } - if (cmp(Primitive_array.get(a, x), Primitive_array.get(a, i31 + 2 | 0)) < 0) { - x = i31 + 2 | 0; - } - return x; - } - if ((i31 + 1 | 0) < l && cmp(Primitive_array.get(a, i31), Primitive_array.get(a, i31 + 1 | 0)) < 0) { - return i31 + 1 | 0; - } - if (i31 < l) { - return i31; - } - throw { - RE_EXN_ID: Bottom, - _1: i, - Error: new Error() - }; - }; - let trickle = (l, i, e) => { - try { - let _i = i; - while (true) { - let i$1 = _i; - let j = maxson(l, i$1); - if (cmp(Primitive_array.get(a, j), e) <= 0) { - return Primitive_array.set(a, i$1, e); - } - Primitive_array.set(a, i$1, Primitive_array.get(a, j)); - _i = j; - continue; - }; - } catch (raw_i) { - let i$2 = Primitive_exceptions.internalToException(raw_i); - if (i$2.RE_EXN_ID === Bottom) { - return Primitive_array.set(a, i$2._1, e); - } - throw i$2; - } - }; - let bubble = (l, i) => { - try { - let _i = i; - while (true) { - let i$1 = _i; - let j = maxson(l, i$1); - Primitive_array.set(a, i$1, Primitive_array.get(a, j)); - _i = j; - continue; - }; - } catch (raw_i) { - let i$2 = Primitive_exceptions.internalToException(raw_i); - if (i$2.RE_EXN_ID === Bottom) { - return i$2._1; - } - throw i$2; - } - }; - let trickleup = (_i, e) => { - while (true) { - let i = _i; - let father = (i - 1 | 0) / 3 | 0; - if (i === father) { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "Ocaml_Array.res", - 296, - 4 - ], - Error: new Error() - }; - } - if (cmp(Primitive_array.get(a, father), e) >= 0) { - return Primitive_array.set(a, i, e); - } - Primitive_array.set(a, i, Primitive_array.get(a, father)); - if (father <= 0) { - return Primitive_array.set(a, 0, e); - } - _i = father; - continue; - }; - }; - let l = a.length; - for (let i = ((l + 1 | 0) / 3 | 0) - 1 | 0; i >= 0; --i) { - trickle(l, i, Primitive_array.get(a, i)); - } - for (let i$1 = l - 1 | 0; i$1 >= 2; --i$1) { - let e = Primitive_array.get(a, i$1); - Primitive_array.set(a, i$1, Primitive_array.get(a, 0)); - trickleup(bubble(i$1, 0), e); - } - if (l <= 1) { - return; - } - let e$1 = Primitive_array.get(a, 1); - Primitive_array.set(a, 1, Primitive_array.get(a, 0)); - Primitive_array.set(a, 0, e$1); -} - -function stable_sort(cmp, a) { - let merge = (src1ofs, src1len, src2, src2ofs, src2len, dst, dstofs) => { - let src1r = src1ofs + src1len | 0; - let src2r = src2ofs + src2len | 0; - let _i1 = src1ofs; - let _s1 = Primitive_array.get(a, src1ofs); - let _i2 = src2ofs; - let _s2 = Primitive_array.get(src2, src2ofs); - let _d = dstofs; - while (true) { - let d = _d; - let s2 = _s2; - let i2 = _i2; - let s1 = _s1; - let i1 = _i1; - if (cmp(s1, s2) <= 0) { - Primitive_array.set(dst, d, s1); - let i1$1 = i1 + 1 | 0; - if (i1$1 >= src1r) { - return blit(src2, i2, dst, d + 1 | 0, src2r - i2 | 0); - } - _d = d + 1 | 0; - _s1 = Primitive_array.get(a, i1$1); - _i1 = i1$1; - continue; - } - Primitive_array.set(dst, d, s2); - let i2$1 = i2 + 1 | 0; - if (i2$1 >= src2r) { - return blit(a, i1, dst, d + 1 | 0, src1r - i1 | 0); - } - _d = d + 1 | 0; - _s2 = Primitive_array.get(src2, i2$1); - _i2 = i2$1; - continue; - }; - }; - let isortto = (srcofs, dst, dstofs, len) => { - for (let i = 0; i < len; ++i) { - let e = Primitive_array.get(a, srcofs + i | 0); - let j = (dstofs + i | 0) - 1 | 0; - while (j >= dstofs && cmp(Primitive_array.get(dst, j), e) > 0) { - Primitive_array.set(dst, j + 1 | 0, Primitive_array.get(dst, j)); - j = j - 1 | 0; - }; - Primitive_array.set(dst, j + 1 | 0, e); - } - }; - let sortto = (srcofs, dst, dstofs, len) => { - if (len <= 5) { - return isortto(srcofs, dst, dstofs, len); - } - let l1 = len / 2 | 0; - let l2 = len - l1 | 0; - sortto(srcofs + l1 | 0, dst, dstofs + l1 | 0, l2); - sortto(srcofs, a, srcofs + l2 | 0, l1); - merge(srcofs + l2 | 0, l1, dst, dstofs + l1 | 0, l2, dst, dstofs); - }; - let l = a.length; - if (l <= 5) { - return isortto(0, a, 0, l); - } - let l1 = l / 2 | 0; - let l2 = l - l1 | 0; - let x = Primitive_array.get(a, 0); - let t = init(l2, param => x); - sortto(l1, t, 0, l2); - sortto(0, a, l2, l1); - merge(l2, l1, t, 0, l2, a, 0); -} - -let fast_sort = stable_sort; - -export { - make, - create_float, - init, - make_matrix, - append, - concat, - sub, - fill, - blit, - to_list, - of_list, - iter, - iteri, - map, - mapi, - fold_left, - fold_right, - iter2, - map2, - for_all, - exists, - mem, - memq, - sort, - stable_sort, - fast_sort, -} -/* No side effect */ diff --git a/tests/tests/src/ocaml_compat/Ocaml_Array.res b/tests/tests/src/ocaml_compat/Ocaml_Array.res deleted file mode 100644 index 4f714df4e3..0000000000 --- a/tests/tests/src/ocaml_compat/Ocaml_Array.res +++ /dev/null @@ -1,385 +0,0 @@ -// FIXME: -// This exists for compatibility reason. -// Move this into Pervasives or Core - -module List = Ocaml_List - -// Caution: `Array.get` is implicitly used by `array[idx]` syntax -external get: (array<'a>, int) => 'a = "%array_safe_get" - -// Caution: `Array.set` is implicitly used by `array[idx]` syntax -external set: (array<'a>, int, 'a) => unit = "%array_safe_set" - -// Below is all deprecated and should be removed in v13 - -external length: array<'a> => int = "%array_length" - -external unsafe_get: (array<'a>, int) => 'a = "%array_unsafe_get" - -external unsafe_set: (array<'a>, int, 'a) => unit = "%array_unsafe_set" - -let init: (int, int => 'a) => array<'a> = %raw(`(length, f) => Array.from({ length }, f)`) - -let make = (len, x) => init(len, _ => x) - -@send external slice: (array<'a>, int, int) => array<'a> = "slice" -let unsafe_sub = (array, offset, length) => array->slice(offset, offset + length) - -@send external concat: (array<'a>, array<'a>) => array<'a> = "concat" -@send external append_prim: (array<'a>, array<'a>) => array<'a> = "concat" - -let concat = list => { - List.fold_left((arr1, arr2) => arr1->concat(arr2), [], list) -} - -let unsafe_blit = (srcArray, srcOffset, destArray, destOffset, len) => { - for i in 0 to len - 1 { - destArray->unsafe_set(destOffset + i, srcArray->unsafe_get(srcOffset + i)) - } -} - -let create_float = len => make(len, 0.0) - -let make_matrix = (sx, sy, init) => { - let res = make(sx, []) - for x in 0 to pred(sx) { - unsafe_set(res, x, make(sy, init)) - } - res -} - -@send external copy: array<'a> => array<'a> = "slice" - -let append = (a1, a2) => { - let l1 = length(a1) - if l1 == 0 { - copy(a2) - } else if length(a2) == 0 { - unsafe_sub(a1, 0, l1) - } else { - append_prim(a1, a2) - } -} - -let sub = (a, ofs, len) => - if ofs < 0 || (len < 0 || ofs > length(a) - len) { - invalid_arg("Array.sub") - } else { - unsafe_sub(a, ofs, len) - } - -let fill = (a, ofs, len, v) => - if ofs < 0 || (len < 0 || ofs > length(a) - len) { - invalid_arg("Array.fill") - } else { - for i in ofs to ofs + len - 1 { - unsafe_set(a, i, v) - } - } - -let blit = (a1, ofs1, a2, ofs2, len) => - if len < 0 || (ofs1 < 0 || (ofs1 > length(a1) - len || (ofs2 < 0 || ofs2 > length(a2) - len))) { - invalid_arg("Array.blit") - } else { - unsafe_blit(a1, ofs1, a2, ofs2, len) - } - -let iter = (f, a) => - for i in 0 to length(a) - 1 { - f(unsafe_get(a, i)) - } - -let iter2 = (f, a, b) => - if length(a) != length(b) { - invalid_arg("Array.iter2: arrays must have the same length") - } else { - for i in 0 to length(a) - 1 { - f(unsafe_get(a, i), unsafe_get(b, i)) - } - } - -let map = (f, a) => { - let l = length(a) - if l == 0 { - [] - } else { - let r = make(l, f(unsafe_get(a, 0))) - for i in 1 to l - 1 { - unsafe_set(r, i, f(unsafe_get(a, i))) - } - r - } -} - -let map2 = (f, a, b) => { - let la = length(a) - let lb = length(b) - if la != lb { - invalid_arg("Array.map2: arrays must have the same length") - } else if la == 0 { - [] - } else { - let r = make(la, f(unsafe_get(a, 0), unsafe_get(b, 0))) - for i in 1 to la - 1 { - unsafe_set(r, i, f(unsafe_get(a, i), unsafe_get(b, i))) - } - r - } -} - -let iteri = (f, a) => - for i in 0 to length(a) - 1 { - f(i, unsafe_get(a, i)) - } - -let mapi = (f, a) => { - let l = length(a) - if l == 0 { - [] - } else { - let r = make(l, f(0, unsafe_get(a, 0))) - for i in 1 to l - 1 { - unsafe_set(r, i, f(i, unsafe_get(a, i))) - } - r - } -} - -let to_list = a => { - let rec tolist = (i, res) => - if i < 0 { - res - } else { - tolist(i - 1, list{unsafe_get(a, i), ...res}) - } - tolist(length(a) - 1, list{}) -} - -/* Cannot use List.length here because the List module depends on Array. */ -let rec list_length = (accu, param) => - switch param { - | list{} => accu - | list{_, ...t} => list_length(succ(accu), t) - } - -let of_list = param => - switch param { - | list{} => [] - | list{hd, ...tl} as l => - let a = make(list_length(0, l), hd) - let rec fill = (i, param) => - switch param { - | list{} => a - | list{hd, ...tl} => - unsafe_set(a, i, hd) - fill(i + 1, tl) - } - fill(1, tl) - } - -let fold_left = (f, x, a) => { - let r = ref(x) - for i in 0 to length(a) - 1 { - r := f(r.contents, unsafe_get(a, i)) - } - r.contents -} - -let fold_right = (f, a, x) => { - let r = ref(x) - for i in length(a) - 1 downto 0 { - r := f(unsafe_get(a, i), r.contents) - } - r.contents -} - -let exists = (p, a) => { - let n = length(a) - let rec loop = i => - if i == n { - false - } else if p(unsafe_get(a, i)) { - true - } else { - loop(succ(i)) - } - loop(0) -} - -let for_all = (p, a) => { - let n = length(a) - let rec loop = i => - if i == n { - true - } else if p(unsafe_get(a, i)) { - loop(succ(i)) - } else { - false - } - loop(0) -} - -let mem = (x, a) => { - let n = length(a) - let rec loop = i => - if i == n { - false - } else if compare(unsafe_get(a, i), x) == 0 { - true - } else { - loop(succ(i)) - } - loop(0) -} - -let memq = (x, a) => { - let n = length(a) - let rec loop = i => - if i == n { - false - } else if x === unsafe_get(a, i) { - true - } else { - loop(succ(i)) - } - loop(0) -} - -exception Bottom(int) -let sort = (cmp, a) => { - let maxson = (l, i) => { - let i31 = i + i + i + 1 - let x = ref(i31) - if i31 + 2 < l { - if cmp(get(a, i31), get(a, i31 + 1)) < 0 { - x := i31 + 1 - } - if cmp(get(a, x.contents), get(a, i31 + 2)) < 0 { - x := i31 + 2 - } - x.contents - } else if i31 + 1 < l && cmp(get(a, i31), get(a, i31 + 1)) < 0 { - i31 + 1 - } else if i31 < l { - i31 - } else { - throw(Bottom(i)) - } - } - - let rec trickledown = (l, i, e) => { - let j = maxson(l, i) - if cmp(get(a, j), e) > 0 { - set(a, i, get(a, j)) - trickledown(l, j, e) - } else { - set(a, i, e) - } - } - - let trickle = (l, i, e) => - try trickledown(l, i, e) catch { - | Bottom(i) => set(a, i, e) - } - let rec bubbledown = (l, i) => { - let j = maxson(l, i) - set(a, i, get(a, j)) - bubbledown(l, j) - } - - let bubble = (l, i) => - try bubbledown(l, i) catch { - | Bottom(i) => i - } - let rec trickleup = (i, e) => { - let father = (i - 1) / 3 - assert(i != father) - if cmp(get(a, father), e) < 0 { - set(a, i, get(a, father)) - if father > 0 { - trickleup(father, e) - } else { - set(a, 0, e) - } - } else { - set(a, i, e) - } - } - - let l = length(a) - for i in (l + 1) / 3 - 1 downto 0 { - trickle(l, i, get(a, i)) - } - for i in l - 1 downto 2 { - let e = get(a, i) - set(a, i, get(a, 0)) - trickleup(bubble(i, 0), e) - } - if l > 1 { - let e = get(a, 1) - set(a, 1, get(a, 0)) - set(a, 0, e) - } -} - -let cutoff = 5 -let stable_sort = (cmp, a) => { - let merge = (src1ofs, src1len, src2, src2ofs, src2len, dst, dstofs) => { - let src1r = src1ofs + src1len and src2r = src2ofs + src2len - let rec loop = (i1, s1, i2, s2, d) => - if cmp(s1, s2) <= 0 { - set(dst, d, s1) - let i1 = i1 + 1 - if i1 < src1r { - loop(i1, get(a, i1), i2, s2, d + 1) - } else { - blit(src2, i2, dst, d + 1, src2r - i2) - } - } else { - set(dst, d, s2) - let i2 = i2 + 1 - if i2 < src2r { - loop(i1, s1, i2, get(src2, i2), d + 1) - } else { - blit(a, i1, dst, d + 1, src1r - i1) - } - } - loop(src1ofs, get(a, src1ofs), src2ofs, get(src2, src2ofs), dstofs) - } - - let isortto = (srcofs, dst, dstofs, len) => - for i in 0 to len - 1 { - let e = get(a, srcofs + i) - let j = ref(dstofs + i - 1) - while j.contents >= dstofs && cmp(get(dst, j.contents), e) > 0 { - set(dst, j.contents + 1, get(dst, j.contents)) - decr(j) - } - set(dst, j.contents + 1, e) - } - - let rec sortto = (srcofs, dst, dstofs, len) => - if len <= cutoff { - isortto(srcofs, dst, dstofs, len) - } else { - let l1 = len / 2 - let l2 = len - l1 - sortto(srcofs + l1, dst, dstofs + l1, l2) - sortto(srcofs, a, srcofs + l2, l1) - merge(srcofs + l2, l1, dst, dstofs + l1, l2, dst, dstofs) - } - - let l = length(a) - if l <= cutoff { - isortto(0, a, 0, l) - } else { - let l1 = l / 2 - let l2 = l - l1 - let t = make(l2, get(a, 0)) - sortto(l1, t, 0, l2) - sortto(0, a, l2, l1) - merge(l2, l1, t, 0, l2, a, 0) - } -} - -let fast_sort = stable_sort diff --git a/tests/tests/src/ocaml_compat/Ocaml_Array.resi b/tests/tests/src/ocaml_compat/Ocaml_Array.resi deleted file mode 100644 index da0cca40c3..0000000000 --- a/tests/tests/src/ocaml_compat/Ocaml_Array.resi +++ /dev/null @@ -1,248 +0,0 @@ -// FIXME: -// This exists for compatibility reason. -// Move this into Pervasives or Core - -// Caution: `Array.get` is implicitly used by `array[idx]` syntax -external get: (array<'a>, int) => 'a = "%array_safe_get" - -// Caution: `Array.set` is implicitly used by `array[idx]` syntax -external set: (array<'a>, int, 'a) => unit = "%array_safe_set" - -// Below is all deprecated and should be removed in v13 - -/** Return the length (number of elements) of the given array. */ -@deprecated("Use Core instead. This will be removed in v13") -external length: array<'a> => int = "%array_length" - -/** [Array.make n x] returns a fresh array of length [n], - initialized with [x]. - All the elements of this new array are initially - physically equal to [x] (in the sense of the [==] predicate). - Consequently, if [x] is mutable, it is shared among all elements - of the array, and modifying [x] through one of the array entries - will modify all other entries at the same time. - - Raise [Invalid_argument] if [n < 0] or [n > Sys.max_array_length]. - If the value of [x] is a floating-point number, then the maximum - size is only [Sys.max_array_length / 2].*/ -@deprecated("Use Core instead. This will be removed in v13") -let make: (int, 'a) => array<'a> - -/** [Array.create_float n] returns a fresh float array of length [n], - with uninitialized data. - @since 4.03 */ -@deprecated("Use Core instead. This will be removed in v13") -let create_float: int => array - -/** [Array.init n f] returns a fresh array of length [n], - with element number [i] initialized to the result of [f i]. - In other terms, [Array.init n f] tabulates the results of [f] - applied to the integers [0] to [n-1]. - - Raise [Invalid_argument] if [n < 0] or [n > Sys.max_array_length]. - If the return type of [f] is [float], then the maximum - size is only [Sys.max_array_length / 2].*/ -@deprecated("Use Core instead. This will be removed in v13") -let init: (int, int => 'a) => array<'a> - -/** [Array.make_matrix dimx dimy e] returns a two-dimensional array - (an array of arrays) with first dimension [dimx] and - second dimension [dimy]. All the elements of this new matrix - are initially physically equal to [e]. - The element ([x,y]) of a matrix [m] is accessed - with the notation [m.(x).(y)]. - - Raise [Invalid_argument] if [dimx] or [dimy] is negative or - greater than {!Sys.max_array_length}. - If the value of [e] is a floating-point number, then the maximum - size is only [Sys.max_array_length / 2]. */ -@deprecated("Use Core instead. This will be removed in v13") -let make_matrix: (int, int, 'a) => array> - -/** [Array.append v1 v2] returns a fresh array containing the - concatenation of the arrays [v1] and [v2]. */ -@deprecated("Use Core instead. This will be removed in v13") -let append: (array<'a>, array<'a>) => array<'a> - -/** Same as {!Array.append}, but concatenates a list of arrays. */ -@deprecated("Use Core instead. This will be removed in v13") -let concat: list> => array<'a> - -/** [Array.sub a start len] returns a fresh array of length [len], - containing the elements number [start] to [start + len - 1] - of array [a]. - - Raise [Invalid_argument "Array.sub"] if [start] and [len] do not - designate a valid subarray of [a]; that is, if - [start < 0], or [len < 0], or [start + len > Array.length a]. */ -@deprecated("Use Core instead. This will be removed in v13") -let sub: (array<'a>, int, int) => array<'a> - -/** [Array.copy a] returns a copy of [a], that is, a fresh array - containing the same elements as [a]. */ -@deprecated("Use Core instead. This will be removed in v13") @send -external copy: array<'a> => array<'a> = "slice" - -/** [Array.fill a ofs len x] modifies the array [a] in place, - storing [x] in elements number [ofs] to [ofs + len - 1]. - - Raise [Invalid_argument "Array.fill"] if [ofs] and [len] do not - designate a valid subarray of [a]. */ -@deprecated("Use Core instead. This will be removed in v13") -let fill: (array<'a>, int, int, 'a) => unit - -/** [Array.blit v1 o1 v2 o2 len] copies [len] elements - from array [v1], starting at element number [o1], to array [v2], - starting at element number [o2]. It works correctly even if - [v1] and [v2] are the same array, and the source and - destination chunks overlap. - - Raise [Invalid_argument "Array.blit"] if [o1] and [len] do not - designate a valid subarray of [v1], or if [o2] and [len] do not - designate a valid subarray of [v2]. */ -@deprecated("Use Core instead. This will be removed in v13") -let blit: (array<'a>, int, array<'a>, int, int) => unit - -/** [Array.to_list a] returns the list of all the elements of [a]. */ -@deprecated("Use Core instead. This will be removed in v13") -let to_list: array<'a> => list<'a> - -/** [Array.of_list l] returns a fresh array containing the elements - of [l]. */ -@deprecated("Use Core instead. This will be removed in v13") -let of_list: list<'a> => array<'a> - -/* {1 Iterators} */ - -/** [Array.iter f a] applies function [f] in turn to all - the elements of [a]. It is equivalent to - [f a.(0); f a.(1); ...; f a.(Array.length a - 1); ()]. */ -@deprecated("Use Core instead. This will be removed in v13") -let iter: ('a => unit, array<'a>) => unit - -/** Same as {!Array.iter}, but the - function is applied with the index of the element as first argument, - and the element itself as second argument. */ -@deprecated("Use Core instead. This will be removed in v13") -let iteri: ((int, 'a) => unit, array<'a>) => unit - -/** [Array.map f a] applies function [f] to all the elements of [a], - and builds an array with the results returned by [f]: - [[| f a.(0); f a.(1); ...; f a.(Array.length a - 1) |]]. */ -@deprecated("Use Core instead. This will be removed in v13") -let map: ('a => 'b, array<'a>) => array<'b> - -/** Same as {!Array.map}, but the - function is applied to the index of the element as first argument, - and the element itself as second argument. */ -@deprecated("Use Core instead. This will be removed in v13") -let mapi: ((int, 'a) => 'b, array<'a>) => array<'b> - -/** [Array.fold_left f x a] computes - [f (... (f (f x a.(0)) a.(1)) ...) a.(n-1)], - where [n] is the length of the array [a]. */ -@deprecated("Use Core instead. This will be removed in v13") -let fold_left: (('a, 'b) => 'a, 'a, array<'b>) => 'a - -/** [Array.fold_right f a x] computes - [f a.(0) (f a.(1) ( ... (f a.(n-1) x) ...))], - where [n] is the length of the array [a]. */ -@deprecated("Use Core instead. This will be removed in v13") -let fold_right: (('b, 'a) => 'a, array<'b>, 'a) => 'a - -/* {1 Iterators on two arrays} */ - -/** [Array.iter2 f a b] applies function [f] to all the elements of [a] - and [b]. - Raise [Invalid_argument] if the arrays are not the same size. - @since 4.03.0 */ -@deprecated("Use Core instead. This will be removed in v13") -let iter2: (('a, 'b) => unit, array<'a>, array<'b>) => unit - -/** [Array.map2 f a b] applies function [f] to all the elements of [a] - and [b], and builds an array with the results returned by [f]: - [[| f a.(0) b.(0); ...; f a.(Array.length a - 1) b.(Array.length b - 1)|]]. - Raise [Invalid_argument] if the arrays are not the same size. - @since 4.03.0 */ -@deprecated("Use Core instead. This will be removed in v13") -let map2: (('a, 'b) => 'c, array<'a>, array<'b>) => array<'c> - -/* {1 Array scanning} */ - -/** [Array.for_all p [|a1; ...; an|]] checks if all elements of the array - satisfy the predicate [p]. That is, it returns - [(p a1) && (p a2) && ... && (p an)]. - @since 4.03.0 */ -@deprecated("Use Core instead. This will be removed in v13") -let for_all: ('a => bool, array<'a>) => bool - -/** [Array.exists p [|a1; ...; an|]] checks if at least one element of - the array satisfies the predicate [p]. That is, it returns - [(p a1) || (p a2) || ... || (p an)]. - @since 4.03.0 */ -@deprecated("Use Core instead. This will be removed in v13") -let exists: ('a => bool, array<'a>) => bool - -/** [mem a l] is true if and only if [a] is equal - to an element of [l]. - @since 4.03.0 */ -@deprecated("Use Core instead. This will be removed in v13") -let mem: ('a, array<'a>) => bool - -/** Same as {!Array.mem}, but uses physical equality instead of structural - equality to compare array elements. - @since 4.03.0 */ -@deprecated("Use Core instead. This will be removed in v13") -let memq: ('a, array<'a>) => bool - -/* {1 Sorting} */ - -/** Sort an array in increasing order according to a comparison - function. The comparison function must return 0 if its arguments - compare as equal, a positive integer if the first is greater, - and a negative integer if the first is smaller (see below for a - complete specification). For example, {!Pervasives.compare} is - a suitable comparison function, provided there are no floating-point - NaN values in the data. After calling [Array.sort], the - array is sorted in place in increasing order. - [Array.sort] is guaranteed to run in constant heap space - and (at most) logarithmic stack space. - - The current implementation uses Heap Sort. It runs in constant - stack space. - - Specification of the comparison function: - Let [a] be the array and [cmp] the comparison function. The following - must be true for all x, y, z in a : -- [cmp x y] > 0 if and only if [cmp y x] < 0 -- if [cmp x y] >= 0 and [cmp y z] >= 0 then [cmp x z] >= 0 - - When [Array.sort] returns, [a] contains the same elements as before, - reordered in such a way that for all i and j valid indices of [a] : -- [cmp a.(i) a.(j)] >= 0 if and only if i >= j -*/ -@deprecated("Use Core instead. This will be removed in v13") -let sort: (('a, 'a) => int, array<'a>) => unit - -/** Same as {!Array.sort}, but the sorting algorithm is stable (i.e. - elements that compare equal are kept in their original order) and - not guaranteed to run in constant heap space. - - The current implementation uses Merge Sort. It uses [n/2] - words of heap space, where [n] is the length of the array. - It is usually faster than the current implementation of {!Array.sort}. -*/ -@deprecated("Use Core instead. This will be removed in v13") -let stable_sort: (('a, 'a) => int, array<'a>) => unit - -/** Same as {!Array.sort} or {!Array.stable_sort}, whichever is faster - on typical input. -*/ -@deprecated("Use Core instead. This will be removed in v13") -let fast_sort: (('a, 'a) => int, array<'a>) => unit - -@deprecated("Use Core instead. This will be removed in v13") -external unsafe_get: (array<'a>, int) => 'a = "%array_unsafe_get" - -@deprecated("Use Core instead. This will be removed in v13") -external unsafe_set: (array<'a>, int, 'a) => unit = "%array_unsafe_set" diff --git a/tests/tests/src/ocaml_compat/Ocaml_Hashtbl.res b/tests/tests/src/ocaml_compat/Ocaml_Hashtbl.res deleted file mode 100644 index b581705f85..0000000000 --- a/tests/tests/src/ocaml_compat/Ocaml_Hashtbl.res +++ /dev/null @@ -1,10 +0,0 @@ -// FIXME: -// This exists for compatibility reason. -// Move this into Pervasives or Core - -// Below is all deprecated and should be removed in v13 - -@noalloc external seeded_hash_param: (int, int, int, 'a) => int = "%hash" - -@deprecated("Use an alternative library. This will be removed in v13") -let hash = x => seeded_hash_param(10, 100, 0, x) diff --git a/tests/tests/src/ocaml_compat/Ocaml_Hashtbl.resi b/tests/tests/src/ocaml_compat/Ocaml_Hashtbl.resi deleted file mode 100644 index 411fe9b6f0..0000000000 --- a/tests/tests/src/ocaml_compat/Ocaml_Hashtbl.resi +++ /dev/null @@ -1,2 +0,0 @@ -@deprecated("Use an alternative library. This will be removed in v13") -let hash: 'a => int diff --git a/tests/tests/src/ocaml_compat/Ocaml_List.mjs b/tests/tests/src/ocaml_compat/Ocaml_List.mjs deleted file mode 100644 index be952fcfe1..0000000000 --- a/tests/tests/src/ocaml_compat/Ocaml_List.mjs +++ /dev/null @@ -1,1630 +0,0 @@ -// Generated by ReScript, PLEASE EDIT WITH CARE - -import * as Pervasives from "@rescript/runtime/lib/es6/Pervasives.js"; -import * as Primitive_option from "@rescript/runtime/lib/es6/Primitive_option.js"; - -function length(l) { - let _len = 0; - let _param = l; - while (true) { - let param = _param; - let len = _len; - if (param === 0) { - return len; - } - _param = param.tl; - _len = len + 1 | 0; - continue; - }; -} - -function cons(a, l) { - return { - hd: a, - tl: l - }; -} - -function hd(param) { - if (param !== 0) { - return param.hd; - } else { - return Pervasives.failwith("hd"); - } -} - -function tl(param) { - if (param !== 0) { - return param.tl; - } else { - return Pervasives.failwith("tl"); - } -} - -function nth(l, n) { - if (n < 0) { - return Pervasives.invalid_arg("List.nth"); - } - let _l = l; - let _n = n; - while (true) { - let n$1 = _n; - let l$1 = _l; - if (l$1 === 0) { - return Pervasives.failwith("nth"); - } - if (n$1 === 0) { - return l$1.hd; - } - _n = n$1 - 1 | 0; - _l = l$1.tl; - continue; - }; -} - -function nth_opt(l, n) { - if (n < 0) { - return Pervasives.invalid_arg("List.nth"); - } - let _l = l; - let _n = n; - while (true) { - let n$1 = _n; - let l$1 = _l; - if (l$1 === 0) { - return; - } - if (n$1 === 0) { - return Primitive_option.some(l$1.hd); - } - _n = n$1 - 1 | 0; - _l = l$1.tl; - continue; - }; -} - -function rev_append(_l1, _l2) { - while (true) { - let l2 = _l2; - let l1 = _l1; - if (l1 === 0) { - return l2; - } - _l2 = { - hd: l1.hd, - tl: l2 - }; - _l1 = l1.tl; - continue; - }; -} - -function rev(l) { - return rev_append(l, /* [] */0); -} - -function init_tailrec_aux(_acc, _i, n, f) { - while (true) { - let i = _i; - let acc = _acc; - if (i >= n) { - return acc; - } - _i = i + 1 | 0; - _acc = { - hd: f(i), - tl: acc - }; - continue; - }; -} - -function init_aux(i, n, f) { - if (i >= n) { - return /* [] */0; - } - let r = f(i); - return { - hd: r, - tl: init_aux(i + 1 | 0, n, f) - }; -} - -function init(len, f) { - if (len < 0) { - return Pervasives.invalid_arg("List.init"); - } else if (len > 10000) { - return rev_append(init_tailrec_aux(/* [] */0, 0, len, f), /* [] */0); - } else { - return init_aux(0, len, f); - } -} - -function flatten(param) { - if (param !== 0) { - return Pervasives.$at(param.hd, flatten(param.tl)); - } else { - return /* [] */0; - } -} - -function map(f, param) { - if (param === 0) { - return /* [] */0; - } - let r = f(param.hd); - return { - hd: r, - tl: map(f, param.tl) - }; -} - -function mapi(i, f, param) { - if (param === 0) { - return /* [] */0; - } - let r = f(i, param.hd); - return { - hd: r, - tl: mapi(i + 1 | 0, f, param.tl) - }; -} - -function mapi$1(f, l) { - return mapi(0, f, l); -} - -function rev_map(f, l) { - let _accu = /* [] */0; - let _param = l; - while (true) { - let param = _param; - let accu = _accu; - if (param === 0) { - return accu; - } - _param = param.tl; - _accu = { - hd: f(param.hd), - tl: accu - }; - continue; - }; -} - -function iter(f, _param) { - while (true) { - let param = _param; - if (param === 0) { - return; - } - f(param.hd); - _param = param.tl; - continue; - }; -} - -function iteri(f, l) { - let _i = 0; - let _param = l; - while (true) { - let param = _param; - let i = _i; - if (param === 0) { - return; - } - f(i, param.hd); - _param = param.tl; - _i = i + 1 | 0; - continue; - }; -} - -function fold_left(f, _accu, _l) { - while (true) { - let l = _l; - let accu = _accu; - if (l === 0) { - return accu; - } - _l = l.tl; - _accu = f(accu, l.hd); - continue; - }; -} - -function fold_right(f, l, accu) { - if (l !== 0) { - return f(l.hd, fold_right(f, l.tl, accu)); - } else { - return accu; - } -} - -function map2(f, l1, l2) { - if (l1 === 0) { - if (l2 !== 0) { - return Pervasives.invalid_arg("List.map2"); - } else { - return /* [] */0; - } - } - if (l2 === 0) { - return Pervasives.invalid_arg("List.map2"); - } - let r = f(l1.hd, l2.hd); - return { - hd: r, - tl: map2(f, l1.tl, l2.tl) - }; -} - -function rev_map2(f, l1, l2) { - let _accu = /* [] */0; - let _l1 = l1; - let _l2 = l2; - while (true) { - let l2$1 = _l2; - let l1$1 = _l1; - let accu = _accu; - if (l1$1 === 0) { - if (l2$1 !== 0) { - return Pervasives.invalid_arg("List.rev_map2"); - } else { - return accu; - } - } - if (l2$1 === 0) { - return Pervasives.invalid_arg("List.rev_map2"); - } - _l2 = l2$1.tl; - _l1 = l1$1.tl; - _accu = { - hd: f(l1$1.hd, l2$1.hd), - tl: accu - }; - continue; - }; -} - -function iter2(f, _l1, _l2) { - while (true) { - let l2 = _l2; - let l1 = _l1; - if (l1 === 0) { - if (l2 !== 0) { - return Pervasives.invalid_arg("List.iter2"); - } else { - return; - } - } - if (l2 === 0) { - return Pervasives.invalid_arg("List.iter2"); - } - f(l1.hd, l2.hd); - _l2 = l2.tl; - _l1 = l1.tl; - continue; - }; -} - -function fold_left2(f, _accu, _l1, _l2) { - while (true) { - let l2 = _l2; - let l1 = _l1; - let accu = _accu; - if (l1 === 0) { - if (l2 !== 0) { - return Pervasives.invalid_arg("List.fold_left2"); - } else { - return accu; - } - } - if (l2 === 0) { - return Pervasives.invalid_arg("List.fold_left2"); - } - _l2 = l2.tl; - _l1 = l1.tl; - _accu = f(accu, l1.hd, l2.hd); - continue; - }; -} - -function fold_right2(f, l1, l2, accu) { - if (l1 !== 0) { - if (l2 !== 0) { - return f(l1.hd, l2.hd, fold_right2(f, l1.tl, l2.tl, accu)); - } else { - return Pervasives.invalid_arg("List.fold_right2"); - } - } else if (l2 !== 0) { - return Pervasives.invalid_arg("List.fold_right2"); - } else { - return accu; - } -} - -function for_all(p, _param) { - while (true) { - let param = _param; - if (param === 0) { - return true; - } - if (!p(param.hd)) { - return false; - } - _param = param.tl; - continue; - }; -} - -function exists(p, _param) { - while (true) { - let param = _param; - if (param === 0) { - return false; - } - if (p(param.hd)) { - return true; - } - _param = param.tl; - continue; - }; -} - -function for_all2(p, _l1, _l2) { - while (true) { - let l2 = _l2; - let l1 = _l1; - if (l1 === 0) { - if (l2 !== 0) { - return Pervasives.invalid_arg("List.for_all2"); - } else { - return true; - } - } - if (l2 === 0) { - return Pervasives.invalid_arg("List.for_all2"); - } - if (!p(l1.hd, l2.hd)) { - return false; - } - _l2 = l2.tl; - _l1 = l1.tl; - continue; - }; -} - -function exists2(p, _l1, _l2) { - while (true) { - let l2 = _l2; - let l1 = _l1; - if (l1 === 0) { - if (l2 !== 0) { - return Pervasives.invalid_arg("List.exists2"); - } else { - return false; - } - } - if (l2 === 0) { - return Pervasives.invalid_arg("List.exists2"); - } - if (p(l1.hd, l2.hd)) { - return true; - } - _l2 = l2.tl; - _l1 = l1.tl; - continue; - }; -} - -function mem(x, _param) { - while (true) { - let param = _param; - if (param === 0) { - return false; - } - if (param.hd === x) { - return true; - } - _param = param.tl; - continue; - }; -} - -function memq(x, _param) { - while (true) { - let param = _param; - if (param === 0) { - return false; - } - if (param.hd === x) { - return true; - } - _param = param.tl; - continue; - }; -} - -function assoc(x, _param) { - while (true) { - let param = _param; - if (param !== 0) { - let match = param.hd; - if (match[0] === x) { - return match[1]; - } - _param = param.tl; - continue; - } - throw { - RE_EXN_ID: "Not_found", - Error: new Error() - }; - }; -} - -function assoc_opt(x, _param) { - while (true) { - let param = _param; - if (param === 0) { - return; - } - let match = param.hd; - if (match[0] === x) { - return Primitive_option.some(match[1]); - } - _param = param.tl; - continue; - }; -} - -function assq(x, _param) { - while (true) { - let param = _param; - if (param !== 0) { - let match = param.hd; - if (match[0] === x) { - return match[1]; - } - _param = param.tl; - continue; - } - throw { - RE_EXN_ID: "Not_found", - Error: new Error() - }; - }; -} - -function assq_opt(x, _param) { - while (true) { - let param = _param; - if (param === 0) { - return; - } - let match = param.hd; - if (match[0] === x) { - return Primitive_option.some(match[1]); - } - _param = param.tl; - continue; - }; -} - -function mem_assoc(x, _param) { - while (true) { - let param = _param; - if (param === 0) { - return false; - } - if (param.hd[0] === x) { - return true; - } - _param = param.tl; - continue; - }; -} - -function mem_assq(x, _param) { - while (true) { - let param = _param; - if (param === 0) { - return false; - } - if (param.hd[0] === x) { - return true; - } - _param = param.tl; - continue; - }; -} - -function remove_assoc(x, param) { - if (param === 0) { - return /* [] */0; - } - let l = param.tl; - let pair = param.hd; - if (pair[0] === x) { - return l; - } else { - return { - hd: pair, - tl: remove_assoc(x, l) - }; - } -} - -function remove_assq(x, param) { - if (param === 0) { - return /* [] */0; - } - let l = param.tl; - let pair = param.hd; - if (pair[0] === x) { - return l; - } else { - return { - hd: pair, - tl: remove_assq(x, l) - }; - } -} - -function find(p, _param) { - while (true) { - let param = _param; - if (param !== 0) { - let x = param.hd; - if (p(x)) { - return x; - } - _param = param.tl; - continue; - } - throw { - RE_EXN_ID: "Not_found", - Error: new Error() - }; - }; -} - -function find_opt(p, _param) { - while (true) { - let param = _param; - if (param === 0) { - return; - } - let x = param.hd; - if (p(x)) { - return Primitive_option.some(x); - } - _param = param.tl; - continue; - }; -} - -function find_all(p, l) { - let _accu = /* [] */0; - let _param = l; - while (true) { - let param = _param; - let accu = _accu; - if (param === 0) { - return rev_append(accu, /* [] */0); - } - let l$1 = param.tl; - let x = param.hd; - if (p(x)) { - _param = l$1; - _accu = { - hd: x, - tl: accu - }; - continue; - } - _param = l$1; - continue; - }; -} - -function partition(p, l) { - let _yes = /* [] */0; - let _no = /* [] */0; - let _param = l; - while (true) { - let param = _param; - let no = _no; - let yes = _yes; - if (param === 0) { - return [ - rev_append(yes, /* [] */0), - rev_append(no, /* [] */0) - ]; - } - let l$1 = param.tl; - let x = param.hd; - if (p(x)) { - _param = l$1; - _yes = { - hd: x, - tl: yes - }; - continue; - } - _param = l$1; - _no = { - hd: x, - tl: no - }; - continue; - }; -} - -function split(param) { - if (param === 0) { - return [ - /* [] */0, - /* [] */0 - ]; - } - let match = param.hd; - let match$1 = split(param.tl); - return [ - { - hd: match[0], - tl: match$1[0] - }, - { - hd: match[1], - tl: match$1[1] - } - ]; -} - -function combine(l1, l2) { - if (l1 !== 0) { - if (l2 !== 0) { - return { - hd: [ - l1.hd, - l2.hd - ], - tl: combine(l1.tl, l2.tl) - }; - } else { - return Pervasives.invalid_arg("List.combine"); - } - } else if (l2 !== 0) { - return Pervasives.invalid_arg("List.combine"); - } else { - return /* [] */0; - } -} - -function merge(cmp, l1, l2) { - if (l1 === 0) { - return l2; - } - if (l2 === 0) { - return l1; - } - let h2 = l2.hd; - let h1 = l1.hd; - if (cmp(h1, h2) <= 0) { - return { - hd: h1, - tl: merge(cmp, l1.tl, l2) - }; - } else { - return { - hd: h2, - tl: merge(cmp, l1, l2.tl) - }; - } -} - -function chop(_k, _l) { - while (true) { - let l = _l; - let k = _k; - if (k === 0) { - return l; - } - if (l !== 0) { - _l = l.tl; - _k = k - 1 | 0; - continue; - } - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "Ocaml_List.res", - 411, - 11 - ], - Error: new Error() - }; - }; -} - -function stable_sort(cmp, l) { - let sort = (n, l) => { - if (n !== 2) { - if (n === 3 && l !== 0) { - let match = l.tl; - if (match !== 0) { - let match$1 = match.tl; - if (match$1 !== 0) { - let x3 = match$1.hd; - let x2 = match.hd; - let x1 = l.hd; - if (cmp(x1, x2) <= 0) { - if (cmp(x2, x3) <= 0) { - return { - hd: x1, - tl: { - hd: x2, - tl: { - hd: x3, - tl: /* [] */0 - } - } - }; - } else if (cmp(x1, x3) <= 0) { - return { - hd: x1, - tl: { - hd: x3, - tl: { - hd: x2, - tl: /* [] */0 - } - } - }; - } else { - return { - hd: x3, - tl: { - hd: x1, - tl: { - hd: x2, - tl: /* [] */0 - } - } - }; - } - } else if (cmp(x1, x3) <= 0) { - return { - hd: x2, - tl: { - hd: x1, - tl: { - hd: x3, - tl: /* [] */0 - } - } - }; - } else if (cmp(x2, x3) <= 0) { - return { - hd: x2, - tl: { - hd: x3, - tl: { - hd: x1, - tl: /* [] */0 - } - } - }; - } else { - return { - hd: x3, - tl: { - hd: x2, - tl: { - hd: x1, - tl: /* [] */0 - } - } - }; - } - } - - } - - } - - } else if (l !== 0) { - let match$2 = l.tl; - if (match$2 !== 0) { - let x2$1 = match$2.hd; - let x1$1 = l.hd; - if (cmp(x1$1, x2$1) <= 0) { - return { - hd: x1$1, - tl: { - hd: x2$1, - tl: /* [] */0 - } - }; - } else { - return { - hd: x2$1, - tl: { - hd: x1$1, - tl: /* [] */0 - } - }; - } - } - - } - let n1 = (n >> 1); - let n2 = n - n1 | 0; - let l2 = chop(n1, l); - let s1 = rev_sort(n1, l); - let s2 = rev_sort(n2, l2); - let _l1 = s1; - let _l2 = s2; - let _accu = /* [] */0; - while (true) { - let accu = _accu; - let l2$1 = _l2; - let l1 = _l1; - if (l1 === 0) { - return rev_append(l2$1, accu); - } - if (l2$1 === 0) { - return rev_append(l1, accu); - } - let h2 = l2$1.hd; - let h1 = l1.hd; - if (cmp(h1, h2) > 0) { - _accu = { - hd: h1, - tl: accu - }; - _l1 = l1.tl; - continue; - } - _accu = { - hd: h2, - tl: accu - }; - _l2 = l2$1.tl; - continue; - }; - }; - let rev_sort = (n, l) => { - if (n !== 2) { - if (n === 3 && l !== 0) { - let match = l.tl; - if (match !== 0) { - let match$1 = match.tl; - if (match$1 !== 0) { - let x3 = match$1.hd; - let x2 = match.hd; - let x1 = l.hd; - if (cmp(x1, x2) > 0) { - if (cmp(x2, x3) > 0) { - return { - hd: x1, - tl: { - hd: x2, - tl: { - hd: x3, - tl: /* [] */0 - } - } - }; - } else if (cmp(x1, x3) > 0) { - return { - hd: x1, - tl: { - hd: x3, - tl: { - hd: x2, - tl: /* [] */0 - } - } - }; - } else { - return { - hd: x3, - tl: { - hd: x1, - tl: { - hd: x2, - tl: /* [] */0 - } - } - }; - } - } else if (cmp(x1, x3) > 0) { - return { - hd: x2, - tl: { - hd: x1, - tl: { - hd: x3, - tl: /* [] */0 - } - } - }; - } else if (cmp(x2, x3) > 0) { - return { - hd: x2, - tl: { - hd: x3, - tl: { - hd: x1, - tl: /* [] */0 - } - } - }; - } else { - return { - hd: x3, - tl: { - hd: x2, - tl: { - hd: x1, - tl: /* [] */0 - } - } - }; - } - } - - } - - } - - } else if (l !== 0) { - let match$2 = l.tl; - if (match$2 !== 0) { - let x2$1 = match$2.hd; - let x1$1 = l.hd; - if (cmp(x1$1, x2$1) > 0) { - return { - hd: x1$1, - tl: { - hd: x2$1, - tl: /* [] */0 - } - }; - } else { - return { - hd: x2$1, - tl: { - hd: x1$1, - tl: /* [] */0 - } - }; - } - } - - } - let n1 = (n >> 1); - let n2 = n - n1 | 0; - let l2 = chop(n1, l); - let s1 = sort(n1, l); - let s2 = sort(n2, l2); - let _l1 = s1; - let _l2 = s2; - let _accu = /* [] */0; - while (true) { - let accu = _accu; - let l2$1 = _l2; - let l1 = _l1; - if (l1 === 0) { - return rev_append(l2$1, accu); - } - if (l2$1 === 0) { - return rev_append(l1, accu); - } - let h2 = l2$1.hd; - let h1 = l1.hd; - if (cmp(h1, h2) <= 0) { - _accu = { - hd: h1, - tl: accu - }; - _l1 = l1.tl; - continue; - } - _accu = { - hd: h2, - tl: accu - }; - _l2 = l2$1.tl; - continue; - }; - }; - let len = length(l); - if (len < 2) { - return l; - } else { - return sort(len, l); - } -} - -function sort_uniq(cmp, l) { - let sort = (n, l) => { - if (n !== 2) { - if (n === 3 && l !== 0) { - let match = l.tl; - if (match !== 0) { - let match$1 = match.tl; - if (match$1 !== 0) { - let x3 = match$1.hd; - let x2 = match.hd; - let x1 = l.hd; - let c = cmp(x1, x2); - if (c === 0) { - let c$1 = cmp(x2, x3); - if (c$1 === 0) { - return { - hd: x2, - tl: /* [] */0 - }; - } else if (c$1 < 0) { - return { - hd: x2, - tl: { - hd: x3, - tl: /* [] */0 - } - }; - } else { - return { - hd: x3, - tl: { - hd: x2, - tl: /* [] */0 - } - }; - } - } - if (c < 0) { - let c$2 = cmp(x2, x3); - if (c$2 === 0) { - return { - hd: x1, - tl: { - hd: x2, - tl: /* [] */0 - } - }; - } - if (c$2 < 0) { - return { - hd: x1, - tl: { - hd: x2, - tl: { - hd: x3, - tl: /* [] */0 - } - } - }; - } - let c$3 = cmp(x1, x3); - if (c$3 === 0) { - return { - hd: x1, - tl: { - hd: x2, - tl: /* [] */0 - } - }; - } else if (c$3 < 0) { - return { - hd: x1, - tl: { - hd: x3, - tl: { - hd: x2, - tl: /* [] */0 - } - } - }; - } else { - return { - hd: x3, - tl: { - hd: x1, - tl: { - hd: x2, - tl: /* [] */0 - } - } - }; - } - } - let c$4 = cmp(x1, x3); - if (c$4 === 0) { - return { - hd: x2, - tl: { - hd: x1, - tl: /* [] */0 - } - }; - } - if (c$4 < 0) { - return { - hd: x2, - tl: { - hd: x1, - tl: { - hd: x3, - tl: /* [] */0 - } - } - }; - } - let c$5 = cmp(x2, x3); - if (c$5 === 0) { - return { - hd: x2, - tl: { - hd: x1, - tl: /* [] */0 - } - }; - } else if (c$5 < 0) { - return { - hd: x2, - tl: { - hd: x3, - tl: { - hd: x1, - tl: /* [] */0 - } - } - }; - } else { - return { - hd: x3, - tl: { - hd: x2, - tl: { - hd: x1, - tl: /* [] */0 - } - } - }; - } - } - - } - - } - - } else if (l !== 0) { - let match$2 = l.tl; - if (match$2 !== 0) { - let x2$1 = match$2.hd; - let x1$1 = l.hd; - let c$6 = cmp(x1$1, x2$1); - if (c$6 === 0) { - return { - hd: x1$1, - tl: /* [] */0 - }; - } else if (c$6 < 0) { - return { - hd: x1$1, - tl: { - hd: x2$1, - tl: /* [] */0 - } - }; - } else { - return { - hd: x2$1, - tl: { - hd: x1$1, - tl: /* [] */0 - } - }; - } - } - - } - let n1 = (n >> 1); - let n2 = n - n1 | 0; - let l2 = chop(n1, l); - let s1 = rev_sort(n1, l); - let s2 = rev_sort(n2, l2); - let _l1 = s1; - let _l2 = s2; - let _accu = /* [] */0; - while (true) { - let accu = _accu; - let l2$1 = _l2; - let l1 = _l1; - if (l1 === 0) { - return rev_append(l2$1, accu); - } - if (l2$1 === 0) { - return rev_append(l1, accu); - } - let t2 = l2$1.tl; - let h2 = l2$1.hd; - let t1 = l1.tl; - let h1 = l1.hd; - let c$7 = cmp(h1, h2); - if (c$7 === 0) { - _accu = { - hd: h1, - tl: accu - }; - _l2 = t2; - _l1 = t1; - continue; - } - if (c$7 > 0) { - _accu = { - hd: h1, - tl: accu - }; - _l1 = t1; - continue; - } - _accu = { - hd: h2, - tl: accu - }; - _l2 = t2; - continue; - }; - }; - let rev_sort = (n, l) => { - if (n !== 2) { - if (n === 3 && l !== 0) { - let match = l.tl; - if (match !== 0) { - let match$1 = match.tl; - if (match$1 !== 0) { - let x3 = match$1.hd; - let x2 = match.hd; - let x1 = l.hd; - let c = cmp(x1, x2); - if (c === 0) { - let c$1 = cmp(x2, x3); - if (c$1 === 0) { - return { - hd: x2, - tl: /* [] */0 - }; - } else if (c$1 > 0) { - return { - hd: x2, - tl: { - hd: x3, - tl: /* [] */0 - } - }; - } else { - return { - hd: x3, - tl: { - hd: x2, - tl: /* [] */0 - } - }; - } - } - if (c > 0) { - let c$2 = cmp(x2, x3); - if (c$2 === 0) { - return { - hd: x1, - tl: { - hd: x2, - tl: /* [] */0 - } - }; - } - if (c$2 > 0) { - return { - hd: x1, - tl: { - hd: x2, - tl: { - hd: x3, - tl: /* [] */0 - } - } - }; - } - let c$3 = cmp(x1, x3); - if (c$3 === 0) { - return { - hd: x1, - tl: { - hd: x2, - tl: /* [] */0 - } - }; - } else if (c$3 > 0) { - return { - hd: x1, - tl: { - hd: x3, - tl: { - hd: x2, - tl: /* [] */0 - } - } - }; - } else { - return { - hd: x3, - tl: { - hd: x1, - tl: { - hd: x2, - tl: /* [] */0 - } - } - }; - } - } - let c$4 = cmp(x1, x3); - if (c$4 === 0) { - return { - hd: x2, - tl: { - hd: x1, - tl: /* [] */0 - } - }; - } - if (c$4 > 0) { - return { - hd: x2, - tl: { - hd: x1, - tl: { - hd: x3, - tl: /* [] */0 - } - } - }; - } - let c$5 = cmp(x2, x3); - if (c$5 === 0) { - return { - hd: x2, - tl: { - hd: x1, - tl: /* [] */0 - } - }; - } else if (c$5 > 0) { - return { - hd: x2, - tl: { - hd: x3, - tl: { - hd: x1, - tl: /* [] */0 - } - } - }; - } else { - return { - hd: x3, - tl: { - hd: x2, - tl: { - hd: x1, - tl: /* [] */0 - } - } - }; - } - } - - } - - } - - } else if (l !== 0) { - let match$2 = l.tl; - if (match$2 !== 0) { - let x2$1 = match$2.hd; - let x1$1 = l.hd; - let c$6 = cmp(x1$1, x2$1); - if (c$6 === 0) { - return { - hd: x1$1, - tl: /* [] */0 - }; - } else if (c$6 > 0) { - return { - hd: x1$1, - tl: { - hd: x2$1, - tl: /* [] */0 - } - }; - } else { - return { - hd: x2$1, - tl: { - hd: x1$1, - tl: /* [] */0 - } - }; - } - } - - } - let n1 = (n >> 1); - let n2 = n - n1 | 0; - let l2 = chop(n1, l); - let s1 = sort(n1, l); - let s2 = sort(n2, l2); - let _l1 = s1; - let _l2 = s2; - let _accu = /* [] */0; - while (true) { - let accu = _accu; - let l2$1 = _l2; - let l1 = _l1; - if (l1 === 0) { - return rev_append(l2$1, accu); - } - if (l2$1 === 0) { - return rev_append(l1, accu); - } - let t2 = l2$1.tl; - let h2 = l2$1.hd; - let t1 = l1.tl; - let h1 = l1.hd; - let c$7 = cmp(h1, h2); - if (c$7 === 0) { - _accu = { - hd: h1, - tl: accu - }; - _l2 = t2; - _l1 = t1; - continue; - } - if (c$7 < 0) { - _accu = { - hd: h1, - tl: accu - }; - _l1 = t1; - continue; - } - _accu = { - hd: h2, - tl: accu - }; - _l2 = t2; - continue; - }; - }; - let len = length(l); - if (len < 2) { - return l; - } else { - return sort(len, l); - } -} - -function compare_lengths(_l1, _l2) { - while (true) { - let l2 = _l2; - let l1 = _l1; - if (l1 === 0) { - if (l2 !== 0) { - return -1; - } else { - return 0; - } - } - if (l2 === 0) { - return 1; - } - _l2 = l2.tl; - _l1 = l1.tl; - continue; - }; -} - -function compare_length_with(_l, _n) { - while (true) { - let n = _n; - let l = _l; - if (l === 0) { - if (n === 0) { - return 0; - } else if (n > 0) { - return -1; - } else { - return 1; - } - } - if (n <= 0) { - return 1; - } - _n = n - 1 | 0; - _l = l.tl; - continue; - }; -} - -let append = Pervasives.$at; - -let concat = flatten; - -let filter = find_all; - -let sort = stable_sort; - -let fast_sort = stable_sort; - -export { - length, - compare_lengths, - compare_length_with, - cons, - hd, - tl, - nth, - nth_opt, - rev, - init, - append, - rev_append, - concat, - flatten, - iter, - iteri, - map, - mapi$1 as mapi, - rev_map, - fold_left, - fold_right, - iter2, - map2, - rev_map2, - fold_left2, - fold_right2, - for_all, - exists, - for_all2, - exists2, - mem, - memq, - find, - find_opt, - filter, - find_all, - partition, - assoc, - assoc_opt, - assq, - assq_opt, - mem_assoc, - mem_assq, - remove_assoc, - remove_assq, - split, - combine, - sort, - stable_sort, - fast_sort, - sort_uniq, - merge, -} -/* No side effect */ diff --git a/tests/tests/src/ocaml_compat/Ocaml_List.res b/tests/tests/src/ocaml_compat/Ocaml_List.res deleted file mode 100644 index 30369323b3..0000000000 --- a/tests/tests/src/ocaml_compat/Ocaml_List.res +++ /dev/null @@ -1,740 +0,0 @@ -// FIXME: -// This exists for compatibility reason. -// Move this into Pervasives or Core - -// Below is all deprecated and should be removed in v13 - -type t<'a> = list<'a> - -let rec length_aux = (len, param) => - switch param { - | list{} => len - | list{_, ...l} => length_aux(len + 1, l) - } - -let length = l => length_aux(0, l) - -let cons = (a, l) => list{a, ...l} - -let hd = param => - switch param { - | list{} => failwith("hd") - | list{a, ..._} => a - } - -let tl = param => - switch param { - | list{} => failwith("tl") - | list{_, ...l} => l - } - -let nth = (l, n) => - if n < 0 { - invalid_arg("List.nth") - } else { - let rec nth_aux = (l, n) => - switch l { - | list{} => failwith("nth") - | list{a, ...l} => - if n == 0 { - a - } else { - nth_aux(l, n - 1) - } - } - nth_aux(l, n) - } - -let nth_opt = (l, n) => - if n < 0 { - invalid_arg("List.nth") - } else { - let rec nth_aux = (l, n) => - switch l { - | list{} => None - | list{a, ...l} => - if n == 0 { - Some(a) - } else { - nth_aux(l, n - 1) - } - } - nth_aux(l, n) - } - -let append = \"@" - -let rec rev_append = (l1, l2) => - switch l1 { - | list{} => l2 - | list{a, ...l} => rev_append(l, list{a, ...l2}) - } - -let rev = l => rev_append(l, list{}) - -let rec init_tailrec_aux = (acc, i, n, f) => - if i >= n { - acc - } else { - init_tailrec_aux(list{f(i), ...acc}, i + 1, n, f) - } - -let rec init_aux = (i, n, f) => - if i >= n { - list{} - } else { - let r = f(i) - list{r, ...init_aux(i + 1, n, f)} - } - -let init = (len, f) => - if len < 0 { - invalid_arg("List.init") - } else if len > 10_000 { - rev(init_tailrec_aux(list{}, 0, len, f)) - } else { - init_aux(0, len, f) - } - -let rec flatten = param => - switch param { - | list{} => list{} - | list{l, ...r} => \"@"(l, flatten(r)) - } - -let concat = flatten - -let rec map = (f, param) => - switch param { - | list{} => list{} - | list{a, ...l} => - let r = f(a) - list{r, ...map(f, l)} - } - -let rec mapi = (i, f, param) => - switch param { - | list{} => list{} - | list{a, ...l} => - let r = f(i, a) - list{r, ...mapi(i + 1, f, l)} - } - -let mapi = (f, l) => mapi(0, f, l) - -let rev_map = (f, l) => { - let rec rmap_f = (accu, param) => - switch param { - | list{} => accu - | list{a, ...l} => rmap_f(list{f(a), ...accu}, l) - } - - rmap_f(list{}, l) -} - -let rec iter = (f, param) => - switch param { - | list{} => () - | list{a, ...l} => - f(a) - iter(f, l) - } - -let rec iteri = (i, f, param) => - switch param { - | list{} => () - | list{a, ...l} => - f(i, a) - iteri(i + 1, f, l) - } - -let iteri = (f, l) => iteri(0, f, l) - -let rec fold_left = (f, accu, l) => - switch l { - | list{} => accu - | list{a, ...l} => fold_left(f, f(accu, a), l) - } - -let rec fold_right = (f, l, accu) => - switch l { - | list{} => accu - | list{a, ...l} => f(a, fold_right(f, l, accu)) - } - -let rec map2 = (f, l1, l2) => - switch (l1, l2) { - | (list{}, list{}) => list{} - | (list{a1, ...l1}, list{a2, ...l2}) => - let r = f(a1, a2) - list{r, ...map2(f, l1, l2)} - | (_, _) => invalid_arg("List.map2") - } - -let rev_map2 = (f, l1, l2) => { - let rec rmap2_f = (accu, l1, l2) => - switch (l1, l2) { - | (list{}, list{}) => accu - | (list{a1, ...l1}, list{a2, ...l2}) => rmap2_f(list{f(a1, a2), ...accu}, l1, l2) - | (_, _) => invalid_arg("List.rev_map2") - } - - rmap2_f(list{}, l1, l2) -} - -let rec iter2 = (f, l1, l2) => - switch (l1, l2) { - | (list{}, list{}) => () - | (list{a1, ...l1}, list{a2, ...l2}) => - f(a1, a2) - iter2(f, l1, l2) - | (_, _) => invalid_arg("List.iter2") - } - -let rec fold_left2 = (f, accu, l1, l2) => - switch (l1, l2) { - | (list{}, list{}) => accu - | (list{a1, ...l1}, list{a2, ...l2}) => fold_left2(f, f(accu, a1, a2), l1, l2) - | (_, _) => invalid_arg("List.fold_left2") - } - -let rec fold_right2 = (f, l1, l2, accu) => - switch (l1, l2) { - | (list{}, list{}) => accu - | (list{a1, ...l1}, list{a2, ...l2}) => f(a1, a2, fold_right2(f, l1, l2, accu)) - | (_, _) => invalid_arg("List.fold_right2") - } - -let rec for_all = (p, param) => - switch param { - | list{} => true - | list{a, ...l} => p(a) && for_all(p, l) - } - -let rec exists = (p, param) => - switch param { - | list{} => false - | list{a, ...l} => p(a) || exists(p, l) - } - -let rec for_all2 = (p, l1, l2) => - switch (l1, l2) { - | (list{}, list{}) => true - | (list{a1, ...l1}, list{a2, ...l2}) => p(a1, a2) && for_all2(p, l1, l2) - | (_, _) => invalid_arg("List.for_all2") - } - -let rec exists2 = (p, l1, l2) => - switch (l1, l2) { - | (list{}, list{}) => false - | (list{a1, ...l1}, list{a2, ...l2}) => p(a1, a2) || exists2(p, l1, l2) - | (_, _) => invalid_arg("List.exists2") - } - -let rec mem = (x, param) => - switch param { - | list{} => false - | list{a, ...l} => compare(a, x) == 0 || mem(x, l) - } - -let rec memq = (x, param) => - switch param { - | list{} => false - | list{a, ...l} => a === x || memq(x, l) - } - -let rec assoc = (x, param) => - switch param { - | list{} => throw(Not_found) - | list{(a, b), ...l} => - if compare(a, x) == 0 { - b - } else { - assoc(x, l) - } - } - -let rec assoc_opt = (x, param) => - switch param { - | list{} => None - | list{(a, b), ...l} => - if compare(a, x) == 0 { - Some(b) - } else { - assoc_opt(x, l) - } - } - -let rec assq = (x, param) => - switch param { - | list{} => throw(Not_found) - | list{(a, b), ...l} => - if a === x { - b - } else { - assq(x, l) - } - } - -let rec assq_opt = (x, param) => - switch param { - | list{} => None - | list{(a, b), ...l} => - if a === x { - Some(b) - } else { - assq_opt(x, l) - } - } - -let rec mem_assoc = (x, param) => - switch param { - | list{} => false - | list{(a, _), ...l} => compare(a, x) == 0 || mem_assoc(x, l) - } - -let rec mem_assq = (x, param) => - switch param { - | list{} => false - | list{(a, _), ...l} => a === x || mem_assq(x, l) - } - -let rec remove_assoc = (x, param) => - switch param { - | list{} => list{} - | list{(a, _) as pair, ...l} => - if compare(a, x) == 0 { - l - } else { - list{pair, ...remove_assoc(x, l)} - } - } - -let rec remove_assq = (x, param) => - switch param { - | list{} => list{} - | list{(a, _) as pair, ...l} => - if a === x { - l - } else { - list{pair, ...remove_assq(x, l)} - } - } - -let rec find = (p, param) => - switch param { - | list{} => throw(Not_found) - | list{x, ...l} => - if p(x) { - x - } else { - find(p, l) - } - } - -let rec find_opt = (p, param) => - switch param { - | list{} => None - | list{x, ...l} => - if p(x) { - Some(x) - } else { - find_opt(p, l) - } - } - -let find_all = (p, l) => { - let rec find = (accu, param) => - switch param { - | list{} => rev(accu) - | list{x, ...l} => - if p(x) { - find(list{x, ...accu}, l) - } else { - find(accu, l) - } - } - find(list{}, l) -} - -let filter = find_all - -let partition = (p, l) => { - let rec part = (yes, no, param) => - switch param { - | list{} => (rev(yes), rev(no)) - | list{x, ...l} => - if p(x) { - part(list{x, ...yes}, no, l) - } else { - part(yes, list{x, ...no}, l) - } - } - part(list{}, list{}, l) -} - -let rec split = param => - switch param { - | list{} => (list{}, list{}) - | list{(x, y), ...l} => - let (rx, ry) = split(l) - (list{x, ...rx}, list{y, ...ry}) - } - -let rec combine = (l1, l2) => - switch (l1, l2) { - | (list{}, list{}) => list{} - | (list{a1, ...l1}, list{a2, ...l2}) => list{(a1, a2), ...combine(l1, l2)} - | (_, _) => invalid_arg("List.combine") - } - -/* sorting */ - -let rec merge = (cmp, l1, l2) => - switch (l1, l2) { - | (list{}, l2) => l2 - | (l1, list{}) => l1 - | (list{h1, ...t1}, list{h2, ...t2}) => - if cmp(h1, h2) <= 0 { - list{h1, ...merge(cmp, t1, l2)} - } else { - list{h2, ...merge(cmp, l1, t2)} - } - } - -let rec chop = (k, l) => - if k == 0 { - l - } else { - switch l { - | list{_, ...t} => chop(k - 1, t) - | _ => assert(false) - } - } - -let stable_sort = (cmp, l) => { - let rec rev_merge = (l1, l2, accu) => - switch (l1, l2) { - | (list{}, l2) => rev_append(l2, accu) - | (l1, list{}) => rev_append(l1, accu) - | (list{h1, ...t1}, list{h2, ...t2}) => - if cmp(h1, h2) <= 0 { - rev_merge(t1, l2, list{h1, ...accu}) - } else { - rev_merge(l1, t2, list{h2, ...accu}) - } - } - - let rec rev_merge_rev = (l1, l2, accu) => - switch (l1, l2) { - | (list{}, l2) => rev_append(l2, accu) - | (l1, list{}) => rev_append(l1, accu) - | (list{h1, ...t1}, list{h2, ...t2}) => - if cmp(h1, h2) > 0 { - rev_merge_rev(t1, l2, list{h1, ...accu}) - } else { - rev_merge_rev(l1, t2, list{h2, ...accu}) - } - } - - let rec sort = (n, l) => - switch (n, l) { - | (2, list{x1, x2, ..._}) => - if cmp(x1, x2) <= 0 { - list{x1, x2} - } else { - list{x2, x1} - } - | (3, list{x1, x2, x3, ..._}) => - if cmp(x1, x2) <= 0 { - if cmp(x2, x3) <= 0 { - list{x1, x2, x3} - } else if cmp(x1, x3) <= 0 { - list{x1, x3, x2} - } else { - list{x3, x1, x2} - } - } else if cmp(x1, x3) <= 0 { - list{x2, x1, x3} - } else if cmp(x2, x3) <= 0 { - list{x2, x3, x1} - } else { - list{x3, x2, x1} - } - | (n, l) => - let n1 = asr(n, 1) - let n2 = n - n1 - let l2 = chop(n1, l) - let s1 = rev_sort(n1, l) - let s2 = rev_sort(n2, l2) - rev_merge_rev(s1, s2, list{}) - } - and rev_sort = (n, l) => - switch (n, l) { - | (2, list{x1, x2, ..._}) => - if cmp(x1, x2) > 0 { - list{x1, x2} - } else { - list{x2, x1} - } - | (3, list{x1, x2, x3, ..._}) => - if cmp(x1, x2) > 0 { - if cmp(x2, x3) > 0 { - list{x1, x2, x3} - } else if cmp(x1, x3) > 0 { - list{x1, x3, x2} - } else { - list{x3, x1, x2} - } - } else if cmp(x1, x3) > 0 { - list{x2, x1, x3} - } else if cmp(x2, x3) > 0 { - list{x2, x3, x1} - } else { - list{x3, x2, x1} - } - | (n, l) => - let n1 = asr(n, 1) - let n2 = n - n1 - let l2 = chop(n1, l) - let s1 = sort(n1, l) - let s2 = sort(n2, l2) - rev_merge(s1, s2, list{}) - } - - let len = length(l) - if len < 2 { - l - } else { - sort(len, l) - } -} - -let sort = stable_sort -let fast_sort = stable_sort - -/* Note: on a list of length between about 100000 (depending on the minor - heap size and the type of the list) and Sys.max_array_size, it is - actually faster to use the following, but it might also use more memory - because the argument list cannot be deallocated incrementally. - - Also, there seems to be a bug in this code or in the - implementation of obj_truncate. - -external obj_truncate : 'a array -> int -> unit = "caml_obj_truncate" - -let array_to_list_in_place a = - let l = Array.length a in - let rec loop accu n p = - if p <= 0 then accu else begin - if p = n then begin - obj_truncate a p; - loop (a.(p-1) :: accu) (n-1000) (p-1) - end else begin - loop (a.(p-1) :: accu) n (p-1) - end - end - in - loop [] (l-1000) l - - -let stable_sort cmp l = - let a = Array.of_list l in - Array.stable_sort cmp a; - array_to_list_in_place a - -*/ - -/* sorting + removing duplicates */ - -let sort_uniq = (cmp, l) => { - let rec rev_merge = (l1, l2, accu) => - switch (l1, l2) { - | (list{}, l2) => rev_append(l2, accu) - | (l1, list{}) => rev_append(l1, accu) - | (list{h1, ...t1}, list{h2, ...t2}) => - let c = cmp(h1, h2) - if c == 0 { - rev_merge(t1, t2, list{h1, ...accu}) - } else if c < 0 { - rev_merge(t1, l2, list{h1, ...accu}) - } else { - rev_merge(l1, t2, list{h2, ...accu}) - } - } - - let rec rev_merge_rev = (l1, l2, accu) => - switch (l1, l2) { - | (list{}, l2) => rev_append(l2, accu) - | (l1, list{}) => rev_append(l1, accu) - | (list{h1, ...t1}, list{h2, ...t2}) => - let c = cmp(h1, h2) - if c == 0 { - rev_merge_rev(t1, t2, list{h1, ...accu}) - } else if c > 0 { - rev_merge_rev(t1, l2, list{h1, ...accu}) - } else { - rev_merge_rev(l1, t2, list{h2, ...accu}) - } - } - - let rec sort = (n, l) => - switch (n, l) { - | (2, list{x1, x2, ..._}) => - let c = cmp(x1, x2) - if c == 0 { - list{x1} - } else if c < 0 { - list{x1, x2} - } else { - list{x2, x1} - } - | (3, list{x1, x2, x3, ..._}) => - let c = cmp(x1, x2) - if c == 0 { - let c = cmp(x2, x3) - if c == 0 { - list{x2} - } else if c < 0 { - list{x2, x3} - } else { - list{x3, x2} - } - } else if c < 0 { - let c = cmp(x2, x3) - if c == 0 { - list{x1, x2} - } else if c < 0 { - list{x1, x2, x3} - } else { - let c = cmp(x1, x3) - if c == 0 { - list{x1, x2} - } else if c < 0 { - list{x1, x3, x2} - } else { - list{x3, x1, x2} - } - } - } else { - let c = cmp(x1, x3) - if c == 0 { - list{x2, x1} - } else if c < 0 { - list{x2, x1, x3} - } else { - let c = cmp(x2, x3) - if c == 0 { - list{x2, x1} - } else if c < 0 { - list{x2, x3, x1} - } else { - list{x3, x2, x1} - } - } - } - | (n, l) => - let n1 = asr(n, 1) - let n2 = n - n1 - let l2 = chop(n1, l) - let s1 = rev_sort(n1, l) - let s2 = rev_sort(n2, l2) - rev_merge_rev(s1, s2, list{}) - } - and rev_sort = (n, l) => - switch (n, l) { - | (2, list{x1, x2, ..._}) => - let c = cmp(x1, x2) - if c == 0 { - list{x1} - } else if c > 0 { - list{x1, x2} - } else { - list{x2, x1} - } - | (3, list{x1, x2, x3, ..._}) => - let c = cmp(x1, x2) - if c == 0 { - let c = cmp(x2, x3) - if c == 0 { - list{x2} - } else if c > 0 { - list{x2, x3} - } else { - list{x3, x2} - } - } else if c > 0 { - let c = cmp(x2, x3) - if c == 0 { - list{x1, x2} - } else if c > 0 { - list{x1, x2, x3} - } else { - let c = cmp(x1, x3) - if c == 0 { - list{x1, x2} - } else if c > 0 { - list{x1, x3, x2} - } else { - list{x3, x1, x2} - } - } - } else { - let c = cmp(x1, x3) - if c == 0 { - list{x2, x1} - } else if c > 0 { - list{x2, x1, x3} - } else { - let c = cmp(x2, x3) - if c == 0 { - list{x2, x1} - } else if c > 0 { - list{x2, x3, x1} - } else { - list{x3, x2, x1} - } - } - } - | (n, l) => - let n1 = asr(n, 1) - let n2 = n - n1 - let l2 = chop(n1, l) - let s1 = sort(n1, l) - let s2 = sort(n2, l2) - rev_merge(s1, s2, list{}) - } - - let len = length(l) - if len < 2 { - l - } else { - sort(len, l) - } -} - -let rec compare_lengths = (l1, l2) => - switch (l1, l2) { - | (list{}, list{}) => 0 - | (list{}, _) => -1 - | (_, list{}) => 1 - | (list{_, ...l1}, list{_, ...l2}) => compare_lengths(l1, l2) - } - -let rec compare_length_with = (l, n) => - switch l { - | list{} => - if n == 0 { - 0 - } else if n > 0 { - -1 - } else { - 1 - } - | list{_, ...l} => - if n <= 0 { - 1 - } else { - compare_length_with(l, n - 1) - } - } diff --git a/tests/tests/src/ocaml_compat/Ocaml_List.resi b/tests/tests/src/ocaml_compat/Ocaml_List.resi deleted file mode 100644 index 1fdfd31f0c..0000000000 --- a/tests/tests/src/ocaml_compat/Ocaml_List.resi +++ /dev/null @@ -1,365 +0,0 @@ -// FIXME: -// This exists for compatibility reason. -// Move this into Pervasives or Core - -// Below is all deprecated and should be removed in v13 - -@deprecated("Use Core instead. This will be removed in v13") -type t<'a> = list<'a> - -/** Return the length (number of elements) of the given list. */ -@deprecated("Use Core instead. This will be removed in v13") -let length: list<'a> => int - -/** Compare the lengths of two lists. [compare_lengths l1 l2] is - equivalent to [compare (length l1) (length l2)], except that - the computation stops after itering on the shortest list. - @since 4.05.0 - */ -@deprecated("Use Core instead. This will be removed in v13") -let compare_lengths: (list<'a>, list<'b>) => int - -/** Compare the length of a list to an integer. [compare_length_with l n] is - equivalent to [compare (length l) n], except that - the computation stops after at most [n] iterations on the list. - @since 4.05.0 -*/ -@deprecated("Use Core instead. This will be removed in v13") -let compare_length_with: (list<'a>, int) => int - -/** [cons x xs] is [x :: xs] - @since 4.03.0 -*/ -@deprecated("Use Core instead. This will be removed in v13") -let cons: ('a, list<'a>) => list<'a> - -/** Return the first element of the given list. Raise - [Failure "hd"] if the list is empty. */ -@deprecated("Use Core instead. This will be removed in v13") -let hd: list<'a> => 'a - -/** Return the given list without its first element. Raise - [Failure "tl"] if the list is empty. */ -@deprecated("Use Core instead. This will be removed in v13") -let tl: list<'a> => list<'a> - -/** Return the [n]-th element of the given list. - The first element (head of the list) is at position 0. - Raise [Failure "nth"] if the list is too short. - Raise [Invalid_argument "List.nth"] if [n] is negative. */ -@deprecated("Use Core instead. This will be removed in v13") -let nth: (list<'a>, int) => 'a - -/** Return the [n]-th element of the given list. - The first element (head of the list) is at position 0. - Return [None] if the list is too short. - Raise [Invalid_argument "List.nth"] if [n] is negative. - @since 4.05 -*/ -@deprecated("Use Core instead. This will be removed in v13") -let nth_opt: (list<'a>, int) => option<'a> - -/** List reversal. */ -@deprecated("Use Core instead. This will be removed in v13") -let rev: list<'a> => list<'a> - -/** [List.init len f] is [f 0; f 1; ...; f (len-1)], evaluated left to right. - - @raise Invalid_argument if len < 0. - @since 4.06.0 -*/ -@deprecated("Use Core instead. This will be removed in v13") -let init: (int, int => 'a) => list<'a> - -/** Concatenate two lists. Same as the infix operator [@]. - Not tail-recursive (length of the first argument). */ -@deprecated("Use Core instead. This will be removed in v13") -let append: (list<'a>, list<'a>) => list<'a> - -/** [List.rev_append l1 l2] reverses [l1] and concatenates it to [l2]. - This is equivalent to {!List.rev}[ l1 @ l2], but [rev_append] is - tail-recursive and more efficient. */ -@deprecated("Use Core instead. This will be removed in v13") -let rev_append: (list<'a>, list<'a>) => list<'a> - -/** Concatenate a list of lists. The elements of the argument are all - concatenated together (in the same order) to give the result. - Not tail-recursive - (length of the argument + length of the longest sub-list). */ -@deprecated("Use Core instead. This will be removed in v13") -let concat: list> => list<'a> - -/** An alias for [concat]. */ -@deprecated("Use Core instead. This will be removed in v13") -let flatten: list> => list<'a> - -/* {1 Iterators} */ - -/** [List.iter f [a1; ...; an]] applies function [f] in turn to - [a1; ...; an]. It is equivalent to - [begin f a1; f a2; ...; f an; () end]. */ -@deprecated("Use Core instead. This will be removed in v13") -let iter: ('a => unit, list<'a>) => unit - -/** Same as {!List.iter}, but the function is applied to the index of - the element as first argument (counting from 0), and the element - itself as second argument. - @since 4.00.0 -*/ -@deprecated("Use Core instead. This will be removed in v13") -let iteri: ((int, 'a) => unit, list<'a>) => unit - -/** [List.map f [a1; ...; an]] applies function [f] to [a1, ..., an], - and builds the list [[f a1; ...; f an]] - with the results returned by [f]. Not tail-recursive. */ -@deprecated("Use Core instead. This will be removed in v13") -let map: ('a => 'b, list<'a>) => list<'b> - -/** Same as {!List.map}, but the function is applied to the index of - the element as first argument (counting from 0), and the element - itself as second argument. Not tail-recursive. - @since 4.00.0 -*/ -@deprecated("Use Core instead. This will be removed in v13") -let mapi: ((int, 'a) => 'b, list<'a>) => list<'b> - -/** [List.rev_map f l] gives the same result as - {!List.rev}[ (]{!List.map}[ f l)], but is tail-recursive and - more efficient. */ -@deprecated("Use Core instead. This will be removed in v13") -let rev_map: ('a => 'b, list<'a>) => list<'b> - -/** [List.fold_left f a [b1; ...; bn]] is - [f (... (f (f a b1) b2) ...) bn]. */ -@deprecated("Use Core instead. This will be removed in v13") -let fold_left: (('a, 'b) => 'a, 'a, list<'b>) => 'a - -/** [List.fold_right f [a1; ...; an] b] is - [f a1 (f a2 (... (f an b) ...))]. Not tail-recursive. */ -@deprecated("Use Core instead. This will be removed in v13") -let fold_right: (('a, 'b) => 'b, list<'a>, 'b) => 'b - -/* {1 Iterators on two lists} */ - -/** [List.iter2 f [a1; ...; an] [b1; ...; bn]] calls in turn - [f a1 b1; ...; f an bn]. - Raise [Invalid_argument] if the two lists are determined - to have different lengths. */ -@deprecated("Use Core instead. This will be removed in v13") -let iter2: (('a, 'b) => unit, list<'a>, list<'b>) => unit - -/** [List.map2 f [a1; ...; an] [b1; ...; bn]] is - [[f a1 b1; ...; f an bn]]. - Raise [Invalid_argument] if the two lists are determined - to have different lengths. Not tail-recursive. */ -@deprecated("Use Core instead. This will be removed in v13") -let map2: (('a, 'b) => 'c, list<'a>, list<'b>) => list<'c> - -/** [List.rev_map2 f l1 l2] gives the same result as - {!List.rev}[ (]{!List.map2}[ f l1 l2)], but is tail-recursive and - more efficient. */ -@deprecated("Use Core instead. This will be removed in v13") -let rev_map2: (('a, 'b) => 'c, list<'a>, list<'b>) => list<'c> - -/** [List.fold_left2 f a [b1; ...; bn] [c1; ...; cn]] is - [f (... (f (f a b1 c1) b2 c2) ...) bn cn]. - Raise [Invalid_argument] if the two lists are determined - to have different lengths. */ -@deprecated("Use Core instead. This will be removed in v13") -let fold_left2: (('a, 'b, 'c) => 'a, 'a, list<'b>, list<'c>) => 'a - -/** [List.fold_right2 f [a1; ...; an] [b1; ...; bn] c] is - [f a1 b1 (f a2 b2 (... (f an bn c) ...))]. - Raise [Invalid_argument] if the two lists are determined - to have different lengths. Not tail-recursive. */ -@deprecated("Use Core instead. This will be removed in v13") -let fold_right2: (('a, 'b, 'c) => 'c, list<'a>, list<'b>, 'c) => 'c - -/* {1 List scanning} */ - -/** [for_all p [a1; ...; an]] checks if all elements of the list - satisfy the predicate [p]. That is, it returns - [(p a1) && (p a2) && ... && (p an)]. */ -@deprecated("Use Core instead. This will be removed in v13") -let for_all: ('a => bool, list<'a>) => bool - -/** [exists p [a1; ...; an]] checks if at least one element of - the list satisfies the predicate [p]. That is, it returns - [(p a1) || (p a2) || ... || (p an)]. */ -@deprecated("Use Core instead. This will be removed in v13") -let exists: ('a => bool, list<'a>) => bool - -/** Same as {!List.for_all}, but for a two-argument predicate. - Raise [Invalid_argument] if the two lists are determined - to have different lengths. */ -@deprecated("Use Core instead. This will be removed in v13") -let for_all2: (('a, 'b) => bool, list<'a>, list<'b>) => bool - -/** Same as {!List.exists}, but for a two-argument predicate. - Raise [Invalid_argument] if the two lists are determined - to have different lengths. */ -@deprecated("Use Core instead. This will be removed in v13") -let exists2: (('a, 'b) => bool, list<'a>, list<'b>) => bool - -/** [mem a l] is true if and only if [a] is equal - to an element of [l]. */ -@deprecated("Use Core instead. This will be removed in v13") -let mem: ('a, list<'a>) => bool - -/** Same as {!List.mem}, but uses physical equality instead of structural - equality to compare list elements. */ -@deprecated("Use Core instead. This will be removed in v13") -let memq: ('a, list<'a>) => bool - -/* {1 List searching} */ - -/** [find p l] returns the first element of the list [l] - that satisfies the predicate [p]. - Raise [Not_found] if there is no value that satisfies [p] in the - list [l]. */ -@deprecated("Use Core instead. This will be removed in v13") -let find: ('a => bool, list<'a>) => 'a - -/** [find_opt p l] returns the first element of the list [l] that - satisfies the predicate [p], or [None] if there is no value that - satisfies [p] in the list [l]. - @since 4.05 */ -@deprecated("Use Core instead. This will be removed in v13") -let find_opt: ('a => bool, list<'a>) => option<'a> - -/** [filter p l] returns all the elements of the list [l] - that satisfy the predicate [p]. The order of the elements - in the input list is preserved. */ -@deprecated("Use Core instead. This will be removed in v13") -let filter: ('a => bool, list<'a>) => list<'a> - -/** [find_all] is another name for {!List.filter}. */ -let find_all: ('a => bool, list<'a>) => list<'a> - -/** [partition p l] returns a pair of lists [(l1, l2)], where - [l1] is the list of all the elements of [l] that - satisfy the predicate [p], and [l2] is the list of all the - elements of [l] that do not satisfy [p]. - The order of the elements in the input list is preserved. */ -@deprecated("Use Core instead. This will be removed in v13") -let partition: ('a => bool, list<'a>) => (list<'a>, list<'a>) - -/* {1 Association lists} */ - -/** [assoc a l] returns the value associated with key [a] in the list of - pairs [l]. That is, - [assoc a [ ...; (a,b); ...] = b] - if [(a,b)] is the leftmost binding of [a] in list [l]. - Raise [Not_found] if there is no value associated with [a] in the - list [l]. */ -@deprecated("Use Core instead. This will be removed in v13") -let assoc: ('a, list<('a, 'b)>) => 'b - -/** [assoc_opt a l] returns the value associated with key [a] in the list of - pairs [l]. That is, - [assoc_opt a [ ...; (a,b); ...] = b] - if [(a,b)] is the leftmost binding of [a] in list [l]. - Returns [None] if there is no value associated with [a] in the - list [l]. - @since 4.05 */ -@deprecated("Use Core instead. This will be removed in v13") -let assoc_opt: ('a, list<('a, 'b)>) => option<'b> - -/** Same as {!List.assoc}, but uses physical equality instead of structural - equality to compare keys. */ -@deprecated("Use Core instead. This will be removed in v13") -let assq: ('a, list<('a, 'b)>) => 'b - -/** Same as {!List.assoc_opt}, but uses physical equality instead of structural - equality to compare keys. - @since 4.05 */ -@deprecated("Use Core instead. This will be removed in v13") -let assq_opt: ('a, list<('a, 'b)>) => option<'b> - -/** Same as {!List.assoc}, but simply return true if a binding exists, - and false if no bindings exist for the given key. */ -@deprecated("Use Core instead. This will be removed in v13") -let mem_assoc: ('a, list<('a, 'b)>) => bool - -/** Same as {!List.mem_assoc}, but uses physical equality instead of - structural equality to compare keys. */ -@deprecated("Use Core instead. This will be removed in v13") -let mem_assq: ('a, list<('a, 'b)>) => bool - -/** [remove_assoc a l] returns the list of - pairs [l] without the first pair with key [a], if any. - Not tail-recursive. */ -@deprecated("Use Core instead. This will be removed in v13") -let remove_assoc: ('a, list<('a, 'b)>) => list<('a, 'b)> - -/** Same as {!List.remove_assoc}, but uses physical equality instead - of structural equality to compare keys. Not tail-recursive. */ -@deprecated("Use Core instead. This will be removed in v13") -let remove_assq: ('a, list<('a, 'b)>) => list<('a, 'b)> - -/* {1 Lists of pairs} */ - -/** Transform a list of pairs into a pair of lists: - [split [(a1,b1); ...; (an,bn)]] is [([a1; ...; an], [b1; ...; bn])]. - Not tail-recursive. -*/ -@deprecated("Use Core instead. This will be removed in v13") -let split: list<('a, 'b)> => (list<'a>, list<'b>) - -/** Transform a pair of lists into a list of pairs: - [combine [a1; ...; an] [b1; ...; bn]] is - [[(a1,b1); ...; (an,bn)]]. - Raise [Invalid_argument] if the two lists - have different lengths. Not tail-recursive. */ -@deprecated("Use Core instead. This will be removed in v13") -let combine: (list<'a>, list<'b>) => list<('a, 'b)> - -/* {1 Sorting} */ - -/** Sort a list in increasing order according to a comparison - function. The comparison function must return 0 if its arguments - compare as equal, a positive integer if the first is greater, - and a negative integer if the first is smaller (see Array.sort for - a complete specification). For example, - {!Pervasives.compare} is a suitable comparison function. - The resulting list is sorted in increasing order. - [List.sort] is guaranteed to run in constant heap space - (in addition to the size of the result list) and logarithmic - stack space. - - The current implementation uses Merge Sort. It runs in constant - heap space and logarithmic stack space. -*/ -@deprecated("Use Core instead. This will be removed in v13") -let sort: (('a, 'a) => int, list<'a>) => list<'a> - -/** Same as {!List.sort}, but the sorting algorithm is guaranteed to - be stable (i.e. elements that compare equal are kept in their - original order) . - - The current implementation uses Merge Sort. It runs in constant - heap space and logarithmic stack space. -*/ -@deprecated("Use Core instead. This will be removed in v13") -let stable_sort: (('a, 'a) => int, list<'a>) => list<'a> - -/** Same as {!List.sort} or {!List.stable_sort}, whichever is faster - on typical input. */ -@deprecated("Use Core instead. This will be removed in v13") -let fast_sort: (('a, 'a) => int, list<'a>) => list<'a> - -/** Same as {!List.sort}, but also remove duplicates. - @since 4.02.0 */ -@deprecated("Use Core instead. This will be removed in v13") -let sort_uniq: (('a, 'a) => int, list<'a>) => list<'a> - -/** Merge two lists: - Assuming that [l1] and [l2] are sorted according to the - comparison function [cmp], [merge cmp l1 l2] will return a - sorted list containing all the elements of [l1] and [l2]. - If several elements compare equal, the elements of [l1] will be - before the elements of [l2]. - Not tail-recursive (sum of the lengths of the arguments). -*/ -@deprecated("Use Core instead. This will be removed in v13") -let merge: (('a, 'a) => int, list<'a>, list<'a>) => list<'a> diff --git a/tests/tests/src/ocaml_compat/Ocaml_String.mjs b/tests/tests/src/ocaml_compat/Ocaml_String.mjs deleted file mode 100644 index 02707988c4..0000000000 --- a/tests/tests/src/ocaml_compat/Ocaml_String.mjs +++ /dev/null @@ -1,304 +0,0 @@ -// Generated by ReScript, PLEASE EDIT WITH CARE - -import * as Char from "@rescript/runtime/lib/es6/Char.js"; -import * as Pervasives from "@rescript/runtime/lib/es6/Pervasives.js"; -import * as Ocaml_Array from "./Ocaml_Array.mjs"; -import * as Primitive_exceptions from "@rescript/runtime/lib/es6/Primitive_exceptions.js"; - -function apply1(f, bytes) { - if (bytes.length === 0) { - return bytes; - } - let r = bytes.slice(); - r[0] = f(bytes[0]); - return r; -} - -function concat(sep, xs) { - return Ocaml_Array.of_list(xs).join(sep); -} - -function bos(str) { - return Ocaml_Array.map(str => str.codePointAt(0), Array.from(str)); -} - -function make(len, ch) { - return String.fromCodePoint(ch).repeat(len); -} - -function init(len, f) { - return Ocaml_Array.init(len, i => String.fromCodePoint(f(i))).join(""); -} - -function sub(s, ofs, len) { - return String.fromCodePoint(...Ocaml_Array.sub(bos(s), ofs, len)); -} - -function iter(f, s) { - for (let i = 0, i_finish = s.length; i < i_finish; ++i) { - f(s.codePointAt(i)); - } -} - -function iteri(f, s) { - for (let i = 0, i_finish = s.length; i < i_finish; ++i) { - f(i, s.codePointAt(i)); - } -} - -function map(f, s) { - return String.fromCodePoint(...Ocaml_Array.map(f, bos(s))); -} - -function mapi(f, s) { - return String.fromCodePoint(...Ocaml_Array.mapi(f, bos(s))); -} - -function escaped(s) { - let needs_escape = _i => { - while (true) { - let i = _i; - if (i >= s.length) { - return false; - } - let match = s.codePointAt(i); - if (match < 32) { - return true; - } - if (match > 92 || match < 34) { - if (match >= 127) { - return true; - } - _i = i + 1 | 0; - continue; - } - if (match > 91 || match < 35) { - return true; - } - _i = i + 1 | 0; - continue; - }; - }; - if (!needs_escape(0)) { - return s; - } - let bytes = bos(s); - return Ocaml_Array.map(Char.escaped, bytes).join(""); -} - -function index_rec(s, lim, _i, c) { - while (true) { - let i = _i; - if (i >= lim) { - throw { - RE_EXN_ID: "Not_found", - Error: new Error() - }; - } - if (s.codePointAt(i) === c) { - return i; - } - _i = i + 1 | 0; - continue; - }; -} - -function index(s, c) { - return index_rec(s, s.length, 0, c); -} - -function index_rec_opt(s, lim, _i, c) { - while (true) { - let i = _i; - if (i >= lim) { - return; - } - if (s.codePointAt(i) === c) { - return i; - } - _i = i + 1 | 0; - continue; - }; -} - -function index_opt(s, c) { - return index_rec_opt(s, s.length, 0, c); -} - -function index_from(s, i, c) { - let l = s.length; - if (i < 0 || i > l) { - return Pervasives.invalid_arg("String.index_from / Bytes.index_from"); - } else { - return index_rec(s, l, i, c); - } -} - -function index_from_opt(s, i, c) { - let l = s.length; - if (i < 0 || i > l) { - return Pervasives.invalid_arg("String.index_from_opt / Bytes.index_from_opt"); - } else { - return index_rec_opt(s, l, i, c); - } -} - -function rindex_rec(s, _i, c) { - while (true) { - let i = _i; - if (i < 0) { - throw { - RE_EXN_ID: "Not_found", - Error: new Error() - }; - } - if (s.codePointAt(i) === c) { - return i; - } - _i = i - 1 | 0; - continue; - }; -} - -function rindex(s, c) { - return rindex_rec(s, s.length - 1 | 0, c); -} - -function rindex_from(s, i, c) { - if (i < -1 || i >= s.length) { - return Pervasives.invalid_arg("String.rindex_from / Bytes.rindex_from"); - } else { - return rindex_rec(s, i, c); - } -} - -function rindex_rec_opt(s, _i, c) { - while (true) { - let i = _i; - if (i < 0) { - return; - } - if (s.codePointAt(i) === c) { - return i; - } - _i = i - 1 | 0; - continue; - }; -} - -function rindex_opt(s, c) { - return rindex_rec_opt(s, s.length - 1 | 0, c); -} - -function rindex_from_opt(s, i, c) { - if (i < -1 || i >= s.length) { - return Pervasives.invalid_arg("String.rindex_from_opt / Bytes.rindex_from_opt"); - } else { - return rindex_rec_opt(s, i, c); - } -} - -function contains_from(s, i, c) { - let l = s.length; - if (i < 0 || i > l) { - return Pervasives.invalid_arg("String.contains_from / Bytes.contains_from"); - } - try { - index_rec(s, l, i, c); - return true; - } catch (raw_exn) { - let exn = Primitive_exceptions.internalToException(raw_exn); - if (exn.RE_EXN_ID === "Not_found") { - return false; - } - throw exn; - } -} - -function contains(s, c) { - return contains_from(s, 0, c); -} - -function rcontains_from(s, i, c) { - if (i < 0 || i >= s.length) { - return Pervasives.invalid_arg("String.rcontains_from / Bytes.rcontains_from"); - } - try { - rindex_rec(s, i, c); - return true; - } catch (raw_exn) { - let exn = Primitive_exceptions.internalToException(raw_exn); - if (exn.RE_EXN_ID === "Not_found") { - return false; - } - throw exn; - } -} - -function uppercase_ascii(s) { - let bytes = bos(s); - return String.fromCodePoint(...Ocaml_Array.map(Char.uppercase_ascii, bytes)); -} - -function lowercase_ascii(s) { - let bytes = bos(s); - return String.fromCodePoint(...Ocaml_Array.map(Char.lowercase_ascii, bytes)); -} - -function capitalize_ascii(s) { - let bytes = bos(s); - return String.fromCodePoint(...apply1(Char.uppercase_ascii, bytes)); -} - -function uncapitalize_ascii(s) { - let bytes = bos(s); - return String.fromCodePoint(...apply1(Char.lowercase_ascii, bytes)); -} - -function split_on_char(sep, s) { - let r = /* [] */0; - let j = s.length; - for (let i = s.length - 1 | 0; i >= 0; --i) { - if (s.codePointAt(i) === sep) { - r = { - hd: sub(s, i + 1 | 0, (j - i | 0) - 1 | 0), - tl: r - }; - j = i; - } - - } - return { - hd: sub(s, 0, j), - tl: r - }; -} - -export { - make, - init, - sub, - concat, - iter, - iteri, - map, - mapi, - escaped, - index, - index_opt, - rindex, - rindex_opt, - index_from, - index_from_opt, - rindex_from, - rindex_from_opt, - contains, - contains_from, - rcontains_from, - uppercase_ascii, - lowercase_ascii, - capitalize_ascii, - uncapitalize_ascii, - split_on_char, -} -/* No side effect */ diff --git a/tests/tests/src/ocaml_compat/Ocaml_String.res b/tests/tests/src/ocaml_compat/Ocaml_String.res deleted file mode 100644 index f839830d4c..0000000000 --- a/tests/tests/src/ocaml_compat/Ocaml_String.res +++ /dev/null @@ -1,225 +0,0 @@ -// FIXME: -// This exists for compatibility reason. -// Move this into Pervasives or Core - -// Below is all deprecated and should be removed in v13 - -module Array = Ocaml_Array - -type t = string - -module B = { - include Array - - let uppercase_ascii = bytes => map(Char.uppercase_ascii, bytes) - let lowercase_ascii = bytes => map(Char.lowercase_ascii, bytes) - - let apply1 = (f, bytes) => - if length(bytes) == 0 { - bytes - } else { - let r = copy(bytes) - unsafe_set(r, 0, f(unsafe_get(bytes, 0))) - r - } - let capitalize_ascii = bytes => apply1(Char.uppercase_ascii, bytes) - let uncapitalize_ascii = bytes => apply1(Char.lowercase_ascii, bytes) - - let escaped = bytes => map(Char.escaped, bytes) -} - -@send external join: (array, string) => string = "join" - -let concat = (sep: string, xs: list) => xs->Array.of_list->join(sep) - -external length: string => int = "%string_length" - -@send external get: (string, int) => char = "codePointAt" - -@send external unsafe_get: (string, int) => char = "codePointAt" - -@scope("Array") external bos: string => array = "from" -let bos = str => B.map(str => str->unsafe_get(0), str->bos) - -@scope("String") @variadic -external bts: array => string = "fromCodePoint" - -let make = (len, ch) => Primitive_string_extern.fromChar(ch)->Primitive_string_extern.repeat(len) - -let init = (len, f) => Array.init(len, i => Primitive_string_extern.fromChar(f(i)))->join("") - -let sub = (s, ofs, len) => bts(B.sub(bos(s), ofs, len)) - -external compare: (t, t) => int = "%compare" - -external equal: (t, t) => bool = "%equal" - -let iter = (f, s) => - for i in 0 to length(s) - 1 { - f(unsafe_get(s, i)) - } - -let iteri = (f, s) => - for i in 0 to length(s) - 1 { - f(i, unsafe_get(s, i)) - } - -let map = (f, s) => bts(B.map(f, bos(s))) -let mapi = (f, s) => bts(B.mapi(f, bos(s))) - -@send external trim: string => string = "trim" - -let escaped = s => { - let rec needs_escape = i => - if i >= length(s) { - false - } else { - switch unsafe_get(s, i) { - | '"' | '\\' | '\n' | '\t' | '\r' | '\b' => true - | ' ' .. '~' => needs_escape(i + 1) - | _ => true - } - } - - if needs_escape(0) { - join(B.escaped(bos(s)), "") - } else { - s - } -} - -/* duplicated in bytes.ml */ -let rec index_rec = (s, lim, i, c) => - if i >= lim { - throw(Not_found) - } else if unsafe_get(s, i) == c { - i - } else { - index_rec(s, lim, i + 1, c) - } - -/* duplicated in bytes.ml */ -let index = (s, c) => index_rec(s, length(s), 0, c) - -/* duplicated in bytes.ml */ -let rec index_rec_opt = (s, lim, i, c) => - if i >= lim { - None - } else if unsafe_get(s, i) == c { - Some(i) - } else { - index_rec_opt(s, lim, i + 1, c) - } - -/* duplicated in bytes.ml */ -let index_opt = (s, c) => index_rec_opt(s, length(s), 0, c) - -/* duplicated in bytes.ml */ -let index_from = (s, i, c) => { - let l = length(s) - if i < 0 || i > l { - invalid_arg("String.index_from / Bytes.index_from") - } else { - index_rec(s, l, i, c) - } -} - -/* duplicated in bytes.ml */ -let index_from_opt = (s, i, c) => { - let l = length(s) - if i < 0 || i > l { - invalid_arg("String.index_from_opt / Bytes.index_from_opt") - } else { - index_rec_opt(s, l, i, c) - } -} - -/* duplicated in bytes.ml */ -let rec rindex_rec = (s, i, c) => - if i < 0 { - throw(Not_found) - } else if unsafe_get(s, i) == c { - i - } else { - rindex_rec(s, i - 1, c) - } - -/* duplicated in bytes.ml */ -let rindex = (s, c) => rindex_rec(s, length(s) - 1, c) - -/* duplicated in bytes.ml */ -let rindex_from = (s, i, c) => - if i < -1 || i >= length(s) { - invalid_arg("String.rindex_from / Bytes.rindex_from") - } else { - rindex_rec(s, i, c) - } - -/* duplicated in bytes.ml */ -let rec rindex_rec_opt = (s, i, c) => - if i < 0 { - None - } else if unsafe_get(s, i) == c { - Some(i) - } else { - rindex_rec_opt(s, i - 1, c) - } - -/* duplicated in bytes.ml */ -let rindex_opt = (s, c) => rindex_rec_opt(s, length(s) - 1, c) - -/* duplicated in bytes.ml */ -let rindex_from_opt = (s, i, c) => - if i < -1 || i >= length(s) { - invalid_arg("String.rindex_from_opt / Bytes.rindex_from_opt") - } else { - rindex_rec_opt(s, i, c) - } - -/* duplicated in bytes.ml */ -let contains_from = (s, i, c) => { - let l = length(s) - if i < 0 || i > l { - invalid_arg("String.contains_from / Bytes.contains_from") - } else { - try { - ignore(index_rec(s, l, i, c)) - true - } catch { - | Not_found => false - } - } -} - -/* duplicated in bytes.ml */ -let contains = (s, c) => contains_from(s, 0, c) - -/* duplicated in bytes.ml */ -let rcontains_from = (s, i, c) => - if i < 0 || i >= length(s) { - invalid_arg("String.rcontains_from / Bytes.rcontains_from") - } else { - try { - ignore(rindex_rec(s, i, c)) - true - } catch { - | Not_found => false - } - } - -let uppercase_ascii = s => bts(B.uppercase_ascii(bos(s))) -let lowercase_ascii = s => bts(B.lowercase_ascii(bos(s))) -let capitalize_ascii = s => bts(B.capitalize_ascii(bos(s))) -let uncapitalize_ascii = s => bts(B.uncapitalize_ascii(bos(s))) - -let split_on_char = (sep, s) => { - let r = ref(list{}) - let j = ref(length(s)) - for i in length(s) - 1 downto 0 { - if unsafe_get(s, i) == sep { - r := list{sub(s, i + 1, j.contents - i - 1), ...r.contents} - j := i - } - } - list{sub(s, 0, j.contents), ...r.contents} -} diff --git a/tests/tests/src/ocaml_compat/Ocaml_String.resi b/tests/tests/src/ocaml_compat/Ocaml_String.resi deleted file mode 100644 index e541233a1c..0000000000 --- a/tests/tests/src/ocaml_compat/Ocaml_String.resi +++ /dev/null @@ -1,248 +0,0 @@ -// FIXME: -// This exists for compatibility reason. -// Move this into Pervasives or Core - -// Below is all deprecated and should be removed in v13 - -/** Return the length (number of characters) of the given string. */ -@deprecated("Use Core instead. This will be removed in v13") -external length: string => int = "%string_length" - -/** [String.get s n] returns the character at index [n] in string [s]. - You can also write [s.[n]] instead of [String.get s n]. - - Raise [Invalid_argument] if [n] not a valid index in [s]. */ -@deprecated("Use Core instead. This will be removed in v13") @send -external get: (string, int) => char = "codePointAt" - -/** [String.make n c] returns a fresh string of length [n], - filled with the character [c]. */ -@deprecated("Use Core instead. This will be removed in v13") -let make: (int, char) => string - -/** [String.init n f] returns a string of length [n], with character - [i] initialized to the result of [f i] (called in increasing - index order). -*/ -@deprecated("Use Core instead. This will be removed in v13") -let init: (int, int => char) => string - -/** [String.sub s start len] returns a fresh string of length [len], - containing the substring of [s] that starts at position [start] and - has length [len]. - - Raise [Invalid_argument] if [start] and [len] do not - designate a valid substring of [s]. */ -@deprecated("Use Core instead. This will be removed in v13") -let sub: (string, int, int) => string - -/** [String.concat sep sl] concatenates the list of strings [sl], - inserting the separator string [sep] between each. - - Raise [Invalid_argument] if the result is longer than - {!Sys.max_string_length} bytes. */ -@deprecated("Use Core instead. This will be removed in v13") -let concat: (string, list) => string - -/** [String.iter f s] applies function [f] in turn to all - the characters of [s]. It is equivalent to - [f s.[0]; f s.[1]; ...; f s.[String.length s - 1]; ()]. */ -@deprecated("Use Core instead. This will be removed in v13") -let iter: (char => unit, string) => unit - -/** Same as {!String.iter}, but the - function is applied to the index of the element as first argument - (counting from 0), and the character itself as second argument. - @since 4.00.0 */ -@deprecated("Use Core instead. This will be removed in v13") -let iteri: ((int, char) => unit, string) => unit - -/** [String.map f s] applies function [f] in turn to all the - characters of [s] (in increasing index order) and stores the - results in a new string that is returned. - @since 4.00.0 */ -@deprecated("Use Core instead. This will be removed in v13") -let map: (char => char, string) => string - -/** [String.mapi f s] calls [f] with each character of [s] and its - index (in increasing index order) and stores the results in a new - string that is returned. - @since 4.02.0 */ -@deprecated("Use Core instead. This will be removed in v13") -let mapi: ((int, char) => char, string) => string - -/** Return a copy of the argument, without leading and trailing - whitespace. The characters regarded as whitespace are: [' '], - ['\x0c'], ['\n'], ['\r'], and ['\t']. If there is neither leading nor - trailing whitespace character in the argument, return the original - string itself, not a copy. - @since 4.00.0 */ -@deprecated("Use Core instead. This will be removed in v13") @send -external trim: string => string = "trim" - -/** Return a copy of the argument, with special characters - represented by escape sequences, following the lexical - conventions of OCaml. - All characters outside the ASCII printable range (32..126) are - escaped, as well as backslash and double-quote. - - If there is no special character in the argument that needs - escaping, return the original string itself, not a copy. - */ -@deprecated("Use Core instead. This will be removed in v13") -let escaped: string => string - -/** [String.index s c] returns the index of the first - occurrence of character [c] in string [s]. - - Raise [Not_found] if [c] does not occur in [s]. */ -@deprecated("Use Core instead. This will be removed in v13") -let index: (string, char) => int - -/** [String.index_opt s c] returns the index of the first - occurrence of character [c] in string [s], or - [None] if [c] does not occur in [s]. - @since 4.05 */ -@deprecated("Use Core instead. This will be removed in v13") -let index_opt: (string, char) => option - -/** [String.rindex s c] returns the index of the last - occurrence of character [c] in string [s]. - - Raise [Not_found] if [c] does not occur in [s]. */ -@deprecated("Use Core instead. This will be removed in v13") -let rindex: (string, char) => int - -/** [String.rindex_opt s c] returns the index of the last occurrence - of character [c] in string [s], or [None] if [c] does not occur in - [s]. - @since 4.05 */ -@deprecated("Use Core instead. This will be removed in v13") -let rindex_opt: (string, char) => option - -/** [String.index_from s i c] returns the index of the - first occurrence of character [c] in string [s] after position [i]. - [String.index s c] is equivalent to [String.index_from s 0 c]. - - Raise [Invalid_argument] if [i] is not a valid position in [s]. - Raise [Not_found] if [c] does not occur in [s] after position [i]. */ -@deprecated("Use Core instead. This will be removed in v13") -let index_from: (string, int, char) => int - -/** [String.index_from_opt s i c] returns the index of the - first occurrence of character [c] in string [s] after position [i] - or [None] if [c] does not occur in [s] after position [i]. - - [String.index_opt s c] is equivalent to [String.index_from_opt s 0 c]. - Raise [Invalid_argument] if [i] is not a valid position in [s]. - - @since 4.05 -*/ -@deprecated("Use Core instead. This will be removed in v13") -let index_from_opt: (string, int, char) => option - -/** [String.rindex_from s i c] returns the index of the - last occurrence of character [c] in string [s] before position [i+1]. - [String.rindex s c] is equivalent to - [String.rindex_from s (String.length s - 1) c]. - - Raise [Invalid_argument] if [i+1] is not a valid position in [s]. - Raise [Not_found] if [c] does not occur in [s] before position [i+1]. */ -@deprecated("Use Core instead. This will be removed in v13") -let rindex_from: (string, int, char) => int - -/** [String.rindex_from_opt s i c] returns the index of the - last occurrence of character [c] in string [s] before position [i+1] - or [None] if [c] does not occur in [s] before position [i+1]. - - [String.rindex_opt s c] is equivalent to - [String.rindex_from_opt s (String.length s - 1) c]. - - Raise [Invalid_argument] if [i+1] is not a valid position in [s]. - - @since 4.05 -*/ -@deprecated("Use Core instead. This will be removed in v13") -let rindex_from_opt: (string, int, char) => option - -/** [String.contains s c] tests if character [c] - appears in the string [s]. */ -@deprecated("Use Core instead. This will be removed in v13") -let contains: (string, char) => bool - -/** [String.contains_from s start c] tests if character [c] - appears in [s] after position [start]. - [String.contains s c] is equivalent to - [String.contains_from s 0 c]. - - Raise [Invalid_argument] if [start] is not a valid position in [s]. */ -@deprecated("Use Core instead. This will be removed in v13") -let contains_from: (string, int, char) => bool - -/** [String.rcontains_from s stop c] tests if character [c] - appears in [s] before position [stop+1]. - - Raise [Invalid_argument] if [stop < 0] or [stop+1] is not a valid - position in [s]. */ -@deprecated("Use Core instead. This will be removed in v13") -let rcontains_from: (string, int, char) => bool - -/** Return a copy of the argument, with all lowercase letters - translated to uppercase, using the US-ASCII character set. - @since 4.03.0 */ -@deprecated("Use Core instead. This will be removed in v13") -let uppercase_ascii: string => string - -/** Return a copy of the argument, with all uppercase letters - translated to lowercase, using the US-ASCII character set. - @since 4.03.0 */ -@deprecated("Use Core instead. This will be removed in v13") -let lowercase_ascii: string => string - -/** Return a copy of the argument, with the first character set to uppercase, - using the US-ASCII character set. - @since 4.03.0 */ -@deprecated("Use Core instead. This will be removed in v13") -let capitalize_ascii: string => string - -/** Return a copy of the argument, with the first character set to lowercase, - using the US-ASCII character set. - @since 4.03.0 */ -@deprecated("Use Core instead. This will be removed in v13") -let uncapitalize_ascii: string => string - -/** An alias for the type of strings. */ -@deprecated("Use `string` instead. This will be removed in v13") -type t = string - -/** The comparison function for strings, with the same specification as - {!Pervasives.compare}. Along with the type [t], this function [compare] - allows the module [String] to be passed as argument to the functors - {!Set.Make} and {!Map.Make}. */ -@deprecated("Use Core instead. This will be removed in v13") -external compare: (t, t) => int = "%compare" - -/** The equal function for strings. - @since 4.03.0 */ -@deprecated("Use Core instead. This will be removed in v13") -external equal: (t, t) => bool = "%equal" - -/** [String.split_on_char sep s] returns the list of all (possibly empty) - substrings of [s] that are delimited by the [sep] character. - - The function's output is specified by the following invariants: - - - The list is not empty. - - Concatenating its elements using [sep] as a separator returns a - string equal to the input ([String.concat (String.make 1 sep) - (String.split_on_char sep s) = s]). - - No string in the result contains the [sep] character. - - @since 4.04.0 -*/ -@deprecated("Use Core instead. This will be removed in v13") -let split_on_char: (char, string) => list - -/* The following is for system use only. Do not call directly. */ -@deprecated("Use Core instead. This will be removed in v13") @send -external unsafe_get: (string, int) => char = "codePointAt" diff --git a/tests/tests/src/string_set.mjs b/tests/tests/src/string_set.mjs index a527046fbf..86ae7fd6c5 100644 --- a/tests/tests/src/string_set.mjs +++ b/tests/tests/src/string_set.mjs @@ -5,7 +5,9 @@ import * as Belt_List from "@rescript/runtime/lib/es6/Belt_List.js"; import * as Belt_Array from "@rescript/runtime/lib/es6/Belt_Array.js"; import * as Primitive_string from "@rescript/runtime/lib/es6/Primitive_string.js"; -let compare_elt = Primitive_string.compare; +function compare_elt(a, b) { + return Primitive_string.compare(a, b) | 0; +} function split(x, tree) { if (typeof tree !== "object") { @@ -18,7 +20,7 @@ function split(x, tree) { let r = tree._2; let v = tree._1; let l = tree._0; - let c = Primitive_string.compare(x, v); + let c = Primitive_string.compare(x, v) | 0; if (c === 0) { return [ l, @@ -55,7 +57,7 @@ function add(x, tree) { let r = tree._2; let v = tree._1; let l = tree._0; - let c = Primitive_string.compare(x, v); + let c = Primitive_string.compare(x, v) | 0; if (c === 0) { return tree; } else if (c < 0) { @@ -134,7 +136,7 @@ function mem(x, _tree) { if (typeof tree !== "object") { return false; } - let c = Primitive_string.compare(x, tree._1); + let c = Primitive_string.compare(x, tree._1) | 0; if (c === 0) { return true; } @@ -150,7 +152,7 @@ function remove(x, tree) { let r = tree._2; let v = tree._1; let l = tree._0; - let c = Primitive_string.compare(x, v); + let c = Primitive_string.compare(x, v) | 0; if (c === 0) { return Set_gen.internal_merge(l, r); } else if (c < 0) { @@ -183,7 +185,7 @@ function subset(_s1, _s2) { } let r2 = s2._2; let l2 = s2._0; - let c = Primitive_string.compare(v1, s2._1); + let c = Primitive_string.compare(v1, s2._1) | 0; if (c === 0) { if (!subset(l1, l2)) { return false; @@ -229,7 +231,7 @@ function find(x, _tree) { }; } let v = tree._1; - let c = Primitive_string.compare(x, v); + let c = Primitive_string.compare(x, v) | 0; if (c === 0) { return v; } @@ -279,8 +281,6 @@ function invariant(t) { return Set_gen.is_ordered(compare_elt, t); } -let $$String; - let empty = Set_gen.empty; let is_empty = Set_gen.is_empty; @@ -314,7 +314,6 @@ let of_sorted_list = Set_gen.of_sorted_list; let of_sorted_array = Set_gen.of_sorted_array; export { - $$String, compare_elt, empty, is_empty, diff --git a/tests/tests/src/string_set.res b/tests/tests/src/string_set.res index fa50691bb1..6804a07abd 100644 --- a/tests/tests/src/string_set.res +++ b/tests/tests/src/string_set.res @@ -22,10 +22,8 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -module String = Ocaml_String - type elt = string -let compare_elt = String.compare +let compare_elt = (a, b) => String.compare(a, b)->Float.toInt type t = Set_gen.t let empty = Set_gen.empty diff --git a/tests/tests/src/tagged_template_test.mjs b/tests/tests/src/tagged_template_test.mjs index 6752ffb598..65155ab03d 100644 --- a/tests/tests/src/tagged_template_test.mjs +++ b/tests/tests/src/tagged_template_test.mjs @@ -2,7 +2,6 @@ import * as Mocha from "mocha"; import * as Test_utils from "./test_utils.mjs"; -import * as Primitive_array from "@rescript/runtime/lib/es6/Primitive_array.js"; import * as Tagged_template_libJs from "./tagged_template_lib.js"; function sql(prim0, prim1) { @@ -28,9 +27,9 @@ function foo(strings, values) { let res = ""; let valueCount = values.length; for (let i = 0; i < valueCount; ++i) { - res = res + Primitive_array.get(strings, i) + (Primitive_array.get(values, i) * 10 | 0).toString(); + res = res + strings[i] + (values[i] * 10 | 0).toString(); } - return res + Primitive_array.get(strings, valueCount); + return res + strings[valueCount]; } let res = foo([ @@ -39,21 +38,18 @@ let res = foo([ ], [5]); Mocha.describe("tagged templates", () => { - Mocha.test("with externals, it should return a string with the correct interpolations", () => Test_utils.eq("File \"tagged_template_test.res\", line 40, characters 6-13", query, ` + Mocha.test("with externals, it should return a string with the correct interpolations", () => Test_utils.eq("File \"tagged_template_test.res\", line 41, characters 6-13", query, ` " SELECT * FROM 'users' WHERE id = '5'`)); - Mocha.test("with module scoped externals, it should also return a string with the correct interpolations", () => Test_utils.eq("File \"tagged_template_test.res\", line 49, characters 13-20", queryWithModule, "SELECT * FROM 'users' WHERE id = '5'")); - Mocha.test("with externals, it should return the result of the function", () => Test_utils.eq("File \"tagged_template_test.res\", line 52, characters 79-86", length, 52)); - Mocha.test("with rescript function, it should return a string with the correct encoding and interpolations", () => Test_utils.eq("File \"tagged_template_test.res\", line 56, characters 13-20", res, "| 5 × 10 = 50 |")); - Mocha.test("a template literal tagged with json should generate a regular string interpolation for now", () => Test_utils.eq("File \"tagged_template_test.res\", line 61, characters 13-20", "some random " + "string", "some random string")); - Mocha.test("a regular string interpolation should continue working", () => Test_utils.eq("File \"tagged_template_test.res\", line 65, characters 7-14", `some random ` + "string" + ` interpolation`, "some random string interpolation")); + Mocha.test("with module scoped externals, it should also return a string with the correct interpolations", () => Test_utils.eq("File \"tagged_template_test.res\", line 50, characters 13-20", queryWithModule, "SELECT * FROM 'users' WHERE id = '5'")); + Mocha.test("with externals, it should return the result of the function", () => Test_utils.eq("File \"tagged_template_test.res\", line 53, characters 79-86", length, 52)); + Mocha.test("with rescript function, it should return a string with the correct encoding and interpolations", () => Test_utils.eq("File \"tagged_template_test.res\", line 57, characters 13-20", res, "| 5 × 10 = 50 |")); + Mocha.test("a template literal tagged with json should generate a regular string interpolation for now", () => Test_utils.eq("File \"tagged_template_test.res\", line 62, characters 13-20", "some random " + "string", "some random string")); + Mocha.test("a regular string interpolation should continue working", () => Test_utils.eq("File \"tagged_template_test.res\", line 66, characters 7-14", `some random ` + "string" + ` interpolation`, "some random string interpolation")); }); -let $$Array; - let extraLength = 10; export { - $$Array, Pg, table, id, diff --git a/tests/tests/src/tagged_template_test.res b/tests/tests/src/tagged_template_test.res index ca501ac2e1..f8c579be68 100644 --- a/tests/tests/src/tagged_template_test.res +++ b/tests/tests/src/tagged_template_test.res @@ -1,8 +1,6 @@ open Mocha open Test_utils -module Array = Ocaml_Array - module Pg = { @module("./tagged_template_lib.js") @taggedTemplate external sql: (array, array) => string = "sql" @@ -27,9 +25,12 @@ let foo = (strings, values) => { let res = ref("") let valueCount = Belt.Array.length(values) for i in 0 to valueCount - 1 { - res := res.contents ++ strings[i] ++ Js.Int.toString(values[i] * 10) + res := + res.contents ++ + strings->Array.getUnsafe(i) ++ + Js.Int.toString(values->Array.getUnsafe(i) * 10) } - res.contents ++ strings[valueCount] + res.contents ++ strings->Array.getUnsafe(valueCount) } let res = foo`| 5 × 10 = ${5} |` diff --git a/tests/tests/src/test_string.mjs b/tests/tests/src/test_string.mjs index 2a2632bab0..30cd2a02ba 100644 --- a/tests/tests/src/test_string.mjs +++ b/tests/tests/src/test_string.mjs @@ -12,7 +12,7 @@ function f(x) { RE_EXN_ID: "Assert_failure", _1: [ "test_string.res", - 7, + 5, 17 ], Error: new Error() @@ -35,13 +35,10 @@ function c(x, y) { let v = "xx".length; function h(s) { - return s.codePointAt(0) === /* 'a' */97; + return s.codePointAt(0) === 97; } -let $$String; - export { - $$String, f, a, b, @@ -49,4 +46,4 @@ export { v, h, } -/* No side effect */ +/* v Not a pure module */ diff --git a/tests/tests/src/test_string.res b/tests/tests/src/test_string.res index 05b4711917..48f1d5d8f0 100644 --- a/tests/tests/src/test_string.res +++ b/tests/tests/src/test_string.res @@ -1,5 +1,3 @@ -module String = Ocaml_String - let f = x => switch x { | "aaaabb" => 0 @@ -15,4 +13,4 @@ let c = (x, y) => x ++ "hello" ++ ("hi" ++ ("u" ++ ("hi" ++ y))) let v = String.length("xx") -let h = (s: string) => String.get(s, 0) == 'a' +let h = (s: string) => String.codePointAt(s, 0) === Some(97) diff --git a/tests/tests/src/test_string_const.mjs b/tests/tests/src/test_string_const.mjs index b72cdead14..e9d7c97859 100644 --- a/tests/tests/src/test_string_const.mjs +++ b/tests/tests/src/test_string_const.mjs @@ -1,28 +1,13 @@ // Generated by ReScript, PLEASE EDIT WITH CARE -import * as Primitive_exceptions from "@rescript/runtime/lib/es6/Primitive_exceptions.js"; +import * as Mocha from "mocha"; +import * as Test_utils from "./test_utils.mjs"; -let f = "ghsogh".codePointAt(3); +Mocha.describe("Test_string_const", () => { + Mocha.test("getUnsafe", () => { + Test_utils.eq("File \"test_string_const.res\", line 6, characters 7-14", "ghsogh".codePointAt(3), 111); + Test_utils.eq("File \"test_string_const.res\", line 7, characters 7-14", "ghsogh".codePointAt(-3), undefined); + }); +}); -let hh; - -try { - hh = "ghsogh".codePointAt(-3); -} catch (raw_e) { - let e = Primitive_exceptions.internalToException(raw_e); - if (e.RE_EXN_ID === "Invalid_argument") { - console.log(e._1); - hh = /* 'a' */97; - } else { - throw e; - } -} - -let $$String; - -export { - $$String, - f, - hh, -} -/* f Not a pure module */ +/* Not a pure module */ diff --git a/tests/tests/src/test_string_const.res b/tests/tests/src/test_string_const.res index 613e183d58..c09e089172 100644 --- a/tests/tests/src/test_string_const.res +++ b/tests/tests/src/test_string_const.res @@ -1,9 +1,9 @@ -module String = Ocaml_String +open Mocha +open Test_utils -let f = String.get("ghsogh", 3) - -let hh = try String.get("ghsogh", -3) catch { -| Invalid_argument(e) => - Js.log(e) - 'a' -} +describe(__MODULE__, () => { + test("getUnsafe", () => { + eq(__LOC__, String.codePointAt("ghsogh", 3), Some(111)) + eq(__LOC__, String.codePointAt("ghsogh", -3), None) + }) +})