diff options
| author | hachem <im@hachem.wtf> | 2026-08-31 17:55:16 +0200 |
|---|---|---|
| committer | hachem <im@hachem.wtf> | 2026-08-31 17:55:16 +0200 |
| commit | cbdb9073480c3e4d8a088b306c23406cf42e25c0 (patch) | |
| tree | 39f3093654cc8f27ea701ed1338cac84d93f42eb /tests/sema_test.c | |
| parent | 53aed3fadf1f7ad66dea9a8a0b46bf42eda921be (diff) | |
feat: hex/binary integer literals and constant-folding const expressions
Diffstat (limited to 'tests/sema_test.c')
| -rw-r--r-- | tests/sema_test.c | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/tests/sema_test.c b/tests/sema_test.c index 2757e6c..2d6e187 100644 --- a/tests/sema_test.c +++ b/tests/sema_test.c @@ -76,6 +76,21 @@ static void test_assign_to_const(struct TestContext* context) check(context, !analyze_source("const K = 5\nproc main\n{\nK = 1\n}\n")); } +static void test_const_expr_ok(struct TestContext* context) +{ + check(context, analyze_source("const A = 1\nconst B = A + 2 * 3\nproc main\n{\nsyscall\n}\n")); +} + +static void test_const_expr_rejects_register(struct TestContext* context) +{ + check(context, !analyze_source("const X = rax + 1\nproc main\n{\nsyscall\n}\n")); +} + +static void test_const_expr_rejects_data(struct TestContext* context) +{ + check(context, !analyze_source("data d = \"x\"\nconst X = d\nproc main\n{\nsyscall\n}\n")); +} + static void test_deref_needs_register(struct TestContext* context) { check(context, !analyze_source("proc main\n{\nrax = ^MISSING\n}\n")); @@ -114,6 +129,9 @@ void run_sema_tests(struct TestContext* context) test_undefined_call(context); test_call_arg_count(context); test_assign_to_const(context); + test_const_expr_ok(context); + test_const_expr_rejects_register(context); + test_const_expr_rejects_data(context); test_deref_needs_register(context); test_references_resolve(context); } |
