123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869openCommonopenOUnit(*****************************************************************************)(* Unit tests *)(*****************************************************************************)letunittest="parsing_js">:::["regression files">::(fun()->letdir=Filename.concatConfig_pfff.path"/tests/js/parsing"inletfiles=Common2.glob(spf"%s/*.js"dir)@Common2.glob(spf"%s/jsx/*.js"dir)@Common2.glob(spf"%s/typescript/*.js"dir)@[]infiles|>List.iter(funfile->trylet_=Parse_js.parse_programfilein()withParse_info.Parsing_error_->assert_failure(spf"it should correctly parse %s"file)));"rejecting bad code">::(fun()->tryCommon.save_excursionFlag_parsing.show_parsing_errorfalse(fun()->let_=Parse_js.program_of_string"echo 1+"inassert_failure"it should have thrown a Parse_error exception")withParse_info.Parsing_error_->());(*
"the javascript AST mapper" >:: (fun () ->
let js_ex = "foo(42, 101);" in
Common2.with_tmp_file ~str:js_ex ~ext:".js" (fun file ->
let prog = Parse_js.parse_program file in
let map_visitor = M.mk_visitor { M.default_visitor with
M.kexpr = (fun (k, _) x ->
match x with
| L (Num (s, tok)) ->
let i = s_to_i s in
L (Num (i_to_s (i+1), Ast.fakeInfo()))
| _ -> k x
);
}
in
let transformed_ast = map_visitor (Program prog) in
let integers =
V.do_visit_with_ref (fun aref -> { V.default_visitor with
V.kexpr = (fun (k, _) x ->
match x with
| L (Num (s, tok)) ->
Common.push2 (s_to_i s) aref
| _ -> k x
);
}) transformed_ast in
assert_equal
~msg:"it should increment all the integers in the program"
[43; 102] integers;
)
);
*)]