| ... | @@ -125,7 +125,7 @@ fn expectEqualInner(comptime T: type, expected: T, actual: T) !void { | ... | @@ -125,7 +125,7 @@ fn expectEqualInner(comptime T: type, expected: T, actual: T) !void { |
| 125 | var i: usize = 0; | 125 | var i: usize = 0; |
| 126 | while (i < info.len) : (i += 1) { | 126 | while (i < info.len) : (i += 1) { |
| 127 | if (!std.meta.eql(expected[i], actual[i])) { | 127 | if (!std.meta.eql(expected[i], actual[i])) { |
| 128 | print("index {} incorrect. expected {}, found {}\n", .{ | 128 | print("index {d} incorrect. expected {any}, found {any}\n", .{ |
| 129 | i, expected[i], actual[i], | 129 | i, expected[i], actual[i], |
| 130 | }); | 130 | }); |
| 131 | return error.TestExpectedEqual; | 131 | return error.TestExpectedEqual; |
| ... | @@ -214,6 +214,34 @@ test "expectEqual union with comptime-only field" { | ... | @@ -214,6 +214,34 @@ test "expectEqual union with comptime-only field" { |
| 214 | try expectEqual(U{ .a = {} }, .a); | 214 | try expectEqual(U{ .a = {} }, .a); |
| 215 | } | 215 | } |
| 216 | | 216 | |
| | 217 | test "expectEqual nested array" { |
| | 218 | const a = [2][2]f32{ |
| | 219 | [_]f32{ 1.0, 0.0 }, |
| | 220 | [_]f32{ 0.0, 1.0 }, |
| | 221 | }; |
| | 222 | |
| | 223 | const b = [2][2]f32{ |
| | 224 | [_]f32{ 1.0, 0.0 }, |
| | 225 | [_]f32{ 0.0, 1.0 }, |
| | 226 | }; |
| | 227 | |
| | 228 | try expectEqual(a, b); |
| | 229 | } |
| | 230 | |
| | 231 | test "expectEqual vector" { |
| | 232 | const a: @Vector(4, u32) = @splat(4); |
| | 233 | const b: @Vector(4, u32) = @splat(4); |
| | 234 | |
| | 235 | try expectEqual(a, b); |
| | 236 | } |
| | 237 | |
| | 238 | test "expectEqual null" { |
| | 239 | const a = .{null}; |
| | 240 | const b = @Vector(1, ?*u8){null}; |
| | 241 | |
| | 242 | try expectEqual(a, b); |
| | 243 | } |
| | 244 | |
| 217 | /// This function is intended to be used only in tests. When the formatted result of the template | 245 | /// This function is intended to be used only in tests. When the formatted result of the template |
| 218 | /// and its arguments does not equal the expected text, it prints diagnostics to stderr to show how | 246 | /// and its arguments does not equal the expected text, it prints diagnostics to stderr to show how |
| 219 | /// they are not equal, then returns an error. It depends on `expectEqualStrings()` for printing | 247 | /// they are not equal, then returns an error. It depends on `expectEqualStrings()` for printing |
| ... | @@ -584,27 +612,6 @@ pub fn tmpDir(opts: std.fs.Dir.OpenOptions) TmpDir { | ... | @@ -584,27 +612,6 @@ pub fn tmpDir(opts: std.fs.Dir.OpenOptions) TmpDir { |
| 584 | }; | 612 | }; |
| 585 | } | 613 | } |
| 586 | | 614 | |
| 587 | test "expectEqual nested array" { | | |
| 588 | const a = [2][2]f32{ | | |
| 589 | [_]f32{ 1.0, 0.0 }, | | |
| 590 | [_]f32{ 0.0, 1.0 }, | | |
| 591 | }; | | |
| 592 | | | |
| 593 | const b = [2][2]f32{ | | |
| 594 | [_]f32{ 1.0, 0.0 }, | | |
| 595 | [_]f32{ 0.0, 1.0 }, | | |
| 596 | }; | | |
| 597 | | | |
| 598 | try expectEqual(a, b); | | |
| 599 | } | | |
| 600 | | | |
| 601 | test "expectEqual vector" { | | |
| 602 | const a: @Vector(4, u32) = @splat(4); | | |
| 603 | const b: @Vector(4, u32) = @splat(4); | | |
| 604 | | | |
| 605 | try expectEqual(a, b); | | |
| 606 | } | | |
| 607 | | | |
| 608 | pub fn expectEqualStrings(expected: []const u8, actual: []const u8) !void { | 615 | pub fn expectEqualStrings(expected: []const u8, actual: []const u8) !void { |
| 609 | if (std.mem.indexOfDiff(u8, actual, expected)) |diff_index| { | 616 | if (std.mem.indexOfDiff(u8, actual, expected)) |diff_index| { |
| 610 | print("\n====== expected this output: =========\n", .{}); | 617 | print("\n====== expected this output: =========\n", .{}); |