diff options
| author | Andrew Kelley <superjoe30@gmail.com> | 2016-12-26 02:49:30 -0500 |
|---|---|---|
| committer | Andrew Kelley <superjoe30@gmail.com> | 2016-12-26 02:49:30 -0500 |
| commit | 6c9ec3688eead05f1c41e0444a17e1d2bdb7a21e (patch) | |
| tree | fd8a9ca5e291fec0fce4ac17f77d018df4298c64 /test/cases/array.zig | |
| parent | 66777ccd7d3744670fe58d451f982f29d65612ac (diff) | |
| download | zig-6c9ec3688eead05f1c41e0444a17e1d2bdb7a21e.tar.gz zig-6c9ec3688eead05f1c41e0444a17e1d2bdb7a21e.zip | |
IR testing: rename cases3 dir to cases
Diffstat (limited to 'test/cases/array.zig')
| -rw-r--r-- | test/cases/array.zig | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/test/cases/array.zig b/test/cases/array.zig new file mode 100644 index 0000000000..d27b611a9d --- /dev/null +++ b/test/cases/array.zig @@ -0,0 +1,64 @@ +fn arrays() { + @setFnTest(this); + + var array : [5]u32 = undefined; + + var i : u32 = 0; + while (i < 5) { + array[i] = i + 1; + i = array[i]; + } + + i = 0; + var accumulator = u32(0); + while (i < 5) { + accumulator += array[i]; + + i += 1; + } + + assert(accumulator == 15); + assert(getArrayLen(array) == 5); +} +fn getArrayLen(a: []u32) -> usize { + a.len +} + +fn voidArrays() { + @setFnTest(this); + + var array: [4]void = undefined; + array[0] = void{}; + array[1] = array[2]; + assert(@sizeOf(@typeOf(array)) == 0); + assert(array.len == 4); +} + +fn arrayLiteral() { + @setFnTest(this); + + const hex_mult = []u16{4096, 256, 16, 1}; + + assert(hex_mult.len == 4); + assert(hex_mult[1] == 256); +} + +fn arrayDotLenConstExpr() { + @setFnTest(this); + + assert(@staticEval(some_array.len) == 4); +} + +const ArrayDotLenConstExpr = struct { + y: [some_array.len]u8, +}; +const some_array = []u8 {0, 1, 2, 3}; + + + + +// TODO const assert = @import("std").debug.assert; +fn assert(ok: bool) { + if (!ok) + @unreachable(); +} |
