Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
7h3kk1d committed Oct 7, 2024
1 parent 46709ea commit 0fd9c4b
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 45 deletions.
68 changes: 39 additions & 29 deletions test/Test_Elaboration.re
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ let mk_map = Statics.mk(CoreSettings.on, Builtins.ctx_init);
let dhexp_of_uexp = u => Elaborator.elaborate(mk_map(u), u) |> fst;
let alco_check = dhexp_typ |> Alcotest.check;

let u1: Exp.t = {ids: [id_at(0)], term: Int(8), copied: false};
let u1: Exp.t = {ids: [id_at(0)], term: IntLit(8), copied: false};
let single_integer = () =>
alco_check("Integer literal 8", u1, dhexp_of_uexp(u1));

Expand All @@ -28,8 +28,9 @@ let free_var = () => alco_check("free variable", u3, dhexp_of_uexp(u3));

let u4: Exp.t =
Let(
Tuple([Var("a") |> Pat.fresh, Var("b") |> Pat.fresh]) |> Pat.fresh,
Tuple([Int(4) |> Exp.fresh, Int(6) |> Exp.fresh]) |> Exp.fresh,
TuplePat([VarPat("a") |> Pat.fresh, VarPat("b") |> Pat.fresh])
|> Pat.fresh,
Tuple([IntLit(4) |> Exp.fresh, IntLit(6) |> Exp.fresh]) |> Exp.fresh,
BinOp(Int(Minus), Var("a") |> Exp.fresh, Var("b") |> Exp.fresh)
|> Exp.fresh,
)
Expand All @@ -39,13 +40,17 @@ let let_exp = () =>
alco_check("Let expression for tuple (a, b)", u4, dhexp_of_uexp(u4));

let u5 =
BinOp(Int(Plus), Bool(false) |> Exp.fresh, Var("y") |> Exp.fresh)
BinOp(Int(Plus), BoolLit(false) |> Exp.fresh, Var("y") |> Exp.fresh)
|> Exp.fresh;

