test: basic test for parser

This commit is contained in:
Simon Cruanes 2022-10-05 23:02:42 -04:00
parent 1c2c9deefd
commit ea755e5bc6
No known key found for this signature in database
GPG key ID: EBFFF6F283F3A2B4
3 changed files with 26 additions and 0 deletions

4
unittest/parser/dune Normal file
View file

@ -0,0 +1,4 @@
(tests
(names p1)
(flags :standard -open Sidekick_util -open Sidekick_parser)
(libraries sidekick.util sidekick.parser))

20
unittest/parser/p1.ml Normal file
View file

@ -0,0 +1,20 @@
module P = Parse_term
module A = Ast_term
(*
let () = Printexc.record_backtrace true
*)
let () =
Printexc.register_printer (function
| Parser_comb.ParseError e -> Some (Parser_comb.Error.to_string e)
| _ -> None)
let test_str what s =
let t = P.of_string_exn s in
Fmt.printf "%s: %a@." what A.pp_term t;
Fmt.printf "loc(%s): %a@." what A.pp_loc (A.loc t)
let () = test_str "t1" "f (g x) y"
let () = test_str "t2" "let x:= 1 in f (f x 2)"

View file

@ -0,0 +1,2 @@