diff options
Diffstat (limited to 'tests/features')
| -rw-r--r-- | tests/features/test_concurrency_suite.zc | 2 | ||||
| -rw-r--r-- | tests/features/test_const_def.zc | 32 | ||||
| -rw-r--r-- | tests/features/test_match_ref.zc | 2 | ||||
| -rw-r--r-- | tests/features/test_operators_suite.zc | 2 |
4 files changed, 35 insertions, 3 deletions
diff --git a/tests/features/test_concurrency_suite.zc b/tests/features/test_concurrency_suite.zc index 836594d..aa7512a 100644 --- a/tests/features/test_concurrency_suite.zc +++ b/tests/features/test_concurrency_suite.zc @@ -59,7 +59,7 @@ test "test_thread" { c.val = 0; c.lock = Mutex::new(); - const N = 10000; + def N = 10000; var t1_res = Thread::spawn(fn() { for (var i=0; i<N; ++i) { 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 diff --git a/tests/features/test_match_ref.zc b/tests/features/test_match_ref.zc index cdd0835..0442dc7 100644 --- a/tests/features/test_match_ref.zc +++ b/tests/features/test_match_ref.zc @@ -50,7 +50,7 @@ enum Test { } test "match ref binding concrete" { - const t = Test::ONE(Hello{ world: 123 }); + var t = Test::ONE(Hello{ world: 123 }); var val = 0; match t { diff --git a/tests/features/test_operators_suite.zc b/tests/features/test_operators_suite.zc index 68b73fe..cf0f4c2 100644 --- a/tests/features/test_operators_suite.zc +++ b/tests/features/test_operators_suite.zc @@ -93,7 +93,7 @@ test "test_operator_overloading" { f1 |= f2; "Result bits: {f1.bits} (Expected 5)"; - const MAX_LIMIT = 100; + def MAX_LIMIT = 100; } test "test_extended_overloading" { |
