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 library itself.
Zig › std/ › testing.zig › expectEqualStrings
expectEqualStrings
testing.expectEqualStrings
pub fn expectEqualStrings (expected : []const u8 , actual : []const u8 ) !void
File
Code
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 ,
}));
}
print ("\n====== expected this output: =========\n" , .{});
printWithVisibleNewlines (expected );
print ("\n======== instead found this: =========\n" , .{});
printWithVisibleNewlines (actual );
print ("\n======================================\n" , .{});
var diff_line_number : usize = 1 ;
for (expected [0 ..diff_index ]) |value | {
if (value == '\n' ) diff_line_number += 1 ;
}
print ("First difference occurs on line {d}:\n" , .{diff_line_number });
print ("expected:\n" , .{});
printIndicatorLine (expected , diff_index );
print ("found:\n" , .{});
printIndicatorLine (actual , diff_index );
return error .TestExpectedEqual ;
}
}