summaryrefslogtreecommitdiff
path: root/test/behaviour
diff options
context:
space:
mode:
Diffstat (limited to 'test/behaviour')
-rw-r--r--test/behaviour/edit.zig21
-rw-r--r--test/behaviour/other_files.zig23
-rw-r--r--test/behaviour/panes.zig40
3 files changed, 84 insertions, 0 deletions
diff --git a/test/behaviour/edit.zig b/test/behaviour/edit.zig
new file mode 100644
index 00000000..e95471c6
--- /dev/null
+++ b/test/behaviour/edit.zig
@@ -0,0 +1,21 @@
+//! docs/typ/reference.typ, Edit <edit>.
+const std = @import("std");
+const Session = @import("session").Session;
+
+test "edit: a write of an Edit block carries it whole, to a pane's ctl, the root's ctl and exec" {
+ var s = try Session.initFile(std.testing.allocator, "foo x\nfoo y\n");
+ defer s.deinit();
+ const n = try s.focused();
+ const body = s.at("/pane/{d}/body", .{n});
+ try s.write(s.at("/pane/{d}/ctl", .{n}), "Edit ,x/foo/{\ni/[/\na/]/\n}\n");
+ try s.expect(body, "[foo] x\n[foo] y\n");
+ try s.write("/ctl", "Edit ,x/\\[/{\nc/</\n}\n");
+ try s.expect(body, "<foo] x\n<foo] y\n");
+ try s.write(s.at("/pane/{d}/exec", .{n}), "Edit $a\nend\n.\n");
+ try s.expect(body, "<foo] x\n<foo] y\nend\n");
+ // A group still open when its open closes fails there, an err in the
+ // log, and nothing after it runs as a line.
+ try s.write(s.at("/pane/{d}/ctl", .{n}), "Edit ,x/foo/{\nd\n");
+ try s.expect(body, "<foo] x\n<foo] y\nend\n");
+ try std.testing.expect(std.mem.indexOf(u8, try s.read("/log"), "unmatched") != null);
+}
diff --git a/test/behaviour/other_files.zig b/test/behaviour/other_files.zig
new file mode 100644
index 00000000..b97affc4
--- /dev/null
+++ b/test/behaviour/other_files.zig
@@ -0,0 +1,23 @@
+//! docs/typ/reference.typ, Other files <other-files>.
+const std = @import("std");
+const Session = @import("session").Session;
+
+test "other-files: kbdin types at the pane with the keyboard and mousein clicks, each done before its write is answered" {
+ var s = try Session.initFile(std.testing.allocator, "x\n");
+ defer s.deinit();
+ const body = try std.fmt.allocPrint(s.arena.allocator(), "/pane/{d}/body", .{try s.focused()});
+ try s.keys("ihello \x1b");
+ try s.expect(body, "hello x\n");
+ // Plan 9's Khome rune, then text before it.
+ try s.keys("A!\x1b\u{F00D}i>\x1b");
+ try s.expect(body, ">hello x!\n");
+ // A left click on the second l, then text there.
+ try s.click(">hello", 4, 1);
+ try s.keys("i#\x1b");
+ try s.expect(body, ">hel#lo x!\n");
+ // Refused, in words, as rio and devmouse refuse.
+ try std.testing.expectEqual(@as(u16, 22), try s.refused("/mousein", "m 1 2\n"));
+ try std.testing.expectEqual(@as(u16, 22), try s.refused("/mousein", "x 1 2 0\n"));
+ try std.testing.expectEqual(@as(u16, 22), try s.refused("/kbdin", "\xff"));
+ try std.testing.expectError(error.Refused, s.read("/kbdin"));
+}
diff --git a/test/behaviour/panes.zig b/test/behaviour/panes.zig
new file mode 100644
index 00000000..45b7152c
--- /dev/null
+++ b/test/behaviour/panes.zig
@@ -0,0 +1,40 @@
+//! docs/typ/reference.typ, Panes <panes>.
+const std = @import("std");
+const Session = @import("session").Session;
+
+test "panes: a collapsed pane's ctl says so" {
+ var s = try Session.initFile(std.testing.allocator, "x\n");
+ defer s.deinit();
+ const first = try s.focused();
+ _ = try s.newPane();
+ try s.write(s.at("/pane/{d}/ctl", .{first}), "Collapse\n");
+ try std.testing.expect(std.mem.endsWith(u8, try s.read(s.at("/pane/{d}/ctl", .{first})), " collapsed "));
+}
+
+test "panes: the ctl word name refuses a leading blank, as the name file does" {
+ var s = try Session.initFile(std.testing.allocator, "x\n");
+ defer s.deinit();
+ const ctl = s.at("/pane/{d}/ctl", .{try s.focused()});
+ try std.testing.expectEqual(@as(u16, 22), try s.refused(ctl, "name /tmp/lead.txt\n"));
+ try std.testing.expectEqualStrings("bad character in file name: a blank at its start", s.said);
+ try s.write(ctl, "name /tmp/ok.txt\n");
+ try s.expect(s.at("/pane/{d}/name", .{try s.focused()}), "/tmp/ok.txt\n");
+}
+
+test "panes: Putall saves every pane with unsaved edits to a file, one each, and leaves the rest" {
+ var tmp = std.testing.tmpDir(.{});
+ defer tmp.cleanup();
+ try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "clean.txt", .data = "clean\n" });
+ var dir_buf: [4096]u8 = undefined;
+ const dir = dir_buf[0..try tmp.dir.realPath(std.testing.io, &dir_buf)];
+ var s = try Session.initFile(std.testing.allocator, "x\n");
+ defer s.deinit();
+ const first = try s.focused();
+ try s.write(s.at("/pane/{d}/name", .{first}), "/tmp/pardes-putall-a.txt\n");
+ try s.write(s.at("/pane/{d}/body", .{first}), "edited\n");
+ // A file opened from disk, unedited.
+ try s.write(s.at("/pane/{d}/look", .{first}), s.at("{s}/clean.txt\n", .{dir}));
+ try std.testing.expectEqual(@as(usize, 0), s.saved);
+ try s.write("/ctl", "Putall\n");
+ try std.testing.expectEqual(@as(usize, 1), s.saved);
+}