diff options
Diffstat (limited to 'test/behaviour')
| -rw-r--r-- | test/behaviour/columns_and_tags.zig | 39 | ||||
| -rw-r--r-- | test/behaviour/modes.zig | 65 | ||||
| -rw-r--r-- | test/behaviour/panes.zig | 63 | ||||
| -rw-r--r-- | test/behaviour/tags.zig | 19 |
4 files changed, 186 insertions, 0 deletions
diff --git a/test/behaviour/columns_and_tags.zig b/test/behaviour/columns_and_tags.zig index 80f9c710..5b78a6c8 100644 --- a/test/behaviour/columns_and_tags.zig +++ b/test/behaviour/columns_and_tags.zig @@ -149,3 +149,42 @@ test "columns-and-tags: New is a column tag's word, in no pane's tag nor the wor } try expectEqualStrings("New Tty Find Grep Joincol Delcol", try s.read(s.at("/col/{d}/tag", .{try s.column(0)}))); } + +test "columns-and-tags: a click past a column tag's text types after it, a newline typed there a space, and a long tag scrolls to its caret" { + var s = try Session.initFile(std.testing.allocator, "body\n"); + defer s.deinit(); + const tag = s.at("/col/{d}/tag", .{try s.column(0)}); + // Its row, then the pane's tag: the column's stays one row. + const rows = " New Tty Find Grep Joincol Delcol"; + try std.testing.expect(std.mem.indexOf(u8, try s.screen(), rows ++ " ") != null); + try s.click("Delcol", 20, 1); + try s.keys("\nSnarf"); + try expectEqualStrings("New Tty Find Grep Joincol Delcol Snarf", try s.read(tag)); + try std.testing.expect(std.mem.indexOf(u8, try s.screen(), rows ++ " Snarf ") != null); + try std.testing.expect(std.mem.indexOf(u8, try s.screen(), "\n /test.txt Save") != null); + // Wider than the screen: the tag scrolls to keep its caret drawn. + try s.keys(" 界界界界界界界界界界界界界界界界界界界界界界界界界界界界界界"); + const col, const row = (try s.cursor()).?; + try std.testing.expectEqual(@as(usize, 1), row); + try std.testing.expect(col < 80); + try std.testing.expect(std.mem.indexOf(u8, try s.screen(), rows) == null); + try s.keys("\u{F00D}"); + try std.testing.expect(std.mem.indexOf(u8, try s.screen(), rows) != null); +} + +test "columns-and-tags: Enter in a tag in normal mode runs the word under its cursor, and Tab does too, letting go of the keyboard first" { + var s = try Session.initFile(std.testing.allocator, "body\n"); + defer s.deinit(); + const first = try s.focused(); + try s.click("Newcol", 1, 1); + try s.keys("\x1b\n"); + try expectEqualStrings(s.at("{d}:{d} {d}:", .{ try s.column(0), first, try s.column(1) }), try s.columns()); + // The workspace tag lets go of the keyboard: the new, empty column's + // tag has it. + try s.expect("/focus", ""); + try s.keys("iMine\x1b"); + try std.testing.expect(std.mem.indexOf(u8, try s.read(s.at("/col/{d}/tag", .{try s.column(1)})), "Mine") != null); + try s.click("Tutor", 1, 1); + try s.keys("\x1b\t"); + try std.testing.expect(std.mem.endsWith(u8, try s.read(s.at("/pane/{d}/name", .{try s.focused()})), "/+Tutor\n")); +} diff --git a/test/behaviour/modes.zig b/test/behaviour/modes.zig new file mode 100644 index 00000000..cdcf1be6 --- /dev/null +++ b/test/behaviour/modes.zig @@ -0,0 +1,65 @@ +//! docs/typ/guide.typ, Modes <modes>. +const std = @import("std"); +const Session = @import("session").Session; +const expectEqual = std.testing.expectEqual; + +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 "modes: Esc in normal mode alternates between two panes of the same kind" { + var tmp = std.testing.tmpDir(.{}); + defer tmp.cleanup(); + try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "b.txt", .data = "b\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, "a\n"); + defer s.deinit(); + const a = try s.focused(); + try s.write("/look", s.at("{s}/b.txt\n", .{at})); + const b = try s.focused(); + try std.testing.expect(a != b); + for (0..6) |_| { + const was = try s.focused(); + try s.keys("\x1b"); + try expectEqual(if (was == a) b else a, try s.focused()); + } +} + +test "modes: Esc in a column or the workspace tag gives the keyboard back to a pane, as Shift-Esc does" { + var s = try Session.initFile(std.testing.allocator, "x\n"); + defer s.deinit(); + _ = try s.newPane(); + for ([_][]const u8{ "New Tty", "Newcol" }) |tag| { + const was = try s.focused(); + // A click types into the tag; Esc is normal mode there, the next + // one is out of it. + try s.click(tag, 0, 1); + try s.keys("\x1b"); + try s.expect("/focus", ""); + try s.keys("\x1b"); + try std.testing.expect(was != try s.focused()); + } +} + +test "modes: Shift-Esc backs out to the previous pane in every mode, never into raw" { + var s = try Session.initFile(std.testing.allocator, "x\n"); + defer s.deinit(); + const doc = try s.focused(); + try s.keys("\u{F015}n"); // a shell under the doc + const shell = try s.focused(); + if (std.mem.eql(u8, try mode(&s, shell), "tty")) try s.keys("\x02"); + try std.testing.expectEqualStrings("normal", try mode(&s, shell)); + // A terminal in normal mode: out, still normal, never raw. + try s.keys("\u{F016}\x1b"); + try expectEqual(doc, try s.focused()); + try std.testing.expectEqualStrings("normal", try mode(&s, shell)); + // A text pane in insert mode: out of insert, and out of the pane. + try s.keys("i"); + try std.testing.expectEqualStrings("insert", try mode(&s, doc)); + try s.keys("\u{F016}\x1b"); + try std.testing.expectEqualStrings("normal", try mode(&s, doc)); + try std.testing.expect(doc != try s.focused()); +} diff --git a/test/behaviour/panes.zig b/test/behaviour/panes.zig index 01820a07..d0773bfb 100644 --- a/test/behaviour/panes.zig +++ b/test/behaviour/panes.zig @@ -49,3 +49,66 @@ test "panes: Putall saves every pane with unsaved edits to a file, one each, and try s.write("/ctl", "Putall\n"); try std.testing.expectEqual(@as(usize, 1), s.saved); } + +test "panes: an unsaved file's tag is its name alone, its dirty file says it is unsaved" { + var s = try Session.initFile(std.testing.allocator, "before\n"); + defer s.deinit(); + const n = try s.focused(); + const tag = s.at("/pane/{d}/tag", .{n}); + const clean = try s.read(tag); + try s.write(s.at("/pane/{d}/body", .{n}), "after\n"); + try std.testing.expectEqualStrings(clean, try s.read(tag)); + try std.testing.expect(std.mem.indexOf(u8, clean, " *") == null); + try s.expect(s.at("/pane/{d}/dirty", .{n}), "1\n"); +} + +test "panes: a pane closed while its question stands ends the question in the log" { + var s = try Session.initFile(std.testing.allocator, "x\n"); + defer s.deinit(); + try s.write("/ctl", "Placement pardes\n"); + const top = try s.focused(); + try s.write(s.at("/pane/{d}/exec", .{top}), "New\n"); + const closing = try s.focused(); + try s.write(s.at("/pane/{d}/exec", .{closing}), "New\n"); + // A middle pane: Del from a key asks which side. + try s.write("/focus", s.at("{d}\n", .{closing})); + try s.keys(" d"); + try std.testing.expect(std.mem.indexOf(u8, try s.read("/log"), s.at("ask {d} del k j\n", .{closing})) != null); + // A bare answer says what this question takes. + const ctl = s.at("/pane/{d}/ctl", .{closing}); + _ = try s.refused(ctl, "answer\n"); + try std.testing.expectEqualStrings("answer takes k j or -", s.said); + try s.write(ctl, "Del\n"); + try std.testing.expect(std.mem.indexOf(u8, try s.read("/log"), s.at("answer {d} -\ndel {d}", .{ closing, closing })) != null); +} + +test "panes: focus on a closed pane goes to the pane that takes its place, not the one focused before" { + var s = try Session.initFile(std.testing.allocator, "x\n"); + defer s.deinit(); + const left = try s.focused(); + try s.write("/ctl", "Newcol\n"); + try s.write(s.at("/col/{d}/ctl", .{try s.column(1)}), "New\n"); + const right = try s.focused(); + try s.write(s.at("/pane/{d}/exec", .{left}), "New\n"); + const low = try s.focused(); + // `right` was focused just before `low`, but `left` grows into `low`'s + // rows, so `left` gets the focus. + try s.write(s.at("/pane/{d}/ctl", .{low}), "Del\n"); + try std.testing.expectEqual(left, try s.focused()); + // Closing a pane that has no focus leaves the focus where it is. + try s.write(s.at("/pane/{d}/exec", .{left}), "New\n"); + const other = try s.focused(); + try s.write("/focus", s.at("{d}\n", .{right})); + try s.write(s.at("/pane/{d}/ctl", .{other}), "Del\n"); + try std.testing.expectEqual(right, try s.focused()); + // Delcol: the column that takes the width holds, level with the closed + // pane, the pane that takes its place; `right` was focused just before. + try s.write(s.at("/pane/{d}/exec", .{right}), "New\n"); + const right_low = try s.focused(); + try s.write(s.at("/pane/{d}/exec", .{left}), "New\n"); + const left_low = try s.focused(); + try s.write("/focus", s.at("{d}\n", .{right})); + try s.write("/focus", s.at("{d}\n", .{left_low})); + try s.write(s.at("/col/{d}/ctl", .{try s.column(0)}), "Delcol\n"); + try std.testing.expectEqual(right_low, try s.focused()); +} diff --git a/test/behaviour/tags.zig b/test/behaviour/tags.zig new file mode 100644 index 00000000..ab109b78 --- /dev/null +++ b/test/behaviour/tags.zig @@ -0,0 +1,19 @@ +//! docs/typ/guide.typ, Tags <tags>. +const std = @import("std"); +const Session = @import("session").Session; + +test "tags: a name typed into the tag's path survives Esc, pending, and the next Enter renames; a second Esc drops it" { + var s = try Session.initFile(std.testing.allocator, "x\n"); + defer s.deinit(); + const n = try s.focused(); + const name = s.at("/pane/{d}/name", .{n}); + // A click on the path types into it; a stray key while it waits + // changes nothing. + try s.click("/test.txt", 1, 1); + try s.keys("z\x1bq\n"); + try s.expect(name, "/ztest.txt\n"); + try s.click("/ztest.txt", 1, 1); + try s.keys("z\x1bq\x1b"); + try s.expect(name, "/ztest.txt\n"); + try std.testing.expect(std.mem.startsWith(u8, try s.read(s.at("/pane/{d}/tag", .{n})), "/ztest.txt ")); +} |
