authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2024-01-28 22:02:23 -08:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2024-01-28 22:02:23 -08:00
log081f21d7b99764305f3025bb007c7caf2c2422ef
treec5365c3a4d880830dec0c3f0a5a100dbd3f3059e
parent0338911c09c3dc9ed6a3577b6b15573cfd14db32

add expectSimilarType


2 files changed, 40 insertions(+), 0 deletions(-)

src/expectSimilarType.zig created+39
...@@ -0,0 +1,39 @@
1const std = @import("std");
2const string = []const u8;
3const extras = @import("./lib.zig");
4
5pub fn expectSimilarType(comptime A: type, comptime B: type) !void {
6 const info_a = @typeInfo(A);
7 const info_b = @typeInfo(B);
8 try std.testing.expect(std.meta.activeTag(info_a) == std.meta.activeTag(info_b));
9
10 if (info_a == .Struct) {
11 const info_a_s = info_a.Struct;
12 const info_b_s = info_b.Struct;
13
14 try std.testing.expect(info_a_s.layout == info_b_s.layout);
15 try std.testing.expect(info_a_s.is_tuple == info_b_s.is_tuple);
16 try std.testing.expect(info_a_s.backing_integer == info_b_s.backing_integer);
17
18 for (info_a_s.decls, info_b_s.decls) |da, db| {
19 try std.testing.expect(std.mem.eql(u8, da.name, db.name));
20 }
21
22 inline for (info_a_s.fields, info_b_s.fields) |fa, fb| {
23 try std.testing.expect(std.mem.eql(u8, fa.name, fb.name));
24 try std.testing.expect(fa.type == fb.type);
25 try std.testing.expect(fa.alignment == fb.alignment);
26 try std.testing.expect(fa.is_comptime == fb.is_comptime);
27 }
28
29 return;
30 }
31 @compileError("not implemented");
32}
33
34test {
35 try expectSimilarType(
36 struct { a: u32, b: u8, c: u16 },
37 struct { a: u32, b: u8, c: u16 },
38 );
39}
src/lib.zig+1
...@@ -88,3 +88,4 @@ pub fn fd_realpath(fd: std.os.fd_t) ![std.fs.MAX_PATH_BYTES:0]u8 {...@@ -88,3 +88,4 @@ pub fn fd_realpath(fd: std.os.fd_t) ![std.fs.MAX_PATH_BYTES:0]u8 {
88}88}
8989
90pub usingnamespace @import("./rawInt.zig");90pub usingnamespace @import("./rawInt.zig");
91pub usingnamespace @import("./expectSimilarType.zig");