Mercurial > lbo > hg > ylisp
changeset 160:8b04d8628314
eval: Add test for indirect undefined reference
author | Lewin Bormann <lbo@spheniscida.de> |
---|---|
date | Tue, 03 Sep 2019 16:55:29 +0200 |
parents | 28d1b36a05cd |
children | 72a52494df50 |
files | src/eval_test.c |
diffstat | 1 files changed, 25 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/src/eval_test.c Tue Sep 03 16:55:15 2019 +0200 +++ b/src/eval_test.c Tue Sep 03 16:55:29 2019 +0200 @@ -86,7 +86,6 @@ void test_eval_higher_order(void) { fprintf(stderr, "test_eval_higher_order ===========\n"); - // Calculate faculty values from 1 to 10. ystr_t input = ystr_new( "(defn f (a) (+ a 1))" "(defn g (fn) (fn 3))" @@ -109,11 +108,36 @@ ystr_destroy(&input); } +void test_eval_undefined_ref(void) { + fprintf(stderr, "test_eval_undefined_ref ===========\n"); + + ystr_t input = ystr_new( + "(defn f (a) (+ a 1))" + "(g f)"); + + yexpr_t program = yexpr_new(); + ystr_t error = ystr_new(NULL); + assert(yparse_str(&input, &program, &error)); + ypreprocess(&program); + + yeval_state_t state; + state.call_stack = YVEC_NEW(NULL, 4, yexpr_t); + yexpr_t result = yeval_list_return_last(&state, &program.value.list, 0); + assert(YEXPR_LIST == result.typ && YEXPR_EXCEPTION == YVEC_AT(&result.value.list, 0, yexpr_t)->typ); + + yexpr_destroy(&program); + yvec_destroy(&state.call_stack); + ystr_destroy(&error); + yexpr_destroy(&result); + ystr_destroy(&input); +} + int main(void) { test_eval_edge_cases(); test_eval_func_wrong_call(); test_eval_recursion(); test_eval_higher_order(); + test_eval_undefined_ref(); yvalue_free_all(); yatom_free_all(); return 0;