Test nested callbacks, patterns, evaluation count, and exceptions
This commit is contained in:
1 file changed
+22
@@ -0,0 +1,22 @@
|
||||
let each xs callback = List.map callback xs
|
||||
|
||||
let () =
|
||||
assert ((let%continue x = each [1; 2; 3] in x * 5) = [5; 10; 15]);
|
||||
assert ((let%cps x = each [1; 2] in x + 1) = [2; 3]);
|
||||
assert ((let%continue (x, y) = each [2, 3] in x + y) = [5]);
|
||||
assert ((let%continue x = each [1; 2] in
|
||||
let%continue y = each [3; 4] in x + y) = [[4; 5]; [5; 6]]);
|
||||
let active = ref false in
|
||||
let scope callback = active := true; callback (); active := false in
|
||||
(let%continue () = scope in assert !active);
|
||||
assert (not !active);
|
||||
let calls = ref 0 in
|
||||
let producer () = incr calls; each [1; 2] in
|
||||
assert ((let%continue x = producer () in x) = [1; 2]);
|
||||
assert (!calls = 1);
|
||||
assert ((let%continue _ = each [] in failwith "unreachable") = []);
|
||||
assert ((let%continue x = (let%continue f = each [each [7]] in f) |> List.hd
|
||||
in x + 1) = [8]);
|
||||
(try (let%continue () = scope in failwith "callback"); assert false
|
||||
with Failure message -> assert (message = "callback"));
|
||||
print_endline "continuum_ppx: behavior checks passed"
|
||||
Reference in new issue
Block a user