From d1a58e6ef03d4b970d172b4339ff0fb1d6180dab Mon Sep 17 00:00:00 2001 From: pfg Date: Tue, 15 Jul 2025 21:16:15 -0700 Subject: [PATCH] wip --- src/bun.js/test/diff_format.zig | 18 +++++++++++------- src/deps/diffz/DiffMatchPatch.zig | 4 ++-- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/bun.js/test/diff_format.zig b/src/bun.js/test/diff_format.zig index 4881156960..386cd28e6a 100644 --- a/src/bun.js/test/diff_format.zig +++ b/src/bun.js/test/diff_format.zig @@ -7,19 +7,23 @@ pub const DiffFormatter = struct { not: bool = false, pub fn format(this: DiffFormatter, comptime _: []const u8, _: std.fmt.FormatOptions, writer: anytype) !void { + var scope = bun.AllocationScope.init(default_allocator); + // defer scope.deinit(); // TODO: fix leaks + const allocator = scope.allocator(); + if (this.expected_string != null and this.received_string != null) { const received = this.received_string.?; const expected = this.expected_string.?; - try printDiff(this.not, received, expected, writer); + try printDiff(allocator, this.not, received, expected, writer); return; } if (this.received == null or this.expected == null) return; const received = this.received.?; - var received_buf = MutableString.init(default_allocator, 0) catch unreachable; - var expected_buf = MutableString.init(default_allocator, 0) catch unreachable; + var received_buf = MutableString.init(allocator, 0) catch unreachable; + var expected_buf = MutableString.init(allocator, 0) catch unreachable; defer { received_buf.deinit(); expected_buf.deinit(); @@ -70,11 +74,11 @@ pub const DiffFormatter = struct { const received_slice = received_buf.slice(); const expected_slice = expected_buf.slice(); - try printDiff(this.not, received_slice, expected_slice, writer); + try printDiff(allocator, this.not, received_slice, expected_slice, writer); } }; -fn printDiff(not: bool, received_slice: string, expected_slice: string, writer: anytype) !void { +fn printDiff(allocator: std.mem.Allocator, not: bool, received_slice: string, expected_slice: string, writer: anytype) !void { if (not) { const not_fmt = "Expected: not {s}"; if (Output.enable_ansi_colors) { @@ -88,8 +92,8 @@ fn printDiff(not: bool, received_slice: string, expected_slice: string, writer: // Always use line-based diff for consistency var dmp = DiffMatchPatch.default; dmp.diff_timeout = 200; - var diffs = try dmp.diff(default_allocator, received_slice, expected_slice, received_slice.len > 300 or expected_slice.len > 300); - defer diffs.deinit(default_allocator); + var diffs = try dmp.diff(allocator, received_slice, expected_slice, received_slice.len > 300 or expected_slice.len > 300); + defer diffs.deinit(allocator); const equal_fmt = " {s}"; const delete_fmt = "-{s}"; diff --git a/src/deps/diffz/DiffMatchPatch.zig b/src/deps/diffz/DiffMatchPatch.zig index 060c0b4778..23307b7496 100644 --- a/src/deps/diffz/DiffMatchPatch.zig +++ b/src/deps/diffz/DiffMatchPatch.zig @@ -685,7 +685,7 @@ const LinesToCharsResult = struct { /// @return Three element Object array, containing the encoded text1, the /// encoded text2 and the List of unique strings. The zeroth element /// of the List of unique strings is intentionally blank. -fn diffLinesToChars( +pub fn diffLinesToChars( allocator: std.mem.Allocator, text1: []const u8, text2: []const u8, @@ -754,7 +754,7 @@ fn diffLinesToCharsMunge( /// of text. /// @param diffs List of Diff objects. /// @param lineArray List of unique strings. -fn diffCharsToLines( +pub fn diffCharsToLines( allocator: std.mem.Allocator, diffs: []Diff, line_array: []const []const u8,