summaryrefslogtreecommitdiff
path: root/test/consumer
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-21 05:30:58 -0300
committerGabriel Schneider <[email protected]>2026-11-21 05:31:07 -0300
commited0103e9738e3cf5a7c7a91aec5adf0be2fc409a (patch)
tree99add792416c5827ce515e892f2de3274225ab30 /test/consumer
parentd04f4acfb9af968caaa53d6cf10a486622c95400 (diff)
downloadpardes-ed0103e9738e3cf5a7c7a91aec5adf0be2fc409a.tar.gz
pardes-ed0103e9738e3cf5a7c7a91aec5adf0be2fc409a.zip
library: a patch row's text is its line without its end, said and tested: hunks.format trims a diff line's `\r` before its `\n` (and diff.Walk.step, and each of a source's lines, so the two compare) on purpose, and nothing a consumer reads said so (toilet saw a CRLF file's rows without their `\r`); the Patch doc comment, lib_syntax's, abi/wasm.zig's record and docs/typ/building.typ (the patch view, the record's text) say it now; test/consumer: a CRLF diff stacks to the LF diff's rows with no file, and with a CRLF main.c handed in its lines still match the diff's (its declaration found above `main.c:3 *`); no code changes
Co-Authored-By: Claude Opus <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
Diffstat (limited to 'test/consumer')
-rw-r--r--test/consumer/lib.zig25
1 files changed, 25 insertions, 0 deletions
diff --git a/test/consumer/lib.zig b/test/consumer/lib.zig
index fa0f8aee..ea0d56fd 100644
--- a/test/consumer/lib.zig
+++ b/test/consumer/lib.zig
@@ -254,3 +254,28 @@ test "a diff stacked with its file handed in: the declaration it stands in, from
try std.testing.expectEqual(pardes.PatchRow.Kind.hunk, p.rows[2].kind);
try std.testing.expectEqual("main.c:3".len, p.rows[2].location_end);
}
+
+test "a row's text is its line without its end: a CRLF diff's rows have no \\r, and a CRLF file handed in still matches" {
+ const gpa = std.testing.allocator;
+ pardes.start(gpa);
+ defer pardes.stop();
+ var arena: std.heap.ArenaAllocator = .init(gpa);
+ defer arena.deinit();
+ const a = arena.allocator();
+ const patch_crlf = try std.mem.replaceOwned(u8, a, patch_c, "\n", "\r\n");
+ const Given = struct {
+ var text: []const u8 = "";
+ fn source(_: *const pardes.PatchCtx, _: []const u8, path: []const u8) ?pardes.PatchSource {
+ return .{ .path = path, .bytes = text };
+ }
+ };
+ Given.text = try std.mem.replaceOwned(u8, a, main_c, "\n", "\r\n");
+ // no file: the rows as an LF diff's
+ const plain = try pardes.formatPatch(&.{ .arena = a }, "", patch_crlf);
+ try std.testing.expectEqualStrings("main.c:3\n int main(void)\n {\n- int x = foo(1);\n+ int x = bar(1);\n return x;\n }\n", plain.text);
+ try std.testing.expect(plain.rows[6].no_newline);
+ // a CRLF file: its lines compare with the diff's, so its declaration is found
+ const given = try pardes.formatPatch(&.{ .arena = a, .source = Given.source, .declarations = pardes.PatchCtx.parsed }, "", patch_crlf);
+ try std.testing.expectEqualStrings("main.c:1\n int main(void)\nmain.c:3 *\n {\n- int x = foo(1);\n+ int x = bar(1);\n return x;\n }\n", given.text);
+ try std.testing.expectEqual(pardes.PatchRow.Kind.declaration, given.rows[0].kind);
+}