pub fn expectStringEndsWith(actual: []const u8, expected_ends_with: []const u8) !void actual: []const u8expected_ends_with: []const u8729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747pub fn expectStringEndsWith(actual: []const u8, expected_ends_with: []const u8) !void {
if (std.mem.endsWith(u8, actual, expected_ends_with))
return;
const shortened_actual = if (actual.len >= expected_ends_with.len)
actual[(actual.len - expected_ends_with.len)..]
else
actual;
failPrint("\n====== expected to end with: =========\n", .{});
failPrintWithVisibleNewlines(expected_ends_with);
failPrint("\n====== instead ended with: ===========\n", .{});
failPrintWithVisibleNewlines(shortened_actual);
failPrint("\n========= full output: ==============\n", .{});
failPrintWithVisibleNewlines(actual);
failPrint("\n======================================\n", .{});
return error.TestExpectedEndsWith;
}
This function is intended to be used only in test. When the end of
actualandexpected_ends_withare not equal, it prints diagnostics to stderr to show how they are not equal, then returns an error.