summaryrefslogtreecommitdiff
path: root/tests/control_flow/test_loop_edge_cases.zc
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/control_flow/test_loop_edge_cases.zc
parenta918df69269a39ef7350a645b5db025d66ecb18a (diff)
Added some of the tests.
Diffstat (limited to 'tests/control_flow/test_loop_edge_cases.zc')
-rw-r--r--tests/control_flow/test_loop_edge_cases.zc99
1 files changed, 99 insertions, 0 deletions
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!";
+}