Skip to content

Commit

Permalink
chore: Add and update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
wwared committed Sep 13, 2024
1 parent 814d0de commit 3e7d7c4
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 4 deletions.
6 changes: 3 additions & 3 deletions src/lurk/eval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1990,9 +1990,9 @@ mod test {
expected.assert_eq(&computed.to_string());
};
expect_eq(lurk_main.width(), expect!["97"]);
expect_eq(preallocate_symbols.width(), expect!["164"]);
expect_eq(preallocate_symbols.width(), expect!["172"]);
expect_eq(eval.width(), expect!["75"]);
expect_eq(eval_builtin_expr.width(), expect!["141"]);
expect_eq(eval_builtin_expr.width(), expect!["148"]);
expect_eq(eval_opening_unop.width(), expect!["97"]);
expect_eq(eval_hide.width(), expect!["115"]);
expect_eq(eval_unop.width(), expect!["78"]);
Expand All @@ -2007,7 +2007,7 @@ mod test {
expect_eq(equal.width(), expect!["82"]);
expect_eq(equal_inner.width(), expect!["57"]);
expect_eq(car_cdr.width(), expect!["61"]);
expect_eq(apply.width(), expect!["100"]);
expect_eq(apply.width(), expect!["113"]);
expect_eq(env_lookup.width(), expect!["52"]);
expect_eq(ingress.width(), expect!["105"]);
expect_eq(egress.width(), expect!["82"]);
Expand Down
64 changes: 63 additions & 1 deletion src/lurk/eval_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,30 @@ test!(test_app2, "((lambda (x y z) y) 1 2 3)", |_| uint(2));
test!(test_app3, "((lambda (x) (lambda (y) x)) 1 2)", |_| {
uint(1)
});
test!(test_app4, "(apply (lambda (x) x) '(1))", |_| uint(1));
test!(test_app5, "(apply (lambda (x y z) y) (list 1 2 3))", |_| {
uint(2)
});
test!(
test_app6,
"(apply (lambda (x) (lambda (y) x)) '(1 2))",
|_| { uint(1) }
);
test!(test_app7, "((lambda (x &rest y) (car (cdr y))) 1)", |z| *z
.nil());
test!(test_app8, "((lambda (x &rest y) (car (cdr y))) 1 2)", |z| {
*z.nil()
});
test!(
test_app9,
"((lambda (x &rest y) (car (cdr y))) 1 2 3)",
|_| uint(3)
);
test!(
test_app10,
"((lambda (x &rest y) (car (cdr y))) 1 2 3 4)",
|_| uint(3)
);
test!(test_app_err, "(a)", |_| ZPtr::err(EvalErr::UnboundVar));
test!(test_app_err2, "((lambda () a) 2)", |_| ZPtr::err(
EvalErr::UnboundVar
Expand Down Expand Up @@ -388,7 +412,15 @@ test!(
(if (= n 0) 0
(if (= n 1) 1
(+ (fib (- n 1)) (fib (- n 2))))))))
(fib 10))",
(fib 10))",
|_| uint(55)
);
test!(
test_sum,
"(letrec ((sum
(lambda (x &rest y)
(if y (+ x (apply sum y)) x))))
(sum 1 2 3 4 5 6 7 8 9 10))",
|_| uint(55)
);

Expand Down Expand Up @@ -497,6 +529,16 @@ test!(test_shadow3, "((lambda (cons) (+ cons 1)) 1)", |_| uint(2));
test!(test_shadow4, "(let ((cons 1)) (cons cons cons))", |z| {
z.intern_cons(uint(1), uint(1))
});
test!(
test_shadow5,
"((lambda (cons &rest car) (+ cons (car car))) 1 2 5)",
|_| uint(3)
);
test!(
test_shadow6,
"((lambda (&rest &rest) (car &rest)) 1 2 5)",
|_| uint(1)
);

// errors
test!(test_unbound_var, "a", |_| ZPtr::err(EvalErr::UnboundVar));
Expand Down Expand Up @@ -549,3 +591,23 @@ test!(test_shadow_err5, "(letrec ((t 1)) (+ t 1))", |_| ZPtr::err(
test!(test_shadow_err6, "((lambda (t) (+ t 1)) 1)", |_| ZPtr::err(
EvalErr::IllegalBindingVar
));
test!(test_shadow_err7, "((lambda (x &rest t) (+ x 1)) 1)", |_| {
ZPtr::err(EvalErr::IllegalBindingVar)
});
test!(
test_shadow_err8,
"((lambda (x &rest nil) (+ x 1)) 1)",
|_| ZPtr::err(EvalErr::IllegalBindingVar)
);
test!(test_rest_err1, "((lambda (x &rest) x) 1)", |_| ZPtr::err(
EvalErr::ParamInvalidRest
));
test!(test_rest_err2, "((lambda (x &rest y z) x) 1)", |_| {
ZPtr::err(EvalErr::ParamInvalidRest)
});
test!(test_rest_err3, "((lambda (&rest y z) z) 1)", |_| ZPtr::err(
EvalErr::ParamInvalidRest
));
test!(test_rest_err4, "((lambda (&rest) &rest) 1)", |_| {
ZPtr::err(EvalErr::ParamInvalidRest)
});

0 comments on commit 3e7d7c4

Please sign in to comment.