Zig 0.17.0-dev (Split by item)

Shortcut keys
?
Show these tips
S
Focus search field
Esc
Clear focus & close tips
U
Jump to source code
↑
Move up in search results
↓
Move down in search results
↵
Go to active search result
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. Public Function

expectEqualStrings

Public Function
std.testing.expectEqualStrings
pub fn expectEqualStrings(expected: []const u8, actual: []const u8) !void

it prints diagnostics to stderr to show how they are not equal, then returns an error.

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;
    }
}