pub fn expectStringStartsWith(actual: []const u8, expected_starts_with: []const u8) !void actual: []const u8expected_starts_with: []const u8703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721pub fn expectStringStartsWith(actual: []const u8, expected_starts_with: []const u8) !void {
if (std.mem.startsWith(u8, actual, expected_starts_with))
return;
const shortened_actual = if (actual.len >= expected_starts_with.len)
actual[0..expected_starts_with.len]
else
actual;
failPrint("\n====== expected to start with: =========\n", .{});
failPrintWithVisibleNewlines(expected_starts_with);
failPrint("\n====== instead started with: ===========\n", .{});
failPrintWithVisibleNewlines(shortened_actual);
failPrint("\n========= full output: ==============\n", .{});
failPrintWithVisibleNewlines(actual);
failPrint("\n======================================\n", .{});
return error.TestExpectedStartsWith;
}
This function is intended to be used only in test. When the start of
actualandexpected_starts_withare not equal, it prints diagnostics to stderr to show how they are not equal, then returns an error.