#include "../test.h" #include "../parser.h" #include #include static void test_parser_missing_semicolon_import(void) { test_get_ast(); assert_log_file("expected error for missing semicolon"); } static void test_parser_bad_import_name(void) { test_get_ast(); assert_log_file("expected error for bad import name"); } static void test_parser_imports(void) { Module* m = test_get_ast(); assert_not_null(m, "expected module to be parsed"); assert_str("my_module", m->name, "expected name 'my_module'"); assert_not_null(m->imports, "expected imports to be parsed"); assert_int(1, (int)m->import_count, "expected one import"); assert_str("other_module", m->imports[0].module_name, "expected import name 'other_module'"); assert_false(m->imports[0].is_public, "expected import to not be public"); } static void test_parser_public_imports(void) { Module* m = test_get_ast(); assert_not_null(m, "expected module to be parsed"); assert_str("my_module", m->name, "expected name 'my_module'"); assert_not_null(m->imports, "expected imports to be parsed"); assert_int(1, (int)m->import_count, "expected one import"); assert_str("other_module", m->imports[0].module_name, "expected import name 'other_module'"); assert_true(m->imports[0].is_public, "expected import to be public"); } static void test_parser_alias_simple(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_str("myalias", alias.name, "expected correct alias name"); } static void test_parser_variable_simple(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_var", var.name, "expected correct variable name"); assert_false(var.is_const, "expected not const"); 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'"); }