123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217openExpect_test_commonopenBaseopenPpxlibopenAst_builder.Defaultletlift_location~loc({filename;line_number;line_start;start_pos;end_pos}:File.Location.t)=Merlin_helpers.hide_expression[%expr({filename=Expect_test_common.File.Name.of_string[%eestring~loc(File.Name.to_stringfilename)];line_number=[%eeint~locline_number];line_start=[%eeint~locline_start];start_pos=[%eeint~locstart_pos];end_pos=[%eeint~locend_pos]}:Expect_test_common.File.Location.t)];;leteoption~locx=matchxwith|None->pexp_construct~loc(Located.mk~loc(lident"None"))None|Somee->pexp_construct~loc(Located.mk~loc(lident"Some"))(Somee);;letestring_option~locx=eoption~loc(Option.mapx~f:(estring~loc))letlift_expectation~loc({tag;body;extid_location;body_location}:_Expectation.t)=Merlin_helpers.hide_expression[%expr({tag=[%eestring_option~loctag];body=[%ematchbodywith|Exactstring->[%exprExact[%eestring~locstring]]|Output->[%exprOutput]|Prettystring->[%exprPretty[%eestring~locstring]]|Unreachable->[%exprUnreachable]];extid_location=[%elift_location~locextid_location];body_location=[%elift_location~locbody_location]}:stringExpect_test_common.Expectation.t)];;(* Grab a list of all the output expressions *)letcollect_expectations=objectinherit[(Location.t*Expectation.Raw.t)list]Ast_traverse.foldassupermethod!expressionexpracc=matchExpect_extension.match_expectationexprwith|None->super#expressionexpracc|Someext->assert_no_attributesexpr.pexp_attributes;(expr.pexp_loc,ext)::accend;;letreplace_expects=objectinheritAst_traverse.mapassupermethod!expression({pexp_attributes;pexp_loc=loc;_}asexpr)=matchExpect_extension.match_expectationexprwith|None->super#expressionexpr|Someext->letf_var=matchext.bodywith|Exact_|Pretty_|Unreachable->"Expect_test_collector.save_output"|Output->"Expect_test_collector.save_and_return_output"inletexpr=[%expr[%eevar~locf_var][%elift_location~locext.extid_location]]in{exprwithpexp_attributes}end;;letfile_digest=letcache=Hashtbl.create(moduleString)~size:32infunfname->Hashtbl.find_or_addcachefname~default:(fun()->Stdlib.Digest.filefname|>Stdlib.Digest.to_hex);;letrewrite_test_body~descr~tags~uncaught_exn~called_by_merlinpstr_locbody=letloc=pstr_locinletexpectations=List.map(collect_expectations#expressionbody[])~f:(fun(loc,expect_extension)->lift_expectation~locexpect_extension)|>elist~locinletuncaught_exn=Option.mapuncaught_exn~f:(fun(loc,expectation)->lift_expectation~locexpectation)|>eoption~locinletbody=replace_expects#expressionbodyinletabsolute_filename=Ppx_here_expander.expand_filenamepstr_loc.loc_start.pos_fnameinlethash=ifcalled_by_merlinthenStdlib.Digest.string""elsefile_digestloc.loc_start.pos_fnamein[%exprletmoduleExpect_test_collector=Expect_test_collector.Make(Expect_test_config)inExpect_test_collector.run~file_digest:(Expect_test_common.File.Digest.of_string[%eestring~lochash])~location:[%elift_location~loc(Ppx_expect_payload.transl_locpstr_loc)]~absolute_filename:[%eestring~locabsolute_filename]~description:[%eestring_option~locdescr]~tags:[%eelist~loc(List.maptags~f:(estring~loc))]~expectations:[%eexpectations]~uncaught_exn_expectation:[%euncaught_exn]~inline_test_config:(moduleInline_test_config)(fun()->[%ebody])];;moduleP=structopenAst_patternletuncaught_exn=Attribute.declare_with_name_loc"@expect.uncaught_exn"Attribute.Context.value_binding(map1'(Ppx_expect_payload.pattern())~f:(funlocx->loc,x))(fun~name_loc(loc,x)->loc,Ppx_expect_payload.makex~kind:Normal~extension_id_loc:name_loc);;letopt_name()=map(pstring__)~f:(funfx->f(Somex))|||mapppat_any~f:(funf->fNone);;letpattern()=pstr(pstr_valuenonrecursive(Attribute.patternuncaught_exn(value_binding~pat:(map(Attribute.patternPpx_inline_test.tags(opt_name()))~f:(funfattributesname_opt->f~name:name_opt~tags:(matchattributeswith|None->[]|Somex->x)))~expr:__)^::nil)^::nil);;end(* Set to [true] when we see a [%expect_test] extension *)moduleHas_tests=Driver.Create_file_property(structletname="ppx_expect.has_tests"end)(Bool)letexpect_test=Extension.V3.declare_inline"expect_test"Structure_item(P.pattern())(fun~ctxtuncaught_exn~name~tagscode->letloc=Ppxlib.Expansion_context.Extension.extension_point_locctxtinletloc={locwithloc_ghost=true}inletcalled_by_merlin=String.equal(Ppxlib.Expansion_context.Extension.tool_namectxt)"merlin"inHas_tests.settrue;Ppx_inline_test.validate_extension_point_exn~name_of_ppx_rewriter:"ppx_expect"~loc~tags;rewrite_test_body~descr:name~tags~uncaught_exn~called_by_merlinloccode|>Ppx_inline_test.maybe_droploc);;let()=Driver.register_transformation"expect_test"~rules:[Context_free.Rule.extensionexpect_test]~enclose_impl:(funwhole_loc->matchwhole_loc,Ppx_inline_test_libname.get()with|None,_|_,None->[],[]|Someloc,Some_->letloc={locwithloc_ghost=true}inletmaybe_drop=Ppx_inline_test.maybe_dropinletabsolute_filename=Ppx_here_expander.expand_filenameloc.loc_start.pos_fnameinletheader=letloc={locwithloc_end=loc.loc_start}inmaybe_droploc[%exprExpect_test_collector.Current_file.set~absolute_filename:[%eestring~locabsolute_filename]]andfooter=letloc={locwithloc_start=loc.loc_end}inmaybe_droploc[%exprExpect_test_collector.Current_file.unset()]inheader,footer);;