Skip to content

Commit 47783c7

Browse files
committed
Tests: Js.eval_string and Js.js_expr
1 parent 93f3c4f commit 47783c7

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

lib/tests/dune.inc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,16 @@
2929
(preprocess
3030
(pps ppx_js_internal ppx_expect)))
3131

32+
(library
33+
;; lib/tests/test_eval.ml
34+
(name test_eval_75)
35+
(enabled_if true)
36+
(modules test_eval)
37+
(libraries js_of_ocaml unix)
38+
(inline_tests (modes js wasm))
39+
(preprocess
40+
(pps ppx_js_internal ppx_expect)))
41+
3242
(library
3343
;; lib/tests/test_fun_call.ml
3444
(name test_fun_call_75)

lib/tests/test_eval.ml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
open Js_of_ocaml
2+
3+
let check d = if d == 1 then print_endline "PASSED" else print_endline "FAILED"
4+
5+
let%expect_test "eval_string" =
6+
check (Js.Unsafe.eval_string "{x:1}");
7+
(try
8+
let _ = Js.Unsafe.eval_string "function f() {return 1} ()" in
9+
print_endline "FAILED"
10+
with _ -> print_endline "PASSED");
11+
[%expect {|
12+
PASSED
13+
PASSED
14+
|}]
15+
16+
let%expect_test "js_expr" =
17+
check Js.Unsafe.(get (js_expr "{x:1}") "x");
18+
check (Js.Unsafe.js_expr "function f() {return 1} ()");
19+
[%expect {|
20+
PASSED
21+
PASSED
22+
|}]

0 commit comments

Comments
 (0)