summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-03 17:09:53 -0300
committerGabriel Schneider <[email protected]>2026-11-03 17:17:31 -0300
commit5cc02232d522d5cd5a453caedd1e592ca20471ea (patch)
tree034d370ad6eed53abb27f2c7ff607f8e656b17c8 /test
parent37408da299e21b8807ccd10545482a709bac88c7 (diff)
downloadpardes-5cc02232d522d5cd5a453caedd1e592ca20471ea.tar.gz
pardes-5cc02232d522d5cd5a453caedd1e592ca20471ea.zip
test: eleven more of src/pardes.zig's tests through the 9P tree alone (test/behaviour/columns_and_tags, modes, tags, panes): a click past a column tag's text typing after it, a newline there a space and a long tag scrolled to its caret, Enter and Tab in a tag running the word under the cursor, Esc alternating two panes of a kind, Esc out of a column or the workspace tag, Shift-Esc out of every mode, a name typed into the tag's path pending past Esc, an unsaved file's tag its name alone, a question ended in the log when its pane closes, focus on a closed pane to the one taking its place; Session's cursor (/screen's); each checked to fail against a break (flatten keeping newlines, the header drawn unscrolled, Enter in a header a Look, Esc in normal mode not running Last, Esc in a header not leaving it, Shift-Esc leaving insert on, the first Esc on a drafted name dropping it, a dirty tag marked ' *', del_side left out of noteRetire's answer, removeColumn's focus to any pane)
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge
Diffstat (limited to 'test')
-rw-r--r--test/behaviour.zig2
-rw-r--r--test/behaviour/columns_and_tags.zig39
-rw-r--r--test/behaviour/modes.zig65
-rw-r--r--test/behaviour/panes.zig63
-rw-r--r--test/behaviour/tags.zig19
-rw-r--r--test/session.zig10
6 files changed, 198 insertions, 0 deletions
diff --git a/test/behaviour.zig b/test/behaviour.zig
index 32138f94..902ef520 100644
--- a/test/behaviour.zig
+++ b/test/behaviour.zig
@@ -6,7 +6,9 @@ test {
_ = @import("behaviour/columns_and_tags.zig");
_ = @import("behaviour/edit.zig");
_ = @import("behaviour/look_and_exec.zig");
+ _ = @import("behaviour/modes.zig");
_ = @import("behaviour/other_files.zig");
_ = @import("behaviour/panes.zig");
_ = @import("behaviour/root_ctl.zig");
+ _ = @import("behaviour/tags.zig");
}
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 "));
+}
diff --git a/test/session.zig b/test/session.zig
index c4ed0db2..f67f3b25 100644
--- a/test/session.zig
+++ b/test/session.zig
@@ -210,6 +210,16 @@ pub const Session = struct {
const col = cols.next() orelse return error.NoColumn;
return std.fmt.parseInt(u32, col[0..std.mem.indexOfScalar(u8, col, ':').?], 10);
}
+
+ /// Where /screen draws the cursor, column and row; null when it draws none.
+ pub fn cursor(s: *Session) !?struct { usize, usize } {
+ const json = try std.json.parseFromSliceLeaky(std.json.Value, s.arena.allocator(), try s.read("/screen"), .{});
+ const c = switch (json.object.get("cursor").?) {
+ .object => |o| o,
+ else => return null,
+ };
+ return .{ @intCast(c.get("x").?.integer), @intCast(c.get("y").?.integer) };
+ }
};
fn refusal(path: []const u8, r: Reply) error{Refused} {