Skip to content

Commit d9dc1c0

Browse files
Hongbo Zhangbobzhang
authored andcommitted
add a test case
1 parent f71b3d7 commit d9dc1c0

File tree

5 files changed

+108
-1
lines changed

5 files changed

+108
-1
lines changed

jscomp/test/.depend

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ a_string_test.cmo : mt.cmo ../stdlib/list.cmi ext_string.cmo
2626
a_string_test.cmx : mt.cmx ../stdlib/list.cmx ext_string.cmx
2727
abstract_type.cmo : abstract_type.cmi
2828
abstract_type.cmx : abstract_type.cmi
29+
and_or_tailcall_test.cmo : mt.cmo
30+
and_or_tailcall_test.cmx : mt.cmx
2931
ari_regress_test.cmo : mt.cmo ari_regress_test.cmi
3032
ari_regress_test.cmx : mt.cmx ari_regress_test.cmi
3133
arith_lexer.cmo : ../stdlib/lexing.cmi arith_syntax.cmo arith_parser.cmo
@@ -390,6 +392,8 @@ a_string_test.cmo : mt.cmo ../stdlib/list.cmi ext_string.cmo
390392
a_string_test.cmj : mt.cmj ../stdlib/list.cmj ext_string.cmj
391393
abstract_type.cmo : abstract_type.cmi
392394
abstract_type.cmj : abstract_type.cmi
395+
and_or_tailcall_test.cmo : mt.cmo
396+
and_or_tailcall_test.cmj : mt.cmj
393397
ari_regress_test.cmo : mt.cmo ari_regress_test.cmi
394398
ari_regress_test.cmj : mt.cmj ari_regress_test.cmi
395399
arith_lexer.cmo : ../stdlib/lexing.cmi arith_syntax.cmo arith_parser.cmo

jscomp/test/and_or_tailcall_test.d.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export var f: (b : any, x : any, n : any) => any ;
2+
export var or_f: (b : any, x : any, n : any) => any ;
3+
export var suites: any ;
4+

jscomp/test/and_or_tailcall_test.js

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
// Generated CODE, PLEASE EDIT WITH CARE
2+
'use strict';
3+
4+
var Mt = require("./mt");
5+
6+
function f(b, _, _n) {
7+
while(true) {
8+
var n = _n;
9+
if (n > 100000) {
10+
return /* false */0;
11+
}
12+
else if (b) {
13+
_n = n + 1;
14+
continue ;
15+
16+
}
17+
else {
18+
return /* false */0;
19+
}
20+
};
21+
}
22+
23+
function or_f(b, _, _n) {
24+
while(true) {
25+
var n = _n;
26+
if (n > 100000) {
27+
return /* false */0;
28+
}
29+
else if (b) {
30+
return /* true */1;
31+
}
32+
else {
33+
_n = n + 1;
34+
continue ;
35+
36+
}
37+
};
38+
}
39+
40+
var suites_001 = [
41+
/* tuple */0,
42+
"and_tail",
43+
function () {
44+
return [
45+
/* Eq */0,
46+
/* false */0,
47+
f(/* true */1, 1, 0)
48+
];
49+
}
50+
];
51+
52+
var suites_002 = [
53+
/* :: */0,
54+
[
55+
/* tuple */0,
56+
"or_tail",
57+
function () {
58+
return [
59+
/* Eq */0,
60+
/* false */0,
61+
or_f(/* false */0, 1, 0)
62+
];
63+
}
64+
],
65+
/* [] */0
66+
];
67+
68+
var suites = [
69+
/* :: */0,
70+
suites_001,
71+
suites_002
72+
];
73+
74+
Mt.from_pair_suites("and_or_tailcall_test.ml", suites);
75+
76+
exports.f = f;
77+
exports.or_f = or_f;
78+
exports.suites = suites;
79+
/* Not a pure module */

jscomp/test/and_or_tailcall_test.ml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
let rec f b x n =
2+
if n > 100000 then false
3+
else b && f b x (n + 1)
4+
5+
6+
let rec or_f b x n =
7+
if n > 100000 then false
8+
else b || or_f b x (n + 1)
9+
10+
11+
12+
let suites = Mt.[
13+
(* becareful inlining will defeat the test purpose here *)
14+
"and_tail", (fun _ -> Eq(false, f true 1 0 ));
15+
"or_tail", (fun _ -> Eq(false, or_f false 1 0 ));
16+
]
17+
18+
;; Mt.from_pair_suites __FILE__ suites

jscomp/test/test.mllib

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,4 +159,6 @@ regression_print
159159
global_exception_regression_test
160160
printf_test
161161
format_regression
162-
loop_regression_test
162+
loop_regression_test
163+
and_or_tailcall_test
164+

0 commit comments

Comments
 (0)