Skip to content

Commit

Permalink
Added Test_ExpToSegment
Browse files Browse the repository at this point in the history
  • Loading branch information
7h3kk1d committed Oct 7, 2024
1 parent 4c9520c commit 769cd63
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 0 deletions.
69 changes: 69 additions & 0 deletions test/Test_ExpToSegment.re
Original file line number Diff line number Diff line change
@@ -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,
);
},
),
];
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),
("ExpToSegment", Test_ExpToSegment.tests),
],
);
Junit.to_file(Junit.make([suite]), "junit_tests.xml");

0 comments on commit 769cd63

Please sign in to comment.