Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make term tests #1411

Merged
merged 3 commits into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 82 additions & 0 deletions test/Test_MakeTerm.re
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/**
* 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);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exp.fast_equal does not differentiate parens :(.

I can readd the eq derivings if we think that makes more sense.


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 ",
)
}),
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",
)
}),
];
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");
Loading