diff options
| -rw-r--r-- | src/ninep/ctl.zig | 301 | ||||
| -rw-r--r-- | test/behaviour.zig | 1 | ||||
| -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 |
12 files changed, 277 insertions, 301 deletions
diff --git a/src/ninep/ctl.zig b/src/ninep/ctl.zig index bd460098..bb0fcb96 100644 --- a/src/ninep/ctl.zig +++ b/src/ninep/ctl.zig @@ -1465,73 +1465,6 @@ test "commands lists every builtin with its argument and the ctl that takes it" try testing.expect(std.mem.indexOf(u8, listed.bytes, row) != null); } -test "Undo and Redo on a pane's ctl step its body through its edits" { - const p = try withFile(testing.allocator, "one\n"); - defer p.deinit(); - const serial = serialOf(p); - const body = Node.of(serial, .body); - try testing.expectEqual(Status.ok, wr(p, body, "two\n").reply.status); - try testing.expectEqualStrings("one\ntwo\n", rd(p, body, 0, 64).bytes); - 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); - try testing.expectEqual(Status.ok, wr(p, Node.of(serial, .ctl), "Redo").reply.status); - try testing.expectEqualStrings("one\ntwo\n", rd(p, body, 0, 64).bytes); - // Nothing left: said, and the write still succeeds, as acme's is silent. - try testing.expectEqual(Status.ok, wr(p, Node.of(serial, .ctl), "Redo").reply.status); - try testing.expect(th.logHas(p, "Redo: nothing to redo")); - _ = wr(p, Node.of(serial, .ctl), "Undo"); - try testing.expectEqual(Status.ok, wr(p, Node.of(serial, .ctl), "Undo").reply.status); - try testing.expect(th.logHas(p, "Undo: nothing to undo")); - // Said again word for word, it is that line counted, as err's are. - for (0..3) |_| _ = wr(p, Node.of(serial, .ctl), "Undo"); - try testing.expect(th.logHas(p, "Undo: nothing to undo (x4)\n")); -} - -test "Edit through a pane's ctl renames every foo in one undo step, and a failed one changes nothing" { - const p = try withFile(testing.allocator, "foo x foo y foo\n"); - defer p.deinit(); - const serial = serialOf(p); - const ctl_node = Node.of(serial, .ctl); - const body = Node.of(serial, .body); - try testing.expectEqual(Status.ok, wr(p, ctl_node, "Edit ,x/foo/c/foobar/\n").reply.status); - try testing.expectEqualStrings("foobar x foobar y foobar\n", rd(p, body, 0, 64).bytes); - const failed = wr(p, ctl_node, "Edit ,s/nothing/x/\n"); - try testing.expectEqual(E.IO, failed.errno()); - try testing.expectStringStartsWith(failed.reply.ename, "Edit: no substitution"); - try testing.expectEqualStrings("foobar x foobar y foobar\n", rd(p, body, 0, 64).bytes); - // The whole rename is one undo step. - try testing.expectEqual(Status.ok, wr(p, ctl_node, "Undo").reply.status); - try testing.expectEqualStrings("foo x foo y foo\n", rd(p, body, 0, 64).bytes); -} - - -test "dirty goes back to 0 when the text is the saved text again" { - const p = try withFile(testing.allocator, "one\n"); - defer p.deinit(); - const serial = serialOf(p); - const dirty = Node.of(serial, .dirty); - try testing.expectEqualStrings("0\n", rd(p, dirty, 0, 8).bytes); - try testing.expectEqual(Status.ok, wr(p, Node.of(serial, .body), "two\n").reply.status); - try testing.expectEqualStrings("1\n", rd(p, dirty, 0, 8).bytes); - try testing.expectEqual(Status.ok, wr(p, Node.of(serial, .ctl), "Undo").reply.status); - try testing.expectEqualStrings("0\n", rd(p, dirty, 0, 8).bytes); - try testing.expectEqual(Status.ok, wr(p, Node.of(serial, .ctl), "Redo").reply.status); - try testing.expectEqualStrings("1\n", rd(p, dirty, 0, 8).bytes); -} - -test "a look's miss repeats the path whole up to 256 bytes, then gives up its middle to an ellipsis" { - const gpa = testing.allocator; - const p = try withFile(gpa, "x\n"); - defer p.deinit(); - const root = @backingInt(tree.TopFile.look); - const long = "some/deeply/nested/directory/that/goes/on/and/on/with/a_rather_long_file_name.txt"; - var line: [512]u8 = undefined; - _ = wr(p, root, try std.fmt.bufPrint(&line, "{s}\n", .{long})); - try testing.expect(th.logHas(p, try std.fmt.bufPrint(&line, "look: no match for \"{s}\"\n", .{long}))); - const huge = std.mem.asBytes(&@as([150][2]u8, @splat("é".*))); // 300 bytes: its middle cut to fit 256, between characters - _ = wr(p, root, huge ++ "\n"); - try testing.expect(th.logHas(p, "look: no match for \"" ++ std.mem.asBytes(&@as([63][2]u8, @splat("é".*))) ++ "…" ++ std.mem.asBytes(&@as([63][2]u8, @splat("é".*))) ++ "\"\n")); -} test "status reads the editor, and look and exec validate whole batches" { const gpa = testing.allocator; @@ -2150,17 +2083,6 @@ test "a look at a file it may not read fails the write naming the file" { try testing.expectEqualStrings(expected, refused.reply.ename); } -test "a bad setting value is quoted, so two different bad values log as two records, never one counted twice" { - const p = try withFile(testing.allocator, "x\n"); - defer p.deinit(); - const root_ctl = @backingInt(tree.TopFile.ctl); - _ = wr(p, root_ctl, "Verbose maybe\n"); - _ = wr(p, root_ctl, "Verbose nope\n"); - try testing.expect(th.logHas(p, "takes on, off \"maybe\"\n")); - try testing.expect(th.logHas(p, "takes on, off \"nope\"\n")); - try testing.expect(!th.logHas(p, "(x2)")); -} - 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(); @@ -2408,19 +2330,6 @@ test "Joincol with no column to the right and Theme with no such theme say so" { } -test "a look at file:addr whose file is not there is one miss, quoting what was written, in a terminal too" { - const p = try th.withTerm(testing.allocator); - defer p.deinit(); - const looked = Node.of(serialOf(p), .look); - for ([_][]const u8{ "zzq:#3", "zzq:2", "zzq:/re/" }) |written| { - var line: [64]u8 = undefined; - _ = wr(p, looked, try std.fmt.bufPrint(&line, "{s}\n", .{written})); - var want: [64]u8 = undefined; - try testing.expectEqual(@as(usize, 1), th.logCount(p, try std.fmt.bufPrint(&want, "look: no match for \"{s}\"\n", .{written}))); - } - try testing.expectEqual(@as(usize, 3), th.logCount(p, "\nerr ")); -} - test "a look whose pane is refused a place fails with that alone, not a missing line too" { const gpa = testing.allocator; // A screen with rows for one pane only. @@ -2603,16 +2512,6 @@ test "Tty in a directory that is not there fails and makes no pane; a shell that try testing.expectEqualStrings("error shell gone\n", call(p, .{ .tag = 3, .op = .read, .node = run_node, .handle = h, .size = 64 }).bytes); } -test "a builtin that needs its argument, written bare to an exec, is EINVAL as through ctl" { - const p = try withFile(testing.allocator, "x\n"); - defer p.deinit(); - for ([_]u64{ root_exec, Node.of(serialOf(p), .exec), @backingInt(tree.TopFile.tagexec) }) |node| { - const refused = wr(p, node, "Mount\n"); - try testing.expectEqual(E.INVAL, refused.errno()); - try testing.expectEqualStrings("wrong #args in control message \"Mount\"", refused.reply.ename); - } -} - test "a script's Grep and Find fill the pane's one query pane, a row a line under its file; a miss says not found and opens nothing" { const p = try withFile(testing.allocator, "x\n"); defer p.deinit(); @@ -2677,14 +2576,6 @@ test "a script's Grep and Find fill the pane's one query pane, a row a line unde try testing.expect(panes.Query.ofOwner(p, serialOf(p)) == null); } -test "Unmount of a name not mounted says no such mount, which a mount reads as ENOENT" { - const p = try withFile(testing.allocator, "x\n"); - defer p.deinit(); - const refused = wr(p, @backingInt(tree.TopFile.ctl), "Unmount nothere\n"); - try testing.expectEqual(E.NOENT, refused.errno()); - try testing.expectStringStartsWith(refused.reply.ename, "Unmount: no such mount nothere"); -} - test "a terminal told the directory it already goes by logs no rename" { const p = try withFile(testing.allocator, "x\n"); defer p.deinit(); @@ -2987,14 +2878,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 "Mini with no argument is wrong #args, EINVAL, as every word that needs one" { - const p = try withFile(testing.allocator, "x\n"); - defer p.deinit(); - const r = wr(p, Node.of(serialOf(p), .ctl), "Mini\n"); - try testing.expectEqual(E.INVAL, r.errno()); - try testing.expectEqualStrings("wrong #args in control message \"Mini\"", r.reply.ename); -} - 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(); @@ -3049,26 +2932,6 @@ test "with no pane at all, the root look opens its file and the root exec runs i try testing.expectEqualStrings(session, made.cwdSlice()); } -test "a look at file:3:0 is refused as addr 3:0 is, a column counting from 1" { - const p = try withFile(testing.allocator, "one\ntwo\nthree\n"); - defer p.deinit(); - const serial = serialOf(p); - const by_addr = wr(p, Node.of(serial, .addr), "3:0"); - const by_look = wr(p, Node.of(serial, .look), "/test.txt:3:0\n"); - try testing.expectEqual(E.INVAL, by_addr.errno()); - try testing.expectEqual(E.INVAL, by_look.errno()); - try testing.expectEqualStrings(by_addr.reply.ename, by_look.reply.ename); - try testing.expectEqual(Status.ok, wr(p, Node.of(serial, .look), "/test.txt:3:1\n").reply.status); -} - -test "Kill with a name and nothing running says so and does not fail, as bare Kill does" { - const p = try withFile(testing.allocator, "x\n"); - defer p.deinit(); - const r = wr(p, @backingInt(tree.TopFile.ctl), "Kill zzz\n"); - try testing.expectEqual(Status.ok, r.reply.status); - try testing.expect(th.logHas(p, "Kill: nothing running")); -} - test "a restored pane whose file is gone from disk comes back dirty, and Del asks first" { if (comptime !pardes.hosted) return error.SkipZigTest; const p = try withFile(testing.allocator, "kept text\n"); @@ -3136,17 +2999,6 @@ test "a Restore of a name in the DumpDir asks for, and logs, the whole path it r } -test "a builtin that takes no argument, written with one to an exec, is refused wrong #args, as at a ctl" { - const p = try withFile(testing.allocator, "x\n"); - defer p.deinit(); - const serial = serialOf(p); - for ([_]u64{ @backingInt(tree.TopFile.exec), Node.of(serial, .exec) }) |node| for ([_][]const u8{ "Config extra\n", "DumpConfig extra\n" }) |line| { - const r = wr(p, node, line); - try testing.expectEqual(E.INVAL, r.errno()); - try testing.expectStringStartsWith(r.reply.ename, "wrong #args in control message"); - }; -} - 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(); @@ -3202,32 +3054,6 @@ test "a pane's ctl takes acme's words: done by the files that replace them, or r try testing.expectEqualStrings("0", std.mem.trimEnd(u8, rd(p, Node.of(serial, .dirty), 0, 8).bytes, "\n")); } -test "ctl reads acme's fields in acme's order, undo and redo flags included, then pardes's own" { - const p = try withFile(testing.allocator, "one\n"); - defer p.deinit(); - const serial = serialOf(p); - const ctl_node = Node.of(serial, .ctl); - const fields = struct { - fn of(text: []const u8, buf: *[16][]const u8) [][]const u8 { - var it = std.mem.tokenizeScalar(u8, text, ' '); - var n: usize = 0; - while (it.next()) |t| : (n += 1) buf[n] = t; - return buf[0..n]; - } - }; - var buf: [16][]const u8 = undefined; - var f = fields.of(rd(p, ctl_node, 0, 4096).bytes, &buf); - try testing.expectEqualStrings("0", f[8]); // nothing to undo - try testing.expectEqualStrings("0", f[9]); // nothing to redo - try testing.expect(std.mem.eql(u8, f[10], "current") or std.mem.eql(u8, f[10], "notcurrent")); - _ = wr(p, Node.of(serial, .body), "two\n"); - f = fields.of(rd(p, ctl_node, 0, 4096).bytes, &buf); - try testing.expectEqualStrings("1", f[8]); - _ = wr(p, ctl_node, "Undo\n"); - f = fields.of(rd(p, ctl_node, 0, 4096).bytes, &buf); - try testing.expectEqualStrings("1", f[9]); -} - 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(); @@ -3284,26 +3110,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 look at a ./ or ../ name that is not there is a miss naming the file; a plain one is looked for as text" { - const p = try withFile(testing.allocator, "x\n"); - defer p.deinit(); - var tmp = testing.tmpDir(.{}); - defer tmp.cleanup(); - try tmp.dir.createDirPath(testing.io, "many"); - 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}/many/a.txt\n", .{dir})); - for ([_][]const u8{ "./zz.txt", "../zz.txt" }) |name| { - const r = wr(p, Node.of(serialOf(p), .look), try std.fmt.bufPrint(&line, "{s}\n", .{name})); - try testing.expectEqual(Status.ok, r.reply.status); - var want: [64]u8 = undefined; - try testing.expect(th.logHas(p, try std.fmt.bufPrint(&want, "look: {s}: no such file", .{name}))); - } - try testing.expectEqual(Status.ok, wr(p, Node.of(serialOf(p), .look), "zz.txt\n").reply.status); - try testing.expect(th.logHas(p, "look: no match for \"zz.txt\"")); -} - 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(); @@ -3329,43 +3135,6 @@ test "a served-tree pane spoils no Grep, and Look . from a gone directory is ENO try testing.expectStringStartsWith(looked.reply.ename, "look: /tmp/pardes-no-such-dir-zz: no such directory"); } -test "a malformed address is bad address syntax; on a pane with no text any address is refused as nothing to address" { - const p = try th.withTerm(testing.allocator); - defer p.deinit(); - const t = try withFile(testing.allocator, "one\n"); - defer t.deinit(); - for ([_][]const u8{ "1x", "/(/", ",,x" }) |expr| { - const refused = wr(t, Node.of(serialOf(t), .addr), expr); - try testing.expectEqual(E.INVAL, refused.errno()); - try testing.expect(refused.reply.ename.len > 0); - } - try testing.expectEqualStrings("bad address syntax", wr(t, Node.of(serialOf(t), .addr), "1x").reply.ename); - // A terminal (as an image or a PDF): addr, dot and limit alike. - for ([_]tree.PaneFile{ .addr, .dot, .limit }) |file| for ([_][]const u8{ "1", "1x" }) |expr| { - const refused = wr(p, Node.of(serialOf(p), file), expr); - try testing.expectEqual(E.INVAL, refused.errno()); - try testing.expectEqualStrings("invalid address: this pane has no text to address", refused.reply.ename); - }; -} - -test "a bad event record says what is wrong with it" { - const p = try withFile(testing.allocator, "one\n"); - defer p.deinit(); - const event = Node.of(serialOf(p), .event); - const h = call(p, .{ .tag = 1, .op = .open, .node = event, .omode = 2 }).reply.handle; - 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| { - const refused = call(p, .{ .tag = 2, .op = .write, .node = event, .handle = h, .data = c[0] }); - try testing.expectEqual(E.INVAL, refused.errno()); - try testing.expect(std.mem.indexOf(u8, refused.reply.ename, c[1]) != null); - } - _ = call(p, .{ .tag = 3, .op = .release, .node = event, .handle = h }); -} - 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(); @@ -3790,24 +3559,6 @@ test "size is monotonic: growing is never refused, and a size once taken is take try testing.expectStringStartsWith(bad.reply.ename, "invalid size"); } -test "Repl with no such language is invalid, EINVAL, and names a few whole and how many more" { - const p = try th.withTerm(testing.allocator); - defer p.deinit(); - const refused = wr(p, Node.of(serialOf(p), .ctl), "Repl zzlang\n"); - try testing.expectEqual(E.INVAL, refused.errno()); - try testing.expect(std.mem.indexOf(u8, refused.reply.ename, "Repl: invalid language \"zzlang\"; - or one like zig ada bash c c_sharp clojure (") != null); - try testing.expect(std.mem.endsWith(u8, refused.reply.ename, " more)")); -} - -test "answer quotes the choice it refuses, and a bare name says it names nothing" { - const p = try withFile(testing.allocator, "x\n"); - defer p.deinit(); - const node = Node.of(serialOf(p), .ctl); - const empty = wr(p, node, "name \n"); - try testing.expectEqual(E.INVAL, empty.errno()); - try testing.expectEqualStrings("invalid file name: name takes the name, and there is none", empty.reply.ename); -} - test "a 10k-line Edit text block is taken in linear time and memory" { const gpa = testing.allocator; const p = try withFile(gpa, "x\n"); @@ -4040,40 +3791,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 "@p<serial>:<address> takes any sam address; a miss and an unknown serial are errs" { - const p = try withFile(testing.allocator, "foo x foo y\nbar\n"); - defer p.deinit(); - const serial = serialOf(p); - const root = @backingInt(tree.TopFile.look); - const dot = Node.of(serial, .dot); - const Case = struct { addr: []const u8, want: []const u8 }; - for ([_]Case{ - .{ .addr = "0/foo/", .want = " 0 3 " }, - .{ .addr = "/foo/", .want = " 6 9 " }, - .{ .addr = "#12,#15", .want = " 12 15 " }, - .{ .addr = "$", .want = " 16 16 " }, - .{ .addr = "1,2", .want = " 0 16 " }, - // Backward, as in addr: from the dot's start, wrapping to the last. - .{ .addr = "?foo?", .want = " 6 9 " }, - .{ .addr = "$-?y?", .want = " 10 11 " }, - }) |c| { - var line: [64]u8 = undefined; - try testing.expectEqual(Status.ok, wr(p, root, try std.fmt.bufPrint(&line, "@p{d}:{s}\n", .{ serial, c.addr })).reply.status); - try testing.expectEqualStrings(c.want, rd(p, dot, 0, 64).bytes); - } - var line: [64]u8 = undefined; - _ = wr(p, root, try std.fmt.bufPrint(&line, "@p{d}:/zzqq/\n", .{serial})); - try testing.expect(th.logHas(p, ": no match for regexp")); - try testing.expectEqualStrings("", rd(p, root, 0, 64).bytes); - _ = wr(p, root, "@p999:/foo/\n"); - try testing.expect(th.logHas(p, "look: no pane @p999")); - try testing.expectEqualStrings("", rd(p, root, 0, 64).bytes); - // A line address to no pane is a miss too, not the active pane. - _ = wr(p, root, "@p77:1\n"); - try testing.expect(th.logHas(p, "look: no pane @p77")); - try testing.expectEqualStrings("", rd(p, root, 0, 64).bytes); -} - 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(); @@ -4380,16 +4097,6 @@ test "Lspinfo's answer is the +Lsp pane it fills, as a Rename preview's is its + } -test "a look of ./x that is not there is a miss, as x and /abs/x are: answered, the err logged" { - const p = try withFile(testing.allocator, "x\n"); - defer p.deinit(); - for ([_][]const u8{ "./zzq-nosuch.txt\n", "zzq-nosuch.txt\n", "/zzq-nosuch.txt\n" }) |line| { - const r = wr(p, Node.of(serialOf(p), .look), line); - try testing.expectEqual(Status.ok, r.reply.status); - } - try testing.expect(th.logHas(p, "look: ./zzq-nosuch.txt: no such file")); -} - 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(); @@ -4429,14 +4136,6 @@ test "DumpDir refuses a relative directory and one that may not be written, up f try testing.expect(std.mem.endsWith(u8, p.fs.late_failure[0..p.fs.late_failure_len], ": permission denied")); } -test "a Mount dial with a network it does not know is a bad dial address, EINVAL" { - const p = try withFile(testing.allocator, "x\n"); - defer p.deinit(); - const r = wr(p, @backingInt(tree.TopFile.ctl), "Mount peer nowhere!x\n"); - try testing.expectEqual(E.INVAL, r.errno()); - try testing.expectStringStartsWith(r.reply.ename, "Mount: bad dial address: nowhere!x"); -} - test "a command or a terminal refused for room is refused before anything is logged of it, and its serial is never handed out again" { const p = try withFile(testing.allocator, "x\n"); defer p.deinit(); diff --git a/test/behaviour.zig b/test/behaviour.zig index d9b15183..72806b21 100644 --- a/test/behaviour.zig +++ b/test/behaviour.zig @@ -18,6 +18,7 @@ test { _ = @import("behaviour/other_files.zig"); _ = @import("behaviour/panes.zig"); _ = @import("behaviour/placement.zig"); + _ = @import("behaviour/repls.zig"); _ = @import("behaviour/root_ctl.zig"); _ = @import("behaviour/rules.zig"); _ = @import("behaviour/settings.zig"); 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)")); +} |
