diff options
Diffstat (limited to 'test/behaviour/look_and_exec.zig')
| -rw-r--r-- | test/behaviour/look_and_exec.zig | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/test/behaviour/look_and_exec.zig b/test/behaviour/look_and_exec.zig index 0d8056da..c46ca394 100644 --- a/test/behaviour/look_and_exec.zig +++ b/test/behaviour/look_and_exec.zig @@ -713,3 +713,45 @@ test "look-and-exec: a pane's tagexec runs a word as a click in its tag, and rea try std.testing.expect(std.mem.indexOf(u8, try s.read("/log"), "from the tag") != null); try s.expect(tagexec, s.at("{d}\n", .{n})); } + +test "look-and-exec: a look at a directory opens a pane listing it, as acme's directory window: named with a trailing /, its entries, ctl's isdir 1, get reading it again" { + var tmp = std.testing.tmpDir(.{}); + defer tmp.cleanup(); + try tmp.dir.createDirPath(std.testing.io, "listed/sub"); + try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "listed/.dot", .data = "" }); + var s = try Session.initFile(std.testing.allocator, "x\n"); + defer s.deinit(); + const dir = s.at("{s}/listed", .{try tmpPath(&s, &tmp)}); + const scratch = try s.newPane(); + try s.write(s.at("/pane/{d}/look", .{scratch}), s.at("{s}\n", .{dir})); + const serial = try std.fmt.parseInt(u32, std.mem.trim(u8, try s.read("/look"), "\n"), 10); + try std.testing.expect(serial != scratch); + const words = struct { + fn of(text: []const u8, buf: [][]const u8) []const []const u8 { + var it = std.mem.tokenizeAny(u8, text, " \n"); + var n: usize = 0; + while (it.next()) |w| : (n += 1) buf[n] = w; + return buf[0..n]; + } + }.of; + var buf: [16][]const u8 = undefined; + var rows = std.mem.tokenizeScalar(u8, try s.read("/index"), '\n'); + const row = while (rows.next()) |r| { + if (std.mem.startsWith(u8, r, s.at("{d} ", .{serial}))) break words(r, &buf); + } else return error.NoRow; + try std.testing.expectEqualStrings("text", row[1]); + try std.testing.expectEqualStrings("0", row[2]); + try std.testing.expectEqualStrings(s.at("{s}/", .{dir}), row[3]); + const body = words(try s.read(s.at("/pane/{d}/body", .{serial})), &buf); + try std.testing.expectEqual(@as(usize, 2), body.len); + try std.testing.expectEqualStrings(".dot", body[0]); + try std.testing.expectEqualStrings("sub/", body[1]); + try std.testing.expectEqualStrings("1", words(try s.read(s.at("/pane/{d}/ctl", .{serial})), &buf)[3]); + try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "listed/later", .data = "" }); + try s.write(s.at("/pane/{d}/ctl", .{serial}), "get\n"); + const again = words(try s.read(s.at("/pane/{d}/body", .{serial})), &buf); + try std.testing.expectEqual(@as(usize, 3), again.len); + try std.testing.expectEqualStrings(".dot", again[0]); + try std.testing.expectEqualStrings("later", again[1]); + try std.testing.expectEqualStrings("sub/", again[2]); +} |
