Zig 0.14 compatibility

This commit is contained in:
Karl Seguin
2025-03-06 23:00:13 +08:00
committed by Pierre Tachoire
parent 17d3d620ff
commit 21c9dde858
26 changed files with 78 additions and 197 deletions

View File

@@ -11,10 +11,10 @@ const App = @import("app.zig").App;
// exactly how to assert equality
pub fn expectEqual(expected: anytype, actual: anytype) !void {
switch (@typeInfo(@TypeOf(actual))) {
.Array => |arr| if (arr.child == u8) {
.array => |arr| if (arr.child == u8) {
return std.testing.expectEqualStrings(expected, &actual);
},
.Pointer => |ptr| {
.pointer => |ptr| {
if (ptr.child == u8) {
return std.testing.expectEqualStrings(expected, actual);
} else if (comptime isStringArray(ptr.child)) {
@@ -23,19 +23,19 @@ pub fn expectEqual(expected: anytype, actual: anytype) !void {
return expectString(expected, actual);
}
},
.Struct => |structType| {
.@"struct" => |structType| {
inline for (structType.fields) |field| {
try expectEqual(@field(expected, field.name), @field(actual, field.name));
}
return;
},
.Optional => {
.optional => {
if (actual == null) {
return std.testing.expectEqual(null, expected);
}
return expectEqual(expected, actual.?);
},
.Union => |union_info| {
.@"union" => |union_info| {
if (union_info.tag_type == null) {
@compileError("Unable to compare untagged union values");
}
@@ -59,12 +59,12 @@ pub fn expectEqual(expected: anytype, actual: anytype) !void {
}
pub fn expectDelta(expected: anytype, actual: anytype, delta: anytype) !void {
if (@typeInfo(@TypeOf(expected)) == .Null) {
if (@typeInfo(@TypeOf(expected)) == .null) {
return std.testing.expectEqual(null, actual);
}
switch (@typeInfo(@TypeOf(actual))) {
.Optional => {
.optional => {
if (actual) |value| {
return expectDelta(expected, value, delta);
}
@@ -74,7 +74,7 @@ pub fn expectDelta(expected: anytype, actual: anytype, delta: anytype) !void {
}
switch (@typeInfo(@TypeOf(expected))) {
.Optional => {
.optional => {
if (expected) |value| {
return expectDelta(value, actual, delta);
}
@@ -96,7 +96,7 @@ pub fn expectDelta(expected: anytype, actual: anytype, delta: anytype) !void {
}
fn isStringArray(comptime T: type) bool {
if (!is(.Array)(T) and !isPtrTo(.Array)(T)) {
if (!is(.array)(T) and !isPtrTo(.array)(T)) {
return false;
}
return std.meta.Elem(T) == u8;
@@ -124,7 +124,7 @@ pub fn isPtrTo(comptime id: std.builtin.TypeId) TraitFn {
pub fn isSingleItemPtr(comptime T: type) bool {
if (comptime is(.pointer)(T)) {
return @typeInfo(T).Pointer.size == .one;
return @typeInfo(T).pointer.size == .one;
}
return false;
}