// Generated by ReScript, PLEASE EDIT WITH CARE import * as Mocha from "mocha"; import * as Test_utils from "./test_utils.mjs"; function id(x) { return x; } function closures() { let fs = []; let i_start = id(0); let tmp; try { tmp = id(2); } catch (exn) { tmp = 0; } for (let i = i_start; i <= tmp; ++i) { fs.push(() => i); } return fs.map(f => f()); } function closuresDownto() { let fs = []; let i_start = id(2); let n = id(0); for (let i = i_start, i_finish = n !== undefined ? n : 1; i >= i_finish; --i) { fs.push(() => i); } return fs.map(f => f()); } function emptyRange() { let fs = []; let i_start = id(3); let tmp; try { tmp = id(1); } catch (exn) { tmp = 0; } for (let i = i_start; i <= tmp; ++i) { fs.push(() => i); } return fs.length; } function startBeforeEnd() { let order = []; let note = x => { order.push(x); return x; }; let fs = []; let i_start = note(1); let tmp; try { tmp = note(3); } catch (exn) { tmp = 0; } for (let i = i_start; i <= tmp; ++i) { fs.push(() => i); } return [ order, fs.map(f => f()) ]; } function uppercaseExotic() { let fs = []; let Start_start = id(0); let tmp; try { tmp = id(2); } catch (exn) { tmp = 0; } for (let Start = Start_start; Start <= tmp; ++Start) { fs.push(() => Start); } for (let End = 3, End_finish = id(4); End <= End_finish; ++End) { fs.push(() => End); } return fs.map(f => f()); } function inOperatorEnd(d) { let fs = []; let i_start = id(0); let n; try { n = id(1); } catch (exn) { n = 0; } for (let i = i_start, i_finish = ("x" in d) ? n : 2; i <= i_finish; ++i) { fs.push(() => i); } return fs.map(f => f()); } function inOperatorEndConditional(d) { let fs = []; for (let i = 0, i_finish = ("x" in d) ? 3 : 2; i <= i_finish; ++i) { fs.push(() => i); } return fs.map(f => f()); } Mocha.describe("For_loop_closure_test", () => { Mocha.test("closures capture each iteration", () => Test_utils.eq("File \"for_loop_closure_test.res\", line 109, characters 7-14", closures(), [ 0, 1, 2 ])); Mocha.test("closures capture each iteration with downto", () => Test_utils.eq("File \"for_loop_closure_test.res\", line 112, characters 7-14", closuresDownto(), [ 2, 1, 0 ])); Mocha.test("empty range runs no iteration", () => Test_utils.eq("File \"for_loop_closure_test.res\", line 115, characters 7-14", emptyRange(), 0)); Mocha.test("the start runs before the end's statements", () => Test_utils.eq("File \"for_loop_closure_test.res\", line 118, characters 7-14", startBeforeEnd(), [ [ 1, 3 ], [ 1, 2, 3 ] ])); Mocha.test("uppercase exotic loop variables", () => Test_utils.eq("File \"for_loop_closure_test.res\", line 121, characters 7-14", uppercaseExotic(), [ 0, 1, 2, 3, 4 ])); Mocha.test("an end using `in` after a start that runs first", () => { Test_utils.eq("File \"for_loop_closure_test.res\", line 124, characters 7-14", inOperatorEnd({ x: 1 }), [ 0, 1 ]); Test_utils.eq("File \"for_loop_closure_test.res\", line 125, characters 7-14", inOperatorEnd({}), [ 0, 1, 2 ]); }); Mocha.test("an end using `in` in a conditional", () => { Test_utils.eq("File \"for_loop_closure_test.res\", line 128, characters 7-14", inOperatorEndConditional({ x: 1 }), [ 0, 1, 2, 3 ]); Test_utils.eq("File \"for_loop_closure_test.res\", line 129, characters 7-14", inOperatorEndConditional({}), [ 0, 1, 2 ]); }); }); export { id, closures, closuresDownto, emptyRange, startBeforeEnd, uppercaseExotic, inOperatorEnd, inOperatorEndConditional, } /* Not a pure module */