diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-04 10:52:24 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-04 10:56:17 -0300 |
| commit | 350e7cc22b85130cbe95a114c668945b1dc12fd7 (patch) | |
| tree | 26454697f244051bb3b616cb7810e3dcade54eeb /test | |
| parent | b798f2c1cf5dd4f98c8c1f81c8642b005890f6ee (diff) | |
| download | pardes-350e7cc22b85130cbe95a114c668945b1dc12fd7.tar.gz pardes-350e7cc22b85130cbe95a114c668945b1dc12fd7.zip | |
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 <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge
Diffstat (limited to 'test')
| -rw-r--r-- | test/behaviour.zig | 1 | ||||
| -rw-r--r-- | test/behaviour/edit.zig | 12 | ||||
| -rw-r--r-- | test/behaviour/from_acme.zig | 28 | ||||
| -rw-r--r-- | test/behaviour/limits.zig | 22 | ||||
| -rw-r--r-- | test/behaviour/look_and_exec.zig | 261 | ||||
| -rw-r--r-- | test/behaviour/panes.zig | 45 | ||||
| -rw-r--r-- | test/behaviour/placement.zig | 20 | ||||
| -rw-r--r-- | test/behaviour/root_ctl.zig | 18 | ||||
| -rw-r--r-- | test/behaviour/rules.zig | 22 | ||||
| -rw-r--r-- | test/behaviour/settings.zig | 20 |
10 files changed, 449 insertions, 0 deletions
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 <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 /")); +} |
