test: update parser test

This commit is contained in:
Simon Cruanes 2022-10-06 22:04:32 -04:00
parent 8866f032fe
commit 6e423e3f75
No known key found for this signature in database
GPG key ID: EBFFF6F283F3A2B4
3 changed files with 35 additions and 11 deletions

View file

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

View file

@ -1,4 +1,13 @@
t1: f (g x) y t1: f (g x) y
loc(t1): at line 0, column 0 - at line 0, column 9 loc(t1): at line 1, column 0 - at line 1, column 9
t2: let x := 1 in (f (f x 2)) t2: let x := 1 in f (f x 2)
loc(t2): at line 0, column 0 - at line 0, column 21 loc(t2): at line 1, column 0 - at line 1, column 22
t3: let l := map f (list 1 2 3) in let l2 := rev l in = (rev l2) l
loc(t3): at line 1, column 1 - at line 1, column 61
t4: let assm := ==> (is_foo p) (= (filter p l) nil) in true
loc(t4): at line 1, column 0 - at line 1, column 51
t5: let
f := lam (x : int) (y : int) (z : bool). (= (+ x y) z) and
g := lam x. (f (f x)) in
is_g g
loc(t5): at line 1, column 0 - at line 1, column 84

View file

@ -1,20 +1,24 @@
module P = Parse_term module P = Parse_util
module A = Ast_term module A = Ast_term
(* (*
let () = Printexc.record_backtrace true let () = Printexc.record_backtrace true
*) *)
let () = Printexc.record_backtrace true
let () = let () =
Printexc.register_printer (function Printexc.register_printer (function
| Parser_comb.ParseError e -> Some (Parser_comb.Error.to_string e) | P.Exn_parse_error e -> Some (P.Error.to_string e)
| _ -> None) | _ -> None)
let test_str what s = let test_str what s =
let t = P.of_string_exn s in let t = P.term_of_string s in
match t with
| Ok t ->
Fmt.printf "%s: %a@." what A.pp_term t; Fmt.printf "%s: %a@." what A.pp_term t;
Fmt.printf "loc(%s): %a@." what A.pp_loc (A.loc t) Fmt.printf "loc(%s): %a@." what Loc.pp (A.loc t)
| Error err ->
Fmt.printf "FAIL:@ error while parsing %S:@ %a@." what P.Error.pp err
let () = test_str "t1" "f (g x) y" let () = test_str "t1" "f (g x) y"
let () = test_str "t2" "let x:= 1 in f (f x 2)" let () = test_str "t2" "let x:= 1 in f (f x 2)"
@ -23,5 +27,15 @@ let () =
test_str "t3" test_str "t3"
{| {|
let l := map f (list 1 2 3) in let l := map f (list 1 2 3) in
let l2 := rev l in eq (rev l2) l let l2 := rev l in rev l2 = l
|}
let () =
test_str "t4" {|let assm := is_foo p ==> (filter p l = nil) in true
|}
let () =
test_str "t5"
{|let f := fn (x y : int) (z:bool). ( x+ y) = z
and g := fn x. f (f x) in is_g g
|} |}