diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-17 00:25:19 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-17 12:15:01 -0300 |
| commit | 6d9272b83d122585ad7bbe7214c078f65351c3c0 (patch) | |
| tree | 5d55a1025ccc4a33ac1e1935f510884d8fae49a8 /test/lib/lib.zig | |
| parent | 5caef6d571f51e98eab3a48c063678ad35e09cce (diff) | |
| download | pardes-6d9272b83d122585ad7bbe7214c078f65351c3c0.tar.gz pardes-6d9272b83d122585ad7bbe7214c078f65351c3c0.zip | |
lib: the diff is a language of pardes-syntax: `diff` (Walk, targetAt), `highlightDiff`, the style byte's `syn_bits` and grounds and colors.Grounds, a theme's colours for them; test/lib colours a C patch through it (each side's code as C, the rows' grounds, Orchard's, and the place a `+` row names)
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
Diffstat (limited to 'test/lib/lib.zig')
| -rw-r--r-- | test/lib/lib.zig | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/test/lib/lib.zig b/test/lib/lib.zig index a3f99b56..7e297920 100644 --- a/test/lib/lib.zig +++ b/test/lib/lib.zig @@ -102,6 +102,60 @@ test "a C and a Zig source are coloured, outlined and walked as pardes has them, try std.testing.expectEqual(null, pardes.theme("no such theme")); } +test "a diff is a language: its hunks coloured as their file's, its added and removed rows on a theme's grounds" { + const gpa = std.testing.allocator; + pardes.start(gpa); + defer pardes.stop(); + const patch = + \\diff --git a/main.c b/main.c + \\--- a/main.c + \\+++ b/main.c + \\@@ -1,3 +1,3 @@ + \\ int main(void) { + \\- return 1; + \\+ return 0; + \\ } + \\ + ; + const styles = try pardes.highlightDiff(gpa, patch, 0, patch.len); + defer gpa.free(styles); + try std.testing.expectEqual(patch.len, styles.len); + const syn = struct { + fn at(s: []const u8, text: []const u8, needle: []const u8) pardes.Syn { + return @fromBackingInt(s[std.mem.indexOf(u8, text, needle).?] & pardes.syn_bits); + } + }.at; + try std.testing.expectEqual(pardes.Syn.comment, syn(styles, patch, "--- a/main.c")); + try std.testing.expectEqual(pardes.Syn.keyword, syn(styles, patch, "@@ -1,3")); + // each side's code as C, behind its marker + try std.testing.expectEqual(pardes.Syn.keyword, syn(styles, patch, "return 1")); + try std.testing.expectEqual(pardes.Syn.keyword, syn(styles, patch, "return 0")); + try std.testing.expectEqual(pardes.Syn.number, syn(styles, patch, "0;")); + const added = std.mem.indexOf(u8, patch, "+ return 0").?; + const removed = std.mem.indexOf(u8, patch, "- return 1").?; + try std.testing.expectEqual(pardes.ground_add | pardes.ground_emph, styles[added]); + try std.testing.expect(styles[added + 5] & pardes.ground_add != 0 and styles[added + 5] & pardes.ground_emph == 0); + try std.testing.expectEqual(pardes.ground_del | pardes.ground_emph, styles[removed]); + try std.testing.expectEqual(0, styles[std.mem.indexOf(u8, patch, " int main").?] & (pardes.ground_add | pardes.ground_del)); + + // a row's hue in a theme: a ground between the page and the theme's green, a stronger and a fainter one + const th = pardes.theme("Orchard").?; + const g = pardes.Grounds.of(th); + const ground = g.forStyle(styles[added]).?; + try std.testing.expectEqual(g.add, ground); + try std.testing.expectEqual(g.del, g.forStyle(styles[removed]).?); + try std.testing.expectEqual(null, g.forStyle(@backingInt(pardes.Syn.keyword))); + try std.testing.expect(!std.mem.eql(u8, &ground.row, &pardes.page(th)) and !std.mem.eql(u8, &ground.row, &ground.emph) and !std.mem.eql(u8, &ground.row, &ground.line)); + + // what a row points at: the new line a `+` row is + var lines: std.ArrayList([]const u8) = .empty; + defer lines.deinit(gpa); + var it = std.mem.splitScalar(u8, patch, '\n'); + while (it.next()) |line| try lines.append(gpa, line); + var buf: [64]u8 = undefined; + try std.testing.expectEqualStrings("main.c:2", pardes.diff.targetAt(lines.items, 6, false).?.address(&buf).?); +} + test "every name the library has compiles outside pardes" { std.testing.refAllDecls(pardes); } |
