aboutsummaryrefslogtreecommitdiff
path: root/test/behavior/array.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2021-10-21 19:05:26 -0700
committerAndrew Kelley <andrew@ziglang.org>2021-10-21 19:05:26 -0700
commit7f70c27e9d57c8234545120da81861e2cfb354b5 (patch)
tree47948dcf37e5e5767db2b428a8ef8177ef8eee86 /test/behavior/array.zig
parenta3c9bfef301e0a4675fcea57356653334e07df45 (diff)
downloadzig-7f70c27e9d57c8234545120da81861e2cfb354b5.tar.gz
zig-7f70c27e9d57c8234545120da81861e2cfb354b5.zip
stage2: more division support
AIR: * div is renamed to div_trunc. * Add div_float, div_floor, div_exact. - Implemented in Sema and LLVM codegen. C backend has a stub. Improvements to std.math.big.Int: * Add `eqZero` function to `Mutable`. * Fix incorrect results for `divFloor`. Compiler-rt: * Add muloti4 to the stage2 section.
Diffstat (limited to 'test/behavior/array.zig')
-rw-r--r--test/behavior/array.zig52
1 files changed, 52 insertions, 0 deletions
diff --git a/test/behavior/array.zig b/test/behavior/array.zig
index 0b4babca67..3ff339b140 100644
--- a/test/behavior/array.zig
+++ b/test/behavior/array.zig
@@ -112,3 +112,55 @@ test "void arrays" {
try expect(@sizeOf(@TypeOf(array)) == 0);
try expect(array.len == 4);
}
+
+test "nested arrays" {
+ const array_of_strings = [_][]const u8{ "hello", "this", "is", "my", "thing" };
+ for (array_of_strings) |s, i| {
+ if (i == 0) try expect(mem.eql(u8, s, "hello"));
+ if (i == 1) try expect(mem.eql(u8, s, "this"));
+ if (i == 2) try expect(mem.eql(u8, s, "is"));
+ if (i == 3) try expect(mem.eql(u8, s, "my"));
+ if (i == 4) try expect(mem.eql(u8, s, "thing"));
+ }
+}
+
+var s_array: [8]Sub = undefined;
+const Sub = struct { b: u8 };
+const Str = struct { a: []Sub };
+test "set global var array via slice embedded in struct" {
+ var s = Str{ .a = s_array[0..] };
+
+ s.a[0].b = 1;
+ s.a[1].b = 2;
+ s.a[2].b = 3;
+
+ try expect(s_array[0].b == 1);
+ try expect(s_array[1].b == 2);
+ try expect(s_array[2].b == 3);
+}
+
+test "implicit comptime in array type size" {
+ var arr: [plusOne(10)]bool = undefined;
+ try expect(arr.len == 11);
+}
+
+fn plusOne(x: u32) u32 {
+ return x + 1;
+}
+
+test "read/write through global variable array of struct fields initialized via array mult" {
+ const S = struct {
+ fn doTheTest() !void {
+ try expect(storage[0].term == 1);
+ storage[0] = MyStruct{ .term = 123 };
+ try expect(storage[0].term == 123);
+ }
+
+ pub const MyStruct = struct {
+ term: usize,
+ };
+
+ var storage: [1]MyStruct = [_]MyStruct{MyStruct{ .term = 1 }} ** 1;
+ };
+ try S.doTheTest();
+}