summaryrefslogtreecommitdiff
path: root/test/behaviour/look_and_exec.zig
diff options
context:
space:
mode:
Diffstat (limited to 'test/behaviour/look_and_exec.zig')
-rw-r--r--test/behaviour/look_and_exec.zig110
1 files changed, 110 insertions, 0 deletions
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"));
+ };
+}