summaryrefslogtreecommitdiff
path: root/test/behaviour
diff options
context:
space:
mode:
Diffstat (limited to 'test/behaviour')
-rw-r--r--test/behaviour/addons.zig159
-rw-r--r--test/behaviour/addons_pdf.zig34
-rw-r--r--test/behaviour/columns_and_tags.zig50
-rw-r--r--test/behaviour/keys.zig21
-rw-r--r--test/behaviour/language_servers.zig82
-rw-r--r--test/behaviour/modes.zig23
-rw-r--r--test/behaviour/mouse.zig17
-rw-r--r--test/behaviour/other_files.zig6
-rw-r--r--test/behaviour/panes.zig23
-rw-r--r--test/behaviour/placement.zig5
-rw-r--r--test/behaviour/tags.zig87
-rw-r--r--test/behaviour/terminals.zig6
12 files changed, 416 insertions, 97 deletions
diff --git a/test/behaviour/addons.zig b/test/behaviour/addons.zig
index ce3c7b02..0b0555c2 100644
--- a/test/behaviour/addons.zig
+++ b/test/behaviour/addons.zig
@@ -371,3 +371,162 @@ test "addons: an image pane whose file changes on disk shows the new picture, un
try std.testing.expectEqual(n, try s.focused());
try std.testing.expect(has(try s.read("/screen"), "\"src\":[0,0,3,1]"));
}
+
+/// A tmp directory's real path, kept in the session's arena.
+fn dirOf(s: *Session, tmp: *std.testing.TmpDir) ![]const u8 {
+ var buf: [4096]u8 = undefined;
+ return s.arena.allocator().dupe(u8, buf[0..try tmp.dir.realPath(std.testing.io, &buf)]);
+}
+
+test "addons: a picker shows a file of an addon's kind through its kind in the pane it lands in, Esc puts that pane back as it was, and Enter lands as a Look does" {
+ var tmp = std.testing.tmpDir(.{});
+ defer tmp.cleanup();
+ // A work tree of its own: Find searches it, not the one the test runs in.
+ try tmp.dir.createDir(std.testing.io, ".git", .default_dir);
+ try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "notes.txt", .data = "the notes\n" });
+ try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "seven.fake", .data = "1234567" });
+ var s = try Session.initFile(std.testing.allocator, "x\n");
+ defer s.deinit();
+ try load(&s, fake.ok);
+ defer unload(&s, "fake");
+ const dir = try dirOf(&s, &tmp);
+ const pane = try s.lookFile(s.at("{s}/notes.txt", .{dir}));
+ const body = s.at("/pane/{d}/body", .{pane});
+ const a = s.arena.allocator();
+ const screen = try a.dupe(u8, try s.screen());
+ const index = try a.dupe(u8, try s.read("/index"));
+ // Its kind's paint in the reading pane's body (the fake counts the
+ // file's 7 bytes), not the pane's own text, nor the file's bytes.
+ try s.keys(" ffseven");
+ s.tick();
+ const shown = try s.screen();
+ try std.testing.expect(has(shown, "count 7"));
+ try std.testing.expect(!has(shown, "the notes") and !has(shown, "1234567"));
+ // Esc: the pane exactly as it was, and no pane more or less.
+ try s.keys("\x1b");
+ s.tick();
+ // (The notice row says the Find ran: the session's, not the pane's.)
+ const after = try s.screen();
+ try std.testing.expectEqualStrings(screen[0..std.mem.lastIndexOfScalar(u8, screen, '\n').?], after[0..std.mem.lastIndexOfScalar(u8, after, '\n').?]);
+ try s.expect(body, "the notes\n");
+ try std.testing.expectEqualStrings(index, try s.read("/index"));
+ // Enter: the kind's pane where a Look puts it; the reading pane keeps
+ // its text. (The listing is the next frame's, as for the keyboard.)
+ try s.keys(" ffseven");
+ s.tick();
+ try s.keys("\n");
+ s.tick();
+ const opened = try paneOf(&s, "fake");
+ try std.testing.expect(opened != pane);
+ try s.expect(body, "the notes\n");
+ try std.testing.expect(has(try s.screen(), "count 7"));
+}
+
+test "addons: a picker's row of a file no kind takes and not text shows one line naming it, and the row before's file never stays in the body" {
+ var tmp = std.testing.tmpDir(.{});
+ defer tmp.cleanup();
+ // A work tree of its own: Find searches it, not the one the test runs in.
+ try tmp.dir.createDir(std.testing.io, ".git", .default_dir);
+ try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "notes.txt", .data = "the notes\n" });
+ try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "other.txt", .data = "other text\n" });
+ try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "seven.fake", .data = "1234567" });
+ var blob: [3000]u8 = undefined;
+ for (&blob, 0..) |*b, i| b.* = @truncate(i *% 7);
+ try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "blob.bin", .data = &blob });
+ var s = try Session.initFile(std.testing.allocator, "x\n");
+ defer s.deinit();
+ try load(&s, fake.ok);
+ defer unload(&s, "fake");
+ const dir = try dirOf(&s, &tmp);
+ const pane = try s.lookFile(s.at("{s}/notes.txt", .{dir}));
+ try s.keys(" ffother");
+ s.tick();
+ try std.testing.expect(has(try s.screen(), "other text"));
+ // Onto the binary: its one line, never its bytes, nor other.txt.
+ try s.keys("\x08\x08\x08\x08\x08blob");
+ s.tick();
+ var shown = try s.screen();
+ try std.testing.expect(has(shown, "blob.bin · binary · 3.0 kB"));
+ try std.testing.expect(!has(shown, "other text"));
+ // Onto a kind's file: its kind's paint, not the binary's line.
+ try s.keys("\x08\x08\x08\x08seven");
+ s.tick();
+ shown = try s.screen();
+ try std.testing.expect(has(shown, "count 7"));
+ try std.testing.expect(!has(shown, "blob.bin · binary"));
+ // Back onto text, then Esc: the pane's own.
+ try s.keys("\x08\x08\x08\x08\x08other");
+ s.tick();
+ shown = try s.screen();
+ try std.testing.expect(has(shown, "other text") and !has(shown, "count 7"));
+ try s.keys("\x1b");
+ s.tick();
+ try s.expect(s.at("/pane/{d}/body", .{pane}), "the notes\n");
+ try std.testing.expect(has(try s.screen(), "the notes"));
+}
+
+test "addons: moving the cursor over pictures in a picker draws only the one it rests on, and a draw of one passed by is dropped whenever it comes back" {
+ var tmp = std.testing.tmpDir(.{});
+ defer tmp.cleanup();
+ // A work tree of its own: Find searches it, not the one the test runs in.
+ try tmp.dir.createDir(std.testing.io, ".git", .default_dir);
+ const png = "\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x00\x01\x00\x00\x00\x01\x08\x02\x00\x00\x00\x90wS\xde\x00\x00\x00\x0cIDATx\x9cc\xf8\xcf\xc0\x00\x00\x03\x01\x01\x00\xc9\xfe\x92\xef\x00\x00\x00\x00IEND\xaeB`\x82";
+ try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "notes.txt", .data = "the notes\n" });
+ try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "pic1.png", .data = png });
+ try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "pic2.png", .data = png });
+ try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "pic3.ppm", .data = "P6\n2 1\n255\n\x0d\x4d\xe7\x0d\x4d\xe7" });
+ var s = try Session.initFile(std.testing.allocator, "x\n");
+ defer s.deinit();
+ s.graphics();
+ try load(&s, Session.image_addon);
+ defer unload(&s, "image");
+ const dir = try dirOf(&s, &tmp);
+ const pane = try s.lookFile(s.at("{s}/notes.txt", .{dir}));
+ s.holdJobs();
+ try s.keys(" ffpic");
+ s.tick();
+ // Until its picture is drawn, one line names it.
+ const first = try s.screen();
+ try std.testing.expect(has(first, " · image · "));
+ try std.testing.expectEqual(1, s.held.items.len);
+ // Two rows down with no frame between: only the row it rests on draws.
+ try s.keys("\u{F800}\u{F800}");
+ s.tick();
+ _ = try s.screen();
+ try std.testing.expectEqual(2, s.held.items.len);
+ const rested = if (has(try s.screen(), "▶ pic3.ppm")) "\"src\":[0,0,2,1]" else "\"src\":[0,0,1,1]";
+ const passed = if (std.mem.eql(u8, rested, "\"src\":[0,0,2,1]")) "\"src\":[0,0,1,1]" else "\"src\":[0,0,2,1]";
+ // The rested one's answer first, the passed one's after: dropped.
+ std.mem.reverse(@TypeOf(s.held.items[0]), s.held.items);
+ s.releaseJobs();
+ const screen = try s.read("/screen");
+ try std.testing.expect(has(screen, s.at("\"serial\":{d},", .{pane})) and has(screen, rested));
+ try std.testing.expect(!has(screen, passed));
+}
+
+test "addons: Enter on a picture in a picker opens its kind's pane, never its bytes as text in the reading pane (the user's report)" {
+ var tmp = std.testing.tmpDir(.{});
+ defer tmp.cleanup();
+ // A work tree of its own: Find searches it, not the one the test runs in.
+ try tmp.dir.createDir(std.testing.io, ".git", .default_dir);
+ try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "notes.txt", .data = "the notes\n" });
+ try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "pic.ppm", .data = "P6\n2 1\n255\n\x0d\x4d\xe7\x0d\x4d\xe7" });
+ var s = try Session.initFile(std.testing.allocator, "x\n");
+ defer s.deinit();
+ s.graphics();
+ try load(&s, Session.image_addon);
+ defer unload(&s, "image");
+ const dir = try dirOf(&s, &tmp);
+ const pane = try s.lookFile(s.at("{s}/notes.txt", .{dir}));
+ // The listing is the next frame's, as for the keyboard.
+ try s.keys(" ffpic");
+ s.tick();
+ try s.keys("\n");
+ s.tick();
+ try s.expect(s.at("/pane/{d}/body", .{pane}), "the notes\n");
+ const image = try paneOf(&s, "image");
+ try std.testing.expect(image != pane);
+ const screen = try s.read("/screen");
+ try std.testing.expect(has(screen, s.at("\"serial\":{d},", .{image})) and has(screen, "\"src\":[0,0,2,1]"));
+ try std.testing.expect(!has(try s.screen(), "1 P6"));
+}
diff --git a/test/behaviour/addons_pdf.zig b/test/behaviour/addons_pdf.zig
index 0c7982d1..7df5d5ee 100644
--- a/test/behaviour/addons_pdf.zig
+++ b/test/behaviour/addons_pdf.zig
@@ -45,10 +45,10 @@ test "addons: a PDF is the pdf addon's pane, its pages pictures, its page in its
const first = try shown(&s, n);
try std.testing.expect(first.len >= 1);
// Its tag: its page, then the core's art words (it placed a picture),
- // its path and its kind's words.
+ // its path and its kind's words, then Del (UX K'3).
const tag = try s.read(s.at("/pane/{d}/tag", .{n}));
try std.testing.expect(std.mem.startsWith(u8, tag, "[1/16] petscii:off palette:commodore ascii:on /"));
- try std.testing.expect(has(tag, "/docs/design.pdf Term PdfSections PdfTint PdfFit Collapse Del"));
+ try std.testing.expect(has(tag, "/docs/design.pdf PdfSections PdfTint PdfFit Del"));
try std.testing.expect(has(try ctlOf(&s, n), " fit:width tint:filtered mode:normal "));
// The words: bare they step, given a value they take it, any other
// value refused; another pane's is refused and leaves the PDF alone.
@@ -299,3 +299,33 @@ test "addons: a PDF whose file changes on disk while a page of it renders: the p
try s.keys("0");
try std.testing.expect((try shown(&s, n)).len >= 1);
}
+
+test "addons: a PDF under a picker's cursor shows through the pdf addon in the pane it lands in, never its bytes as text, and Esc puts the pane's own text back" {
+ var s = try Session.initFile(std.testing.allocator, "x\n");
+ defer s.deinit();
+ s.graphics();
+ try s.loadPdf();
+ var tmp = std.testing.tmpDir(.{});
+ defer tmp.cleanup();
+ // A work tree of its own: Find searches it, not the one the test runs in.
+ try tmp.dir.createDir(std.testing.io, ".git", .default_dir);
+ const pdf = try std.Io.Dir.cwd().readFileAlloc(std.testing.io, "docs/design.pdf", s.arena.allocator(), .limited(4 << 20));
+ try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "paper.pdf", .data = pdf });
+ try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "notes.txt", .data = "the notes\n" });
+ var buf: [4096]u8 = undefined;
+ const dir = buf[0..try tmp.dir.realPath(std.testing.io, &buf)];
+ const pane = try s.lookFile(s.at("{s}/notes.txt", .{dir}));
+ try s.keys(" ffpaper");
+ // (Its kind told its view at the frame after the one that opened it.)
+ s.tick();
+ s.tick();
+ const screen = try s.screen();
+ try std.testing.expect(!has(screen, "%PDF") and !has(screen, "the notes"));
+ // Its pages pictures in that pane's body, as a PDF's pane shows them.
+ try std.testing.expect((try shown(&s, pane)).len > 0);
+ try s.keys("\x1b");
+ s.tick();
+ try s.expect(s.at("/pane/{d}/body", .{pane}), "the notes\n");
+ try std.testing.expectEqual(0, (try shown(&s, pane)).len);
+ try std.testing.expect(has(try s.screen(), "the notes"));
+}
diff --git a/test/behaviour/columns_and_tags.zig b/test/behaviour/columns_and_tags.zig
index 9abe64f4..4ca6f7b3 100644
--- a/test/behaviour/columns_and_tags.zig
+++ b/test/behaviour/columns_and_tags.zig
@@ -129,9 +129,12 @@ test "columns-and-tags: Delcol on the last column leaves the window, drawn and t
try s.write(s.at("/col/{d}/ctl", .{try s.column(0)}), "Delcol\n");
try expectEqualStrings("", try s.columns());
try s.expect("/index", "");
- // Drawn, and keys go to the workspace tag.
+ // Drawn, its words at the window row's right end (UX K'2), and keys go
+ // to the workspace tag.
try s.keys("x\n");
- try std.testing.expect(std.mem.startsWith(u8, try s.screen(), " Newcol "));
+ const screen = try s.screen();
+ const first = std.mem.trimEnd(u8, screen[0..std.mem.indexOfScalar(u8, screen, '\n').?], " ");
+ try std.testing.expect(std.mem.endsWith(u8, first, "Find Grep Newcol Help Exit"));
try s.write("/ctl", "Newcol\n");
try s.write(s.at("/col/{d}/ctl", .{try s.column(0)}), "New\n");
try expectEqualStrings(s.at("{d}:{d}", .{ try s.column(0), try s.focused() }), try s.columns());
@@ -162,7 +165,8 @@ test "columns-and-tags: New is a column tag's word, in no pane's tag nor the wor
var words = std.mem.tokenizeScalar(u8, tag, ' ');
while (words.next()) |word| try std.testing.expect(!std.mem.eql(u8, word, "New"));
}
- try expectEqualStrings("New Term Find Grep Joincol Delcol", try s.read(s.at("/col/{d}/tag", .{try s.column(0)})));
+ // A lone column's words (UX K'2), and no text of the user's.
+ try expectEqualStrings("New Term ", 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" {
@@ -171,18 +175,20 @@ test "columns-and-tags: a click past a column tag's text types after it, a newli
// A held pane (Keep): its tag as it was before the walk, no `Keep` word (SPEC §6.5).
try s.write(s.at("/pane/{d}/exec", .{try s.focused()}), "Keep\n");
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 Term Find Grep Joincol Delcol";
- try std.testing.expect(std.mem.indexOf(u8, try s.screen(), rows ++ " ") != null);
- try s.click("Delcol", 20, 1);
- // A clicked tag is in normal mode: `i` types where it was clicked.
+ // A lone column's tag is at the window row's left (UX K'2).
+ try std.testing.expect(std.mem.startsWith(u8, try s.screen(), " New Term "));
+ // Past its text, on its caret's cell. A clicked tag is in normal mode:
+ // `i` types where it was clicked, after its computed words.
+ try s.click("Term", 5, 1);
try s.keys("i\nSnarf");
- try expectEqualStrings("New Term Find Grep Joincol Delcol Snarf", try s.read(tag));
- try std.testing.expect(std.mem.indexOf(u8, try s.screen(), rows ++ " Snarf ") != null);
- // The pane's tag on the row right under it: the column's is one row.
- try std.testing.expectEqual((try s.where(rows))[1] + 1, (try s.where("/test.txt Save"))[1]);
+ try expectEqualStrings("New Term Snarf", try s.read(tag));
+ // The user's text brings the column row, one row under the window's,
+ // and the pane's tag on the row right under it.
+ const rows = " New Term Snarf";
+ try std.testing.expectEqual(@as(usize, 1), (try s.where(rows ++ " "))[1]);
+ try std.testing.expectEqual((try s.where(rows))[1] + 1, (try s.where("/test.txt Del"))[1]);
// Wider than the screen: the tag scrolls to keep its caret drawn.
- try s.keys(" 界界界界界界界界界界界界界界界界界界界界界界界界界界界界界界");
+ try s.keys(" 界界界界界界界界界界界界界界界界界界界界界界界界界界界界界界界界界界界界界界界界界界界界界界");
const col, const row = (try s.cursor()).?;
try std.testing.expectEqual(@as(usize, 1), row);
try std.testing.expect(col < 80);
@@ -204,9 +210,9 @@ test "columns-and-tags: Enter in a tag in normal mode runs the word under its cu
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.click("Help", 1, 1);
try s.keys("\t");
- try std.testing.expect(std.mem.endsWith(u8, try s.read(s.at("/pane/{d}/name", .{try s.focused()})), "/+Tutor\n"));
+ try std.testing.expect(std.mem.endsWith(u8, try s.read(s.at("/pane/{d}/name", .{try s.focused()})), "/+Help\n"));
}
test "columns-and-tags: a tag write refuses NUL and the other control characters, the workspace's, a column's and a pane's" {
@@ -279,14 +285,18 @@ test "columns-and-tags: a column tag lights the word under the mouse, is clicked
try s.write("/mousein", s.at("m {d} 1 1\nm {d} 1 0\n", .{ x + 3, x + 3 }));
for (0..4) |k| try expectEqualStrings(lit, try s.bg(x + k, 1));
try std.testing.expect(!std.mem.eql(u8, lit, try s.bg(x + 4, 1)));
- // A clicked tag is in normal mode: `i` types at its caret.
- try s.keys("\u{F00D}iHelp ");
- try std.testing.expect(std.mem.startsWith(u8, try s.read(tag), "Help New Term"));
- try std.testing.expectEqual(x + 5, (try s.cursor()).?[0]);
+ // A clicked tag is in normal mode: `i` types at its caret, after its
+ // computed words (UX K'1).
+ const lead = "New Term Joincol Delcol ".len;
+ try s.keys("\u{F00D}");
+ try s.write("/mousein", s.at("m {d} 1 1\nm {d} 1 0\n", .{ x + lead, x + lead }));
+ try s.keys("iHelp ");
+ try expectEqualStrings("New Term Joincol Delcol Help ", try s.read(tag));
+ try std.testing.expectEqual(x + lead + 5, (try s.cursor()).?[0]);
// A tag one short of its room: its caret at the end is drawn on the
// last cell, and one more letter scrolls the text, never the caret.
const as: [80]u8 = @splat('a');
- const row = as[0 .. width - 1];
+ const row = as[0 .. width - 1 - lead];
try s.replace(tag, row);
try s.keys("\u{F018}");
try std.testing.expectEqual(x + width - 1, (try s.cursor()).?[0]);
diff --git a/test/behaviour/keys.zig b/test/behaviour/keys.zig
index c5dccb1e..241468ac 100644
--- a/test/behaviour/keys.zig
+++ b/test/behaviour/keys.zig
@@ -14,7 +14,7 @@ test "keys: a prompt's entry and cancellation leave the tag, the body and its cu
const n = try s.focused();
const tag = s.at("/pane/{d}/tag", .{n});
const dot = s.at("/pane/{d}/dot", .{n});
- try s.replace(tag, " keep");
+ try s.replace(tag, "keep");
for ([_]struct { keys: []const u8, shown: []const u8 }{
.{ .keys = "s", .shown = " s zq" },
.{ .keys = "|", .shown = " | zq" },
@@ -34,14 +34,15 @@ test "keys: a prompt's entry and cancellation leave the tag, the body and its cu
try s.keys("\x1b");
try std.testing.expectError(error.NotOnScreen, s.where(case.shown));
try std.testing.expect(std.mem.endsWith(u8, try s.read(s.at("/pane/{d}/ctl", .{n})), " mode:normal "));
- try std.testing.expectEqualStrings("/test.txt keep", try s.read(tag));
+ try std.testing.expectEqualStrings("/test.txt Del keep", try s.read(tag));
try std.testing.expectEqual(.{ 6, 6 }, try s.range(dot));
try s.expect(s.at("/pane/{d}/body", .{n}), "one\ntwo\n");
}
- // Save on a scratch asks for a path, starting from its directory.
+ // Save on a scratch (SPC f s: no word of its tag, UX K'3) asks for a
+ // path, starting from its directory.
const scratch = try s.newPane();
const scratch_tag = try s.read(s.at("/pane/{d}/tag", .{scratch}));
- try s.keys("::\tzq");
+ try s.keys(" fszq");
_ = try s.where("/zq");
try s.expect(s.at("/pane/{d}/tag", .{scratch}), scratch_tag);
try s.keys("\x1b");
@@ -124,7 +125,7 @@ test "keys: a count or a prefix a click or a change of pane cancels leaves nothi
.body => try s.click("abcdefghij", 3, 1),
.tag => {
// A clicked tag is in normal mode: `:` goes back.
- try s.click("/test.txt Save", "/test.txt ".len + 3, 1);
+ try s.click("/test.txt Del", "/test.txt ".len + 2, 1);
try s.keys(":");
},
.focus, .last => {
@@ -273,7 +274,8 @@ test "keys: Save's prompt on a scratch starts from the scratch's directory, one
// New from the file's pane: a scratch in its directory.
try s.write(s.at("/pane/{d}/exec", .{n}), "New\n");
try std.testing.expect(try s.focused() != n);
- try s.keys("::\tzq");
+ // SPC f s: Save is no word of a scratch's tag (UX K'3).
+ try s.keys(" fszq");
_ = try s.where(c[1]);
try s.keys("\x1b");
}
@@ -412,11 +414,12 @@ test "keys: zz and zc put the cursor's line in the middle row of an odd view, as
for (&lines, 0..) |*l, i| _ = try std.fmt.bufPrint(l, "l{d:0>2}\n", .{i});
var s = try Session.initFile(std.testing.allocator, std.mem.asBytes(&lines));
defer s.deinit();
- s.resize(80, 25);
+ s.resize(80, 24);
for ([_][]const u8{ "15jzz", "ztzc" }) |keys| {
try s.keys(keys);
- // 80x25 gives the pane 21 rows (the notice row under it): l05 to
- // l25, l15 the eleventh
+ // 80x24 gives the pane 21 rows (the window row and its tag above
+ // them, the notice row under them; one column, no column row):
+ // l05 to l25, l15 the eleventh
const top = (try s.where("l05"))[1];
try std.testing.expectEqual(top + 10, (try s.where("l15"))[1]);
try std.testing.expectEqual(top + 20, (try s.where("l25"))[1]);
diff --git a/test/behaviour/language_servers.zig b/test/behaviour/language_servers.zig
index 13e42fa6..d1b160ee 100644
--- a/test/behaviour/language_servers.zig
+++ b/test/behaviour/language_servers.zig
@@ -206,7 +206,7 @@ test "language-servers: Symbols lists the file's definitions by name, a local's
try s.write(s.at("/pane/{d}/look", .{main}), s.at("{s}/lib.rs\n", .{std.fs.path.dirname(std.mem.trimEnd(u8, try s.read(s.at("/pane/{d}/name", .{main})), "\n")).?}));
try s.write(s.at("/pane/{d}/ctl", .{try s.focused()}), "Symbols\n");
const rows = try bodyOf(&s, "+Search");
- for ([_][]const u8{ "lib.rs:1:11-15\nShape\n", "lib.rs:2:8-11\narea\n", "lib.rs:5:8-10\nadd\n", "lib.rs:8:12-17\nSquare\n", "lib.rs:10:8-11\narea\n" }) |row|
+ for ([_][]const u8{ "lib.rs:1:11-15 Shape\n", "lib.rs:2:8-11 area\n", "lib.rs:5:8-10 add\n", "lib.rs:8:12-17 Square\n", "lib.rs:10:8-11 area\n" }) |row|
try std.testing.expect(has(rows, row));
try std.testing.expect(!has(rows, "lib.rs:5:12"));
}
@@ -323,3 +323,83 @@ test "language-servers: SPC l a lists the server's code actions in the pane's ta
try s.keys("u");
try s.expect(body, before);
}
+
+test "language-servers: a server's Symbols are the Symbols picker's rows: types, functions, fields, then the rest, each its kind's mark and its name in the ones it is in (UX DESIGN N)" {
+ var tmp = std.testing.tmpDir(.{});
+ defer tmp.cleanup();
+ var s = try Session.initLanguage(std.testing.allocator);
+ defer s.deinit();
+ try s.write("/ctl", "Jumps new-pane\n");
+ // No index: the server is asked.
+ try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "shapes.rs", .data = "const LIMIT: u32 = 4;\n\nfn main() {}\npub struct Shape {\n side: u32,\n fn area() {}\n}\nenum Kind {\n Round,\n}\nmod lib;\n" });
+ var buf: [4096]u8 = undefined;
+ const dir = buf[0..try tmp.dir.realPath(std.testing.io, &buf)];
+ const shapes = try s.lookFile(s.at("{s}/shapes.rs:1:1", .{dir}));
+ try s.write(s.at("/pane/{d}/ctl", .{shapes}), "Symbols\n");
+ const rows = try bodyOf(&s, "+Search");
+ var at: usize = 0;
+ for ([_][]const u8{ "shapes.rs:4:12-16 t Shape\n", "shapes.rs:8:6-9 t Kind\n", "shapes.rs:3:4-7 f main\n", "shapes.rs:6:8-11 f Shape.area\n", "shapes.rs:5:5-8 m Shape.side\n", "shapes.rs:9:5-9 m Kind.Round\n", "shapes.rs:1:7-11 c LIMIT\n", "shapes.rs:11:5-7 n lib\n" }) |row| {
+ const found = std.mem.indexOfPos(u8, rows, at, row) orelse {
+ std.debug.print("{s} not after {d} in\n{s}\n", .{ row, at, rows });
+ return error.TestUnexpectedResult;
+ };
+ at = found + row.len;
+ }
+}
+
+extern "c" fn setenv(name: [*:0]const u8, value: [*:0]const u8, overwrite: c_int) c_int;
+
+/// The row of Lspinfo's report on the server `name` (`zls`), asked of the
+/// pane with the keyboard, and how many queries its client has answered.
+fn serverRow(s: *Session, name: []const u8) !struct { []const u8, []const u8 } {
+ try s.write(s.at("/pane/{d}/ctl", .{try s.focused()}), "Lspinfo\n");
+ const info = try bodyOf(s, "+Lsp");
+ const at = (std.mem.indexOf(u8, info, s.at("\n {s} ", .{name})) orelse return error.NoSuchServer) + 1;
+ const row = info[at .. std.mem.indexOfScalarPos(u8, info, at, '\n') orelse info.len];
+ const log = std.mem.indexOf(u8, info, "client queries (") orelse return error.NoQueryLog;
+ return .{ row, info[log .. std.mem.indexOfPos(u8, info, log, " total") orelse return error.NoQueryLog] };
+}
+
+test "language-servers: a file of a server's language opened in a pane starts that server and tells it of the file, with no query asked; a picker's preview of one starts none, a second file no second server, and a server not installed is found silently" {
+ const io = std.testing.io;
+ var tmp = std.testing.tmpDir(.{});
+ defer tmp.cleanup();
+ // A work tree of its own: Find searches it, not the one the test runs in.
+ try tmp.dir.createDir(io, ".git", .default_dir);
+ try tmp.dir.writeFile(io, .{ .sub_path = "a.zig", .data = "const a = 1;\n" });
+ try tmp.dir.writeFile(io, .{ .sub_path = "b.zig", .data = "const b = 2;\n" });
+ try tmp.dir.writeFile(io, .{ .sub_path = "c.py", .data = "c = 3\n" });
+ try tmp.dir.writeFile(io, .{ .sub_path = "d.py", .data = "d = 4\n" });
+ try tmp.dir.writeFile(io, .{ .sub_path = "notes.txt", .data = "the notes\n" });
+ var buf: [4096]u8 = undefined;
+ const dir = buf[0..try tmp.dir.realPath(io, &buf)];
+ var s = try Session.initLanguage(std.testing.allocator);
+ defer s.deinit();
+ _ = try s.lookFile(s.at("{s}/notes.txt", .{dir}));
+ // a.zig previewed by Find's picker (the session's jumps walk): its text
+ // shown, its server (the scripted one, the session's zls) not started.
+ try s.keys(" ffa.zig");
+ s.tick();
+ try std.testing.expect(has(try s.screen(), "const a = 1;"));
+ try s.keys("\x1b");
+ const before, const asked = try serverRow(&s, "zls");
+ try std.testing.expect(has(before, "not started yet"));
+ // Opened: started and told of a.zig, no query asked of it.
+ _ = try s.lookFile(s.at("{s}/a.zig", .{dir}));
+ const opened, const asked_open = try serverRow(&s, "zls");
+ try std.testing.expect(has(opened, "ready") and has(opened, "docs 1"));
+ try std.testing.expectEqualStrings(asked, asked_open);
+ // A second file: the same server told of it too (a second would know one).
+ _ = try s.lookFile(s.at("{s}/b.zig", .{dir}));
+ const second, _ = try serverRow(&s, "zls");
+ try std.testing.expect(has(second, "ready") and has(second, "docs 2"));
+ // Not installed: the language's server disabled at the first file's
+ // open, with no word at either (its first query says it is not found).
+ _ = setenv("PARDES_LSP_PY", "/nonexistent/pyright-langserver", 1);
+ _ = try s.lookFile(s.at("{s}/c.py", .{dir}));
+ _ = try s.lookFile(s.at("{s}/d.py", .{dir}));
+ const missing, const asked_missing = try serverRow(&s, "pyright");
+ try std.testing.expect(has(missing, "disabled"));
+ try std.testing.expectEqualStrings(asked, asked_missing);
+ try std.testing.expect(!has(try s.screen(), "not found"));
+}
diff --git a/test/behaviour/modes.zig b/test/behaviour/modes.zig
index 0f7c9d26..39bb66c8 100644
--- a/test/behaviour/modes.zig
+++ b/test/behaviour/modes.zig
@@ -98,7 +98,8 @@ test "modes: Esc back into a file leaves its view where it was, and a look centr
// 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("Term Save Mode"))[1] - (try s.where("/test.txt"))[1] - 1;
+ // (The shell's tag: its computed Del, then its own text, Term.)
+ const rows = (try s.where("Del Term"))[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);
@@ -163,7 +164,7 @@ test "modes: Ctrl-w outlines a pane, h j k l move the outline, and Enter, Esc, :
// `:` gives the outlined pane's tag the keyboard.
try s.keys("\x17l:");
try expectEqual(b, try s.focused());
- try expectEqual((try s.where("/b.txt Save"))[1], (try s.cursor()).?[1]);
+ try expectEqual((try s.where("/b.txt Del"))[1], (try s.cursor()).?[1]);
try s.keys("\x1b");
// A letter goes straight there.
try s.keys("\x17a");
@@ -190,11 +191,11 @@ test "modes: in window mode d deletes the outlined pane, asking k or j between t
try s.write(s.at("/pane/{d}/name", .{mid}), "/mid\n");
try s.write(s.at("/pane/{d}/name", .{low}), "/low\n");
const names = &[_][]const u8{ "/test.txt", "/mid", "/low" };
- const row_top = (try s.where("/test.txt Save"))[1];
- const row_mid = (try s.where("/mid Save"))[1];
- const row_low = (try s.where("/low Save"))[1];
+ const row_top = (try s.where("/test.txt Del"))[1];
+ const row_mid = (try s.where("/mid Del"))[1];
+ const row_low = (try s.where("/low Del"))[1];
// From the bottom pane, the outline up to the middle one.
- const mx, const my = try s.where("/mid Save");
+ const mx, const my = try s.where("/mid Del");
const plain = try s.bg(mx, my);
try s.keys("\x17k");
const lit = try s.bg(mx, my);
@@ -217,7 +218,7 @@ test "modes: in window mode d deletes the outlined pane, asking k or j between t
// j: the pane below takes the rows, and the outline goes with them.
try s.keys("dj");
try std.testing.expect(!try listed(&s, mid));
- try expectEqual(row_top, (try s.where("/test.txt Save"))[1]);
+ try expectEqual(row_top, (try s.where("/test.txt Del"))[1]);
try expectEqual(row_mid, (try s.where("/low "))[1]);
try std.testing.expectEqualStrings("/low", try outlined(&s, lit, &.{ "/test.txt", "/low" }));
// With one neighbour nothing is asked: d closes it, the outline on the
@@ -248,10 +249,12 @@ test "modes: window keys walk from a pane up through its column's tag and the wo
try std.testing.expect(x0 < right);
const tag = s.at("/col/{d}/tag", .{try s.column(0)});
const words = try s.read(tag);
- try s.keys("w");
+ // On its user's text, after its computed words (UX K'1): `b` moves
+ // back onto them.
+ try s.keys("b");
try s.expect(tag, words);
const remembered = (try s.cursor()).?;
- try std.testing.expect(remembered[0] > x0);
+ try std.testing.expect(remembered[0] < x0);
// Across to the right column's tag, and back to where the caret was.
try s.keys("\x17l");
try std.testing.expect((try s.cursor()).?[0] >= right);
@@ -461,7 +464,7 @@ test "modes: hopping between two panes by Esc, window mode or a click makes no p
try expectEqual(want, try s.focused());
}
const doc_row = (try s.where("row"))[1];
- const shell_row = (try s.where("Term Save Mode"))[1] + 1;
+ const shell_row = (try s.where("Del Term"))[1] + 1;
for (0..8) |_| {
const other = if (try s.focused() == doc) shell else doc;
const row = if (other == doc) doc_row else shell_row;
diff --git a/test/behaviour/mouse.zig b/test/behaviour/mouse.zig
index 951ab493..0e22416f 100644
--- a/test/behaviour/mouse.zig
+++ b/test/behaviour/mouse.zig
@@ -25,9 +25,10 @@ test "mouse: a double-click selects a word, a line, a bracketed or quoted text,
try s.click(w.at, w.into, 1);
try s.expect(sel, "");
}
- // In the tag too: what it selected is what a yank takes.
- try s.click("Follow Del", "Follow D".len, 1);
- try s.click("Follow Del", "Follow D".len, 1);
+ // In the tag too: what it selected is what a yank takes (its computed
+ // Del, after Keep: the file is reading).
+ try s.click("Keep Del", "Keep D".len, 1);
+ try s.click("Keep Del", "Keep D".len, 1);
try s.keys("\x1by:ggP");
try s.expect(s.at("/pane/{d}/body", .{n}), "Delcall foo_bar(a, b)\nsay \"hi there\"\n");
}
@@ -120,13 +121,15 @@ test "mouse: a B1 sweep over several lines is a stream, as acme's, in a body and
// Upward, the same text.
try mouse(&s, "m {d} {d} 1\nm {d} {d} 1\nm {d} {d} 3\nm {d} {d} 0\n", .{ x + 1, y + 2, x + 2, y, x + 2, y, x + 2, y });
try s.expect(body, "alarlie\n");
- // A tag of several rows sweeps the same way.
+ // A tag of several rows sweeps the same way, in its own text (its
+ // computed words are read-only, UX K'1).
const tag = s.at("/pane/{d}/tag", .{n});
- try s.write(tag, "\nLook Edit");
+ try s.write(tag, "Collapse\nLook Edit");
+ const was = try s.read(tag);
const tx, const ty = try s.where("Collapse");
const lx, const ly = try s.where("Look Edit");
try mouse(&s, "m {d} {d} 1\nm {d} {d} 1\nm {d} {d} 3\nm {d} {d} 0\n", .{ tx + 3, ty, lx + 1, ly, lx + 1, ly, lx + 1, ly });
- try s.expect(tag, "/test.txt Save Term Colok Edit");
+ try s.expect(tag, s.at("{s}Colok Edit", .{was[0 .. was.len - "Collapse\nLook Edit".len]}));
}
test "mouse: a click on either half of a wide character lands before it, in the text and on a tag's path, and the caret steps over it whole" {
@@ -157,7 +160,7 @@ test "mouse: a click on either half of a wide character lands before it, in the
// Typed past the tag's words, a two-byte λ goes in and one backspace
// takes it out whole.
const tag = try s.read(s.at("/pane/{d}/tag", .{n}));
- try s.click("Follow Del", "Follow Del".len + 1, 1);
+ try s.click("Keep Del", "Keep Del".len + 1, 1);
const caret = (try s.cursor()).?;
// A clicked tag is in normal mode: `i` types at the caret.
try s.keys("iλ");
diff --git a/test/behaviour/other_files.zig b/test/behaviour/other_files.zig
index e6c104c3..95d4de6d 100644
--- a/test/behaviour/other_files.zig
+++ b/test/behaviour/other_files.zig
@@ -25,6 +25,8 @@ test "other-files: kbdin types at the pane with the keyboard and mousein clicks,
test "other-files: kbdin's keys are the user's: SPC f f opens Find's picker in the pane's tag where jumps walk, not the +Search a script's Find opens" {
var tmp = std.testing.tmpDir(.{});
defer tmp.cleanup();
+ // A work tree of its own: Find searches it, not the one the test runs in.
+ try tmp.dir.createDir(std.testing.io, ".git", .default_dir);
try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "a.txt", .data = "a\n" });
try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "b.txt", .data = "b\n" });
var s = try Session.initFile(std.testing.allocator, "x\n");
@@ -33,7 +35,9 @@ test "other-files: kbdin's keys are the user's: SPC f f opens Find's picker in t
_ = try s.lookFile(s.at("{s}/a.txt", .{buf[0..try tmp.dir.realPath(std.testing.io, &buf)]}));
try s.keys(" ff");
try std.testing.expect(std.mem.indexOf(u8, try s.read("/index"), "+Search") == null);
- // Its rows under the tag of the pane typed at, the cursor on the first.
+ // Its rows under the tag of the pane typed at, the cursor on the first,
+ // the next frame, as the keyboard's: the listing is not the write's.
+ s.tick();
_ = try s.where("▶ a.txt");
_ = try s.where(" b.txt");
}
diff --git a/test/behaviour/panes.zig b/test/behaviour/panes.zig
index 4c76df25..11c2a0e6 100644
--- a/test/behaviour/panes.zig
+++ b/test/behaviour/panes.zig
@@ -167,7 +167,7 @@ test "panes: a second lock is refused until the holder unlocks or closes, and bi
s.clunk(e);
}
-test "panes: an unsaved file's tag is its name alone, its dirty file says it is unsaved" {
+test "panes: an unsaved file's tag marks nothing on its name, Save and Undo come into its words, its dirty file says it is unsaved" {
var s = try Session.initFile(std.testing.allocator, "before\n");
defer s.deinit();
// A held pane (Keep): its tag as it was before the walk, no `Keep` word (SPEC §6.5).
@@ -175,9 +175,13 @@ test "panes: an unsaved file's tag is its name alone, its dirty file says it is
const n = try s.focused();
const tag = s.at("/pane/{d}/tag", .{n});
const clean = try s.read(tag);
+ try std.testing.expectEqualStrings("/test.txt Del ", clean);
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);
+ // Its words say what acts now, Save and Undo (UX K'3); no mark after
+ // the name.
+ const unsaved = try s.read(tag);
+ try std.testing.expectEqualStrings("/test.txt Save Undo Del ", unsaved);
+ try std.testing.expect(std.mem.indexOf(u8, unsaved, " *") == null);
try s.expect(s.at("/pane/{d}/dirty", .{n}), "1\n");
}
@@ -237,14 +241,19 @@ test "panes: Collapse keeps the text and folds the pane to its tag, and again re
var t = try Session.initTerm(std.testing.allocator);
defer t.deinit();
const n = try s.focused();
+ // Collapse is no word of a tag (UX K'3), a file's, a scratch's or a
+ // terminal's: its keys are C-w c and SPC w c, and it runs from ctl.
for ([_][]const u8{
try s.read(s.at("/pane/{d}/tag", .{n})),
try s.read(s.at("/pane/{d}/tag", .{try s.newPane()})),
- }) |tag| try std.testing.expect(std.mem.endsWith(u8, tag, " Collapse Follow Del"));
- try std.testing.expect(std.mem.endsWith(u8, try t.read(t.at("/pane/{d}/tag", .{try t.focused()})), " Collapse Del"));
+ try t.read(t.at("/pane/{d}/tag", .{try t.focused()})),
+ }) |tag| try std.testing.expect(std.mem.indexOf(u8, tag, "Collapse") == null);
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");
+ // C-w c folds the outlined pane, the keyboard's; Esc leaves window
+ // mode on it.
+ try std.testing.expectEqual(n, try s.focused());
+ try s.keys("\x17c\x1b");
// 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);
@@ -321,7 +330,7 @@ test "panes: PdfTint steps a PDF's tint, read in its ctl and never in its tag, a
const n = try s.lookFile("docs/design.pdf");
const ctl = s.at("/pane/{d}/ctl", .{n});
const tag = try s.read(s.at("/pane/{d}/tag", .{n}));
- try std.testing.expect(std.mem.endsWith(u8, tag, " PdfSections PdfTint PdfFit Collapse Del"));
+ try std.testing.expect(std.mem.endsWith(u8, tag, " PdfSections PdfTint PdfFit Del "));
for ([_][]const u8{ "full", "disabled", "filtered" }) |want| {
try std.testing.expect(std.mem.indexOf(u8, try s.read(ctl), "fit:width ") != null);
try s.write(ctl, "PdfTint\n");
diff --git a/test/behaviour/placement.zig b/test/behaviour/placement.zig
index 467afd1b..c0bf6305 100644
--- a/test/behaviour/placement.zig
+++ b/test/behaviour/placement.zig
@@ -25,9 +25,10 @@ test "placement: an empty active column takes the new pane whole, a look from an
try std.testing.expectEqualStrings(s.at("{d}:{d} {d}:{d}", .{ try s.column(0), first, try s.column(1), made }), try s.columns());
}
-/// The screen row the tag starting `name` is drawn on.
+/// The screen row the tag starting `name` is drawn on: the name, then a
+/// blank before its computed words (Del at least, UX K'3).
fn tagRow(s: *Session, name: []const u8) !usize {
- return (try s.where(s.at("{s} Save", .{name})))[1];
+ return (try s.where(s.at("{s} ", .{name})))[1];
}
test "placement: New and 9P's new take the bottom half of the column's last pane" {
diff --git a/test/behaviour/tags.zig b/test/behaviour/tags.zig
index c8de115b..fcef9fd3 100644
--- a/test/behaviour/tags.zig
+++ b/test/behaviour/tags.zig
@@ -25,10 +25,11 @@ test "tags: s and S in a tag answer for the tag's own text; / still searches the
// A held pane (Keep): its tag as it was before the walk, no `Keep` word (SPEC §6.5).
try s.write(s.at("/pane/{d}/exec", .{try s.focused()}), "Keep\n");
const n = try s.focused();
- try s.replace(s.at("/pane/{d}/tag", .{n}), " Save Del Snarf");
+ // Its own text, after its computed Del (UX K'1).
+ try s.replace(s.at("/pane/{d}/tag", .{n}), "Save Del Snarf");
// The tag's line, its S's selected, then changed: both are the tag's.
try s.keys("::xsS\ncZ\x1b");
- try std.testing.expectEqualStrings("/test.txt Zave Del Znarf", try tag(&s, n));
+ try std.testing.expectEqualStrings("/test.txt Del Zave Del Znarf", try tag(&s, n));
try s.expect(s.at("/pane/{d}/body", .{n}), "Some body\n");
// `/` from the tag is the body's search, as acme's Look from a tag is.
// Its places list the body's match.
@@ -42,10 +43,12 @@ test "tags: ms and md edit a tag's own text, and the text the edit made is read
// A held pane (Keep): its tag as it was before the walk, no `Keep` word (SPEC §6.5).
try s.write(s.at("/pane/{d}/exec", .{try s.focused()}), "Keep\n");
const n = try s.focused();
+ // Its own text after its computed Del (UX K'1), where `:` lands.
+ try s.write(s.at("/pane/{d}/tag", .{n}), "Save Term");
try s.keys("::miwms(");
- try std.testing.expectEqualStrings("/test.txt (Save) Term Collapse Follow Del", try tag(&s, n));
+ try std.testing.expectEqualStrings("/test.txt Del (Save) Term", try tag(&s, n));
try s.keys("md(");
- try std.testing.expectEqualStrings("/test.txt Save Term Collapse Follow Del", try tag(&s, n));
+ try std.testing.expectEqualStrings("/test.txt Del Save Term", try tag(&s, n));
}
test "tags: the keyboard reaches a tag's path, which it can select and yank but not edit" {
@@ -70,27 +73,29 @@ test "tags: the keyboard reaches a tag's path, which it can select and yank but
try s.expect(s.at("/pane/{d}/name", .{n}), "/test.txt\n");
// After the path, the text is the tag's own to edit.
try s.keys("::A!\x1b");
- try std.testing.expectEqualStrings("/test.txt Save Term Collapse Follow Del!", try tag(&s, n));
+ try std.testing.expectEqualStrings("/test.txt Del !", try tag(&s, n));
// What it yanked was the path.
try s.keys(":P");
try s.expect(s.at("/pane/{d}/body", .{n}), "/test.txtbody\n");
}
-test "tags: a tag remembers its cursor, starts on Save, and a click moves it" {
+test "tags: a tag remembers its cursor, starts on its own text, and a click moves it" {
var s = try Session.initFile(std.testing.allocator, "body\n");
defer s.deinit();
// A held pane (Keep): its tag as it was before the walk, no `Keep` word (SPEC §6.5).
try s.write(s.at("/pane/{d}/exec", .{try s.focused()}), "Keep\n");
const first = try s.focused();
+ // Its own text, after its computed Del (UX K'1).
+ try s.write(s.at("/pane/{d}/tag", .{first}), "Save Term");
try s.write("/ctl", "Newcol\n");
const second = try s.newPane();
try s.write(s.at("/pane/{d}/name", .{second}), "/second.txt");
const focus = s.at("{d}", .{first});
const other = s.at("{d}", .{second});
try s.write("/focus", focus);
- // Nothing to remember yet: `:` lands on Save.
+ // Nothing to remember yet: `:` lands on its own text.
try s.keys("::");
- try std.testing.expectEqual(@as(usize, "/test.txt ".len), try tagCol(&s, "/test.txt"));
+ try std.testing.expectEqual(@as(usize, "/test.txt Del ".len), try tagCol(&s, "/test.txt"));
// Home is the line's start, the path's: the keyboard reaches it.
try s.keys(home ++ right ++ right ++ right);
try std.testing.expectEqual(@as(usize, 3), try tagCol(&s, "/test.txt"));
@@ -110,11 +115,11 @@ test "tags: a tag remembers its cursor, starts on Save, and a click moves it" {
// A click in the tag puts its cursor there, the pane's keyboard with it.
try s.click("Save Term", 6, 1);
try std.testing.expectEqual(first, try s.focused());
- try std.testing.expectEqual(@as(usize, "/test.txt Save T".len), try tagCol(&s, "/test.txt"));
+ try std.testing.expectEqual(@as(usize, "/test.txt Del Save T".len), try tagCol(&s, "/test.txt"));
// A prompt opened and left from the body leaves it there (a clicked
// tag is in normal mode: `:` goes back to the body).
try s.keys(":/\x1b::");
- try std.testing.expectEqual(@as(usize, "/test.txt Save T".len), try tagCol(&s, "/test.txt"));
+ try std.testing.expectEqual(@as(usize, "/test.txt Del Save T".len), try tagCol(&s, "/test.txt"));
try s.keys(":");
try s.expect(s.at("/pane/{d}/body", .{first}), "body\n");
}
@@ -125,16 +130,19 @@ test "tags: executing a word from the tag runs it and gives the keyboard back to
defer s.deinit();
const n = try s.focused();
try s.keys("ix\x1b");
- // `:` lands on Save; the execute key runs it, the look key looks
- // it up. Either way the tag lets go of the keyboard first.
+ // Save typed into the tag's own text, where `:` lands (UX K'1);
+ // the execute key runs it, the look key looks it up. Either way
+ // the tag lets go of the keyboard first.
+ try s.write(s.at("/pane/{d}/tag", .{n}), "Save");
try s.keys("::");
try s.keys(chord);
try std.testing.expectEqual(@as(usize, if (chord[0] == '\t') 1 else 0), s.saved);
try s.keys("iQ\x1b");
try s.expect(s.at("/pane/{d}/body", .{n}), "xQbody\n");
- // ...and the tag still knows where it was.
+ // ...and the tag still knows where it was: on that Save, after the
+ // computed words the save changed.
try s.keys("::");
- try std.testing.expectEqual(@as(usize, "/test.txt ".len), try tagCol(&s, "/test.txt"));
+ try std.testing.expectEqual((try tag(&s, n)).len - "Save".len, try tagCol(&s, "/test.txt"));
}
}
@@ -144,15 +152,15 @@ test "tags: a renamed path moves the tag's cursor with the text after it and a s
// A held pane (Keep): its tag as it was before the walk, no `Keep` word (SPEC §6.5).
try s.write(s.at("/pane/{d}/exec", .{try s.focused()}), "Keep\n");
const n = try s.focused();
- try s.keys(":::"); // `::` on Save, and `:` back
+ try s.keys(":::"); // `::` on its own text, after Del, and `:` back
try s.write(s.at("/pane/{d}/name", .{n}), "/界.zig");
try s.keys("::");
- try std.testing.expectEqual(@as(usize, "/界.zig ".len - 1), try tagCol(&s, "/界"));
+ try std.testing.expectEqual(@as(usize, "/界.zig Del ".len - 1), try tagCol(&s, "/界"));
try s.keys(":");
try s.replace(s.at("/pane/{d}/tag", .{n}), "é");
try s.keys("::");
- // `/界.zig é`: the cursor is pulled back onto the last character.
- try std.testing.expectEqual(@as(usize, "/界.zig ".len - 1), try tagCol(&s, "/界"));
+ // `/界.zig Del é`: the cursor is pulled back onto the last character.
+ try std.testing.expectEqual(@as(usize, "/界.zig Del ".len - 1), try tagCol(&s, "/界"));
try s.expect(s.at("/pane/{d}/body", .{n}), "body\n");
}
@@ -192,7 +200,7 @@ test "tags: a tag's normal mode is the body's: motions stay in the tag and inser
try s.keys(window ++ "h\n");
try std.testing.expectEqual(first, try s.focused());
try s.keys("::i\u{F018}hjklHJKL:");
- try std.testing.expectEqualStrings("/test.txt Save Term Collapse Follow DelhjklHJKL:", try tag(&s, first));
+ try std.testing.expectEqualStrings("/test.txt Del hjklHJKL:", try tag(&s, first));
try std.testing.expect(std.mem.endsWith(u8, try s.read(s.at("/pane/{d}/ctl", .{first})), " mode:normal "));
try s.expect(s.at("/pane/{d}/body", .{first}), "body\n");
try std.testing.expectEqual(first, try s.focused());
@@ -206,7 +214,7 @@ test "tags: a tag with a newline in it is as tall as its lines, and each line is
const n = try s.focused();
// Insert mode in a tag is a body's: Enter is a new line.
try s.keys("::A\nSecond");
- try std.testing.expectEqualStrings("/test.txt Save Term Collapse Follow Del\nSecond", try tag(&s, n));
+ try std.testing.expectEqualStrings("/test.txt Del \nSecond", try tag(&s, n));
const x, const y = try s.where("/test.txt");
try std.testing.expectEqual(.{ x, y + 1 }, try s.where("Second"));
// The caret is on the second line, after what was typed.
@@ -220,7 +228,7 @@ test "tags: a tag with a newline in it is as tall as its lines, and each line is
try std.testing.expectEqual(.{ x + 2, y + 1 }, (try s.cursor()).?);
// A clicked tag is in normal mode: `i` types where it was clicked.
try s.keys("iX");
- try std.testing.expectEqualStrings("/test.txt Save Term Collapse Follow Del\nSeXcond", try tag(&s, n));
+ try std.testing.expectEqualStrings("/test.txt Del \nSeXcond", try tag(&s, n));
try s.expect(s.at("/pane/{d}/body", .{n}), "body\n");
}
@@ -247,12 +255,13 @@ test "tags: a tag with more lines than rows scrolls to keep its caret in view" {
try s.keys("\x1bgg");
try std.testing.expectEqual(.{ x, y }, try s.where("/test.txt"));
try std.testing.expectEqual(y, (try s.cursor()).?[1]);
- // A column tag is one row, as acme's: its lines are joined.
+ // A column tag is one row, as acme's: its lines are joined. Its user's
+ // text brings the column row (UX K'2): the pane one row lower, no more.
var layout = std.mem.tokenizeScalar(u8, try s.read("/layout"), ' ');
const col_tag = s.at("/col/{s}/tag", .{layout.next().?});
try s.replace(col_tag, "New\nC1\nC2");
try std.testing.expect(std.mem.indexOfScalar(u8, try s.read(col_tag), '\n') == null);
- try std.testing.expectEqual(y, (try s.where("/test.txt"))[1]);
+ try std.testing.expectEqual(y + 1, (try s.where("/test.txt"))[1]);
}
test "tags: a long pane tag wraps onto rows, and a click on a wrapped row maps to the whole tag's address" {
@@ -310,20 +319,20 @@ test "tags: a name drafted in the tag commits with Enter, cancels with two Escs,
try s.write(s.at("/pane/{d}/exec", .{try s.focused()}), "Keep\n");
const n = try s.focused();
const name = s.at("/pane/{d}/name", .{n});
- try s.write(s.at("/pane/{d}/tag", .{n}), " JumpTrail");
+ try s.write(s.at("/pane/{d}/tag", .{n}), "JumpTrail");
for ([_]bool{ false, true }) |commit| {
const path = std.mem.trimEnd(u8, try s.read(name), "\n");
try clickPathEnd(&s, path);
try s.keys("\x15/new name.zig");
try s.expect(name, s.at("{s}\n", .{path}));
- _ = try s.where("/new name.zig Save Term Collapse Follow Del JumpTrail");
+ _ = try s.where("/new name.zig Del JumpTrail");
try s.expect(s.at("/pane/{d}/body", .{n}), "original body\n");
// Esc keeps the draft pending; a second drops it.
try s.keys(if (commit) "\n" else "\x1b\x1b");
try s.expect(name, if (commit) "/new name.zig\n" else "/test.txt\n");
- try std.testing.expectEqualStrings(s.at("{s} Save Term Collapse Follow Del JumpTrail", .{if (commit) "/new name.zig" else "/test.txt"}), try tag(&s, n));
+ try std.testing.expectEqualStrings(s.at("{s} Del JumpTrail", .{if (commit) "/new name.zig" else "/test.txt"}), try tag(&s, n));
// The keyboard is the body's again.
- try std.testing.expect((try s.cursor()).?[1] != (try s.where("Save Term"))[1]);
+ try std.testing.expect((try s.cursor()).?[1] != (try s.where("Del JumpTrail"))[1]);
}
try std.testing.expectEqual(@as(usize, 0), s.saved);
// A name alone is no edit: the pane stays clean.
@@ -338,9 +347,9 @@ test "tags: a drafted name's edits are by grapheme, and an empty one is not comm
const n = try s.focused();
try clickPathEnd(&s, "/test.txt");
try s.keys("\x15/café界\x08");
- _ = try s.where("/café Save");
+ _ = try s.where("/café Del");
try s.keys("\x08");
- _ = try s.where("/caf Save");
+ _ = try s.where("/caf Del");
// (The tag, not the screen: the notice row says where the caret is.)
const tagfile = s.at("/pane/{d}/tag", .{n});
try s.keys("\x15\n");
@@ -374,11 +383,13 @@ test "tags: middle clicking Save commits the drafted name before saving" {
// A held pane (Keep): its tag as it was before the walk, no `Keep` word (SPEC §6.5).
try s.write(s.at("/pane/{d}/exec", .{try s.focused()}), "Keep\n");
const n = try s.focused();
+ // Save typed into its own text: a clean file's tag has no Save (UX K'3).
+ try s.write(s.at("/pane/{d}/tag", .{n}), "Save");
try clickPathEnd(&s, "/test.txt");
try s.keys("\x15/renamed.txt");
- try s.click("Save Term", 0, 2);
+ try s.click("Del Save", "Del ".len, 2);
try s.expect(s.at("/pane/{d}/name", .{n}), "/renamed.txt\n");
- try std.testing.expectEqualStrings("/renamed.txt Save Term Collapse Follow Del", try tag(&s, n));
+ try std.testing.expectEqualStrings("/renamed.txt Del Save", try tag(&s, n));
try s.expect(s.at("/pane/{d}/body", .{n}), "untouched\n");
try std.testing.expectEqual(@as(usize, 1), s.saved);
}
@@ -415,6 +426,8 @@ test "tags: a click on a tag puts its cursor there in normal mode: a letter is a
var s = try Session.initFile(std.testing.allocator, "body\n");
defer s.deinit();
const n = try s.focused();
+ // Its own text, after its computed words (UX K'1).
+ try s.write(s.at("/pane/{d}/tag", .{n}), "Save Term");
const was = try tag(&s, n);
try s.click("Save", 0, 1);
// `w` moves to the next word, as in a body's normal mode: nothing typed.
@@ -459,16 +472,16 @@ test "tags: truncating a tag clears its own text, u in the tag undoes it, and >
try s.truncate(h);
try std.testing.expect(std.mem.indexOf(u8, try tag(&s, n), "Mine") == null);
s.clunk(h);
- try std.testing.expectEqualStrings("/test.txt", std.mem.trimEnd(u8, try tag(&s, n), " "));
+ try std.testing.expectEqualStrings("/test.txt Del", std.mem.trimEnd(u8, try tag(&s, n), " "));
// The tag keeps its undo: undoing in it brings back what was cleared.
try s.keys("::u:");
try std.testing.expect(std.mem.endsWith(u8, try tag(&s, n), " Mine"));
// Written back without a leading space, the text still stands apart
- // from the path, and a click on its first letter lands on it.
+ // from the computed words, and a click on its first letter lands on it.
try s.replace(path, "Get");
- try std.testing.expectEqualStrings("/test.txt Get", try tag(&s, n));
+ try std.testing.expectEqualStrings("/test.txt Del Get", try tag(&s, n));
try s.click("Get", 0, 1);
- try std.testing.expectEqual(@as(usize, "/test.txt ".len), try tagCol(&s, "/test.txt"));
+ try std.testing.expectEqual(@as(usize, "/test.txt Del ".len), try tagCol(&s, "/test.txt"));
// `echo Make > tag`: the newline ending the truncating write's text is
// dropped, one only; a newline between its writes stays.
const m = try s.hold(path, 1);
@@ -476,10 +489,10 @@ test "tags: truncating a tag clears its own text, u in the tag undoes it, and >
_ = try s.writeFid(m, "Make\n");
_ = try s.writeFid(m, "More\n\n");
s.clunk(m);
- try std.testing.expectEqualStrings("/test.txt Make\nMore\n", try tag(&s, n));
+ try std.testing.expectEqualStrings("/test.txt Del Make\nMore\n", try tag(&s, n));
// `>>` keeps what it is given.
try s.write(path, " Tail\n");
- try std.testing.expectEqualStrings("/test.txt Make\nMore\n Tail\n", try tag(&s, n));
+ try std.testing.expectEqualStrings("/test.txt Del Make\nMore\n Tail\n", try tag(&s, n));
}
test "tags: a pane tag's file name is tinted, its directory, dirty marker and words not" {
diff --git a/test/behaviour/terminals.zig b/test/behaviour/terminals.zig
index f6bbdfa0..a2f7e951 100644
--- a/test/behaviour/terminals.zig
+++ b/test/behaviour/terminals.zig
@@ -13,7 +13,11 @@ test "terminals: Togglettymode and Ctrl-B share the mode's transitions, from the
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);
+ // Mode is a word of its kind's, not its tag's (UX K'3): the tag is
+ // Del, then its own text, Term.
+ const tag = try s.read(s.at("/pane/{d}/tag", .{n}));
+ try std.testing.expect(std.mem.indexOf(u8, tag, " Mode ") == null);
+ try std.testing.expect(std.mem.indexOf(u8, tag, " Del Term") != 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");