diff options
Diffstat (limited to 'test/behavior/array_llvm.zig')
| -rw-r--r-- | test/behavior/array_llvm.zig | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/test/behavior/array_llvm.zig b/test/behavior/array_llvm.zig new file mode 100644 index 0000000000..8e65045210 --- /dev/null +++ b/test/behavior/array_llvm.zig @@ -0,0 +1,35 @@ +const std = @import("std"); +const testing = std.testing; +const expect = testing.expect; + +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 "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(); +} |
