Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commite1e3cf8

Browse files
authored
Migrate mocha tests from OCaml-styleMt to idiomatic ReScript/JS usage (#7861)
* Biome: ignore lib/js* Migrate mocha tests from OCaml-style `Mt` to idiomatic ReScript/JS usage* Update CONTRIBUTING.md* Add missing describe call
1 parentcfa4f7b commite1e3cf8

File tree

359 files changed

+14666
-25453
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

359 files changed

+14666
-25453
lines changed

‎CONTRIBUTING.md‎

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -227,14 +227,23 @@ Below we will discuss on how to write, build and run these test files.
227227
- 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:
228228

229229
```rescript
230-
let suites: Mt.pair_suites = list{
231-
("hey", _ => Eq(true, 3 > 2)),
232-
("hi", _ => Neq(2, 3)),
233-
("hello", _ => Approx(3.0, 3.0)),
234-
("throw", _ => ThrowAny(_ => raise(SomeException))),
235-
}
236-
237-
Mt.from_pair_suites(__MODULE__, suites)
230+
open Mocha
231+
open Test_utils
232+
233+
describe(__MODULE__, () => {
234+
test("hey", () => {
235+
ok(__LOC__, 3 > 2)
236+
})
237+
238+
test("hi", () => {
239+
eq(__LOC__, 2, 2)
240+
eq(__LOC__, 3, 3)
241+
})
242+
243+
test("throw", () => {
244+
throws(__LOC__, () => throw(SomeException))
245+
})
246+
})
238247
```
239248

240249
- Build the test files and run the tests:`node scripts/test.js -mocha`.

‎biome.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
"rewatch/**",
6666
"lib/es6/**",
6767
"lib/js/**",
68+
"lib/bs/**",
6869
"ninja/**",
6970
"playground/**",
7071
"*.bs.js",

‎tests/tests/src/abstract_type.resi‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,3 @@ type arrow_type = int => int
44

55
typepoly_type<'a>='a
66
typepoly_abstract_type<'a>
7-
openMt
Lines changed: 6 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Generated by ReScript, PLEASE EDIT WITH CARE
22

3-
import*asMtfrom"./mt.mjs";
3+
import*asMochafrom"mocha";
4+
import*asTest_utilsfrom"./test_utils.mjs";
45

56
functionf(b,x,_n){
67
while(true){
@@ -30,37 +31,13 @@ function or_f(b, x, _n) {
3031
};
3132
}
3233

33-
letsuites_0=[
34-
"and_tail",
35-
param=>({
36-
TAG:"Eq",
37-
_0:false,
38-
_1:f(true,1,0)
39-
})
40-
];
41-
42-
letsuites_1={
43-
hd:[
44-
"or_tail",
45-
param=>({
46-
TAG:"Eq",
47-
_0:false,
48-
_1:or_f(false,1,0)
49-
})
50-
],
51-
tl:/* [] */0
52-
};
53-
54-
letsuites={
55-
hd:suites_0,
56-
tl:suites_1
57-
};
58-
59-
Mt.from_pair_suites("And_or_tailcall_test",suites);
34+
Mocha.describe("And_or_tailcall_test",()=>{
35+
Mocha.test("and_tail",()=>Test_utils.eq("File \"and_or_tailcall_test.res\", line 21, characters 7-14",false,f(true,1,0)));
36+
Mocha.test("or_tail",()=>Test_utils.eq("File \"and_or_tailcall_test.res\", line 24, characters 7-14",false,or_f(false,1,0)));
37+
});
6038

6139
export{
6240
f,
6341
or_f,
64-
suites,
6542
}
6643
/* Not a pure module */

‎tests/tests/src/and_or_tailcall_test.res‎

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,15 @@ let rec or_f = (b, x, n) =>
1212
b||or_f(b,x,n+1)
1313
}
1414

15-
letsuites= {
16-
openMt
17-
list{
18-
/* becareful inlining will defeat the test purpose here */
19-
("and_tail",_=>Eq(false,f(true,1,0))),
20-
("or_tail",_=>Eq(false,or_f(false,1,0))),
21-
}
22-
}
15+
openMocha
16+
openTest_utils
2317

24-
Mt.from_pair_suites(__MODULE__,suites)
18+
describe(__MODULE__, ()=> {
19+
/* becareful inlining will defeat the test purpose here */
20+
test("and_tail", ()=> {
21+
eq(__LOC__,false,f(true,1,0))
22+
})
23+
test("or_tail", ()=> {
24+
eq(__LOC__,false,or_f(false,1,0))
25+
})
26+
})
Lines changed: 8 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Generated by ReScript, PLEASE EDIT WITH CARE
22

3-
import*asMtfrom"./mt.mjs";
3+
import*asMochafrom"mocha";
4+
import*asTest_utilsfrom"./test_utils.mjs";
45

56
letg=7;
67

@@ -22,52 +23,11 @@ function v(__x) {
2223
returng1(3,4)(6,__x);
2324
}
2425

25-
letsuites_0=[
26-
"curry",
27-
param=>({
28-
TAG:"Eq",
29-
_0:g,
30-
_1:7
31-
})
32-
];
33-
34-
letsuites_1={
35-
hd:[
36-
"curry2",
37-
param=>({
38-
TAG:"Eq",
39-
_0:14,
40-
_1:(v(1),v(1))
41-
})
42-
],
43-
tl:{
44-
hd:[
45-
"curry3",
46-
param=>({
47-
TAG:"Eq",
48-
_0:x,
49-
_1:14
50-
})
51-
],
52-
tl:{
53-
hd:[
54-
"File \"ari_regress_test.res\", line 35, characters 5-12",
55-
param=>({
56-
TAG:"Eq",
57-
_0:h.contents,
58-
_1:2
59-
})
60-
],
61-
tl:/* [] */0
62-
}
63-
}
64-
};
65-
66-
letsuites={
67-
hd:suites_0,
68-
tl:suites_1
69-
};
70-
71-
Mt.from_pair_suites("Ari_regress_test",suites);
26+
Mocha.describe("Ari_regress_test",()=>{
27+
Mocha.test("curry",()=>Test_utils.eq("File \"ari_regress_test.res\", line 25, characters 7-14",g,7));
28+
Mocha.test("curry2",()=>Test_utils.eq("File \"ari_regress_test.res\", line 30, characters 6-13",14,(v(1),v(1))));
29+
Mocha.test("curry3",()=>Test_utils.eq("File \"ari_regress_test.res\", line 40, characters 7-14",x,14));
30+
Mocha.test("ref count",()=>Test_utils.eq("File \"ari_regress_test.res\", line 44, characters 7-14",h.contents,2));
31+
});
7232

7333
/* Not a pure module */
Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
openMocha
2+
openTest_utils
3+
14
letf=x=> \"+"(x,...)
25
letg=f(3)(4)
36

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

1821
letv=g1(3,4)(6,_)
1922

20-
letsuites= {
21-
openMt
22-
list{
23-
("curry",_=>Eq(g,7)),
24-
(
25-
"curry2",
26-
_=>Eq(
27-
14,
28-
{
29-
ignore(v(1))
30-
v(1)
31-
},
32-
),
33-
),
34-
("curry3",_=>Eq(x,14)),
35-
(__LOC__,_=>Eq(h.contents,2)),
36-
}
37-
}
23+
describe(__MODULE__, ()=> {
24+
test("curry", ()=> {
25+
eq(__LOC__,g,7)
26+
})
27+
28+
test("curry2", ()=> {
29+
eq(
30+
__LOC__,
31+
14,
32+
{
33+
ignore(v(1))
34+
v(1)
35+
},
36+
)
37+
})
38+
39+
test("curry3", ()=> {
40+
eq(__LOC__,x,14)
41+
})
3842

39-
Mt.from_pair_suites(__MODULE__,suites)
43+
test("ref count", ()=> {
44+
eq(__LOC__,h.contents,2)
45+
})
46+
})

‎tests/tests/src/arity_deopt.mjs‎

Lines changed: 10 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,7 @@
11
// Generated by ReScript, PLEASE EDIT WITH CARE
22

3-
import*asMtfrom"./mt.mjs";
4-
5-
letsuites={
6-
contents:/* [] */0
7-
};
8-
9-
lettest_id={
10-
contents:0
11-
};
12-
13-
functioneq(loc,x,y){
14-
test_id.contents=test_id.contents+1|0;
15-
suites.contents={
16-
hd:[
17-
loc+(" id "+test_id.contents.toString()),
18-
()=>({
19-
TAG:"Eq",
20-
_0:x,
21-
_1:y
22-
})
23-
],
24-
tl:suites.contents
25-
};
26-
}
3+
import*asMochafrom"mocha";
4+
import*asTest_utilsfrom"./test_utils.mjs";
275

286
functionf0(x,y,z){
297
return(x+y|0)+z|0;
@@ -41,20 +19,16 @@ function f3(x) {
4119
return(y,z)=>(x+y|0)+z|0;
4220
}
4321

44-
eq("File \"arity_deopt.res\", line 50, characters 5-12",6,6);
45-
46-
eq("File \"arity_deopt.res\", line 51, characters 5-12",6,6);
47-
48-
eq("File \"arity_deopt.res\", line 52, characters 5-12",6,6);
49-
50-
eq("File \"arity_deopt.res\", line 53, characters 5-12",6,6);
51-
52-
Mt.from_pair_suites("Arity_deopt",suites.contents);
22+
Mocha.describe("Arity_deopt",()=>{
23+
Mocha.test("arity_deopt_tests",()=>{
24+
Test_utils.eq("File \"arity_deopt.res\", line 43, characters 7-14",6,6);
25+
Test_utils.eq("File \"arity_deopt.res\", line 44, characters 7-14",6,6);
26+
Test_utils.eq("File \"arity_deopt.res\", line 45, characters 7-14",6,6);
27+
Test_utils.eq("File \"arity_deopt.res\", line 46, characters 7-14",6,6);
28+
});
29+
});
5330

5431
export{
55-
suites,
56-
test_id,
57-
eq,
5832
f0,
5933
f1,
6034
f2,

‎tests/tests/src/arity_deopt.res‎

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,5 @@
1-
letsuites:ref<Mt.pair_suites>=ref(list{})
2-
lettest_id=ref(0)
3-
leteq= (loc,x,y)=> {
4-
incr(test_id)
5-
suites:=
6-
list{
7-
(loc++ (" id "++Js.Int.toString(test_id.contents)),_=>Mt.Eq(x,y)),
8-
...suites.contents,
9-
}
10-
}
1+
openMocha
2+
openTest_utils
113

124
/* let f = fun x y */
135

@@ -46,10 +38,11 @@ let f3 = x => {
4638
(Ml_app) will not hold any more.
4739
So the best is never shrink functons which could change arity
4840
*/
49-
let ()= {
50-
eq(__LOC__,6,...)(f0(1,2,3))
51-
eq(__LOC__,6,...)(f1(1)(2,3))
52-
eq(__LOC__,6,...)(f2(1,2)(3))
53-
eq(__LOC__,6,...)(f3(1)(2,3))
54-
}
55-
let ()=Mt.from_pair_suites(__MODULE__,suites.contents)
41+
describe(__MODULE__, ()=> {
42+
test("arity_deopt_tests", ()=> {
43+
eq(__LOC__,6,f0(1,2,3))
44+
eq(__LOC__,6,f1(1)(2,3))
45+
eq(__LOC__,6,f2(1,2)(3))
46+
eq(__LOC__,6,f3(1)(2,3))
47+
})
48+
})

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp