master
 1const std = @import("std");
 2const builtin = @import("builtin");
 3const testing = std.testing;
 4const expect = testing.expect;
 5const expectEqualStrings = testing.expectEqualStrings;
 6
 7test "tuple declaration type info" {
 8    if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
 9    if (builtin.zig_backend == .stage2_spirv) return error.SkipZigTest;
10
11    {
12        const T = struct { comptime u32 = 1, []const u8 };
13        const info = @typeInfo(T).@"struct";
14
15        try expect(info.layout == .auto);
16        try expect(info.backing_integer == null);
17        try expect(info.fields.len == 2);
18        try expect(info.decls.len == 0);
19        try expect(info.is_tuple);
20
21        try expectEqualStrings(info.fields[0].name, "0");
22        try expect(info.fields[0].type == u32);
23        try expect(info.fields[0].defaultValue() == 1);
24        try expect(info.fields[0].is_comptime);
25        try expect(info.fields[0].alignment == @alignOf(u32));
26
27        try expectEqualStrings(info.fields[1].name, "1");
28        try expect(info.fields[1].type == []const u8);
29        try expect(info.fields[1].defaultValue() == null);
30        try expect(!info.fields[1].is_comptime);
31        try expect(info.fields[1].alignment == @alignOf([]const u8));
32    }
33}
34
35test "tuple declaration usage" {
36    if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
37    if (builtin.zig_backend == .stage2_spirv) return error.SkipZigTest;
38
39    const T = struct { u32, []const u8 };
40    var t: T = .{ 1, "foo" };
41    _ = &t;
42    try expect(t[0] == 1);
43    try expectEqualStrings(t[1], "foo");
44
45    const mul = t ** 3;
46    try expect(@TypeOf(mul) != T);
47    try expect(mul.len == 6);
48    try expect(mul[2] == 1);
49    try expectEqualStrings(mul[3], "foo");
50
51    var t2: T = .{ 2, "bar" };
52    _ = &t2;
53    const cat = t ++ t2;
54    try expect(@TypeOf(cat) != T);
55    try expect(cat.len == 4);
56    try expect(cat[2] == 2);
57    try expectEqualStrings(cat[3], "bar");
58}