From ea755e5bc6374103ec03038f393f63ad63113aaa Mon Sep 17 00:00:00 2001 From: Simon Cruanes Date: Wed, 5 Oct 2022 23:02:42 -0400 Subject: [PATCH] test: basic test for parser --- unittest/parser/dune | 4 ++++ unittest/parser/p1.ml | 20 ++++++++++++++++++++ unittest/parser/t1.expected | 2 ++ 3 files changed, 26 insertions(+) create mode 100644 unittest/parser/dune create mode 100644 unittest/parser/p1.ml create mode 100644 unittest/parser/t1.expected diff --git a/unittest/parser/dune b/unittest/parser/dune new file mode 100644 index 00000000..46dcbe1e --- /dev/null +++ b/unittest/parser/dune @@ -0,0 +1,4 @@ +(tests + (names p1) + (flags :standard -open Sidekick_util -open Sidekick_parser) + (libraries sidekick.util sidekick.parser)) diff --git a/unittest/parser/p1.ml b/unittest/parser/p1.ml new file mode 100644 index 00000000..f42c7064 --- /dev/null +++ b/unittest/parser/p1.ml @@ -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)" diff --git a/unittest/parser/t1.expected b/unittest/parser/t1.expected new file mode 100644 index 00000000..139597f9 --- /dev/null +++ b/unittest/parser/t1.expected @@ -0,0 +1,2 @@ + +