test: sema + codegen 测试补全 — 86 单元测试

- test_sema: +4 测试 (let_mut_assign_ok, assign_immutable_error, str_type_ok, str_concat_ok) → 21 tests
- test_codegen: +1 测试 (while_loop LLVMVerifyModule) → 9 tests
- 总单元测试: 86 (词法41+语法15+语义21+代码生成9)
- 基于 Codex 分析报告 §5-3 §5-4 技术债务补偿
This commit is contained in:
2026-06-05 06:34:45 +08:00
parent 8144f1bfd7
commit 382cd089d0
2 changed files with 94 additions and 0 deletions
+26
View File
@@ -88,9 +88,35 @@ void test_codegen_binary_ops() {
arena_destroy(&a);
}
void test_codegen_while_loop() {
Arena a = arena_create(1);
// fn main() -> i64 { while true { return 0; } return 1; }
AstNode* while_body_stmts[] = {
ast_make_return(&a, ast_make_literal_i64(&a, 0, 1, 1), 1, 1)
};
AstNode* while_body = ast_make_block(&a, while_body_stmts, 1, 1, 1);
AstNode* while_stmt = ast_make_while(&a,
ast_make_literal_bool(&a, true, 1, 1), while_body, 1, 1);
AstNode* ret = ast_make_return(&a, ast_make_literal_i64(&a, 1, 1, 1), 1, 1);
AstNode* stmts[] = { while_stmt, ret };
AstNode* fn_body = ast_make_block(&a, stmts, 2, 1, 1);
AstNode* fn = ast_make_function(&a, "main", NULL, 0, TYPE_I64, fn_body, 1, 1);
AstNode* fns[] = { fn };
AstNode* prog = ast_make_program(&a, fns, 1, 1, 1);
const char* err = NULL;
LLVMModuleRef mod = codegen_module(prog, &a, "test_while", &err);
ASSERT(mod != NULL);
char* verify_err = NULL;
ASSERT(!LLVMVerifyModule(mod, LLVMReturnStatusAction, &verify_err));
LLVMDisposeModule(mod);
arena_destroy(&a);
}
int main(void) {
TEST_RUN(test_codegen_simple_function);
TEST_RUN(test_codegen_if_else);
TEST_RUN(test_codegen_binary_ops);
TEST_RUN(test_codegen_while_loop);
return test_summary();
}