Skip to content

Commit 5cdd15e

Browse files
committed
more tests
1 parent ebf5434 commit 5cdd15e

File tree

9 files changed

+77
-7
lines changed

9 files changed

+77
-7
lines changed

jscomp/runtime/js.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ type + 'a null_undefined = 'a nullable
6262
this type is the same as {!Js.Null_undefined.t}*)
6363

6464
external toOpt : 'a nullable -> 'a option = "#null_undefined_to_opt"
65-
external nullable : 'a nullable -> bool = "#is_nil_undef"
65+
external test : 'a nullable -> bool = "#is_nil_undef"
6666

6767
type boolean
6868
(** The JS boolean type, can be [Js.true_] or [Js.false_] *)

jscomp/runtime/js.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ type + 'a nullable
7474
type + 'a null_undefined = 'a nullable
7575

7676
external toOpt : 'a nullable -> 'a option = "#null_undefined_to_opt"
77-
external nullable : 'a nullable -> bool = "#is_nil_undef"
77+
external test : 'a nullable -> bool = "#is_nil_undef"
7878

7979
type boolean
8080
(** The value could be either {!Js.true_} or {!Js.false_}.

jscomp/test/.depend

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,7 @@ js_math_test.cmj : mt.cmj ../runtime/js.cmj
310310
js_null_test.cmj : mt.cmj ../runtime/js_null.cmj
311311
js_null_undefined_test.cmj : mt.cmj ../others/js_null_undefined.cmj \
312312
../runtime/js.cmj
313+
js_nullable_test.cmj : mt.cmj ../runtime/js.cmj
313314
js_obj_test.cmj : mt.cmj ../others/js_obj.cmj ../stdlib/array.cmj
314315
js_option_test.cmj : mt.cmj ../runtime/js.cmj
315316
js_promise_basic_test.cmj : ../stdlib/obj.cmj mt.cmj ../stdlib/list.cmj \

jscomp/test/Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,8 @@ OTHERS := literals a test_ari test_export2 test_internalOO test_obj_simple_ffi t
179179
gpr_1817_test\
180180
gpr_1822_test\
181181
bs_unwrap_test\
182-
dollar_escape_test
182+
dollar_escape_test\
183+
js_nullable_test
183184

184185
# bs_uncurry_test
185186
# needs Lam to get rid of Uncurry arity first

jscomp/test/js_null_undefined_test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ var suites_001 = /* :: */[
9292
(function () {
9393
return /* Eq */Block.__(0, [
9494
/* false */0,
95-
+(/* () */0 == null)
95+
/* false */0
9696
]);
9797
})
9898
],
@@ -249,7 +249,7 @@ var suites_001 = /* :: */[
249249
/* tuple */[
250250
"File \"js_null_undefined_test.ml\", line 42, characters 2-9",
251251
(function () {
252-
return /* Ok */Block.__(4, [1 - +(3 == null)]);
252+
return /* Ok */Block.__(4, [/* true */1]);
253253
})
254254
],
255255
/* [] */0

jscomp/test/js_null_undefined_test.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ let suites = Mt.[
4242
__LOC__, (fun _ ->
4343
Ok(
4444
let null =3 in
45-
not (Js.nullable (Js.Nullable.return null ))
45+
not (Js.test (Js.Nullable.return null ))
4646
)
4747
)
4848
]

jscomp/test/js_nullable_test.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
'use strict';
2+
3+
var Mt = require("./mt.js");
4+
var Block = require("../../lib/js/block.js");
5+
6+
var suites = [/* [] */0];
7+
8+
var test_id = [0];
9+
10+
function eq(loc, x, y) {
11+
test_id[0] = test_id[0] + 1 | 0;
12+
suites[0] = /* :: */[
13+
/* tuple */[
14+
loc + (" id " + test_id[0]),
15+
(function () {
16+
return /* Eq */Block.__(0, [
17+
x,
18+
y
19+
]);
20+
})
21+
],
22+
suites[0]
23+
];
24+
return /* () */0;
25+
}
26+
27+
function f(x, y) {
28+
console.log("no inline");
29+
return x + y | 0;
30+
}
31+
32+
eq("File \"js_nullable_test.ml\", line 13, characters 7-14", /* false */0, /* false */0);
33+
34+
eq("File \"js_nullable_test.ml\", line 15, characters 7-14", +(f(1, 2) == null), /* false */0);
35+
36+
eq("File \"js_nullable_test.ml\", line 17, characters 6-13", +((null) == null), /* true */1);
37+
38+
eq("File \"js_nullable_test.ml\", line 21, characters 3-10", /* false */0, /* false */0);
39+
40+
Mt.from_pair_suites("js_nullable_test.ml", suites[0]);
41+
42+
exports.suites = suites;
43+
exports.test_id = test_id;
44+
exports.eq = eq;
45+
exports.f = f;
46+
/* Not a pure module */

jscomp/test/js_nullable_test.ml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
let suites : Mt.pair_suites ref = ref []
2+
let test_id = ref 0
3+
let eq loc x y =
4+
incr test_id ;
5+
suites :=
6+
(loc ^" id " ^ (string_of_int !test_id), (fun _ -> Mt.Eq(x,y))) :: !suites
7+
8+
9+
let f x y =
10+
Js.log "no inline";
11+
Js.Nullable.return (x + y)
12+
13+
;; eq __LOC__ (Js.test (Js.Nullable.return 3 )) false
14+
15+
;; eq __LOC__ (Js.test ((f 1 2) )) false
16+
17+
;; eq __LOC__ (Js.test [%raw "null"]) true
18+
19+
;; let null2 = Js.Nullable.return 3 in
20+
let null = null2 in
21+
eq __LOC__ (Js.test null) false
22+
;; Mt.from_pair_suites __FILE__ !suites

jscomp/test/test_zero_nullable.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ function f10$2(x) {
262262
return +(x == null);
263263
}
264264

265-
var f11$2 = +(3 == null);
265+
var f11$2 = /* false */0;
266266

267267
var Test_null_def = /* module */[
268268
/* f1 */f1$2,

0 commit comments

Comments
 (0)