diff options
Diffstat (limited to 'core/jj.zig')
| -rw-r--r-- | core/jj.zig | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/core/jj.zig b/core/jj.zig index 429ea9c9..7784c1c1 100644 --- a/core/jj.zig +++ b/core/jj.zig @@ -419,3 +419,52 @@ test "provenance: a value a line, which pinned change wrote it, from what jj ans }, } } + +test "a B3 click on path@rev:line in running text opens the file at that revision there" { + const gpa = testing.allocator; + var repo = try Repo.init(gpa) orelse return error.SkipZigTest; + defer repo.deinit(gpa); + try repo.tmp.dir.writeFile(testing.io, .{ .sub_path = "notes.txt", .data = "see a.zig@@-:2 here\n" }); + const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 100, .rows = 30 }); + defer p.deinit(); + var line: [4200]u8 = undefined; + p.update(.{ .command = try std.fmt.bufPrint(&line, "Look {s}/notes.txt", .{repo.dir}) }); + const notes = p.view().active; + p.sync(); + var arena: std.heap.ArenaAllocator = .init(gpa); + defer arena.deinit(); + const s = try p.render(arena.allocator()); + const body = s.region(.body, notes).?.rect; + // On the `@` of the address, the body's first row. + const x: u16 = body.x + File.gutterWidth(p.panes[notes].?) + @as(u16, "see a.zig".len); + p.update(.{ .mouse = .{ .button = .right, .kind = .press, .col = x, .row = body.y } }); + p.update(.{ .mouse = .{ .button = .right, .kind = .release, .col = x, .row = body.y } }); + const shown = p.view().active; + try testing.expect(shown != notes); + const f = &p.panes[shown].?.file.?; + try testing.expect(of(f) != null); + try testing.expectEqualStrings(Repo.two, f.content); + try testing.expectEqual(@as(i32, 1), p.panes[shown].?.body.cur_row); +} + +test "a revision's text is read-only over 9P too: an open to write it is refused in words" { + const gpa = testing.allocator; + var repo = try Repo.init(gpa) orelse return error.SkipZigTest; + defer repo.deinit(gpa); + const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 100, .rows = 30 }); + defer p.deinit(); + var line: [4200]u8 = undefined; + p.update(.{ .command = try std.fmt.bufPrint(&line, "Look {s}@@-", .{repo.file}) }); + const pane = p.panes[p.view().active].?; + try testing.expect(of(&pane.file.?) != null); + const th = @import("ninep/harness.zig"); + const tree = @import("ninep/tree.zig"); + for ([_]tree.PaneFile{ .body, .data, .xdata, .sel }) |file| { + const got = th.call(p, .{ .tag = 1, .op = .open, .node = tree.Node.of(pane.serial, file), .omode = 1 }); + try testing.expectEqual(@as(u16, 30), got.errno()); + try testing.expectEqual(@as(u16, 30), @import("cloud9").fs.enameErrno(got.reply.ename)); + } + // Reading it is as any text's. + try testing.expectEqual(@as(u16, 0), th.call(p, .{ .tag = 1, .op = .open, .node = tree.Node.of(pane.serial, .body), .omode = 0 }).errno()); + try testing.expectEqualStrings(Repo.two, pane.file.?.content); +} |
