Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
25 changes: 17 additions & 8 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -227,14 +227,23 @@ Below we will discuss on how to write, build and run these test files.
- Inside the file, add a mocha test suite. The mocha bindings are defined in `tests/tests/src/mt.res`. To get you started, here is a simple scaffold for a test suite with multiple test cases:

```rescript
let suites: Mt.pair_suites = list{
("hey", _ => Eq(true, 3 > 2)),
("hi", _ => Neq(2, 3)),
("hello", _ => Approx(3.0, 3.0)),
("throw", _ => ThrowAny(_ => raise(SomeException))),
}

Mt.from_pair_suites(__MODULE__, suites)
open Mocha
open Test_utils

describe(__MODULE__, () => {
test("hey", () => {
ok(__LOC__, 3 > 2)
})

test("hi", () => {
eq(__LOC__, 2, 2)
eq(__LOC__, 3, 3)
})

test("throw", () => {
throws(__LOC__, () => throw(SomeException))
})
})
```

- Build the test files and run the tests: `node scripts/test.js -mocha`.
Expand Down
1 change: 1 addition & 0 deletions biome.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
"rewatch/**",
"lib/es6/**",
"lib/js/**",
"lib/bs/**",
"ninja/**",
"playground/**",
"*.bs.js",
Expand Down
1 change: 0 additions & 1 deletion tests/tests/src/abstract_type.resi
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,3 @@ type arrow_type = int => int

type poly_type<'a> = 'a
type poly_abstract_type<'a>
open Mt
35 changes: 6 additions & 29 deletions tests/tests/src/and_or_tailcall_test.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Generated by ReScript, PLEASE EDIT WITH CARE

import * as Mt from "./mt.mjs";
import * as Mocha from "mocha";
import * as Test_utils from "./test_utils.mjs";

function f(b, x, _n) {
while (true) {
Expand Down Expand Up @@ -30,37 +31,13 @@ function or_f(b, x, _n) {
};
}

let suites_0 = [
"and_tail",
param => ({
TAG: "Eq",
_0: false,
_1: f(true, 1, 0)
})
];

let suites_1 = {
hd: [
"or_tail",
param => ({
TAG: "Eq",
_0: false,
_1: or_f(false, 1, 0)
})
],
tl: /* [] */0
};

let suites = {
hd: suites_0,
tl: suites_1
};

Mt.from_pair_suites("And_or_tailcall_test", suites);
Mocha.describe("And_or_tailcall_test", () => {
Mocha.test("and_tail", () => Test_utils.eq("File \"and_or_tailcall_test.res\", line 21, characters 7-14", false, f(true, 1, 0)));
Mocha.test("or_tail", () => Test_utils.eq("File \"and_or_tailcall_test.res\", line 24, characters 7-14", false, or_f(false, 1, 0)));
});

export {
f,
or_f,
suites,
}
/* Not a pure module */
20 changes: 11 additions & 9 deletions tests/tests/src/and_or_tailcall_test.res
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@ let rec or_f = (b, x, n) =>
b || or_f(b, x, n + 1)
}

let suites = {
open Mt
list{
/* becareful inlining will defeat the test purpose here */
("and_tail", _ => Eq(false, f(true, 1, 0))),
("or_tail", _ => Eq(false, or_f(false, 1, 0))),
}
}
open Mocha
open Test_utils

Mt.from_pair_suites(__MODULE__, suites)
describe(__MODULE__, () => {
/* becareful inlining will defeat the test purpose here */
test("and_tail", () => {
eq(__LOC__, false, f(true, 1, 0))
})
test("or_tail", () => {
eq(__LOC__, false, or_f(false, 1, 0))
})
})
56 changes: 8 additions & 48 deletions tests/tests/src/ari_regress_test.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Generated by ReScript, PLEASE EDIT WITH CARE

import * as Mt from "./mt.mjs";
import * as Mocha from "mocha";
import * as Test_utils from "./test_utils.mjs";

let g = 7;

Expand All @@ -22,52 +23,11 @@ function v(__x) {
return g1(3, 4)(6, __x);
}

let suites_0 = [
"curry",
param => ({
TAG: "Eq",
_0: g,
_1: 7
})
];

let suites_1 = {
hd: [
"curry2",
param => ({
TAG: "Eq",
_0: 14,
_1: (v(1), v(1))
})
],
tl: {
hd: [
"curry3",
param => ({
TAG: "Eq",
_0: x,
_1: 14
})
],
tl: {
hd: [
"File \"ari_regress_test.res\", line 35, characters 5-12",
param => ({
TAG: "Eq",
_0: h.contents,
_1: 2
})
],
tl: /* [] */0
}
}
};

let suites = {
hd: suites_0,
tl: suites_1
};

