// Generated by ReScript, PLEASE EDIT WITH CARE import * as Mocha from "mocha"; import * as Test_utils from "./test_utils.mjs"; import * as Primitive_array from "@rescript/runtime/lib/es6/Primitive_array.mjs"; function id(x) { return x; } function dictTry(base) { let tmp = {...base}; let tmp$1; try { base["a"] = 100; tmp$1 = id(5); } catch (exn) { tmp$1 = 0; } return { ...tmp, b: tmp$1 }; } function dictLaterSpread(base, other) { let tmp = id(0); let tmp$1 = {...base}; let tmp$2; try { base["a"] = 100; tmp$2 = other(); } catch (exn) { tmp$2 = {}; } return { first: tmp, ...tmp$1, ...tmp$2, ...base }; } function arrayTry(base) { let tmp = [...base]; let tmp$1; try { base.push(100); tmp$1 = id(5); } catch (exn) { tmp$1 = 0; } return Primitive_array.spread([ tmp, [tmp$1] ]); } function arrayCall(base, f) { return [ ...base, f() ]; } function arrayLaterSpread(base, f) { return [ 0, ...base, ...f(), ...base ]; } function arrayCallThenTry(base, f) { let tmp = [...base]; let tmp$1 = f(); let tmp$2; try { tmp$2 = f(); } catch (exn) { tmp$2 = 0; } return Primitive_array.spread([ tmp, [ tmp$1, tmp$2 ] ]); } function arrayNested(base, f) { let tmp = [ ...base, f() ]; let tmp$1; try { tmp$1 = f(); } catch (exn) { tmp$1 = 0; } return id([ tmp, tmp$1 ]); } async function arrayAwait(base, f) { return [ ...base, await f() ]; } function arrayObjectRead(base, obj) { return [ ...base, obj.x ]; } function arrayIndexedCall(base, f) { return [ ...base, f()[0] ]; } function arrayIndexCall(base, items, f) { return [ ...base, items[f()] ]; } function arraySequence(base) { return [ ...base, (base[2] = undefined, undefined) ]; } function arrayAppendLeft(base, f) { return [ ...base, f() + "!" ]; } function arrayAppendRight(base, f) { return [ ...base, "!" + f() ]; } function arrayOperandLeft(base, obj) { return [ ...base, obj.x + 1 | 0 ]; } function arrayOperandRight(base, obj) { return [ ...base, 1 + obj.x | 0 ]; } function arrayOperandCall(base, f) { return [ ...base, (f() << 1) ]; } function arrayCondTest(base, f) { return [ ...base, f() > 0 ? 1 : 2 ]; } function arrayCondThen(base, flag, f) { return [ ...base, flag ? f() : 2 ]; } function arrayCondElse(base, flag, f) { return [ ...base, flag ? 1 : f() ]; } function arrayTemplate(base, x, f) { return [ ...base, `${x}-${f()}` ]; } function arrayDictElement(base, f) { return [ ...base, { x: 1, y: f() } ]; } function arrayDictSpreadElement(base, other) { return [ ...base, { x: 1, ...other } ]; } function arrayRecordSpreadCall(base, f) { let tmp = [...base]; let init = f(); return Primitive_array.spread([ tmp, [{ a: 1, items: init.items }] ]); } function arrayRecordSpreadField(base, r, f) { return [ ...base, { a: f(), items: r.items } ]; } function variadicCall(base, f) { return Array.of(...base, f()); } function dictCall(base, f) { return { ...base, b: f() }; } function dictPure(base, r) { let a = r.a; return { ...base, a: a * a | 0 }; } function arrayPure(base, r) { return Primitive_array.spread([ base, [r.a + 1 | 0], r.items, [ base.length, r.a > 0 ? 1 : 2 ] ]); } function arrayPureStatement(base, r) { let a = r.a; return Primitive_array.spread([ base, [a * a | 0] ]); } function arrayPureConstants(base, r) { return Primitive_array.spread([ base, [ undefined, null, r ] ]); } function arrayPureFunction(base) { return Primitive_array.spread([ base, [() => { base.push(() => {}); }] ]); } function arrayPureAppend(base, x) { return Primitive_array.spread([ base, [x + "!"] ]); } function arrayPureTemplate(base, x) { return Primitive_array.spread([ base, [`${x}-${x}`] ]); } function arrayPureDict(base, x) { return Primitive_array.spread([ base, [{ x: x }] ]); } function arrayPureRecordSpread(base, r, x) { return Primitive_array.spread([ base, [{ a: x, items: r.items }] ]); } function arrayOptionalRecordSpreadCall(base, f) { return [ ...base, { ...f(), a: 1 } ]; } function arrayPureOptionalRecordSpread(base, r, x) { return Primitive_array.spread([ base, [{ ...r, a: x }] ]); } function arrayNoElement(base, f) { return Primitive_array.spread([ [f()], base ]); } function arrayLiteral(f) { return Primitive_array.spread([ [ f(), 2 ], [f()] ]); } function arrayHeldCall(base, f, r) { let tmp = [...base]; let tmp$1 = f(); let a = r.a; return Primitive_array.spread([ tmp, tmp$1, [a * a | 0] ]); } function dictHeldCall(base, f, r) { let tmp = {...base}; let tmp$1 = f(); let a = r.a; return { ...tmp, ...tmp$1, a: a * a | 0 }; } function dictHeldValue(base, f, other, r) { let tmp = {...base}; let tmp$1 = f(); let a = r.a; return { ...tmp, x: tmp$1, ...other, a: a * a | 0 }; } function arrayIndexRead(base, d) { return [ ...base, d["x"] ]; } function arrayArrayIndexRead(base, items) { return [ ...base, items[0] ]; } function dictIndexRead(base, d, r) { let tmp = {...base}; let tmp$1 = d["x"]; let a = r.a; return { ...tmp, x: tmp$1, a: a * a | 0 }; } Mocha.describe("Dict_array_spread_order_test", () => { let base = [ 1, 2 ]; let pushing = base => (() => { base.push(100); return id(5); }); Mocha.test("a dict spread is copied before later statements", () => { Test_utils.eq("File \"dict_array_spread_order_test.res\", line 219, characters 7-14", dictTry({ a: 1 }), { a: 1, b: 5 }); let dict = dictLaterSpread({ a: 1 }, () => ({ c: 3 })); Test_utils.eq("File \"dict_array_spread_order_test.res\", line 221, characters 7-14", dict, { first: 0, a: 100, c: 3 }); let base = { a: 1 }; let dict$1 = dictLaterSpread(base, () => { delete(base["a"]); return { c: 3 }; }); Test_utils.eq("File \"dict_array_spread_order_test.res\", line 230, characters 7-14", dict$1, { first: 0, a: 1, c: 3 }); }); Mocha.test("an array spread is copied before later statements", () => Test_utils.eq("File \"dict_array_spread_order_test.res\", line 234, characters 7-14", arrayTry([ 1, 2 ]), [ 1, 2, 5 ])); Mocha.test("an array spread is copied before later calls", () => { let base = [ 1, 2 ]; Test_utils.eq("File \"dict_array_spread_order_test.res\", line 239, characters 7-14", arrayCall(base, pushing(base)), [ 1, 2, 5 ]); Test_utils.eq("File \"dict_array_spread_order_test.res\", line 240, characters 7-14", base, [ 1, 2, 100 ]); let base$1 = [ 1, 2 ]; let result = arrayLaterSpread(base$1, () => { base$1.push(100); return base$1; }); Test_utils.eq("File \"dict_array_spread_order_test.res\", line 250, characters 7-14", result, [ 0, 1, 2, 1, 2, 100, 1, 2, 100 ]); let base$2 = [ 1, 2 ]; Test_utils.eq("File \"dict_array_spread_order_test.res\", line 253, characters 7-14", arrayCallThenTry(base$2, pushing(base$2)), [ 1, 2, 5, 5 ]); let base$3 = [ 1, 2 ]; Test_utils.eq("File \"dict_array_spread_order_test.res\", line 256, characters 7-14", arrayNested(base$3, pushing(base$3)), [ [ 1, 2, 5 ], 5 ]); let base$4 = [ 1, 2 ]; Test_utils.eq("File \"dict_array_spread_order_test.res\", line 259, characters 7-14", variadicCall(base$4, pushing(base$4)), [ 1, 2, 5 ]); }); Mocha.test("an array spread is copied before a later getter", () => { let base = [ 1, 2 ]; let obj = ((base => ({get x() { base.push(100); return 5; }})))(base); Test_utils.eq("File \"dict_array_spread_order_test.res\", line 265, characters 7-14", arrayObjectRead(base, obj), [ 1, 2, 5 ]); }); Mocha.test("an array spread is copied before a later await", async () => { let base = [ 1, 2 ]; return Test_utils.eq("File \"dict_array_spread_order_test.res\", line 270, characters 7-14", await arrayAwait(base, async () => pushing(base)()), [ 1, 2, 5 ]); }); Mocha.test("an array spread is copied before code in any part of a later element", () => { let base = [ 1, 2 ]; Test_utils.eq("File \"dict_array_spread_order_test.res\", line 275, characters 7-14", arrayIndexedCall(base, () => [pushing(base)()]), [ 1, 2, 5 ]); let base$1 = [ 1, 2 ]; Test_utils.eq("File \"dict_array_spread_order_test.res\", line 277, characters 7-14", arrayIndexCall(base$1, [7], () => pushing(base$1)() - 5 | 0), [ 1, 2, 7 ]); let base$2 = [ 1, 2 ]; Test_utils.eq("File \"dict_array_spread_order_test.res\", line 279, characters 7-14", arrayOperandCall(base$2, pushing(base$2)), [ 1, 2, 10 ]); let base$3 = [ 1, 2 ]; Test_utils.eq("File \"dict_array_spread_order_test.res\", line 281, characters 7-14", arrayCondTest(base$3, pushing(base$3)), [ 1, 2, 1 ]); let base$4 = [ 1, 2 ]; Test_utils.eq("File \"dict_array_spread_order_test.res\", line 283, characters 7-14", arrayCondThen(base$4, true, pushing(base$4)), [ 1, 2, 5 ]); let base$5 = [ 1, 2 ]; Test_utils.eq("File \"dict_array_spread_order_test.res\", line 285, characters 7-14", arrayCondElse(base$5, false, pushing(base$5)), [ 1, 2, 5 ]); let base$6 = [ 1, 2 ]; let obj = ((base => ({get x() { base.push(100); return 5; }})))(base$6); Test_utils.eq("File \"dict_array_spread_order_test.res\", line 288, characters 7-14", arrayOperandLeft(base$6, obj), [ 1, 2, 6 ]); let base$7 = [ 1, 2 ]; let obj$1 = ((base => ({get x() { base.push(100); return 5; }})))(base$7); Test_utils.eq("File \"dict_array_spread_order_test.res\", line 291, characters 7-14", arrayOperandRight(base$7, obj$1), [ 1, 2, 6 ]); }); Mocha.test("an array spread of strings is copied before a later call", () => { let pushingString = base => (() => { base.push("z"); return "y"; }); let base = ["a"]; Test_utils.eq("File \"dict_array_spread_order_test.res\", line 301, characters 7-14", arrayAppendLeft(base, pushingString(base)), [ "a", "y!" ]); let base$1 = ["a"]; Test_utils.eq("File \"dict_array_spread_order_test.res\", line 303, characters 7-14", arrayAppendRight(base$1, pushingString(base$1)), [ "a", "!y" ]); let base$2 = ["a"]; Test_utils.eq("File \"dict_array_spread_order_test.res\", line 305, characters 7-14", arrayTemplate(base$2, "x", pushingString(base$2)), [ "a", "x-y" ]); }); Mocha.test("an array spread is copied before a later object or record that runs code", () => { let base = [{ a: 1 }]; let f = () => { base.push({ z: 0 }); return 2; }; Test_utils.eq("File \"dict_array_spread_order_test.res\", line 314, characters 7-14", arrayDictElement(base, f), [ { a: 1 }, { x: 1, y: 2 } ]); let base$1 = [{ a: 1 }]; let other = ((base => ({get y() { base.push({}); return 2; }})))(base$1); Test_utils.eq("File \"dict_array_spread_order_test.res\", line 317, characters 7-14", arrayDictSpreadElement(base$1, other), [ { a: 1 }, { x: 1, y: 2 } ]); let base$2 = [{ a: 0, items: [] }]; let f$1 = () => { base$2.push({ a: 9, items: [] }); return { a: 5, items: [3] }; }; Test_utils.eq("File \"dict_array_spread_order_test.res\", line 323, characters 7-14", arrayRecordSpreadCall(base$2, f$1), [ { a: 0, items: [] }, { a: 1, items: [3] } ]); let base$3 = [{ a: 0, items: [] }]; let f$2 = () => { base$3.push({ a: 9, items: [] }); return 4; }; let r = { a: 5, items: [3] }; Test_utils.eq("File \"dict_array_spread_order_test.res\", line 330, characters 7-14", arrayRecordSpreadField(base$3, r, f$2), [ { a: 0, items: [] }, { a: 4, items: [3] } ]); let base$4 = [{ a: 0 }]; let f$3 = () => { base$4.push({ a: 9 }); return { a: 5, b: 3 }; }; Test_utils.eq("File \"dict_array_spread_order_test.res\", line 336, characters 7-14", arrayOptionalRecordSpreadCall(base$4, f$3), [ { a: 0 }, { a: 1, b: 3 } ]); }); Mocha.test("a spread is copied before a later value held before pure statements", () => { let r = { a: 3, items: [] }; let base = [ 1, 2 ]; let f = () => { base.push(100); return [7]; }; Test_utils.eq("File \"dict_array_spread_order_test.res\", line 346, characters 7-14", arrayHeldCall(base, f, r), [ 1, 2, 7, 9 ]); let base$1 = { b: 1 }; let f$1 = () => { base$1["z"] = 100; return { c: 2 }; }; Test_utils.eq("File \"dict_array_spread_order_test.res\", line 352, characters 7-14", dictHeldCall(base$1, f$1, r), { b: 1, c: 2, a: 9 }); let base$2 = { b: 1 }; let f$2 = () => { base$2["z"] = 100; return 5; }; Test_utils.eq("File \"dict_array_spread_order_test.res\", line 358, characters 7-14", dictHeldValue(base$2, f$2, { c: 2 }, r), { b: 1, x: 5, c: 2, a: 9 }); }); Mocha.test("a spread is copied before a later index read that runs a getter", () => { let base = [ 1, 2 ]; let d = ((base => ({get x() { base.push(100); return 5; }})))(base); Test_utils.eq("File \"dict_array_spread_order_test.res\", line 364, characters 7-14", arrayIndexRead(base, d), [ 1, 2, 5 ]); Test_utils.eq("File \"dict_array_spread_order_test.res\", line 365, characters 7-14", arrayArrayIndexRead([ 1, 2 ], [7]), [ 1, 2, 7 ]); let base$1 = { b: 1 }; let d$1 = ((base => ({get x() { base.z = 100; return 5; }})))(base$1); Test_utils.eq("File \"dict_array_spread_order_test.res\", line 368, characters 7-14", dictIndexRead(base$1, d$1, { a: 3, items: [] }), { b: 1, x: 5, a: 9 }); }); Mocha.test("a later element that changes the spread where it stands", () => { let base = [ undefined, undefined ]; Test_utils.eq("File \"dict_array_spread_order_test.res\", line 373, characters 7-14", arraySequence(base).length, 3); }); Mocha.test("elements that run no code", () => { let r = { a: 3, items: [7] }; Test_utils.eq("File \"dict_array_spread_order_test.res\", line 378, characters 7-14", dictCall({ a: 1 }, () => 5), { a: 1, b: 5 }); Test_utils.eq("File \"dict_array_spread_order_test.res\", line 379, characters 7-14", dictPure({ b: 1 }, r), { b: 1, a: 9 }); Test_utils.eq("File \"dict_array_spread_order_test.res\", line 380, characters 7-14", arrayPure(base, r), [ 1, 2, 4, 7, 2, 1 ]); Test_utils.eq("File \"dict_array_spread_order_test.res\", line 381, characters 7-14", arrayPureStatement(base, r), [ 1, 2, 9 ]); Test_utils.eq("File \"dict_array_spread_order_test.res\", line 382, characters 7-14", arrayNoElement(base, () => 0), [ 0, 1, 2 ]); Test_utils.eq("File \"dict_array_spread_order_test.res\", line 383, characters 7-14", arrayLiteral(() => 1), [ 1, 2, 1 ]); Test_utils.eq("File \"dict_array_spread_order_test.res\", line 384, characters 7-14", arrayPureAppend(["a"], "x"), [ "a", "x!" ]); Test_utils.eq("File \"dict_array_spread_order_test.res\", line 385, characters 7-14", arrayPureTemplate(["a"], "x"), [ "a", "x-x" ]); Test_utils.eq("File \"dict_array_spread_order_test.res\", line 386, characters 7-14", arrayPureDict([{ a: 1 }], 2), [ { a: 1 }, { x: 2 } ]); Test_utils.eq("File \"dict_array_spread_order_test.res\", line 387, characters 7-14", arrayPureRecordSpread([r], r, 1), [ r, { a: 1, items: [7] } ]); Test_utils.eq("File \"dict_array_spread_order_test.res\", line 388, characters 7-14", arrayPureOptionalRecordSpread([], { a: 0, b: 2 }, 1), [{ a: 1, b: 2 }]); Test_utils.eq("File \"dict_array_spread_order_test.res\", line 389, characters 7-14", arrayPureFunction([]).length, 1); Test_utils.eq("File \"dict_array_spread_order_test.res\", line 390, characters 7-14", arrayPureConstants([], 1).length, 3); }); }); export { id, dictTry, dictLaterSpread, arrayTry, arrayCall, arrayLaterSpread, arrayCallThenTry, arrayNested, arrayAwait, arrayObjectRead, arrayIndexedCall, arrayIndexCall, arraySequence, arrayAppendLeft, arrayAppendRight, arrayOperandLeft, arrayOperandRight, arrayOperandCall, arrayCondTest, arrayCondThen, arrayCondElse, arrayTemplate, arrayDictElement, arrayDictSpreadElement, arrayRecordSpreadCall, arrayRecordSpreadField, variadicCall, dictCall, dictPure, arrayPure, arrayPureStatement, arrayPureConstants, arrayPureFunction, arrayPureAppend, arrayPureTemplate, arrayPureDict, arrayPureRecordSpread, arrayOptionalRecordSpreadCall, arrayPureOptionalRecordSpread, arrayNoElement, arrayLiteral, arrayHeldCall, dictHeldCall, dictHeldValue, arrayIndexRead, arrayArrayIndexRead, dictIndexRead, } /* Not a pure module */