diff options
Diffstat (limited to 'test/behavior/array.zig')
| -rw-r--r-- | test/behavior/array.zig | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/test/behavior/array.zig b/test/behavior/array.zig index a56e382821..6397094398 100644 --- a/test/behavior/array.zig +++ b/test/behavior/array.zig @@ -804,6 +804,52 @@ test "slice initialized through reference to anonymous array init provides resul try std.testing.expectEqualSlices(u16, &.{ 123, 456, 123, 456 }, foo); } +test "sentinel-terminated slice initialized through reference to anonymous array init provides result types" { + var my_u32: u32 = 123; + var my_u64: u64 = 456; + _ = .{ &my_u32, &my_u64 }; + const foo: [:999]const u16 = &.{ + @intCast(my_u32), + @intCast(my_u64), + @truncate(my_u32), + @truncate(my_u64), + }; + try std.testing.expectEqualSentinel(u16, 999, &.{ 123, 456, 123, 456 }, foo); +} + +test "many-item pointer initialized through reference to anonymous array init provides result types" { + var my_u32: u32 = 123; + var my_u64: u64 = 456; + _ = .{ &my_u32, &my_u64 }; + const foo: [*]const u16 = &.{ + @intCast(my_u32), + @intCast(my_u64), + @truncate(my_u32), + @truncate(my_u64), + }; + try expectEqual(123, foo[0]); + try expectEqual(456, foo[1]); + try expectEqual(123, foo[2]); + try expectEqual(456, foo[3]); +} + +test "many-item sentinel-terminated pointer initialized through reference to anonymous array init provides result types" { + var my_u32: u32 = 123; + var my_u64: u64 = 456; + _ = .{ &my_u32, &my_u64 }; + const foo: [*:999]const u16 = &.{ + @intCast(my_u32), + @intCast(my_u64), + @truncate(my_u32), + @truncate(my_u64), + }; + try expectEqual(123, foo[0]); + try expectEqual(456, foo[1]); + try expectEqual(123, foo[2]); + try expectEqual(456, foo[3]); + try expectEqual(999, foo[4]); +} + test "pointer to array initialized through reference to anonymous array init provides result types" { var my_u32: u32 = 123; var my_u64: u64 = 456; @@ -817,6 +863,19 @@ test "pointer to array initialized through reference to anonymous array init pro try std.testing.expectEqualSlices(u16, &.{ 123, 456, 123, 456 }, foo); } +test "pointer to sentinel-terminated array initialized through reference to anonymous array init provides result types" { + var my_u32: u32 = 123; + var my_u64: u64 = 456; + _ = .{ &my_u32, &my_u64 }; + const foo: *const [4:999]u16 = &.{ + @intCast(my_u32), + @intCast(my_u64), + @truncate(my_u32), + @truncate(my_u64), + }; + try std.testing.expectEqualSentinel(u16, 999, &.{ 123, 456, 123, 456 }, foo); +} + test "tuple initialized through reference to anonymous array init provides result types" { const Tuple = struct { u64, *const u32 }; const foo: *const Tuple = &.{ |
