diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2021-09-13 21:37:11 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2021-09-13 21:37:11 -0700 |
| commit | 97d69e3352ab50f88580c383b5f375b0edadacfd (patch) | |
| tree | 8245d3d55b3304c19ca18238a01d6532031e1ff8 /test/behavior/array.zig | |
| parent | a9a21c59888905e060915dee818633110cc54cfa (diff) | |
| download | zig-97d69e3352ab50f88580c383b5f375b0edadacfd.tar.gz zig-97d69e3352ab50f88580c383b5f375b0edadacfd.zip | |
stage2: add array_to_slice AIR instruction
Diffstat (limited to 'test/behavior/array.zig')
| -rw-r--r-- | test/behavior/array.zig | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/test/behavior/array.zig b/test/behavior/array.zig index 232ba87f55..8cf0042d5f 100644 --- a/test/behavior/array.zig +++ b/test/behavior/array.zig @@ -3,3 +3,27 @@ const testing = std.testing; const mem = std.mem; const expect = testing.expect; const expectEqual = testing.expectEqual; + +test "arrays" { + var array: [5]u32 = undefined; + + var i: u32 = 0; + while (i < 5) { + array[i] = i + 1; + i = array[i]; + } + + i = 0; + var accumulator = @as(u32, 0); + while (i < 5) { + accumulator += array[i]; + + i += 1; + } + + try expect(accumulator == 15); + try expect(getArrayLen(&array) == 5); +} +fn getArrayLen(a: []const u32) usize { + return a.len; +} |
