summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/behaviour.zig1
-rw-r--r--test/behaviour/addresses.zig20
-rw-r--r--test/behaviour/edit.zig16
-rw-r--r--test/behaviour/event.zig16
-rw-r--r--test/behaviour/flags.zig42
-rw-r--r--test/behaviour/look_and_exec.zig110
-rw-r--r--test/behaviour/mounts.zig7
-rw-r--r--test/behaviour/panes.zig36
-rw-r--r--test/behaviour/repls.zig11
-rw-r--r--test/behaviour/root_ctl.zig7
-rw-r--r--test/behaviour/settings.zig11
11 files changed, 277 insertions, 0 deletions
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)"));
+}