summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorZuhaitz Méndez Fernández de Aránguiz <zuhaitz@debian>2026-01-24 00:09:29 +0000
committerZuhaitz Méndez Fernández de Aránguiz <zuhaitz@debian>2026-01-24 00:09:29 +0000
commit27d041865d17a4055e7e6b3e297656d6f35a0f3b (patch)
tree8fe0cbd2fecf24a6da3150dc4a2666a1c6dec0c3 /tests
parent1991cb62d26b954e54cf13c2d765fb3a0bbaa3ca (diff)
Welcome to 'def' + changed 'const'
Diffstat (limited to 'tests')
-rw-r--r--tests/features/test_concurrency_suite.zc2
-rw-r--r--tests/features/test_const_def.zc32
-rw-r--r--tests/features/test_match_ref.zc2
-rw-r--r--tests/features/test_operators_suite.zc2
-rw-r--r--tests/memory/test_memory_safety.zc6
5 files changed, 38 insertions, 6 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" {
diff --git a/tests/memory/test_memory_safety.zc b/tests/memory/test_memory_safety.zc
index 020a7ba..c7ba01d 100644
--- a/tests/memory/test_memory_safety.zc
+++ b/tests/memory/test_memory_safety.zc
@@ -189,9 +189,9 @@ test "test_immutable" {
}
test "test_permissions" {
- const READ : U8 = 0b100;
- const WRITE : U8 = 0b010;
- const EXEC : U8 = 0b001;
+ def READ : U8 = 0b100;
+ def WRITE : U8 = 0b010;
+ def EXEC : U8 = 0b001;
var p1 = Permissions::new(READ);
"Start: {p1.mask} (Read)";