std: Use {s} instead of {} when printing strings
This commit is contained in:
@@ -29,10 +29,11 @@ pub var zig_exe_path: []const u8 = undefined;
|
||||
/// and then aborts when actual_error_union is not expected_error.
|
||||
pub fn expectError(expected_error: anyerror, actual_error_union: anytype) void {
|
||||
if (actual_error_union) |actual_payload| {
|
||||
std.debug.panic("expected error.{}, found {}", .{ @errorName(expected_error), actual_payload });
|
||||
// std.debug.panic("expected error.{s}, found {}", .{ @errorName(expected_error), actual_payload });
|
||||
std.debug.panic("expected error.{s}, found", .{@errorName(expected_error)});
|
||||
} else |actual_error| {
|
||||
if (expected_error != actual_error) {
|
||||
std.debug.panic("expected error.{}, found error.{}", .{
|
||||
std.debug.panic("expected error.{s}, found error.{s}", .{
|
||||
@errorName(expected_error),
|
||||
@errorName(actual_error),
|
||||
});
|
||||
@@ -60,7 +61,7 @@ pub fn expectEqual(expected: anytype, actual: @TypeOf(expected)) void {
|
||||
|
||||
.Type => {
|
||||
if (actual != expected) {
|
||||
std.debug.panic("expected type {}, found type {}", .{ @typeName(expected), @typeName(actual) });
|
||||
std.debug.panic("expected type {s}, found type {s}", .{ @typeName(expected), @typeName(actual) });
|
||||
}
|
||||
},
|
||||
|
||||
@@ -360,7 +361,7 @@ pub fn expectEqualStrings(expected: []const u8, actual: []const u8) void {
|
||||
for (expected[0..diff_index]) |value| {
|
||||
if (value == '\n') diff_line_number += 1;
|
||||
}
|
||||
print("First difference occurs on line {}:\n", .{diff_line_number});
|
||||
print("First difference occurs on line {d}:\n", .{diff_line_number});
|
||||
|
||||
print("expected:\n", .{});
|
||||
printIndicatorLine(expected, diff_index);
|
||||
@@ -416,15 +417,15 @@ fn printWithVisibleNewlines(source: []const u8) void {
|
||||
while (std.mem.indexOf(u8, source[i..], "\n")) |nl| : (i += nl + 1) {
|
||||
printLine(source[i .. i + nl]);
|
||||
}
|
||||
print("{}␃\n", .{source[i..]}); // End of Text symbol (ETX)
|
||||
print("{s}␃\n", .{source[i..]}); // End of Text symbol (ETX)
|
||||
}
|
||||
|
||||
fn printLine(line: []const u8) void {
|
||||
if (line.len != 0) switch (line[line.len - 1]) {
|
||||
' ', '\t' => print("{}⏎\n", .{line}), // Carriage return symbol,
|
||||
' ', '\t' => print("{s}⏎\n", .{line}), // Carriage return symbol,
|
||||
else => {},
|
||||
};
|
||||
print("{}\n", .{line});
|
||||
print("{s}\n", .{line});
|
||||
}
|
||||
|
||||
test "" {
|
||||
|
||||
Reference in New Issue
Block a user