Add more tests for lets with errors

This commit is contained in:
2022-11-02 20:22:32 -04:00
parent 1451970ca8
commit 9c1a81811c
2 changed files with 15 additions and 3 deletions

View File

@@ -20,6 +20,7 @@ void setUp(void) {
state = ucl_state_create();
ucl_state_put(state, "let", ucl_builtin_create(ucl_builtin_let));
ucl_state_put(state, "+", ucl_builtin_create(ucl_builtin_add));
ucl_state_put(state, "error", ucl_builtin_create(ucl_builtin_error));
}
void tearDown(void) {
@@ -50,12 +51,22 @@ static void test_simple_let(void) {
TEST_ASSERT_EQUAL(response->integer, 5);
}
static void test_let_assignment_error(void) {
response = eval("(let ((x (error \"foo\"))) (+ x 3))");
TEST_ASSERT_OBJ_ERROR(response);
}
static void test_nested_let(void) {
response = eval("(let ((x 2)) (let ((y 5)) (+ x y)))");
TEST_ASSERT_OBJ_INT(response);
TEST_ASSERT_EQUAL(response->integer, 7);
}
static void test_nested_let_scope(void) {
response = eval("(let ((x 2)) (let ((y 5)) (+ x y)) y)");
TEST_ASSERT_OBJ_ERROR(response);
}
static void test_multi_let(void) {
response = eval("(let ((x 2)(y 5)) (+ x y))");
TEST_ASSERT_OBJ_INT(response);
@@ -97,7 +108,9 @@ int main(void) {
RUN_TEST(test_simple_add);
RUN_TEST(test_simple_let);
RUN_TEST(test_let_assignment_error);
RUN_TEST(test_nested_let);
RUN_TEST(test_nested_let_scope);
RUN_TEST(test_multi_let);
RUN_TEST(test_let_return_sym);
RUN_TEST(test_eval_int);