summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorCarlos Maniero <carlos@maniero.me>2023-05-10 16:07:39 -0300
committerCarlos Maniero <carlos@maniero.me>2023-05-10 17:35:03 -0300
commit75639fbf01bd6ae1212521b6cf822025eb8b598d (patch)
tree49709154c437cfbc01568f1e0c9abc8574fd3a54 /test
parent2cf0bcb409f3a1fd298b664103d57c945c6349f5 (diff)
namespaces: Add a namespace structure that represents a file
We have been always parsing a single function. Since we want to have multiple functions in a near future, this patch introduces an namespace that represents an entire file. To ensure a function is defined inside a namespace, a helper function was created. Today our ast_node structure is highly exposed, and this is something that Johnny and I have been discussed. So then, this is a first step to try to protected the code generation from our ast tree. Signed-off-by: Carlos Maniero <carlos@maniero.me>
Diffstat (limited to 'test')
-rw-r--r--test/parser_test.c12
1 files changed, 5 insertions, 7 deletions
diff --git a/test/parser_test.c b/test/parser_test.c
index 8565dc8..78e2e23 100644
--- a/test/parser_test.c
+++ b/test/parser_test.c
@@ -64,17 +64,15 @@ test_parse_function(const MunitParameter params[], void *user_data_or_fixture)
lexer_t lexer;
scope_t *scope = scope_new();
- make_lexer_from_static_src(&lexer, "fn main(): i32 { \nreturn 42;\n }");
+ make_lexer_from_static_src(&lexer, "fn add(): i32 { return 2; } fn main(): i32 { \nreturn 42;\n }");
parser_init(&parser, &lexer, scope);
- ast_node_t *ast_function = parser_parse_function_declaration(&parser);
+ ast_node_t *ast_ns = parser_parse_ns(&parser);
- assert_not_null(ast_function);
+ assert_not_null(ast_ns);
- char actual[5];
+ ast_node_t *ast_function = ast_node_ns_get_function_node_by_name(ast_ns, "main");
- string_view_to_str(&ast_function->data.function.identifier.name, actual);
- assert_string_equal("main", actual);
- assert_int(AST_FUNCTION_DECLARATION, ==, ast_function->kind);
+ assert_not_null(ast_function);
ast_node_t *ast_return = vector_at(ast_function->data.function.body->data.block.body, 0);