Mt.from_pair_suites("Ari_regress_test", suites);
Mocha.describe("Ari_regress_test", () => {
Mocha.test("curry", () => Test_utils.eq("File \"ari_regress_test.res\", line 25, characters 7-14", g, 7));
Mocha.test("curry2", () => Test_utils.eq("File \"ari_regress_test.res\", line 30, characters 6-13", 14, (v(1), v(1))));
Mocha.test("curry3", () => Test_utils.eq("File \"ari_regress_test.res\", line 40, characters 7-14", x, 14));
Mocha.test("ref count", () => Test_utils.eq("File \"ari_regress_test.res\", line 44, characters 7-14", h.contents, 2));
});

/* Not a pure module */
45 changes: 26 additions & 19 deletions tests/tests/src/ari_regress_test.res
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
open Mocha
open Test_utils

let f = x => \"+"(x, ...)
let g = f(3)(4)

Expand All @@ -17,23 +20,27 @@ let x = gg(3, 5)(6)

let v = g1(3, 4)(6, _)

let suites = {
open Mt
list{
("curry", _ => Eq(g, 7)),
(
"curry2",
_ => Eq(
14,
{
ignore(v(1))
v(1)
},
),
),
("curry3", _ => Eq(x, 14)),
(__LOC__, _ => Eq(h.contents, 2)),
}
}
describe(__MODULE__, () => {
test("curry", () => {
eq(__LOC__, g, 7)
})

test("curry2", () => {
eq(
__LOC__,
14,
{
ignore(v(1))
v(1)
},
)
})

test("curry3", () => {
eq(__LOC__, x, 14)
})

Mt.from_pair_suites(__MODULE__, suites)
test("ref count", () => {
eq(__LOC__, h.contents, 2)
})
})
46 changes: 10 additions & 36 deletions tests/tests/src/arity_deopt.mjs
Original file line number Diff line number Diff line change
@@ -1,29 +1,7 @@
// Generated by ReScript, PLEASE EDIT WITH CARE

import * as Mt from "./mt.mjs";

let suites = {
contents: /* [] */0
};

let test_id = {
contents: 0
};

function eq(loc, x, y) {
test_id.contents = test_id.contents + 1 | 0;
suites.contents = {
hd: [
loc + (" id " + test_id.contents.toString()),
() => ({
TAG: "Eq",
_0: x,
_1: y
})
],
tl: suites.contents
};
}
import * as Mocha from "mocha";
import * as Test_utils from "./test_utils.mjs";

function f0(x, y, z) {
return (x + y | 0) + z | 0;
Expand All @@ -41,20 +19,16 @@ function f3(x) {
return (y, z) => (x + y | 0) + z | 0;
}

eq("File \"arity_deopt.res\", line 50, characters 5-12", 6, 6);

eq("File \"arity_deopt.res\", line 51, characters 5-12", 6, 6);

eq("File \"arity_deopt.res\", line 52, characters 5-12", 6, 6);

eq("File \"arity_deopt.res\", line 53, characters 5-12", 6, 6);

Mt.from_pair_suites("Arity_deopt", suites.contents);
Mocha.describe("Arity_deopt", () => {
Mocha.test("arity_deopt_tests", () => {
Test_utils.eq("File \"arity_deopt.res\", line 43, characters 7-14", 6, 6);
Test_utils.eq("File \"arity_deopt.res\", line 44, characters 7-14", 6, 6);
Test_utils.eq("File \"arity_deopt.res\", line 45, characters 7-14", 6, 6);
Test_utils.eq("File \"arity_deopt.res\", line 46, characters 7-14", 6, 6);
});
});

export {
suites,
test_id,
eq,
f0,
f1,
f2,
Expand Down
27 changes: 10 additions & 17 deletions tests/tests/src/arity_deopt.res
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
let suites: ref<Mt.pair_suites> = ref(list{})
let test_id = ref(0)
let eq = (loc, x, y) => {
incr(test_id)
suites :=
list{
(loc ++ (" id " ++ Js.Int.toString(test_id.contents)), _ => Mt.Eq(x, y)),
...suites.contents,
}
}
open Mocha
open Test_utils

/* let f = fun x y */

Expand Down Expand Up @@ -46,10 +38,11 @@ let f3 = x => {
(Ml_app) will not hold any more.
So the best is never shrink functons which could change arity
*/
let () = {
eq(__LOC__, 6, ...)(f0(1, 2, 3))
eq(__LOC__, 6, ...)(f1(1)(2, 3))
eq(__LOC__, 6, ...)(f2(1, 2)(3))
eq(__LOC__, 6, ...)(f3(1)(2, 3))
}
let () = Mt.from_pair_suites(__MODULE__, suites.contents)
describe(__MODULE__, () => {
test("arity_deopt_tests", () => {
eq(__LOC__, 6, f0(1, 2, 3))
eq(__LOC__, 6, f1(1)(2, 3))
eq(__LOC__, 6, f2(1, 2)(3))
eq(__LOC__, 6, f3(1)(2, 3))
})
})
Loading
Loading