diff options
Diffstat (limited to 'tests/features/test_const_def.zc')
| -rw-r--r-- | tests/features/test_const_def.zc | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/tests/features/test_const_def.zc b/tests/features/test_const_def.zc new file mode 100644 index 0000000..b104196 --- /dev/null +++ b/tests/features/test_const_def.zc @@ -0,0 +1,32 @@ + +test "def_constants" { + def PI = 3.14159; + def MAX = 100; + + assert(MAX == 100, "def constant value mismatch"); + // PI check (float) - exact match might be tricky but 3.14159 is literal + + var x = MAX; + assert(x == 100, "Assign from def"); +} + +test "def_scoping" { + def VAL = 1; + { + def VAL = 2; // Shadowing + assert(VAL == 2, "Shadowed def"); + } + assert(VAL == 1, "Original def preserved"); +} + +test "const_type_qualifier" { + var x: const int = 10; + assert(x == 10, "const Var init"); + + // Address of const var should be allowed + var p: const int* = &x; + assert(*p == 10, "Pointer to const var"); +} + +// Note: Negative tests (compilation failures) are hard to test in this harness currently +// but we verified the logic in parser_expr.c |
