From 7bbcd971a761def328fb9eeb881301bf45fb4783 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Wed, 4 Nov 2026 10:28:11 -0300 Subject: test: twenty-one of src/ninep/ctl.zig's tests through the 9P tree alone: in test/behaviour/look_and_exec.zig a look's miss quoting up to 256 bytes then an ellipsis, @p:
taking any sam address (a miss and an unknown serial errs), file:3:0 refused as addr 3:0 is, ./x, ../x, x and /abs/x misses, a terminal's file:addr miss logged once, and an exec's builtin refused wrong #args bare or with an argument it takes none of; in flags.zig Undo and Redo stepping the body and saying when there is none (counted), dirty back to 0 at the saved text; in edit.zig an Edit rename one undo step and a failed one changing nothing; in panes.zig Mini bare, the name word bare, and ctl's undo and redo fields; in addresses.zig malformed addresses and a terminal's addr, dot and limit refused; in event.zig a bad record's words; in the new repls.zig Repl with no such language; in settings.zig two bad values logged as two; in root_ctl.zig Kill with a name and nothing running; in mounts.zig an unknown network a bad dial address; the old Unmount test dropped, mounts.zig's first test covering it; each checked to fail against a break (miss_path_cap 200, "no pane at", captured's wrong #args words, Redo's and Kill's messages, the name word's refusal, an event's backwards-range words, e_syntax, Repl's "others)", Mount's bad dial words, a splice back to the saved text left dirty, Edit's no substitution words, a setting's refusal quoting "x", zeroColumn missing a column 0, a look's no such file words, a terminal's text miss unquoted, ctl's undo flag needing two edits) Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge --- test/behaviour/look_and_exec.zig | 110 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 110 insertions(+) (limited to 'test/behaviour/look_and_exec.zig') diff --git a/test/behaviour/look_and_exec.zig b/test/behaviour/look_and_exec.zig index 98cab342..360055d2 100644 --- a/test/behaviour/look_and_exec.zig +++ b/test/behaviour/look_and_exec.zig @@ -323,3 +323,113 @@ test "look-and-exec: a +PdfSections row's first number is the page: a section no _ = try s.refused(look, "design.pdf:1:999\n"); try expectEqual(@as(usize, 2), try errs(&s)); } + +test "look-and-exec: a look's miss repeats the path whole up to 256 bytes, then gives up its middle to an ellipsis" { + var s = try Session.initFile(std.testing.allocator, "x\n"); + defer s.deinit(); + const long = "some/deeply/nested/directory/that/goes/on/and/on/with/a_rather_long_file_name.txt"; + try s.write("/look", long ++ "\n"); + try std.testing.expect(has(try s.read("/log"), "look: no match for \"" ++ long ++ "\"\n")); + const huge = std.mem.asBytes(&@as([150][2]u8, @splat("é".*))); // 300 bytes: its middle cut to fit 256, between characters + const kept = std.mem.asBytes(&@as([63][2]u8, @splat("é".*))); + try s.write("/look", huge ++ "\n"); + try std.testing.expect(has(try s.read("/log"), "look: no match for \"" ++ kept ++ "…" ++ kept ++ "\"\n")); +} + +test "look-and-exec: @p:
takes any sam address; a miss and an unknown serial are errs" { + var s = try Session.initFile(std.testing.allocator, "foo x foo y\nbar\n"); + defer s.deinit(); + const n = try s.focused(); + const dot = s.at("/pane/{d}/dot", .{n}); + const Case = struct { []const u8, u32, u32 }; + for ([_]Case{ + .{ "0/foo/", 0, 3 }, + .{ "/foo/", 6, 9 }, + .{ "#12,#15", 12, 15 }, + .{ "$", 16, 16 }, + .{ "1,2", 0, 16 }, + // Backward, as in addr: from the dot's start, wrapping to the last. + .{ "?foo?", 6, 9 }, + .{ "$-?y?", 10, 11 }, + }) |c| { + try s.write("/look", s.at("@p{d}:{s}\n", .{ n, c[0] })); + try expectEqual(.{ c[1], c[2] }, try s.range(dot)); + } + try s.write("/look", s.at("@p{d}:/zzqq/\n", .{n})); + try std.testing.expect(has(try s.read("/log"), ": no match for regexp")); + try s.expect("/look", ""); + try s.write("/look", "@p999:/foo/\n"); + try std.testing.expect(has(try s.read("/log"), "look: no pane @p999")); + try s.expect("/look", ""); + // A line address to no pane is a miss too, not the active pane. + try s.write("/look", "@p77:1\n"); + try std.testing.expect(has(try s.read("/log"), "look: no pane @p77")); + try s.expect("/look", ""); +} + +test "look-and-exec: a look at file:3:0 is refused as addr 3:0 is, a column counting from 1" { + var s = try Session.initFile(std.testing.allocator, "one\ntwo\nthree\n"); + defer s.deinit(); + const n = try s.focused(); + try expectEqual(@as(u16, 22), try s.refused(s.at("/pane/{d}/addr", .{n}), "3:0")); + const by_addr = s.said; + try expectEqual(@as(u16, 22), try s.refused(s.at("/pane/{d}/look", .{n}), "/test.txt:3:0\n")); + try std.testing.expectEqualStrings(by_addr, s.said); + try s.write(s.at("/pane/{d}/look", .{n}), "/test.txt:3:1\n"); +} + +test "look-and-exec: a look of ./x, x or /abs/x that is not there is a miss: answered, the err logged" { + var s = try Session.initFile(std.testing.allocator, "x\n"); + defer s.deinit(); + const look = s.at("/pane/{d}/look", .{try s.focused()}); + for ([_][]const u8{ "./zzq-nosuch.txt\n", "zzq-nosuch.txt\n", "/zzq-nosuch.txt\n" }) |line| try s.write(look, line); + try std.testing.expect(has(try s.read("/log"), "look: ./zzq-nosuch.txt: no such file")); +} + +test "look-and-exec: a look at a ./ or ../ name that is not there is a miss naming the file; a plain one is looked for as text" { + var tmp = std.testing.tmpDir(.{}); + defer tmp.cleanup(); + try tmp.dir.createDirPath(std.testing.io, "many"); + var buf: [4096]u8 = undefined; + const dir = buf[0..try tmp.dir.realPath(std.testing.io, &buf)]; + var s = try Session.initFile(std.testing.allocator, "x\n"); + defer s.deinit(); + const n = try s.focused(); + try s.write(s.at("/pane/{d}/name", .{n}), s.at("{s}/many/a.txt\n", .{dir})); + for ([_][]const u8{ "./zz.txt", "../zz.txt" }) |name| { + try s.write(s.at("/pane/{d}/look", .{n}), s.at("{s}\n", .{name})); + try std.testing.expect(has(try s.read("/log"), s.at("look: {s}: no such file", .{name}))); + } + try s.write(s.at("/pane/{d}/look", .{n}), "zz.txt\n"); + try std.testing.expect(has(try s.read("/log"), "look: no match for \"zz.txt\"")); +} + +test "look-and-exec: a look at file:addr whose file is not there is one miss, quoting what was written, in a terminal too" { + var s = try Session.initTerm(std.testing.allocator); + defer s.deinit(); + const look = s.at("/pane/{d}/look", .{try s.focused()}); + const before = try errs(&s); + for ([_][]const u8{ "zzq:#3", "zzq:2", "zzq:/re/" }) |written| { + try s.write(look, s.at("{s}\n", .{written})); + try expectEqual(@as(usize, 1), std.mem.count(u8, try s.read("/log"), s.at("look: no match for \"{s}\"\n", .{written}))); + } + try expectEqual(before + 3, try errs(&s)); +} + +test "look-and-exec: a builtin that needs its argument, written bare to an exec, is EINVAL as through ctl" { + var s = try Session.initFile(std.testing.allocator, "x\n"); + defer s.deinit(); + for ([_][]const u8{ "/exec", s.at("/pane/{d}/exec", .{try s.focused()}), "/tagexec" }) |path| { + try expectEqual(@as(u16, 22), try s.refused(path, "Mount\n")); + try std.testing.expectEqualStrings("wrong #args in control message \"Mount\"", s.said); + } +} + +test "look-and-exec: a builtin that takes no argument, written with one to an exec, is refused wrong #args, as at a ctl" { + var s = try Session.initFile(std.testing.allocator, "x\n"); + defer s.deinit(); + for ([_][]const u8{ "/exec", s.at("/pane/{d}/exec", .{try s.focused()}) }) |path| for ([_][]const u8{ "Config extra\n", "DumpConfig extra\n" }) |line| { + try expectEqual(@as(u16, 22), try s.refused(path, line)); + try std.testing.expect(std.mem.startsWith(u8, s.said, "wrong #args in control message")); + }; +} -- cgit v1.3 From fb9b3a3304e0bdbeffc68e56dfe2ad6511a6a64e Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Wed, 4 Nov 2026 10:35:50 -0300 Subject: test: nineteen of src/ninep/pane.zig's tests through the 9P tree alone: in test/behaviour/flags.zig a > into an empty body one undo step (Undo empties it), a write that changes nothing no step and no new qid version (an empty : > data, a line written over itself, Edit's s/d/d/), and an open's hundred writes one edit (version +1, one Undo); in addresses.zig a 9P write moving dot as acme's textinsert (dot written, read back), an addr pair out of order or range refused in the address form's words, every address on a rune (a combining mark, a lone \r, a match inside a rune), and truncating data or xdata deleting only the addressed range; in panes.zig name refusing a directory (EISDIR), two lines on a held open or not, a component over 255 bytes by the write that holds it, a name cut across writes applied at its newline or close, a scratch promoted by name without touching its body, its file on disk or its undo, relative names from the file's directory and from a pane/new scratch's session directory and a /virtual one, errors appending to one +Errors (found in /index), and a truncated body's stat; in tags.zig a pane tag read whole and appended to up to 4096 bytes, and a truncated tag cleared, undone by u in the tag, clicked on, and a > dropping its one trailing newline; in look_and_exec.zig a pane's tagexec; each checked to fail against a break (a truncated empty body's step joined, spliceBody's no-op return gone, every held write put in at once, shiftOne growing nothing at dot's start, a pair's range unchecked, #n not snapped to a rune, data's truncation to the end, is_dir false, o.named never set, a held name's component limit 1255, a pane open's closing line dropped, a rename pushing an undo step, names resolved from /, pane/new taking the active pane's directory, a new +Errors every write, the tag's room one more, the tag's clear not remembered, the results read with a blank, an empty truncation of body); two old tests trimmed to what is an effect (a long path's failed Save; the watch a rename asks for); the line-index U test, the clock-held writes X test and the terminal and shell ones (pty bytes, output, spawns) stay Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge --- src/ninep/pane.zig | 505 ++------------------------------------- test/behaviour/addresses.zig | 91 +++++++ test/behaviour/flags.zig | 60 +++++ test/behaviour/look_and_exec.zig | 10 + test/behaviour/panes.zig | 185 ++++++++++++++ test/behaviour/tags.zig | 53 ++++ 6 files changed, 420 insertions(+), 484 deletions(-) (limited to 'test/behaviour/look_and_exec.zig') diff --git a/src/ninep/pane.zig b/src/ninep/pane.zig index bf9dc381..cfc93ee5 100644 --- a/src/ninep/pane.zig +++ b/src/ninep/pane.zig @@ -312,56 +312,6 @@ pub fn spliceBody(p: *Pardes, pane: *Pane, q0: usize, q1: usize, bytes: []const return take; } -test "a shell's > into an empty pane's body is one undo step, as into any other" { - const p = try withFile(testing.allocator, ""); - defer p.deinit(); - const pane = p.panes[0].?; - const f = &pane.file.?; - const body = Node.of(pane.serial, .body); - const steps = f.history.undo_len; - const h = call(p, .{ .tag = 1, .op = .open, .node = body, .omode = 1 }).reply.handle; - _ = call(p, .{ .tag = 2, .op = .setattr, .node = body, .truncate = true }); - try testing.expectEqual(tree.Status.ok, call(p, .{ .tag = 3, .op = .write, .node = body, .handle = h, .data = "fresh\n" }).reply.status); - _ = call(p, .{ .tag = 4, .op = .release, .node = body, .handle = h, .opened = true }); - try testing.expectEqualStrings("fresh\n", f.content); - try testing.expectEqual(steps + 1, f.history.undo_len); -} - -test "a write that changes nothing, an empty range deleted or a range replaced by itself, makes no undo step" { - const p = try withFile(testing.allocator, "abc\ndef\n"); - defer p.deinit(); - const pane = p.panes[0].?; - const serial = pane.serial; - const f = &pane.file.?; - const steps = f.history.undo_len; - const revision = f.revision; - const data = Node.of(serial, .data); - // Each as a shell does it, on an open of its own: `: > data` after - // an empty address, then `echo abc > data` over the line it holds. - _ = wr(p, Node.of(serial, .addr), "#2,#2"); - const h = call(p, .{ .tag = 1, .op = .open, .node = data, .omode = 1 }).reply.handle; - try testing.expectEqual(tree.Status.ok, call(p, .{ .tag = 2, .op = .setattr, .node = data, .truncate = true }).reply.status); - _ = call(p, .{ .tag = 3, .op = .release, .node = data, .handle = h, .opened = true }); - for ([_][]const u8{ "abc\n", "abd\n" }) |text| { - _ = wr(p, Node.of(serial, .addr), "1"); - const w = call(p, .{ .tag = 4, .op = .open, .node = data, .omode = 1 }).reply.handle; - try testing.expectEqual(tree.Status.ok, call(p, .{ .tag = 5, .op = .write, .node = data, .handle = w, .data = text }).reply.status); - _ = call(p, .{ .tag = 6, .op = .release, .node = data, .handle = w, .opened = true }); - if (text[2] == 'c') { - try testing.expectEqualStrings("abc\ndef\n", f.content); - try testing.expectEqual(steps, f.history.undo_len); - try testing.expectEqual(revision, f.revision); - } - } - // Edit's `s/d/d/` is the same nothing. - const undone = f.history.undo_len; - try testing.expectEqual(tree.Status.ok, wr(p, Node.of(serial, .ctl), "Edit ,s/d/d/\n").reply.status); - try testing.expectEqual(undone, f.history.undo_len); - // A real change is still one. - try testing.expectEqualStrings("abd\ndef\n", f.content); - try testing.expectEqual(steps + 1, f.history.undo_len); -} - test "rows through the line index are the ones counting newlines gives, at every offset" { const p = try withFile(testing.allocator, "héllo\nwo\u{301}rld\n\n last line é\ntail"); defer p.deinit(); @@ -1114,38 +1064,6 @@ test "a body write to a terminal pane types at its shell" { try testing.expectEqual(Status.ok, r.reply.status); } -test "tag reads the whole tag and writes append to the editable tail" { - const gpa = testing.allocator; - const p = try withFile(gpa, "x\n"); - defer p.deinit(); - const pane = p.panes[0].?; - const node = Node.of(pane.serial, .tag); - - const whole = rd(p, node, 0, 4096); - try testing.expect(std.mem.startsWith(u8, whole.bytes, "/test.txt")); - try testing.expect(std.mem.indexOf(u8, whole.bytes, "Del") != null); - try testing.expectEqual(@as(u64, whole.bytes.len), call(p, .{ .tag = 1, .op = .getattr, .node = node }).reply.attr.size); - - const before = rd(p, node, 0, 4096).bytes.len; - const w = wr(p, node, " Mine"); - try testing.expectEqual(@as(u32, 5), w.reply.written); - try testing.expect(std.mem.endsWith(u8, tagline.curTail(pane), " Mine")); - const after = rd(p, node, 0, 4096); - try testing.expectEqual(before + 5, after.bytes.len); - try testing.expect(std.mem.endsWith(u8, after.bytes, " Mine")); - - // A tag is a text like the body: a newline written to it stays one, and - // the tag reads back taller by it. - try testing.expectEqual(@as(u32, 10), wr(p, node, "\nNext Line").reply.written); - try testing.expect(std.mem.endsWith(u8, tagline.curTail(pane), " Mine\nNext Line")); - try testing.expect(std.mem.endsWith(u8, rd(p, node, 0, 4096).bytes, " Mine\nNext Line")); - - if (pane.tag.own) |own| p.gpa.free(own); - pane.tag.own = try p.gpa.alloc(u8, limits.max_tag_tail); - @memset(pane.tag.own.?, 'x'); - try testing.expectEqual(E.NOSPC, wr(p, node, "x").errno()); -} - test "data never splits a rune, in either direction" { const gpa = testing.allocator; const p = try withFile(gpa, "\u{00e9}x\n"); @@ -1179,32 +1097,6 @@ test "the writes of one open are one undo step, as bash's line-buffered printf m } } -test "an open's writes in a row are held and go in as one edit, seen by the next request" { - const p = try withFile(testing.allocator, "one\n"); - defer p.deinit(); - const serial = serialOf(p); - const body = Node.of(serial, .body); - const h = call(p, .{ .tag = 1, .op = .open, .node = body, .omode = 1 }).reply.handle; - const revision = p.panes[0].?.file.?.revision; - for (0..100) |_| _ = call(p, .{ .tag = 2, .op = .write, .node = body, .handle = h, .data = "0123456789\n" }); - // Held: nothing edited yet. - try testing.expectEqual(revision, p.panes[0].?.file.?.revision); - // Any other request puts them in, once. - try testing.expectEqual(@as(usize, 4 + 1100), rd(p, body, 0, 4096).bytes.len); - try testing.expectEqual(revision + 1, p.panes[0].?.file.?.revision); - _ = call(p, .{ .tag = 3, .op = .release, .node = body, .handle = h, .opened = true }); - try testing.expectEqual(Status.ok, wr(p, Node.of(serial, .ctl), "Undo").reply.status); - try testing.expectEqualStrings("one\n", rd(p, body, 0, 64).bytes); - // data inserts at its address go on the same way. - const data = Node.of(serial, .data); - _ = wr(p, Node.of(serial, .addr), "#0"); - const d = call(p, .{ .tag = 4, .op = .open, .node = data, .omode = 1 }).reply.handle; - _ = call(p, .{ .tag = 5, .op = .write, .node = data, .handle = d, .data = "a" }); - _ = call(p, .{ .tag = 5, .op = .write, .node = data, .handle = d, .data = "b" }); - _ = call(p, .{ .tag = 6, .op = .release, .node = data, .handle = d, .opened = true }); - try testing.expectEqualStrings("abone\n", rd(p, body, 0, 64).bytes); -} - test "writes held before the shell's clock is first seen go in at its first step" { const p = try withFile(testing.allocator, "one\n"); defer p.deinit(); @@ -1266,97 +1158,12 @@ test "after a failed address, one that goes from it says there is none" { try testing.expectEqual(Status.ok, wr(p, addr, ".").reply.status); } -test "a 9P write moves dot only as acme's textinsert does, and scrolls only the view" { - const Case = struct { at: u32, want: State.Range }; - // dot is `cd` of `abcdef\n` (2..4); two bytes go in at `at`. - for ([_]Case{ - .{ .at = 0, .want = .{ .q0 = 4, .q1 = 6 } }, // before: shifted - .{ .at = 2, .want = .{ .q0 = 2, .q1 = 6 } }, // at its start: grown - .{ .at = 3, .want = .{ .q0 = 2, .q1 = 6 } }, // inside: grown - .{ .at = 4, .want = .{ .q0 = 2, .q1 = 4 } }, // at its end: left - .{ .at = 6, .want = .{ .q0 = 2, .q1 = 4 } }, // after: left - }) |c| { - const p = try withFile(testing.allocator, "abcdef\n"); - defer p.deinit(); - const serial = serialOf(p); - const pane = p.panes[p.paneBySerial(serial).?].?; - setDot(pane, .{ .q0 = 2, .q1 = 4 }); - var addr: [16]u8 = undefined; - _ = wr(p, Node.of(serial, .addr), try std.fmt.bufPrint(&addr, "#{d}", .{c.at})); - try testing.expectEqual(Status.ok, wr(p, Node.of(serial, .data), "XX").reply.status); - try testing.expectEqual(c.want, dotOf(pane)); - } - // A body append leaves dot, and a sel write after it replaces dot, not - // the text appended. - const p = try withFile(testing.allocator, "abcdef\n"); - defer p.deinit(); - const serial = serialOf(p); - const pane = p.panes[p.paneBySerial(serial).?].?; - setDot(pane, .{ .q0 = 2, .q1 = 4 }); - try testing.expectEqual(Status.ok, wr(p, Node.of(serial, .body), "more\n").reply.status); - try testing.expectEqual(State.Range{ .q0 = 2, .q1 = 4 }, dotOf(pane)); - try testing.expectEqual(Status.ok, wr(p, Node.of(serial, .sel), "YY").reply.status); - try testing.expectEqualStrings("abYYef\nmore\n", fileOf(pane).?.content); -} - -test "an addr pair out of order or out of range is refused as the address form is, not clamped" { - const p = try withFile(testing.allocator, "abcdef\n"); - defer p.deinit(); - const serial = serialOf(p); - const addr = Node.of(serial, .addr); - try testing.expectEqualStrings(addressing.e_order, wr(p, addr, "5 2").reply.ename); - try testing.expectEqualStrings(addressing.e_order, wr(p, addr, "#5,#2").reply.ename); - try testing.expectEqualStrings(addressing.e_range, wr(p, addr, "2 99").reply.ename); - try testing.expectEqualStrings(addressing.e_range, wr(p, addr, "#2,#99").reply.ename); - try testing.expectEqual(Status.ok, wr(p, addr, "2 4").reply.status); - try testing.expectEqual(State.Range{ .q0 = 2, .q1 = 4 }, p.panes[p.paneBySerial(serial).?].?.fs.addr); -} - -test "name refuses a directory, EISDIR, and leaves the name as it was" { - const p = try withFile(testing.allocator, "x\n"); - defer p.deinit(); - const serial = serialOf(p); - const node = Node.of(serial, .name); - for ([_][]const u8{ "/\n", "/tmp/\n", "sub/\n", "/tmp\n" }) |dir| { - if (comptime !pardes.hosted) if (std.mem.eql(u8, dir, "/tmp\n")) continue; - const r = wr(p, node, dir); - try testing.expectEqual(E.ISDIR, r.errno()); - try testing.expect(std.mem.indexOf(u8, r.reply.ename, "is a directory") != null); - } - try testing.expectEqualStrings("/test.txt", nameOf(p, p.panes[p.paneBySerial(serial).?].?)); -} - -test "a write of two lines to name is refused EINVAL, on a held open or not" { +// The rest moved to test/behaviour/panes.zig; a Save's failure and the +// watches a rename asks for are effects a host performs. +test "a long path's failed Save keeps its reason" { const p = try withFile(testing.allocator, "x\n"); defer p.deinit(); const serial = serialOf(p); - const node = Node.of(serial, .name); - try testing.expectEqual(E.INVAL, wr(p, node, "/tmp/a\n/tmp/b\n").errno()); - const h = call(p, .{ .tag = 1, .op = .open, .node = node, .omode = 1 }).reply.handle; - try testing.expectEqual(E.INVAL, call(p, .{ .tag = 2, .op = .write, .node = node, .handle = h, .data = "/tmp/a\n/tmp/b\n" }).errno()); - _ = call(p, .{ .tag = 3, .op = .release, .node = node, .handle = h, .opened = true }); - try testing.expectEqualStrings("/test.txt", nameOf(p, p.panes[p.paneBySerial(serial).?].?)); - // Line by line, as bash writes it: the second line is refused. - const h2 = call(p, .{ .tag = 1, .op = .open, .node = node, .omode = 1 }).reply.handle; - try testing.expectEqual(Status.ok, call(p, .{ .tag = 2, .op = .write, .node = node, .handle = h2, .data = "/tmp/pardes-a\n" }).reply.status); - try testing.expectEqual(E.INVAL, call(p, .{ .tag = 2, .op = .write, .node = node, .handle = h2, .data = "/tmp/pardes-b\n" }).errno()); - _ = call(p, .{ .tag = 3, .op = .release, .node = node, .handle = h2, .opened = true }); - try testing.expectEqualStrings("/tmp/pardes-a", nameOf(p, p.panes[p.paneBySerial(serial).?].?)); -} - -test "a name with a component over 255 bytes is refused, and a long path's failed Save keeps its reason" { - const p = try withFile(testing.allocator, "x\n"); - defer p.deinit(); - const serial = serialOf(p); - const refused = wr(p, Node.of(serial, .name), "/tmp/" ++ &@as([256]u8, @splat('c')) ++ "/f.txt\n"); - try testing.expectEqual(E.INVAL, refused.errno()); - try testing.expectEqualStrings("invalid file name: a component over 255 bytes", refused.reply.ename); - try testing.expectEqual(Status.ok, wr(p, Node.of(serial, .name), "/tmp/" ++ &@as([255]u8, @splat('c')) ++ "\n").reply.status); - // Held with no newline, it is refused by that write, not at the close. - const held = call(p, .{ .tag = 1, .op = .open, .node = Node.of(serial, .name), .omode = 1 }).reply.handle; - try testing.expectEqual(E.INVAL, call(p, .{ .tag = 2, .op = .write, .node = Node.of(serial, .name), .handle = held, .data = "/tmp/" ++ &@as([256]u8, @splat('e')) }).errno()); - _ = call(p, .{ .tag = 3, .op = .release, .node = Node.of(serial, .name), .handle = held, .opened = true }); - try testing.expectEqual(@as(usize, 0), p.fs.closed_lines.items.len); // A Save of a 3000-byte path the host refuses: the waiting write's // reason is at the end, the path giving up its middle. // (Under /tmp: under / a user's Save is refused permission, not @@ -1372,28 +1179,25 @@ test "a name with a component over 255 bytes is refused, and a long path's faile try testing.expect(std.mem.endsWith(u8, late, "/f.txt: no such directory")); } -test "a name cut across writes is one name, applied once at its newline or its close" { - const p = try withFile(testing.allocator, "x\n"); +test "a scratch renamed to a file watches it only after its Save, and a virtual name never" { + const p = try withFile(testing.allocator, "opener\n"); defer p.deinit(); - const serial = serialOf(p); - const node = Node.of(serial, .name); - const h = call(p, .{ .tag = 1, .op = .open, .node = node, .omode = 1 }).reply.handle; - try testing.expect(h != 0); - // A piece that fills its Twrite goes on in the next. - p.fs.write_room = "/tmp/pardes-na".len; - _ = call(p, .{ .tag = 2, .op = .write, .node = node, .handle = h, .data = "/tmp/pardes-na" }); - p.fs.write_room = 0; - try testing.expectEqualStrings("/test.txt", nameOf(p, p.panes[p.paneBySerial(serial).?].?)); - _ = call(p, .{ .tag = 2, .op = .write, .node = node, .handle = h, .data = "me.txt\n" }); - try testing.expectEqualStrings("/tmp/pardes-name.txt", nameOf(p, p.panes[p.paneBySerial(serial).?].?)); - _ = call(p, .{ .tag = 3, .op = .release, .node = node, .handle = h, .opened = true }); - // No newline: held, whatever the write's size, and applied at the close. - const h3 = call(p, .{ .tag = 1, .op = .open, .node = node, .omode = 1 }).reply.handle; - _ = call(p, .{ .tag = 2, .op = .write, .node = node, .handle = h3, .data = "/tmp/pardes-closed.txt" }); - try testing.expectEqualStrings("/tmp/pardes-name.txt", nameOf(p, p.panes[p.paneBySerial(serial).?].?)); - _ = call(p, .{ .tag = 3, .op = .release, .node = node, .handle = h3, .opened = true }); - tree.runClosedLines(p); - try testing.expectEqualStrings("/tmp/pardes-closed.txt", nameOf(p, p.panes[p.paneBySerial(serial).?].?)); + const serial = try th.newPane(p); + const pane = p.panes[p.paneBySerial(serial).?].?; + const name = Node.of(serial, .name); + var tmp = testing.tmpDir(.{}); + defer tmp.cleanup(); + var directory_buf: [4096]u8 = undefined; + const directory = directory_buf[0..try tmp.dir.realPath(testing.io, &directory_buf)]; + var line: [4120]u8 = undefined; + const renamed = wr(p, name, try std.fmt.bufPrint(&line, "{s}/renamed.zig\n", .{directory})); + try testing.expectEqual(false, renamed.watch.?); + try testing.expect(pane.file.?.watch_after_save); + const virtual = try th.newPane(p); + _ = wr(p, Node.of(virtual, .name), try std.fmt.bufPrint(&line, "/virtual/pane/{d}/body\n", .{serial})); + const unchanged = wr(p, Node.of(virtual, .name), "./body\n"); + try testing.expect(unchanged.watch == null); + try testing.expect(!p.panes[p.paneBySerial(virtual).?].?.file.?.watch_after_save); } test "a replace through data, truncate then write, is one undo step" { @@ -1424,120 +1228,6 @@ test "writes under mark 0 are one undo step, even with no history before them" { try testing.expectEqualStrings("one\ntwo\nthree\n", rd(p, body, 0, 64).bytes); } -test "truncating the tag clears its editable tail" { - const p = try withFile(testing.allocator, "x\n"); - defer p.deinit(); - const pane = p.panes[0].?; - const tag = Node.of(pane.serial, .tag); - _ = wr(p, tag, " Mine"); - try testing.expect(tagline.curTail(pane).len > 0); - const cleared = call(p, .{ .tag = 1, .op = .setattr, .node = tag, .truncate = true }); - try testing.expectEqual(Status.ok, cleared.reply.status); - // Done at the first read or write after it (or the close). - _ = rd(p, tag, 0, 4096); - try testing.expectEqualStrings("", pane.tag.own.?); - try testing.expect(std.mem.indexOf(u8, rd(p, tag, 0, 4096).bytes, " Mine") == null); - // The tag keeps its undo: undoing in it brings back what was cleared. - pardes.edit.doUndo(p, &pane.tag); - try testing.expect(std.mem.endsWith(u8, tagline.curTail(pane), " Mine")); - _ = call(p, .{ .tag = 2, .op = .setattr, .node = tag, .truncate = true }); - _ = rd(p, tag, 0, 4096); - try testing.expectEqualStrings("", pane.tag.own.?); - - // Written back without a leading space, the text still stands apart - // from the path: the computed prefix brings the separator, so Look and - // Exec find `Get`, not `test.txtGet`. - _ = wr(p, tag, "Get"); - try testing.expectEqualStrings("Get", pane.tag.own.?); - const whole = rd(p, tag, 0, 4096).bytes; - try testing.expectEqualStrings("/test.txt Get", whole); - const word = config.wordBounds(whole, whole.len - "Get".len); - try testing.expectEqualStrings("Get", whole[word.lo..word.hi]); - // and a click on the G puts the tag's cursor on it - const at = tagline.tagOffsetAt(p, pane, 0, "/test.txt ".len).?; - try testing.expectEqualStrings("Get", whole[at.col..]); - - // `echo Make > tag`: the newline ending the truncating write's text is - // dropped, one only; a newline between its writes stays. - _ = call(p, .{ .tag = 3, .op = .release, .node = tag }); - _ = call(p, .{ .tag = 4, .op = .setattr, .node = tag, .truncate = true }); - _ = wr(p, tag, "Make\n"); - try testing.expectEqualStrings("Make", pane.tag.own.?); - _ = wr(p, tag, "More\n\n"); - try testing.expectEqualStrings("Make\nMore\n", pane.tag.own.?); - _ = call(p, .{ .tag = 5, .op = .release, .node = tag }); - // `>>` keeps what it is given. - _ = wr(p, tag, " Tail\n"); - try testing.expectEqualStrings("Make\nMore\n Tail\n", pane.tag.own.?); -} - -test "name reads the file name and writing it promotes a scratch without touching its body" { - const gpa = testing.allocator; - const p = try withFile(gpa, "opener\n"); - defer p.deinit(); - const serial = try th.newPane(p); - const pane = p.panes[p.paneBySerial(serial).?].?; - const name = Node.of(serial, .name); - const body = Node.of(serial, .body); - var scratch_name: [4200]u8 = undefined; - const scratch_line = try std.fmt.bufPrint(&scratch_name, "{s}\n", .{nameOf(p, pane)}); - try testing.expectEqualStrings(scratch_line, rd(p, name, 0, 4096).bytes); - try testing.expectEqual(@as(u64, scratch_line.len), call(p, .{ .tag = 1, .op = .getattr, .node = name }).reply.attr.size); - _ = wr(p, body, "scratch "); - _ = wr(p, body, "work\n"); - const undo_len = pane.file.?.history.undo_len; - var tmp = testing.tmpDir(.{}); - defer tmp.cleanup(); - try tmp.dir.writeFile(testing.io, .{ .sub_path = "renamed.zig", .data = "existing target\n" }); - var directory_buf: [4096]u8 = undefined; - const directory = directory_buf[0..try tmp.dir.realPath(testing.io, &directory_buf)]; - var path_buffer: [4096]u8 = undefined; - const path = try std.fmt.bufPrint(&path_buffer, "{s}/renamed.zig", .{directory}); - var line: [4104]u8 = undefined; - const renamed = wr(p, name, try std.fmt.bufPrint(&line, "{s}\n", .{path})); - try testing.expectEqual(Status.ok, renamed.reply.status); - try testing.expectEqual(false, renamed.watch.?); - try testing.expectEqualStrings("scratch work\n", pane.file.?.content); - try testing.expectEqual(undo_len, pane.file.?.history.undo_len); - try testing.expect(pane.file.?.output == null and dirtyOf(pane)); - try testing.expect(pane.file.?.watch_after_save); - try testing.expectEqualStrings(path, std.mem.trimEnd(u8, rd(p, name, 0, 4096).bytes, "\n")); - const target = try fs.readFile(gpa, path); - defer gpa.free(target); - try testing.expectEqualStrings("existing target\n", target); - for ([_][]const u8{ "", "\n" }) |bad| - try testing.expectEqual(E.INVAL, wr(p, name, bad).errno()); - // One name, and what no file name holds: a second line, a NUL. - for ([_][2][]const u8{ - .{ "two\nlines\n", "a newline" }, - .{ "nul\x00.zig\n", "a NUL" }, - }) |c| { - const refused = wr(p, name, c[0]); - try testing.expectEqual(E.INVAL, refused.errno()); - try testing.expectStringStartsWith(refused.reply.ename, "bad character in file name: "); - try testing.expect(std.mem.indexOf(u8, refused.reply.ename, c[1]) != null); - } - // Any other byte a file name holds is taken, and reads back as written: - // blanks at its ends, a tab, a control byte, DEL, C1, bytes not UTF-8. - for ([_][]const u8{ " lead.zig ", "tab\t.zig", "c\x01.zig", "del\x7f.zig", "c1\xc2\x85.zig", "bad\xff.zig" }) |odd| { - try testing.expectEqual(Status.ok, wr(p, name, try std.fmt.bufPrint(&line, "{s}\n", .{odd})).reply.status); - const read_back = std.mem.trimEnd(u8, rd(p, name, 0, 4096).bytes, "\n"); - try testing.expect(std.mem.endsWith(u8, read_back, odd)); - var again: [4200]u8 = undefined; - @memcpy(again[0..read_back.len], read_back); - try testing.expectEqual(Status.ok, wr(p, name, again[0..read_back.len]).reply.status); - try testing.expectEqualStrings(again[0..read_back.len], pane.file.?.path); - } - // A name that is one line and UTF-8 is taken, é and all. - try testing.expectEqual(Status.ok, wr(p, name, "caf\xc3\xa9.zig\n").reply.status); - try testing.expect(std.mem.endsWith(u8, pane.file.?.path, "/caf\xc3\xa9.zig")); - try testing.expectEqual(Status.ok, wr(p, name, try std.fmt.bufPrint(&line, "{s}\n", .{path})).reply.status); - try testing.expectEqualStrings(path, pane.file.?.path); - try testing.expectEqual(Status.ok, wr(p, name, "two words.zig\n").reply.status); - const spaced = try std.fmt.bufPrint(&path_buffer, "{s}/two words.zig", .{directory}); - try testing.expectEqualStrings(spaced, pane.file.?.path); -} - test "name refreshes cached syntax for unchanged contents" { if (!pardes.syntax.enabled) return error.SkipZigTest; pardes.syntax.start(testing.allocator); @@ -1555,58 +1245,6 @@ test "name refreshes cached syntax for unchanged contents" { try testing.expectEqualStrings("fn check() void {}\n", pane.file.?.content); } -test "relative names use the file directory and can name a new target" { - const gpa = testing.allocator; - const p = try withFile(gpa, "retained body\n"); - defer p.deinit(); - var tmp = testing.tmpDir(.{}); - defer tmp.cleanup(); - try tmp.dir.writeFile(testing.io, .{ .sub_path = "note.txt", .data = "from pane directory\n" }); - var directory_buf: [4096]u8 = undefined; - const directory = directory_buf[0..try tmp.dir.realPath(testing.io, &directory_buf)]; - const pane = p.panes[0].?; - const name = Node.of(pane.serial, .name); - const ctl_node = Node.of(pane.serial, .ctl); - var line: [4140]u8 = undefined; - try testing.expectEqual(Status.ok, wr(p, name, try std.fmt.bufPrint(&line, "{s}/old.txt\n", .{directory})).reply.status); - try testing.expectEqual(Status.ok, wr(p, name, "child/../note.txt\n").reply.status); - try testing.expectEqual(Status.ok, wr(p, ctl_node, "get\n").reply.status); - try testing.expectEqualStrings("from pane directory\n", pane.file.?.content); - try testing.expectEqualStrings(directory, Pardes.paneDir(pane)); - try testing.expectEqual(Status.ok, wr(p, name, "./created.txt\n").reply.status); - var expected_buf: [4096]u8 = undefined; - const expected = try std.fmt.bufPrint(&expected_buf, "{s}/created.txt", .{directory}); - try testing.expectEqualStrings(expected, pane.file.?.path); - try testing.expect(!dirtyOf(pane)); // a name alone is no edit -} - -test "relative names follow a pane/new scratch's session directory and virtual directories" { - const p = try withFile(testing.allocator, "source body\n"); - defer p.deinit(); - const source = p.panes[0].?; - try testing.expectEqual(Status.ok, wr(p, Node.of(source.serial, .name), "/elsewhere/source.zig\n").reply.status); - // pane/new's scratch is the session's, not the active pane's. - const session = "/project/src"; - @memcpy(p.session_dir[0..session.len], session); - p.session_dir_len = session.len; - const serial = try th.newPane(p); - const scratch = p.panes[p.paneBySerial(serial).?].?; - const name = Node.of(serial, .name); - try testing.expectEqualStrings("/project/src", Pardes.paneDir(scratch)); - try testing.expectEqual(Status.ok, wr(p, name, "../out/./notes.txt\n").reply.status); - try testing.expectEqualStrings("/project/out/notes.txt", scratch.file.?.path); - try testing.expectEqualStrings("/project/out", Pardes.paneDir(scratch)); - var line: [256]u8 = undefined; - try testing.expectEqual(Status.ok, wr(p, name, try std.fmt.bufPrint(&line, "/virtual/pane/{d}/./body\n", .{source.serial})).reply.status); - try testing.expectEqual(Status.ok, wr(p, Node.of(serial, .ctl), "get\n").reply.status); - try testing.expectEqualStrings(source.file.?.content, scratch.file.?.content); - const unchanged = wr(p, name, "./body\n"); - try testing.expectEqual(Status.ok, unchanged.reply.status); - try testing.expect(unchanged.watch == null); - try testing.expect(!dirtyOf(scratch)); - try testing.expect(!scratch.file.?.watch_after_save); -} - test "owned cwd name promotion releases the former directory" { const p = try th.withTerm(testing.allocator); defer p.deinit(); @@ -1622,96 +1260,6 @@ test "owned cwd name promotion releases the former directory" { try testing.expectEqualStrings("/old/directory", Pardes.paneDir(pane)); } -test "errors append to one +Errors buffer per directory" { - const gpa = testing.allocator; - const p = try withFile(gpa, "x\n"); - defer p.deinit(); - const serial = serialOf(p); - - const live = for (p.panes) |slot| { - if (slot) |q| if (q.file) |f| if (f.output) |o| if (std.meta.activeTag(o.from) == .errors) break q; - } else null; - try testing.expect(live == null); - - try testing.expectEqual(Status.ok, wr(p, Node.of(serial, .errors), "boom\n").reply.status); - try testing.expectEqual(Status.ok, wr(p, Node.of(serial, .errors), "again\n").reply.status); - - var found: usize = 0; - for (p.panes) |slot| { - const q = slot orelse continue; - const f = q.file orelse continue; - const o = f.output orelse continue; - if (std.meta.activeTag(o.from) != .errors) continue; - found += 1; - try testing.expectEqualStrings("boom\nagain\n", f.content); - try testing.expectEqualStrings("/+Errors", f.path); - } - try testing.expectEqual(@as(usize, 1), found); -} - -test "truncating data deletes only the addressed range, so > data replaces it" { - const p = try withFile(testing.allocator, "hello world\nsecond line\n"); - defer p.deinit(); - const serial = serialOf(p); - for ([_]PaneFile{ .data, .xdata }) |file| { - _ = call(p, .{ .tag = 1, .op = .setattr, .node = Node.of(serial, .body), .truncate = true }); - _ = wr(p, Node.of(serial, .body), "hello world\nsecond line\n"); - _ = wr(p, Node.of(serial, .addr), "#0,#5"); - try testing.expectEqual(Status.ok, call(p, .{ .tag = 2, .op = .setattr, .node = Node.of(serial, file), .truncate = true }).reply.status); - try testing.expectEqualStrings(" world\nsecond line\n", p.panes[0].?.file.?.content); - try testing.expectEqual(Status.ok, wr(p, Node.of(serial, file), "HOWDY").reply.status); - try testing.expectEqualStrings("HOWDY world\nsecond line\n", p.panes[0].?.file.?.content); - } -} - -test "setattr truncation empties the body and answers fresh attributes" { - const gpa = testing.allocator; - const p = try withFile(gpa, "one\ntwo\n"); - defer p.deinit(); - const serial = serialOf(p); - - const a = call(p, .{ .tag = 7, .op = .setattr, .node = Node.of(serial, .body), .truncate = true }); - try testing.expectEqual(Status.ok, a.reply.status); - try testing.expectEqual(@as(u64, 0), a.reply.attr.size); - try testing.expectEqualStrings("", p.panes[0].?.file.?.content); - - _ = wr(p, Node.of(serial, .body), "new text\n"); - try testing.expectEqualStrings("new text\n", p.panes[0].?.file.?.content); - - const noop = call(p, .{ .tag = 8, .op = .setattr, .node = Node.of(serial, .body) }); - try testing.expectEqual(@as(u64, 9), noop.reply.attr.size); -} - -test "addresses are in runes: a combining mark and a lone \\r are places of their own" { - const gpa = testing.allocator; - // e, U+0301 (two bytes, 1-2), x, \r, \n - const p = try withFile(gpa, "e\u{0301}x\r\n"); - defer p.deinit(); - const serial = serialOf(p); - const addr_node = Node.of(serial, .addr); - const dot = Node.of(serial, .dot); - const Case = struct { expr: []const u8, q0: u32, q1: u32 }; - for ([_]Case{ - .{ .expr = "#1,#3", .q0 = 1, .q1 = 3 }, // the mark alone - .{ .expr = "#2", .q0 = 1, .q1 = 1 }, // inside it: back to its start - .{ .expr = "#4,#5", .q0 = 4, .q1 = 5 }, // the \r alone - .{ .expr = "1:2", .q0 = 1, .q1 = 1 }, // line:col the same - .{ .expr = "1:3", .q0 = 1, .q1 = 1 }, - .{ .expr = "0/\xCC/", .q0 = 1, .q1 = 3 }, // a match inside a rune covers it - }) |c| { - try testing.expectEqual(Status.ok, wr(p, addr_node, c.expr).reply.status); - try testing.expectEqual(c.q0, p.panes[0].?.fs.addr.q0); - try testing.expectEqual(c.q1, p.panes[0].?.fs.addr.q1); - } - // Copied to dot, it reads back the same. - _ = wr(p, addr_node, "#1,#3"); - try testing.expectEqual(Status.ok, wr(p, dot, " 1 3 ").reply.status); - p.sync(); - try testing.expectEqualStrings(" 1 3 ", rd(p, dot, 0, 100).bytes); - _ = wr(p, addr_node, "#4,#5"); - try testing.expectEqualStrings("\r", rd(p, Node.of(serial, .xdata), 0, 100).bytes); -} - test "a limit write that fails keeps the limit a truncation cleared before it" { const gpa = testing.allocator; const p = try withFile(gpa, "one two\n"); @@ -1727,17 +1275,6 @@ test "a limit write that fails keeps the limit a truncation cleared before it" { try testing.expectEqualStrings("", rd(p, limit, 0, 100).bytes); } -test "a pane's tagexec runs a word as a click in its tag, and reads back what it touched" { - const gpa = testing.allocator; - const p = try withFile(gpa, "x\n"); - defer p.deinit(); - const serial = serialOf(p); - try testing.expectEqual(Status.ok, wr(p, Node.of(serial, .tagexec), "Msg from the tag\n").reply.status); - try testing.expect(th.logHas(p, "from the tag")); - var want: [16]u8 = undefined; - try testing.expectEqualStrings(try std.fmt.bufPrint(&want, "{d}\n", .{serial}), rd(p, Node.of(serial, .tagexec), 0, 64).bytes); -} - test "index names a command's pane cmd, a shell's term" { const p = try withFile(testing.allocator, "x\n"); defer p.deinit(); diff --git a/test/behaviour/addresses.zig b/test/behaviour/addresses.zig index a1474c3d..dde36f59 100644 --- a/test/behaviour/addresses.zig +++ b/test/behaviour/addresses.zig @@ -63,3 +63,94 @@ test "addresses: sel reads the selection, and a write to sel replaces it and is try s.expect(body, "ab\ntwo\n"); try s.expect(sel, "ab"); } + +test "addresses: a 9P write moves dot only as acme's textinsert does" { + // dot is `cd` of `abcdef\n` (2 4); two bytes go in at `at`. + for ([_][3]u32{ + .{ 0, 4, 6 }, // before: shifted + .{ 2, 2, 6 }, // at its start: grown + .{ 3, 2, 6 }, // inside: grown + .{ 4, 2, 4 }, // at its end: left + .{ 6, 2, 4 }, // after: left + }) |c| { + var s = try Session.initFile(std.testing.allocator, "abcdef\n"); + defer s.deinit(); + const n = try s.focused(); + const dot = s.at("/pane/{d}/dot", .{n}); + try s.write(dot, "2 4"); + try s.write(s.at("/pane/{d}/addr", .{n}), s.at("#{d}", .{c[0]})); + try s.write(s.at("/pane/{d}/data", .{n}), "XX"); + try expectEqual(.{ c[1], c[2] }, try s.range(dot)); + } + // A body append leaves dot, and a sel write after it replaces dot, not + // the text appended. + var s = try Session.initFile(std.testing.allocator, "abcdef\n"); + defer s.deinit(); + const n = try s.focused(); + const dot = s.at("/pane/{d}/dot", .{n}); + try s.write(dot, "2 4"); + try s.write(s.at("/pane/{d}/body", .{n}), "more\n"); + try expectEqual(.{ @as(u32, 2), @as(u32, 4) }, try s.range(dot)); + try s.write(s.at("/pane/{d}/sel", .{n}), "YY"); + try s.expect(s.at("/pane/{d}/body", .{n}), "abYYef\nmore\n"); +} + +test "addresses: a pair out of order or out of range is refused as the address form is, not clamped" { + var s = try Session.initFile(std.testing.allocator, "abcdef\n"); + defer s.deinit(); + const addr = s.at("/pane/{d}/addr", .{try s.focused()}); + for ([_][2][]const u8{ + .{ "5 2", "addresses out of order" }, + .{ "#5,#2", "addresses out of order" }, + .{ "2 99", "address out of range" }, + .{ "#2,#99", "address out of range" }, + }) |c| { + try expectEqual(@as(u16, 22), try s.refused(addr, c[0])); + try std.testing.expectEqualStrings(c[1], s.said); + } + try s.write(addr, "2 4"); + try expectEqual(.{ @as(u32, 2), @as(u32, 4) }, try s.range(addr)); +} + +test "addresses: every address lands on a rune, and a combining mark and a lone \\r are places of their own" { + // e, U+0301 (two bytes, 1-2), x, \r, \n + var s = try Session.initFile(std.testing.allocator, "e\u{0301}x\r\n"); + defer s.deinit(); + const n = try s.focused(); + const addr = s.at("/pane/{d}/addr", .{n}); + for ([_]struct { []const u8, u32, u32 }{ + .{ "#1,#3", 1, 3 }, // the mark alone + .{ "#2", 1, 1 }, // inside it: back to its start + .{ "#4,#5", 4, 5 }, // the \r alone + .{ "1:2", 1, 1 }, // line:col the same + .{ "1:3", 1, 1 }, + .{ "0/\xCC/", 1, 3 }, // a match inside a rune covers it + }) |c| { + try s.write(addr, c[0]); + try expectEqual(.{ c[1], c[2] }, try s.range(addr)); + } + // Copied to dot, it reads back the same. + const dot = s.at("/pane/{d}/dot", .{n}); + try s.write(addr, "#1,#3"); + try s.write(dot, " 1 3 "); + try s.expect(dot, " 1 3 "); + try s.write(addr, "#4,#5"); + try s.expect(s.at("/pane/{d}/xdata", .{n}), "\r"); +} + +test "addresses: truncating data or xdata deletes only the addressed range, so > data replaces it" { + var s = try Session.initFile(std.testing.allocator, ""); + defer s.deinit(); + const n = try s.focused(); + const body = s.at("/pane/{d}/body", .{n}); + for ([_][]const u8{ "data", "xdata" }) |file| { + try s.replace(body, "hello world\nsecond line\n"); + try s.write(s.at("/pane/{d}/addr", .{n}), "#0,#5"); + const h = try s.hold(s.at("/pane/{d}/{s}", .{ n, file }), 1); + try s.truncate(h); + try s.expect(body, " world\nsecond line\n"); + try expectEqual(@as(u16, 0), try s.writeFid(h, "HOWDY")); + s.clunk(h); + try s.expect(body, "HOWDY world\nsecond line\n"); + } +} diff --git a/test/behaviour/flags.zig b/test/behaviour/flags.zig index 656d219f..0c8b6660 100644 --- a/test/behaviour/flags.zig +++ b/test/behaviour/flags.zig @@ -40,3 +40,63 @@ test "flags: dirty, mark and scroll read and write the state acme kept behind ct try t.expect(term_dirty, "0\n"); try std.testing.expectEqual(@as(u16, 22), try t.refused(term_dirty, "1")); } + +test "flags: a > into an empty body is one undo step, as into any other" { + var s = try Session.initFile(std.testing.allocator, ""); + defer s.deinit(); + const n = try s.focused(); + const body = s.at("/pane/{d}/body", .{n}); + try s.replace(body, "fresh\n"); + try s.expect(body, "fresh\n"); + try s.write(s.at("/pane/{d}/ctl", .{n}), "Undo\n"); + try s.expect(body, ""); +} + +test "flags: a write that changes nothing, an empty range deleted or a range replaced by itself, is no undo step and no new version" { + var s = try Session.initFile(std.testing.allocator, "abc\ndef\n"); + defer s.deinit(); + const n = try s.focused(); + const body = s.at("/pane/{d}/body", .{n}); + const addr = s.at("/pane/{d}/addr", .{n}); + const data = s.at("/pane/{d}/data", .{n}); + const ctl = s.at("/pane/{d}/ctl", .{n}); + // One real change, so a step made after it would be the one undone. + try s.write(addr, "1"); + try s.write(data, "abd\n"); + const version = (try s.stat(body)).version; + // Each as a shell does it: `: > data` after an empty address, `echo + // abd > data` over the line it holds, and Edit's `s/d/d/`. + try s.write(addr, "#2,#2"); + const h = try s.hold(data, 1); + try s.truncate(h); + s.clunk(h); + try s.write(addr, "1"); + try s.write(data, "abd\n"); + try s.write(ctl, "Edit ,s/d/d/\n"); + try s.expect(body, "abd\ndef\n"); + try std.testing.expectEqual(version, (try s.stat(body)).version); + try s.write(ctl, "Undo\n"); + try s.expect(body, "abc\ndef\n"); +} + +test "flags: an open's writes in a row go in as one edit, seen by the next request" { + var s = try Session.initFile(std.testing.allocator, "one\n"); + defer s.deinit(); + const n = try s.focused(); + const body = s.at("/pane/{d}/body", .{n}); + const version = (try s.stat(body)).version; + const h = try s.hold(body, 1); + for (0..100) |_| try std.testing.expectEqual(@as(u16, 0), try s.writeFid(h, "0123456789\n")); + try std.testing.expectEqual(@as(usize, 4 + 1100), (try s.read(body)).len); + try std.testing.expectEqual(version + 1, (try s.stat(body)).version); + s.clunk(h); + try s.write(s.at("/pane/{d}/ctl", .{n}), "Undo\n"); + try s.expect(body, "one\n"); + // data inserts at its address go on the same way. + try s.write(s.at("/pane/{d}/addr", .{n}), "#0"); + const d = try s.hold(s.at("/pane/{d}/data", .{n}), 1); + _ = try s.writeFid(d, "a"); + _ = try s.writeFid(d, "b"); + s.clunk(d); + try s.expect(body, "abone\n"); +} diff --git a/test/behaviour/look_and_exec.zig b/test/behaviour/look_and_exec.zig index 98cab342..0777d385 100644 --- a/test/behaviour/look_and_exec.zig +++ b/test/behaviour/look_and_exec.zig @@ -323,3 +323,13 @@ test "look-and-exec: a +PdfSections row's first number is the page: a section no _ = try s.refused(look, "design.pdf:1:999\n"); try expectEqual(@as(usize, 2), try errs(&s)); } + +test "look-and-exec: a pane's tagexec runs a word as a click in its tag, and reads back what it touched" { + var s = try Session.initFile(std.testing.allocator, "x\n"); + defer s.deinit(); + const n = try s.focused(); + const tagexec = s.at("/pane/{d}/tagexec", .{n}); + try s.write(tagexec, "Msg from the tag\n"); + try std.testing.expect(std.mem.indexOf(u8, try s.read("/log"), "from the tag") != null); + try s.expect(tagexec, s.at("{d}\n", .{n})); +} diff --git a/test/behaviour/panes.zig b/test/behaviour/panes.zig index a46f8432..553b1ca9 100644 --- a/test/behaviour/panes.zig +++ b/test/behaviour/panes.zig @@ -363,3 +363,188 @@ test "panes: a Mini that cannot read its file leaves the panes, the last Mini's try s.expect("/index", index); try s.expect(s.at("/pane/{d}/body", .{mini}), body); } + +test "panes: name refuses a directory, EISDIR, and leaves the name as it was" { + var s = try Session.initFile(std.testing.allocator, "x\n"); + defer s.deinit(); + const name = s.at("/pane/{d}/name", .{try s.focused()}); + for ([_][]const u8{ "/\n", "/tmp/\n", "sub/\n", "/tmp\n" }) |dir| { + try std.testing.expectEqual(@as(u16, 21), try s.refused(name, dir)); + try std.testing.expect(std.mem.indexOf(u8, s.said, "is a directory") != null); + } + try s.expect(name, "/test.txt\n"); +} + +test "panes: a write of two lines to name is refused EINVAL, on a held open or not" { + var s = try Session.initFile(std.testing.allocator, "x\n"); + defer s.deinit(); + const name = s.at("/pane/{d}/name", .{try s.focused()}); + try std.testing.expectEqual(@as(u16, 22), try s.refused(name, "/tmp/a\n/tmp/b\n")); + const h = try s.hold(name, 1); + try std.testing.expectEqual(@as(u16, 22), try s.writeFid(h, "/tmp/a\n/tmp/b\n")); + s.clunk(h); + try s.expect(name, "/test.txt\n"); + // Line by line, as bash writes it: the second line is refused. + const h2 = try s.hold(name, 1); + try std.testing.expectEqual(@as(u16, 0), try s.writeFid(h2, "/tmp/pardes-a\n")); + try std.testing.expectEqual(@as(u16, 22), try s.writeFid(h2, "/tmp/pardes-b\n")); + s.clunk(h2); + try s.expect(name, "/tmp/pardes-a\n"); +} + +test "panes: a name with a component over 255 bytes is refused by the write that holds it" { + var s = try Session.initFile(std.testing.allocator, "x\n"); + defer s.deinit(); + const name = s.at("/pane/{d}/name", .{try s.focused()}); + try std.testing.expectEqual(@as(u16, 22), try s.refused(name, "/tmp/" ++ &@as([256]u8, @splat('c')) ++ "/f.txt\n")); + try std.testing.expectEqualStrings("invalid file name: a component over 255 bytes", s.said); + const longest = "/tmp/" ++ &@as([255]u8, @splat('c')); + try s.write(name, longest ++ "\n"); + // Held with no newline, it is refused by that write, and the close + // has nothing left to apply. + const held = try s.hold(name, 1); + try std.testing.expectEqual(@as(u16, 22), try s.writeFid(held, "/tmp/" ++ &@as([256]u8, @splat('e')))); + s.clunk(held); + try s.expect(name, longest ++ "\n"); +} + +test "panes: a name cut across writes is one name, applied once at its newline or its close" { + var s = try Session.initFile(std.testing.allocator, "x\n"); + defer s.deinit(); + const name = s.at("/pane/{d}/name", .{try s.focused()}); + const h = try s.hold(name, 1); + _ = try s.writeFid(h, "/tmp/pardes-na"); + try s.expect(name, "/test.txt\n"); + _ = try s.writeFid(h, "me.txt\n"); + try s.expect(name, "/tmp/pardes-name.txt\n"); + s.clunk(h); + // No newline: held, and applied at the close. + const h3 = try s.hold(name, 1); + _ = try s.writeFid(h3, "/tmp/pardes-closed.txt"); + try s.expect(name, "/tmp/pardes-name.txt\n"); + s.clunk(h3); + try s.expect(name, "/tmp/pardes-closed.txt\n"); +} + +test "panes: name reads the file name, and a write promotes a scratch without touching its body or its file" { + const gpa = std.testing.allocator; + var s = try Session.initFile(gpa, "opener\n"); + defer s.deinit(); + const n = try s.newPane(); + const name = s.at("/pane/{d}/name", .{n}); + const body = s.at("/pane/{d}/body", .{n}); + const scratch = try s.read(name); + try std.testing.expect(std.mem.endsWith(u8, scratch, "/+New\n")); + try std.testing.expectEqual(@as(u64, scratch.len), (try s.stat(name)).size); + try s.write(body, "scratch "); + try s.write(body, "work\n"); + var tmp = std.testing.tmpDir(.{}); + defer tmp.cleanup(); + try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "renamed.zig", .data = "existing target\n" }); + var dir_buf: [4096]u8 = undefined; + const dir = dir_buf[0..try tmp.dir.realPath(std.testing.io, &dir_buf)]; + const path = s.at("{s}/renamed.zig", .{dir}); + try s.write(name, s.at("{s}\n", .{path})); + try s.expect(body, "scratch work\n"); + try s.expect(s.at("/pane/{d}/dirty", .{n}), "1\n"); + try s.expect(name, s.at("{s}\n", .{path})); + var target_buf: [64]u8 = undefined; + try std.testing.expectEqualStrings("existing target\n", try tmp.dir.readFile(std.testing.io, "renamed.zig", &target_buf)); + try std.testing.expectEqual(@as(u16, 22), try s.refused(name, "\n")); + // One name, and what no file name holds: a second line, a NUL. + for ([_][2][]const u8{ + .{ "two\nlines\n", "invalid file name: one name a write, on one line" }, + .{ "nul\x00.zig\n", "bad character in file name: a NUL" }, + }) |c| { + try std.testing.expectEqual(@as(u16, 22), try s.refused(name, c[0])); + try std.testing.expectEqualStrings(c[1], s.said); + } + // Any other byte a file name holds is taken, and reads back as written: + // blanks at its ends, a tab, a control byte, DEL, C1, bytes not UTF-8. + for ([_][]const u8{ " lead.zig ", "tab\t.zig", "c\x01.zig", "del\x7f.zig", "c1\xc2\x85.zig", "bad\xff.zig" }) |odd| { + try s.write(name, s.at("{s}\n", .{odd})); + const read_back = std.mem.trimEnd(u8, try s.read(name), "\n"); + try std.testing.expect(std.mem.endsWith(u8, read_back, odd)); + try s.write(name, read_back); + try s.expect(name, s.at("{s}\n", .{read_back})); + } + // A name that is one line and UTF-8 is taken, é and all. + try s.write(name, "caf\xc3\xa9.zig\n"); + try std.testing.expect(std.mem.endsWith(u8, try s.read(name), "/caf\xc3\xa9.zig\n")); + try s.write(name, "two words.zig\n"); + try s.expect(name, s.at("{s}/two words.zig\n", .{dir})); + // A rename is no edit: Undo takes back the last write. + try s.write(s.at("/pane/{d}/ctl", .{n}), "Undo\n"); + try s.expect(body, "scratch "); +} + +test "panes: relative names go from the file's directory and can name a new target" { + var s = try Session.initFile(std.testing.allocator, "retained body\n"); + defer s.deinit(); + var tmp = std.testing.tmpDir(.{}); + defer tmp.cleanup(); + try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "note.txt", .data = "from pane directory\n" }); + var dir_buf: [4096]u8 = undefined; + const dir = dir_buf[0..try tmp.dir.realPath(std.testing.io, &dir_buf)]; + const n = try s.focused(); + const name = s.at("/pane/{d}/name", .{n}); + try s.write(name, s.at("{s}/old.txt\n", .{dir})); + try s.write(name, "child/../note.txt\n"); + try s.write(s.at("/pane/{d}/ctl", .{n}), "get\n"); + try s.expect(s.at("/pane/{d}/body", .{n}), "from pane directory\n"); + try s.write(name, "./created.txt\n"); + try s.expect(name, s.at("{s}/created.txt\n", .{dir})); + // A name alone is no edit. + try s.expect(s.at("/pane/{d}/dirty", .{n}), "0\n"); +} + +test "panes: relative names follow a pane/new scratch's session directory, and a virtual one" { + var s = try Session.initFile(std.testing.allocator, "source body\n"); + defer s.deinit(); + const source = try s.focused(); + try s.write(s.at("/pane/{d}/name", .{source}), "/elsewhere/source.zig\n"); + // pane/new's scratch is the session's, not the active pane's. + const n = try s.newPane(); + const name = s.at("/pane/{d}/name", .{n}); + const session = std.fs.path.dirname(std.mem.trimEnd(u8, try s.read(name), "\n")).?; + try std.testing.expect(!std.mem.eql(u8, session, "/elsewhere")); + const up = std.fs.path.dirname(session) orelse ""; + try s.write(name, "../out/./notes.txt\n"); + try s.expect(name, s.at("{s}/out/notes.txt\n", .{up})); + try s.write(name, "again.txt\n"); + try s.expect(name, s.at("{s}/out/again.txt\n", .{up})); + try s.write(name, s.at("/virtual/pane/{d}/./body\n", .{source})); + try s.write(s.at("/pane/{d}/ctl", .{n}), "get\n"); + try s.expect(s.at("/pane/{d}/body", .{n}), "source body\n"); + try s.write(name, "./body\n"); + try s.expect(name, s.at("/virtual/pane/{d}/body\n", .{source})); + try s.expect(s.at("/pane/{d}/dirty", .{n}), "0\n"); +} + +test "panes: errors appends to one +Errors pane for the pane's directory" { + var s = try Session.initFile(std.testing.allocator, "x\n"); + defer s.deinit(); + const n = try s.focused(); + try std.testing.expect(std.mem.indexOf(u8, try s.read("/index"), "+Errors") == null); + try s.write(s.at("/pane/{d}/errors", .{n}), "boom\n"); + try s.write(s.at("/pane/{d}/errors", .{n}), "again\n"); + const index = try s.read("/index"); + try std.testing.expectEqual(@as(usize, 1), std.mem.count(u8, index, " /+Errors ")); + const at = std.mem.indexOf(u8, index, " /+Errors ").?; + const line = index[(if (std.mem.lastIndexOfScalar(u8, index[0..at], '\n')) |i| i + 1 else 0)..]; + const serial = line[0..std.mem.indexOfScalar(u8, line, ' ').?]; + try s.expect(s.at("/pane/{s}/body", .{serial}), "boom\nagain\n"); +} + +test "panes: truncating body empties it, and a stat says the length after" { + var s = try Session.initFile(std.testing.allocator, "one\ntwo\n"); + defer s.deinit(); + const body = s.at("/pane/{d}/body", .{try s.focused()}); + const h = try s.hold(body, 1); + try s.truncate(h); + try std.testing.expectEqual(@as(u64, 0), (try s.stat(body)).size); + try s.expect(body, ""); + s.clunk(h); + try s.write(body, "new text\n"); + try std.testing.expectEqual(@as(u64, 9), (try s.stat(body)).size); +} diff --git a/test/behaviour/tags.zig b/test/behaviour/tags.zig index 6c1c6fcd..f4a5a469 100644 --- a/test/behaviour/tags.zig +++ b/test/behaviour/tags.zig @@ -397,3 +397,56 @@ test "tags: a name typed into the tag's path survives Esc, pending, and the next try s.expect(name, "/ztest.txt\n"); try std.testing.expect(std.mem.startsWith(u8, try s.read(s.at("/pane/{d}/tag", .{n})), "/ztest.txt ")); } + +test "tags: a pane's tag reads whole, its path first, and a write appends to its own text up to 4096 bytes" { + var s = try Session.initFile(std.testing.allocator, "x\n"); + defer s.deinit(); + const n = try s.focused(); + const path = s.at("/pane/{d}/tag", .{n}); + const whole = try tag(&s, n); + try std.testing.expect(std.mem.startsWith(u8, whole, "/test.txt")); + try std.testing.expect(std.mem.indexOf(u8, whole, "Del") != null); + try std.testing.expectEqual(@as(u64, whole.len), (try s.stat(path)).size); + try s.write(path, " Mine"); + try std.testing.expectEqualStrings(s.at("{s} Mine", .{whole}), try tag(&s, n)); + // A tag is a text like the body: a newline written to it stays one. + try s.write(path, "\nNext Line"); + try std.testing.expectEqualStrings(s.at("{s} Mine\nNext Line", .{whole}), try tag(&s, n)); + // Full, it takes not a byte more. + try s.replace(path, &@as([4096]u8, @splat('x'))); + try std.testing.expectEqual(@as(u16, 28), try s.refused(path, "x")); +} + +test "tags: truncating a tag clears its own text, u in the tag undoes it, and > drops the one newline ending it" { + var s = try Session.initFile(std.testing.allocator, "x\n"); + defer s.deinit(); + const n = try s.focused(); + const path = s.at("/pane/{d}/tag", .{n}); + try s.write(path, " Mine"); + // Done at the first read or write after it (or the close). + const h = try s.hold(path, 1); + try s.truncate(h); + try std.testing.expect(std.mem.indexOf(u8, try tag(&s, n), "Mine") == null); + s.clunk(h); + try std.testing.expectEqualStrings("/test.txt", std.mem.trimEnd(u8, try tag(&s, n), " ")); + // The tag keeps its undo: undoing in it brings back what was cleared. + try s.keys(":u:"); + try std.testing.expect(std.mem.endsWith(u8, try tag(&s, n), " Mine")); + // Written back without a leading space, the text still stands apart + // from the path, and a click on its first letter lands on it. + try s.replace(path, "Get"); + try std.testing.expectEqualStrings("/test.txt Get", try tag(&s, n)); + try s.click("Get", 0, 1); + try std.testing.expectEqual(@as(usize, "/test.txt ".len), try tagCol(&s, "/test.txt")); + // `echo Make > tag`: the newline ending the truncating write's text is + // dropped, one only; a newline between its writes stays. + const m = try s.hold(path, 1); + try s.truncate(m); + _ = try s.writeFid(m, "Make\n"); + _ = try s.writeFid(m, "More\n\n"); + s.clunk(m); + try std.testing.expectEqualStrings("/test.txt Make\nMore\n", try tag(&s, n)); + // `>>` keeps what it is given. + try s.write(path, " Tail\n"); + try std.testing.expectEqualStrings("/test.txt Make\nMore\n Tail\n", try tag(&s, n)); +} -- cgit v1.3 From 350e7cc22b85130cbe95a114c668945b1dc12fd7 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Wed, 4 Nov 2026 10:52:24 -0300 Subject: test: twenty-two more of src/ninep/ctl.zig's tests through the 9P tree alone: in test/behaviour/look_and_exec.zig a look opening a spaced path at its line and column leaving the source as it was, a batch validated whole before any virtual file opens, /status's lines, mode and refusal with look and exec validating batches and reading back their panes, a look at a file it may not read, a trailing colon dropped and a failed address opening nothing, a file:/re/ miss logged as its file's pane, a look into another pane leaving the source's dot, a word looked for in its own pane (wrapping, then LookWord list's +Search), a second LookWord list look refilling its +Search, @pN: and a line past the end said one way, an exec over the command limit, a builtin failing through exec, tagexec and a column's exec with one err and no msg, and Look . from a gone directory; in rules.zig every EINVAL's words, the log's too; in limits.zig a ctl line over 1 MiB refused once; in panes.zig acme's ctl words and +Unsaved dropping a closed pane's row; in the new from_acme.zig Put, Delete and acme's words refused; in settings.zig GUI-only settings and DumpDir read back; in root_ctl.zig Joincol and Theme's refusals and a theme's name in any case; in placement.zig a look from a pane made after Delcol placed in a column; in edit.zig Edit ,p logged with no room for +Errors; the status test kept for its window's pointer line, and Joincol's for themesNear's unit checks, each trimmed; each checked to fail against a break (status's pane count, a look's open failure words, the trailing colon kept, e_no_match, the empty name's words, the 1 MiB cap doubled, acme's Put renamed, the GUI-only words, themeIndex by case, command_max 1023, a repeat counted by two, Look .'s no such directory words, dropUnsaved doing nothing, lookWord not wrapping, limit=addr not taking, Edit's text not logged when unplaced, @pN: with no address a miss, a look into another pane clearing the source's dot, a column taken as the cursor's, the batch's control-character check and command's checking pass both skipped, LookWord's +Search never shared, atFoot placing nothing) Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge --- src/ninep/ctl.zig | 558 +-------------------------------------- test/behaviour.zig | 1 + test/behaviour/edit.zig | 12 + test/behaviour/from_acme.zig | 28 ++ test/behaviour/limits.zig | 22 ++ test/behaviour/look_and_exec.zig | 261 ++++++++++++++++++ test/behaviour/panes.zig | 45 ++++ test/behaviour/placement.zig | 20 ++ test/behaviour/root_ctl.zig | 18 ++ test/behaviour/rules.zig | 22 ++ test/behaviour/settings.zig | 20 ++ 11 files changed, 458 insertions(+), 549 deletions(-) create mode 100644 test/behaviour/from_acme.zig (limited to 'test/behaviour/look_and_exec.zig') diff --git a/src/ninep/ctl.zig b/src/ninep/ctl.zig index fc09c730..f23f2579 100644 --- a/src/ninep/ctl.zig +++ b/src/ninep/ctl.zig @@ -1466,118 +1466,16 @@ test "commands lists every builtin with its argument and the ctl that takes it" } -test "status reads the editor, and look and exec validate whole batches" { - const gpa = testing.allocator; - const p = try withFile(gpa, "Msg root\n"); +test "status in a window says whether the pointer is over it" { + // The rest of status is test/behaviour/look_and_exec.zig's: a session + // there is a terminal's view. + const p = try withFile(testing.allocator, "x\n"); defer p.deinit(); - // A terminal's view first (a window's build starts windowed). - p.windowed = false; - const status = rd(p, root_status, 0, 4096); - try testing.expectEqual(Status.ok, status.reply.status); - var lines = std.mem.tokenizeScalar(u8, status.bytes, '\n'); - try testing.expect(std.mem.startsWith(u8, lines.next().?, "pid ")); - var expected: [64]u8 = undefined; - try testing.expectEqualStrings(try std.fmt.bufPrint(&expected, "version {s}", .{pardes.version}), lines.next().?); - var live: usize = 0; - for (p.panes) |slot| live += @intFromBool(slot != null); - try testing.expectEqualStrings(try std.fmt.bufPrint(&expected, "panes {d}", .{live}), lines.next().?); - try testing.expect(lines.next() == null); - // A window says whether the pointer is over it. p.windowed = true; - var again = std.mem.tokenizeScalar(u8, rd(p, root_status, 0, 4096).bytes, '\n'); - for (0..3) |_| _ = again.next(); - try testing.expectEqualStrings("pointer out", again.next().?); + var lines = std.mem.tokenizeScalar(u8, rd(p, root_status, 0, 4096).bytes, '\n'); + for (0..3) |_| _ = lines.next(); + try testing.expectEqualStrings("pointer out", lines.next().?); p.windowed = false; - const stat = call(p, .{ .tag = 1, .op = .getattr, .node = root_status }); - try testing.expectEqual(@as(u64, status.bytes.len), stat.reply.attr.size); - try testing.expectEqual(@as(u16, 0o444), stat.reply.attr.mode); - try testing.expectEqual(E.PERM, wr(p, root_status, "anything\n").errno()); - try testing.expectEqualStrings("", rd(p, root_exec, 0, 4096).bytes); - - const serial = p.next_serial; - for ([_][]const u8{ "Msg a\x00b", "Msg x\nMsg \x01y\n" }) |invalid| { - try testing.expectEqual(E.INVAL, wr(p, root_exec, invalid).errno()); - try testing.expectEqual(serial, p.next_serial); - } - // An empty write is a no-op, not a command. - try testing.expectEqual(Status.ok, wr(p, root_exec, "\n \n").reply.status); - try testing.expectEqualStrings("", rd(p, root_exec, 0, 4096).bytes); - try testing.expectEqualStrings(status.bytes, rd(p, root_status, 0, 4096).bytes); - - const pane = p.panes[0].?; - try testing.expectEqual(Status.ok, wr(p, root_exec, "Msg hello there\n").reply.status); - try testing.expectEqualStrings("hello there", pane.msg[0..pane.msg_len]); - try testing.expectEqualStrings(try std.fmt.bufPrint(&expected, "{d}\n", .{pane.serial}), rd(p, root_exec, 0, 4096).bytes); - - try testing.expectEqual(Status.ok, wr(p, root_look, "/virtual/index\n").reply.status); - const opened = p.panes[p.active].?; - try testing.expectEqualStrings("/virtual/index", opened.file.?.path); - try testing.expectEqualStrings(try std.fmt.bufPrint(&expected, "{d}\n", .{opened.serial}), rd(p, root_look, 0, 4096).bytes); - - try testing.expectEqual(Status.ok, wr(p, root_exec, "New\n").reply.status); - const made = p.panes[p.active].?; - try testing.expect(made.serial != opened.serial); - try testing.expectEqualStrings(try std.fmt.bufPrint(&expected, "{d}\n", .{made.serial}), rd(p, root_exec, 0, 4096).bytes); -} - -test "look opens spaced paths and locations without editing the source pane" { - if (!fs.platform_has_fs) return error.SkipZigTest; - const gpa = testing.allocator; - var tmp = testing.tmpDir(.{}); - defer tmp.cleanup(); - try tmp.dir.writeFile(testing.io, .{ .sub_path = "two words.zig", .data = "first\nsecond\nthird\n" }); - var path_buf: [4096]u8 = undefined; - const path = path_buf[0..try tmp.dir.realPathFile(testing.io, "two words.zig", &path_buf)]; - const p = try withFile(gpa, "source stays intact\n"); - defer p.deinit(); - const source = p.panes[0].?; - const look_node = Node.of(source.serial, .look); - const revision = source.file.?.revision; - const undo_len = source.file.?.history.undo_len; - source.body.cur_col = 3; - var clicked: [4200]u8 = undefined; - try testing.expectEqual(Status.ok, wr(p, look_node, try std.fmt.bufPrint(&clicked, "{s}:2:3\n", .{path})).reply.status); - const opened = p.panes[p.active].?; - try testing.expect(opened != source); - try testing.expectEqualStrings(path, opened.file.?.path); - try testing.expectEqualStrings("first\nsecond\nthird\n", opened.file.?.content); - try testing.expectEqual(@as(i32, 1), opened.body.cur_row); - try testing.expectEqual(@as(i32, 2), opened.body.cur_col); - try testing.expectEqualStrings("source stays intact\n", source.file.?.content); - try testing.expectEqual(revision, source.file.?.revision); - try testing.expectEqual(undo_len, source.file.?.history.undo_len); - try testing.expectEqual(@as(i32, 3), source.body.cur_col); - var expected: [16]u8 = undefined; - try testing.expectEqualStrings(try std.fmt.bufPrint(&expected, "{d}\n", .{opened.serial}), rd(p, root_look, 0, 4096).bytes); - - p.active = 0; - try testing.expectEqual(Status.ok, wr(p, root_look, try std.fmt.bufPrint(&clicked, "{s}:3:2\n", .{path})).reply.status); - try testing.expect(p.panes[p.active].? == opened); - try testing.expectEqual(@as(i32, 2), opened.body.cur_row); - try testing.expectEqual(@as(i32, 1), opened.body.cur_col); - try testing.expectEqualStrings(try std.fmt.bufPrint(&expected, "{d}\n", .{opened.serial}), rd(p, root_look, 0, 4096).bytes); -} - -test "look validates the whole batch before opening virtual files" { - const gpa = testing.allocator; - const p = try withFile(gpa, "source\n"); - defer p.deinit(); - const source = p.panes[0].?; - const look_node = Node.of(source.serial, .look); - const serial = p.next_serial; - for ([_][]const u8{ - "/virtual/index\x00ignored", "/virtual/index\n/virtual/\x01index\n", - }) |invalid| { - try testing.expectEqual(E.INVAL, wr(p, look_node, invalid).errno()); - try testing.expectEqual(serial, p.next_serial); - try testing.expectEqual(@as(usize, 0), p.active); - try testing.expectEqualStrings("source\n", source.file.?.content); - } - try testing.expectEqual(Status.ok, wr(p, look_node, "/n/self/index\n").reply.status); - const opened = p.panes[p.active].?; - try testing.expectEqualStrings("/virtual/index", opened.file.?.path); - try testing.expect(std.mem.indexOf(u8, opened.file.?.content, "/test.txt") != null); - try testing.expectEqualStrings("source\n", source.file.?.content); } @@ -1795,55 +1693,6 @@ test "a refusal's +Unsaved goes in the session's directory when the active pane' try testing.expectEqualStrings(p.sessionDir(), std.fs.path.dirname(unsaved).?); } -test "a look at a file it may not read fails the write naming the file" { - if (comptime !pardes.hosted) return; - const p = try withFile(testing.allocator, "x\n"); - defer p.deinit(); - var tmp = testing.tmpDir(.{}); - defer tmp.cleanup(); - try tmp.dir.writeFile(testing.io, .{ .sub_path = "locked.txt", .data = "secret\n", .flags = .{ .permissions = .fromMode(0o000) } }); - var dir_buf: [4096]u8 = undefined; - const dir = dir_buf[0..try tmp.dir.realPath(testing.io, &dir_buf)]; - var line: [4200]u8 = undefined; - const path = try std.fmt.bufPrint(&line, "{s}/locked.txt", .{dir}); - var want: [4200]u8 = undefined; - const expected = try std.fmt.bufPrint(&want, "look: {s}: permission denied", .{path}); - var with_newline: [4300]u8 = undefined; - const refused = wr(p, root_look, try std.fmt.bufPrint(&with_newline, "{s}\n", .{path})); - if (refused.reply.status == .ok) return error.SkipZigTest; // root reads anything - try testing.expectEqualStrings(expected, refused.reply.ename); -} - -test "a look line's trailing colon is dropped, and a look whose address fails never leaves its file open" { - const p = try withFile(testing.allocator, "x\n"); - defer p.deinit(); - var tmp = testing.tmpDir(.{}); - defer tmp.cleanup(); - try tmp.dir.writeFile(testing.io, .{ .sub_path = "a.txt", .data = "one\ntwo\nthree\n" }); - var dir_buf: [4096]u8 = undefined; - const dir = dir_buf[0..try tmp.dir.realPath(testing.io, &dir_buf)]; - var line: [4200]u8 = undefined; - const count = struct { - fn of(pp: *Pardes) usize { - var n: usize = 0; - for (pp.panes) |slot| n += @intFromBool(slot != null); - return n; - } - }.of; - const before = count(p); - // Failing addresses: nothing opened, the write still answered. - inline for ([_][]const u8{ "{s}/a.txt:/nomatch/\n", "{s}/a.txt:9:\n" }) |fmt| { - _ = wr(p, root_look, try std.fmt.bufPrint(&line, fmt, .{dir})); - try testing.expectEqual(before, count(p)); - } - // `a.txt:2:3:` is `a.txt:2:3`: it opens there. - try testing.expectEqual(Status.ok, wr(p, root_look, try std.fmt.bufPrint(&line, "{s}/a.txt:2:3:\n", .{dir})).reply.status); - try testing.expectEqual(before + 1, count(p)); - const opened = p.panes[p.active].?; - try testing.expect(std.mem.endsWith(u8, opened.file.?.path, "/a.txt")); - try testing.expectEqual(@as(i32, 1), opened.body.cur_row); -} - 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; @@ -2019,32 +1868,10 @@ test "after a ThemeFile the root ctl and DumpConfig say ThemeFile and its path, try testing.expectEqual(Status.ok, wr(p, root_ctl, "ThemeFile " ++ path ++ "\n").reply.status); } -test "Joincol with no column to the right and Theme with no such theme say so" { - const gpa = testing.allocator; - const p = try withFile(gpa, "x\n"); - defer p.deinit(); - const root_ctl = @backingInt(tree.TopFile.ctl); - const joined = wr(p, root_ctl, "Joincol\n"); - try testing.expectEqual(tree.Status.err, joined.reply.status); - try testing.expectStringStartsWith(joined.reply.ename, "Joincol: no column to the right"); - const themed = wr(p, root_ctl, "Theme drak\n"); - try testing.expectEqual(E.INVAL, themed.errno()); - try testing.expectStringStartsWith(themed.reply.ename, "bad value in control message; like it: "); - try testing.expect(std.mem.indexOf(u8, themed.reply.ename, ": dr") != null); - try testing.expect(std.mem.endsWith(u8, themed.reply.ename, "\"drak\"")); - // A click on the word says it on the message row. - _ = wr(p, Node.of(serialOf(p), .exec), "Theme drak\n"); - const pane = p.panes[p.active].?; - try testing.expect(std.mem.indexOf(u8, pane.msg[0..pane.msg_len], "no theme \"drak\"") != null); - // Within the 128 bytes an Rerror carries, the quoted line kept. - try testing.expect(themed.reply.ename.len <= 128); - // A name in any case is the theme. - try testing.expectEqual(Status.ok, wr(p, root_ctl, "Theme DRACULA\n").reply.status); - try testing.expectEqualStrings("dracula", pardes.themes[p.settings.theme].name); - // A misspelling far from any first letter's list still finds its like. +test "themesNear finds a misspelling's like far from any first letter, and every theme sharing the first letter when they fit" { + // Joincol and Theme's refusals are test/behaviour/root_ctl.zig's. var near: [170]u8 = undefined; try testing.expect(std.mem.indexOf(u8, pardes.colors.themesNear(&near, "9dracula"), "dracula") != null); - // Every theme sharing the first letter, when they fit. var tested = false; for ("abcdefghijklmnopqrstuvwxyz") |letter| { var count: usize = 0; @@ -2081,26 +1908,6 @@ test "a look whose pane is refused a place fails with that alone, not a missing try testing.expectEqual(@as(usize, 1), th.logCount(p, "\nerr ")); } -test "a look under pardes's placement, from a pane pane/new made after Delcol, opens its file" { - const gpa = testing.allocator; - const p = try withFile(gpa, "x\n"); - defer p.deinit(); - var tmp = testing.tmpDir(.{}); - defer tmp.cleanup(); - try tmp.dir.writeFile(testing.io, .{ .sub_path = "f.txt", .data = "file\n" }); - var dir: [4096]u8 = undefined; - const at = dir[0..try tmp.dir.realPath(testing.io, &dir)]; - var line: [4200]u8 = undefined; - const first = serialOf(p); - try testing.expectEqual(tree.Status.ok, wr(p, Node.of(first, .exec), "Placement\n").reply.status); - try testing.expectEqual(tree.Status.ok, wr(p, Node.of(first, .exec), "Delcol\n").reply.status); - const made = try th.newPane(p); - try testing.expectEqual(tree.Status.ok, wr(p, Node.of(made, .look), try std.fmt.bufPrint(&line, "{s}/f.txt:#4\n", .{at})).reply.status); - // The pane pane/new made is placed, and so is the one its look opened. - for (p.panes, 0..) |slot, i| if (slot != null) try testing.expect(layout.findPane(p, i) != null); - try testing.expect(p.panes[p.active].?.serial != made); -} - test "a Restore of a file that is no dump fails the write before any warning, and a failed Dump fails its write" { if (comptime !pardes.hosted) return error.SkipZigTest; const p = try withFile(testing.allocator, "x\n"); @@ -2133,58 +1940,6 @@ test "a Restore of a file that is no dump fails the write before any warning, an try testing.expectEqualStrings("Dump /dev/null/pardes.dump.zon: /dev/null is not a directory", p.fs.late_failure[0..p.fs.late_failure_len]); } -test "a setting this frontend cannot show says GUI-only, and DumpDir reads back the directory in effect" { - const p = try withFile(testing.allocator, "x\n"); - defer p.deinit(); - const root_ctl = @backingInt(tree.TopFile.ctl); - if (!builtins.viewCapabilities(p).lift) { - try testing.expectEqualStrings("Lift is GUI-only, invalid here \"Lift\"", wr(p, root_ctl, "Lift on\n").reply.ename); - try testing.expectEqualStrings("GripWidth is GUI-only, invalid here \"GripWidth\"", wr(p, root_ctl, "GripWidth 120\n").reply.ename); - // A builtin the GUI alone has, written to a ctl or an exec, never - // runs as a shell command. - if (comptime !pardes.font_picker) { - try testing.expectEqualStrings("Fonts is GUI-only, invalid here \"Fonts\"", wr(p, root_ctl, "Fonts\n").reply.ename); - const ran = wr(p, root_exec, "Fonts\n"); - try testing.expectEqual(E.INVAL, ran.errno()); - try testing.expectEqualStrings("Fonts is GUI-only, invalid here", ran.reply.ename); - } - } - try testing.expectEqualStrings("unknown control message \"Liftt\"", wr(p, root_ctl, "Liftt on\n").reply.ename); - var buf: [900]u8 = undefined; - if (pardes.dump.directory(&buf, "")) |dir| { - var want: [920]u8 = undefined; - const line = try std.fmt.bufPrint(&want, "\nDumpDir {s}\n", .{dir}); - try testing.expect(std.mem.indexOf(u8, rd(p, root_ctl, 0, 1 << 16).bytes, line) != null); - } -} - -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(); - const long = "echo " ++ &@as([pardes.exec.command_max]u8, @splat('y')) ++ "\n"; - const refused = wr(p, root_exec, long); - try testing.expectEqual(E.INVAL, refused.errno()); - try testing.expectEqualStrings(e_too_long, refused.reply.ename); - var rec: [96]u8 = undefined; - try testing.expect(th.logHas(p, try std.fmt.bufPrint(&rec, "err {d} exec: invalid command line: a command line is at most 1024 bytes", .{serialOf(p)}))); - try testing.expectEqualStrings(e_control, wr(p, root_exec, "echo a\x01b\n").reply.ename); - try testing.expect(th.logHas(p, try std.fmt.bufPrint(&rec, "err {d} exec: invalid command line: it holds", .{serialOf(p)}))); - try testing.expectEqual(Status.ok, wr(p, root_exec, "Msg " ++ &@as([1100]u8, @splat('z')) ++ "\n").reply.status); -} - -test "Edit's p and = never fail for want of room for +Errors: the text is logged instead" { - const p = try withFile(testing.allocator, "one\ntwo\n"); - defer p.deinit(); - p.update(.{ .resize = .{ .cols = 80, .rows = 6 } }); - const ctl_node = Node.of(serialOf(p), .ctl); - try testing.expectEqual(Status.ok, wr(p, ctl_node, "Edit ,p\n").reply.status); - try testing.expect(th.logHas(p, " one\n") and th.logHas(p, " two\n")); - p.sync(); - var count: usize = 0; - for (p.panes) |slot| count += @intFromBool(slot != null); - try testing.expectEqual(@as(usize, 1), count); // the +Errors that had no room is gone -} - test "Mount dials its peer and fails, mounting nothing, when none answers; a look through a peer gone says dial failed" { const p = try withFile(testing.allocator, "x\n"); @@ -2560,31 +2315,6 @@ test "Grep, Symbols and Diagnostics share their directory's one +Search" { try testing.expectEqual(@as(usize, 1), searches); } -test "+Unsaved drops a pane once it has closed" { - const p = try withFile(testing.allocator, "x\n"); - defer p.deinit(); - const a = try th.newPane(p); - _ = wr(p, Node.of(a, .name), "/tmp/pardes-unsaved-a.txt\n"); - _ = wr(p, Node.of(a, .body), "edited\n"); - const b = try th.newPane(p); - _ = wr(p, Node.of(b, .name), "/tmp/pardes-unsaved-b.txt\n"); - _ = wr(p, Node.of(b, .body), "edited\n"); - const root_ctl = @backingInt(tree.TopFile.ctl); - try testing.expectEqual(Status.err, wr(p, root_ctl, "Exit\n").reply.status); - var listed: ?*pardes.Pane = null; - for (p.panes) |slot| if (slot) |q| if (q.file) |f| if (f.output) |o| if (o.from == .unsaved) { - listed = q; - }; - const list = listed.?; - try testing.expect(std.mem.indexOf(u8, list.file.?.content, "/tmp/pardes-unsaved-a.txt: Modified") != null); - // a closes (discarded): its row goes; b's stays. - _ = wr(p, Node.of(a, .ctl), "Del\n"); - _ = wr(p, Node.of(a, .ctl), "Del\n"); - p.sync(); - try testing.expect(p.paneBySerial(a) == null); - try testing.expect(std.mem.indexOf(u8, list.file.?.content, "/tmp/pardes-unsaved-a.txt: Modified") == null); -} - test "a buffer whose file was deleted on disk is dirty, and Del asks first" { const p = try withFile(testing.allocator, "x\n"); defer p.deinit(); @@ -2609,23 +2339,6 @@ test "a failure said while a 9P write waits on it posts no msg, only the write's try testing.expect(p.fs.late_failure_len > 0); } -test "a look that misses file:/re/ names the file, and is logged as its pane's" { - const p = try withFile(testing.allocator, "x\n"); - defer p.deinit(); - var tmp = testing.tmpDir(.{}); - defer tmp.cleanup(); - try tmp.dir.writeFile(testing.io, .{ .sub_path = "f.txt", .data = "alpha\n" }); - var dir_buf: [4096]u8 = undefined; - const dir = dir_buf[0..try tmp.dir.realPath(testing.io, &dir_buf)]; - var line: [4200]u8 = undefined; - _ = wr(p, root_look, try std.fmt.bufPrint(&line, "{s}/f.txt\n", .{dir})); - p.sync(); - const f_serial = p.panes[p.active].?.serial; - _ = wr(p, Node.of(serialOf(p), .look), try std.fmt.bufPrint(&line, "{s}/f.txt:/zzqq/\n", .{dir})); - var want: [4300]u8 = undefined; - try testing.expect(th.logHas(p, try std.fmt.bufPrint(&want, "err {d} look: {s}/f.txt: no match for regexp", .{ f_serial, dir }))); -} - test "with no pane at all, the root look opens its file and the root exec runs in the session's directory" { const p = try withFile(testing.allocator, "x\n"); defer p.deinit(); @@ -2730,61 +2443,6 @@ test "a Restore of a name in the DumpDir asks for, and logs, the whole path it r } -test "acme's words run as pardes's (Put is Save, Delete a Del that does not ask) or are refused, never run as commands" { - const p = try withFile(testing.allocator, "x\n"); - defer p.deinit(); - const serial = serialOf(p); - for ([_][]const u8{ "Snarf\n", "Indent\n", "Local\n", "Abort\n" }) |line| { - for ([_]u64{ Node.of(serial, .ctl), Node.of(serial, .exec) }) |node| { - const r = wr(p, node, line); - try testing.expectEqual(E.INVAL, r.errno()); - try testing.expect(std.mem.indexOf(u8, r.reply.ename, "is not a pardes builtin") != null); - } - } - // Load is Restore: whatever it says, never acme's word refused. - const load = wr(p, Node.of(serial, .exec), "Load /tmp/pardes-surely-no-dump.zon\n"); - try testing.expect(std.mem.indexOf(u8, load.reply.ename, "is not a pardes builtin") == null); - // Put saves, as Save does. - _ = wr(p, Node.of(serial, .name), "/tmp/pardes-put.txt\n"); - const put = wr(p, Node.of(serial, .exec), "Put\n"); - try testing.expectEqual(Status.ok, put.reply.status); - try testing.expect(put.saved); - // Delete closes an edited pane without asking. - const made = try th.newPane(p); - _ = wr(p, Node.of(made, .name), "/tmp/pardes-delete.txt\n"); - _ = wr(p, Node.of(made, .body), "edited\n"); - try testing.expectEqual(Status.ok, wr(p, Node.of(made, .ctl), "Delete\n").reply.status); - p.sync(); - try testing.expect(p.paneBySerial(made) == null); -} - -test "a pane's ctl takes acme's words: done by the files that replace them, or refused with why" { - const p = try withFile(testing.allocator, "one two\n"); - defer p.deinit(); - const serial = serialOf(p); - const ctl_node = Node.of(serial, .ctl); - const pane = p.panes[p.paneBySerial(serial).?].?; - try testing.expectEqual(Status.ok, wr(p, ctl_node, "name /tmp/pardes-acme-ctl.txt\n").reply.status); - try testing.expectEqualStrings("/tmp/pardes-acme-ctl.txt", pane.file.?.path); - try testing.expectEqual(Status.ok, wr(p, ctl_node, "dirty\n").reply.status); - try testing.expectEqualStrings("1", std.mem.trimEnd(u8, rd(p, Node.of(serial, .dirty), 0, 8).bytes, "\n")); - try testing.expectEqual(Status.ok, wr(p, ctl_node, "clean\n").reply.status); - try testing.expectEqualStrings("0", std.mem.trimEnd(u8, rd(p, Node.of(serial, .dirty), 0, 8).bytes, "\n")); - _ = wr(p, Node.of(serial, .addr), "/two/"); - try testing.expectEqual(Status.ok, wr(p, ctl_node, "dot=addr\nshow\nnomark\nmark\nlimit=addr\n").reply.status); - try testing.expectEqual(@as(u32, 4), pane_files.dotOf(pane).q0); - try testing.expect(pane.fs.limit != null); - try testing.expectEqual(Status.ok, wr(p, ctl_node, "cleartag\n").reply.status); - for ([_][]const u8{ "menu", "nomenu", "dump echo hi", "dumpdir /tmp", "font Go Mono" }) |line| { - const r = wr(p, ctl_node, line); - try testing.expectEqual(E.INVAL, r.errno()); - try testing.expect(std.mem.startsWith(u8, r.reply.ename, "invalid: acme's ")); - } - // Checked whole: a refused word anywhere and nothing ran. - try testing.expectEqual(E.INVAL, wr(p, ctl_node, "dirty\nmenu\n").errno()); - try testing.expectEqualStrings("0", std.mem.trimEnd(u8, rd(p, Node.of(serial, .dirty), 0, 8).bytes, "\n")); -} - test "a write to addr, limit or mark asks for no frame; one to body does" { const p = try withFile(testing.allocator, "one\n"); defer p.deinit(); @@ -2799,28 +2457,6 @@ test "a write to addr, limit or mark asks for no frame; one to body does" { try testing.expect(p.needs_frame); } -test "every EINVAL a write gets says why, in its err record too; DEL is a control character in a line" { - const p = try withFile(testing.allocator, "x\n"); - defer p.deinit(); - const serial = serialOf(p); - const log = @backingInt(tree.TopFile.log); - const h = call(p, .{ .tag = 1, .op = .open, .node = log, .omode = 2 }).reply.handle; - const Case = struct { node: u64, data: []const u8, words: []const u8, handle: u32 = 0 }; - for ([_]Case{ - .{ .node = root_exec, .data = "echo a\x7fb\n", .words = "control character" }, - .{ .node = root_look, .data = "a\x7fb\n", .words = "control character" }, - .{ .node = Node.of(serial, .name), .data = "\n", .words = "an empty name" }, - .{ .node = log, .data = "bogus\n", .words = "takes `follow`", .handle = h }, - }) |c| { - const refused = call(p, .{ .tag = 2, .op = .write, .node = c.node, .handle = c.handle, .data = c.data }); - try testing.expectEqual(E.INVAL, refused.errno()); - try testing.expect(std.mem.indexOf(u8, refused.reply.ename, c.words) != null); - } - _ = call(p, .{ .tag = 3, .op = .release, .node = log, .handle = h }); - try testing.expect(!th.logHas(p, "Invalid argument")); - try testing.expect(th.logHas(p, "an empty name")); -} - test "/index shows a name as the log does: a newline in it is \\n, a control byte, C1 or byte not UTF-8 \\xNN" { const p = try th.withTerm(testing.allocator); defer p.deinit(); @@ -2841,31 +2477,6 @@ test "/index shows a name as the log does: a newline in it is \\n, a control byt try testing.expect(std.mem.indexOf(u8, rd(p, @backingInt(tree.TopFile.index), 0, 4096).bytes, "/tmp/back\\\\nslash") != null); } -test "a served-tree pane spoils no Grep, and Look . from a gone directory is ENOENT, not /virtual/" { - const p = try withFile(testing.allocator, "x\n"); - defer p.deinit(); - var tmp = testing.tmpDir(.{}); - defer tmp.cleanup(); - try tmp.dir.writeFile(testing.io, .{ .sub_path = "hit.txt", .data = "needle here\n" }); - var dir_buf: [4096]u8 = undefined; - const dir = dir_buf[0..try tmp.dir.realPath(testing.io, &dir_buf)]; - var line: [4200]u8 = undefined; - _ = wr(p, Node.of(serialOf(p), .name), try std.fmt.bufPrint(&line, "{s}/other.txt\n", .{dir})); - // A pane of the served tree. - const virtual = try th.newPane(p); - _ = wr(p, Node.of(virtual, .name), "/virtual/index\n"); - // One named the served tree's root, whose directory is `/`. - const top = try th.newPane(p); - _ = wr(p, Node.of(top, .name), "/virtual\n"); - try testing.expectEqual(Status.ok, wr(p, Node.of(serialOf(p), .exec), "Grep needle\n").reply.status); - // `.` from a pane whose directory is gone. - const gone = try th.newPane(p); - _ = wr(p, Node.of(gone, .name), "/tmp/pardes-no-such-dir-zz/f.txt\n"); - const looked = wr(p, Node.of(gone, .look), ".\n"); - try testing.expectEqual(E.NOENT, looked.errno()); - try testing.expectStringStartsWith(looked.reply.ename, "look: /tmp/pardes-no-such-dir-zz: no such directory"); -} - test "a column takes panes until their documented minimums fill it, not until none can be halved" { const p = try Pardes.init(testing.allocator, .{ .tty_only = true, .cols = 160, .rows = 50 }); defer p.deinit(); @@ -3335,39 +2946,6 @@ test "a file changed on disk under unsaved edits is not reloaded: it says so, ge try testing.expect(wr(p, Node.of(serial, .ctl), "Save\n").saved); } -test "a looked word is found in its own pane, next place after the dot, wrapping, and opens no pane" { - const p = try withFile(testing.allocator, "foo x foo y\n"); - defer p.deinit(); - const serial = serialOf(p); - const look_node = Node.of(serial, .look); - const dot = Node.of(serial, .dot); - var count: usize = 0; - for (p.panes) |slot| count += @intFromBool(slot != null); - for ([_][]const u8{ " 0 3 ", " 6 9 ", " 0 3 " }) |want| { - try testing.expectEqual(Status.ok, wr(p, look_node, "foo\n").reply.status); - try testing.expectEqualStrings(want, rd(p, dot, 0, 64).bytes); - } - var after: usize = 0; - for (p.panes) |slot| after += @intFromBool(slot != null); - try testing.expectEqual(count, after); - // LookWord list: the +Search listing, as before. - try testing.expect(p.executeBuiltinLine(0, "LookWord list")); - try testing.expectEqual(Status.ok, wr(p, look_node, "foo\n").reply.status); - after = 0; - for (p.panes) |slot| after += @intFromBool(slot != null); - try testing.expect(after > count); - // ...and look reads back that +Search pane, where the places are. - var listed = false; - var rows = std.mem.tokenizeScalar(u8, rd(p, look_node, 0, 256).bytes, '\n'); - while (rows.next()) |row| { - const made = p.panes[p.paneBySerial(try std.fmt.parseInt(u32, row, 10)).?].?; - if (made.file) |f| if (f.output) |o| if (o.from == .search) { - listed = true; - }; - } - try testing.expect(listed); -} - test "every word's /commands description is its own doc comment's first sentence, no citation" { const p = try withFile(testing.allocator, "x\n"); defer p.deinit(); @@ -3478,37 +3056,6 @@ test "get names the path it could not read, logs the edits it threw away, and a _ = call(p, .{ .tag = 3, .op = .release, .node = log, .handle = h }); } -test "a builtin that fails through exec, tagexec or a column's exec fails the write with one err and no msg" { - 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 serial = serialOf(p); - for ([_]u64{ root_exec, Node.of(serial, .exec), @backingInt(tree.TopFile.tagexec), Node.ofCol(pardes.layout.columnSerial(p, 0), .exec) }) |node| { - const failed = wr(p, node, "Unmount zzz\n"); - try testing.expectEqual(Status.err, failed.reply.status); - try testing.expect(std.mem.indexOf(u8, failed.reply.ename, "Unmount: no such mount zzz") != null); - } - 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.indexOf(u8, text, "msg ") == null); - // The root's exec ran at the pane, so its err and the pane's exec's are - // the same record, counted. - try testing.expectEqual(@as(usize, 3), std.mem.count(u8, text, "Unmount: no such mount zzz")); - try testing.expect(std.mem.indexOf(u8, text, "mount zzz (x2)") != null); - _ = call(p, .{ .tag = 3, .op = .release, .node = log, .handle = h }); - // A control character is refused with its reason. - try testing.expectEqualStrings(e_control, wr(p, root_exec, "Msg a\x01b\n").reply.ename); - // A look miss: one err, no msg. - _ = wr(p, @backingInt(tree.TopFile.look), "zzqqnotthere\n"); - try testing.expect(th.logHas(p, "look: no match for \"zzqqnotthere\"")); - try testing.expect(!th.logHas(p, "msg 1 Look: no match")); - // The same miss again is that record counted, as any repeated err is. - _ = wr(p, @backingInt(tree.TopFile.look), "zzqqnotthere\n"); - try testing.expect(th.logHas(p, "look: no match for \"zzqqnotthere\" (x2)\n")); -} - test "a word written to a raw terminal's look is listed as in normal mode" { const p = try th.withTerm(testing.allocator); defer p.deinit(); @@ -3522,30 +3069,6 @@ test "a word written to a raw terminal's look is listed as in normal mode" { try testing.expect(made.file.?.output.?.from == .search); } -test "a look that goes to another pane leaves the looking pane's dot alone" { - const p = try withFile(testing.allocator, "alpha bravo\ncharlie\n"); - defer p.deinit(); - const source = serialOf(p); - const other = try th.newPane(p); - _ = wr(p, Node.of(other, .body), "one\ntwo\nthree\n"); - var tmp = testing.tmpDir(.{}); - defer tmp.cleanup(); - try tmp.dir.writeFile(testing.io, .{ .sub_path = "f.txt", .data = "f one\nf two\n" }); - var dir_buf: [4096]u8 = undefined; - const dir = dir_buf[0..try tmp.dir.realPath(testing.io, &dir_buf)]; - var line: [4200]u8 = undefined; - for ([_][]const u8{ "@p{d}:2", "@p{d}:/three/", "{s}/f.txt:2" }) |form| { - @import("pane.zig").setDot(p.panes[p.paneBySerial(source).?].?, .{ .q0 = 6, .q1 = 11 }); - const text = if (form[0] == '@') - (if (std.mem.eql(u8, form, "@p{d}:2")) try std.fmt.bufPrint(&line, "@p{d}:2\n", .{other}) else try std.fmt.bufPrint(&line, "@p{d}:/three/\n", .{other})) - else - try std.fmt.bufPrint(&line, "{s}/f.txt:2\n", .{dir}); - try testing.expectEqual(Status.ok, wr(p, Node.of(source, .look), text).reply.status); - try testing.expect(p.active != p.paneBySerial(source).?); - try testing.expectEqualStrings(" 6 11 ", rd(p, Node.of(source, .dot), 0, 64).bytes); - } -} - test "@p:
takes any address over the terminal's lines, selecting the match" { const p = try th.withTerm(testing.allocator); defer p.deinit(); @@ -3713,45 +3236,6 @@ test "Edit on an image pane is refused as a data write there is, EINVAL, before try testing.expectEqual(E.INVAL, wr(p, Node.of(doc.serial, .name), "/tmp/other.ppm\n").errno()); } -test "`@pN:` looks at pane N as `a.txt:` looks at a.txt, and a line past the end is said one way, `:N` or `file:N`" { - const p = try withFile(testing.allocator, "one\ntwo\n"); - defer p.deinit(); - const s = serialOf(p); - var buf: [64]u8 = undefined; - p.look_missed = false; - pardes.look.lookAt(p, 0, try std.fmt.bufPrint(&buf, "@p{d}:", .{s})); - try testing.expect(!p.look_missed); - const f = pane_files.fileOf(p.panes[0].?).?; - for ([_][]const u8{ ":99999", try std.fmt.bufPrint(&buf, "{s}:99999", .{f.path}) }) |looked| { - pardes.look.lookAt(p, 0, looked); - const said = p.panes[0].?.msg[0..p.panes[0].?.msg_len]; - try testing.expect(std.mem.endsWith(u8, said, "/test.txt:99999 has no line 99999")); - } -} - -test "a second LookWord list look in a directory refills its +Search rather than stacking another" { - if (comptime !pardes.hosted) return; - const gpa = testing.allocator; - var tmp = testing.tmpDir(.{}); - defer tmp.cleanup(); - try tmp.dir.writeFile(testing.io, .{ .sub_path = "words.txt", .data = "alpha beta\nalpha beta\n" }); - var dir_buf: [4096]u8 = undefined; - const dir = dir_buf[0..try tmp.dir.realPath(testing.io, &dir_buf)]; - var path_buf: [4200]u8 = undefined; - const path = try std.fmt.bufPrint(&path_buf, "{s}/words.txt", .{dir}); - const p = try Pardes.init(gpa, .{ .file = path, .tty_only = true, .cols = 80, .rows = 30 }); - defer p.deinit(); - _ = wr(p, @backingInt(tree.TopFile.ctl), "LookWord list\n"); - pardes.look.lookAt(p, 0, "alpha"); - pardes.look.lookAt(p, 0, "beta"); - var searches: usize = 0; - for (p.panes) |slot| if (slot) |pn| if (pn.file) |f| if (std.mem.endsWith(u8, f.path, "+Search")) { - searches += 1; - try testing.expectEqualStrings("beta", f.output.?.arg()); - }; - try testing.expectEqual(@as(usize, 1), searches); -} - test "Petscii, Palette and Ascii take the state their tag word names, set rather than flipped" { const p = try withFile(testing.allocator, "x\n"); defer p.deinit(); @@ -3828,30 +3312,6 @@ test "Lspinfo's answer is the +Lsp pane it fills, as a Rename preview's is its + } -test "a ctl line over 1 MiB is refused once, EINVAL, and its tail is not run as a line of its own" { - const p = try withFile(testing.allocator, "x\n"); - defer p.deinit(); - const node = Node.of(serialOf(p), .ctl); - const h = call(p, .{ .tag = 1, .op = .open, .node = node, .omode = 1 }).reply.handle; - const chunk: [4096]u8 = @splat('z'); - var refused: usize = 0; - var off: u64 = 0; - for (0..270) |_| { - const r = call(p, .{ .tag = 2, .op = .write, .node = node, .handle = h, .off = off, .data = &chunk }); - if (r.reply.status == .err) { - refused += 1; - try testing.expectEqual(E.INVAL, r.errno()); - } - off += chunk.len; - } - try testing.expectEqual(Status.ok, call(p, .{ .tag = 3, .op = .write, .node = node, .handle = h, .off = off, .data = "zzz\nEdit ,d\n" }).reply.status); - try testing.expectEqual(@as(usize, 1), refused); - try testing.expect(!th.logHas(p, "unknown control message")); - // What came after the long line's newline ran. - try testing.expectEqualStrings("", pane_files.fileOf(p.panes[0].?).?.content); - _ = call(p, .{ .tag = 4, .op = .release, .node = node, .handle = h }); -} - test "DumpDir refuses a relative directory and one that may not be written, up front; a Dump there says permission denied" { if (comptime !pardes.hosted) return; const p = try withFile(testing.allocator, "x\n"); diff --git a/test/behaviour.zig b/test/behaviour.zig index 72806b21..c6e1dc9d 100644 --- a/test/behaviour.zig +++ b/test/behaviour.zig @@ -8,6 +8,7 @@ test { _ = @import("behaviour/edit.zig"); _ = @import("behaviour/event.zig"); _ = @import("behaviour/flags.zig"); + _ = @import("behaviour/from_acme.zig"); _ = @import("behaviour/keys.zig"); _ = @import("behaviour/limits.zig"); _ = @import("behaviour/log.zig"); diff --git a/test/behaviour/edit.zig b/test/behaviour/edit.zig index bfb17533..83b1b464 100644 --- a/test/behaviour/edit.zig +++ b/test/behaviour/edit.zig @@ -45,3 +45,15 @@ test "edit: Edit through a pane's ctl renames every foo in one undo step, and a try s.write(ctl, "Undo"); try s.expect(body, "foo x foo y foo\n"); } + +test "edit: Edit's p and = never fail for want of room for +Errors: the text is logged instead" { + var s = try Session.initFile(std.testing.allocator, "one\ntwo\n"); + defer s.deinit(); + s.detach(); + try s.write("/ctl", "size 80 6\n"); + const index = try s.read("/index"); + try s.write(s.at("/pane/{d}/ctl", .{try s.focused()}), "Edit ,p\n"); + const log = try s.read("/log"); + try std.testing.expect(std.mem.indexOf(u8, log, " one\n") != null and std.mem.indexOf(u8, log, " two\n") != null); + try s.expect("/index", index); // the +Errors that had no room is gone +} diff --git a/test/behaviour/from_acme.zig b/test/behaviour/from_acme.zig new file mode 100644 index 00000000..62d4fc55 --- /dev/null +++ b/test/behaviour/from_acme.zig @@ -0,0 +1,28 @@ +//! docs/typ/reference.typ, Coming from acme . +const std = @import("std"); +const Session = @import("session").Session; + +test "from-acme: acme's words run as pardes's (Put is Save, Delete a Del that does not ask) or are refused, never run as commands" { + var s = try Session.initFile(std.testing.allocator, "x\n"); + defer s.deinit(); + const n = try s.focused(); + for ([_][]const u8{ "Snarf\n", "Indent\n", "Local\n", "Abort\n" }) |line| { + for ([_][]const u8{ s.at("/pane/{d}/ctl", .{n}), s.at("/pane/{d}/exec", .{n}) }) |path| { + try std.testing.expectEqual(@as(u16, 22), try s.refused(path, line)); + try std.testing.expect(std.mem.indexOf(u8, s.said, "is not a pardes builtin") != null); + } + } + // Load is Restore: whatever it says, never acme's word refused. + _ = try s.refused(s.at("/pane/{d}/exec", .{n}), "Load /tmp/pardes-surely-no-dump.zon\n"); + try std.testing.expect(std.mem.indexOf(u8, s.said, "is not a pardes builtin") == null); + // Put saves, as Save does. + try s.write(s.at("/pane/{d}/name", .{n}), "/tmp/pardes-put.txt\n"); + try s.write(s.at("/pane/{d}/exec", .{n}), "Put\n"); + try std.testing.expectEqual(@as(usize, 1), s.saved); + // Delete closes an edited pane without asking. + const made = try s.newPane(); + try s.write(s.at("/pane/{d}/name", .{made}), "/tmp/pardes-delete.txt\n"); + try s.write(s.at("/pane/{d}/body", .{made}), "edited\n"); + try s.write(s.at("/pane/{d}/ctl", .{made}), "Delete\n"); + try std.testing.expect(std.mem.indexOf(u8, try s.read("/index"), "/tmp/pardes-delete.txt") == null); +} diff --git a/test/behaviour/limits.zig b/test/behaviour/limits.zig index 08c864eb..d84d4490 100644 --- a/test/behaviour/limits.zig +++ b/test/behaviour/limits.zig @@ -16,3 +16,25 @@ test "limits: a builtin that needs a pane says so when every slot is taken" { try std.testing.expectEqualStrings("help: no space for a pane: 64 max", s.said); try std.testing.expect(std.mem.indexOf(u8, try s.read("/log"), "help: no space for a pane") != null); } + +test "limits: a ctl line over 1 MiB is refused once, EINVAL, and its tail is not run as a line of its own" { + var s = try Session.initFile(std.testing.allocator, "x\n"); + defer s.deinit(); + const n = try s.focused(); + const ctl = try s.hold(s.at("/pane/{d}/ctl", .{n}), 1); + const chunk: [4096]u8 = @splat('z'); + var refused: usize = 0; + for (0..270) |_| { + const errno = try s.writeFid(ctl, &chunk); + if (errno != 0) { + refused += 1; + try std.testing.expectEqual(@as(u16, 22), errno); + } + } + try std.testing.expectEqual(@as(u16, 0), try s.writeFid(ctl, "zzz\nEdit ,d\n")); + s.clunk(ctl); + try std.testing.expectEqual(@as(usize, 1), refused); + try std.testing.expect(std.mem.indexOf(u8, try s.read("/log"), "unknown control message") == null); + // What came after the long line's newline ran. + try s.expect(s.at("/pane/{d}/body", .{n}), ""); +} diff --git a/test/behaviour/look_and_exec.zig b/test/behaviour/look_and_exec.zig index 360055d2..2ce95354 100644 --- a/test/behaviour/look_and_exec.zig +++ b/test/behaviour/look_and_exec.zig @@ -433,3 +433,264 @@ test "look-and-exec: a builtin that takes no argument, written with one to an ex try std.testing.expect(std.mem.startsWith(u8, s.said, "wrong #args in control message")); }; } + +/// A fresh directory's absolute path, kept until deinit. +fn tmpPath(s: *Session, tmp: *std.testing.TmpDir) ![]const u8 { + var buf: [4096]u8 = undefined; + return s.at("{s}", .{buf[0..try tmp.dir.realPath(std.testing.io, &buf)]}); +} + +test "look-and-exec: a look opens spaced paths and locations without editing the source pane" { + var tmp = std.testing.tmpDir(.{}); + defer tmp.cleanup(); + try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "two words.zig", .data = "first\nsecond\nthird\n" }); + var s = try Session.initFile(std.testing.allocator, "source stays intact\n"); + defer s.deinit(); + const path = s.at("{s}/two words.zig", .{try tmpPath(&s, &tmp)}); + const source = try s.focused(); + const ctl = try s.read(s.at("/pane/{d}/ctl", .{source})); + try s.write(s.at("/pane/{d}/dot", .{source}), "3 3"); + try s.write(s.at("/pane/{d}/look", .{source}), s.at("{s}:2:3\n", .{path})); + const opened = try s.focused(); + try std.testing.expect(opened != source); + try s.expect(s.at("/pane/{d}/name", .{opened}), s.at("{s}\n", .{path})); + try s.expect(s.at("/pane/{d}/body", .{opened}), "first\nsecond\nthird\n"); + try expectEqual(@as(u32, 8), (try s.range(s.at("/pane/{d}/dot", .{opened})))[0]); // line 2, column 3 + // The source: its text, its undo steps and its cursor as they were. + try s.expect(s.at("/pane/{d}/body", .{source}), "source stays intact\n"); + try std.testing.expectEqualStrings(ctl[0..60], (try s.read(s.at("/pane/{d}/ctl", .{source})))[0..60]); + try expectEqual(.{ @as(u32, 3), @as(u32, 3) }, try s.range(s.at("/pane/{d}/dot", .{source}))); + try s.expect("/look", s.at("{d}\n", .{opened})); + // From the root, with the source focused: the same pane, moved. + try s.write("/focus", s.at("{d}\n", .{source})); + try s.write("/look", s.at("{s}:3:2\n", .{path})); + try expectEqual(opened, try s.focused()); + try expectEqual(@as(u32, 14), (try s.range(s.at("/pane/{d}/dot", .{opened})))[0]); // line 3, column 2 + try s.expect("/look", s.at("{d}\n", .{opened})); +} + +test "look-and-exec: a look validates the whole batch before opening virtual files" { + var s = try Session.initFile(std.testing.allocator, "source\n"); + defer s.deinit(); + const source = try s.focused(); + const look = s.at("/pane/{d}/look", .{source}); + const index = try s.read("/index"); + for ([_][]const u8{ "/virtual/index\x00ignored", "/virtual/index\n/virtual/\x01index\n" }) |invalid| { + try expectEqual(@as(u16, 22), try s.refused(look, invalid)); + try s.expect("/index", index); + try expectEqual(source, try s.focused()); + try s.expect(s.at("/pane/{d}/body", .{source}), "source\n"); + } + try s.write(look, "/n/self/index\n"); + const opened = try s.focused(); + try s.expect(s.at("/pane/{d}/name", .{opened}), "/virtual/index\n"); + try std.testing.expect(has(try s.read(s.at("/pane/{d}/body", .{opened})), "/test.txt")); + try s.expect(s.at("/pane/{d}/body", .{source}), "source\n"); +} + +test "look-and-exec: status reads the editor, and look and exec validate whole batches" { + var s = try Session.initFile(std.testing.allocator, "Msg root\n"); + defer s.deinit(); + const status = try s.read("/status"); + var rows = std.mem.tokenizeScalar(u8, status, '\n'); + try std.testing.expect(std.mem.startsWith(u8, rows.next().?, "pid ")); + try std.testing.expect(std.mem.startsWith(u8, rows.next().?, "version ")); + try std.testing.expectEqualStrings(s.at("panes {d}", .{lines(try s.read("/index"))}), rows.next().?); + try std.testing.expect(rows.next() == null); + const st = try s.stat("/status"); + try expectEqual(@as(u64, status.len), st.size); + try expectEqual(@as(u16, 0o444), st.mode & 0o777); + try expectEqual(@as(u16, 1), try s.refused("/status", "anything\n")); + try s.expect("/exec", ""); + const index = try s.read("/index"); + for ([_][]const u8{ "Msg a\x00b", "Msg x\nMsg \x01y\n" }) |invalid| { + try expectEqual(@as(u16, 22), try s.refused("/exec", invalid)); + try s.expect("/index", index); + } + // An empty write is a no-op, not a command. + try s.write("/exec", "\n \n"); + try s.expect("/exec", ""); + try s.expect("/status", status); + const n = try s.focused(); + try s.write("/exec", "Msg hello there\n"); + try std.testing.expect(has(try s.read("/log"), s.at("msg {d} hello there\n", .{n}))); + try s.expect("/exec", s.at("{d}\n", .{n})); + try s.write("/look", "/virtual/index\n"); + const opened = try s.focused(); + try s.expect(s.at("/pane/{d}/name", .{opened}), "/virtual/index\n"); + try s.expect("/look", s.at("{d}\n", .{opened})); + try s.write("/exec", "New\n"); + const made = try s.focused(); + try std.testing.expect(made != opened); + try s.expect("/exec", s.at("{d}\n", .{made})); +} + +test "look-and-exec: a look at a file it may not read fails the write naming the file" { + var tmp = std.testing.tmpDir(.{}); + defer tmp.cleanup(); + try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "locked.txt", .data = "secret\n", .flags = .{ .permissions = .fromMode(0o000) } }); + var s = try Session.initFile(std.testing.allocator, "x\n"); + defer s.deinit(); + const path = s.at("{s}/locked.txt", .{try tmpPath(&s, &tmp)}); + if (try s.refused("/look", s.at("{s}\n", .{path})) == 0) return error.SkipZigTest; // root reads anything + try std.testing.expectEqualStrings(s.at("look: {s}: permission denied", .{path}), s.said); +} + +test "look-and-exec: a look line's trailing colon is dropped, and a look whose address fails never leaves its file open" { + var tmp = std.testing.tmpDir(.{}); + defer tmp.cleanup(); + try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "a.txt", .data = "one\ntwo\nthree\n" }); + var s = try Session.initFile(std.testing.allocator, "x\n"); + defer s.deinit(); + const dir = try tmpPath(&s, &tmp); + const before = lines(try s.read("/index")); + // Failing addresses: nothing opened, the write still answered. + for ([_][]const u8{ s.at("{s}/a.txt:/nomatch/\n", .{dir}), s.at("{s}/a.txt:9:\n", .{dir}) }) |line| { + _ = try s.refused("/look", line); + try expectEqual(before, lines(try s.read("/index"))); + } + // `a.txt:2:3:` is `a.txt:2:3`: it opens there. + try s.write("/look", s.at("{s}/a.txt:2:3:\n", .{dir})); + try expectEqual(before + 1, lines(try s.read("/index"))); + const opened = try s.focused(); + try s.expect(s.at("/pane/{d}/name", .{opened}), s.at("{s}/a.txt\n", .{dir})); + try expectEqual(@as(u32, 6), (try s.range(s.at("/pane/{d}/dot", .{opened})))[0]); +} + +test "look-and-exec: a look that misses file:/re/ names the file, and is logged as its pane's" { + var tmp = std.testing.tmpDir(.{}); + defer tmp.cleanup(); + try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "f.txt", .data = "alpha\n" }); + var s = try Session.initFile(std.testing.allocator, "x\n"); + defer s.deinit(); + const dir = try tmpPath(&s, &tmp); + const first = try s.focused(); + try s.write("/look", s.at("{s}/f.txt\n", .{dir})); + const f = try s.focused(); + _ = try s.refused(s.at("/pane/{d}/look", .{first}), s.at("{s}/f.txt:/zzqq/\n", .{dir})); + try std.testing.expect(has(try s.read("/log"), s.at("err {d} look: {s}/f.txt: no match for regexp", .{ f, dir }))); +} + +test "look-and-exec: a look that goes to another pane leaves the looking pane's dot alone" { + var tmp = std.testing.tmpDir(.{}); + defer tmp.cleanup(); + try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "f.txt", .data = "f one\nf two\n" }); + var s = try Session.initFile(std.testing.allocator, "alpha bravo\ncharlie\n"); + defer s.deinit(); + const dir = try tmpPath(&s, &tmp); + const source = try s.focused(); + const other = try s.newPane(); + try s.write(s.at("/pane/{d}/body", .{other}), "one\ntwo\nthree\n"); + for ([_][]const u8{ s.at("@p{d}:2\n", .{other}), s.at("@p{d}:/three/\n", .{other}), s.at("{s}/f.txt:2\n", .{dir}) }) |line| { + try s.write(s.at("/pane/{d}/dot", .{source}), "6 11"); + try s.write(s.at("/pane/{d}/look", .{source}), line); + try std.testing.expect(try s.focused() != source); + try expectEqual(.{ @as(u32, 6), @as(u32, 11) }, try s.range(s.at("/pane/{d}/dot", .{source}))); + } +} + +test "look-and-exec: a looked word is found in its own pane, next place after the dot, wrapping, and opens no pane; LookWord list lists it in +Search" { + var s = try Session.initFile(std.testing.allocator, "foo x foo y\n"); + defer s.deinit(); + const n = try s.focused(); + const look = s.at("/pane/{d}/look", .{n}); + const index = try s.read("/index"); + for ([_]u32{ 0, 6, 0 }) |at| { + try s.write(look, "foo\n"); + try expectEqual(.{ at, at + 3 }, try s.range(s.at("/pane/{d}/dot", .{n}))); + } + try s.expect("/index", index); + try s.write("/ctl", "LookWord list\n"); + try s.write(look, "foo\n"); + try std.testing.expect(lines(try s.read("/index")) > lines(index)); + // ...and look reads back that +Search pane, where the places are. + const search = try paneNamed(&s, "/+Search"); + try std.testing.expect(has(try s.read(look), s.at("{d}\n", .{search}))); +} + +test "look-and-exec: a second LookWord list look in a directory refills its +Search rather than stacking another" { + var tmp = std.testing.tmpDir(.{}); + defer tmp.cleanup(); + try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "words.txt", .data = "alpha beta\nalpha beta\n" }); + var s = try Session.initFile(std.testing.allocator, "x\n"); + defer s.deinit(); + const n = try s.focused(); + try s.write(s.at("/pane/{d}/name", .{n}), s.at("{s}/words.txt\n", .{try tmpPath(&s, &tmp)})); + try s.write(s.at("/pane/{d}/exec", .{n}), "Get\n"); + try s.write("/ctl", "LookWord list\n"); + try s.write(s.at("/pane/{d}/look", .{n}), "alpha\n"); + const first = try paneNamed(&s, "/+Search"); + try s.write(s.at("/pane/{d}/look", .{n}), "beta\n"); + try expectEqual(@as(usize, 1), std.mem.count(u8, try s.read("/index"), "/+Search ")); + try expectEqual(first, try paneNamed(&s, "/+Search")); +} + +test "look-and-exec: `@pN:` looks at pane N as `a.txt:` looks at a.txt, and a line past the end is said one way, `:N` or `file:N`" { + var s = try Session.initFile(std.testing.allocator, "one\ntwo\n"); + defer s.deinit(); + const n = try s.focused(); + const look = s.at("/pane/{d}/look", .{n}); + const before = try errs(&s); + try s.write(look, s.at("@p{d}:\n", .{n})); + try expectEqual(before, try errs(&s)); + try s.write(look, ":99999\n"); + try s.write(look, "/test.txt:99999\n"); + try std.testing.expect(has(try s.read("/log"), "/test.txt:99999 has no line 99999 (x2)\n")); +} + +test "look-and-exec: an exec line over the command limit fails the write and says the limit; a builtin's may be longer" { + var s = try Session.initFile(std.testing.allocator, "x\n"); + defer s.deinit(); + const n = try s.focused(); + const long = "echo " ++ &@as([1024]u8, @splat('y')) ++ "\n"; + try expectEqual(@as(u16, 22), try s.refused("/exec", long)); + try std.testing.expectEqualStrings("invalid command line: a command line is at most 1024 bytes", s.said); + try std.testing.expect(has(try s.read("/log"), s.at("err {d} exec: invalid command line: a command line is at most 1024 bytes", .{n}))); + _ = try s.refused("/exec", "echo a\x01b\n"); + try std.testing.expectEqualStrings("invalid command line: it holds a control character (or DEL) other than a tab", s.said); + try std.testing.expect(has(try s.read("/log"), s.at("err {d} exec: invalid command line: it holds", .{n}))); + try s.write("/exec", "Msg " ++ &@as([1100]u8, @splat('z')) ++ "\n"); +} + +test "look-and-exec: a builtin that fails through exec, tagexec or a column's exec fails the write with one err and no msg" { + var s = try Session.initFile(std.testing.allocator, "x\n"); + defer s.deinit(); + const n = try s.focused(); + // Another failure first: the pane's `new` is logged after it. + _ = try s.refused("/ctl", "Unmount yyy\n"); + for ([_][]const u8{ "/exec", s.at("/pane/{d}/exec", .{n}), "/tagexec", s.at("/col/{d}/exec", .{try s.column(0)}) }) |path| { + try std.testing.expect(try s.refused(path, "Unmount zzz\n") != 0); + try std.testing.expect(has(s.said, "Unmount: no such mount zzz")); + } + const log = try s.read("/log"); + try std.testing.expect(!has(log, "msg ")); + // The root's exec ran at the pane, so its err and the pane's exec's are + // the same record, counted. + try expectEqual(@as(usize, 3), std.mem.count(u8, log, "Unmount: no such mount zzz")); + try std.testing.expect(has(log, "mount zzz (x2)")); + // A look miss: one err, no msg; the same miss again is that record counted. + try s.write("/look", "zzqqnotthere\n"); + try std.testing.expect(has(try s.read("/log"), "look: no match for \"zzqqnotthere\"")); + try std.testing.expect(!has(try s.read("/log"), "msg ")); + try s.write("/look", "zzqqnotthere\n"); + try std.testing.expect(has(try s.read("/log"), "look: no match for \"zzqqnotthere\" (x2)\n")); +} + +test "look-and-exec: a served-tree pane spoils no Grep, and Look . from a gone directory is ENOENT, not /virtual/" { + var tmp = std.testing.tmpDir(.{}); + defer tmp.cleanup(); + try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "hit.txt", .data = "needle here\n" }); + 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}), s.at("{s}/other.txt\n", .{try tmpPath(&s, &tmp)})); + // A pane of the served tree, and one named its root, whose directory is `/`. + try s.write(s.at("/pane/{d}/name", .{try s.newPane()}), "/virtual/index\n"); + try s.write(s.at("/pane/{d}/name", .{try s.newPane()}), "/virtual\n"); + try s.write(s.at("/pane/{d}/exec", .{first}), "Grep needle\n"); + // `.` from a pane whose directory is gone. + const gone = try s.newPane(); + try s.write(s.at("/pane/{d}/name", .{gone}), "/tmp/pardes-no-such-dir-zz/f.txt\n"); + try expectEqual(@as(u16, 2), try s.refused(s.at("/pane/{d}/look", .{gone}), ".\n")); + try std.testing.expect(std.mem.startsWith(u8, s.said, "look: /tmp/pardes-no-such-dir-zz: no such directory")); +} diff --git a/test/behaviour/panes.zig b/test/behaviour/panes.zig index 9103508c..7bcf13d0 100644 --- a/test/behaviour/panes.zig +++ b/test/behaviour/panes.zig @@ -657,3 +657,48 @@ test "panes: Get of a file not there says so without asking about unsaved edits" try std.testing.expect(try s.refused(s.at("/pane/{d}/exec", .{n}), s.at("Get {s}/f.txt\n", .{dir})) != 0); try s.expect(s.at("/pane/{d}/body", .{n}), "x\nunsaved\n"); } + +test "panes: a pane's ctl takes acme's words: done by the files that replace them, or refused with why" { + var s = try Session.initFile(std.testing.allocator, "one two\n"); + defer s.deinit(); + const n = try s.focused(); + const ctl = s.at("/pane/{d}/ctl", .{n}); + const dirty = s.at("/pane/{d}/dirty", .{n}); + try s.write(ctl, "name /tmp/pardes-acme-ctl.txt\n"); + try s.expect(s.at("/pane/{d}/name", .{n}), "/tmp/pardes-acme-ctl.txt\n"); + try s.write(ctl, "dirty\n"); + try s.expect(dirty, "1\n"); + try s.write(ctl, "clean\n"); + try s.expect(dirty, "0\n"); + try s.write(s.at("/pane/{d}/addr", .{n}), "/two/"); + try s.write(ctl, "dot=addr\nshow\nnomark\nmark\nlimit=addr\n"); + try std.testing.expectEqual(@as(u32, 4), (try s.range(s.at("/pane/{d}/dot", .{n})))[0]); + try std.testing.expectEqual(.{ @as(u32, 4), @as(u32, 7) }, try s.range(s.at("/pane/{d}/limit", .{n}))); + try s.write(ctl, "cleartag\n"); + for ([_][]const u8{ "menu\n", "nomenu\n", "dump echo hi\n", "dumpdir /tmp\n", "font Go Mono\n" }) |line| { + try std.testing.expectEqual(@as(u16, 22), try s.refused(ctl, line)); + try std.testing.expect(std.mem.startsWith(u8, s.said, "invalid: acme's ")); + } + // Checked whole: a refused word anywhere and nothing ran. + try std.testing.expectEqual(@as(u16, 22), try s.refused(ctl, "dirty\nmenu\n")); + try s.expect(dirty, "0\n"); +} + +test "panes: +Unsaved drops a pane once it has closed" { + var s = try Session.initFile(std.testing.allocator, "x\n"); + defer s.deinit(); + const a = try s.newPane(); + try s.write(s.at("/pane/{d}/name", .{a}), "/tmp/pardes-unsaved-a.txt\n"); + try s.write(s.at("/pane/{d}/body", .{a}), "edited\n"); + const b = try s.newPane(); + try s.write(s.at("/pane/{d}/name", .{b}), "/tmp/pardes-unsaved-b.txt\n"); + try s.write(s.at("/pane/{d}/body", .{b}), "edited\n"); + try std.testing.expect(try s.refused("/ctl", "Exit\n") != 0); + const list = s.at("/pane/{d}/body", .{(try panesNamed(&s, "/+Unsaved"))[0]}); + try std.testing.expect(has(try s.read(list), "/tmp/pardes-unsaved-a.txt: Modified")); + // a closes (discarded): its row goes. + _ = try s.refused(s.at("/pane/{d}/ctl", .{a}), "Del\n"); + try s.write(s.at("/pane/{d}/ctl", .{a}), "Del\n"); + try std.testing.expectEqual(@as(usize, 0), (try panesNamed(&s, "/pardes-unsaved-a.txt")).len); + try std.testing.expect(!has(try s.read(list), "/tmp/pardes-unsaved-a.txt: Modified")); +} diff --git a/test/behaviour/placement.zig b/test/behaviour/placement.zig index 079b5a5e..893cd9a4 100644 --- a/test/behaviour/placement.zig +++ b/test/behaviour/placement.zig @@ -59,3 +59,23 @@ test "placement: Placement pardes puts a new pane right under the asking one, an try s.write("/ctl", "Placement\n"); try std.testing.expect(std.mem.indexOf(u8, try s.read("/ctl"), "\nPlacement acme\n") != null); } + +test "placement: a look under pardes's placement, from a pane pane/new made after Delcol, opens its file in a column" { + var tmp = std.testing.tmpDir(.{}); + defer tmp.cleanup(); + try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "f.txt", .data = "file\n" }); + var buf: [4096]u8 = undefined; + const dir = buf[0..try tmp.dir.realPath(std.testing.io, &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}/exec", .{first}), "Placement\n"); + try s.write(s.at("/pane/{d}/exec", .{first}), "Delcol\n"); + const made = try s.newPane(); + try s.write(s.at("/pane/{d}/look", .{made}), s.at("{s}/f.txt:#4\n", .{dir})); + const opened = try s.focused(); + try std.testing.expect(opened != made); + // The pane pane/new made is placed, and so is the one its look opened. + const cols = try s.columns(); + for ([_]u32{ made, opened }) |n| try std.testing.expect(std.mem.indexOf(u8, cols, s.at(":{d}", .{n})) != null or std.mem.indexOf(u8, cols, s.at(",{d}", .{n})) != null); +} diff --git a/test/behaviour/root_ctl.zig b/test/behaviour/root_ctl.zig index 3e546237..12f2b56a 100644 --- a/test/behaviour/root_ctl.zig +++ b/test/behaviour/root_ctl.zig @@ -123,3 +123,21 @@ fn lastIncl(s: *Session) ![]const u8 { const at = std.mem.indexOf(u8, log, "\nmsg - Incl:") orelse return error.NoIncl; return log[at .. std.mem.indexOfScalarPos(u8, log, at + 1, '\n').? + 1]; } + +test "root-ctl: Joincol with no column to the right and Theme with no such theme say so; a theme's name is any case" { + var s = try Session.initFile(std.testing.allocator, "x\n"); + defer s.deinit(); + try std.testing.expect(try s.refused("/ctl", "Joincol\n") != 0); + try std.testing.expect(std.mem.startsWith(u8, s.said, "Joincol: no column to the right")); + try std.testing.expectEqual(@as(u16, 22), try s.refused("/ctl", "Theme drak\n")); + try std.testing.expect(std.mem.startsWith(u8, s.said, "bad value in control message; like it: ")); + try std.testing.expect(has(s.said, ": dr")); + try std.testing.expect(std.mem.endsWith(u8, s.said, "\"drak\"")); + // Within the 128 bytes an Rerror carries, the quoted line kept. + try std.testing.expect(s.said.len <= 128); + // A click on the word says it in the log. + _ = try s.refused(s.at("/pane/{d}/exec", .{try s.focused()}), "Theme drak\n"); + try std.testing.expect(has(try s.read("/log"), "no theme \"drak\"")); + try s.write("/ctl", "Theme DRACULA\n"); + try std.testing.expect(has(try s.read("/ctl"), "\nTheme dracula\n")); +} diff --git a/test/behaviour/rules.zig b/test/behaviour/rules.zig index 4b853a40..8f5597ae 100644 --- a/test/behaviour/rules.zig +++ b/test/behaviour/rules.zig @@ -37,3 +37,25 @@ test "rules: body reads at any offset and writes append; a stat says its length, try std.testing.expect((try s.stat(body)).version != st.version); try std.testing.expectEqual(@as(u32, 0), (try s.stat(s.at("/pane/{d}/tag", .{try s.focused()}))).version); } + +test "rules: every EINVAL a write gets says why, in its err record too; DEL is a control character in a line" { + var s = try Session.initFile(std.testing.allocator, "x\n"); + defer s.deinit(); + const n = try s.focused(); + for ([_][2][]const u8{ + .{ "/exec", "echo a\x7fb\n" }, + .{ "/look", "a\x7fb\n" }, + }) |c| { + try std.testing.expectEqual(@as(u16, 22), try s.refused(c[0], c[1])); + try std.testing.expect(std.mem.indexOf(u8, s.said, "control character") != null); + } + try std.testing.expectEqual(@as(u16, 22), try s.refused(s.at("/pane/{d}/name", .{n}), "\n")); + try std.testing.expect(std.mem.indexOf(u8, s.said, "an empty name") != null); + const log = try s.hold("/log", 2); + try std.testing.expectEqual(@as(u16, 22), try s.writeFid(log, "bogus\n")); + try std.testing.expect(std.mem.indexOf(u8, s.said, "takes `follow`") != null); + s.clunk(log); + const text = try s.read("/log"); + try std.testing.expect(std.mem.indexOf(u8, text, "Invalid argument") == null); + try std.testing.expect(std.mem.indexOf(u8, text, "an empty name") != null); +} diff --git a/test/behaviour/settings.zig b/test/behaviour/settings.zig index b850a532..f3ed57de 100644 --- a/test/behaviour/settings.zig +++ b/test/behaviour/settings.zig @@ -112,3 +112,23 @@ test "settings: a bad setting value is quoted, so two different bad values log a try std.testing.expect(has(log, "takes on, off \"nope\"\n")); try std.testing.expect(!has(log, "(x2)")); } + +test "settings: a setting this frontend cannot show says GUI-only, never run as a command, and DumpDir reads back" { + var s = try Session.initFile(std.testing.allocator, "x\n"); + defer s.deinit(); + if (comptime @import("pardes_config").platform != .gui) { + _ = try s.refused("/ctl", "Lift on\n"); + try std.testing.expectEqualStrings("Lift is GUI-only, invalid here \"Lift\"", s.said); + _ = try s.refused("/ctl", "GripWidth 120\n"); + try std.testing.expectEqualStrings("GripWidth is GUI-only, invalid here \"GripWidth\"", s.said); + // A builtin the GUI alone has, written to a ctl or an exec, never + // runs as a shell command. + _ = try s.refused("/ctl", "Fonts\n"); + try std.testing.expectEqualStrings("Fonts is GUI-only, invalid here \"Fonts\"", s.said); + try std.testing.expectEqual(@as(u16, 22), try s.refused("/exec", "Fonts\n")); + try std.testing.expectEqualStrings("Fonts is GUI-only, invalid here", s.said); + } + _ = try s.refused("/ctl", "Liftt on\n"); + try std.testing.expectEqualStrings("unknown control message \"Liftt\"", s.said); + try std.testing.expect(has(try s.read("/ctl"), "\nDumpDir /")); +} -- cgit v1.3 From ee36e1d07d455aed8b3895e35329b1de4c21ab94 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Wed, 4 Nov 2026 11:14:05 -0300 Subject: test: review of the ctl migration: the second LookWord list look checked refilled with beta's places (its +Search body's words.txt:1:7-10), not only the one +Search; a failing builtin's test again refuses Msg a\x01b on the root exec with its control-character reason, as the old test did; a look opening a spaced path checks the source's ctl undo flag still 0 (the old revision and undo_len checks; the first 60 bytes stopped at dirty); a name's own backslash doubled in /index and in /recent's closed row moved to test/behaviour/other_files.zig through a name write to a file named back\nslash, the old /index and /recent tests trimmed to their setCwd control bytes and newline (no 9P name holds one); each checked to fail against a break (events' backslash doubling skipped, the second look searching alpha again, both control-character checks letting \x01 through); ten of the migrated tests checked against the reviewer's own breaks (fitErr's end left mid-character, Tab taking 0, a deleted file's Back step not going on, Delete asking, recentKeeps keeping a non-local name, a 1 MiB line not discarding its tail, is a dir not EISDIR, an event range backwards taken, DEL let through both checks, a remembered place's column clamped past the line) Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge --- src/ninep/ctl.zig | 11 +++++------ test/behaviour/look_and_exec.zig | 11 ++++++++++- test/behaviour/other_files.zig | 17 +++++++++++++++++ 3 files changed, 32 insertions(+), 7 deletions(-) (limited to 'test/behaviour/look_and_exec.zig') diff --git a/src/ninep/ctl.zig b/src/ninep/ctl.zig index ec7cb3bc..89549933 100644 --- a/src/ninep/ctl.zig +++ b/src/ninep/ctl.zig @@ -2471,10 +2471,7 @@ test "/index shows a name as the log does: a newline in it is \\n, a control byt // Its tag never carries the raw newline either. const tag = rd(p, Node.of(serialOf(p), .tag), 0, 4096).bytes; try testing.expect(std.mem.indexOf(u8, tag, "/tmp/two\\nlines") != null); - // A backslash of the name's own is doubled: `\n` written in a name - // reads back unlike a newline. - p.setCwd(term, "/tmp/back\\nslash"); - try testing.expect(std.mem.indexOf(u8, rd(p, @backingInt(tree.TopFile.index), 0, 4096).bytes, "/tmp/back\\\\nslash") != null); + // A name's own backslash doubled is test/behaviour/other_files.zig's. } test "a column takes panes until their documented minimums fill it, not until none can be halved" { @@ -2525,9 +2522,11 @@ test "a new file saved shows in /recent, open, while it is" { test "/recent shows a name as /index does, a newline in it escaped" { const p = try withFile(testing.allocator, "x\n"); defer p.deinit(); - p.recent.opened(p.recentGpa(), "/tmp/a\nb\\c"); + // A backslash doubled is test/behaviour/other_files.zig's; a 9P name + // write cannot hold a newline. + p.recent.opened(p.recentGpa(), "/tmp/a\nb"); const text = rd(p, @backingInt(tree.TopFile.recent), 0, 8192).bytes; - try testing.expect(std.mem.indexOf(u8, text, "closed /tmp/a\\nb\\\\c\n") != null); + try testing.expect(std.mem.indexOf(u8, text, "closed /tmp/a\\nb\n") != null); } test "size is monotonic: growing is never refused, and a size once taken is taken again" { diff --git a/test/behaviour/look_and_exec.zig b/test/behaviour/look_and_exec.zig index 2ce95354..f769d72a 100644 --- a/test/behaviour/look_and_exec.zig +++ b/test/behaviour/look_and_exec.zig @@ -458,7 +458,11 @@ test "look-and-exec: a look opens spaced paths and locations without editing the try expectEqual(@as(u32, 8), (try s.range(s.at("/pane/{d}/dot", .{opened})))[0]); // line 2, column 3 // The source: its text, its undo steps and its cursor as they were. try s.expect(s.at("/pane/{d}/body", .{source}), "source stays intact\n"); - try std.testing.expectEqualStrings(ctl[0..60], (try s.read(s.at("/pane/{d}/ctl", .{source})))[0..60]); + const after = try s.read(s.at("/pane/{d}/ctl", .{source})); + try std.testing.expectEqualStrings(ctl[0..60], after[0..60]); + var fields = std.mem.tokenizeScalar(u8, after, ' '); + for (0..8) |_| _ = fields.next(); + try std.testing.expectEqualStrings("0", fields.next().?); // still no undo step try expectEqual(.{ @as(u32, 3), @as(u32, 3) }, try s.range(s.at("/pane/{d}/dot", .{source}))); try s.expect("/look", s.at("{d}\n", .{opened})); // From the root, with the source focused: the same pane, moved. @@ -623,6 +627,8 @@ test "look-and-exec: a second LookWord list look in a directory refills its +Sea try s.write(s.at("/pane/{d}/look", .{n}), "beta\n"); try expectEqual(@as(usize, 1), std.mem.count(u8, try s.read("/index"), "/+Search ")); try expectEqual(first, try paneNamed(&s, "/+Search")); + // Refilled with beta's places (columns 7-10), not alpha's. + try std.testing.expect(has(try s.read(s.at("/pane/{d}/body", .{first})), "words.txt:1:7-10\n")); } test "look-and-exec: `@pN:` looks at pane N as `a.txt:` looks at a.txt, and a line past the end is said one way, `:N` or `file:N`" { @@ -668,6 +674,9 @@ test "look-and-exec: a builtin that fails through exec, tagexec or a column's ex // the same record, counted. try expectEqual(@as(usize, 3), std.mem.count(u8, log, "Unmount: no such mount zzz")); try std.testing.expect(has(log, "mount zzz (x2)")); + // A control character is refused with its reason. + try expectEqual(@as(u16, 22), try s.refused("/exec", "Msg a\x01b\n")); + try std.testing.expectEqualStrings("invalid command line: it holds a control character (or DEL) other than a tab", s.said); // A look miss: one err, no msg; the same miss again is that record counted. try s.write("/look", "zzqqnotthere\n"); try std.testing.expect(has(try s.read("/log"), "look: no match for \"zzqqnotthere\"")); diff --git a/test/behaviour/other_files.zig b/test/behaviour/other_files.zig index 2d5cb112..701f4f14 100644 --- a/test/behaviour/other_files.zig +++ b/test/behaviour/other_files.zig @@ -309,3 +309,20 @@ test "other-files: a remembered place is clamped to the file as it is now, its s try std.testing.expectEqual(back, try s.focused()); try std.testing.expectEqual(dot, try s.range(s.at("/pane/{d}/dot", .{back}))); } + +test "other-files: /index and /recent show a name's own backslash doubled, so `\\n` written in a name reads back unlike a newline" { + var tmp = std.testing.tmpDir(.{}); + defer tmp.cleanup(); + try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "back\\nslash", .data = "x\n" }); + var s = try Session.initFile(std.testing.allocator, "x\n"); + defer s.deinit(); + const dir = try tmpPath(&s, &tmp); + const n = try s.focused(); + try s.write(s.at("/pane/{d}/name", .{n}), s.at("{s}/back\\nslash\n", .{dir})); + const index = try s.read("/index"); + try std.testing.expect(has(index, s.at("{s}/back\\\\nslash ", .{dir}))); + try std.testing.expectEqual(@as(usize, 1), std.mem.count(u8, index, "\n")); + try s.write(s.at("/pane/{d}/exec", .{n}), "Get\n"); + try s.write(s.at("/pane/{d}/ctl", .{n}), "Del\n"); + try std.testing.expect(has(try s.read("/recent"), s.at("closed {s}/back\\\\nslash\n", .{dir}))); +} -- cgit v1.3