Skip to content

Commit

Permalink
✅ Add same/different child tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Zeta611 committed Jul 9, 2024
1 parent a8c0e14 commit bf12cdf
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 3 deletions.
14 changes: 11 additions & 3 deletions samples/simple.ml
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
let C x =
stt s, setS = if --42 = +42 then +0+42*1 else 42 in
eff (setS (fun s -> -43));
stt s, setS = 42 in
eff (setS (fun s -> 0));
view [()]
;;
view [C ()]
let D x =
stt s, setS = true in
eff (setS (fun s -> false));
if s then
view [C ()]
else
view [C (), C ()]
;;
view [D ()]
48 changes: 48 additions & 0 deletions test/test_react_trace.ml
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,52 @@ view [D ()]
let { Interp.steps; _ } = Interp.run ~fuel prog in
Alcotest.(check' int) ~msg:"step two times" ~expected:2 ~actual:steps

let state_persists_in_child () =
let prog =
parse_prog
{|
let C x =
stt s, setS = 42 in
eff (setS (fun s -> 0));
view [()]
;;
let D x =
stt s, setS = true in
eff (setS (fun s -> false));
if s then
view [C ()]
else
view [C ()]
;;
view [D ()]
|}
in
let { Interp.steps; _ } = Interp.run ~fuel prog in
Alcotest.(check' int) ~msg:"step two times" ~expected:2 ~actual:steps

let new_child_steps_again () =
let prog =
parse_prog
{|
let C x =
stt s, setS = 42 in
eff (setS (fun s -> 0));
view [()]
;;
let D x =
stt s, setS = true in
eff (setS (fun s -> false));
if s then
view [C ()]
else
view [C (), C ()]
;;
view [D ()]
|}
in
let { Interp.steps; _ } = Interp.run ~fuel prog in
Alcotest.(check' int) ~msg:"step three times" ~expected:3 ~actual:steps

let () =
let open Alcotest in
run "Interpreter"
Expand Down Expand Up @@ -507,5 +553,7 @@ let () =
set_in_effect_twice_step_one_time;
test_case "Set in removed child should step two times" `Quick
set_in_removed_child_step_two_times;
test_case "Same child gets persisted" `Quick state_persists_in_child;
test_case "New child steps again" `Quick new_child_steps_again;
] );
]

0 comments on commit bf12cdf

Please sign in to comment.