summaryrefslogtreecommitdiff
path: root/test/lib/lib.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-17 02:31:20 -0300
committerGabriel Schneider <[email protected]>2026-11-17 12:15:01 -0300
commitf749eb712d990a9b03f1db372d5311e77bd32edd (patch)
treeee4d9966f1eb293054b7ed865c9d4d6eb49e432b /test/lib/lib.zig
parent8f6621f9f70db86d56266a59b56dfb92b324b0d9 (diff)
parentb3d32656413734952bc918c2d4cfd12fede6c214 (diff)
downloadpardes-f749eb712d990a9b03f1db372d5311e77bd32edd.tar.gz
pardes-f749eb712d990a9b03f1db372d5311e77bd32edd.zip
integration: the terminal behind src/Term.zig, with the diff viewer and the plumber's first phase
A merge of term-phase0 and pardes-next. File.zig's recolorSyntax keeps the theme's grounds and names Term.Filter and Term.Span; the changelog keeps both sides' entries, the palette sentence in the place of the entry the terminal work cut down. core-test 985/985 on tui; the diff, pager and tree process cases pass, goldens unchanged. Co-Authored-By: Claude Fable 5.2 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
Diffstat (limited to 'test/lib/lib.zig')
-rw-r--r--test/lib/lib.zig54
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);
}