Skip to content
This repository was archived by the owner on Nov 22, 2023. It is now read-only.

Commit d3699f8

Browse files
author
gek
committed
make push
1 parent d5d7d1c commit d3699f8

File tree

1 file changed

+61
-3
lines changed

1 file changed

+61
-3
lines changed

featuretest.cbas

+61-3
Original file line numberDiff line numberDiff line change
@@ -60,16 +60,18 @@ fn codegen test_loops:
6060
:after_for_111
6161
i64 i
6262
i64 j = 0
63+
i64 k
6364
//if(1)
65+
k = 0
6466
for(i = 0, i < 20; i++)
65-
__builtin_puts("You should see this print! (for i = 0 to 3 inclusive, 4 times)");
67+
k++;
6668
if(i == 3)
6769
j--;
6870
break
6971
end
7072
j++;
7173
end
72-
if(i != 3 || j != (3-1))
74+
if(i != 3 || j != (3-1) || k != 4)
7375
__builtin_puts("Failed Loop Test 1");
7476
char[50] buf
7577
__builtin_utoa(buf, i);
@@ -157,7 +159,6 @@ fn codegen test_loops:
157159
end
158160
end
159161
:out2
160-
i64 k
161162
for(k = 0, k < i, k++)
162163
;
163164
end
@@ -176,11 +177,68 @@ fn codegen test_loops:
176177

177178
end
178179

180+
fn codegen test_switch:
181+
i64 i = 0
182+
i64 j = 0
183+
i64 k = 0
184+
switch(1+2+3) l0 l1 l2 l3 l4 l5 l6 l7 l8 l9 l10;
185+
186+
187+
188+
:l0 i = 1 goto l_last
189+
:l1 i = 1 goto l_last
190+
:l2 i = 1 goto l_last
191+
:l3 i = 1 goto l_last
192+
:l4 i = 1 goto l_last
193+
:l5 i = 1 goto l_last
194+
:l6 goto l_last
195+
:l7 i = 1 goto l_last
196+
:l8 i = 1 goto l_last
197+
:l9 i = 1 goto l_last
198+
:l10 i = 1 goto l_last
199+
:l11 i = 1 goto l_last
200+
:l12 i = 1 goto l_last
201+
:l13 i = 1 goto l_last
202+
:l14 i = 1 goto l_last
203+
204+
:l_last
205+
if(i != 0)
206+
have_failed = 1;
207+
__builtin_puts("Failed switch test")
208+
end
209+
210+
return
211+
end
212+
213+
fn codegen test_writefile_readfile:
214+
__builtin_open_ofile("test.out");
215+
__builtin_emit("1234567890",11);
216+
__builtin_close_ofile();
217+
u64[1] len
218+
len[0] = 0
219+
220+
char* p = __builtin_read_file("test.out",len);
221+
if(len[0] != 11 || p == 0)
222+
__builtin_puts("Failed File I/O test - Could not read file.");
223+
have_failed = 1;
224+
end
225+
if(p strneq "1234567890")
226+
__builtin_puts("Failed File I/O test - File contents failure.");
227+
have_failed = 1;
228+
end
229+
__builtin_free(p);
230+
end
231+
179232

180233
fn codegen codegen_main:
181234
__builtin_puts("TESTING BASIC ARITHMETIC");
182235
testmath();
236+
__builtin_puts("TESTING LOOPS");
183237
test_loops();
238+
__builtin_puts("TESTING SWITCH");
239+
test_switch;
240+
__builtin_puts("TESTING FILES");
241+
test_writefile_readfile();
184242
if(!have_failed)
185243
__builtin_puts("Success!!!!");
186244
else

0 commit comments

Comments
 (0)