summaryrefslogtreecommitdiff
path: root/test/consumer/none.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-21 05:29:51 -0300
committerGabriel Schneider <[email protected]>2026-11-21 05:29:51 -0300
commit63538d28cee238ff53c731f965c22e615d43bec1 (patch)
treefb00203f05512a9f14d0e8089a2f4b1919edffc9 /test/consumer/none.zig
parent638122f18a66669c433e332c91fc8b068019681e (diff)
parentd04f4acfb9af968caaa53d6cf10a486622c95400 (diff)
downloadpardes-63538d28cee238ff53c731f965c22e615d43bec1.tar.gz
pardes-63538d28cee238ff53c731f965c22e615d43bec1.zip
integration: the library for a browser reader on the gathered line: pardes-syntax-lib (`wqlkznns`: a dependent package names its languages, the patch view without the editor as formatPatch, build.zig's wasmModule and abi/wasm.zig, the manual) and pardes-reorg (`ukkqwpqu`: the terminals' line, the wire at 26); no conflict; its gate: .scratch/sketch/reorg/merge47, the numbers in PARDES.md (2026-11-21)
Co-Authored-By: Claude Fable 5.2 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
Diffstat (limited to 'test/consumer/none.zig')
-rw-r--r--test/consumer/none.zig56
1 files changed, 56 insertions, 0 deletions
diff --git a/test/consumer/none.zig b/test/consumer/none.zig
new file mode 100644
index 00000000..a389d429
--- /dev/null
+++ b/test/consumer/none.zig
@@ -0,0 +1,56 @@
+//! The patch view in a build with no grammar at all (`.grammars = .none`):
+//! a diff of a file in a language it does not have still gets its grounds,
+//! its changed words and its rows, and the colours it is not given stay
+//! out.
+const std = @import("std");
+const ps = @import("pardes-syntax");
+
+const patch_rs =
+ \\diff --git a/src/lib.rs b/src/lib.rs
+ \\--- a/src/lib.rs
+ \\+++ b/src/lib.rs
+ \\@@ -10,3 +10,3 @@ fn total(items: &[u32]) -> u32 {
+ \\ let mut sum = 0;
+ \\- for i in items { sum += i; }
+ \\+ for i in items { sum += *i; }
+ \\ sum
+ \\
+;
+
+test "a diff with no grammar in the build: rows, grounds and changed words, no colours" {
+ var arena: std.heap.ArenaAllocator = .init(std.testing.allocator);
+ defer arena.deinit();
+ try std.testing.expect(!ps.supportsPath("lib.rs"));
+ const ctx: ps.PatchCtx = .{ .arena = arena.allocator() };
+ const p = try ps.formatPatch(&ctx, "", patch_rs);
+ try std.testing.expectEqualStrings("src/lib.rs:11\n fn total(items: &[u32]) -> u32 {\n let mut sum = 0;\n- for i in items { sum += i; }\n+ for i in items { sum += *i; }\n sum\n", p.text);
+ try std.testing.expectEqual(ps.PatchRow.Kind.hunk, p.rows[0].kind);
+ try std.testing.expectEqual(ps.PatchRow.Kind.declaration, p.rows[1].kind);
+ const removed = p.rows[3];
+ const added = p.rows[4];
+ try std.testing.expectEqual(.{ 11, null }, .{ removed.old, removed.new });
+ try std.testing.expectEqual(.{ null, 11 }, .{ added.old, added.new });
+ try std.testing.expectEqual(ps.ground_del, removed.styles[0]);
+ try std.testing.expectEqual(ps.ground_add, added.styles[0]);
+ // `*` added: the one word emphasised; no byte has a colour of its own
+ const star = std.mem.indexOfScalar(u8, "+ for i in items { sum += *i; }", '*').?;
+ for (added.styles, 0..) |s, i| try std.testing.expectEqual(i == star, s & ps.ground_emph != 0);
+ for (p.rows) |row| for (row.styles) |s| try std.testing.expectEqual(0, s & ps.syn_bits);
+}
+
+test "with no grammar, a file handed in still places the hunk, and no declaration is made up" {
+ var arena: std.heap.ArenaAllocator = .init(std.testing.allocator);
+ defer arena.deinit();
+ const Given = struct {
+ fn source(_: *const ps.PatchCtx, _: []const u8, path: []const u8) ?ps.PatchSource {
+ return .{ .path = path, .bytes = "\n" ++ "\n" ++ "\n" ++ "\n" ++ "\n" ++ "\n" ++ "\n" ++ "\n" ++
+ "fn total(items: &[u32]) -> u32 {\n let mut sum = 0;\n for i in items { sum += *i; }\n sum\n}\n" };
+ }
+ };
+ const ctx: ps.PatchCtx = .{ .arena = arena.allocator(), .source = Given.source, .declarations = ps.PatchCtx.parsed };
+ const p = try ps.formatPatch(&ctx, "", patch_rs);
+ // found (no `@@` words then: git's guess would only contradict the
+ // file's own), and no grammar to read a declaration from
+ try std.testing.expectEqualStrings("src/lib.rs:11\n let mut sum = 0;\n- for i in items { sum += i; }\n+ for i in items { sum += *i; }\n sum\n", p.text);
+ for (p.rows) |row| try std.testing.expect(row.kind != .declaration);
+}