ea55dedd07
- Split ast.h into granular headers in v0/ast/ - Split parser.c into modular implementation files in v0/parser/ - Move and rename parser tests to v0/parser/test_*.c - Update build system (include.mk) with modular sub-makefiles - Maintain v0/ast.h and v0/parser.h as umbrella headers
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) {
|
|
Module* 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");
|
|
AliasDeclaration alias = m->aliases[0];
|
|
assert_int(TYPE_EXPRESSION_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) {
|
|
Module* 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");
|
|
AliasDeclaration alias = m->aliases[0];
|
|
assert_int(TYPE_EXPRESSION_ARRAY, alias.value.tag, "expected correct alias tag");
|
|
TypeExpression* valueType = alias.value.array.array;
|
|
assert_not_null(valueType, "expected pointer to array type");
|
|
assert_int(TYPE_EXPRESSION_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) {
|
|
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");
|
|
}
|
|
|
|
static void test_parser_variable_simple_type(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_int(TYPE_EXPRESSION_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");
|
|
}
|