diff options
| -rw-r--r-- | src/ninep/ctl.zig | 64 | ||||
| -rw-r--r-- | test/behaviour/columns_and_tags.zig | 23 | ||||
| -rw-r--r-- | test/behaviour/look_and_exec.zig | 36 |
3 files changed, 59 insertions, 64 deletions
diff --git a/src/ninep/ctl.zig b/src/ninep/ctl.zig index 7441afeb..bd460098 100644 --- a/src/ninep/ctl.zig +++ b/src/ninep/ctl.zig @@ -2192,29 +2192,6 @@ test "a look line's trailing colon is dropped, and a look whose address fails ne } -test "look and exec read back what the last command touched, a ctl write's too" { - const gpa = testing.allocator; - const p = try withFile(gpa, "x\n"); - defer p.deinit(); - const serial = serialOf(p); - var want: [32]u8 = undefined; - _ = wr(p, root_exec, "Msg first\n"); - try testing.expectEqualStrings(try std.fmt.bufPrint(&want, "{d}\n", .{serial}), rd(p, root_exec, 0, 64).bytes); - // A pane made through ctl is what both read next, not the Msg's pane. - try testing.expectEqual(tree.Status.ok, wr(p, Node.of(serial, .ctl), "Tty\n").reply.status); - const made = p.panes[p.active].?.serial; - try testing.expect(made != serial); - try testing.expectEqualStrings(try std.fmt.bufPrint(&want, "{d}\n", .{made}), rd(p, root_exec, 0, 64).bytes); - try testing.expectEqualStrings(try std.fmt.bufPrint(&want, "{d}\n", .{made}), rd(p, @backingInt(tree.TopFile.look), 0, 64).bytes); - // A ctl write that makes nothing names the pane it ran at. - try testing.expectEqual(tree.Status.ok, wr(p, @backingInt(tree.TopFile.ctl), "Verbose off\n").reply.status); - try testing.expectEqualStrings(try std.fmt.bufPrint(&want, "{d}\n", .{made}), rd(p, root_exec, 0, 64).bytes); - // Closed, it is no pane to go to: a fresh read of look is empty. - try testing.expectEqual(tree.Status.ok, wr(p, Node.of(made, .ctl), "Del\n").reply.status); - try testing.expect(p.paneBySerial(made) == null); - try testing.expectEqualStrings("", rd(p, @backingInt(tree.TopFile.look), 0, 64).bytes); -} - test "a builtin's Verbose announcement is logged only when it succeeds, its failure said now or by the host later" { const gpa = testing.allocator; const p = try withFile(gpa, "x\n"); @@ -3158,24 +3135,6 @@ test "a Restore of a name in the DumpDir asks for, and logs, the whole path it r try testing.expectEqualStrings(try std.fmt.bufPrint(&want, "{s}/x.dump.zon", .{dir}), p.restore_req.?); } -test "a line starting with # runs as nothing at an exec or a ctl, silently" { - const p = try withFile(testing.allocator, "x\n"); - defer p.deinit(); - const serial = serialOf(p); - // The setup's own announcements are made by the first write's update. - _ = wr(p, @backingInt(tree.TopFile.ctl), "# settle\n"); - const before = p.next_serial; - const log_before = try pardes.ctlfs.events.freezeLog(p); - defer p.gpa.free(log_before.bytes); - for ([_]u64{ @backingInt(tree.TopFile.exec), Node.of(serial, .exec), @backingInt(tree.TopFile.ctl), Node.of(serial, .ctl), Node.ofCol(layout.columnSerial(p, 0), .ctl) }) |node| { - try testing.expectEqual(Status.ok, wr(p, node, "# Platform: tty\n # indented too\n").reply.status); - } - try testing.expectEqual(before, p.next_serial); - const log_after = try pardes.ctlfs.events.freezeLog(p); - defer p.gpa.free(log_after.bytes); - try testing.expectEqualStrings(log_before.bytes, log_after.bytes); -} - test "a builtin that takes no argument, written with one to an exec, is refused wrong #args, as at a ctl" { const p = try withFile(testing.allocator, "x\n"); @@ -4165,29 +4124,6 @@ test "@p<terminal>:<address> takes any address over the terminal's lines, select try testing.expectEqualStrings("", rd(p, root, 0, 64).bytes); } -test "a refused Delcol changes nothing: no pane, no focus" { - const p = try withFile(testing.allocator, "x\n"); - defer p.deinit(); - _ = wr(p, @backingInt(tree.TopFile.ctl), "Newcol\n"); - const made = try th.newPane(p); - _ = wr(p, Node.of(made, .name), "/tmp/pardes-delcol-refused.txt\n"); - _ = wr(p, Node.of(made, .body), "edit\n"); - p.sync(); - const col = layout.findPane(p, p.paneBySerial(made).?).?.col; - const active = p.active; - const active_column = p.active_column; - var count: usize = 0; - for (p.panes) |slot| count += @intFromBool(slot != null); - try testing.expectEqual(Status.err, wr(p, Node.ofCol(layout.columnSerial(p, col), .ctl), "Delcol\n").reply.status); - p.sync(); - var after: usize = 0; - for (p.panes) |slot| after += @intFromBool(slot != null); - try testing.expectEqual(count, after); - try testing.expectEqual(active, p.active); - try testing.expectEqual(active_column, p.active_column); - try testing.expect(th.logHas(p, "unsaved ")); -} - test "what a /pager open writes after its directory is the text: plain in the body, its colours the pane's, clean, in by the read" { const p = try withFile(testing.allocator, "x\n"); defer p.deinit(); diff --git a/test/behaviour/columns_and_tags.zig b/test/behaviour/columns_and_tags.zig index 71cff4b2..fa3baf48 100644 --- a/test/behaviour/columns_and_tags.zig +++ b/test/behaviour/columns_and_tags.zig @@ -42,3 +42,26 @@ test "columns-and-tags: a tag write refuses NUL and the other control characters try std.testing.expectEqual(@as(u16, 22), try s.refused(tag, " \x7f")); } } + +test "columns-and-tags: a refused Delcol changes nothing: no pane, no focus" { + var s = try Session.initFile(std.testing.allocator, "x\n"); + defer s.deinit(); + try s.write("/ctl", "Newcol\n"); + const made = try s.newPane(); + try s.write(s.at("/pane/{d}/name", .{made}), "/tmp/pardes-delcol-refused.txt\n"); + try s.write(s.at("/pane/{d}/body", .{made}), "edit\n"); + // Its column, /index's last field. + const col = col: { + var rows = std.mem.tokenizeScalar(u8, try s.read("/index"), '\n'); + while (rows.next()) |row| if (std.mem.startsWith(u8, row, s.at("{d} ", .{made}))) break :col row[std.mem.lastIndexOfScalar(u8, row, ' ').? + 1 ..]; + return error.NotListed; + }; + const index = try s.read("/index"); + const layout = try s.read("/layout"); + const focus = try s.read("/focus"); + try std.testing.expect(try s.refused(s.at("/col/{s}/ctl", .{col}), "Delcol\n") != 0); + try s.expect("/index", index); + try s.expect("/layout", layout); + try s.expect("/focus", focus); + try std.testing.expect(std.mem.indexOf(u8, try s.read("/log"), "unsaved ") != null); +} diff --git a/test/behaviour/look_and_exec.zig b/test/behaviour/look_and_exec.zig index f9b49ae0..f3b94a3f 100644 --- a/test/behaviour/look_and_exec.zig +++ b/test/behaviour/look_and_exec.zig @@ -125,3 +125,39 @@ test "look-and-exec: exec runs a builtin at the pane, and look and exec read bac try std.testing.expect(try listed(&s, n) and !try listed(&s, made)); try s.expect("/exec", s.at("{d}\n", .{made})); } + +test "look-and-exec: look and exec read back what the last command touched, a ctl write's too" { + var s = try Session.initFile(std.testing.allocator, "x\n"); + defer s.deinit(); + const n = try s.focused(); + try s.write("/exec", "Msg first\n"); + try s.expect("/exec", s.at("{d}\n", .{n})); + // A pane made through ctl is what both read next, not the Msg's pane. + try s.write(s.at("/pane/{d}/ctl", .{n}), "Tty\n"); + const made = try s.focused(); + try std.testing.expect(made != n); + try s.expect("/exec", s.at("{d}\n", .{made})); + try s.expect("/look", s.at("{d}\n", .{made})); + // A ctl write that makes nothing names the pane it ran at. + try s.write("/ctl", "Verbose off\n"); + try s.expect("/exec", s.at("{d}\n", .{made})); + // Closed, it is no pane to go to: a fresh read of look is empty. + try s.write(s.at("/pane/{d}/ctl", .{made}), "Del\n"); + try std.testing.expect(!try listed(&s, made)); + try s.expect("/look", ""); +} + +test "look-and-exec: a line starting with # runs as nothing at an exec or a ctl, silently" { + var s = try Session.initFile(std.testing.allocator, "x\n"); + defer s.deinit(); + const n = try s.focused(); + // The setup's own announcements are made by the first write. + try s.write("/ctl", "# settle\n"); + const index = try s.read("/index"); + const log = try s.read("/log"); + const col = std.mem.sliceTo(try s.read("/layout"), ' '); + for ([_][]const u8{ "/exec", s.at("/pane/{d}/exec", .{n}), "/ctl", s.at("/pane/{d}/ctl", .{n}), s.at("/col/{s}/ctl", .{col}) }) |path| + try s.write(path, "# Platform: tty\n # indented too\n"); + try s.expect("/index", index); + try s.expect("/log", log); +} |
