mirror of
https://github.com/ziglang/zig.git
synced 2025-12-14 18:23:12 +00:00
Effectively a small continuation of #10152 This allows the for.zig behavior tests to pass. Unfortunately to fully test everything I had to move a lot of behavior tests from array.zig; most of them now pass (sorry @rainbowbismuth!) I'm also conflicted on how I store constants into arrays because it's kind of stupid; array's can't be re-initialized using the same syntax, so instead of initializing each element, a new array is made which is copied into the destination. This also required that renderValue can't emit string literals for byte arrays given that they need to always have an extra byte for the NULL terminator, meaning that strings are no longer grep-able in the output.
36 lines
932 B
Zig
36 lines
932 B
Zig
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();
|
|
}
|