summaryrefslogtreecommitdiff
path: root/test/behaviour/tree.zig
diff options
context:
space:
mode:
Diffstat (limited to 'test/behaviour/tree.zig')
-rw-r--r--test/behaviour/tree.zig44
1 files changed, 44 insertions, 0 deletions
diff --git a/test/behaviour/tree.zig b/test/behaviour/tree.zig
new file mode 100644
index 00000000..7f9b37a4
--- /dev/null
+++ b/test/behaviour/tree.zig
@@ -0,0 +1,44 @@
+//! docs/typ/reference.typ, The tree <tree>.
+const std = @import("std");
+const Session = @import("session").Session;
+
+fn has(hay: []const u8, needle: []const u8) bool {
+ return std.mem.indexOf(u8, hay, needle) != null;
+}
+
+/// The first column's serial, /layout's first word.
+fn firstColumn(s: *Session) ![]const u8 {
+ return std.mem.sliceTo(try s.read("/layout"), ' ');
+}
+
+test "tree: index lists serial kind dirty name column, and stats 0, a view generated by each read" {
+ var s = try Session.initFile(std.testing.allocator, "hello\nthere\n");
+ defer s.deinit();
+ const n = try s.focused();
+ const col = try firstColumn(&s);
+ const clean = s.at("{d} text 0 /test.txt {s}\n", .{ n, col });
+ const index = try s.read("/index");
+ const at = std.mem.indexOf(u8, index, clean) orelse return error.NotListed;
+ const st = try s.stat("/index");
+ try std.testing.expectEqual(@as(u64, 0), st.size);
+ try std.testing.expectEqual(@as(u16, 0o444), st.mode);
+ try s.write(s.at("/pane/{d}/body", .{n}), "more\n");
+ try std.testing.expect(has(try s.read("/index"), s.at("{d} text 1 /test.txt {s}\n", .{ n, col })));
+ // Read from an offset, as any file.
+ const kind = at + std.mem.indexOfScalar(u8, clean, ' ').? + 1;
+ try std.testing.expectEqualStrings("text", try s.readAt("/index", kind, 4));
+ const made = try s.newPane();
+ const name = std.mem.trimEnd(u8, try s.read(s.at("/pane/{d}/name", .{made})), "\n");
+ try std.testing.expect(std.mem.endsWith(u8, try s.read("/index"), s.at("\n{d} text 0 {s} {s}\n", .{ made, name, col })));
+}
+
+test "tree: a terminal is listed as term with its directory as name, which a write to name cannot change" {
+ var s = try Session.initTerm(std.testing.allocator);
+ defer s.deinit();
+ const n = try s.focused();
+ const dir = std.mem.trimEnd(u8, try s.read(s.at("/pane/{d}/name", .{n})), "\n");
+ try std.testing.expect(std.mem.startsWith(u8, dir, "/"));
+ try std.testing.expect(has(try s.read("/index"), s.at("{d} term 0 {s} {s}\n", .{ n, dir, try firstColumn(&s) })));
+ try std.testing.expectEqual(@as(u16, 22), try s.refused(s.at("/pane/{d}/name", .{n}), "/elsewhere\n"));
+ try std.testing.expect(std.mem.startsWith(u8, s.said, "invalid rename: a terminal is named"));
+}