| ... | @@ -2960,36 +2960,6 @@ fn testParse(source: []const u8, allocator: *mem.Allocator, anything_changed: *b | ... | @@ -2960,36 +2960,6 @@ fn testParse(source: []const u8, allocator: *mem.Allocator, anything_changed: *b |
| 2960 | return buffer.toOwnedSlice(); | 2960 | return buffer.toOwnedSlice(); |
| 2961 | } | 2961 | } |
| 2962 | | 2962 | |
| 2963 | fn printLine(line: []const u8) void { | | |
| 2964 | warn("{}⏎\n", .{line}); // Carriage return symbol | | |
| 2965 | } | | |
| 2966 | | | |
| 2967 | fn printIndicatorLine(source: []const u8, indicator_index: usize) void { | | |
| 2968 | const line_begin_index = if (mem.lastIndexOfScalar(u8, source[0..indicator_index], '\n')) |line_begin| | | |
| 2969 | line_begin + 1 | | |
| 2970 | else | | |
| 2971 | 0; | | |
| 2972 | const line_end_index = if (mem.indexOfScalar(u8, source[indicator_index..], '\n')) |line_end| | | |
| 2973 | (indicator_index + line_end) | | |
| 2974 | else | | |
| 2975 | (source.len - 1); | | |
| 2976 | printLine(source[line_begin_index..line_end_index]); | | |
| 2977 | { | | |
| 2978 | var i: usize = line_begin_index; | | |
| 2979 | while (i < indicator_index) : (i += 1) | | |
| 2980 | warn(" ", .{}); | | |
| 2981 | } | | |
| 2982 | warn("^~~~~\n", .{}); | | |
| 2983 | } | | |
| 2984 | | | |
| 2985 | fn printWithVisibleNewlines(source: []const u8) void { | | |
| 2986 | var i: usize = 0; | | |
| 2987 | while (mem.indexOf(u8, source[i..], "\n")) |nl| : (i += nl + 1) { | | |
| 2988 | printLine(source[i .. i + nl]); | | |
| 2989 | } | | |
| 2990 | warn("{}{}\n", .{ source[i..], "\u{2403}" }); // End of Text symbol (ETX) | | |
| 2991 | } | | |
| 2992 | | | |
| 2993 | fn testTransform(source: []const u8, expected_source: []const u8) !void { | 2963 | fn testTransform(source: []const u8, expected_source: []const u8) !void { |
| 2994 | const needed_alloc_count = x: { | 2964 | const needed_alloc_count = x: { |
| 2995 | // Try it once with unlimited memory, make sure it works | 2965 | // Try it once with unlimited memory, make sure it works |
| ... | @@ -2997,27 +2967,7 @@ fn testTransform(source: []const u8, expected_source: []const u8) !void { | ... | @@ -2997,27 +2967,7 @@ fn testTransform(source: []const u8, expected_source: []const u8) !void { |
| 2997 | var failing_allocator = std.testing.FailingAllocator.init(&fixed_allocator.allocator, maxInt(usize)); | 2967 | var failing_allocator = std.testing.FailingAllocator.init(&fixed_allocator.allocator, maxInt(usize)); |
| 2998 | var anything_changed: bool = undefined; | 2968 | var anything_changed: bool = undefined; |
| 2999 | const result_source = try testParse(source, &failing_allocator.allocator, &anything_changed); | 2969 | const result_source = try testParse(source, &failing_allocator.allocator, &anything_changed); |
| 3000 | if (mem.indexOfDiff(u8, result_source, expected_source)) |diff_index| { | 2970 | std.testing.expectEqualStrings(expected_source, result_source); |
| 3001 | warn("\n====== expected this output: =========\n", .{}); | | |
| 3002 | printWithVisibleNewlines(expected_source); | | |
| 3003 | warn("\n======== instead found this: =========\n", .{}); | | |
| 3004 | printWithVisibleNewlines(result_source); | | |
| 3005 | warn("\n======================================\n", .{}); | | |
| 3006 | | | |
| 3007 | var diff_line_number: usize = 1; | | |
| 3008 | for (expected_source[0..diff_index]) |value| { | | |
| 3009 | if (value == '\n') diff_line_number += 1; | | |
| 3010 | } | | |
| 3011 | warn("First difference occurs on line {}:\n", .{diff_line_number}); | | |
| 3012 | | | |
| 3013 | warn("expected:\n", .{}); | | |
| 3014 | printIndicatorLine(expected_source, diff_index); | | |
| 3015 | | | |
| 3016 | warn("found:\n", .{}); | | |
| 3017 | printIndicatorLine(result_source, diff_index); | | |
| 3018 | | | |
| 3019 | return error.TestFailed; | | |
| 3020 | } | | |
| 3021 | const changes_expected = source.ptr != expected_source.ptr; | 2971 | const changes_expected = source.ptr != expected_source.ptr; |
| 3022 | if (anything_changed != changes_expected) { | 2972 | if (anything_changed != changes_expected) { |
| 3023 | warn("std.zig.render returned {} instead of {}\n", .{ anything_changed, changes_expected }); | 2973 | warn("std.zig.render returned {} instead of {}\n", .{ anything_changed, changes_expected }); |