summaryrefslogtreecommitdiff
path: root/core/jj.zig
diff options
context:
space:
mode:
Diffstat (limited to 'core/jj.zig')
-rw-r--r--core/jj.zig53
1 files changed, 53 insertions, 0 deletions
diff --git a/core/jj.zig b/core/jj.zig
index 963e4c42..78c0e857 100644
--- a/core/jj.zig
+++ b/core/jj.zig
@@ -3498,6 +3498,59 @@ test "the layer's lines are the pane's text, read-only: j and k go onto them, a
}
}
+test "the node keys and the indent read the file's text: Alt-o and a function's text object beside the layer's lines select what they select with the layer hidden (the layer's lines inside the node with it), and o opens a line indented as there" {
+ const gpa = testing.allocator;
+ var repo = try Lines.repo() orelse return error.SkipZigTest;
+ defer repo.deinit(gpa);
+ const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 60, .rows = 44 });
+ defer p.deinit();
+ var arena: std.heap.ArenaAllocator = .init(gpa);
+ defer arena.deinit();
+ const pane = try Lines.open(p, repo.file);
+ const id = p.view().active;
+ const f = &pane.file.?;
+ const alt_o: pardes.Event = .{ .key = .{ .cp = 'o', .alt = true } };
+ // What each gesture selects, in the file's offsets (9P's dot), with the
+ // cursor on `c2();`'s `c`: buffer line 4 with the layer shown, the
+ // file's line 2 hidden.
+ const Gesture = enum { node1, node2, node3, function };
+ var shown: [4]pardes.ctlfs.pane.State.Range = undefined;
+ var hidden: [4]pardes.ctlfs.pane.State.Range = undefined;
+ for ([_]bool{ true, false }) |layer| {
+ p.view().active = id;
+ if (!layer) p.update(.{ .command = "Changes" });
+ try testing.expectEqual(layer, f.read_only.len > 0);
+ const row: i32 = if (layer) 4 else 2;
+ for (std.enums.values(Gesture), 0..) |g, k| {
+ p.view().active = id;
+ Lines.at(pane, row, 4);
+ switch (g) {
+ .node1, .node2, .node3 => for (0..@intFromEnum(g) + 1) |_| p.update(alt_o),
+ .function => Lines.send(p, "maf"),
+ }
+ (if (layer) &shown else &hidden)[k] = pardes.ctlfs.pane.fileDot(pane);
+ Lines.send(p, "\x1b;");
+ }
+ }
+ errdefer for (shown, hidden) |s, h| std.debug.print("shown {d}..{d} hidden {d}..{d}\n", .{ s.q0, s.q1, h.q0, h.q1 });
+ for (shown, hidden) |s, h| try testing.expectEqual(h, s);
+ // The function, the whole file less its last newline: hidden, the text.
+ try testing.expectEqualStrings("fn f() void {\n a();\n c2();\n}", Lines.cut_text[hidden[3].q0..hidden[3].q1]);
+ // `o` on `c2();`: the line opened with the indent it gets hidden.
+ var opened: [2][]const u8 = undefined;
+ for ([_]bool{ false, true }, &opened) |layer, *o| {
+ p.view().active = id;
+ if (layer) p.update(.{ .command = "Changes" });
+ try testing.expectEqual(layer, f.read_only.len > 0);
+ Lines.at(pane, if (layer) 4 else 2, 4);
+ Lines.send(p, "ox\x1b");
+ o.* = try arena.allocator().dupe(u8, try File.fileText(f, arena.allocator()));
+ Lines.send(p, "u");
+ }
+ try testing.expectEqualStrings("fn f() void {\n a();\n c2();\n x\n}\n", opened[0]);
+ try testing.expectEqualStrings(opened[0], opened[1]);
+}
+
test "THE FILE'S TEXT: with the layer's lines in the buffer, every reader of the file reads what it reads with them out, byte for byte: a Save, a Save to another name, Edit's w, body over 9P, the dirty check, a reread from the disk, a Get, jj's lines asked again, the context declarations, the colours of the file's lines, the language server's text and the place it is asked at" {
const gpa = testing.allocator;
var repo = try Lines.repo() orelse return error.SkipZigTest;