aboutsummaryrefslogtreecommitdiff
path: root/test/test_internal.c
diff options
context:
space:
mode:
Diffstat (limited to 'test/test_internal.c')
-rw-r--r--test/test_internal.c178
1 files changed, 89 insertions, 89 deletions
diff --git a/test/test_internal.c b/test/test_internal.c
index 0f08112..cb0572a 100644
--- a/test/test_internal.c
+++ b/test/test_internal.c
@@ -19,11 +19,11 @@
DECLTEST(_ls_lex)
{
- ls_context_t ctx;
+ ls_t ls;
ls_token_t tok;
- LS_TEST_CATCH(ctx)
+ LS_TEST_CATCH(ls)
{
- munit_errorf("Caught error: %d\n", ctx.error);
+ munit_errorf("Caught error: %d\n", ls.error);
return MUNIT_FAIL;
}
@@ -35,64 +35,64 @@ DECLTEST(_ls_lex)
};
for (size_t i = 0; operstrings[i]; i++)
{
- ls_test_setup(&ctx, operstrings[i]);
- ls_lex(&ctx, &tok);
+ ls_test_setup(&ls, operstrings[i]);
+ ls_lex(&ls, &tok);
munit_assert_int(tok.ty, ==, LS_TOK_OPERATOR);
munit_assert_int(tok.body.oper_val, ==, OPER_LT);
- ls_lex(&ctx, &tok);
+ ls_lex(&ls, &tok);
munit_assert_int(tok.ty, ==, LS_TOK_OPERATOR);
munit_assert_int(tok.body.oper_val, ==, OPER_LEQ);
- ls_lex(&ctx, &tok);
+ ls_lex(&ls, &tok);
munit_assert_int(tok.ty, ==, LS_TOK_OPERATOR);
munit_assert_int(tok.body.oper_val, ==, OPER_EQ);
- ls_lex(&ctx, &tok);
+ ls_lex(&ls, &tok);
munit_assert_int(tok.ty, ==, LS_TOK_OPERATOR);
munit_assert_int(tok.body.oper_val, ==, OPER_NEQ);
- ls_lex(&ctx, &tok);
+ ls_lex(&ls, &tok);
munit_assert_int(tok.ty, ==, LS_TOK_OPERATOR);
munit_assert_int(tok.body.oper_val, ==, OPER_GEQ);
- ls_lex(&ctx, &tok);
+ ls_lex(&ls, &tok);
munit_assert_int(tok.ty, ==, LS_TOK_OPERATOR);
munit_assert_int(tok.body.oper_val, ==, OPER_GT);
}
// Numbers are done separately in _ls_parse_num
- ls_test_setup(&ctx, "foo");
- ls_lex(&ctx, &tok);
+ ls_test_setup(&ls, "foo");
+ ls_lex(&ls, &tok);
munit_assert_int(tok.ty, ==, LS_TOK_WORD);
munit_assert_string_equal(tok.body.word_val, "foo");
- ls_test_setup(&ctx, "foo bar");
- ls_lex(&ctx, &tok);
+ ls_test_setup(&ls, "foo bar");
+ ls_lex(&ls, &tok);
munit_assert_int(tok.ty, ==, LS_TOK_WORD);
munit_assert_string_equal(tok.body.word_val, "foo");
- ls_lex(&ctx, &tok);
+ ls_lex(&ls, &tok);
munit_assert_int(tok.ty, ==, LS_TOK_WORD);
munit_assert_string_equal(tok.body.word_val, "bar");
- ls_test_setup(&ctx, "abittoolong foo");
- ls_lex(&ctx, &tok);
+ ls_test_setup(&ls, "abittoolong foo");
+ ls_lex(&ls, &tok);
munit_assert_int(tok.ty, ==, LS_TOK_WORD);
munit_assert_string_equal(tok.body.word_val, "abittoolo");
- ls_lex(&ctx, &tok);
+ ls_lex(&ls, &tok);
munit_assert_int(tok.ty, ==, LS_TOK_WORD);
munit_assert_string_equal(tok.body.word_val, "foo");
- ls_test_setup(&ctx, " hasspace");
- ls_lex(&ctx, &tok);
+ ls_test_setup(&ls, " hasspace");
+ ls_lex(&ls, &tok);
munit_assert_int(tok.ty, ==, LS_TOK_WORD);
munit_assert_string_equal(tok.body.word_val, "hasspace");
- ls_lex(&ctx, &tok);
+ ls_lex(&ls, &tok);
munit_assert_int(tok.ty, ==, LS_TOK_NONE);
- ls_test_setup(&ctx, "_foo_");
- ls_lex(&ctx, &tok);
+ ls_test_setup(&ls, "_foo_");
+ ls_lex(&ls, &tok);
munit_assert_int(tok.ty, ==, LS_TOK_WORD);
munit_assert_string_equal(tok.body.word_val, "_foo_");
- ls_test_setup(&ctx, "\x7F");
- LS_EXPECT_ERR(ctx, LS_SYNTAX_ERROR, ls_lex(&ctx, &tok));
+ ls_test_setup(&ls, "\x7F");
+ LS_EXPECT_ERR(ls, LS_SYNTAX_ERROR, ls_lex(&ls, &tok));
return MUNIT_OK;
}
@@ -113,65 +113,65 @@ DECLTEST(_ls_convert_kw)
DECLTEST(_ls_parse_num)
{
- ls_context_t ctx;
- LS_TEST_CATCH(ctx)
+ ls_t ls;
+ LS_TEST_CATCH(ls)
{
- munit_errorf("Caught error %d\n", ctx.error);
+ munit_errorf("Caught error %d\n", ls.error);
return MUNIT_FAIL;
}
ls_value_t val;
ls_token_t tok;
- ls_test_setup(&ctx, "42, &H42, &o42, &42, &b101010");
+ ls_test_setup(&ls, "42, &H42, &o42, &42, &b101010");
- ls_eval_expr(&ctx, &val, NULL);
+ ls_eval_expr(&ls, &val, NULL);
munit_assert_int(val.body.integer.value, ==, 42);
- ls_lex(&ctx, &tok); // eat the comma
+ ls_lex(&ls, &tok); // eat the comma
- ls_eval_expr(&ctx, &val, NULL);
+ ls_eval_expr(&ls, &val, NULL);
munit_assert_int(val.body.integer.value, ==, 0x42);
- ls_lex(&ctx, &tok); // eat the comma
+ ls_lex(&ls, &tok); // eat the comma
- ls_eval_expr(&ctx, &val, NULL);
+ ls_eval_expr(&ls, &val, NULL);
munit_assert_int(val.body.integer.value, ==, 042);
- ls_lex(&ctx, &tok); // eat the comma
+ ls_lex(&ls, &tok); // eat the comma
- ls_eval_expr(&ctx, &val, NULL);
+ ls_eval_expr(&ls, &val, NULL);
munit_assert_int(val.body.integer.value, ==, 042);
- ls_lex(&ctx, &tok); // eat the comma
+ ls_lex(&ls, &tok); // eat the comma
- ls_eval_expr(&ctx, &val, NULL);
+ ls_eval_expr(&ls, &val, NULL);
munit_assert_int(val.body.integer.value, ==, 42);
- ls_lex(&ctx, &tok); // eat the comma
+ ls_lex(&ls, &tok); // eat the comma
- ls_test_setup(&ctx, "0e42");
- LS_EXPECT_ERR(ctx, LS_SYNTAX_ERROR, ls_eval_expr(&ctx, &val, NULL));
+ ls_test_setup(&ls, "0e42");
+ LS_EXPECT_ERR(ls, LS_SYNTAX_ERROR, ls_eval_expr(&ls, &val, NULL));
return MUNIT_OK;
}
static void _check_expr(char const * s, int expected)
{
char const * testing = NULL;
- ls_context_t ctx;
+ ls_t ls;
- LS_TEST_CATCH(ctx)
+ LS_TEST_CATCH(ls)
{
if (testing)
munit_errorf("Caught error %d in \"%s\"\n",
- ctx.error, testing);
+ ls.error, testing);
else
- munit_errorf("Caught error %d\n", ctx.error);
+ munit_errorf("Caught error %d\n", ls.error);
}
testing = s;
ls_value_t val;
- ls_test_setup(&ctx, s);
- size_t sz_pool = ls_mem_avail(&ctx);
- ls_eval_expr(&ctx, &val, NULL);
+ ls_test_setup(&ls, s);
+ size_t sz_pool = ls_mem_avail(&ls);
+ ls_eval_expr(&ls, &val, NULL);
munit_assert_int(val.ty, ==, LS_TY_INT);
munit_assert_int(val.body.integer.value, ==, expected);
- munit_assert_size(sz_pool, ==, ls_mem_avail(&ctx));
+ munit_assert_size(sz_pool, ==, ls_mem_avail(&ls));
}
DECLTEST(_ls_eval_expr)
@@ -215,50 +215,50 @@ DECLTEST(_ls_eval_expr)
DECLTEST(_ls_lookup_var)
{
- ls_context_t ctx;
- LS_TEST_CATCH(ctx)
+ ls_t ls;
+ LS_TEST_CATCH(ls)
{
- munit_errorf("Caught error: %d\n", ctx.error);
+ munit_errorf("Caught error: %d\n", ls.error);
return MUNIT_FAIL;
}
- ls_test_setup(&ctx, "2*foo + bar/2");
+ ls_test_setup(&ls, "2*foo + bar/2");
// Create the global stack frame, currently there's no function to
// do that
- ctx.callstack = ls_alloc(&ctx);
- ctx.callstack->ty = LS_TY_SCTX_CALL;
- ctx.callstack->prev = NULL;
- ctx.callstack->next = NULL;
- ctx.callstack->body.sctx_call.pc = LS_ADDR_NULL;
- ctx.callstack->body.sctx_call.readptr = LS_ADDR_NULL;
+ ls.callstack = ls_alloc(&ls);
+ ls.callstack->ty = LS_TY_SCTX_CALL;
+ ls.callstack->prev = NULL;
+ ls.callstack->next = NULL;
+ ls.callstack->body.sctx_call.pc = LS_ADDR_NULL;
+ ls.callstack->body.sctx_call.readptr = LS_ADDR_NULL;
- ls_value_t * var_foo = ls_new_var(&ctx, "foo");
- ls_write_int_var(&ctx, var_foo, 20);
+ ls_value_t * var_foo = ls_new_var(&ls, "foo");
+ ls_write_int_var(&ls, var_foo, 20);
- ls_value_t * var_bar = ls_new_var(&ctx, "bar");
- ls_write_int_var(&ctx, var_bar, 4);
+ ls_value_t * var_bar = ls_new_var(&ls, "bar");
+ ls_write_int_var(&ls, var_bar, 4);
ls_value_t val;
- size_t sz_pool = ls_mem_avail(&ctx);
- ls_eval_expr(&ctx, &val, NULL);
+ size_t sz_pool = ls_mem_avail(&ls);
+ ls_eval_expr(&ls, &val, NULL);
munit_assert_int(val.ty, ==, LS_TY_INT);
munit_assert_int(val.body.integer.value, ==, 42);
- munit_assert_size(sz_pool, ==, ls_mem_avail(&ctx));
+ munit_assert_size(sz_pool, ==, ls_mem_avail(&ls));
return MUNIT_OK;
}
DECLTEST(_ls_let)
{
- ls_context_t ctx;
- LS_TEST_CATCH(ctx)
+ ls_t ls;
+ LS_TEST_CATCH(ls)
{
- munit_errorf("Caught error: %d\n", ctx.error);
+ munit_errorf("Caught error: %d\n", ls.error);
return MUNIT_FAIL;
}
- ls_test_setup(&ctx,
+ ls_test_setup(&ls,
"x = 13\n"
"let y = x * 100\n"
"z = y + 37\n"
@@ -266,19 +266,19 @@ DECLTEST(_ls_let)
// Create the global stack frame, currently there's no function to
// do that
- ctx.callstack = ls_alloc(&ctx);
- ctx.callstack->ty = LS_TY_SCTX_CALL;
- ctx.callstack->prev = NULL;
- ctx.callstack->next = NULL;
- ctx.callstack->body.sctx_call.pc = LS_ADDR_NULL;
- ctx.callstack->body.sctx_call.readptr = LS_ADDR_NULL;
+ ls.callstack = ls_alloc(&ls);
+ ls.callstack->ty = LS_TY_SCTX_CALL;
+ ls.callstack->prev = NULL;
+ ls.callstack->next = NULL;
+ ls.callstack->body.sctx_call.pc = LS_ADDR_NULL;
+ ls.callstack->body.sctx_call.readptr = LS_ADDR_NULL;
- ls_exec_line(&ctx);
- ls_exec_line(&ctx);
- ls_exec_line(&ctx);
+ ls_exec_line(&ls);
+ ls_exec_line(&ls);
+ ls_exec_line(&ls);
- ls_value_t * var_z = ls_find_var(&ctx, "z");
- munit_assert_int(ls_read_int_var(&ctx, var_z), ==, 1337);
+ ls_value_t * var_z = ls_find_var(&ls, "z");
+ munit_assert_int(ls_read_int_var(&ls, var_z), ==, 1337);
return MUNIT_OK;
}
@@ -286,19 +286,19 @@ DECLTEST(_ls_let)
DECLTEST(_ls_run)
{
static const size_t szpool = 1000;
- ls_context_t ctx;
+ ls_t ls;
ls_value_t pool[szpool];
- ls_setup_run(&ctx,
+ ls_setup_run(&ls,
"x = 13;let y=x*100\n"
"z = y + 37\n"
);
- ls_error_t e = ls_run(&ctx, pool, szpool);
+ ls_error_t e = ls_run(&ls, pool, szpool);
munit_assert_int(e, ==, LS_OK);
- ls_value_t * var_z = ls_find_var(&ctx, "z");
- munit_assert_int(ls_read_int_var(&ctx, var_z), ==, 1337);
+ ls_value_t * var_z = ls_find_var(&ls, "z");
+ munit_assert_int(ls_read_int_var(&ls, var_z), ==, 1337);
/*
fprintf(stdout, "\n");
for (size_t i = 0; i < 16; i++)
@@ -313,10 +313,10 @@ DECLTEST(_ls_run)
DECLTEST(_ls_simple_script)
{
static const size_t szpool = 1000;
- ls_context_t ctx;
+ ls_t ls;
ls_value_t pool[szpool];
- ls_setup_run(&ctx,
+ ls_setup_run(&ls,
"x = 13\n"
"y = 24\n"
"y = y + x\n"
@@ -325,7 +325,7 @@ DECLTEST(_ls_simple_script)
"print \"x = \", x, \", twelve = \", 12\n"
);
- ls_error_t e = ls_run(&ctx, pool, szpool);
+ ls_error_t e = ls_run(&ls, pool, szpool);
munit_assert_int(e, ==, LS_OK);
fprintf(stdout, "\n");