123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177open!Coreopen!Bonsaiopen!ImportmoduleResult_spec=structmoduletypeS=sigtypettypeincomingvalview:t->stringvalincoming:t->incoming->unitEffect.tendtype('result,'incoming)t=(moduleSwithtypet='resultandtypeincoming='incoming)moduleNo_incoming=structtypeincoming=Nothing.tletincoming_tincoming=Nothing.unreachable_codeincomingendmoduletypeSexpable=sigtypet[@@derivingsexp_of]endmoduletypeStringable=sigtypetvalto_string:t->stringendletinvisible(typea):(a,Nothing.t)t=(modulestructtypet=aincludeNo_incomingletview_=""end);;letsexp(typea)(moduleS:Sexpablewithtypet=a)=(modulestructtypet=aincludeNo_incomingletviews=s|>S.sexp_of_t|>Sexp.to_string_humend:Swithtypet=aandtypeincoming=Nothing.t);;letstring(typea)(moduleS:Stringablewithtypet=a)=(modulestructtypet=aincludeNo_incomingletviews=s|>S.to_stringend:Swithtypet=aandtypeincoming=Nothing.t);;endmoduleHandle=structtype('result,'incoming)t=(unit,'result*string*('incoming->unitEffect.t))Driver.tletcreate(typeresultincoming)(result_spec:(result,incoming)Result_spec.t)?(clock=Incr.Clock.create~start:Time_ns.epoch())computation=let(moduleR)=result_specinletcomponent(_:unitValue.t)=letopenBonsai.Let_syntaxinlet%subresult=computationinreturn(let%mapresult=resultinresult,R.viewresult,R.incomingresult)inDriver.create~initial_input:()~clockcomponent;;letresulthandle=Driver.flushhandle;letresult,_,_=Driver.resulthandleinresult;;letclock=Driver.clockletadvance_clock_byt=Incr.Clock.advance_clock_by(Driver.clockt)letdo_actionshandleactions=let_,_,inject_action=Driver.resulthandleinletevent=actions|>List.map~f:inject_action|>Effect.sequenceinDriver.schedule_eventhandleevent;;letdisable_bonsai_path_censoring=Driver.disable_bonsai_path_censoringletpath_regex=Re.Str.regexp"bonsai_path\\(_[a-z]*\\)*"letmaybe_censor_bonsai_pathhandlestring=ifDriver.should_censor_bonsai_pathhandlethenRe.Str.global_replacepath_regex"bonsai_path_replaced_in_test"stringelsestring;;letdisable_bonsai_hash_censoring=Driver.disable_bonsai_hash_censoringlethash_regex=Re.Str.regexp"_hash_[a-f0-9]+"letmaybe_censor_bonsai_hashhandlestring=ifDriver.should_censor_bonsai_hashhandlethenRe.Str.global_replacehash_regex"_hash_replaced_in_test"stringelsestring;;letrecompute_viewhandle=Driver.flushhandle;let_,view,_=Driver.resulthandleinlet(_:string)=maybe_censor_bonsai_pathhandleviewinDriver.trigger_lifecycleshandle;;letrecompute_view_until_stable?(max_computes=100)handle=with_return(fun{return}->for_=1tomax_computesdorecompute_viewhandle;ifnot(Driver.has_after_display_eventshandle)thenreturn()done;failwithf"view not stable after %d recomputations"max_computes());;letgeneric_showhandle~before~f=letbefore=beforehandleinDriver.flushhandle;let_,view,_=Driver.resulthandleinletview=view|>maybe_censor_bonsai_pathhandle|>maybe_censor_bonsai_hashhandleinDriver.store_viewhandleview;fbeforeview;Driver.trigger_lifecycleshandle;;letshowhandle=generic_showhandle~before:(Fn.const())~f:(fun()view->print_endlineview);;letshow_diff?(location_style=Patdiff_kernel.Format.Location_style.None)handle=generic_showhandle~before:Driver.last_view~f:(Expect_test_patdiff.print_patdiff~location_style);;letstore_viewhandle=generic_showhandle~before:(Fn.const())~f:(fun()_->())letshow_modelhandle=Driver.flushhandle;Driver.sexp_of_modelhandle|>print_s;;letflushhandle=Driver.flushhandleletresult_incrhandle=let%pattern_bind.Incrresult,_view,_inject=Driver.result_incrhandleinresult;;letapply_action_incr=Driver.apply_action_incrletlifecycle_incr=Driver.lifecycle_incrend