// Generated by ReScript, PLEASE EDIT WITH CARE import * as Mocha from "mocha"; import * as Stdlib_Int from "@rescript/runtime/lib/es6/Stdlib_Int.mjs"; import * as Test_utils from "./test_utils.mjs"; import * as Stdlib_Option from "@rescript/runtime/lib/es6/Stdlib_Option.mjs"; globalThis.orderCounter = 0 globalThis.bumpOrderCounter = () => { globalThis.orderCounter++ } globalThis.makeCounter = () => ({ v: 7, get(x) { return this.v + x } }) ; let resetOrderCounter = (() => { globalThis.orderCounter = 0 }); let makeBox = (x => ({x})); let makeOps = (() => ({f: x => x + 1})); let count = { contents: 0 }; let tmp = count.contents; count.contents = count.contents + 1 | 0; let c = count.contents; let topLevel_1 = c * 10 | 0; let topLevel = [ tmp, topLevel_1 ]; Mocha.describe("Argument_evaluation_order_test", () => { Mocha.test("a read before a block that writes it, at the top level", () => Test_utils.eq("File \"argument_evaluation_order_test.res\", line 47, characters 7-14", [ 0, 10 ], topLevel)); Mocha.test("a local ref that becomes a JS variable", () => { let n = 0; let tmp = n; n = n + 1 | 0; let m = n; let pair_1 = m * 10 | 0; let pair = [ tmp, pair_1 ]; Test_utils.eq("File \"argument_evaluation_order_test.res\", line 60, characters 7-14", [ 0, 10 ], pair); }); Mocha.test("a local ref that a closure called in the block assigns", () => { let n = 0; let bump = () => { n = n + 1 | 0; }; let tmp = n; bump(); let m = n; let pair_1 = m * 10 | 0; let pair = [ tmp, pair_1 ]; Test_utils.eq("File \"argument_evaluation_order_test.res\", line 74, characters 7-14", [ 0, 10 ], pair); }); Mocha.test("effects in arrays, tuples, records, dicts and objects", () => { let log = []; let mark = (s, v) => { log.push(s); return v; }; let tmp = mark("first", 1); let v = mark("second", 2); let arr = [ tmp, v * v | 0 ]; let tmp$1 = mark("first", 1); let v$1 = mark("second", 3); let tup_1 = v$1 * v$1 | 0; let tup = [ tmp$1, tup_1 ]; let tmp$2 = mark("first", 1); let v$2 = mark("second", 4); let rec__b = v$2 * v$2 | 0; let rec_ = { a: tmp$2, b: rec__b }; let tmp$3 = mark("first", 1); let v$3 = mark("second", 5); let d = { a: tmp$3, b: v$3 * v$3 | 0 }; let tmp$4 = mark("first", 1); let v$4 = mark("second", 6); let o = { a: tmp$4, b: v$4 * v$4 | 0 }; Test_utils.eq("File \"argument_evaluation_order_test.res\", line 119, characters 6-13", [ "first", "second", "first", "second", "first", "second", "first", "second", "first", "second" ], log); Test_utils.eq("File \"argument_evaluation_order_test.res\", line 134, characters 7-14", [ 1, 4 ], arr); Test_utils.eq("File \"argument_evaluation_order_test.res\", line 135, characters 7-14", [ 1, 9 ], tup); Test_utils.eq("File \"argument_evaluation_order_test.res\", line 136, characters 7-14", { a: 1, b: 16 }, rec_); Test_utils.eq("File \"argument_evaluation_order_test.res\", line 137, characters 7-14", { a: 1, b: 25 }, d); Test_utils.eq("File \"argument_evaluation_order_test.res\", line 138, characters 7-14", [ 1, 36 ], [ o.a, o.b ]); }); Mocha.test("calls of externals and of ReScript functions", () => { let log = []; let mark = (s, v) => { log.push(s); return v; }; let tmp = mark("x", 1); let v = mark("y", 2); let viaExternal = Array.of(tmp, v * v | 0); let tmp$1 = mark("x", 1); let v$1 = mark("y", 2); let viaFunction = tmp$1 + (v$1 * v$1 | 0) | 0; Test_utils.eq("File \"argument_evaluation_order_test.res\", line 162, characters 7-14", [ "x", "y", "x", "y" ], log); Test_utils.eq("File \"argument_evaluation_order_test.res\", line 163, characters 7-14", [ 1, 4 ], viaExternal); Test_utils.eq("File \"argument_evaluation_order_test.res\", line 164, characters 7-14", 5, viaFunction); }); Mocha.test("a switch and a try as arguments", () => { let log = []; let mark = (s, v) => { log.push(s); return v; }; let tmp = mark("before", 0); let match = mark("scrutinee", 1); let viaSwitch = [ tmp, match !== 0 ? ( match !== 1 ? mark("other", 12) : mark("one", 11) ) : mark("zero", 10) ]; let tmp$1 = mark("before", 0); let tmp$2; try { tmp$2 = mark("body", 1); } catch (exn) { tmp$2 = 2; } let viaTry = [ tmp$1, tmp$2 ]; Test_utils.eq("File \"argument_evaluation_order_test.res\", line 187, characters 7-14", [ "before", "scrutinee", "one", "before", "body" ], log); Test_utils.eq("File \"argument_evaluation_order_test.res\", line 188, characters 7-14", [ 0, 11 ], viaSwitch); Test_utils.eq("File \"argument_evaluation_order_test.res\", line 189, characters 7-14", [ 0, 1 ], viaTry); }); Mocha.test("the start of a for loop before a block in its end", () => { let r = 0; let visited = []; let i_start = r; r = 2; let e = r; for (let i = i_start, i_finish = e - 1 | 0; i <= i_finish; ++i) { visited.push(i); } Test_utils.eq("File \"argument_evaluation_order_test.res\", line 202, characters 7-14", [ 0, 1 ], visited); }); Mocha.test("a JS global read before a block that changes it", () => { resetOrderCounter(); let tmp = orderCounter; bumpOrderCounter(); let m = orderCounter; let pair_1 = m * 10 | 0; let pair = [ tmp, pair_1 ]; Test_utils.eq("File \"argument_evaluation_order_test.res\", line 215, characters 7-14", [ 0, 10 ], pair); }); Mocha.test("the target of a JS object write before a block in the value", () => { let log = []; let mark = (s, v) => { log.push(s); return v; }; let o = makeBox(0); let first = o; let tmp = o; o = makeBox(100); let v = mark("v", 5); tmp.x = v * v | 0; Test_utils.eq("File \"argument_evaluation_order_test.res\", line 232, characters 7-14", [ 25, 100 ], [ first.x, o.x ]); }); Mocha.test("a function read from a record field before the arguments", () => { let o = makeOps(); let tmp = o.f; o.f = x => x + 100 | 0; let y = Stdlib_Option.getOrThrow(Stdlib_Int.fromString("1"), undefined); let r = tmp((y << 1)); Test_utils.eq("File \"argument_evaluation_order_test.res\", line 242, characters 7-14", 3, r); }); Mocha.test("a function read from a ref before the arguments", () => { let fr = x => x + 1 | 0; let tmp = fr; fr = x => x + 100 | 0; let y = Stdlib_Option.getOrThrow(Stdlib_Int.fromString("1"), undefined); let r = tmp((y << 1)); Test_utils.eq("File \"argument_evaluation_order_test.res\", line 252, characters 7-14", 3, r); }); Mocha.test("a held receiver is still passed as this", () => { let log = []; let tmp = makeCounter(); log.push("arg"); let y = log.length; let r = tmp.get((y << 1)); Test_utils.eq("File \"argument_evaluation_order_test.res\", line 262, characters 7-14", 9, r); }); Mocha.test("a method keeps a receiver that stays in place", () => { let arr = [1]; arr.push(2); let l = arr.length; let length = arr.push(l * 100 | 0); Test_utils.eq("File \"argument_evaluation_order_test.res\", line 272, characters 7-14", 3, length); Test_utils.eq("File \"argument_evaluation_order_test.res\", line 273, characters 7-14", [ 1, 2, 200 ], arr); }); }); export { resetOrderCounter, makeBox, makeOps, count, topLevel, } /* Not a pure module */