53 lines
2.2 KiB
C
53 lines
2.2 KiB
C
#include "../test.h"
|
|
#include "../parser.h"
|
|
#include <string.h>
|
|
#include <stdlib.h>
|
|
|
|
static void test_parser_alias_simple_type(void) {
|
|
ModuleTree* m = test_get_ast();
|
|
|
|
assert_not_null(m, "expected module to be parsed");
|
|
assert_int(1, (int)m->alias_count, "expected correct number of aliases");
|
|
AliasTree alias = m->aliases[0];
|
|
assert_int(TYPE_TREE_BUILTIN, alias.value.tag, "expected correct alias tag");
|
|
assert_int(32, alias.value.builtin.bitSize, "expected bitSize 32");
|
|
assert_true(alias.value.builtin.isSigned, "expected signed");
|
|
}
|
|
|
|
static void test_parser_alias_array(void) {
|
|
ModuleTree* m = test_get_ast();
|
|
|
|
assert_not_null(m, "expected module to be parsed");
|
|
assert_int(1, (int)m->alias_count, "expected correct number of aliases");
|
|
AliasTree alias = m->aliases[0];
|
|
assert_int(TYPE_TREE_ARRAY, alias.value.tag, "expected correct alias tag");
|
|
TypeTree* valueType = alias.value.array.array;
|
|
assert_not_null(valueType, "expected pointer to array type");
|
|
assert_int(TYPE_TREE_BUILTIN, valueType->tag, "expected correct type tag");
|
|
assert_int(32, valueType->builtin.bitSize, "expected bitSize 32");
|
|
assert_true(valueType->builtin.isSigned, "expected signed");
|
|
}
|
|
|
|
static void test_parser_variable_init(void) {
|
|
ModuleTree* m = test_get_ast();
|
|
|
|
assert_not_null(m, "expected module to be parsed");
|
|
assert_int(1, (int)m->variable_count, "expected 1 variable");
|
|
VariableTree* 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_TREE_INTEGER, var->initializer->tag, "expected integer initializer");
|
|
assert_int(123, var->initializer->integer, "expected value 123");
|
|
}
|
|
|
|
static void test_parser_variable_simple_type(void) {
|
|
ModuleTree* 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");
|
|
VariableTree var = m->variables[0];
|
|
assert_int(TYPE_TREE_BUILTIN, var.type.tag, "expected correct type tag");
|
|
assert_int(32, var.type.builtin.bitSize, "expected bitSize 32");
|
|
assert_true(var.type.builtin.isSigned, "expected signed");
|
|
}
|