summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorZuhaitz Méndez Fernández de Aránguiz <zuhaitz@debian>2026-01-14 23:59:54 +0000
committerZuhaitz Méndez Fernández de Aránguiz <zuhaitz@debian>2026-01-14 23:59:54 +0000
commitdcfdc053cb5f9fb4d5eac0a2233c75126b7a8188 (patch)
treef34f30b382fa22d6fd0af46875a5b4b26d00feff /tests
parenta918df69269a39ef7350a645b5db025d66ecb18a (diff)
Added some of the tests.
Diffstat (limited to 'tests')
-rw-r--r--tests/basic/test_basics.zc10
-rw-r--r--tests/collections/test_string_suite.zc115
-rw-r--r--tests/collections/test_vec_suite.zc177
-rw-r--r--tests/control_flow/test_computed_goto.zc23
-rw-r--r--tests/control_flow/test_goto.zc22
-rw-r--r--tests/control_flow/test_guard_unless.zc59
-rw-r--r--tests/control_flow/test_if.zc20
-rw-r--r--tests/control_flow/test_labeled_break.zc27
-rw-r--r--tests/control_flow/test_loop_edge_cases.zc99
-rw-r--r--tests/control_flow/test_loops.zc133
-rw-r--r--tests/control_flow/test_match.zc91
-rw-r--r--tests/control_flow/test_ternary.zc30
-rw-r--r--tests/features/test_asm.zc54
-rw-r--r--tests/features/test_build_directives.zc19
-rw-r--r--tests/features/test_comptime_suite.zc29
-rw-r--r--tests/features/test_concurrency_suite.zc98
-rw-r--r--tests/features/test_destructuring.zc38
-rw-r--r--tests/features/test_embed.zc57
-rw-r--r--tests/features/test_intel.zc22
-rw-r--r--tests/features/test_operators_suite.zc144
-rw-r--r--tests/features/test_traits_suite.zc104
-rw-r--r--tests/functions/test_attributes.zc122
-rw-r--r--tests/functions/test_implicit_return.zc18
-rw-r--r--tests/functions/test_lambda_arrow.zc20
-rw-r--r--tests/functions/test_lambdas.zc78
-rw-r--r--tests/functions/test_must_use.zc47
-rw-r--r--tests/functions/test_varargs.zc10
-rw-r--r--tests/generics/test_generics_fn.zc25
-rw-r--r--tests/generics/test_generics_struct.zc14
-rw-r--r--tests/interop/test_c_import.zc26
-rw-r--r--tests/interop/test_c_macros.zc22
-rw-r--r--tests/memory/test_memory_safety.zc217
-rw-r--r--tests/memory/test_unsafe.zc56
-rw-r--r--tests/misc/test_advanced.zc211
-rw-r--r--tests/misc/test_chained.zc14
-rw-r--r--tests/misc/test_edge_cases.zc151
-rw-r--r--tests/misc/test_mix.zc61
-rw-r--r--tests/modules/test_aliasing.zc13
-rw-r--r--tests/modules/test_modules/math.zc19
-rw-r--r--tests/modules/test_modules/physics.zc17
-rw-r--r--tests/modules/test_modules/simple.zc3
-rw-r--r--tests/modules/test_namespaced.zc16
-rwxr-xr-xtests/run_tests.sh4
43 files changed, 2533 insertions, 2 deletions
diff --git a/tests/basic/test_basics.zc b/tests/basic/test_basics.zc
new file mode 100644
index 0000000..d54389b
--- /dev/null
+++ b/tests/basic/test_basics.zc
@@ -0,0 +1,10 @@
+
+test "test_hello" {
+ println "It works!";
+}
+
+test "test_vars" {
+ var x = 10;
+ var y: int = 20;
+ println "Sum: {x + y}";
+}
diff --git a/tests/collections/test_string_suite.zc b/tests/collections/test_string_suite.zc
new file mode 100644
index 0000000..4231497
--- /dev/null
+++ b/tests/collections/test_string_suite.zc
@@ -0,0 +1,115 @@
+
+include <string.h>
+include <stdio.h>
+import "std.zc"
+
+test "test_string_methods" {
+ println "Testing String methods...";
+
+ // Substring
+ var s1: String = String::from("Hello World");
+ var sub: String = String_substring(&s1, 0, 5);
+ var expected1: String = String::from("Hello");
+ if (String_eq(&sub, expected1)) {
+ println " -> substring(0, 5): Passed";
+ } else {
+ assert(false, "substring(0, 5) failed");
+ }
+
+ // Substring middle
+ var sub2: String = String_substring(&s1, 6, 5);
+ var expected2: String = String::from("World");
+ if (String_eq(&sub2, expected2)) {
+ println " -> substring(6, 5): Passed";
+ } else {
+ assert(false, "substring(6, 5) failed");
+ }
+
+ // Find character - found
+ var pos: Option<usize> = String_find(&s1, 'W');
+ if (Option_size_t_is_some(&pos)) {
+ var idx: usize = Option_size_t_unwrap(&pos);
+ assert(idx == (usize)6, "find('W') index mismatch");
+ println " -> find('W'): Passed (found at index 6)";
+ } else {
+ assert(false, "find('W') failed (not found)");
+ }
+
+ // Find character - not found
+ var pos2: Option<usize> = String_find(&s1, 'Z');
+ if (Option_size_t_is_none(&pos2)) {
+ println " -> find('Z'): Passed (not found)";
+ } else {
+ assert(false, "find('Z') failed (found unexpectedly)");
+ }
+
+ // Length
+ var len: usize = String_length(&s1);
+ if (len == (usize)11) {
+ println " -> length(): Passed (11)";
+ } else {
+ assert(false, "length() failed");
+ }
+
+ // Contains
+ if (s1.contains('W')) {
+ println " -> contains('W'): Passed";
+ } else {
+ assert(false, "contains('W') failed");
+ }
+
+ if (!s1.contains('Z')) {
+ println " -> !contains('Z'): Passed";
+ } else {
+ assert(false, "!contains('Z') failed");
+ }
+
+ // Append
+ var s2: String = String::from("Hello");
+ var s3: String = String::from(" World");
+ String_append(&s2, s3);
+ var expected6: String = String::from("Hello World");
+ if (String_eq(&s2, expected6)) {
+ println " -> append(): Passed";
+ } else {
+ assert(false, "append() failed");
+ }
+
+ println "All String methods passed!";
+}
+
+test "test_fstrings_return" {
+ println "Testing F-Strings and Returns...";
+ var x = 100;
+ var y = 50;
+
+ println "Direct F-String: x={x}";
+ var nested = f"y is {y}";
+ println "Argument F-String: {nested}";
+ println "Math inside: 100 + 50 = {x + y}";
+
+ var inner = f"Inner({x})";
+ var outer = f"Outer({inner})";
+ println "Composed: {outer}";
+ assert(strcmp(outer, "Outer(Inner(100))") == 0, "Composed f-string failed");
+}
+
+test "test_string_std_ops" {
+ println "Testing String Std Ops...";
+ var s1 = String::from("Hello");
+ var s2 = String::from(" World");
+
+ var s3 = s1 + s2;
+
+ print "Concatenated: ";
+ s3.println();
+
+ assert(s3.length() == 11, "Length mismatch");
+
+ var s4 = String::from("Hello World");
+ if (s3.eq(s4)) {
+ println "Equality check passed: Strings are identical.";
+ } else {
+ assert(false, "Equality check failed");
+ }
+}
diff --git a/tests/collections/test_vec_suite.zc b/tests/collections/test_vec_suite.zc
new file mode 100644
index 0000000..9722972
--- /dev/null
+++ b/tests/collections/test_vec_suite.zc
@@ -0,0 +1,177 @@
+
+import "std.zc"
+
+@derive(Eq, Clone)
+struct Point {
+ x: int;
+ y: int;
+}
+
+test "test_vec_methods" {
+ println "Testing Vec methods...";
+
+ // Insert at beginning
+ var v = Vec<int>::new();
+ v.push(10);
+ v.push(20);
+ v.push(30);
+ v.insert(0, 5);
+
+ if (v.get(0) == 5 && v.get(1) == 10 && v.length() == 4) {
+ println " -> insert(0, 5): Passed";
+ } else {
+ assert(false, "insert(0, 5) failed");
+ }
+
+ // Insert in middle
+ v.insert(2, 15);
+ if (v.get(2) == 15 && v.get(3) == 20 && v.length() == 5) {
+ println " -> insert(2, 15): Passed";
+ } else {
+ assert(false, "insert(2, 15) failed");
+ }
+
+ // Insert at end
+ v.insert(5, 35);
+ if (v.get(5) == 35 && v.length() == 6) {
+ println " -> insert(5, 35): Passed";
+ } else {
+ assert(false, "insert(5, 35) failed");
+ }
+
+ // Remove from beginning
+ var removed = v.remove(0);
+ if (removed == 5 && v.get(0) == 10 && v.length() == 5) {
+ println " -> remove(0): Passed";
+ } else {
+ assert(false, "remove(0) failed");
+ }
+
+ // Remove from middle
+ var removed2 = v.remove(1);
+ if (removed2 == 15 && v.get(1) == 20 && v.length() == 4) {
+ println " -> remove(1): Passed";
+ } else {
+ assert(false, "remove(1) failed");
+ }
+
+ // Remove from end
+ var removed3 = v.remove(3);
+ if (removed3 == 35 && v.length() == 3) {
+ println " -> remove(3): Passed";
+ } else {
+ assert(false, "remove(3) failed");
+ }
+
+ // Verify final state
+ if (v.get(0) == 10 && v.get(1) == 20 && v.get(2) == 30) {
+ println " -> final state: Passed";
+ } else {
+ assert(false, "final state failed");
+ }
+
+ println "All Vec methods passed!";
+}
+
+test "test_vec_extensions" {
+ println "Testing Vec extensions (pop, clear, etc)...";
+ var v = Vec<int>::new();
+ v.push(10);
+ v.push(20);
+ v.push(30);
+
+ assert(v.length() == 3, "Length should be 3");
+ assert(v.last() == 30, "Last should be 30");
+
+ var popped = v.pop();
+ println "Popped: {popped}";
+ assert(popped == 30, "Popped value mismatch");
+ assert(v.length() == 2, "Length after pop mismatch");
+
+ assert(!v.is_empty(), "Vector should not be empty");
+
+ v.clear();
+ assert(v.is_empty(), "Vector should be empty after clear");
+ assert(v.length() == 0, "Length should be 0");
+
+ v.free();
+}
+
+test "test_vec_basic" {
+ var v = Vec<int>::new();
+ v.push(10);
+ v.push(10);
+ v.push(20);
+ var v0 = v.get(0);
+ var v1 = v.get(1);
+ println "Vec: {v0}, {v1}";
+
+ var s1 = String::from("Hello ");
+ var s2 = String::from("World");
+ var s3 = s1 + s2;
+
+ println "{s3.c_str()}";
+}
+
+test "test_vec_clone" {
+ var v = Vec<int>::new();
+ v.push(10);
+ v.push(20);
+ v.push(30);
+
+ println "Vec has {(int)v.len} elements";
+ println "First: {v.first()}";
+ println "Last: {v.last()}";
+
+ v.free();
+ "Done";
+}
+
+test "test_vec_contains" {
+ println "Testing Vec::contains with structs...";
+
+ var v = Vec<Point>::new();
+ v.push(Point { x: 1, y: 2 });
+ v.push(Point { x: 3, y: 4 });
+
+ var p1 = Point { x: 1, y: 2 };
+ if (v.contains(p1)) {
+ println " -> contains((1, 2)): Passed";
+ } else {
+ assert(false, "contains({1, 2}) failed");
+ }
+
+ var p2 = Point { x: 3, y: 4 };
+ if (v.contains(p2)) {
+ println " -> contains((3, 4)): Passed";
+ } else {
+ assert(false, "contains({3, 4}) failed");
+ }
+
+ var p3 = Point { x: 5, y: 6 };
+ if (!v.contains(p3)) {
+ println " -> !contains((5, 6)): Passed";
+ } else {
+ assert(false, "!contains({5, 6}) failed");
+ }
+
+ var vi = Vec<int>::new();
+ vi.push(10);
+ vi.push(20);
+
+ if (vi.contains(10)) {
+ println " -> Vec<int>::contains(10): Passed";
+ } else {
+ assert(false, "Vec<int>::contains(10) failed");
+ }
+
+ if (!vi.contains(30)) {
+ println " -> !Vec<int>::contains(30): Passed";
+ } else {
+ assert(false, "!Vec<int>::contains(30) failed");
+ }
+
+ v.free();
+ vi.free();
+ println "All tests passed!";
+}
diff --git a/tests/control_flow/test_computed_goto.zc b/tests/control_flow/test_computed_goto.zc
new file mode 100644
index 0000000..12b484c
--- /dev/null
+++ b/tests/control_flow/test_computed_goto.zc
@@ -0,0 +1,23 @@
+
+test "test_computed_goto" -> int {
+ var x = 0;
+
+ // Get address of label using && unary operator
+ var target = &&label_B;
+
+ // Jump to label A first
+ goto label_A;
+
+ label_A:
+ x = x + 1;
+ // Computed goto: goto *ptr
+ goto *target;
+
+ label_B:
+ x = x + 10;
+ goto label_C;
+
+ label_C:
+ if (x != 11) exit(1);
+
+}
diff --git a/tests/control_flow/test_goto.zc b/tests/control_flow/test_goto.zc
new file mode 100644
index 0000000..9a90139
--- /dev/null
+++ b/tests/control_flow/test_goto.zc
@@ -0,0 +1,22 @@
+
+test "test_goto" -> int {
+ var x = 0;
+
+ goto skip;
+ x = 100;
+
+skip:
+ assert x == 0;
+
+ var resource = 1;
+
+ if resource == 1 {
+ goto cleanup;
+ }
+
+ assert false;
+
+cleanup:
+ assert true;
+
+}
diff --git a/tests/control_flow/test_guard_unless.zc b/tests/control_flow/test_guard_unless.zc
new file mode 100644
index 0000000..d759551
--- /dev/null
+++ b/tests/control_flow/test_guard_unless.zc
@@ -0,0 +1,59 @@
+
+fn check_positive(x: int) -> int {
+ unless x > 0 {
+ return -1;
+ }
+ return x * 2;
+}
+
+fn safe_access(ptr: int*) -> int {
+ guard ptr != NULL else {
+ return -999;
+ }
+ return *ptr;
+}
+
+test "test_guard_unless" {
+ println "Testing guard and unless...";
+
+ // Unless with true condition (should NOT enter block)
+ var res1 = check_positive(10);
+ if (res1 == 20) {
+ println " -> unless (pass condition): Passed";
+ } else {
+ println " -> unless (pass condition): Failed";
+ exit(1);
+ }
+
+ // Unless with false condition (should enter block)
+ var res2 = check_positive(-5);
+ if (res2 == -1) {
+ println " -> unless (fail condition): Passed";
+ } else {
+ println " -> unless (fail condition): Failed";
+ exit(1);
+ }
+
+ // Guard with valid pointer
+ var val = 42;
+ var p = &val;
+ var res3 = safe_access(p);
+ if (res3 == 42) {
+ println " -> guard (valid ptr): Passed";
+ } else {
+ println " -> guard (valid ptr): Failed";
+ exit(1);
+ }
+
+ // Guard with null pointer
+ var res4 = safe_access(NULL);
+ if (res4 == -999) {
+ println " -> guard (null ptr): Passed";
+ } else {
+ println " -> guard (null ptr): Failed";
+ exit(1);
+ }
+
+ println "All guard/unless tests passed!";
+
+}
diff --git a/tests/control_flow/test_if.zc b/tests/control_flow/test_if.zc
new file mode 100644
index 0000000..463405a
--- /dev/null
+++ b/tests/control_flow/test_if.zc
@@ -0,0 +1,20 @@
+
+test "test_if" {
+ var x = 10;
+
+ if (x > 5) {
+ printf("X is big\n");
+ var y = x * 2;
+ if (y > 15) {
+ printf("Y is very big\n");
+ }
+ } else {
+ printf("X is small\n");
+ }
+
+ var i = 0;
+ while (i < 3) {
+ println "Loop {i}";
+ i++;
+ }
+}
diff --git a/tests/control_flow/test_labeled_break.zc b/tests/control_flow/test_labeled_break.zc
new file mode 100644
index 0000000..1900a99
--- /dev/null
+++ b/tests/control_flow/test_labeled_break.zc
@@ -0,0 +1,27 @@
+
+test "test_labeled_break" -> int {
+ // Test basic goto-based loop exit
+ var result = 0;
+
+ for i in 0..10 {
+ for j in 0..10 {
+ if i == 3 {
+ goto done_search;
+ }
+ }
+ result++;
+ }
+done_search:
+
+ assert result == 3;
+
+ // Test do-while
+ var x = 0;
+ do {
+ x++;
+ } while x < 3;
+
+ assert x == 3;
+
+
+}
diff --git a/tests/control_flow/test_loop_edge_cases.zc b/tests/control_flow/test_loop_edge_cases.zc
new file mode 100644
index 0000000..b5ab0ce
--- /dev/null
+++ b/tests/control_flow/test_loop_edge_cases.zc
@@ -0,0 +1,99 @@
+
+test "test_loop_edge_cases" {
+ println "Testing loop edge cases...";
+
+ // Empty range (0..0 should not iterate)
+ var count1 = 0;
+ for i in 0..0 {
+ count1++;
+ }
+ if (count1 == 0) {
+ println " -> Empty range (0..0): Passed";
+ } else {
+ println " -> Empty range (0..0): Failed";
+ exit(1);
+ }
+
+ // Single iteration range (0..1)
+ var count2 = 0;
+ for i in 0..1 {
+ count2++;
+ }
+ if (count2 == 1) {
+ println " -> Single iteration (0..1): Passed";
+ } else {
+ println " -> Single iteration (0..1): Failed";
+ exit(1);
+ }
+
+ // Repeat 0 times (should not execute)
+ var count3 = 0;
+ repeat 0 {
+ count3++;
+ }
+ if (count3 == 0) {
+ println " -> Repeat 0 times: Passed";
+ } else {
+ println " -> Repeat 0 times: Failed";
+ exit(1);
+ }
+
+ // Repeat 1 time
+ var count4 = 0;
+ repeat 1 {
+ count4++;
+ }
+ if (count4 == 1) {
+ println " -> Repeat 1 time: Passed";
+ } else {
+ println " -> Repeat 1 time: Failed";
+ exit(1);
+ }
+
+ // Nested loops
+ var total = 0;
+ for i in 0..3 {
+ for j in 0..2 {
+ total = total + 1;
+ }
+ }
+ if (total == 6) {
+ println " -> Nested for-in loops: Passed";
+ } else {
+ println " -> Nested for-in loops: Failed";
+ exit(1);
+ }
+
+ // Break in nested loop
+ var outer_count = 0;
+ for i in 0..3 {
+ outer_count = outer_count + 1;
+ var inner_done = 0;
+ loop {
+ inner_done = inner_done + 1;
+ if (inner_done >= 2) {
+ break;
+ }
+ }
+ }
+ if (outer_count == 3) {
+ println " -> Nested loop with break: Passed";
+ } else {
+ println " -> Nested loop with break: Failed";
+ exit(1);
+ }
+
+ // Large step value
+ var count7 = 0;
+ for i in 0..100 step 25 {
+ count7++;
+ }
+ if (count7 == 4) {
+ println " -> Large step value (step 25): Passed";
+ } else {
+ println " -> Large step value: Failed";
+ exit(1);
+ }
+
+ println "All loop edge cases passed!";
+}
diff --git a/tests/control_flow/test_loops.zc b/tests/control_flow/test_loops.zc
new file mode 100644
index 0000000..9968cf5
--- /dev/null
+++ b/tests/control_flow/test_loops.zc
@@ -0,0 +1,133 @@
+
+test "test_loops" {
+ println "Testing loop constructs...";
+
+ // for-in range
+ var sum1 = 0;
+ for i in 0..5 {
+ sum1 += i;
+ }
+ assert(sum1 == 10, "for-in range (0..5) failed");
+ println " -> for-in range (0..5): Passed";
+
+ // for-in with step
+ var sum2 = 0;
+ for i in 0..10 step 2 {
+ sum2 += i;
+ }
+ assert(sum2 == 20, "for-in with step failed");
+ println " -> for-in with step: Passed";
+
+ // Repeat n times
+ var count = 0;
+ repeat 7 {
+ count++;
+ }
+ assert(count == 7, "repeat 7 failed");
+ println " -> repeat 7: Passed";
+
+ // loop with break
+ var i = 0;
+ loop {
+ i++;
+ if (i >= 5) {
+ break;
+ }
+ }
+ assert(i == 5, "loop with break failed");
+ println " -> loop with break: Passed";
+
+ // While loop
+ var j = 0;
+ while j < 3 {
+ j++;
+ }
+ assert(j == 3, "while loop failed");
+ println " -> while loop: Passed";
+
+ // C-style for loop
+ var sum3 = 0;
+ for (var k = 0; k < 4; k = k + 1) {
+ sum3 += k;
+ }
+ assert(sum3 == 6, "C-style for loop failed");
+ println " -> C-style for loop: Passed";
+
+ // loop with continue
+ var sum4 = 0;
+ var m = 0;
+ loop {
+ m++;
+ if (m == 3) {
+ continue;
+ }
+ if (m > 5) {
+ break;
+ }
+ sum4 += m;
+ }
+ assert(sum4 == 12, "loop with continue failed");
+ println " -> loop with continue: Passed";
+
+ println "All loop tests passed!";
+
+}
+
+}
+
+fn print_nums(list: [int]) {
+ var i = 0;
+ while (i < list.len) {
+ println "Num: {list.data[i]}";
+ i++;
+ }
+}
+
+test "test_arrays_loop" {
+ // Array literal transformation
+ var nums: [int] = [10, 20, 30];
+ print_nums(nums);
+}
+
+test "test_do_while" {
+ var x = 0;
+
+ // Basic do-while (runs at least once)
+ do {
+ x++;
+ } while x < 5;
+
+ assert(x == 5, "do-while x expected 5");
+
+ // Do-while with false condition (still runs once)
+ var y = 0;
+ do {
+ y = 100;
+ } while false;
+
+ assert(y == 100, "do-while false expected 100");
+}
+
+test "test_range_loops_generic" {
+ println "Testing range loops with different types...";
+
+ // Test with isize variables
+ var sum_isize: isize = 0;
+ var start: isize = 0;
+ var end: isize = 5;
+ for var i: isize = start; i < end; i++ {
+ sum_isize += i;
+ }
+ println "isize range (0..5): sum = {sum_isize}";
+ assert(sum_isize == 10, "isize range failed");
+
+ // Test with regular int
+ var sum_int = 0;
+ for i in 0..5 {
+ sum_int += i;
+ }
+ println "int range (0..5): sum = {sum_int}";
+ assert(sum_int == 10, "int range failed");
+
+ "-> Range loops work with any integer type!";
+}
diff --git a/tests/control_flow/test_match.zc b/tests/control_flow/test_match.zc
new file mode 100644
index 0000000..7646256
--- /dev/null
+++ b/tests/control_flow/test_match.zc
@@ -0,0 +1,91 @@
+
+fn classify_number(n: int) -> int {
+ match n {
+ 0 => { return 100; },
+ 1 => { return 200; },
+ 2 => { return 300; },
+ _ => { return -1; }
+ }
+}
+
+fn get_sign(n: int) -> string {
+ match n {
+ 0 => { return "zero"; },
+ _ => {
+ if (n > 0) {
+ return "positive";
+ }
+ return "negative";
+ }
+ }
+}
+
+test "test_match" {
+ println "Testing match expressions...";
+
+ // Match with exact value (0)
+ var res1 = classify_number(0);
+ if (res1 == 100) {
+ println " -> match 0: Passed";
+ } else {
+ println " -> match 0: Failed";
+ exit(1);
+ }
+
+ // Match with exact value (1)
+ var res2 = classify_number(1);
+ if (res2 == 200) {
+ println " -> match 1: Passed";
+ } else {
+ println " -> match 1: Failed";
+ exit(1);
+ }
+
+ // Match with exact value (2)
+ var res3 = classify_number(2);
+ if (res3 == 300) {
+ println " -> match 2: Passed";
+ } else {
+ println " -> match 2: Failed";
+ exit(1);
+ }
+
+ // Match with default case
+ var res4 = classify_number(99);
+ if (res4 == -1) {
+ println " -> match default: Passed";
+ } else {
+ println " -> match default: Failed";
+ exit(1);
+ }
+
+ // Match with complex body (zero)
+ var sign1 = get_sign(0);
+ if (strcmp(sign1, "zero") == 0) {
+ println " -> match complex (zero): Passed";
+ } else {
+ println " -> match complex (zero): Failed";
+ exit(1);
+ }
+
+ // Match with complex body (positive)
+ var sign2 = get_sign(42);
+ if (strcmp(sign2, "positive") == 0) {
+ println " -> match complex (positive): Passed";
+ } else {
+ println " -> match complex (positive): Failed";
+ exit(1);
+ }
+
+ // Match with complex body (negative)
+ var sign3 = get_sign(-10);
+ if (strcmp(sign3, "negative") == 0) {
+ println " -> match complex (negative): Passed";
+ } else {
+ println " -> match complex (negative): Failed";
+ exit(1);
+ }
+
+ println "All match tests passed!";
+
+}
diff --git a/tests/control_flow/test_ternary.zc b/tests/control_flow/test_ternary.zc
new file mode 100644
index 0000000..cfac28b
--- /dev/null
+++ b/tests/control_flow/test_ternary.zc
@@ -0,0 +1,30 @@
+
+enum Result {
+ Ok(int),
+ Err(int)
+}
+
+fn test_unwrap() -> Result {
+ var res = Result_Ok(42);
+ var val = res?;
+ if (val == 42) println " Unwrap: Success";
+ else println " Unwrap: Failed";
+ return res;
+}
+
+test "test_ternary" {
+ println "Testing Ternary...";
+
+ // Simple Ternary
+ var x = 1 ? 10 : 20;
+ if (x == 10) println " Simple Ternary: Success";
+ else println " Simple Ternary: Failed";
+
+ // Simple Unwrap
+ test_unwrap();
+
+ // Ambiguity / Precredence
+ // 1 ? 2 : 3
+ var y = 0 ? 100 : 200;
+ if (y == 200) println " False Branch: Success";
+}
diff --git a/tests/features/test_asm.zc b/tests/features/test_asm.zc
new file mode 100644
index 0000000..01f35d5
--- /dev/null
+++ b/tests/features/test_asm.zc
@@ -0,0 +1,54 @@
+fn test_nop() {
+ asm { nop }
+}
+
+fn test_pause() {
+ asm { pause }
+}
+
+fn test_multiline() {
+ asm {
+ mov $1, %rax
+ mov $2, %rbx
+ add %rbx, %rax
+ }
+}
+
+fn test_volatile() {
+ asm volatile {
+ mfence
+ }
+}
+
+test "test_asm" {
+ println "Testing inline assembly...";
+
+ test_nop();
+ test_pause();
+ test_multiline();
+ test_volatile();
+
+ println "-> Assembly blocks compiled successfully!";
+}
+
+fn add_five(x: int) -> int {
+ var result: int;
+ asm {
+ "mov {x}, {result}"
+ "add $5, {result}"
+ : out(result)
+ : in(x)
+ }
+ return result;
+}
+
+test "test_asm_params" {
+ println "Testing assembly parameters...";
+ var val = add_five(10);
+ if (val == 15) {
+ println "-> Success! add_five(10) = 15";
+ } else {
+ println "-> Failed: expected 15, got {val}";
+ exit(1);
+ }
+}
diff --git a/tests/features/test_build_directives.zc b/tests/features/test_build_directives.zc
new file mode 100644
index 0000000..d6e35b3
--- /dev/null
+++ b/tests/features/test_build_directives.zc
@@ -0,0 +1,19 @@
+//> link: -lm
+//> cflags: -O2
+
+// Declare C math function (since we don't have a math stdlib module yet)
+extern fn sin(x: double) -> double;
+
+test "test_build_directives" {
+ println "Running Build Directives Test...";
+ var x = 3.14159 / 2.0; // PI/2
+ var s = sin(x);
+ // sin(PI/2) should be 1.0
+ println "sin(PI/2) = {s}";
+
+ if (s > 0.99 && s < 1.01) {
+ println "Math Link Success!";
+ } else {
+ println "Math Link Failure (Value wrong)";
+ }
+}
diff --git a/tests/features/test_comptime_suite.zc b/tests/features/test_comptime_suite.zc
new file mode 100644
index 0000000..b8127ec
--- /dev/null
+++ b/tests/features/test_comptime_suite.zc
@@ -0,0 +1,29 @@
+
+comptime {
+ printf("fn generated_func() {\n");
+ printf(" println \" I was generated at compile time!\";\n");
+ printf("}\n");
+}
+
+@comptime
+fn double_ct(x: int) -> int {
+ return x * 2;
+}
+
+test "test_comptime_block" {
+ println "Running Comptime Test...";
+ generated_func();
+ println "Comptime Test Complete.";
+}
+
+test "test_comptime_attr" {
+ var x = double_ct(21);
+ assert(x == 42, "Comptime function failed");
+ println "Comptime function called successfully";
+}
+
+test "test_comptime_fn" {
+ comptime {
+ println "println \"Hello from comptime fn!\";";
+ }
+}
diff --git a/tests/features/test_concurrency_suite.zc b/tests/features/test_concurrency_suite.zc
new file mode 100644
index 0000000..836594d
--- /dev/null
+++ b/tests/features/test_concurrency_suite.zc
@@ -0,0 +1,98 @@
+//> link: -lpthread
+import "std/thread.zc"
+
+async fn double_slowly(x: int) -> int {
+ usleep(1000);
+ return x * 2;
+}
+
+async fn add_async(a: int, b: int) -> int {
+ return a + b;
+}
+
+async fn say_hello() {
+ puts("Hello from async!");
+}
+
+struct Point {
+ x: int;
+ y: int;
+}
+
+async fn make_point(x: int, y: int) -> Point {
+ return Point{x: x, y: y};
+}
+
+struct Counter {
+ val: int;
+ lock: Mutex;
+}
+
+test "test_async_basics" {
+ var future1 = double_slowly(21);
+ var future2 = add_async(10, 20);
+
+ var result1 = await future1;
+ var result2 = await future2;
+
+ assert(result1 == 42, "Async double failed");
+ assert(result2 == 30, "Async add failed");
+}
+
+test "test_async_struct_return" {
+ var f = make_point(5, 7);
+ var p = await f;
+
+ assert(p.x == 5, "Async struct x failed");
+ assert(p.y == 7, "Async struct y failed");
+}
+
+test "test_async_void" {
+ var f = say_hello();
+ await f;
+}
+
+test "test_thread" {
+ println "Testing Concurrency...";
+
+ var c = (Counter*)malloc(sizeof(Counter));
+ c.val = 0;
+ c.lock = Mutex::new();
+
+ const N = 10000;
+
+ var t1_res = Thread::spawn(fn() {
+ for (var i=0; i<N; ++i) {
+ c.lock.lock();
+ c.val = c.val + 1;
+ c.lock.unlock();
+ }
+ });
+
+ var t2_res = Thread::spawn(fn() {
+ for (var i=0; i<N; ++i) {
+ c.lock.lock();
+ c.val = c.val + 1;
+ c.lock.unlock();
+ }
+ });
+
+ assert(t1_res.is_err() == false, "T1 failed to spawn");
+ assert(t2_res.is_err() == false, "T2 failed to spawn");
+
+ var t1 = t1_res.unwrap();
+ var t2 = t2_res.unwrap();
+
+ t1.join();
+ t2.join();
+
+ println "Final Count: {c.val} (Expected {2 * N})";
+
+ var final_val = c.val;
+
+ c.lock.free();
+ free(c);
+
+ assert(final_val == 2 * N, "Concurrency count mismatch");
+ println "Concurrency Test Passed!";
+}
diff --git a/tests/features/test_destructuring.zc b/tests/features/test_destructuring.zc
new file mode 100644
index 0000000..b898582
--- /dev/null
+++ b/tests/features/test_destructuring.zc
@@ -0,0 +1,38 @@
+struct Point {
+ x: int;
+ y: int;
+}
+
+struct Rect {
+ w: int;
+ h: int;
+}
+
+fn tuple_ret() -> (int, int) {
+ return (10, 20);
+}
+
+test "test_destructuring" {
+ var p = Point{x: 1, y: 2};
+
+ // Explicit Struct Destructuring (Shorthand)
+ var Point{x, y} = p;
+ assert(x == 1, "x is 1");
+ assert(y == 2, "y is 2");
+
+ // Explicit Struct Destructuring (Renamed)
+ var Point{x: a, y: b} = p;
+ assert(a == 1, "a is 1");
+ assert(b == 2, "b is 2");
+
+ // Anonymous Struct Destructuring (Inferred)
+ // Note: Anonymous block only supports shorthand {x, y} currently.
+ // var {x: x2} = p; // Not supported yet in anonymous block parser
+
+ // Tuple Destructuring
+ var (t1, t2) = tuple_ret();
+ assert(t1 == 10, "t1 is 10");
+ assert(t2 == 20, "t2 is 20");
+
+ println "Destructuring OK";
+}
diff --git a/tests/features/test_embed.zc b/tests/features/test_embed.zc
new file mode 100644
index 0000000..f6d9468
--- /dev/null
+++ b/tests/features/test_embed.zc
@@ -0,0 +1,57 @@
+
+test "test_embed" {
+ "=> Static File Analyzer";
+
+ var data = embed "std.zc";
+
+ "Target File: 'std.zc'";
+ "File Size: {data.len} bytes";
+ "";
+
+ var lines: I32 = 1;
+ var words: I32 = 0;
+ var sum: U64 = 0;
+ var in_word: bool = 0;
+
+ "Analyzing content...";
+
+ var i: int = 0;
+ while (i < data.len) {
+ var c: char = data.data[i];
+
+ match c {
+ '\n' => {
+ lines++;
+ in_word = 0;
+ }
+
+ ' ', '\t', '\r' => {
+ in_word = 0;
+ }
+
+ _ => {
+ if (!in_word) {
+ words++;
+ in_word = 1;
+ }
+ }
+ }
+
+ var b: U8 = c;
+ sum = sum + b;
+
+ i++;
+ }
+
+ "";
+ "*** Report ***";
+ "Total Lines: {lines}";
+ "Total Words: {words}";
+
+ "Checksum: 0x{sum:X} (Simple Sum)";
+ "Average Byte: {sum / data.len}";
+
+ "";
+ "Analysis successfully completed.";
+
+}
diff --git a/tests/features/test_intel.zc b/tests/features/test_intel.zc
new file mode 100644
index 0000000..8547501
--- /dev/null
+++ b/tests/features/test_intel.zc
@@ -0,0 +1,22 @@
+//> cflags: -masm=intel
+
+fn add_five_intel(x: int) -> int {
+ var result: int;
+ asm {
+ "mov {result}, {x}"
+ "add {result}, 5"
+ : out(result)
+ : in(x)
+ }
+ return result;
+}
+
+test "test_intel" {
+ var val = add_five_intel(10);
+ "Sum Intel: 10 + 5 = {val}";
+
+ match val {
+ 15 => printf("-> Success!\n")
+ _ => printf("-> Failed: expected 15, got {val}\n")
+ }
+}
diff --git a/tests/features/test_operators_suite.zc b/tests/features/test_operators_suite.zc
new file mode 100644
index 0000000..68b73fe
--- /dev/null
+++ b/tests/features/test_operators_suite.zc
@@ -0,0 +1,144 @@
+
+struct Flags {
+ bits: int;
+}
+
+impl Flags {
+ fn new(b: int) -> Flags { return Flags{bits: b}; }
+
+ fn bitor(self, other: Flags) -> Flags {
+ " [DEBUG] Custom bitor called! combining {self.bits} | {other.bits}";
+ return Flags { bits: self.bits | other.bits };
+ }
+}
+
+struct Container {
+ val: int;
+}
+
+impl Container {
+ fn new(v: int) -> Container { return Container { val: v }; }
+
+ fn get(self, idx: int) -> int {
+ return self.val + idx;
+ }
+
+ fn set(self, idx: int, v: int) {
+ self.val = v + idx;
+ }
+
+ fn neg(self) -> Container {
+ return Container { val: -self.val };
+ }
+
+ fn not(self) -> bool {
+ return self.val == 0;
+ }
+
+ fn bitnot(self) -> Container {
+ return Container { val: ~self.val };
+ }
+}
+
+enum Result {
+ Ok(int),
+ Err(int)
+}
+
+fn make_ok(v: int) -> Result {
+ return Result_Ok(v);
+}
+
+fn make_err(e: int) -> Result {
+ return Result_Err(e);
+}
+
+fn process_result(fail: int) -> Result {
+ var val = make_ok(10)?;
+
+ if (fail) {
+ var v2 = make_err(500)?;
+ return Result_Ok(v2 + 1000);
+ }
+
+ return Result_Ok(val + 20);
+}
+
+fn add(a: int, b: int) -> int {
+ return a + b;
+}
+
+fn twice(x: int) -> int {
+ return x * 2;
+}
+
+test "test_operator_overloading" {
+ "=> Bitwise Primitives";
+ var a = 0b1100;
+ var b = 0b1010;
+
+ "{a} | {b} = {a | b} (Expected 14)";
+ "{a} & {b} = {a & b} (Expected 8)";
+ "{a} ^ {b} = {a ^ b} (Expected 6)";
+ "{a} << 1 = {a << 1} (Expected 24)";
+
+ "=> Compound Assignment Desugaring";
+ var x = 10;
+ x += 5; // 15
+ x <<= 1; // 30
+
+ "=> Struct Overloading + Compound (|=)";
+ var f1 = Flags::new(1);
+ var f2 = Flags::new(4);
+ f1 |= f2;
+ "Result bits: {f1.bits} (Expected 5)";
+
+ const MAX_LIMIT = 100;
+}
+
+test "test_extended_overloading" {
+ var c = Container::new(10);
+
+ // Index Get
+ assert(c[5] == 15, "Get Failed");
+
+ // Index Set
+ c[2] = 20;
+ assert(c.val == 22, "Set Failed");
+
+ // Compound Assignment
+ c[0] += 5;
+ assert(c.val == 27, "Compound Set Failed");
+
+ // Unary Neg
+ var n = -c;
+ assert(n.val == -27, "Neg Failed");
+
+ // Unary Not
+ assert(!c == false, "Not Operator Failed");
+
+ // Unary Bitnot
+ var b = ~c;
+ assert(b.val == ~27, "Bitnot Failed");
+}
+
+test "test_pipe_operator" {
+ var res = 5 |> twice;
+ assert(res == 10, "Pipe twice failed");
+
+ var res2 = 10 |> add(20);
+ assert(res2 == 30, "Pipe add failed");
+
+ var res3 = 5 |> twice |> add(10); // 20
+ assert(res3 == 20, "Multi-pipe failed");
+}
+
+test "test_try_operator" {
+ var res_ok = process_result(0);
+ assert(res_ok.tag == Result_Ok_Tag, "Expected Ok");
+ assert(res_ok.data.Ok == 30, "Expected 30");
+
+ var res_err = process_result(1);
+ assert(res_err.tag == Result_Err_Tag, "Expected Err");
+ assert(res_err.data.Err == 500, "Expected Err(500)");
+}
diff --git a/tests/features/test_traits_suite.zc b/tests/features/test_traits_suite.zc
new file mode 100644
index 0000000..7fe7d1c
--- /dev/null
+++ b/tests/features/test_traits_suite.zc
@@ -0,0 +1,104 @@
+
+trait Greeter {
+ fn greet(self, msg: string);
+ fn shout(self);
+}
+
+struct Robot {
+ id: int;
+}
+
+impl Greeter for Robot {
+ fn greet(self, msg: string) {
+ println "Robot {self.id} says: {msg}";
+ }
+ fn shout(self) {
+ println "ROBOT {self.id} ACTIVATED";
+ }
+}
+
+trait Shape {
+ fn area(self) -> float;
+ fn name(self) -> string;
+}
+
+struct Circle {
+ radius: float;
+}
+
+impl Shape for Circle {
+ fn area(self) -> float {
+ return 3.14159 * self.radius * self.radius;
+ }
+ fn name(self) -> string {
+ return "Circle";
+ }
+}
+
+struct Rectangle {
+ width: float;
+ height: float;
+}
+
+impl Shape for Rectangle {
+ fn area(self) -> float {
+ return self.width * self.height;
+ }
+ fn name(self) -> string {
+ return "Rectangle";
+ }
+}
+
+@derive(Debug, Clone, Eq)
+struct Point {
+ x: int;
+ y: int;
+}
+
+
+fn print_shape_info(s: Shape) {
+ println "Shape: {s.name()}, Area: {s.area()}";
+}
+
+test "basic_traits" {
+ var r: Robot = Robot { id: 42 };
+ var g: Greeter = &r;
+
+ g.greet("Hello World");
+ g.shout();
+}
+
+test "advanced_traits" {
+ var c = Circle { radius: 5.0 };
+ var r = Rectangle { width: 4.0, height: 6.0 };
+
+ var s_c: Shape = &c;
+ var s_r: Shape = &r;
+
+ print_shape_info(s_c);
+ print_shape_info(s_r);
+
+ if (s_c.area() > s_r.area()) {
+ println "Circle is larger";
+ } else {
+ println "Rectangle is larger";
+ }
+}
+
+test "test_derive" {
+ var p1 = Point{x: 10, y: 20};
+
+ // Debug
+ var s = p1.to_string();
+ assert(strcmp(s, "Point { ... }") == 0, "Debug string matches");
+
+ // Clone
+ var p2 = p1.clone();
+ assert(p2.x == 10, "Clone x matches");
+
+ // Eq
+ assert(p1.eq(p2) == true, "Eq works (true)");
+
+ var p3 = Point{x: 10, y: 21};
+ assert(p1.eq(p3) == false, "Eq works (false)");
+}
diff --git a/tests/functions/test_attributes.zc b/tests/functions/test_attributes.zc
new file mode 100644
index 0000000..db77d89
--- /dev/null
+++ b/tests/functions/test_attributes.zc
@@ -0,0 +1,122 @@
+
+@must_use
+fn compute() -> int {
+ return 42;
+}
+
+@deprecated("Use new_version instead")
+fn old_function() {
+ "deprecated!";
+}
+
+@inline
+fn fast_add(a: int, b: int) -> int {
+ return a + b;
+}
+
+@must_use @inline
+fn combined() -> int {
+ return 100;
+}
+
+fn optional_result() -> int {
+ return 1;
+}
+
+@packed
+struct PackedHeader {
+ magic: U8;
+ version: U8;
+ size: U32;
+}
+
+@align(16)
+struct AlignedVec4 {
+ x: float;
+ y: float;
+ z: float;
+ w: float;
+}
+
+@packed @align(4)
+struct CombinedStruct {
+ flags: U8;
+ value: U16;
+}
+
+// Normal struct for comparison
+struct NormalStruct {
+ a: U8;
+ b: U32;
+}
+
+var init_called = 0;
+var cleanup_called = 0;
+
+@constructor
+fn my_init() {
+ init_called = 1;
+}
+
+@destructor
+fn my_cleanup() {
+ // We can't easily assert this ran in a test runner, but we can verify it compiles
+ cleanup_called = 1;
+}
+
+@noinline
+fn complex_calc(x: int) -> int {
+ return x * 2;
+}
+
+@section(".custom_section")
+fn section_func() {}
+
+@weak
+fn weak_func() {}
+
+@unused
+fn unused_func() {}
+
+test "function attributes" {
+ // @must_use: result used - no warning
+ var x = compute();
+ assert(x == 42, "compute() failed");
+
+ // No must_use - can discard
+ optional_result();
+
+ // @inline works
+ var sum = fast_add(1, 2);
+ assert(sum == 3, "inline add failed");
+
+ // Combined attributes
+ var c = combined();
+ assert(c == 100, "combined failed");
+
+ // @must_use: discarding should warn
+ compute();
+
+ // Check constructor ran
+ assert(init_called == 1, "Constructor attribute failed");
+
+ // Check noinline compiles and runs
+ assert(complex_calc(10) == 20, "Noinline function failed");
+
+ "Function attributes OK";
+}
+
+test "struct attributes" {
+ // @packed: no padding, should be 6 bytes
+ // (1 + 1 + 4 = 6)
+ // Without packing: 1 + 1 + 2(pad) + 4 = 8
+ assert(sizeof(PackedHeader) == 6, "PackedHeader should be 6 bytes");
+
+ // @align(16): aligned to 16 bytes
+ assert(sizeof(AlignedVec4) >= 16, "AlignedVec4 should be >= 16 bytes");
+
+ // Normal struct has padding
+ assert(sizeof(NormalStruct) == 8, "NormalStruct has padding");
+
+ "Struct attributes OK";
+}
diff --git a/tests/functions/test_implicit_return.zc b/tests/functions/test_implicit_return.zc
new file mode 100644
index 0000000..bb35134
--- /dev/null
+++ b/tests/functions/test_implicit_return.zc
@@ -0,0 +1,18 @@
+test "test_implicit_return" {
+ // Adds newline
+ "Hello Implicit";
+
+ // Adds newline
+ println "Hello Explicit";
+
+ // No newline
+ print "Loading";
+ print ".";
+ print ".";
+ println " Done!";
+
+ // With variables
+ var x = 42;
+ print "Value is: ";
+ println "{x}";
+}
diff --git a/tests/functions/test_lambda_arrow.zc b/tests/functions/test_lambda_arrow.zc
new file mode 100644
index 0000000..c976ecf
--- /dev/null
+++ b/tests/functions/test_lambda_arrow.zc
@@ -0,0 +1,20 @@
+
+fn compute(op: fn(I32, I32) -> I32, a: I32, b: I32) -> I32 {
+ return op(a, b);
+}
+
+test "test_lambda_arrow" {
+ var doubler = x -> x * 2;
+ var res1 = doubler(5);
+ "doubler(5) = {res1}";
+ if res1 != 10 { exit(1); }
+
+ var add = (x, y) -> x + y;
+ var res2 = add(10, 20);
+ "add(10, 20) = {res2}";
+ if res2 != 30 { exit(1); }
+
+ var res3 = compute((a, b) -> a * b, 3, 4);
+ "compute((a, b) -> a * b, 3, 4) = {res3}";
+ if res3 != 12 { exit(1); }
+}
diff --git a/tests/functions/test_lambdas.zc b/tests/functions/test_lambdas.zc
new file mode 100644
index 0000000..5f2c086
--- /dev/null
+++ b/tests/functions/test_lambdas.zc
@@ -0,0 +1,78 @@
+
+fn apply_twice(f: fn(I32) -> I32, x: I32) -> I32 {
+ return f(f(x));
+}
+
+fn make_adder(n: I32) -> fn(I32) -> I32 {
+ // Returns a lambda that captures 'n'
+ return x -> x + n;
+}
+
+test "test_complex_lambdas" {
+ println "Testing complex lambda scenarios...";
+
+ // Lambda with multiple parameters
+ var add_three = (a, b, c) -> a + b + c;
+ var res1 = add_three(1, 2, 3);
+ if (res1 == 6) {
+ println " -> Multi-param lambda: Passed";
+ } else {
+ println " -> Multi-param lambda: Failed";
+ exit(1);
+ }
+
+ // Higher-order function
+ var res2 = apply_twice(x -> x * 2, 5);
+ if (res2 == 20) {
+ println " -> Higher-order function: Passed";
+ } else {
+ println " -> Higher-order function: Failed";
+ exit(1);
+ }
+
+ // Returning a lambda (closure)
+ var add10 = make_adder(10);
+ var res3 = add10(5);
+ if (res3 == 15) {
+ println " -> Returned lambda: Passed";
+ } else {
+ println " -> Returned lambda: Failed";
+ exit(1);
+ }
+
+ // Lambda composition
+ var doubler = x -> x * 2;
+ var add5 = x -> x + 5;
+ var res4 = add5(doubler(10));
+ if (res4 == 25) {
+ println " -> Lambda composition: Passed";
+ } else {
+ println " -> Lambda composition: Failed";
+ exit(1);
+ }
+
+ // Nested application
+ var res5 = apply_twice(x -> x + 1, apply_twice(x -> x * 2, 3));
+ // (3 * 2) * 2 = 12, then (12 + 1) + 1 = 14
+ if (res5 == 14) {
+ println " -> Nested application: Passed";
+ } else {
+ println " -> Nested application: Failed";
+ exit(1);
+ }
+
+ println "All complex lambda tests passed!";
+
+
+}
+
+test "test_basic_closure" {
+ var whatever = 10;
+ var closure: fn(I32) -> I32 = x -> x + whatever;
+ var res = closure(5);
+ // "Result: {res}";
+ if (res != 15) {
+ println "Closure failed: expected 15, got {res}";
+ exit(1);
+ }
+}
diff --git a/tests/functions/test_must_use.zc b/tests/functions/test_must_use.zc
new file mode 100644
index 0000000..a42b341
--- /dev/null
+++ b/tests/functions/test_must_use.zc
@@ -0,0 +1,47 @@
+include <stdio.h>
+
+@must_use
+fn compute() -> int {
+ return 42;
+}
+
+@deprecated("Use new_version instead")
+fn old_function() {
+ "deprecated!";
+}
+
+@inline
+fn fast_add(a: int, b: int) -> int {
+ return a + b;
+}
+
+@must_use @inline
+fn combined() -> int {
+ return 100;
+}
+
+fn optional_result() -> int {
+ return 1;
+}
+
+test "attributes" {
+ // This should NOT warn (result used)
+ var x = compute();
+ assert(x == 42, "compute() should return 42");
+
+ // This should NOT warn (no must_use attribute)
+ optional_result();
+
+ // This SHOULD warn (result discarded on must_use function)
+ compute();
+
+ // Test inline works
+ var sum = fast_add(1, 2);
+ assert(sum == 3, "inline add failed");
+
+ // Combined attributes
+ var c = combined();
+ assert(c == 100, "combined failed");
+
+ "Attributes test completed";
+}
diff --git a/tests/functions/test_varargs.zc b/tests/functions/test_varargs.zc
new file mode 100644
index 0000000..b05e168
--- /dev/null
+++ b/tests/functions/test_varargs.zc
@@ -0,0 +1,10 @@
+//> link: -lm
+
+test "test_varargs" {
+ println "Testing Varargs...";
+ printf(" Direct Printf: %d, %f, %s\n", 42, 3.14, "Hello");
+
+ var buf = malloc(100);
+ sprintf(buf, "Formatted: %d", 123);
+ println " {buf}";
+}
diff --git a/tests/generics/test_generics_fn.zc b/tests/generics/test_generics_fn.zc
new file mode 100644
index 0000000..ac1cbb5
--- /dev/null
+++ b/tests/generics/test_generics_fn.zc
@@ -0,0 +1,25 @@
+
+fn identity<T>(x: T) -> T {
+ return x;
+}
+
+struct Box<T> {
+ val: T;
+}
+
+// Generic Impl
+impl Box<T> {
+ fn get(self) -> T {
+ return self.val;
+ }
+}
+
+test "Generics" {
+ // Generic Function
+ var i = identity<int>(42);
+ assert(i == 42, "Generic function failed");
+
+ // Generic Struct & Impl
+ var b = Box<int> { val: 100 };
+ assert(b.get() == 100, "Generic impl failed");
+}
diff --git a/tests/generics/test_generics_struct.zc b/tests/generics/test_generics_struct.zc
new file mode 100644
index 0000000..ae61e4c
--- /dev/null
+++ b/tests/generics/test_generics_struct.zc
@@ -0,0 +1,14 @@
+
+struct Wrapper<T> {
+ item: T;
+ id: int;
+}
+
+test "test_generics_struct" {
+ // Instantiate with int
+ var w1: Wrapper<int>;
+ w1.id = 1;
+ w1.item = 500;
+
+ println "Wrapper Int: {w1.item} (ID: {w1.id})";
+}
diff --git a/tests/interop/test_c_import.zc b/tests/interop/test_c_import.zc
new file mode 100644
index 0000000..ed95bc1
--- /dev/null
+++ b/tests/interop/test_c_import.zc
@@ -0,0 +1,26 @@
+
+import "math.h" as m;
+
+test "test_c_import" {
+ var x = m::sin(0.0);
+
+ if x == 0.0 {
+ println "Success: m::sin(0.0) == 0.0";
+ } else {
+ println "Failure: Unexpected result";
+ exit(1);
+ }
+ }
+}
+
+extern fn abs(x: int) -> int;
+
+test "test_interop_abs" {
+ var x = -10;
+ var y = abs(x);
+ if (y == 10) println "Abs works";
+ else {
+ println "Abs failed";
+ exit(1);
+ }
+}
diff --git a/tests/interop/test_c_macros.zc b/tests/interop/test_c_macros.zc
new file mode 100644
index 0000000..0b1fc64
--- /dev/null
+++ b/tests/interop/test_c_macros.zc
@@ -0,0 +1,22 @@
+
+#define MAX(a, b) ((a) > (b) ? (a) : (b))
+#define DEBUG_MODE 1
+
+test "test_c_macros" {
+ var x = MAX(10, 20);
+
+ if x == 20 {
+ println "MAX macro worked";
+ } else {
+ println "MAX macro failed";
+ exit(1);
+ }
+
+ #ifdef DEBUG_MODE
+ println "Debug mode active";
+ #endif
+
+ #ifndef INVALID_MACRO
+ println "Conditionals working";
+ #endif
+}
diff --git a/tests/memory/test_memory_safety.zc b/tests/memory/test_memory_safety.zc
new file mode 100644
index 0000000..5cec2db
--- /dev/null
+++ b/tests/memory/test_memory_safety.zc
@@ -0,0 +1,217 @@
+
+import "std/mem.zc"
+
+// --- Globals ---
+var DROP_COUNT = 0;
+
+// --- Structs & Helpers ---
+
+trait Drop {
+ fn drop(self);
+}
+
+struct Resource {
+ id: int;
+}
+
+impl Drop for Resource {
+ fn drop(self) {
+ println "Dropping Resource {self.id}";
+ DROP_COUNT = DROP_COUNT + 1;
+ }
+}
+
+fn create_resource(id: int) {
+ var r = Resource{id: id};
+ println "Created Resource {r.id}";
+}
+
+struct Point {
+ x: int;
+ y: int;
+}
+
+fn distance(p1: Point, p2: Point) -> int {
+ var dx = p2.x - p1.x;
+ var dy = p2.y - p1.y;
+ return dx * dx + dy * dy;
+}
+
+fn accumulate(start: int, count: int) -> int {
+ var mut sum = start;
+ var mut i = 0;
+ while (i < count) {
+ sum += i;
+ i++;
+ }
+ return sum;
+}
+
+fn process_point(p: Point) -> Point {
+ var result = Point { x: p.x * 2, y: p.y * 2 };
+ return result;
+}
+
+fn counter_immut() {
+ var mut count = 0;
+ {
+ var mut inner = 10;
+ inner = inner + 5;
+ count = count + inner;
+ }
+}
+
+struct Permissions {
+ mask: U8;
+}
+
+impl Permissions {
+ fn new(m: U8) -> Permissions {
+ return Permissions { mask: m };
+ }
+ fn bitor(self, other: Permissions) -> Permissions {
+ return Permissions { mask: self.mask | other.mask };
+ }
+ fn has(self, flag: U8) -> U8 {
+ return (self.mask & flag) == flag;
+ }
+}
+
+fn get_resource() -> int {
+ println "resource opened";
+ return 42;
+}
+
+fn release_resource(id: int) {
+ if (id == 42) println "resource 42 released";
+ else println "resource released (unknown)";
+}
+
+fn test_defer_logic() {
+ println "start test";
+ var x = get_resource() defer release_resource(it);
+ println "using resource {x}";
+}
+
+
+test "test_alloc" {
+ "Testing alloc<T>...";
+
+ var p = alloc<int>();
+ *p = 42;
+ f" alloc<int>(): {*p}";
+ assert(*p == 42, "alloc failed");
+ free(p);
+
+ var arr = alloc_n<int>(5);
+ for var i = 0; i < 5; i++ {
+ arr[i] = i * 10;
+ }
+ f" alloc_n<int>(5): [{arr[0]}, {arr[1]}, {arr[2]}, {arr[3]}, {arr[4]}]";
+ free(arr);
+
+ " ✓ alloc works!";
+}
+
+test "test_box" {
+ "Testing Box<T>...";
+ var b = Box<int>::new();
+ *b.get() = 100;
+ var val = *b.get();
+ f" Box value: {val}";
+ assert(val == 100, "Box failed");
+ b.free();
+ " ✓ Box works!";
+}
+
+test "test_slice" {
+ "Testing Slice<T>...";
+ var data: int[5] = [1, 2, 3, 4, 5];
+ var s = Slice<int>::new(&data[0], 5);
+ f" Slice len: {(int)s.len}";
+ var v2 = s.get(2);
+ f" Slice[2]: {v2}";
+ assert(v2 == 3, "Slice get failed");
+ s.set(0, 99);
+ var v0 = s.get(0);
+ f" After set: Slice[0] = {v0}";
+ assert(v0 == 99, "Slice set failed");
+ " ✓ Slice works!";
+}
+
+test "test_swap" {
+ "Testing swap<T>...";
+ var a = 10;
+ var b = 20;
+ f" Before: a={a}, b={b}";
+ swap<int>(&a, &b);
+ f" After: a={a}, b={b}";
+ assert(a == 20 && b == 10, "swap failed");
+ " ✓ swap works!";
+}
+
+test "test_autofree" {
+ println "Testing autofree...";
+ {
+ autofree var p = malloc(1024);
+ if (p == NULL) { eprintln "Malloc failed!"; }
+ strcpy(p, "Auto-freed string");
+ print f"Allocated: {p}"; println "";
+ }
+ println "Exited block successfully (hopefully freed)";
+ {
+ autofree var p1 = malloc(10);
+ autofree var p2 = malloc(20);
+ }
+}
+
+test "test_raii_drop" {
+ DROP_COUNT = 0;
+ "Entering scope...";
+ create_resource(1);
+ "Exited scope.";
+ assert(DROP_COUNT == 1, "Expected Drop to be called once");
+ {
+ var r2 = Resource{id: 2};
+ var r3 = Resource{id: 3};
+ }
+ assert(DROP_COUNT == 3, "Expected 3 total drops");
+}
+
+test "test_immutable" {
+ var p1 = Point { x: 0, y: 0 };
+ var p2 = Point { x: 3, y: 4 };
+ var dist = distance(p1, p2);
+ "Distance: {dist}";
+ var sum = accumulate(10, 5);
+ "Accumulate: {sum}";
+ var p3 = process_point(p1);
+ "Processed: ({p3.x}, {p3.y})";
+ counter_immut();
+}
+
+test "test_permissions" {
+ const READ : U8 = 0b100;
+ const WRITE : U8 = 0b010;
+ const EXEC : U8 = 0b001;
+
+ var p1 = Permissions::new(READ);
+ "Start: {p1.mask} (Read)";
+
+ var p2 = Permissions::new(WRITE);
+ var p_rw = p1 | p2;
+ "Combined: {p_rw.mask} (Read + Write)";
+
+ if (p_rw.has(EXEC)) { " > Has Execute access"; }
+ else { " > No Execute access"; }
+
+ if (p_rw.has(READ)) { " > Has Read access"; }
+
+ var p_all = p_rw | Permissions::new(EXEC);
+ "Final: {p_all.mask} (All)";
+}
+
+test "test_value_defer" {
+ test_defer_logic();
+ println "end test";
+}
diff --git a/tests/memory/test_unsafe.zc b/tests/memory/test_unsafe.zc
new file mode 100644
index 0000000..126404a
--- /dev/null
+++ b/tests/memory/test_unsafe.zc
@@ -0,0 +1,56 @@
+
+raw {
+ #define MY_C_CONST 12345
+ int legacy_add(int a, int b) {
+ return a + b + MY_C_CONST;
+ }
+}
+
+extern fn legacy_add(a: int, b: int) -> int;
+
+fn process_arrays(n: int, a: restrict int*, b: restrict int*, out: restrict int*) {
+ for (var i = 0; i < n; i = i + 1) {
+ out[i] = a[i] + b[i];
+ }
+}
+
+fn counter() -> int {
+ static var count = 0;
+ count = count + 1;
+ return count;
+}
+
+test "test_raw" {
+ println "Testing Raw C Embedding...";
+ var res = legacy_add(10, 20);
+ // Expected: 10 + 20 + 12345 = 12375
+ assert(res == 12375, "Raw C Code failed");
+ println " Raw C Code: Success (Result: {res})";
+}
+
+test "test_restrict" {
+ var a: int[10];
+ var b: int[10];
+ var c: int[10];
+
+ for (var i = 0; i < 10; i = i + 1) {
+ a[i] = i;
+ b[i] = i * 2;
+ }
+
+ process_arrays(10, a, b, c);
+
+ for (var i = 0; i < 10; i = i + 1) {
+ assert(c[i] == i * 3, "Restrict test failed");
+ }
+}
+
+test "test_static_local" {
+ var a = counter(); // 1
+ var b = counter(); // 2
+ var c = counter(); // 3
+
+ assert a == 1;
+ assert b == 2;
+ assert c == 3;
+}
diff --git a/tests/misc/test_advanced.zc b/tests/misc/test_advanced.zc
new file mode 100644
index 0000000..8b5b466
--- /dev/null
+++ b/tests/misc/test_advanced.zc
@@ -0,0 +1,211 @@
+import "std.zc"
+
+fn fibonacci(n: int) -> int {
+ if (n <= 1) {
+ return n;
+ }
+ return fibonacci(n - 1) + fibonacci(n - 2);
+}
+
+fn test_recursion() {
+ var fib10 = fibonacci(10);
+
+ if (fib10 != 55) {
+ println "FAIL: fibonacci(10) should be 55";
+ exit(1);
+ }
+
+ println " -> Recursive function works";
+}
+
+fn add_three(a: int, b: int, c: int) -> int {
+ return a + b + c;
+}
+
+fn test_multi_params() {
+ var result = add_three(1, 2, 3);
+
+ if (result != 6) {
+ println "FAIL: add_three(1,2,3) should be 6";
+ exit(1);
+ }
+
+ println " -> Multi-parameter function works";
+}
+
+fn double_val(x: int) -> int {
+ return x * 2;
+}
+
+fn test_nested_calls() {
+ var result = double_val(double_val(double_val(2)));
+
+ if (result != 16) {
+ println "FAIL: nested calls failed";
+ exit(1);
+ }
+
+ println " -> Nested function calls work";
+}
+
+struct Counter {
+ value: int;
+}
+
+impl Counter {
+ fn new() -> Counter {
+ return Counter { value: 0 };
+ }
+
+ fn get(self) -> int {
+ return self.value;
+ }
+
+ fn increment(self) {
+ self.value = self.value + 1;
+ }
+}
+
+fn test_struct_methods() {
+ var c = Counter::new();
+ c.increment();
+ c.increment();
+ c.increment();
+
+ if (c.get() != 3) {
+ println "FAIL: Counter should be 3";
+ exit(1);
+ }
+
+ println " -> Struct methods work";
+}
+
+fn test_casting() {
+ var f: float = 3.7;
+ var i: int = (int)f;
+
+ if (i != 3) {
+ println "FAIL: float to int cast failed";
+ exit(1);
+ }
+
+ var i2: int = 42;
+ var f2: float = (float)i2;
+
+ if (f2 < 41.9 || f2 > 42.1) {
+ println "FAIL: int to float cast failed";
+ exit(1);
+ }
+
+ println " -> Type casting works";
+}
+
+fn test_bitwise() {
+ var a = 0b1010; // 10
+ var b = 0b1100; // 12
+
+ var and_result = a & b; // 0b1000 = 8
+ var or_result = a | b; // 0b1110 = 14
+ var xor_result = a ^ b; // 0b0110 = 6
+
+ if (and_result != 8) {
+ println "FAIL: bitwise AND failed";
+ exit(1);
+ }
+
+ if (or_result != 14) {
+ println "FAIL: bitwise OR failed";
+ exit(1);
+ }
+
+ if (xor_result != 6) {
+ println "FAIL: bitwise XOR failed";
+ exit(1);
+ }
+
+ println " -> Bitwise operations work";
+}
+
+fn test_shift() {
+ var x = 1;
+ var left = x << 4; // 16
+
+ if (left != 16) {
+ println "FAIL: left shift failed";
+ exit(1);
+ }
+
+ var y = 32;
+ var right = y >> 2; // 8
+
+ if (right != 8) {
+ println "FAIL: right shift failed";
+ exit(1);
+ }
+
+ println " -> Shift operations work";
+}
+
+fn test_modulo() {
+ var a = 17;
+ var b = 5;
+ var result = a % b;
+
+ if (result != 2) {
+ println "FAIL: modulo operation failed";
+ exit(1);
+ }
+
+ println " -> Modulo operator works";
+}
+
+fn test_compound_expr() {
+ var x = 5;
+ var y = 10;
+ var z = 3;
+
+ var result = (x + y) * z - (y / 2);
+ // (5 + 10) * 3 - (10 / 2) = 15 * 3 - 5 = 45 - 5 = 40
+
+ if (result != 40) {
+ println "FAIL: compound expression failed";
+ exit(1);
+ }
+
+ println " -> Compound expressions work";
+}
+
+fn test_increment_style() {
+ var x = 5;
+ x = x + 1;
+
+ if (x != 6) {
+ println "FAIL: increment style failed";
+ exit(1);
+ }
+
+ x = x - 1;
+ if (x != 5) {
+ println "FAIL: decrement style failed";
+ exit(1);
+ }
+
+ print " -> Increment/decrement style works";
+}
+
+test "test_advanced" {
+ println "Running function and advanced tests...";
+
+ test_recursion();
+ test_multi_params();
+ test_nested_calls();
+ test_struct_methods();
+ test_casting();
+ test_bitwise();
+ test_shift();
+ test_modulo();
+ test_compound_expr();
+ test_increment_style();
+
+ println "All function and advanced tests passed!";
+}
diff --git a/tests/misc/test_chained.zc b/tests/misc/test_chained.zc
new file mode 100644
index 0000000..e758db7
--- /dev/null
+++ b/tests/misc/test_chained.zc
@@ -0,0 +1,14 @@
+
+import "std/string.zc"
+
+test "test_chained" {
+ var s = String::from("hello");
+ var opt = s.find('e');
+ if opt.is_some() {
+ "Found at index: {opt.unwrap()}";
+ }
+
+ if s.find('l').is_some() {
+ "Chained call works!";
+ }
+}
diff --git a/tests/misc/test_edge_cases.zc b/tests/misc/test_edge_cases.zc
new file mode 100644
index 0000000..f1a4cf5
--- /dev/null
+++ b/tests/misc/test_edge_cases.zc
@@ -0,0 +1,151 @@
+
+import "std.zc"
+
+// Empty struct
+@derive(Eq, Clone)
+struct Empty {}
+
+fn test_empty_struct() {
+ var e1 = Empty {};
+ var e2 = Empty {};
+
+ if (!e1.eq(e2)) {
+ println "FAIL: Empty struct eq failed";
+ exit(1);
+ }
+
+ println " -> Empty struct with @derive(Eq) works";
+}
+
+// Struct with many fields (stress @derive(Eq))
+@derive(Eq)
+struct ManyFields {
+ a: int;
+ b: int;
+ c: int;
+ d: int;
+ e: int;
+ f: int;
+ g: int;
+ h: int;
+}
+
+fn test_many_fields() {
+ var m1 = ManyFields { a: 1, b: 2, c: 3, d: 4, e: 5, f: 6, g: 7, h: 8 };
+ var m2 = ManyFields { a: 1, b: 2, c: 3, d: 4, e: 5, f: 6, g: 7, h: 8 };
+ var m3 = ManyFields { a: 1, b: 2, c: 3, d: 4, e: 5, f: 6, g: 7, h: 9 }; // h differs
+
+ if (!m1.eq(m2)) {
+ println "FAIL: equal structs not detected as equal";
+ exit(1);
+ }
+
+ if (m1.eq(m3)) {
+ println "FAIL: different structs detected as equal";
+ exit(1);
+ }
+
+ println " -> ManyFields @derive(Eq) works correctly";
+}
+
+// Pointer to struct equality (should use ==, not _eq)
+struct Point {
+ x: int;
+ y: int;
+}
+
+fn test_pointer_equality() {
+ var p1 = Point { x: 1, y: 2 };
+ var ptr1: Point* = &p1;
+ var ptr2: Point* = &p1;
+ var p2 = Point { x: 1, y: 2 };
+ var ptr3: Point* = &p2;
+
+ // Same pointer should be equal
+ if (ptr1 != ptr2) {
+ println "FAIL: same pointer not equal";
+ exit(1);
+ }
+
+ // Different pointers (even to equal values) should not be pointer-equal
+ if (ptr1 == ptr3) {
+ println "FAIL: different pointers compare equal";
+ exit(1);
+ }
+
+ print " -> Pointer equality uses == not _eq";
+}
+
+// Very long string
+fn test_long_string() {
+ var s = String::from("This is a very long string that should test the string handling capabilities of the compiler and make sure that buffer allocations are correct and that there are no overflow issues with long strings.");
+
+ if (s.length() < 100) {
+ println "FAIL: long string length incorrect";
+ exit(1);
+ }
+
+ print " -> Long string handling works";
+}
+
+// Null pointer handling
+fn test_null_pointer() {
+ var ptr: int* = NULL;
+
+ if (ptr != NULL) {
+ println "FAIL: NULL pointer check failed";
+ exit(1);
+ }
+
+ println " -> NULL pointer handling works";
+}
+
+// Numeric edge cases
+fn test_numeric_edges() {
+ var max_int: int = 2147483647;
+ var min_int: int = -1000000000;
+
+ if (max_int <= 0) {
+ println "FAIL: max_int is wrong";
+ exit(1);
+ }
+
+ if (min_int >= 0) {
+ println "FAIL: min_int is wrong";
+ exit(1);
+ }
+
+ println " -> Numeric edge cases work";
+}
+
+// Boolean operations
+fn test_boolean_ops() {
+ var a = true;
+ var b = false;
+
+ if (!(a && !b)) {
+ println "FAIL: boolean AND failed";
+ exit(1);
+ }
+
+ if (!(a || b)) {
+ println "FAIL: boolean OR failed";
+ exit(1);
+ }
+
+ println " -> Boolean operations work\n";
+}
+
+test "test_edge_cases" {
+ println "Running edge case tests...";
+
+ test_empty_struct();
+ test_many_fields();
+ test_pointer_equality();
+ test_long_string();
+ test_null_pointer();
+ test_numeric_edges();
+ test_boolean_ops();
+
+ println "All edge case tests passed!";
+}
diff --git a/tests/misc/test_mix.zc b/tests/misc/test_mix.zc
new file mode 100644
index 0000000..b4edca4
--- /dev/null
+++ b/tests/misc/test_mix.zc
@@ -0,0 +1,61 @@
+
+enum Result {
+ Ok(int),
+ Err(int)
+}
+
+fn add(a: int, b: int) -> int {
+ return a + b;
+}
+
+fn square(x: int) -> int {
+ return x * x;
+}
+
+test "test_result_constructors" {
+ var res = Result_Ok(42);
+
+ assert(res.tag == Result_Ok_Tag, "Expected Ok tag");
+ assert(res.data.Ok == 42, "Data mismatch");
+
+ var err = Result_Err(500);
+ assert(err.tag == Result_Err_Tag, "Expected Err tag");
+}
+
+test "test_pipelines" {
+ // Logic: ((5 + 5) * (5 + 5))
+ // 5 |> add(5) -> 10
+ // 10 |> square() -> 100
+ var val = 5 |> add(5) |> square();
+
+ println "Pipeline result: {val}";
+ assert(val == 100, "Pipeline calculation failed");
+}
+
+test "test_fstrings" {
+ var x = 10;
+ var name = "ZPrep";
+
+ var s = f"Hello {name}, x = {x}, x * 2 = {x * 2}";
+
+ println "F-String: {s}";
+ assert(x == 10, "Sanity check");
+}
+
+test "test_defer" {
+ println " [Defer] 1. Start";
+
+ defer { println " [Defer] 4. Cleanup B"; }
+ defer { println " [Defer] 3. Cleanup A"; }
+
+ println " [Defer] 2. End";
+}
+
+test "test_hex_binary" {
+ var h = 0xFF; // 255
+ var b = 0b1010; // 10
+ assert(h == 255, "Hex parsing failed");
+ assert(b == 10, "Binary parsing failed");
+}
+
+// Removed empty test_result_enum
diff --git a/tests/modules/test_aliasing.zc b/tests/modules/test_aliasing.zc
new file mode 100644
index 0000000..96b200c
--- /dev/null
+++ b/tests/modules/test_aliasing.zc
@@ -0,0 +1,13 @@
+
+import { Vector as MathVec } from "./test_modules/math.zc";
+import { Vector as PhysicsVec } from "./test_modules/physics.zc";
+
+test "test_selective_aliasing" {
+ var mv = MathVec::new(3, 4);
+ var pv = PhysicsVec::new(5.0, 12.0);
+
+ assert(mv.x == 3 && mv.y == 4, "MathVec initialization failed");
+ assert(pv.vx == 5.0 && pv.vy == 12.0, "PhysicsVec initialization failed");
+
+ "PASS: Selective import aliasing works";
+}
diff --git a/tests/modules/test_modules/math.zc b/tests/modules/test_modules/math.zc
new file mode 100644
index 0000000..be65a5c
--- /dev/null
+++ b/tests/modules/test_modules/math.zc
@@ -0,0 +1,19 @@
+
+struct Vector {
+ x: int;
+ y: int;
+}
+
+impl Vector {
+ fn new(x: int, y: int) -> Vector {
+ return Vector { x: x, y: y };
+ }
+
+ fn length(self) -> int {
+ // sqrt(3^2 + 4^2) = 5
+ // Implementing simple integer fallback or mocked logic since we don't have sqrt in std (maybe?)
+ // For 3,4 it is 5.
+ if (self.x == 3 && self.y == 4) return 5;
+ return 0;
+ }
+}
diff --git a/tests/modules/test_modules/physics.zc b/tests/modules/test_modules/physics.zc
new file mode 100644
index 0000000..ee56f7e
--- /dev/null
+++ b/tests/modules/test_modules/physics.zc
@@ -0,0 +1,17 @@
+
+struct Vector {
+ vx: double;
+ vy: double;
+}
+
+impl Vector {
+ fn new(vx: double, vy: double) -> Vector {
+ return Vector { vx: vx, vy: vy };
+ }
+
+ fn magnitude(self) -> double {
+ // sqrt(5^2 + 12^2) = 13
+ if (self.vx == 5.0 && self.vy == 12.0) return 13.0;
+ return 0.0;
+ }
+}
diff --git a/tests/modules/test_modules/simple.zc b/tests/modules/test_modules/simple.zc
new file mode 100644
index 0000000..ed002e2
--- /dev/null
+++ b/tests/modules/test_modules/simple.zc
@@ -0,0 +1,3 @@
+fn foo() -> int {
+ return 100;
+}
diff --git a/tests/modules/test_namespaced.zc b/tests/modules/test_namespaced.zc
new file mode 100644
index 0000000..d2aa8cd
--- /dev/null
+++ b/tests/modules/test_namespaced.zc
@@ -0,0 +1,16 @@
+
+import "./test_modules/math.zc" as math;
+import "./test_modules/physics.zc" as physics;
+
+test "test_namespaced_imports" {
+ var mv = math::Vector::new(3, 4);
+ var pv = physics::Vector::new(5.0, 12.0);
+
+ var len1 = math::Vector::length(&mv);
+ var len2 = physics::Vector::magnitude(&pv);
+
+ assert(len1 == 5, "Math vector length failed");
+ assert(len2 == 13.0, "Physics vector magnitude failed");
+
+ "PASS: Namespaced imports work correctly";
+}
diff --git a/tests/run_tests.sh b/tests/run_tests.sh
index 8c2fbc7..771e77d 100755
--- a/tests/run_tests.sh
+++ b/tests/run_tests.sh
@@ -33,7 +33,7 @@ if [ ! -f "$ZC" ]; then
exit 1
fi
-for test_file in "$TEST_DIR"/*.zc; do
+while read -r test_file; do
[ -e "$test_file" ] || continue
echo -n "Testing $(basename "$test_file")... "
@@ -49,7 +49,7 @@ for test_file in "$TEST_DIR"/*.zc; do
((FAILED++))
FAILED_TESTS="$FAILED_TESTS\n- $(basename "$test_file")"
fi
-done
+done < <(find "$TEST_DIR" -name "*.zc" | sort)
echo "----------------------------------------"
echo "Summary:"