summaryrefslogtreecommitdiff
path: root/test/behaviour
diff options
context:
space:
mode:
Diffstat (limited to 'test/behaviour')
-rw-r--r--test/behaviour/modes.zig39
-rw-r--r--test/behaviour/panes.zig49
-rw-r--r--test/behaviour/placement.zig24
-rw-r--r--test/behaviour/terminals.zig46
4 files changed, 158 insertions, 0 deletions
diff --git a/test/behaviour/modes.zig b/test/behaviour/modes.zig
index cdcf1be6..dde3ffb6 100644
--- a/test/behaviour/modes.zig
+++ b/test/behaviour/modes.zig
@@ -63,3 +63,42 @@ test "modes: Shift-Esc backs out to the previous pane in every mode, never into
try std.testing.expectEqualStrings("normal", try mode(&s, doc));
try std.testing.expect(doc != try s.focused());
}
+
+/// The first line number drawn under the tag that starts with `tag`.
+fn topLine(s: *Session, tag: []const u8) !usize {
+ const row = (try s.where(tag))[1];
+ var rows = std.mem.splitScalar(u8, try s.screen(), '\n');
+ for (0..row + 1) |_| _ = rows.next();
+ var words = std.mem.tokenizeScalar(u8, rows.next().?, ' ');
+ return std.fmt.parseInt(usize, words.next().?, 10);
+}
+
+test "modes: Esc back into a file leaves its view where it was, and a look centres its line" {
+ var s = try Session.initFile(std.testing.allocator, std.mem.asBytes(&@as([100][4]u8, @splat("row\n".*))));
+ defer s.deinit();
+ const doc = try s.focused();
+ const dot = s.at("/pane/{d}/dot", .{doc});
+ try s.keys("\u{F015}n"); // a shell under the doc
+ const shell = try s.focused();
+ try s.keys("\x1b");
+ try expectEqual(doc, try s.focused());
+ // Ride the cursor down until the view has scrolled.
+ try s.keys(&@as([20]u8, @splat('j')));
+ const top = try topLine(&s, "/test.txt");
+ const at = try s.range(dot);
+ try std.testing.expect(top > 1);
+ try s.keys("\x1b");
+ try expectEqual(shell, try s.focused());
+ try s.keys("\x1b");
+ try expectEqual(doc, try s.focused());
+ // Nothing moved: the old landing recentred the line under the cursor.
+ try expectEqual(top, try topLine(&s, "/test.txt"));
+ try expectEqual(at, try s.range(dot));
+ // The other arm still centres: a look's `:NN`.
+ const line = 60;
+ try s.write(s.at("/pane/{d}/look", .{doc}), s.at(":{d}\n", .{line}));
+ const rows = (try s.where("Tty Save Mode"))[1] - (try s.where("/test.txt"))[1] - 1;
+ // Drawn mid-pane, a row either way.
+ const drawn_at = line - try topLine(&s, "/test.txt");
+ try std.testing.expect(drawn_at + 1 >= rows / 2 and drawn_at <= rows / 2 + 1);
+}
diff --git a/test/behaviour/panes.zig b/test/behaviour/panes.zig
index d0773bfb..149c8da1 100644
--- a/test/behaviour/panes.zig
+++ b/test/behaviour/panes.zig
@@ -112,3 +112,52 @@ test "panes: focus on a closed pane goes to the pane that takes its place, not t
try s.write(s.at("/col/{d}/ctl", .{try s.column(0)}), "Delcol\n");
try std.testing.expectEqual(right_low, try s.focused());
}
+
+test "panes: Collapse keeps the text and folds the pane to its tag, and again restores it" {
+ var s = try Session.initFile(std.testing.allocator, "keep this text\n");
+ defer s.deinit();
+ var t = try Session.initTerm(std.testing.allocator);
+ defer t.deinit();
+ const n = try s.focused();
+ for ([_][]const u8{
+ try s.read(s.at("/pane/{d}/tag", .{n})),
+ try s.read(s.at("/pane/{d}/tag", .{try s.newPane()})),
+ try t.read(t.at("/pane/{d}/tag", .{try t.focused()})),
+ }) |tag| try std.testing.expect(std.mem.endsWith(u8, tag, " Collapse Del"));
+ try s.write(s.at("/pane/{d}/ctl", .{try s.focused()}), "Del\n");
+ const ctl = s.at("/pane/{d}/ctl", .{n});
+ try s.write(ctl, "Collapse\n");
+ // Folded to its tag: no text drawn, no cursor in it, the text kept.
+ try std.testing.expect(std.mem.indexOf(u8, try s.read(ctl), " collapsed ") != null);
+ try std.testing.expect(std.mem.indexOf(u8, try s.screen(), "keep this text") == null);
+ try std.testing.expectEqual(null, try s.cursor());
+ try s.expect(s.at("/pane/{d}/body", .{n}), "keep this text\n");
+ try s.expect(s.at("/pane/{d}/dirty", .{n}), "0\n");
+ // Its tag still takes the keyboard, the cursor on the tag's row.
+ try s.keys(":");
+ try std.testing.expectEqual((try s.where("/test.txt"))[1], (try s.cursor()).?[1]);
+ try s.write(ctl, "Collapse\n");
+ try std.testing.expect(std.mem.indexOf(u8, try s.read(ctl), " collapsed ") == null);
+ try std.testing.expectEqual((try s.where("/test.txt"))[1] + 1, (try s.where("1 keep this text"))[1]);
+}
+
+test "panes: a pane its whole text fits in never scrolls to keep a margin" {
+ var tmp = std.testing.tmpDir(.{});
+ defer tmp.cleanup();
+ try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "f.txt", .data = "f\n" });
+ var dir: [4096]u8 = undefined;
+ const at = dir[0..try tmp.dir.realPath(std.testing.io, &dir)];
+ var s = try Session.initFile(std.testing.allocator, "one\ntwo\nthree\n");
+ defer s.deinit();
+ const n = try s.focused();
+ // A second pane under it, as acme's placement puts one: right under the
+ // three lines, which leaves the file exactly three body rows.
+ try s.write(s.at("/pane/{d}/look", .{n}), s.at("{s}/f.txt\n", .{at}));
+ try s.write("/focus", s.at("{d}\n", .{n}));
+ try s.keys("jj");
+ const top = (try s.where("/test.txt"))[1];
+ try std.testing.expectEqual(top + 4, (try s.where(at[0..@min(at.len, 20)]))[1]);
+ // On the last line, and line 1 still the first drawn.
+ try std.testing.expectEqual(.{ @as(u32, 8), @as(u32, 8) }, try s.range(s.at("/pane/{d}/dot", .{n})));
+ try std.testing.expectEqual(top + 1, (try s.where("1 one"))[1]);
+}
diff --git a/test/behaviour/placement.zig b/test/behaviour/placement.zig
new file mode 100644
index 00000000..350e94f8
--- /dev/null
+++ b/test/behaviour/placement.zig
@@ -0,0 +1,24 @@
+//! docs/typ/reference.typ, Placement <placement>.
+const std = @import("std");
+const Session = @import("session").Session;
+
+test "placement: an empty active column takes the new pane whole, a look from another column's text too" {
+ var tmp = std.testing.tmpDir(.{});
+ defer tmp.cleanup();
+ try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "f.txt", .data = "f\n" });
+ var dir: [4096]u8 = undefined;
+ const at = dir[0..try tmp.dir.realPath(std.testing.io, &dir)];
+ var s = try Session.initFile(std.testing.allocator, "x\n");
+ defer s.deinit();
+ const first = try s.focused();
+ // Its tag has the keyboard: it is the active column, and stays so
+ // when Esc gives the keyboard back.
+ try s.write("/ctl", "Newcol\n");
+ try s.keys("\x1b");
+ try std.testing.expectEqual(first, try s.focused());
+ // A look from the first pane's text still lands in the active column,
+ // as acme's makenewwindow puts it in activecol first (util.c:456).
+ try s.write(s.at("/pane/{d}/look", .{first}), s.at("{s}/f.txt\n", .{at}));
+ const made = try s.focused();
+ try std.testing.expectEqualStrings(s.at("{d}:{d} {d}:{d}", .{ try s.column(0), first, try s.column(1), made }), try s.columns());
+}
diff --git a/test/behaviour/terminals.zig b/test/behaviour/terminals.zig
new file mode 100644
index 00000000..f6bbdfa0
--- /dev/null
+++ b/test/behaviour/terminals.zig
@@ -0,0 +1,46 @@
+//! docs/typ/guide.typ, Terminals <terminals>.
+const std = @import("std");
+const Session = @import("session").Session;
+
+fn mode(s: *Session, pane: u32) ![]const u8 {
+ const ctl = try s.read(s.at("/pane/{d}/ctl", .{pane}));
+ const at = std.mem.lastIndexOf(u8, ctl, " mode:").? + " mode:".len;
+ return std.mem.trimEnd(u8, ctl[at..], " ");
+}
+
+test "terminals: Togglettymode and Ctrl-B share the mode's transitions, from the body or its tag, and a text pane refuses it" {
+ var s = try Session.initTerm(std.testing.allocator);
+ defer s.deinit();
+ const n = try s.focused();
+ const ctl = s.at("/pane/{d}/ctl", .{n});
+ try std.testing.expect(std.mem.indexOf(u8, try s.read(s.at("/pane/{d}/tag", .{n})), " Mode ") != null);
+ try s.write(s.at("/pane/{d}/tag", .{n}), " Togglettymode");
+ try std.testing.expectEqualStrings("tty", try mode(&s, n));
+ try s.write(ctl, "Togglettymode\n");
+ try std.testing.expectEqualStrings("normal", try mode(&s, n));
+ try s.keys("\x02");
+ try std.testing.expectEqualStrings("tty", try mode(&s, n));
+ // The tag has its own mode: the body keeps tty while the tag is typed
+ // into, and either way of toggling gives the body the keyboard back.
+ const tag_row = (try s.where("Togglettymode"))[1];
+ try s.click("Togglettymode", 0, 1);
+ try std.testing.expectEqualStrings("tty", try mode(&s, n));
+ try std.testing.expectEqual(tag_row, (try s.cursor()).?[1]);
+ try s.write(ctl, "Togglettymode\n");
+ try std.testing.expectEqualStrings("normal", try mode(&s, n));
+ try std.testing.expect((try s.cursor()).?[1] > tag_row);
+ try s.click("Togglettymode", 0, 1);
+ try s.keys("\x02");
+ try std.testing.expectEqualStrings("tty", try mode(&s, n));
+ try std.testing.expect((try s.cursor()).?[1] > tag_row);
+ // A middle click on the word in the tag.
+ try s.click("Togglettymode", 0, 2);
+ try std.testing.expectEqualStrings("normal", try mode(&s, n));
+ // A text pane refuses it, normal, its text as it was.
+ const file = try s.newPane();
+ try s.write(s.at("/pane/{d}/body", .{file}), "unchanged\n");
+ _ = try s.refused(s.at("/pane/{d}/ctl", .{file}), "Togglettymode\n");
+ try std.testing.expectEqualStrings("Togglettymode: only a terminal pane takes it", s.said);
+ try std.testing.expectEqualStrings("normal", try mode(&s, file));
+ try s.expect(s.at("/pane/{d}/body", .{file}), "unchanged\n");
+}