Zig 0.17.0-dev (Split by item) This is an example of documentation generated by
ZigDoc , an alternative to Zig's built-in
Auto Doc feature. See also
examples in other modes/formats . The project being documented here (as the example) is the Zig standard library.
std › testing › expectEqualStrings Public Function expectEqualStrings Doc Source Public Function std.testing.expectEqualStrings
pub fn expectEqualStrings (expected : []const u8 , actual : []const u8 ) !void Params expected : []const u8 actual : []const u8 File testing.zig: 668
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695 pub fn expectEqualStrings (expected : []const u8 , actual : []const u8 ) !void {
if (std .mem .findDiff (u8 , actual , expected )) |diff_index | {
if (@inComptime ()) {
@compileError (std .fmt .comptimePrint ("\nexpected:\n{s}\nfound:\n{s}\ndifference starts at index {d}" , .{
expected , actual , diff_index ,
}));
}
failPrint ("\n====== expected this output: =========\n" , .{});
failPrintWithVisibleNewlines (expected );
failPrint ("\n======== instead found this: =========\n" , .{});
failPrintWithVisibleNewlines (actual );
failPrint ("\n======================================\n" , .{});
var diff_line_number : usize = 1 ;
for (expected [0 ..diff_index ]) |value | {
if (value == '\n' ) diff_line_number += 1 ;
}
failPrint ("First difference occurs on line {d}:\n" , .{diff_line_number });
failPrint ("expected:\n" , .{});
failPrintIndicatorLine (expected , diff_index );
failPrint ("found:\n" , .{});
failPrintIndicatorLine (actual , diff_index );
return error .TestExpectedEqual ;
}
}
it prints diagnostics to stderr to show how they are not equal, then returns an error.