diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/ninep/ctl.zig | 577 | ||||
| -rw-r--r-- | src/ninep/pane.zig | 200 |
2 files changed, 0 insertions, 777 deletions
diff --git a/src/ninep/ctl.zig b/src/ninep/ctl.zig index cc300476..bd460098 100644 --- a/src/ninep/ctl.zig +++ b/src/ninep/ctl.zig @@ -1415,22 +1415,6 @@ const root_status = @backingInt(tree.TopFile.status); const root_look = @backingInt(tree.TopFile.look); const root_exec = @backingInt(tree.TopFile.exec); -test "a control character in a write to any ctl refuses the whole write, and a quoted line shows a tab as a blank" { - const p = try withFile(testing.allocator, "x\n"); - defer p.deinit(); - const col = layout.columnSerial(p, 0); - for ([_]u64{ @backingInt(tree.TopFile.ctl), Node.of(serialOf(p), .ctl), Node.ofCol(col, .ctl) }) |node| { - const r = wr(p, node, "Wrap off\nbo\x01gus\n"); - try testing.expectEqual(E.INVAL, r.errno()); - try testing.expectEqualStrings(e_control, r.reply.ename); - } - const quoted = wr(p, Node.of(serialOf(p), .ctl), "bogus\tword\n"); - try testing.expectEqual(E.INVAL, quoted.errno()); - // The offending word alone is quoted: a tab ends it. - try testing.expect(std.mem.indexOf(u8, quoted.reply.ename, "\"bogus\"") != null); - try testing.expect(std.mem.indexOfScalar(u8, quoted.reply.ename, '\t') == null); -} - test "pane ctl read is acme's fields -- index's five, width in cells, font, tab width, undo, redo -- then whether it is current" { const gpa = testing.allocator; const p = try withFile(gpa, "x\n"); @@ -1503,189 +1487,6 @@ test "Undo and Redo on a pane's ctl step its body through its edits" { try testing.expect(th.logHas(p, "Undo: nothing to undo (x4)\n")); } -test "focus reads the pane with the keyboard, and a serial written to it moves the keyboard there" { - const p = try withFile(testing.allocator, "x\n"); - defer p.deinit(); - const first = serialOf(p); - const second = try th.newPane(p); - const focus = @backingInt(tree.TopFile.focus); - var line: [16]u8 = undefined; - try testing.expectEqualStrings(try std.fmt.bufPrint(&line, "{d}\n", .{second}), rd(p, focus, 0, 64).bytes); - try testing.expectEqual(@as(u64, rd(p, focus, 0, 64).bytes.len), call(p, .{ .tag = 1, .op = .getattr, .node = focus }).reply.attr.size); - try testing.expect(std.mem.indexOf(u8, rd(p, Node.of(first, .ctl), 0, 4096).bytes, " notcurrent ") != null); - - // A header has the keyboard: no pane does, and a write takes it back. - tagline.enterHeader(p, null); - try testing.expectEqualStrings("", rd(p, focus, 0, 64).bytes); - try testing.expectEqual(@as(u64, 0), call(p, .{ .tag = 1, .op = .getattr, .node = focus }).reply.attr.size); - try testing.expect(std.mem.indexOf(u8, rd(p, Node.of(second, .ctl), 0, 4096).bytes, " notcurrent ") != null); - try testing.expectEqual(Status.ok, wr(p, focus, try std.fmt.bufPrint(&line, "{d}\n", .{first})).reply.status); - try testing.expect(!p.header_focus); - try testing.expectEqual(p.paneBySerial(first).?, p.active); - try testing.expect(std.mem.indexOf(u8, rd(p, Node.of(first, .ctl), 0, 4096).bytes, " current ") != null); - try testing.expect(std.mem.indexOf(u8, rd(p, Node.of(second, .ctl), 0, 4096).bytes, " notcurrent ") != null); - - try testing.expectEqualStrings(e_no_pane, wr(p, focus, "99999\n").reply.ename); - try testing.expectEqual(E.NOENT, wr(p, focus, "99999").errno()); - for ([_][]const u8{ "", "two", "-1", "1 2" }) |bad| try testing.expectEqual(E.INVAL, wr(p, focus, bad).errno()); - try testing.expectEqual(p.paneBySerial(first).?, p.active); - - // Focus gives the keyboard only: a folded pane stays folded. - const folded = p.paneBySerial(second).?; - layout.toggleCollapse(p, folded); - try testing.expect(p.panes[folded].?.collapsed); - try testing.expectEqual(Status.ok, wr(p, focus, try std.fmt.bufPrint(&line, "{d}", .{second})).reply.status); - try testing.expectEqual(folded, p.active); - try testing.expect(p.panes[folded].?.collapsed); -} - -test "the pane ctl takes acme's verbs and the pane's builtins, and refuses the rest in Plan 9's words" { - const gpa = testing.allocator; - const p = try withFile(gpa, "one\ntwo\n"); - defer p.deinit(); - const serial = serialOf(p); - const ctl_node = Node.of(serial, .ctl); - // A builtin is its own capitalised word: `GET` and `DEL` are none; - // acme's own words are done or refused as acme's (the test below). - for ([_][]const u8{ "lock x", "bogus", "DEL", "GET", "get x", "look /tmp", "exec Del" }) |bad| { - const refused = wr(p, ctl_node, bad); - try testing.expectEqual(E.INVAL, refused.errno()); - var want: [64]u8 = undefined; - try testing.expectEqualStrings(try std.fmt.bufPrint(&want, "unknown control message \"{s}\"", .{firstWord(bad)}), refused.reply.ename); - } - try testing.expectEqualStrings("not a window control message \"Newcol\": write it to /ctl", wr(p, ctl_node, "Newcol").reply.ename); - try testing.expectEqualStrings("not a window control message \"Verbose\": write it to /ctl", wr(p, ctl_node, "Verbose off").reply.ename); - try testing.expectEqualStrings("wrong #args in control message \"Collapse\"", wr(p, ctl_node, "Collapse now").reply.ename); - // Checked whole first: a bad line anywhere and nothing ran. - try testing.expectEqual(E.INVAL, wr(p, ctl_node, "Msg first\nbogus").errno()); - try testing.expect(p.panes[0].?.msg_len == 0 or !std.mem.eql(u8, p.panes[0].?.msg[0..p.panes[0].?.msg_len], "first")); - - // A pane's builtin runs at that pane. - try testing.expectEqual(Status.ok, wr(p, ctl_node, "Msg from ctl\n").reply.status); - const pane = p.panes[p.paneBySerial(serial).?].?; - try testing.expectEqualStrings("from ctl", pane.msg[0..pane.msg_len]); - // One that means nothing bare is refused before anything runs. - try testing.expectEqualStrings("wrong #args in control message \"Find\"", wr(p, ctl_node, "Find").reply.ename); - try testing.expectEqual(E.INVAL, wr(p, ctl_node, "Msg first\nMsg").errno()); - try testing.expect(!std.mem.eql(u8, pane.msg[0..pane.msg_len], "first")); - try testing.expect(pane.prompt == .none); - try testing.expect(!p.fs.no_prompt); - // Save with no name on a scratch would ask for one: refused, not asked. - const other = try th.newPane(p); - try testing.expectEqualStrings(e_prompt ++ " \"Save\"", wr(p, Node.of(other, .ctl), "Save").reply.ename); - try testing.expect(p.panes[p.paneBySerial(other).?].?.prompt == .none); - // A line after the one that closed the pane has nowhere to run. - try testing.expectEqual(E.NOENT, wr(p, Node.of(other, .ctl), "Del\nMsg after").errno()); - try testing.expect(p.paneBySerial(other) == null); -} - -test "the root ctl reads the settings as a write takes them, and takes the session's builtins" { - const gpa = testing.allocator; - const p = try withFile(gpa, "x\n"); - defer p.deinit(); - const root_ctl = @backingInt(tree.TopFile.ctl); - const first = rd(p, root_ctl, 0, 1 << 16); - try testing.expectEqual(Status.ok, first.reply.status); - const settings = try gpa.dupe(u8, first.bytes); - defer gpa.free(settings); - try testing.expectEqual(@as(u64, settings.len), call(p, .{ .tag = 1, .op = .getattr, .node = root_ctl }).reply.attr.size); - try testing.expect(std.mem.indexOf(u8, settings, "Verbose on\n") != null); - try testing.expect(std.mem.indexOf(u8, settings, "LocationsConfig ") != null); - try testing.expect(std.mem.indexOf(u8, settings, "CallstackDepth 8\n") != null); - try testing.expectEqual(Status.ok, wr(p, root_ctl, "CallstackDepth").reply.status); - // Settings only: nothing /status or the DumpConfig window says. - try testing.expect(std.mem.indexOf(u8, settings, "Platform") == null); - try testing.expect(std.mem.indexOf(u8, settings, "requested") == null); - - // Every line written back is taken, and changes nothing. - try testing.expectEqual(Status.ok, wr(p, root_ctl, settings).reply.status); - try testing.expectEqualStrings(settings, rd(p, root_ctl, 0, 1 << 16).bytes); - - try testing.expectEqual(Status.ok, wr(p, root_ctl, "Verbose off\n").reply.status); - try testing.expect(!p.settings.verbose); - try testing.expect(std.mem.indexOf(u8, rd(p, root_ctl, 0, 1 << 16).bytes, "Verbose off\n") != null); - const columns = p.ncol; - try testing.expectEqual(Status.ok, wr(p, root_ctl, "Newcol\n").reply.status); - try testing.expectEqual(columns + 1, p.ncol); - - try testing.expectEqualStrings("not a session control message \"Del\": write it to pane/<n>/ctl", wr(p, root_ctl, "Del").reply.ename); - try testing.expectEqualStrings("unknown control message \"Nonsense\"", wr(p, root_ctl, "Nonsense 1").reply.ename); - try testing.expectEqualStrings("bad value in control message; takes on, off \"maybe\"", wr(p, root_ctl, "Verbose maybe").reply.ename); - try testing.expectEqualStrings("bad value in control message; takes acme, pardes \"east\"", wr(p, root_ctl, "Placement east").reply.ename); - // A number's refusal names its range, a path's what it takes. - try testing.expectEqualStrings("bad value in control message; takes 0-100 (a percentage) \"200\"", wr(p, root_ctl, "InactiveDim 200").reply.ename); - try testing.expectEqualStrings("bad value in control message; takes 0-60000 (milliseconds) \"x\"", wr(p, root_ctl, "MessageLinger x").reply.ename); - for (config.Runtime.settings) |setting| if (setting.action != .theme) - try testing.expect(config.Runtime.takes(setting.action) != null); - const no_theme = wr(p, root_ctl, "Theme no-such-theme").reply.ename; - try testing.expectStringStartsWith(no_theme, "bad value in control message; like it: n"); - try testing.expect(std.mem.endsWith(u8, no_theme, "; Themes lists all \"no-such-theme\"")); - try testing.expectEqualStrings("wrong #args in control message \"Newcol\"", wr(p, root_ctl, "Newcol 2").reply.ename); - try testing.expectEqualStrings("wrong #args in control message \"Theme\"", wr(p, root_ctl, "Theme").reply.ename); - // A bare required word fails the check, so the line before never runs. - try testing.expectEqual(E.INVAL, wr(p, root_ctl, "Verbose on\nMount").errno()); - try testing.expect(!p.settings.verbose); - // A builtin that fails as it runs fails the write, quoting its error and - // its line; the lines before it have taken effect, as in acme. - const failed = wr(p, root_ctl, "Verbose on\nMount x /tmp/pardes-no-such-sock-zz\nVerbose off"); - try testing.expectEqual(E.NOENT, failed.errno()); - try testing.expectStringStartsWith(failed.reply.ename, "Mount x: /tmp/pardes-no-such-sock-zz: no such socket"); - try testing.expect(p.settings.verbose); - try testing.expect(!p.fs.no_prompt); - try testing.expectEqual(Status.ok, wr(p, root_ctl, "Verbose off").reply.status); -} - -test "a second lock is refused until the holder unlocks or closes, and binds nobody else" { - const p = try withFile(testing.allocator, "one\ntwo\n"); - defer p.deinit(); - const serial = serialOf(p); - const ctl_node = Node.of(serial, .ctl); - const w = struct { - fn ctl(pp: *Pardes, node: u64, h: u32, data: []const u8) th.Answer { - return call(pp, .{ .tag = 4, .op = .write, .node = node, .handle = h, .data = data }); - } - }; - const a = call(p, .{ .tag = 1, .op = .open, .node = ctl_node, .omode = 2 }).reply.handle; - const b = call(p, .{ .tag = 2, .op = .open, .node = ctl_node, .omode = 1 }).reply.handle; - try testing.expect(a != 0 and b != 0 and a != b); - // Reading the status line holds nothing, so it cannot lock either. - try testing.expectEqual(@as(u32, 0), call(p, .{ .tag = 3, .op = .open, .node = ctl_node }).reply.handle); - try testing.expectEqual(E.INVAL, wr(p, ctl_node, "lock\n").errno()); - - try testing.expectEqual(Status.ok, w.ctl(p, ctl_node, a, "lock\n").reply.status); - try testing.expectEqual(Status.ok, w.ctl(p, ctl_node, a, "lock\n").reply.status); - // Another open's lock is refused at once, and so is its unlock; writes - // to the pane's other files are not. - try testing.expectEqualStrings(e_locked, w.ctl(p, ctl_node, b, "lock\n").reply.ename); - try testing.expectEqual(E.BUSY, w.ctl(p, ctl_node, b, "lock\n").errno()); - try testing.expectEqualStrings(e_not_locked, w.ctl(p, ctl_node, b, "unlock\n").reply.ename); - try testing.expectEqual(Status.ok, wr(p, Node.of(serial, .addr), "1").reply.status); - try testing.expectEqual(Status.ok, wr(p, Node.of(serial, .data), "ONE\n").reply.status); - try testing.expectEqualStrings("ONE\ntwo\n", p.panes[0].?.file.?.content); - - // Once the holder unlocks, the other's try takes it. - try testing.expectEqual(Status.ok, w.ctl(p, ctl_node, a, "unlock\n").reply.status); - try testing.expectEqual(Status.ok, w.ctl(p, ctl_node, b, "lock\n").reply.status); - try testing.expectEqual(E.BUSY, w.ctl(p, ctl_node, a, "lock\nunlock\n").errno()); - // Closing the holder gives it up. - _ = call(p, .{ .tag = 5, .op = .release, .node = ctl_node, .handle = b }); - try testing.expectEqual(Status.ok, w.ctl(p, ctl_node, a, "lock\nunlock\nlock\n").reply.status); - try testing.expectEqual(E.INVAL, w.ctl(p, ctl_node, a, "unlock\nunlock\n").errno()); - try testing.expectEqual(@as(?u32, a), p.panes[0].?.fs.lock); - - // The lock lives and dies with the pane. - const other = try th.newPane(p); - const other_ctl = Node.of(other, .ctl); - const c = call(p, .{ .tag = 6, .op = .open, .node = other_ctl, .omode = 1 }).reply.handle; - try testing.expectEqual(Status.ok, w.ctl(p, other_ctl, c, "lock\n").reply.status); - try testing.expectEqual(Status.ok, th.rmdir(p, Node.of(other, .dir)).reply.status); - try testing.expectEqual(E.NOENT, w.ctl(p, other_ctl, c, "lock\n").errno()); - for ([_]u64{ ctl_node, other_ctl }, [_]u32{ a, c }) |node, h| - _ = call(p, .{ .tag = 7, .op = .release, .node = node, .handle = h }); - try testing.expect(p.panes[0].?.fs.lock == null); - for (p.fs.opens) |o| try testing.expect(o.node == 0); -} - test "Edit through a pane's ctl renames every foo in one undo step, and a failed one changes nothing" { const p = try withFile(testing.allocator, "foo x foo y foo\n"); defer p.deinit(); @@ -1718,81 +1519,6 @@ test "dirty goes back to 0 when the text is the saved text again" { try testing.expectEqualStrings("1\n", rd(p, dirty, 0, 8).bytes); } -test "a message from a root ctl write is the session's in the log" { - const p = try withFile(testing.allocator, "x\n"); - defer p.deinit(); - p.update(.tick); // the pane's `new` is logged before the log is opened - while (p.nextEffect()) |_| {} - const log = @backingInt(tree.TopFile.log); - const f = call(p, .{ .tag = 1, .op = .open, .node = log }).reply.handle; - const frozen = call(p, .{ .tag = 2, .op = .read, .node = log, .handle = f, .size = 8192 }).bytes.len; - _ = call(p, .{ .tag = 3, .op = .write, .node = log, .handle = f, .data = "follow" }); - try testing.expectEqual(Status.ok, wr(p, @backingInt(tree.TopFile.ctl), "Kill\n").reply.status); - // What it said, the session's; its own words name it, so its Verbose - // announcement gives way to them. - try testing.expectEqualStrings("msg - Kill: nothing running\n", call(p, .{ .tag = 5, .op = .read, .node = log, .handle = f, .off = frozen, .size = 4096 }).bytes); -} - -test "a look takes acme's :addr and file:addr, and a miss changes nothing" { - const gpa = testing.allocator; - const p = try withFile(gpa, "foo x foo y\nbar\n"); - defer p.deinit(); - const serial = serialOf(p); - const look_node = Node.of(serial, .look); - const dot = Node.of(serial, .dot); - // :addr is an address in this pane, evaluated from its dot. - try testing.expectEqual(Status.ok, wr(p, look_node, ":/y/\n").reply.status); - try testing.expectEqualStrings(" 10 11 ", rd(p, dot, 0, 64).bytes); - try testing.expectEqual(Status.ok, wr(p, look_node, ":#4\n").reply.status); - try testing.expectEqualStrings(" 4 4 ", rd(p, dot, 0, 64).bytes); - try testing.expectEqual(Status.ok, wr(p, look_node, ":/foo/\n").reply.status); // from #4: the second foo - try testing.expectEqualStrings(" 6 9 ", rd(p, dot, 0, 64).bytes); - // file:addr names the pane's own file here. - var line: [256]u8 = undefined; - const path = p.panes[0].?.file.?.path; - try testing.expectEqual(Status.ok, wr(p, look_node, try std.fmt.bufPrint(&line, "{s}:/bar/\n", .{path})).reply.status); - try testing.expectEqualStrings(" 12 15 ", rd(p, dot, 0, 64).bytes); - // A miss: no buffer, the selection kept, and it says so. - const panes_before = p.panes.len - std.mem.count(?*pardes.Pane, &p.panes, &.{null}); - try testing.expectEqual(Status.ok, wr(p, look_node, "zzqq\n").reply.status); - try testing.expectEqual(panes_before, p.panes.len - std.mem.count(?*pardes.Pane, &p.panes, &.{null})); - try testing.expectEqualStrings(" 12 15 ", rd(p, dot, 0, 64).bytes); - try testing.expectStringStartsWith(p.panes[0].?.msg[0..p.panes[0].?.msg_len], "Look: no match"); - // A hit answers the pane the text is selected in, not its hits buffer. - try testing.expectEqual(Status.ok, wr(p, look_node, "foo\n").reply.status); - var own: [16]u8 = undefined; - try testing.expectEqualStrings(try std.fmt.bufPrint(&own, "{d}\n", .{serial}), rd(p, look_node, 0, 64).bytes); - // A pattern with a blank in it; 0/re/ searches from the top, whatever dot is. - try testing.expectEqual(Status.ok, wr(p, look_node, ":/foo y/\n").reply.status); - try testing.expectEqualStrings(" 6 11 ", rd(p, dot, 0, 64).bytes); - try testing.expectEqual(Status.ok, wr(p, look_node, try std.fmt.bufPrint(&line, "{s}:0/foo/\n", .{path})).reply.status); - try testing.expectEqualStrings(" 0 3 ", rd(p, dot, 0, 64).bytes); - // file:N selects the line; a line past the end moves nothing and reads back empty. - try testing.expectEqual(Status.ok, wr(p, look_node, try std.fmt.bufPrint(&line, "{s}:2\n", .{path})).reply.status); - try testing.expectEqualStrings(" 12 16 ", rd(p, dot, 0, 64).bytes); - try testing.expectEqual(Status.ok, wr(p, look_node, try std.fmt.bufPrint(&line, "{s}:99\n", .{path})).reply.status); - try testing.expectEqualStrings(" 12 16 ", rd(p, dot, 0, 64).bytes); - try testing.expectEqualStrings("", rd(p, look_node, 0, 64).bytes); - try testing.expectStringStartsWith(p.panes[0].?.msg[0..p.panes[0].?.msg_len], "Look: "); -} - -test "the root look's file:/re/ goes on from the dot, and a miss leaves the dot as it was" { - const gpa = testing.allocator; - const p = try withFile(gpa, "foo x foo y\nfoo\n"); - defer p.deinit(); - const dot = Node.of(serialOf(p), .dot); - const root = @backingInt(tree.TopFile.look); - var line: [256]u8 = undefined; - const path = p.panes[0].?.file.?.path; - const again = try std.fmt.bufPrint(&line, "{s}:/foo/\n", .{path}); - for ([_][]const u8{ " 0 3 ", " 6 9 ", " 12 15 ", " 0 3 " }) |want| { - try testing.expectEqual(Status.ok, wr(p, root, again).reply.status); - try testing.expectEqualStrings(want, rd(p, dot, 0, 64).bytes); - } - try testing.expectEqual(Status.ok, wr(p, root, try std.fmt.bufPrint(&line, "{s}:/zzqq/\n", .{path})).reply.status); - try testing.expectEqualStrings(" 0 3 ", rd(p, dot, 0, 64).bytes); -} - test "a look's miss repeats the path whole up to 256 bytes, then gives up its middle to an ellipsis" { const gpa = testing.allocator; const p = try withFile(gpa, "x\n"); @@ -1807,31 +1533,6 @@ test "a look's miss repeats the path whole up to 256 bytes, then gives up its mi try testing.expect(th.logHas(p, "look: no match for \"" ++ std.mem.asBytes(&@as([63][2]u8, @splat("é".*))) ++ "…" ++ std.mem.asBytes(&@as([63][2]u8, @splat("é".*))) ++ "\"\n")); } -test "exec runs a builtin at the pane and records the pane it acted on" { - const gpa = testing.allocator; - const p = try withFile(gpa, "Msg fs-ran\n"); - defer p.deinit(); - const serial = serialOf(p); - const pane = p.panes[0].?; - try testing.expectEqual(Status.ok, wr(p, Node.of(serial, .exec), "Msg from exec\n").reply.status); - try testing.expectEqualStrings("from exec", pane.msg[0..pane.msg_len]); - var expected: [16]u8 = undefined; - const own = try std.fmt.bufPrint(&expected, "{d}\n", .{serial}); - try testing.expectEqualStrings(own, rd(p, root_exec, 0, 4096).bytes); - // Either command file reads back what the last one did. - try testing.expectEqualStrings(own, rd(p, Node.of(serial, .look), 0, 4096).bytes); - try testing.expectEqual(@as(u64, own.len), call(p, .{ .tag = 1, .op = .getattr, .node = root_exec }).reply.attr.size); - - try testing.expectEqual(Status.ok, wr(p, Node.of(serial, .exec), "New\n").reply.status); - const made = p.panes[p.active].?; - try testing.expect(made.serial != serial); - try testing.expectEqualStrings(try std.fmt.bufPrint(&expected, "{d}\n", .{made.serial}), rd(p, root_exec, 0, 4096).bytes); - - try testing.expectEqual(Status.ok, wr(p, Node.of(made.serial, .exec), "Del\n").reply.status); - try testing.expect(p.paneBySerial(made.serial) == null); - try testing.expectEqualStrings(try std.fmt.bufPrint(&expected, "{d}\n", .{made.serial}), rd(p, root_exec, 0, 4096).bytes); -} - test "status reads the editor, and look and exec validate whole batches" { const gpa = testing.allocator; const p = try withFile(gpa, "Msg root\n"); @@ -2335,20 +2036,6 @@ test "Save path of a file pane logs a save record naming that path" { try testing.expect(th.logHas(p, try std.fmt.bufPrint(&want, "save {d} /tmp/pardes-save-copy.txt\n", .{serial}))); } -test "Mount with no dial is wrong #args, and a dial that is no address says bad dial address" { - if (comptime !pardes.hosted) return; - const p = try withFile(testing.allocator, "x\n"); - defer p.deinit(); - const root_ctl = @backingInt(tree.TopFile.ctl); - const bare = wr(p, root_ctl, "Mount work\n"); - try testing.expectEqual(E.INVAL, bare.errno()); - try testing.expectStringStartsWith(bare.reply.ename, "wrong #args"); - const bad = wr(p, root_ctl, "Mount work tcp!nohost\n"); - try testing.expectEqual(E.INVAL, bad.errno()); - try testing.expectStringStartsWith(bad.reply.ename, "Mount: bad dial address: tcp!nohost"); - try testing.expectEqual(@as(usize, 0), p.fs.mounts.items.len); -} - test "an address looked at in an image pane names the image, never an empty subject" { const p = try withFile(testing.allocator, "x\n"); defer p.deinit(); @@ -2463,17 +2150,6 @@ test "a look at a file it may not read fails the write naming the file" { try testing.expectEqualStrings(expected, refused.reply.ename); } -test "Pager is a setting of the root ctl: pardes by default, off taken, anything else refused with its choices" { - const p = try withFile(testing.allocator, "x\n"); - defer p.deinit(); - const root_ctl = @backingInt(tree.TopFile.ctl); - try testing.expect(std.mem.indexOf(u8, rd(p, root_ctl, 0, 1 << 16).bytes, "Pager pardes\n") != null); - try testing.expectEqual(Status.ok, wr(p, root_ctl, "Pager off\n").reply.status); - try testing.expectEqual(config.Runtime.Pager.off, p.settings.pager); - try testing.expect(std.mem.indexOf(u8, rd(p, root_ctl, 0, 1 << 16).bytes, "Pager off\n") != null); - try testing.expectEqualStrings("bad value in control message; takes pardes, off \"less\"", wr(p, root_ctl, "Pager less\n").reply.ename); -} - test "a bad setting value is quoted, so two different bad values log as two records, never one counted twice" { const p = try withFile(testing.allocator, "x\n"); defer p.deinit(); @@ -2516,85 +2192,6 @@ test "a look line's trailing colon is dropped, and a look whose address fails ne } -test "a refused Del written back through event fails that write, EIO, with its err" { - const gpa = testing.allocator; - const p = try withFile(gpa, "text\n"); - defer p.deinit(); - const serial = serialOf(p); - try testing.expectEqual(Status.ok, wr(p, Node.of(serial, .body), "more\n").reply.status); // unsaved - const event = Node.of(serial, .event); - const h = call(p, .{ .tag = 1, .op = .open, .node = event }).reply.handle; - defer _ = call(p, .{ .tag = 9, .op = .release, .node = event, .handle = h }); - try testing.expectEqual(Status.ok, wr(p, Node.of(serial, .exec), "Del\n").reply.status); - const record = call(p, .{ .tag = 2, .op = .read, .node = event, .handle = h, .size = 256 }).bytes; - var copy: [256]u8 = undefined; - @memcpy(copy[0..record.len], record); - const back = wr(p, event, copy[0..record.len]); - try testing.expectEqual(E.IO, back.errno()); - try testing.expect(std.mem.indexOf(u8, back.reply.ename, "Modified") != null); - try testing.expect(p.paneBySerial(serial) != null); -} - -test "a pane's own look and exec go to the event reader holding it, which writes them back to act" { - const gpa = testing.allocator; - const p = try withFile(gpa, "Msg routed\n"); - defer p.deinit(); - const serial = serialOf(p); - const event = Node.of(serial, .event); - const h = call(p, .{ .tag = 1, .op = .open, .node = event }).reply.handle; - try testing.expectEqual(tree.Status.ok, wr(p, Node.of(serial, .exec), "Msg routed\n").reply.status); - // Not done: the reader has it, as it would a middle click. - const pane = p.panes[0].?; - try testing.expect(std.mem.indexOf(u8, pane.msg[0..pane.msg_len], "routed") == null); - const record = call(p, .{ .tag = 2, .op = .read, .node = event, .handle = h, .size = 256 }).bytes; - // Flag 1: its first word is a builtin; no 2, no expansion follows. - try testing.expectEqualStrings("FX0 0 1 10 Msg routed\n", record); - // Written back, it is done. - try testing.expectEqual(tree.Status.ok, wr(p, event, record).reply.status); - try testing.expect(std.mem.indexOf(u8, pane.msg[0..pane.msg_len], "routed") != null); - try testing.expectEqual(tree.Status.ok, wr(p, Node.of(serial, .look), "one.txt:3\n").reply.status); - try testing.expectEqualStrings("FL0 0 4 9 one.txt:3\n", call(p, .{ .tag = 3, .op = .read, .node = event, .handle = h, .size = 256 }).bytes); - // The root's is a click at the pane with the keyboard, this one. - try testing.expectEqual(tree.Status.ok, wr(p, root_exec, "Msg rooted\n").reply.status); - try testing.expect(std.mem.indexOf(u8, pane.msg[0..pane.msg_len], "rooted") == null); - try testing.expectEqualStrings("FX0 0 1 10 Msg rooted\n", call(p, .{ .tag = 5, .op = .read, .node = event, .handle = h, .size = 256 }).bytes); - // A click in its tag is the reader's too, an `x` record, as acme's is; - // written back, it is done. - try testing.expectEqual(tree.Status.ok, wr(p, Node.of(serial, .tagexec), "Msg tagged\n").reply.status); - try testing.expect(std.mem.indexOf(u8, pane.msg[0..pane.msg_len], "tagged") == null); - const tagged = call(p, .{ .tag = 6, .op = .read, .node = event, .handle = h, .size = 256 }).bytes; - try testing.expectEqualStrings("Fx0 0 1 10 Msg tagged\n", tagged); - try testing.expectEqual(tree.Status.ok, wr(p, event, tagged).reply.status); - try testing.expect(std.mem.indexOf(u8, pane.msg[0..pane.msg_len], "tagged") != null); - _ = call(p, .{ .tag = 4, .op = .release, .node = event, .handle = h }); - // With no reader, the root's and the pane's act at once. - try testing.expectEqual(tree.Status.ok, wr(p, Node.of(serial, .exec), "Msg direct\n").reply.status); - try testing.expect(std.mem.indexOf(u8, pane.msg[0..pane.msg_len], "direct") != null); -} - -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"); @@ -2921,42 +2518,6 @@ test "a setting this frontend cannot show says GUI-only, and DumpDir reads back } } -test "Shell refuses a path that is no executable, and bare it goes back to the default" { - const p = try withFile(testing.allocator, "x\n"); - defer p.deinit(); - const root_ctl = @backingInt(tree.TopFile.ctl); - const refused = wr(p, root_ctl, "Shell /nonexistent/zzsh\n"); - try testing.expectEqual(Status.err, refused.reply.status); - try testing.expect(std.mem.indexOf(u8, refused.reply.ename, "Shell: shell \"/nonexistent/zzsh\" not found") != null); - try testing.expect(th.logHas(p, "shell \"/nonexistent/zzsh\" not found")); - // Its words say a directory, which a mount reads as EISDIR too. - try testing.expectEqual(E.ISDIR, wr(p, root_ctl, "Shell /etc\n").errno()); - try testing.expect(th.logHas(p, "Shell: not a shell: /etc is a directory")); - try testing.expectEqualStrings("", p.settings.shell.requested.get()); - try testing.expectEqual(Status.ok, wr(p, root_ctl, "Shell /bin/sh\n").reply.status); - try testing.expectEqualStrings("/bin/sh", p.settings.shell.requested.get()); - try testing.expectEqual(Status.ok, wr(p, root_ctl, "Shell\n").reply.status); - try testing.expectEqualStrings("", p.settings.shell.requested.get()); - try testing.expect(th.logHas(p, "Shell: the default again, ")); - var want: [300]u8 = undefined; - try testing.expect(std.mem.indexOf(u8, rd(p, root_ctl, 0, 8192).bytes, try std.fmt.bufPrint(&want, "Shell {s}\n", .{config.defaultShell()})) != null); -} - -test "a builtin that fails a ctl write logs only its err, so the same failure again is counted" { - const p = try withFile(testing.allocator, "x\n"); - defer p.deinit(); - p.update(.tick); // the pane's `new` is logged first - while (p.nextEffect()) |_| {} - const ctl_node = @backingInt(tree.TopFile.ctl); - for (0..3) |_| try testing.expectEqual(Status.err, wr(p, ctl_node, "Unmount zzz\n").reply.status); - const log = @backingInt(tree.TopFile.log); - const h = call(p, .{ .tag = 1, .op = .open, .node = log }).reply.handle; - const text = call(p, .{ .tag = 2, .op = .read, .node = log, .handle = h, .size = 1 << 16 }).bytes; - try testing.expect(std.mem.endsWith(u8, text, "err - ctl: Unmount: no such mount zzz (x3)\n")); - try testing.expect(std.mem.indexOf(u8, text, "msg - Unmount") == null); - _ = call(p, .{ .tag = 3, .op = .release, .node = log, .handle = h }); -} - test "an exec line over the command limit fails the write and says the limit; a builtin's may be longer" { const p = try withFile(testing.allocator, "x\n"); defer p.deinit(); @@ -3011,17 +2572,6 @@ test "Mount dials its peer and fails, mounting nothing, when none answers; a loo try testing.expect(th.logHas(p, "look: /n/gone/f.txt: dial failed: no answer")); } -test "a root exec that fails logs its err against the pane it ran at" { - const p = try withFile(testing.allocator, "x\n"); - defer p.deinit(); - const f = &p.panes[0].?.file.?; - f.saved_revision = f.revision -% 1; - f.saved_hash = 0; - try testing.expect(wr(p, root_exec, "Exit\n").errno() != 0); - var want: [32]u8 = undefined; - try testing.expect(th.logHas(p, try std.fmt.bufPrint(&want, "err {d} exec: ", .{serialOf(p)}))); -} - test "Tty in a directory that is not there fails and makes no pane; a shell that never started answers a run" { const p = try withFile(testing.allocator, "x\n"); defer p.deinit(); @@ -3585,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"); @@ -3797,17 +3329,6 @@ test "a served-tree pane spoils no Grep, and Look . from a gone directory is ENO try testing.expectStringStartsWith(looked.reply.ename, "look: /tmp/pardes-no-such-dir-zz: no such directory"); } -test "a tag write refuses NUL and the other control characters" { - const p = try withFile(testing.allocator, "x\n"); - defer p.deinit(); - for ([_]u64{ @backingInt(tree.TopFile.tag), tree.Node.ofCol(pardes.layout.columnSerial(p, 0), .tag), Node.of(serialOf(p), .tag) }) |node| { - const refused = wr(p, node, " a\x00b"); - try testing.expectEqual(E.INVAL, refused.errno()); - try testing.expectStringStartsWith(refused.reply.ename, "invalid tag text"); - try testing.expectEqual(E.INVAL, wr(p, node, " \x7f").errno()); - } -} - test "a malformed address is bad address syntax; on a pane with no text any address is refused as nothing to address" { const p = try th.withTerm(testing.allocator); defer p.deinit(); @@ -4603,93 +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 bad command inside an Edit block written whole is named, not the } after it" { - const p = try withFile(testing.allocator, "abc\n"); - defer p.deinit(); - const r = wr(p, Node.of(serialOf(p), .ctl), "Edit {\n,s/a/b/\nzq\n}\n"); - try testing.expectEqual(Status.err, r.reply.status); - try testing.expect(std.mem.indexOf(u8, r.reply.ename, "\"}\"") == null); - try testing.expect(std.mem.indexOf(u8, r.reply.ename, "z") != null); - try testing.expectEqualStrings("abc\n", p.panes[0].?.file.?.content); -} - -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 "pager answers its +Pager on the open that asked, whatever another client exec'd meanwhile" { - const p = try withFile(testing.allocator, "x\n"); - defer p.deinit(); - const pager = @backingInt(tree.TopFile.pager); - const exec = @backingInt(tree.TopFile.exec); - const asked = call(p, .{ .tag = 1, .op = .open, .node = pager, .omode = 2 }).reply.handle; - try testing.expectEqual(Status.ok, call(p, .{ .tag = 2, .op = .write, .node = pager, .handle = asked, .data = "/tmp\n" }).reply.status); - const paged = for (p.panes) |slot| { - const pn = slot orelse continue; - if (pn.file) |f| if (std.mem.eql(u8, f.path, "/tmp/+Pager")) break pn.serial; - } else return error.NoPager; - // Another client execs between the request and its read: a pane of its own. - const racer = call(p, .{ .tag = 3, .op = .open, .node = exec, .omode = 2 }).reply.handle; - try testing.expectEqual(Status.ok, call(p, .{ .tag = 4, .op = .write, .node = exec, .handle = racer, .data = "New\n" }).reply.status); - var line: [16]u8 = undefined; - const want = try std.fmt.bufPrint(&line, "{d}\n", .{paged}); - // A fresh open reads the session's last answer, the racer's pane: what - // `pardes -` once read, and wrote its text into. - try testing.expect(!std.mem.eql(u8, want, rd(p, exec, 0, 64).bytes)); - try testing.expectEqualStrings(want, call(p, .{ .tag = 5, .op = .read, .node = pager, .handle = asked, .size = 64 }).bytes); - _ = call(p, .{ .tag = 6, .op = .release, .node = pager, .handle = asked, .opened = true }); - // Refused, an open answers nothing, not the session's last answer. - const refused = call(p, .{ .tag = 7, .op = .open, .node = pager, .omode = 2 }).reply.handle; - try testing.expectEqual(E.INVAL, call(p, .{ .tag = 8, .op = .write, .node = pager, .handle = refused, .data = "relative\n" }).errno()); - try testing.expectEqualStrings("", call(p, .{ .tag = 9, .op = .read, .node = pager, .handle = refused, .size = 64 }).bytes); - _ = call(p, .{ .tag = 10, .op = .release, .node = pager, .handle = refused, .opened = true }); - // Resolved: `/tmp/../tmp/.` is /tmp, a +Pager of its own beside the - // one made above, which keeps its page. - const resolved = call(p, .{ .tag = 11, .op = .open, .node = pager, .omode = 2 }).reply.handle; - try testing.expectEqual(Status.ok, call(p, .{ .tag = 12, .op = .write, .node = pager, .handle = resolved, .data = "/tmp/../tmp/.\n" }).reply.status); - const second = call(p, .{ .tag = 13, .op = .read, .node = pager, .handle = resolved, .size = 64 }).bytes; - try testing.expect(!std.mem.eql(u8, want, second)); - const second_pane = p.panes[p.paneBySerial(try std.fmt.parseInt(u32, std.mem.trim(u8, second, "\n"), 10)).?].?; - try testing.expectEqualStrings("/tmp/+Pager", second_pane.file.?.path); - try testing.expect(p.paneBySerial(paged) != null); - _ = call(p, .{ .tag = 14, .op = .release, .node = pager, .handle = resolved, .opened = true }); - // One that may not be written is refused, permission denied (Linux's /proc/1). - if (comptime @import("builtin").os.tag == .linux) try testing.expectEqual(E.PERM, wr(p, pager, "/proc/1\n").errno()); - // One directory a write, absolute, and there. - try testing.expectEqual(E.INVAL, wr(p, pager, "/a\n/b\n").errno()); - // One directory an open: one refused is not followed by another, as a - // mount sends two lines in two writes. (After one taken, what follows - // is the paged text: the test below.) - const twice = call(p, .{ .tag = 20, .op = .open, .node = pager, .omode = 2 }).reply.handle; - try testing.expectEqual(E.INVAL, call(p, .{ .tag = 21, .op = .write, .node = pager, .handle = twice, .data = "relative\n" }).errno()); - try testing.expectEqual(E.INVAL, call(p, .{ .tag = 22, .op = .write, .node = pager, .handle = twice, .data = "/tmp\n" }).errno()); - _ = call(p, .{ .tag = 23, .op = .release, .node = pager, .handle = twice }); - const relative = wr(p, pager, "relative\n"); - try testing.expectEqual(E.INVAL, relative.errno()); - try testing.expectEqualStrings("pager: invalid directory \"relative\": must be absolute", relative.reply.ename); - try testing.expectEqual(E.NOENT, wr(p, pager, "/tmp/pardes-surely-missing-dir\n").errno()); - try testing.expectEqual(E.NOTDIR, wr(p, pager, "/etc/passwd\n").errno()); -} - 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(); @@ -5033,17 +4467,6 @@ test "a command or a terminal refused for room is refused before anything is log } } -test "a Mount of a socket path that is not there says no such socket, ENOENT" { - if (comptime !pardes.hosted) return; - const p = try withFile(testing.allocator, "x\n"); - defer p.deinit(); - const r = wr(p, @backingInt(tree.TopFile.ctl), "Mount peer unix!/tmp/pardes-surely-no-socket\n"); - try testing.expectEqual(E.NOENT, r.errno()); - try testing.expect(std.mem.indexOf(u8, r.reply.ename, "no such socket") != null); - try testing.expectEqual(@as(usize, 0), p.fs.mounts.items.len); - try testing.expectEqual(E.INVAL, wr(p, @backingInt(tree.TopFile.ctl), "Mount peer rel/x.sock\n").errno()); -} - test "the init file reads past a BOM, and every line it fails is a notice and an err, never silent" { const p = try Pardes.init(testing.allocator, .{ .tty_only = true, .startup_config = "\xEF\xBB\xBFTheme dusk\nnosuchword 1\nTheme nosuchtheme\n# a comment\nInactiveDim 30 # not a comment, a bad value\n" }); defer p.deinit(); diff --git a/src/ninep/pane.zig b/src/ninep/pane.zig index 33f816fe..bf9dc381 100644 --- a/src/ninep/pane.zig +++ b/src/ninep/pane.zig @@ -1098,88 +1098,6 @@ const withFile = th.withFile; const serialOf = th.serialOf; const Status = tree.Status; -test "index lists serial kind dirty flag and name, and stats 0, a view generated by each read" { - const gpa = testing.allocator; - const p = try withFile(gpa, "hello\nthere\n"); - defer p.deinit(); - const pane = p.panes[0].?; - const index = @backingInt(tree.TopFile.index); - - const a = rd(p, index, 0, 4096); - try testing.expectEqual(Status.ok, a.reply.status); - var want: [64]u8 = undefined; - const clean_row = try std.fmt.bufPrint(&want, "{d} text 0 /test.txt {d}\n", .{ pane.serial, columnOf(p, 0) }); - try testing.expect(std.mem.indexOf(u8, a.bytes, clean_row) != null); - const at = std.mem.indexOf(u8, a.bytes, clean_row).?; - const stat = call(p, .{ .tag = 1, .op = .getattr, .node = index }); - try testing.expectEqual(@as(u64, 0), stat.reply.attr.size); - try testing.expectEqual(@as(u16, 0o444), stat.reply.attr.mode); - - pane.file.?.saved_revision = pane.file.?.revision -% 1; - var dirty_want: [64]u8 = undefined; - const dirty_row = try std.fmt.bufPrint(&dirty_want, "{d} text 1 /test.txt {d}\n", .{ pane.serial, columnOf(p, 0) }); - try testing.expect(std.mem.indexOf(u8, rd(p, index, 0, 4096).bytes, dirty_row) != null); - const kind = at + std.mem.indexOfScalar(u8, clean_row, ' ').? + 1; - try testing.expectEqualStrings("text", rd(p, index, kind, 4).bytes); - - const serial = try th.newPane(p); - const both = rd(p, index, 0, 4096); - var expected: [4200]u8 = undefined; - const made = p.panes[p.paneBySerial(serial).?].?; - try testing.expect(std.mem.endsWith(u8, both.bytes, try std.fmt.bufPrint(&expected, "\n{d} text 0 {s} {d}\n", .{ serial, nameOf(p, made), columnOf(p, p.paneBySerial(serial).?) }))); -} - -test "a terminal is listed as term with its directory as name" { - const p = try th.withTerm(testing.allocator); - defer p.deinit(); - const pane = p.panes[0].?; - p.setCwd(0, "/work/dir"); - var want: [64]u8 = undefined; - try testing.expect(std.mem.indexOf( - u8, - rd(p, @backingInt(tree.TopFile.index), 0, 4096).bytes, - try std.fmt.bufPrint(&want, "{d} term 0 /work/dir {d}\n", .{ pane.serial, columnOf(p, 0) }), - ) != null); - try testing.expectEqualStrings("/work/dir\n", rd(p, Node.of(pane.serial, .name), 0, 4096).bytes); - const refused = wr(p, Node.of(pane.serial, .name), "/elsewhere\n"); - try testing.expectEqual(E.INVAL, refused.errno()); - try testing.expect(std.mem.startsWith(u8, refused.reply.ename, "invalid rename: a terminal is named")); -} - -test "body reads at any offset and writes append" { - const gpa = testing.allocator; - const p = try withFile(gpa, "one\ntwo\n"); - defer p.deinit(); - const serial = serialOf(p); - const body = Node.of(serial, .body); - - try testing.expectEqualStrings("one\ntwo\n", rd(p, body, 0, 100).bytes); - try testing.expectEqualStrings("two\n", rd(p, body, 4, 100).bytes); - try testing.expectEqualStrings("wo", rd(p, body, 5, 2).bytes); - try testing.expectEqualStrings("", rd(p, body, 999, 2).bytes); - try testing.expect(rd(p, body, 0, 100).bytes.ptr == p.panes[0].?.file.?.content.ptr); - - const w = call(p, .{ .tag = 5, .op = .write, .node = body, .off = 0, .data = "three\n" }); - try testing.expectEqual(@as(u32, 6), w.reply.written); - try testing.expectEqualStrings("one\ntwo\nthree\n", p.panes[0].?.file.?.content); - - const short = wr(p, body, "a\xC3"); - try testing.expectEqual(@as(u32, 1), short.reply.written); - try testing.expectEqualStrings("one\ntwo\nthree\na", p.panes[0].?.file.?.content); - - const stat = call(p, .{ .tag = 6, .op = .getattr, .node = body }); - try testing.expectEqual(@as(u64, "one\ntwo\nthree\na".len), stat.reply.attr.size); - try testing.expectEqual(@as(u16, 0o666), stat.reply.attr.mode); - try testing.expect(stat.reply.attr.mtime >= p.fs.started); - - // The qid version is the pane's revision, so a stat sees an edit land. - try testing.expectEqual(p.panes[0].?.file.?.revision, stat.reply.attr.version); - _ = wr(p, body, "more\n"); - const later = call(p, .{ .tag = 7, .op = .getattr, .node = body }); - try testing.expect(later.reply.attr.version != stat.reply.attr.version); - try testing.expectEqual(@as(u32, 0), call(p, .{ .tag = 8, .op = .getattr, .node = Node.of(serial, .tag) }).reply.attr.version); -} - test "a body write to a terminal pane types at its shell" { const gpa = testing.allocator; const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 40, .rows = 10 }); @@ -1228,32 +1146,6 @@ test "tag reads the whole tag and writes append to the editable tail" { try testing.expectEqual(E.NOSPC, wr(p, node, "x").errno()); } -test "data and xdata read from addr, move it, and write through it" { - const gpa = testing.allocator; - const p = try withFile(gpa, "one\ntwo\n"); - defer p.deinit(); - const serial = serialOf(p); - const addr = Node.of(serial, .addr); - const data = Node.of(serial, .data); - const xdata = Node.of(serial, .xdata); - - _ = wr(p, addr, "#0"); - try testing.expectEqualStrings("one", rd(p, data, 0, 3).bytes); - try testing.expectEqual(@as(u32, 3), p.panes[0].?.fs.addr.q0); - try testing.expectEqual(@as(u32, 3), p.panes[0].?.fs.addr.q1); - - _ = wr(p, addr, "1"); - try testing.expectEqualStrings("one\n", rd(p, xdata, 0, 100).bytes); - _ = wr(p, addr, "1"); - try testing.expectEqualStrings("one\ntwo\n", rd(p, data, 0, 100).bytes); - - _ = wr(p, addr, "1"); - const w = wr(p, data, "ONE\n"); - try testing.expectEqual(@as(u32, 4), w.reply.written); - try testing.expectEqualStrings("ONE\ntwo\n", p.panes[0].?.file.?.content); - try testing.expectEqual(@as(u32, 4), p.panes[0].?.fs.addr.q0); -} - test "data never splits a rune, in either direction" { const gpa = testing.allocator; const p = try withFile(gpa, "\u{00e9}x\n"); @@ -1268,98 +1160,6 @@ test "data never splits a rune, in either direction" { try testing.expectEqual(@as(u32, 1), wr(p, Node.of(serial, .data), "a\xC3").reply.written); } -test "sel reads the selection and writing sel replaces it" { - const gpa = testing.allocator; - const p = try withFile(gpa, "one\ntwo\n"); - defer p.deinit(); - const serial = serialOf(p); - const addr_node = Node.of(serial, .addr); - const dot = Node.of(serial, .dot); - const sel = Node.of(serial, .sel); - - // Copying addr onto dot is the whole of acme's `dot=addr`, and back again - // of `addr=dot`; each range file reads exactly what the other takes. - _ = wr(p, addr_node, "#0,#3"); - try testing.expectEqual(Status.ok, wr(p, dot, " 0 3 ").reply.status); - try testing.expectEqualStrings(" 0 3 ", rd(p, dot, 0, 100).bytes); - try testing.expectEqual(range_len, call(p, .{ .tag = 1, .op = .getattr, .node = dot }).reply.attr.size); - try testing.expectEqualStrings("one", rd(p, sel, 0, 100).bytes); - try testing.expectEqual(@as(u64, 3), call(p, .{ .tag = 1, .op = .getattr, .node = sel }).reply.attr.size); - - _ = wr(p, addr_node, "#0"); - _ = wr(p, addr_node, " 0 3 "); - try testing.expectEqual(@as(u32, 0), p.panes[0].?.fs.addr.q0); - try testing.expectEqual(@as(u32, 3), p.panes[0].?.fs.addr.q1); - - // A truncation empties dot once its open goes, nothing written after - // it; an address expression addresses it. - const h = call(p, .{ .tag = 8, .op = .open, .node = dot, .omode = 1 }).reply.handle; - _ = call(p, .{ .tag = 9, .op = .setattr, .node = dot, .truncate = true }); - try testing.expectEqualStrings("one", rd(p, sel, 0, 100).bytes); - _ = call(p, .{ .tag = 10, .op = .release, .node = dot, .handle = h, .opened = true }); - try testing.expectEqualStrings("", rd(p, sel, 0, 100).bytes); - try testing.expectEqual(Status.ok, wr(p, dot, "#0,#3").reply.status); - - try testing.expectEqual(Status.ok, wr(p, sel, "ONE").reply.status); - try testing.expectEqualStrings("ONE\ntwo\n", p.panes[0].?.file.?.content); - // What was written is selected, as acme's wrsel leaves it. - try testing.expectEqualStrings("ONE", rd(p, sel, 0, 100).bytes); - // A write of another open replaces it; one open's writes run on. - _ = wr(p, sel, "!"); - try testing.expectEqualStrings("!\ntwo\n", p.panes[0].?.file.?.content); - const hs = call(p, .{ .tag = 3, .op = .open, .node = sel, .omode = 1 }).reply.handle; - _ = call(p, .{ .tag = 4, .op = .write, .node = sel, .handle = hs, .data = "a" }); - _ = call(p, .{ .tag = 5, .op = .write, .node = sel, .handle = hs, .data = "b" }); - _ = call(p, .{ .tag = 6, .op = .release, .node = sel, .handle = hs, .opened = true }); - try testing.expectEqualStrings("ab\ntwo\n", p.panes[0].?.file.?.content); - try testing.expectEqualStrings("ab", rd(p, sel, 0, 100).bytes); -} - -test "the flag files read and write the state acme kept behind ctl verbs" { - const gpa = testing.allocator; - const p = try withFile(gpa, "one\ntwo\n"); - defer p.deinit(); - const serial = serialOf(p); - const pane = p.panes[0].?; - const pf = &p.panes[0].?.fs; - const dirty = Node.of(serial, .dirty); - const mark = Node.of(serial, .mark); - const scroll = Node.of(serial, .scroll); - - for ([_]u64{ dirty, mark, scroll }) |node| { - try testing.expectEqual(@as(u64, 2), call(p, .{ .tag = 1, .op = .getattr, .node = node }).reply.attr.size); - for ([_][]const u8{ "", "yes", "2", "0 1", "true" }) |bad| { - try testing.expectEqual(E.INVAL, wr(p, node, bad).errno()); - try testing.expectEqualStrings("bad flag: takes 1 or 0", wr(p, node, bad).reply.ename); - } - } - - try testing.expectEqualStrings("0\n", rd(p, dirty, 0, 8).bytes); - try testing.expectEqualStrings("1\n", rd(p, mark, 0, 8).bytes); - try testing.expectEqualStrings("1\n", rd(p, scroll, 0, 8).bytes); - - try testing.expectEqual(Status.ok, wr(p, dirty, "1\n").reply.status); - try testing.expect(dirtyOf(pane)); - try testing.expectEqualStrings("1\n", rd(p, dirty, 0, 8).bytes); - _ = wr(p, dirty, "0"); - try testing.expect(!dirtyOf(pane)); - - _ = wr(p, mark, "0"); - _ = wr(p, scroll, "0"); - try testing.expect(pf.nomark and pf.noscroll); - try testing.expectEqualStrings("0\n", rd(p, mark, 0, 8).bytes); - try testing.expectEqualStrings("0\n", rd(p, scroll, 0, 8).bytes); - _ = wr(p, mark, "1"); - _ = wr(p, scroll, "1"); - try testing.expect(!pf.nomark and !pf.noscroll); - - // A terminal has no file, so its dirty flag is readable but not writable. - const term = try th.withTerm(gpa); - defer term.deinit(); - try testing.expectEqualStrings("0\n", rd(term, Node.of(serialOf(term), .dirty), 0, 8).bytes); - try testing.expectEqual(E.INVAL, wr(term, Node.of(serialOf(term), .dirty), "1").errno()); -} - test "the writes of one open are one undo step, as bash's line-buffered printf makes them; the next open is another" { const p = try withFile(testing.allocator, "one\n"); defer p.deinit(); |
