From a0320c49c1288e8e74f18983f18988a024952bb8 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Tue, 3 Nov 2026 16:38:06 -0300 Subject: test: four more of src/ninep/ctl.zig's tests through the 9P tree alone (test/behaviour/look_and_exec, columns_and_tags, root_ctl): a look's leading blanks and exec's trim, a bare :N look from a pane's look, the root's and an event write-back (dot read from the dot file), a look after Newcol (the column read from /layout), size of a detached session (the screen read from /screen); Session's range and detach; each checked to fail against a break (a look's blanks trimmed, size taking a screen too small for its panes) Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge --- test/behaviour/look_and_exec.zig | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 test/behaviour/look_and_exec.zig (limited to 'test/behaviour/look_and_exec.zig') diff --git a/test/behaviour/look_and_exec.zig b/test/behaviour/look_and_exec.zig new file mode 100644 index 00000000..2ff4345b --- /dev/null +++ b/test/behaviour/look_and_exec.zig @@ -0,0 +1,38 @@ +//! docs/typ/reference.typ, look and exec . +const std = @import("std"); +const Session = @import("session").Session; +const expectEqual = std.testing.expectEqual; + +test "look-and-exec: a 9P look keeps its leading blanks, a blank-only look included, and exec still trims" { + var s = try Session.initFile(std.testing.allocator, "a indented\nb\n indented\n \n"); + defer s.deinit(); + const n = try s.focused(); + const dot = s.at("/pane/{d}/dot", .{n}); + try s.write(dot, "0 0"); + // The indented line, not the `indented` after `a `. + try s.write(s.at("/pane/{d}/look", .{n}), " indented\n"); + try expectEqual(.{ @as(u32, 13), @as(u32, 25) }, try s.range(dot)); + // Blanks alone are text to find too. + try s.write(dot, "26 26"); + try s.write(s.at("/pane/{d}/look", .{n}), " \n"); + try expectEqual(.{ @as(u32, 26), @as(u32, 30) }, try s.range(dot)); + // exec's line is still trimmed: ` Msg hi` runs Msg. + try s.write(s.at("/pane/{d}/exec", .{n}), " Msg blanks trimmed\n"); + try std.testing.expect(std.mem.indexOf(u8, try s.read("/log"), "blanks trimmed") != null); +} + +test "look-and-exec: a bare :N or :N:M look addresses the pane itself, from its look, the root's and event write-back" { + var s = try Session.initFile(std.testing.allocator, "alpha\nbeta\ngamma\n"); + defer s.deinit(); + const n = try s.focused(); + const dot = s.at("/pane/{d}/dot", .{n}); + try s.write(s.at("/pane/{d}/look", .{n}), ":2\n"); + try expectEqual(.{ @as(u32, 6), @as(u32, 11) }, try s.range(dot)); + try s.write("/look", ":3\n"); + try expectEqual(.{ @as(u32, 11), @as(u32, 17) }, try s.range(dot)); + try s.write(s.at("/pane/{d}/look", .{n}), ":3:2\n"); + try expectEqual(@as(u32, 12), (try s.range(dot))[0]); + // Written back by an event reader, the same. + try s.write(s.at("/pane/{d}/event", .{n}), "ML0 0 0 2 :1\n"); + try expectEqual(.{ @as(u32, 0), @as(u32, 6) }, try s.range(dot)); +} -- cgit v1.3