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.is_tuple);
16 try expect(info.layout == .auto);
17 try expect(info.backing_integer == null);
18 try expect(info.field_names.len == 2);
19 try expect(info.decl_names.len == 0);
20
21 try expectEqualStrings(info.field_names[0], "0");
22 try expect(info.field_types[0] == u32);
23 try expect(info.field_attrs[0].defaultValue(info.field_types[0]) == 1);
24 try expect(info.field_attrs[0].@"comptime");
25 try expect(info.field_attrs[0].@"align" == null);
26
27 try expectEqualStrings(info.field_names[1], "1");
28 try expect(info.field_types[1] == []const u8);
29 try expect(info.field_attrs[1].defaultValue(info.field_types[1]) == null);
30 try expect(!info.field_attrs[1].@"comptime");
31 try expect(info.field_attrs[1].@"align" == null);
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 var t2: T = .{ 2, "bar" };
46 _ = &t2;
47 const cat = t ++ t2;
48 try expect(@TypeOf(cat) != T);
49 try expect(cat.len == 4);
50 try expect(cat[2] == 2);
51 try expectEqualStrings(cat[3], "bar");
52}