mirror of
https://codeberg.org/ziglang/zig.git
synced 2025-12-06 13:54:21 +00:00
add test for arrays
This commit is contained in:
parent
e8550814c5
commit
358d699fa9
2 changed files with 70 additions and 2 deletions
|
|
@ -7,9 +7,35 @@ extern {
|
||||||
}
|
}
|
||||||
|
|
||||||
export fn _start() -> unreachable {
|
export fn _start() -> unreachable {
|
||||||
let mut array : [i32; 10];
|
let mut array : [i32; 5];
|
||||||
|
|
||||||
array[4] = array[1] + 5;
|
let mut i = 0;
|
||||||
|
loop_start:
|
||||||
|
if i == 5 {
|
||||||
|
goto loop_end;
|
||||||
|
}
|
||||||
|
array[i] = i + 1;
|
||||||
|
i = array[i];
|
||||||
|
goto loop_start;
|
||||||
|
|
||||||
|
loop_end:
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
let mut accumulator = 0;
|
||||||
|
loop_2_start:
|
||||||
|
if i == 5 {
|
||||||
|
goto loop_2_end;
|
||||||
|
}
|
||||||
|
|
||||||
|
accumulator = accumulator + array[i];
|
||||||
|
|
||||||
|
i = i + 1;
|
||||||
|
goto loop_2_start;
|
||||||
|
loop_2_end:
|
||||||
|
|
||||||
|
if accumulator == 15 {
|
||||||
|
puts("OK");
|
||||||
|
}
|
||||||
|
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -355,6 +355,48 @@ done:
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
)SOURCE", "zero\nloop\nloop\nloop\n");
|
)SOURCE", "zero\nloop\nloop\nloop\n");
|
||||||
|
|
||||||
|
add_simple_case("arrays", R"SOURCE(
|
||||||
|
#link("c")
|
||||||
|
extern {
|
||||||
|
fn puts(s: *const u8) -> i32;
|
||||||
|
fn exit(code: i32) -> unreachable;
|
||||||
|
}
|
||||||
|
|
||||||
|
export fn _start() -> unreachable {
|
||||||
|
let mut array : [i32; 5];
|
||||||
|
|
||||||
|
let mut i = 0;
|
||||||
|
loop_start:
|
||||||
|
if i == 5 {
|
||||||
|
goto loop_end;
|
||||||
|
}
|
||||||
|
array[i] = i + 1;
|
||||||
|
i = array[i];
|
||||||
|
goto loop_start;
|
||||||
|
|
||||||
|
loop_end:
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
let mut accumulator = 0;
|
||||||
|
loop_2_start:
|
||||||
|
if i == 5 {
|
||||||
|
goto loop_2_end;
|
||||||
|
}
|
||||||
|
|
||||||
|
accumulator = accumulator + array[i];
|
||||||
|
|
||||||
|
i = i + 1;
|
||||||
|
goto loop_2_start;
|
||||||
|
loop_2_end:
|
||||||
|
|
||||||
|
if accumulator == 15 {
|
||||||
|
puts("OK");
|
||||||
|
}
|
||||||
|
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
)SOURCE", "OK\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
static void add_compile_failure_test_cases(void) {
|
static void add_compile_failure_test_cases(void) {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue