More variable stuff
This commit is contained in:
@@ -95,3 +95,47 @@ static void test_parser_variable_simple(void) {
|
||||
assert_false(var.is_static, "expected not static");
|
||||
}
|
||||
|
||||
static void test_parser_variable_const(void) {
|
||||
Module* m = test_get_ast();
|
||||
|
||||
assert_not_null(m, "expected module to be parsed");
|
||||
assert_int(1, (int)m->variable_count, "expected correct number of variables");
|
||||
VariableDeclaration var = m->variables[0];
|
||||
assert_str("my_const", var.name, "expected correct variable name");
|
||||
assert_true(var.is_const, "expected const");
|
||||
assert_false(var.is_static, "expected not static");
|
||||
}
|
||||
|
||||
static void test_parser_variable_static(void) {
|
||||
Module* m = test_get_ast();
|
||||
|
||||
assert_not_null(m, "expected module to be parsed");
|
||||
assert_int(1, (int)m->variable_count, "expected correct number of variables");
|
||||
VariableDeclaration var = m->variables[0];
|
||||
assert_str("my_static", var.name, "expected correct variable name");
|
||||
assert_false(var.is_const, "expected not const");
|
||||
assert_true(var.is_static, "expected static");
|
||||
}
|
||||
|
||||
static void test_parser_multiple_vars(void) {
|
||||
Module* m = test_get_ast();
|
||||
|
||||
assert_not_null(m, "expected module to be parsed");
|
||||
assert_int(2, (int)m->variable_count, "expected correct number of variables");
|
||||
assert_str("var1", m->variables[0].name, "expected first variable name 'var1'");
|
||||
assert_str("var2", m->variables[1].name, "expected second variable name 'var2'");
|
||||
}
|
||||
|
||||
|
||||
static void test_parser_variable_init(void) {
|
||||
Module* m = test_get_ast();
|
||||
|
||||
assert_not_null(m, "expected module to be parsed");
|
||||
assert_int(1, (int)m->variable_count, "expected 1 variable");
|
||||
VariableDeclaration* var = &m->variables[0];
|
||||
assert_str("x", var->name, "expected variable name 'x'");
|
||||
assert_not_null(var->initializer, "expected variable to have an initializer");
|
||||
assert_int(EXPRESSION_INTEGER, var->initializer->tag, "expected integer initializer");
|
||||
assert_int(123, var->initializer->integer, "expected value 123");
|
||||
parser_free(m);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user