mirror of
https://github.com/lightpanda-io/browser.git
synced 2025-10-29 15:13:28 +00:00
Zig 0.14 compatibility
This commit is contained in:
committed by
Pierre Tachoire
parent
17d3d620ff
commit
21c9dde858
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user