let d5 =
BinOp(
Int(Plus),
FailedCast(Bool(false) |> Exp.fresh, Bool |> Typ.fresh, Int |> Typ.fresh)
FailedCast(
BoolLit(false) |> Exp.fresh,
Bool |> Typ.fresh,
Int |> Typ.fresh,
)
|> Exp.fresh,
Cast(
Var("y") |> Exp.fresh,
Expand All @@ -64,7 +69,11 @@ let bin_op = () =>
);

let u6: Exp.t =
If(Bool(false) |> Exp.fresh, Int(8) |> Exp.fresh, Int(6) |> Exp.fresh)
If(
BoolLit(false) |> Exp.fresh,
IntLit(8) |> Exp.fresh,
IntLit(6) |> Exp.fresh,
)
|> Exp.fresh;

let consistent_if = () =>
Expand All @@ -77,8 +86,9 @@ let consistent_if = () =>
// x => 4 + 5
let f =
Fun(
Var("x") |> Pat.fresh,
BinOp(Int(Plus), Int(4) |> Exp.fresh, Int(5) |> Exp.fresh) |> Exp.fresh,
VarPat("x") |> Pat.fresh,
BinOp(Int(Plus), IntLit(4) |> Exp.fresh, IntLit(5) |> Exp.fresh)
|> Exp.fresh,
None,
None,
)
Expand All @@ -92,33 +102,33 @@ let ap_fun = () =>

let u8: Exp.t =
Match(
BinOp(Int(Equals), Int(4) |> Exp.fresh, Int(3) |> Exp.fresh)
BinOp(Int(Equals), IntLit(4) |> Exp.fresh, IntLit(3) |> Exp.fresh)
|> Exp.fresh,
[
(Bool(true) |> Pat.fresh, Int(24) |> Exp.fresh),
(Bool(false) |> Pat.fresh, Bool(false) |> Exp.fresh),
(BoolPat(true) |> Pat.fresh, IntLit(24) |> Exp.fresh),
(BoolPat(false) |> Pat.fresh, BoolLit(false) |> Exp.fresh),
],
)
|> Exp.fresh;

let d8: Exp.t =
Match(
BinOp(Int(Equals), Int(4) |> Exp.fresh, Int(3) |> Exp.fresh)
BinOp(Int(Equals), IntLit(4) |> Exp.fresh, IntLit(3) |> Exp.fresh)
|> Exp.fresh,
[
(
Bool(true) |> Pat.fresh,
BoolPat(true) |> Pat.fresh,
Cast(
Int(24) |> Exp.fresh,
IntLit(24) |> Exp.fresh,
Int |> Typ.fresh,
Unknown(Internal) |> Typ.fresh,
)
|> Exp.fresh,
),
(
Bool(false) |> Pat.fresh,
BoolPat(false) |> Pat.fresh,
Cast(
Bool(false) |> Exp.fresh,
BoolLit(false) |> Exp.fresh,
Bool |> Typ.fresh,
Unknown(Internal) |> Typ.fresh,
)
Expand All @@ -137,36 +147,36 @@ let inconsistent_case = () =>

let u9: Exp.t =
Let(
Cast(
Var("f") |> Pat.fresh,
CastPat(
VarPat("f") |> Pat.fresh,
Arrow(Int |> Typ.fresh, Int |> Typ.fresh) |> Typ.fresh,
Unknown(Internal) |> Typ.fresh,
)
|> Pat.fresh,
Fun(
Var("x") |> Pat.fresh,
BinOp(Int(Plus), Int(1) |> Exp.fresh, Var("x") |> Exp.fresh)
VarPat("x") |> Pat.fresh,
BinOp(Int(Plus), IntLit(1) |> Exp.fresh, Var("x") |> Exp.fresh)
|> Exp.fresh,
None,
None,
)
|> Exp.fresh,
Int(55) |> Exp.fresh,
IntLit(55) |> Exp.fresh,
)
|> Exp.fresh;

let d9: Exp.t =
Let(
Var("f") |> Pat.fresh,
VarPat("f") |> Pat.fresh,
Fun(
Var("x") |> Pat.fresh,
BinOp(Int(Plus), Int(1) |> Exp.fresh, Var("x") |> Exp.fresh)
VarPat("x") |> Pat.fresh,
BinOp(Int(Plus), IntLit(1) |> Exp.fresh, Var("x") |> Exp.fresh)
|> Exp.fresh,
None,
Some("f"),
)
|> Exp.fresh,
Int(55) |> Exp.fresh,
IntLit(55) |> Exp.fresh,
)
|> Exp.fresh;

Expand All @@ -184,8 +194,8 @@ let deferral = () =>
DeferredAp(
Var("string_sub") |> Exp.fresh,
[
String("hello") |> Exp.fresh,
Int(1) |> Exp.fresh,
StringLit("hello") |> Exp.fresh,
IntLit(1) |> Exp.fresh,
Deferral(InAp) |> Exp.fresh,
],
)
Expand All @@ -195,8 +205,8 @@ let deferral = () =>
DeferredAp(
Var("string_sub") |> Exp.fresh,
[
String("hello") |> Exp.fresh,
Int(1) |> Exp.fresh,
StringLit("hello") |> Exp.fresh,
IntLit(1) |> Exp.fresh,
Deferral(InAp) |> Exp.fresh,
],
)
Expand Down
9 changes: 5 additions & 4 deletions test/Test_Evaluator.re
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ let type_of = f => {
};

let int_evaluation =
Evaluator.evaluate(Builtins.env_init, {d: Int(8) |> Exp.fresh});
Evaluator.evaluate(Builtins.env_init, {d: IntLit(8) |> Exp.fresh});

let evaluation_test = (msg, expected, unevaluated) =>
check(
Expand All @@ -29,13 +29,14 @@ let evaluation_test = (msg, expected, unevaluated) =>
);

let test_int = () =>
evaluation_test("8", Int(8) |> Exp.fresh, Int(8) |> Exp.fresh);
evaluation_test("8", IntLit(8) |> Exp.fresh, IntLit(8) |> Exp.fresh);

let test_sum = () =>
evaluation_test(
"4 + 5",
Int(9) |> Exp.fresh,
BinOp(Int(Plus), Int(4) |> Exp.fresh, Int(5) |> Exp.fresh) |> Exp.fresh,
IntLit(9) |> Exp.fresh,
BinOp(Int(Plus), IntLit(4) |> Exp.fresh, IntLit(5) |> Exp.fresh)
|> Exp.fresh,
);

let tests = [
Expand Down
37 changes: 25 additions & 12 deletions test/Test_Statics.re
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ let unapplied_function = () =>
Some(FreshId.(arrow(unknown(Internal), int))),
type_of(
Fun(
Var("x") |> Pat.fresh,
BinOp(Int(Plus), Int(4) |> Exp.fresh, Int(5) |> Exp.fresh)
VarPat("x") |> Pat.fresh,
BinOp(Int(Plus), IntLit(4) |> Exp.fresh, IntLit(5) |> Exp.fresh)
|> Exp.fresh,
None,
None,
Expand All @@ -48,8 +48,12 @@ let tests =
Some(arrow(unknown(Internal), int)),
type_of(
Fun(
Var("x") |> Pat.fresh,
BinOp(Int(Plus), Int(4) |> Exp.fresh, Int(5) |> Exp.fresh)
VarPat("x") |> Pat.fresh,
BinOp(
Int(Plus),
IntLit(4) |> Exp.fresh,
IntLit(5) |> Exp.fresh,
)
|> Exp.fresh,
None,
None,
Expand All @@ -64,8 +68,13 @@ let tests =
Some(arrow(int, int)),
type_of(
Fun(
Cast(Var("x") |> Pat.fresh, int, unknown(Internal)) |> Pat.fresh,
BinOp(Int(Plus), Int(4) |> Exp.fresh, Int(5) |> Exp.fresh)
CastPat(VarPat("x") |> Pat.fresh, int, unknown(Internal))
|> Pat.fresh,
BinOp(
Int(Plus),
IntLit(4) |> Exp.fresh,
IntLit(5) |> Exp.fresh,
)
|> Exp.fresh,
None,
None,
Expand All @@ -80,10 +89,10 @@ let tests =
Some(arrow(prod([int, int]), int)),
type_of(
Fun(
Tuple([
Cast(Var("x") |> Pat.fresh, int, unknown(Internal))
TuplePat([
CastPat(VarPat("x") |> Pat.fresh, int, unknown(Internal))
|> Pat.fresh,
Cast(Var("y") |> Pat.fresh, int, unknown(Internal))
CastPat(VarPat("y") |> Pat.fresh, int, unknown(Internal))
|> Pat.fresh,
])
|> Pat.fresh,
Expand All @@ -101,7 +110,11 @@ let tests =
"float_of_int(1)",
Some(float),
type_of(
Ap(Forward, Var("float_of_int") |> Exp.fresh, Int(1) |> Exp.fresh)
Ap(
Forward,
Var("float_of_int") |> Exp.fresh,
IntLit(1) |> Exp.fresh,
)
|> Exp.fresh,
),
)
Expand All @@ -114,8 +127,8 @@ let tests =
DeferredAp(
Var("string_sub") |> Exp.fresh,
[
String("hello") |> Exp.fresh,
Int(1) |> Exp.fresh,
StringLit("hello") |> Exp.fresh,
IntLit(1) |> Exp.fresh,
Deferral(InAp) |> Exp.fresh,
],
)
Expand Down

0 comments on commit 0fd9c4b

Please sign in to comment.