Skip to content

Commit

Permalink
Add MakeTerm tests to test regular hazel parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
7h3kk1d committed Oct 13, 2024
1 parent c1c0eba commit 2003c76
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 0 deletions.
70 changes: 70 additions & 0 deletions test/Test_MakeTerm.re
Original file line number Diff line number Diff line change
@@ -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 ",
)
}),
];
1 change: 1 addition & 0 deletions test/haz3ltest.re
Original file line number Diff line number Diff line change
Expand Up @@ -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");

0 comments on commit 2003c76

Please sign in to comment.