From 769cd632e4b2e1dfa77fb956e3b0d48f5d05c0df Mon Sep 17 00:00:00 2001 From: Alexander Bandukwala <7h3kk1d@gmail.com> Date: Mon, 7 Oct 2024 13:44:02 -0400 Subject: [PATCH] Added Test_ExpToSegment --- test/Test_ExpToSegment.re | 69 +++++++++++++++++++++++++++++++++++++++ test/haz3ltest.re | 1 + 2 files changed, 70 insertions(+) create mode 100644 test/Test_ExpToSegment.re diff --git a/test/Test_ExpToSegment.re b/test/Test_ExpToSegment.re new file mode 100644 index 0000000000..18cc8d0ac2 --- /dev/null +++ b/test/Test_ExpToSegment.re @@ -0,0 +1,69 @@ +open Alcotest; +open Haz3lcore; + +let serialize = (exp: Exp.t): string => { + let seg = + ExpToSegment.exp_to_segment( + ~settings=ExpToSegment.Settings.of_core(~inline=true, CoreSettings.on), + exp, + ); + let zipper = Zipper.unzip(seg); + Printer.zipper_to_string(~holes=Some("?"), zipper); +}; + +let tests = [ + test_case( + "Integer Literal", + `Quick, + () => { + let exp = Int(0) |> Exp.fresh; + let serialized = serialize(exp); + check(string, "0", "0", serialized); + }, + ), + test_case( + "Empty Hole", + `Quick, + () => { + let exp = EmptyHole |> Exp.fresh; + let serialized = serialize(exp); + check(string, "?", "?", serialized); + }, + ), + test_case( + "Let expression", + `Quick, + () => { + let exp = + Let( + Var("x") |> Pat.fresh, + Int(1) |> Exp.fresh, + Var("x") |> Exp.fresh, + ) + |> Exp.fresh; + let serialized = serialize(exp); + check(string, "let x = 1 in x", "let x = 1 in x", serialized); + }, + ), + test_case( + "Function definition", + `Quick, + () => { + let exp = + Let( + Var("f") |> Pat.fresh, + Fun(Var("x") |> Pat.fresh, Var("x") |> Exp.fresh, None, None) + |> Exp.fresh, + Int(1) |> Exp.fresh, + ) + |> Exp.fresh; + let serialized = serialize(exp); + check( + string, + "let f = (fun x -> x) in 1", + "let f = (fun x -> x) in 1", + serialized, + ); + }, + ), +]; diff --git a/test/haz3ltest.re b/test/haz3ltest.re index 3e13ae44b7..862b17df6a 100644 --- a/test/haz3ltest.re +++ b/test/haz3ltest.re @@ -8,6 +8,7 @@ let (suite, _) = ("Elaboration", Test_Elaboration.elaboration_tests), ("Statics", Test_Statics.tests), ("Evaluator", Test_Evaluator.tests), + ("ExpToSegment", Test_ExpToSegment.tests), ], ); Junit.to_file(Junit.make([suite]), "junit_tests.xml");