123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132open!Coreopen!ImportopenBonsai.Let_syntaxopenBonsai.For_openmodulePrivate=Bonsai.Private(* Each test sets this ref to the location at which the test began, so that
test output can be made resilient to adding or remove lines above the test. *)lettest_location_reference_point=ref[%here]lettest_starthere=test_location_reference_point:=herelettest_lintcomputation=letcomputation=Private.reveal_computationcomputationinList.iter(Private.Linter.list_warningscomputation)~f:(funwarning->print_endline(Private.Linter.Warning.to_string(Private.Linter.Warning.relative_to!test_location_reference_pointwarning)));;letconstant_foldcomputation=computation|>Private.reveal_computation|>Private.Constant_fold.constant_fold|>Private.conceal_computation;;let%expect_test"map2_unfolded_constant_warnings"=test_start[%here];letc=let%arra=Value.return5andb=Value.return3ina+bintest_lintc;[%expect{|
lib/bonsai/test/test_linter.ml:2:4: unfolded constant |}];;let%expect_test"map2_optimized_gets_no_warnings"=test_start[%here];letc=let%arra=Value.return5andb=Value.return3ina+bintest_lint(constant_foldc);[%expect{| |}];;let%expect_test"map2_two_unfolded_constants_warnings"=test_start[%here];letsum=let%mapa=Value.return5andb=Value.return3ina+binletdoubled=let%arra=sumandb=sumina+bintest_lintdoubled;[%expect{| lib/bonsai/test/test_linter.ml:7:4: unfolded constant |}];;let%expect_test"cutoff_unfolded_constants_warnings"=test_start[%here];letcutoff=return(Bonsai.Value.cutoff~equal:(=)(Value.return3))intest_lintcutoff;[%expect{| _none_:0:0: unfolded constant |}];;let%expect_test"cutoff_optimized_gets_no_warnings"=test_start[%here];letcutoff=return(Value.cutoff~equal:(=)(Value.return3))intest_lint(constant_foldcutoff);[%expect{| |}];;let%expect_test"sm1_with_const_input_gets_warning"=test_start[%here];letstate_machine=Bonsai.state_machine1(moduleInt)(moduleInt)~default_model:0~apply_action:(fun~inject:_~schedule_event:____->3)(Value.return5)intest_lintstate_machine;[%expect{| _none_:0:0: state_machine1 can be optimized to a state_machine0 |}];;let%expect_test"sm1_optimized_gets_no_warnings"=test_start[%here];letstate_machine=Bonsai.state_machine1(moduleInt)(moduleInt)~default_model:0~apply_action:(fun~inject:_~schedule_event:____->3)(Value.return5)intest_lint(constant_foldstate_machine);[%expect{| |}];;let%expect_test"map2_with_unfolded_constants_and_sm1_with_const_input_both_warned"=test_start[%here];letc=let%subvalue,_inject=Bonsai.state_machine1(moduleInt)(moduleInt)~default_model:0~apply_action:(fun~inject:_~schedule_event:____->3)(Value.return5)inlet%arrvalue=valueandsum=let%mapa=Value.return5andb=Value.return3ina+binvalue+sumintest_lintc;[%expect{|
lib/bonsai/test/test_linter.ml:2:4: state_machine1 can be optimized to a state_machine0
lib/bonsai/test/test_linter.ml:10:4: unfolded constant |}];;