diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-04 10:28:11 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-04 10:33:28 -0300 |
| commit | 7bbcd971a761def328fb9eeb881301bf45fb4783 (patch) | |
| tree | 402020187b24c3f550f1a84fda1709e110c731e1 /test/behaviour | |
| parent | f697bb13c3599db3ce30fac059932242597acdf6 (diff) | |
| download | pardes-7bbcd971a761def328fb9eeb881301bf45fb4783.tar.gz pardes-7bbcd971a761def328fb9eeb881301bf45fb4783.zip | |
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<serial>:<address> 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 <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge
Diffstat (limited to 'test/behaviour')
| -rw-r--r-- | test/behaviour/addresses.zig | 20 | ||||
| -rw-r--r-- | test/behaviour/edit.zig | 16 | ||||
| -rw-r--r-- | test/behaviour/event.zig | 16 | ||||
| -rw-r--r-- | test/behaviour/flags.zig | 42 | ||||
| -rw-r--r-- | test/behaviour/look_and_exec.zig | 110 | ||||
| -rw-r--r-- | test/behaviour/mounts.zig | 7 | ||||
| -rw-r--r-- | test/behaviour/panes.zig | 36 | ||||
| -rw-r--r-- | test/behaviour/repls.zig | 11 | ||||
| -rw-r--r-- | test/behaviour/root_ctl.zig | 7 | ||||
| -rw-r--r-- | test/behaviour/settings.zig | 11 |
10 files changed, 276 insertions, 0 deletions
diff --git a/test/behaviour/addresses.zig b/test/behaviour/addresses.zig index a1474c3d..57fc86e6 100644 --- a/test/behaviour/addresses.zig +++ b/test/behaviour/addresses.zig @@ -63,3 +63,23 @@ 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 malformed address is bad address syntax; on a pane with no text any address is refused as nothing to address" { + var s = try Session.initFile(std.testing.allocator, "one\n"); + defer s.deinit(); + const addr = s.at("/pane/{d}/addr", .{try s.focused()}); + for ([_][]const u8{ "1x", "/(/", ",,x" }) |expr| { + try expectEqual(@as(u16, 22), try s.refused(addr, expr)); + try std.testing.expect(s.said.len > 0); + } + _ = try s.refused(addr, "1x"); + try std.testing.expectEqualStrings("bad address syntax", s.said); + // A terminal (as an image or a PDF): addr, dot and limit alike. + var t = try Session.initTerm(std.testing.allocator); + defer t.deinit(); + const term = try t.focused(); + for ([_][]const u8{ "addr", "dot", "limit" }) |file| for ([_][]const u8{ "1", "1x" }) |expr| { + try expectEqual(@as(u16, 22), try t.refused(t.at("/pane/{d}/{s}", .{ term, file }), expr)); + try std.testing.expectEqualStrings("invalid address: this pane has no text to address", t.said); + }; +} diff --git a/test/behaviour/edit.zig b/test/behaviour/edit.zig index 3d1a731e..bfb17533 100644 --- a/test/behaviour/edit.zig +++ b/test/behaviour/edit.zig @@ -29,3 +29,19 @@ test "edit: a bad command inside an Edit block written whole is named, not the } try std.testing.expect(std.mem.indexOf(u8, s.said, "z") != null); try s.expect(s.at("/pane/{d}/body", .{n}), "abc\n"); } + +test "edit: Edit through a pane's ctl renames every foo in one undo step, and a failed one changes nothing" { + var s = try Session.initFile(std.testing.allocator, "foo x foo y foo\n"); + defer s.deinit(); + const n = try s.focused(); + const ctl = s.at("/pane/{d}/ctl", .{n}); + const body = s.at("/pane/{d}/body", .{n}); + try s.write(ctl, "Edit ,x/foo/c/foobar/\n"); + try s.expect(body, "foobar x foobar y foobar\n"); + try std.testing.expectEqual(@as(u16, 5), try s.refused(ctl, "Edit ,s/nothing/x/\n")); + try std.testing.expect(std.mem.startsWith(u8, s.said, "Edit: no substitution")); + try s.expect(body, "foobar x foobar y foobar\n"); + // The whole rename is one undo step. + try s.write(ctl, "Undo"); + try s.expect(body, "foo x foo y foo\n"); +} diff --git a/test/behaviour/event.zig b/test/behaviour/event.zig index 8aebe8f4..77a80e30 100644 --- a/test/behaviour/event.zig +++ b/test/behaviour/event.zig @@ -53,3 +53,19 @@ test "event: a refused Del written back through event fails that write, EIO, wit try std.testing.expect(has(s.said, "Modified")); _ = try s.read(s.at("/pane/{d}/ctl", .{n})); // still there } + +test "event: a bad event record says what is wrong with it" { + var s = try Session.initFile(std.testing.allocator, "one\n"); + defer s.deinit(); + const event = try s.hold(s.at("/pane/{d}/event", .{try s.focused()}), 2); + defer s.clunk(event); + for ([_][2][]const u8{ + .{ "MI0 1 0 1 x\n", "only a look or exec" }, + .{ "MX3 1 0 0 \n", "ends before it starts" }, + .{ "MX9 9 0 0 \n", "range past end" }, + .{ "garbage\n", "a record is" }, + }) |c| { + try std.testing.expectEqual(@as(u16, 22), try s.writeFid(event, c[0])); + try std.testing.expect(has(s.said, c[1])); + } +} diff --git a/test/behaviour/flags.zig b/test/behaviour/flags.zig index 656d219f..9eca2e38 100644 --- a/test/behaviour/flags.zig +++ b/test/behaviour/flags.zig @@ -40,3 +40,45 @@ 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")); } + +fn has(hay: []const u8, needle: []const u8) bool { + return std.mem.indexOf(u8, hay, needle) != null; +} + +test "flags: Undo and Redo on a pane's ctl step its body through its edits, and say when there is none, counted" { + 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 ctl = s.at("/pane/{d}/ctl", .{n}); + try s.write(body, "two\n"); + try s.expect(body, "one\ntwo\n"); + try s.write(ctl, "Undo"); + try s.expect(body, "one\n"); + try s.write(ctl, "Redo"); + try s.expect(body, "one\ntwo\n"); + // Nothing left: said, and the write still succeeds, as acme's is silent. + try s.write(ctl, "Redo"); + try std.testing.expect(has(try s.read("/log"), "Redo: nothing to redo")); + try s.write(ctl, "Undo"); + try s.write(ctl, "Undo"); + try std.testing.expect(has(try s.read("/log"), "Undo: nothing to undo")); + // Said again word for word, it is that line counted, as err's are. + for (0..3) |_| try s.write(ctl, "Undo"); + try std.testing.expect(has(try s.read("/log"), "Undo: nothing to undo (x4)\n")); +} + +test "flags: dirty goes back to 0 when the text is the saved text again" { + var s = try Session.initFile(std.testing.allocator, "one\n"); + defer s.deinit(); + const n = try s.focused(); + const dirty = s.at("/pane/{d}/dirty", .{n}); + const ctl = s.at("/pane/{d}/ctl", .{n}); + try s.expect(dirty, "0\n"); + try s.write(s.at("/pane/{d}/body", .{n}), "two\n"); + try s.expect(dirty, "1\n"); + try s.write(ctl, "Undo"); + try s.expect(dirty, "0\n"); + try s.write(ctl, "Redo"); + try s.expect(dirty, "1\n"); +} 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<serial>:<address> 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")); + }; +} diff --git a/test/behaviour/mounts.zig b/test/behaviour/mounts.zig index 57685a38..c05166bc 100644 --- a/test/behaviour/mounts.zig +++ b/test/behaviour/mounts.zig @@ -23,3 +23,10 @@ test "mounts: Mount with no dial is wrong #args, any other x!y a bad dial addres try std.testing.expect(has(s.said, "no such mount")); } } + +test "mounts: a Mount dial with a network it does not know is a bad dial address, EINVAL" { + var s = try Session.initFile(std.testing.allocator, "x\n"); + defer s.deinit(); + try expectEqual(@as(u16, 22), try s.refused("/ctl", "Mount peer nowhere!x\n")); + try std.testing.expect(std.mem.startsWith(u8, s.said, "Mount: bad dial address: nowhere!x")); +} diff --git a/test/behaviour/panes.zig b/test/behaviour/panes.zig index a46f8432..7febd667 100644 --- a/test/behaviour/panes.zig +++ b/test/behaviour/panes.zig @@ -363,3 +363,39 @@ 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: Mini with no argument is wrong #args, EINVAL, as every word that needs one" { + var s = try Session.initFile(std.testing.allocator, "x\n"); + defer s.deinit(); + try std.testing.expectEqual(@as(u16, 22), try s.refused(s.at("/pane/{d}/ctl", .{try s.focused()}), "Mini\n")); + try std.testing.expectEqualStrings("wrong #args in control message \"Mini\"", s.said); +} + +test "panes: the ctl word name with nothing after it says it names nothing" { + var s = try Session.initFile(std.testing.allocator, "x\n"); + defer s.deinit(); + try std.testing.expectEqual(@as(u16, 22), try s.refused(s.at("/pane/{d}/ctl", .{try s.focused()}), "name \n")); + try std.testing.expectEqualStrings("invalid file name: name takes the name, and there is none", s.said); +} + +test "panes: ctl reads acme's fields in acme's order, undo and redo flags included, then pardes's own" { + var s = try Session.initFile(std.testing.allocator, "one\n"); + defer s.deinit(); + const n = try s.focused(); + const ctl = s.at("/pane/{d}/ctl", .{n}); + const field = struct { + fn at(text: []const u8, i: usize) []const u8 { + var it = std.mem.tokenizeScalar(u8, text, ' '); + for (0..i) |_| _ = it.next(); + return it.next().?; + } + }.at; + try std.testing.expectEqualStrings("0", field(try s.read(ctl), 8)); // nothing to undo + try std.testing.expectEqualStrings("0", field(try s.read(ctl), 9)); // nothing to redo + const current = field(try s.read(ctl), 10); + try std.testing.expect(std.mem.eql(u8, current, "current") or std.mem.eql(u8, current, "notcurrent")); + try s.write(s.at("/pane/{d}/body", .{n}), "two\n"); + try std.testing.expectEqualStrings("1", field(try s.read(ctl), 8)); + try s.write(ctl, "Undo\n"); + try std.testing.expectEqualStrings("1", field(try s.read(ctl), 9)); +} diff --git a/test/behaviour/repls.zig b/test/behaviour/repls.zig new file mode 100644 index 00000000..44c53361 --- /dev/null +++ b/test/behaviour/repls.zig @@ -0,0 +1,11 @@ +//! docs/typ/reference.typ, REPLs <repls>. +const std = @import("std"); +const Session = @import("session").Session; + +test "repls: Repl with no such language is invalid, EINVAL, and names a few whole and how many more" { + var s = try Session.initTerm(std.testing.allocator); + defer s.deinit(); + try std.testing.expectEqual(@as(u16, 22), try s.refused(s.at("/pane/{d}/ctl", .{try s.focused()}), "Repl zzlang\n")); + try std.testing.expect(std.mem.indexOf(u8, s.said, "Repl: invalid language \"zzlang\"; - or one like zig ada bash c c_sharp clojure (") != null); + try std.testing.expect(std.mem.endsWith(u8, s.said, " more)")); +} diff --git a/test/behaviour/root_ctl.zig b/test/behaviour/root_ctl.zig index 90838d90..c00c3cfe 100644 --- a/test/behaviour/root_ctl.zig +++ b/test/behaviour/root_ctl.zig @@ -85,3 +85,10 @@ test "root-ctl: the root ctl reads the settings as a write takes them, and takes try std.testing.expect(std.mem.startsWith(u8, s.said, "Mount x: /tmp/pardes-no-such-sock-zz: no such socket")); try std.testing.expect(has(try s.read("/ctl"), "Verbose on\n")); } + +test "root-ctl: Kill with a name and nothing running says so and does not fail, as bare Kill does" { + var s = try Session.initFile(std.testing.allocator, "x\n"); + defer s.deinit(); + try s.write("/ctl", "Kill zzz\n"); + try std.testing.expect(has(try s.read("/log"), "Kill: nothing running")); +} diff --git a/test/behaviour/settings.zig b/test/behaviour/settings.zig index ff24704a..b850a532 100644 --- a/test/behaviour/settings.zig +++ b/test/behaviour/settings.zig @@ -101,3 +101,14 @@ test "settings: Config without a configuration directory says so and opens nothi try s.expect("/index", index); try expectHas(try s.read("/log"), "Config: no startup file here: no configuration directory"); } + +test "settings: a bad setting value is quoted, so two different bad values log as two records, never one counted twice" { + var s = try Session.initFile(std.testing.allocator, "x\n"); + defer s.deinit(); + _ = try s.refused("/ctl", "Verbose maybe\n"); + _ = try s.refused("/ctl", "Verbose nope\n"); + const log = try s.read("/log"); + try std.testing.expect(has(log, "takes on, off \"maybe\"\n")); + try std.testing.expect(has(log, "takes on, off \"nope\"\n")); + try std.testing.expect(!has(log, "(x2)")); +} |
