diff options
Diffstat (limited to 'test/behaviour/terminals.zig')
| -rw-r--r-- | test/behaviour/terminals.zig | 46 |
1 files changed, 46 insertions, 0 deletions
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"); +} |
