summaryrefslogtreecommitdiff
path: root/src/look.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-09 00:52:52 -0300
committerGabriel Schneider <[email protected]>2026-11-09 01:28:28 -0300
commit5157579ff7f9ae0cfc3c7629e953da05bce340fc (patch)
tree02147789efdcea998981efcfe05d4bcb3e9bb7b0 /src/look.zig
parent4c4b9bf54d77dbc0f9f4e2619746908e501c6001 (diff)
downloadpardes-5157579ff7f9ae0cfc3c7629e953da05bce340fc.tar.gz
pardes-5157579ff7f9ae0cfc3c7629e953da05bce340fc.zip
tests: at the end of their files: every top-level test block of the 46 files that had one mid-file (the locality analysis's 45 and test/hxdiff.zig; gui.zig, macos.zig, look, host_io, 9p_io, terminal, tui, mouse, fs, replica, layout among them, 11,429 test lines), with the functions only tests call, moved after the file's code in their order, a mechanical move (.scratch/suites/tests_to_end.py), zig fmt'd; the unit suites pass as before (tui 1486/1487, gui 1536/1537, core 956/956 on both), macos.zig only parse-checked here
Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge
Diffstat (limited to 'src/look.zig')
-rw-r--r--src/look.zig447
1 files changed, 223 insertions, 224 deletions
diff --git a/src/look.zig b/src/look.zig
index 7f76602e..e6b0c4ad 100644
--- a/src/look.zig
+++ b/src/look.zig
@@ -109,69 +109,6 @@ pub fn parsePathLine(tok: []const u8) struct { path: []const u8, at: Spot, end:
return .{ .path = tok, .at = .{}, .end = tok.len };
}
-test "parsePathLine: spots, ranges, and the paths that merely look like them" {
- const cases = [_]struct { tok: []const u8, path: []const u8, at: Spot }{
- .{ .tok = "main.zig", .path = "main.zig", .at = .{} },
- .{ .tok = "main.zig:100", .path = "main.zig", .at = .{ .line = 100 } },
- .{ .tok = "main.zig:100:", .path = "main.zig", .at = .{ .line = 100 } },
- .{ .tok = "main.zig:100:7", .path = "main.zig", .at = .{ .line = 100, .col = 7 } },
- .{ .tok = "main.zig:100-104", .path = "main.zig", .at = .{ .line = 100, .end_line = 104 } },
- .{ .tok = "main.zig:100:7-21", .path = "main.zig", .at = .{ .line = 100, .col = 7, .end_line = 100, .end_col = 21 } },
- .{ .tok = "main.zig:100:7-104:3", .path = "main.zig", .at = .{ .line = 100, .col = 7, .end_line = 104, .end_col = 3 } },
- .{ .tok = "my-file.zig", .path = "my-file.zig", .at = .{} },
- .{ .tok = "my-file:10", .path = "my-file", .at = .{ .line = 10 } },
- .{ .tok = "x:1-y", .path = "x:1-y", .at = .{} },
- .{ .tok = "a-b-c", .path = "a-b-c", .at = .{} },
- .{ .tok = "2026-07-30", .path = "2026-07-30", .at = .{} },
- .{ .tok = "main.zig:100x", .path = "main.zig:100x", .at = .{} },
- .{ .tok = "main.zig:100:7x", .path = "main.zig", .at = .{ .line = 100 } },
- };
- for (cases) |c| {
- const got = parsePathLine(c.tok);
- try std.testing.expectEqualStrings(c.path, got.path);
- try std.testing.expectEqual(c.at, got.at);
- }
-}
-
-test "a number too big to be a line saturates instead of taking the editor down" {
- const huge = "99999999999999999999999999";
- const cases = [_][]const u8{
- "f.zig:" ++ huge,
- "f.zig:" ++ huge ++ ":" ++ huge,
- "f.zig:1-" ++ huge,
- "f.zig:1:2-" ++ huge ++ ":" ++ huge,
- };
- for (cases) |tok| {
- const got = parsePathLine(tok);
- try std.testing.expectEqualStrings("f.zig", got.path);
- try std.testing.expect(got.at.line >= 1);
- }
-
- var realbuf: [4096]u8 = undefined;
- const target = resolve(null, "@p" ++ huge, "/tmp", &realbuf);
- try std.testing.expect(target == .pane);
- try std.testing.expect(target.pane.id >= 16);
-}
-
-test "parsePathLine: `end` separates a whole-token target from a lenient read" {
- for ([_][]const u8{
- "main.zig", "main.zig:100", "main.zig:100:7",
- "main.zig:100-104", "main.zig:100:7-21", "main.zig:100:7-104:3",
- "@p3:10:5", "x:1-y",
- }) |tok| try std.testing.expectEqual(tok.len, parsePathLine(tok).end);
- const partial = [_]struct { tok: []const u8, end: usize }{
- .{ .tok = "main.zig:100:", .end = "main.zig:100".len }, // trailing ':' is peeled, not parsed
- .{ .tok = "main.zig:100:7x", .end = "main.zig:100".len },
- .{ .tok = "main.zig:100:7 fn main() void {", .end = "main.zig:100".len },
- .{ .tok = "main.zig:100:7-21 const x = 1;", .end = "main.zig:100:7-21".len },
- .{ .tok = "@p3:10:5 /home/goblin", .end = "@p3:10".len },
- };
- for (partial) |c| try std.testing.expectEqual(c.end, parsePathLine(c.tok).end);
- const whole = "main.zig:100-104 whole lines";
- try std.testing.expectEqual(whole.len, parsePathLine(whole).end);
- try std.testing.expectEqualStrings(whole, parsePathLine(whole).path);
-}
-
pub const FileTarget = struct {
path: []const u8,
at: Spot,
@@ -205,30 +142,6 @@ pub fn wordSpan(p: ?*pardes.Pardes, word: []const u8, cwd: []const u8, realbuf:
return .{ .start = 0, .end = word.len };
}
-test "lookableSpan peels prose punctuation off a path, largest first" {
- if (!platform_has_fs) return;
- var realbuf: [4096]u8 = undefined;
- try std.testing.expectEqualDeep(
- @as(?Span, .{ .start = 0, .end = "src/look.zig".len }),
- wordSpan(null, "src/look.zig", ".", &realbuf),
- );
- try std.testing.expectEqualDeep(
- @as(?Span, .{ .start = 1, .end = 1 + "src/look.zig".len }),
- wordSpan(null, "(src/look.zig),", ".", &realbuf),
- );
- try std.testing.expectEqualDeep(
- @as(?Span, .{ .start = 0, .end = "src/look.zig:12:3".len }),
- wordSpan(null, "src/look.zig:12:3,", ".", &realbuf),
- );
- try std.testing.expectEqualDeep(
- @as(?Span, .{ .start = 0, .end = "src/look.zig:12".len }),
- wordSpan(null, "src/look.zig:12:", ".", &realbuf),
- );
- try std.testing.expectEqual(@as(?Span, null), wordSpan(null, "nothing-here", ".", &realbuf));
- try std.testing.expectEqual(@as(?Span, null), wordSpan(null, "", ".", &realbuf));
- try std.testing.expectEqual(@as(?Span, null), wordSpan(null, "((()))", ".", &realbuf));
-}
-
pub fn lineSpan(p: ?*pardes.Pardes, line: []const u8, cwd: []const u8, realbuf: *[4096]u8) ?Span {
var lo: usize = 0;
while (lo < line.len and (line[lo] == ' ' or line[lo] == '\t')) lo += 1;
@@ -251,59 +164,6 @@ pub fn lineSpan(p: ?*pardes.Pardes, line: []const u8, cwd: []const u8, realbuf:
return null;
}
-test "lookableLineSpan takes the row's location and stops before its text" {
- if (!platform_has_fs) return;
- var realbuf: [4096]u8 = undefined;
- try std.testing.expectEqualDeep(
- @as(?Span, .{ .start = 0, .end = "src/look.zig:12:5-9".len }),
- lineSpan(null, "src/look.zig:12:5-9 const std = @import(\"std\");", ".", &realbuf),
- );
- try std.testing.expectEqualDeep(
- @as(?Span, .{ .start = 0, .end = "src/look.zig:12:5".len }),
- lineSpan(null, "src/look.zig:12:5 pub fn resolve", ".", &realbuf),
- );
- try std.testing.expectEqualDeep(
- @as(?Span, .{ .start = 0, .end = "@p3:10:5".len }),
- lineSpan(null, "@p3:10:5 /home/goblin", ".", &realbuf),
- );
- try std.testing.expectEqualDeep(
- @as(?Span, .{ .start = 3, .end = 3 + "src/look.zig".len }),
- lineSpan(null, " (src/look.zig)", ".", &realbuf),
- );
- try std.testing.expectEqualDeep(
- @as(?Span, .{ .start = 0, .end = "https://pardes.dev/a".len }),
- lineSpan(null, "https://pardes.dev/a Chapter One", ".", &realbuf),
- );
- try std.testing.expectEqual(
- @as(?Span, null),
- lineSpan(null, "see also src/look.zig", ".", &realbuf),
- );
- try std.testing.expectEqual(@as(?Span, null), lineSpan(null, " ", ".", &realbuf));
- try std.testing.expectEqual(@as(?Span, null), lineSpan(null, "", ".", &realbuf));
-}
-
-test "lookableLineSpan prefers the longest run, so a blank inside a path is one span" {
- if (!platform_has_fs) return;
- var realbuf: [4096]u8 = undefined;
- const io = std.testing.io;
- var tmp = std.testing.tmpDir(.{});
- defer tmp.cleanup();
- const name = "pardes look span.txt";
- try tmp.dir.writeFile(io, .{ .sub_path = name, .data = "" });
- try tmp.dir.createDir(io, "subdir", .default_dir);
- var path: [4096]u8 = undefined;
- const len = try tmp.dir.realPathFile(io, name, &path);
- const cwd = std.Io.Dir.path.dirname(path[0..len]).?;
- try std.testing.expectEqualDeep(
- @as(?Span, .{ .start = 0, .end = name.len }),
- lineSpan(null, name, cwd, &realbuf),
- );
- try std.testing.expectEqualDeep(
- @as(?Span, .{ .start = 0, .end = "subdir".len }),
- lineSpan(null, "subdir holds pardes look span.txt", cwd, &realbuf),
- );
-}
-
/// Where a `Plumb` rule sends what it matched: the targets the built-in
/// rules below make (url: the browser, through `xdg-open`), or a loaded
/// kind by its name (`image`, `pdf`).
@@ -558,7 +418,6 @@ pub fn cursorWordSel(p: *Pardes, pane: *Pane) Pane.Sel {
return .{ .state = .done, .c0 = vcol, .c1 = vcol, .r0 = vrow, .r1 = vrow };
}
-
const SearchStart = enum { top, cursor };
pub fn submitSearch(p: *Pardes, id: usize) void {
@@ -1148,17 +1007,6 @@ fn missText(text: []const u8, buf: *[miss_path_cap + "…".len]u8) []const u8 {
return pardes.ctlfs.fitErr(text, buf[0..miss_path_cap]);
}
-test "a miss names a long path by its start and its end, its middle given up to …" {
- var cut: [miss_path_cap + "…".len]u8 = undefined;
- const long = "/home/someone/" ++ std.mem.asBytes(&@as([80][5]u8, @splat("deep/".*))) ++ "the-file.zig";
- const said = missText(long, &cut);
- try std.testing.expect(said.len <= miss_path_cap);
- try std.testing.expect(std.mem.startsWith(u8, said, "/home/someone/"));
- try std.testing.expect(std.mem.endsWith(u8, said, "/the-file.zig"));
- try std.testing.expect(std.mem.indexOf(u8, said, "…") != null);
- try std.testing.expectEqualStrings("short/path.txt", missText("short/path.txt", &cut));
-}
-
/// A file that is there but would not open: said with its path, `look:
/// <path>: permission denied`, the path cut in its middle when long.
fn lookOpenFailed(p: *Pardes, id: usize, path: []const u8, err: anyerror) void {
@@ -1205,16 +1053,6 @@ fn zeroColumnTail(text: []const u8) bool {
return false;
}
-test "a zero column ends a look's text, line 0 included" {
- for ([_][]const u8{ "f.txt:0:0", "f.txt:3:0", "dir/f.txt:3:2-0" }) |t| try std.testing.expect(zeroColumnTail(t));
- for ([_][]const u8{ "f.txt:3", "f.txt:3:1", "f.txt:0", "f.txt", "a:b:0x" }) |t| try std.testing.expect(!zeroColumnTail(t));
-}
-
-test "a zero column after a path is found, in every spelling a look takes" {
- for ([_][]const u8{ ":3:0", ":3:0-4", ":3:2-0", ":3:2-5:0" }) |rest| try std.testing.expect(zeroColumn(rest));
- for ([_][]const u8{ "", ":3", ":3:1", ":3:2-5", ":3:2-5:7", ":30:10" }) |rest| try std.testing.expect(!zeroColumn(rest));
-}
-
fn missed(p: *Pardes, id: usize, comptime fmt: []const u8, args: anytype) void {
p.look_missed = true;
var said: Kind.Buf(miss_path_cap + 64) = .{};
@@ -1361,16 +1199,6 @@ fn isCommitHash(word: []const u8) bool {
return digit and letter;
}
-test "a commit hash is 7 to 40 lowercase hex digits with a letter and a digit" {
- try std.testing.expect(isCommitHash("9bffa7041c"));
- try std.testing.expect(isCommitHash("9bffa7041cd2e8a0b6b1f7c3e4d5a6b7c8d9e0f1"));
- try std.testing.expect(!isCommitHash("9bffa7"));
- try std.testing.expect(!isCommitHash("defaced"));
- try std.testing.expect(!isCommitHash("1234567"));
- try std.testing.expect(!isCommitHash("0x9bffa7041c"));
- try std.testing.expect(!isCommitHash("9BFFA7041C"));
-}
-
/// Opens (or finds) `path` as Look would, `id`'s own pane when it is empty,
/// and selects what `expr` addresses there from its dot. An address that
/// does not evaluate moves nothing and says why (acme: no jump).
@@ -1842,6 +1670,229 @@ pub fn lookAt(p: *Pardes, id: usize, operand_raw: []const u8) void {
}
}
+// A diff pane on `diff_text`, saved as change.diff in a fresh directory
+// that holds `files` (path, content) and, if `repo`, a `.git`.
+const DiffFixture = struct {
+ tmp: std.testing.TmpDir,
+ dir: []const u8,
+ dir_buf: [4096]u8 = undefined,
+
+ fn init(f: *DiffFixture, repo: bool, files: []const [2][]const u8, diff_text: []const u8) !void {
+ const io = std.testing.io;
+ f.tmp = std.testing.tmpDir(.{});
+ errdefer f.tmp.cleanup();
+ if (repo) try f.tmp.dir.createDir(io, ".git", .default_dir);
+ for (files) |file| {
+ if (std.Io.Dir.path.dirname(file[0])) |sub| try f.tmp.dir.createDirPath(io, sub);
+ try f.tmp.dir.writeFile(io, .{ .sub_path = file[0], .data = file[1] });
+ }
+ try f.tmp.dir.writeFile(io, .{ .sub_path = "change.diff", .data = diff_text });
+ const len = try f.tmp.dir.realPathFile(io, "change.diff", &f.dir_buf);
+ f.dir = std.Io.Dir.path.dirname(f.dir_buf[0..len]).?;
+ }
+
+ fn open(f: *DiffFixture, p: *Pardes, diff_text: []const u8) !*Pane {
+ const pane = try p.setTestFile(diff_text);
+ p.gpa.free(pane.file.?.path);
+ pane.file.?.path = try std.Io.Dir.path.join(p.gpa, &.{ f.dir, "change.diff" });
+ return pane;
+ }
+
+ /// A right click's look at `row` of the diff pane (slot 0): the look
+ /// of the address that line names.
+ fn click(p: *Pardes, diff_pane: *Pane, row: usize) void {
+ p.view().active = 0;
+ const lines = diffLines(p, diff_pane).?;
+ var buf: [4096]u8 = undefined;
+ p.look_missed = false;
+ lookAt(p, 0, diffAddress(diff_pane, lines, row, &buf).?);
+ }
+};
+
+/// The rows n/N's walk over look-able text reads before it stops (look.zig).
+pub const max_look_rows = 8192;
+
+fn expectAt(p: *Pardes, suffix: []const u8, line: usize) !void {
+ const pane = p.panes[p.view().active].?;
+ const f = pane.file orelse return error.NoFileOpened;
+ if (!std.mem.endsWith(u8, f.path, suffix)) {
+ std.debug.print("opened {s}, not {s}\n", .{ f.path, suffix });
+ return error.WrongFile;
+ }
+ try std.testing.expectEqual(@as(i32, @intCast(line)) - 1, pane.body.cur_row);
+}
+
+test "parsePathLine: spots, ranges, and the paths that merely look like them" {
+ const cases = [_]struct { tok: []const u8, path: []const u8, at: Spot }{
+ .{ .tok = "main.zig", .path = "main.zig", .at = .{} },
+ .{ .tok = "main.zig:100", .path = "main.zig", .at = .{ .line = 100 } },
+ .{ .tok = "main.zig:100:", .path = "main.zig", .at = .{ .line = 100 } },
+ .{ .tok = "main.zig:100:7", .path = "main.zig", .at = .{ .line = 100, .col = 7 } },
+ .{ .tok = "main.zig:100-104", .path = "main.zig", .at = .{ .line = 100, .end_line = 104 } },
+ .{ .tok = "main.zig:100:7-21", .path = "main.zig", .at = .{ .line = 100, .col = 7, .end_line = 100, .end_col = 21 } },
+ .{ .tok = "main.zig:100:7-104:3", .path = "main.zig", .at = .{ .line = 100, .col = 7, .end_line = 104, .end_col = 3 } },
+ .{ .tok = "my-file.zig", .path = "my-file.zig", .at = .{} },
+ .{ .tok = "my-file:10", .path = "my-file", .at = .{ .line = 10 } },
+ .{ .tok = "x:1-y", .path = "x:1-y", .at = .{} },
+ .{ .tok = "a-b-c", .path = "a-b-c", .at = .{} },
+ .{ .tok = "2026-07-30", .path = "2026-07-30", .at = .{} },
+ .{ .tok = "main.zig:100x", .path = "main.zig:100x", .at = .{} },
+ .{ .tok = "main.zig:100:7x", .path = "main.zig", .at = .{ .line = 100 } },
+ };
+ for (cases) |c| {
+ const got = parsePathLine(c.tok);
+ try std.testing.expectEqualStrings(c.path, got.path);
+ try std.testing.expectEqual(c.at, got.at);
+ }
+}
+
+test "a number too big to be a line saturates instead of taking the editor down" {
+ const huge = "99999999999999999999999999";
+ const cases = [_][]const u8{
+ "f.zig:" ++ huge,
+ "f.zig:" ++ huge ++ ":" ++ huge,
+ "f.zig:1-" ++ huge,
+ "f.zig:1:2-" ++ huge ++ ":" ++ huge,
+ };
+ for (cases) |tok| {
+ const got = parsePathLine(tok);
+ try std.testing.expectEqualStrings("f.zig", got.path);
+ try std.testing.expect(got.at.line >= 1);
+ }
+
+ var realbuf: [4096]u8 = undefined;
+ const target = resolve(null, "@p" ++ huge, "/tmp", &realbuf);
+ try std.testing.expect(target == .pane);
+ try std.testing.expect(target.pane.id >= 16);
+}
+
+test "parsePathLine: `end` separates a whole-token target from a lenient read" {
+ for ([_][]const u8{
+ "main.zig", "main.zig:100", "main.zig:100:7",
+ "main.zig:100-104", "main.zig:100:7-21", "main.zig:100:7-104:3",
+ "@p3:10:5", "x:1-y",
+ }) |tok| try std.testing.expectEqual(tok.len, parsePathLine(tok).end);
+ const partial = [_]struct { tok: []const u8, end: usize }{
+ .{ .tok = "main.zig:100:", .end = "main.zig:100".len }, // trailing ':' is peeled, not parsed
+ .{ .tok = "main.zig:100:7x", .end = "main.zig:100".len },
+ .{ .tok = "main.zig:100:7 fn main() void {", .end = "main.zig:100".len },
+ .{ .tok = "main.zig:100:7-21 const x = 1;", .end = "main.zig:100:7-21".len },
+ .{ .tok = "@p3:10:5 /home/goblin", .end = "@p3:10".len },
+ };
+ for (partial) |c| try std.testing.expectEqual(c.end, parsePathLine(c.tok).end);
+ const whole = "main.zig:100-104 whole lines";
+ try std.testing.expectEqual(whole.len, parsePathLine(whole).end);
+ try std.testing.expectEqualStrings(whole, parsePathLine(whole).path);
+}
+
+test "lookableSpan peels prose punctuation off a path, largest first" {
+ if (!platform_has_fs) return;
+ var realbuf: [4096]u8 = undefined;
+ try std.testing.expectEqualDeep(
+ @as(?Span, .{ .start = 0, .end = "src/look.zig".len }),
+ wordSpan(null, "src/look.zig", ".", &realbuf),
+ );
+ try std.testing.expectEqualDeep(
+ @as(?Span, .{ .start = 1, .end = 1 + "src/look.zig".len }),
+ wordSpan(null, "(src/look.zig),", ".", &realbuf),
+ );
+ try std.testing.expectEqualDeep(
+ @as(?Span, .{ .start = 0, .end = "src/look.zig:12:3".len }),
+ wordSpan(null, "src/look.zig:12:3,", ".", &realbuf),
+ );
+ try std.testing.expectEqualDeep(
+ @as(?Span, .{ .start = 0, .end = "src/look.zig:12".len }),
+ wordSpan(null, "src/look.zig:12:", ".", &realbuf),
+ );
+ try std.testing.expectEqual(@as(?Span, null), wordSpan(null, "nothing-here", ".", &realbuf));
+ try std.testing.expectEqual(@as(?Span, null), wordSpan(null, "", ".", &realbuf));
+ try std.testing.expectEqual(@as(?Span, null), wordSpan(null, "((()))", ".", &realbuf));
+}
+
+test "lookableLineSpan takes the row's location and stops before its text" {
+ if (!platform_has_fs) return;
+ var realbuf: [4096]u8 = undefined;
+ try std.testing.expectEqualDeep(
+ @as(?Span, .{ .start = 0, .end = "src/look.zig:12:5-9".len }),
+ lineSpan(null, "src/look.zig:12:5-9 const std = @import(\"std\");", ".", &realbuf),
+ );
+ try std.testing.expectEqualDeep(
+ @as(?Span, .{ .start = 0, .end = "src/look.zig:12:5".len }),
+ lineSpan(null, "src/look.zig:12:5 pub fn resolve", ".", &realbuf),
+ );
+ try std.testing.expectEqualDeep(
+ @as(?Span, .{ .start = 0, .end = "@p3:10:5".len }),
+ lineSpan(null, "@p3:10:5 /home/goblin", ".", &realbuf),
+ );
+ try std.testing.expectEqualDeep(
+ @as(?Span, .{ .start = 3, .end = 3 + "src/look.zig".len }),
+ lineSpan(null, " (src/look.zig)", ".", &realbuf),
+ );
+ try std.testing.expectEqualDeep(
+ @as(?Span, .{ .start = 0, .end = "https://pardes.dev/a".len }),
+ lineSpan(null, "https://pardes.dev/a Chapter One", ".", &realbuf),
+ );
+ try std.testing.expectEqual(
+ @as(?Span, null),
+ lineSpan(null, "see also src/look.zig", ".", &realbuf),
+ );
+ try std.testing.expectEqual(@as(?Span, null), lineSpan(null, " ", ".", &realbuf));
+ try std.testing.expectEqual(@as(?Span, null), lineSpan(null, "", ".", &realbuf));
+}
+
+test "lookableLineSpan prefers the longest run, so a blank inside a path is one span" {
+ if (!platform_has_fs) return;
+ var realbuf: [4096]u8 = undefined;
+ const io = std.testing.io;
+ var tmp = std.testing.tmpDir(.{});
+ defer tmp.cleanup();
+ const name = "pardes look span.txt";
+ try tmp.dir.writeFile(io, .{ .sub_path = name, .data = "" });
+ try tmp.dir.createDir(io, "subdir", .default_dir);
+ var path: [4096]u8 = undefined;
+ const len = try tmp.dir.realPathFile(io, name, &path);
+ const cwd = std.Io.Dir.path.dirname(path[0..len]).?;
+ try std.testing.expectEqualDeep(
+ @as(?Span, .{ .start = 0, .end = name.len }),
+ lineSpan(null, name, cwd, &realbuf),
+ );
+ try std.testing.expectEqualDeep(
+ @as(?Span, .{ .start = 0, .end = "subdir".len }),
+ lineSpan(null, "subdir holds pardes look span.txt", cwd, &realbuf),
+ );
+}
+
+test "a miss names a long path by its start and its end, its middle given up to …" {
+ var cut: [miss_path_cap + "…".len]u8 = undefined;
+ const long = "/home/someone/" ++ std.mem.asBytes(&@as([80][5]u8, @splat("deep/".*))) ++ "the-file.zig";
+ const said = missText(long, &cut);
+ try std.testing.expect(said.len <= miss_path_cap);
+ try std.testing.expect(std.mem.startsWith(u8, said, "/home/someone/"));
+ try std.testing.expect(std.mem.endsWith(u8, said, "/the-file.zig"));
+ try std.testing.expect(std.mem.indexOf(u8, said, "…") != null);
+ try std.testing.expectEqualStrings("short/path.txt", missText("short/path.txt", &cut));
+}
+
+test "a zero column ends a look's text, line 0 included" {
+ for ([_][]const u8{ "f.txt:0:0", "f.txt:3:0", "dir/f.txt:3:2-0" }) |t| try std.testing.expect(zeroColumnTail(t));
+ for ([_][]const u8{ "f.txt:3", "f.txt:3:1", "f.txt:0", "f.txt", "a:b:0x" }) |t| try std.testing.expect(!zeroColumnTail(t));
+}
+
+test "a zero column after a path is found, in every spelling a look takes" {
+ for ([_][]const u8{ ":3:0", ":3:0-4", ":3:2-0", ":3:2-5:0" }) |rest| try std.testing.expect(zeroColumn(rest));
+ for ([_][]const u8{ "", ":3", ":3:1", ":3:2-5", ":3:2-5:7", ":30:10" }) |rest| try std.testing.expect(!zeroColumn(rest));
+}
+
+test "a commit hash is 7 to 40 lowercase hex digits with a letter and a digit" {
+ try std.testing.expect(isCommitHash("9bffa7041c"));
+ try std.testing.expect(isCommitHash("9bffa7041cd2e8a0b6b1f7c3e4d5a6b7c8d9e0f1"));
+ try std.testing.expect(!isCommitHash("9bffa7"));
+ try std.testing.expect(!isCommitHash("defaced"));
+ try std.testing.expect(!isCommitHash("1234567"));
+ try std.testing.expect(!isCommitHash("0x9bffa7041c"));
+ try std.testing.expect(!isCommitHash("9BFFA7041C"));
+}
+
test "Look hover waits without mutating the pane and input cancels it" {
const delay = config.look_preview_delay_frames;
@@ -2037,55 +2088,6 @@ test "a pointer resting where a look-hover found nothing does not wake the core
try std.testing.expect(p.look_hover_wait == null and p.look_hover_preview == null);
}
-// A diff pane on `diff_text`, saved as change.diff in a fresh directory
-// that holds `files` (path, content) and, if `repo`, a `.git`.
-const DiffFixture = struct {
- tmp: std.testing.TmpDir,
- dir: []const u8,
- dir_buf: [4096]u8 = undefined,
-
- fn init(f: *DiffFixture, repo: bool, files: []const [2][]const u8, diff_text: []const u8) !void {
- const io = std.testing.io;
- f.tmp = std.testing.tmpDir(.{});
- errdefer f.tmp.cleanup();
- if (repo) try f.tmp.dir.createDir(io, ".git", .default_dir);
- for (files) |file| {
- if (std.Io.Dir.path.dirname(file[0])) |sub| try f.tmp.dir.createDirPath(io, sub);
- try f.tmp.dir.writeFile(io, .{ .sub_path = file[0], .data = file[1] });
- }
- try f.tmp.dir.writeFile(io, .{ .sub_path = "change.diff", .data = diff_text });
- const len = try f.tmp.dir.realPathFile(io, "change.diff", &f.dir_buf);
- f.dir = std.Io.Dir.path.dirname(f.dir_buf[0..len]).?;
- }
-
- fn open(f: *DiffFixture, p: *Pardes, diff_text: []const u8) !*Pane {
- const pane = try p.setTestFile(diff_text);
- p.gpa.free(pane.file.?.path);
- pane.file.?.path = try std.Io.Dir.path.join(p.gpa, &.{ f.dir, "change.diff" });
- return pane;
- }
-
- /// A right click's look at `row` of the diff pane (slot 0): the look
- /// of the address that line names.
- fn click(p: *Pardes, diff_pane: *Pane, row: usize) void {
- p.view().active = 0;
- const lines = diffLines(p, diff_pane).?;
- var buf: [4096]u8 = undefined;
- p.look_missed = false;
- lookAt(p, 0, diffAddress(diff_pane, lines, row, &buf).?);
- }
-};
-
-fn expectAt(p: *Pardes, suffix: []const u8, line: usize) !void {
- const pane = p.panes[p.view().active].?;
- const f = pane.file orelse return error.NoFileOpened;
- if (!std.mem.endsWith(u8, f.path, suffix)) {
- std.debug.print("opened {s}, not {s}\n", .{ f.path, suffix });
- return error.WrongFile;
- }
- try std.testing.expectEqual(@as(i32, @intCast(line)) - 1, pane.body.cur_row);
-}
-
test "Look on each kind of diff line opens the new file at the line it names" {
if (!platform_has_fs) return;
const numbered = "line 1\nline 2\nline 3\nline 4\nline 5\nline 6\nline 7\nline 8\nline 9\n" ++
@@ -2666,9 +2668,6 @@ test "Look on a diff line is the look of the address it names, selected by hand:
try std.testing.expectEqual(@as(i32, 1), seen[0].row);
}
-/// The rows n/N's walk over look-able text reads before it stops (look.zig).
-pub const max_look_rows = 8192;
-
test "Plumb: the user's rules come before the built-in ones, the first that matches wins, a bad rule is refused, a dump keeps them" {
if (!platform_has_fs) return;
var tmp = std.testing.tmpDir(.{});