From 2003c7607e55a701eeaa4a8387b561bb7bd11f42 Mon Sep 17 00:00:00 2001 From: Alexander Bandukwala <7h3kk1d@gmail.com> Date: Mon, 7 Oct 2024 10:39:39 -0400 Subject: [PATCH 1/3] Add MakeTerm tests to test regular hazel parsing --- test/Test_MakeTerm.re | 70 +++++++++++++++++++++++++++++++++++++++++++ test/haz3ltest.re | 1 + 2 files changed, 71 insertions(+) create mode 100644 test/Test_MakeTerm.re diff --git a/test/Test_MakeTerm.re b/test/Test_MakeTerm.re new file mode 100644 index 0000000000..82eee683b6 --- /dev/null +++ b/test/Test_MakeTerm.re @@ -0,0 +1,70 @@ +/** + * This file contains tests to validate the `MakeTerm` module's ability to convert + * zippers into expressions. + */ +open Alcotest; +open Haz3lcore; + +let exp_typ = testable(Fmt.using(Exp.show, Fmt.string), Exp.fast_equal); + +// TODO Assertion if it doesn't parse +let parse_exp = (s: string) => + MakeTerm.from_zip_for_sem(Option.get(Printer.zipper_of_string(s))).term; +let exp_check = (expected, actual) => + check(exp_typ, actual, expected, parse_exp(actual)); + +let tests = [ + test_case("Integer Literal", `Quick, () => { + exp_check(Int(0) |> Exp.fresh, "0") + }), + test_case("Empty Hole", `Quick, () => { + exp_check(EmptyHole |> Exp.fresh, "?") + }), + test_case("Free Variable", `Quick, () => { + exp_check(Var("x") |> Exp.fresh, "x") + }), + test_case("Parenthesized Expression", `Quick, () => { + exp_check(Parens(Int(0) |> Exp.fresh) |> Exp.fresh, "(0)") + }), + test_case("Let Expression", `Quick, () => { + exp_check( + Let( + Var("x") |> Pat.fresh, + Int(1) |> Exp.fresh, + Var("x") |> Exp.fresh, + ) + |> Exp.fresh, + "let x = 1 in x", + ) + }), + test_case("Function Application", `Quick, () => { + exp_check( + Ap(Forward, Var("f") |> Exp.fresh, Var("x") |> Exp.fresh) |> Exp.fresh, + "f(x)", + ) + }), + test_case("Named Function Definition", `Quick, () => { + exp_check( + Let( + Var("f") |> Pat.fresh, + Fun(Var("x") |> Pat.fresh, Var("x") |> Exp.fresh, None, None) // It seems as though the function naming happens during elaboration and not during parsing + |> Exp.fresh, + Int(1) |> Exp.fresh, + ) + |> Exp.fresh, + "let f = fun x -> x in 1", + ) + }), + test_case("Incomplete Function Definition", `Quick, () => { + exp_check( + Let( + EmptyHole |> Pat.fresh, + Fun(Var("x") |> Pat.fresh, EmptyHole |> Exp.fresh, None, None) + |> Exp.fresh, + EmptyHole |> Exp.fresh, + ) + |> Exp.fresh, + "let = fun x -> in ", + ) + }), +]; diff --git a/test/haz3ltest.re b/test/haz3ltest.re index 3e13ae44b7..3c6cbb6098 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), + ("MakeTerm", Test_MakeTerm.tests), ], ); Junit.to_file(Junit.make([suite]), "junit_tests.xml"); From 5b82cae1ac1e4b56487301e85d91b57336bd3526 Mon Sep 17 00:00:00 2001 From: Alexander Bandukwala <7h3kk1d@gmail.com> Date: Sun, 13 Oct 2024 09:54:38 -0400 Subject: [PATCH 2/3] Remove todo --- test/Test_MakeTerm.re | 1 - 1 file changed, 1 deletion(-) diff --git a/test/Test_MakeTerm.re b/test/Test_MakeTerm.re index 82eee683b6..be365e9edb 100644 --- a/test/Test_MakeTerm.re +++ b/test/Test_MakeTerm.re @@ -7,7 +7,6 @@ open Haz3lcore; let exp_typ = testable(Fmt.using(Exp.show, Fmt.string), Exp.fast_equal); -// TODO Assertion if it doesn't parse let parse_exp = (s: string) => MakeTerm.from_zip_for_sem(Option.get(Printer.zipper_of_string(s))).term; let exp_check = (expected, actual) => From bc19bf60845760683588eda83c90013e6459075e Mon Sep 17 00:00:00 2001 From: Alexander Bandukwala <7h3kk1d@gmail.com> Date: Thu, 24 Oct 2024 10:58:23 -0400 Subject: [PATCH 3/3] Added additional tests --- test/Test_MakeTerm.re | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/test/Test_MakeTerm.re b/test/Test_MakeTerm.re index be365e9edb..46818664a9 100644 --- a/test/Test_MakeTerm.re +++ b/test/Test_MakeTerm.re @@ -66,4 +66,17 @@ let tests = [ "let = fun x -> in ", ) }), + test_case("Constructor", `Quick, () => { + exp_check( + Constructor("A", Unknown(Internal) |> Typ.fresh) |> Exp.fresh, + "A", + ) + }), + test_case("Type Alias", `Quick, () => { + exp_check( + TyAlias(Var("x") |> TPat.fresh, Int |> Typ.fresh, Int(1) |> Exp.fresh) + |> Exp.fresh, + "type x = Int in 1", + ) + }), ];