summaryrefslogtreecommitdiff
path: root/test/behaviour
diff options
context:
space:
mode:
Diffstat (limited to 'test/behaviour')
-rw-r--r--test/behaviour/event.zig11
-rw-r--r--test/behaviour/settings.zig34
-rw-r--r--test/behaviour/tree.zig15
3 files changed, 60 insertions, 0 deletions
diff --git a/test/behaviour/event.zig b/test/behaviour/event.zig
index 77a80e30..65222175 100644
--- a/test/behaviour/event.zig
+++ b/test/behaviour/event.zig
@@ -69,3 +69,14 @@ test "event: a bad event record says what is wrong with it" {
try std.testing.expect(has(s.said, c[1]));
}
}
+
+test "event: a write to the body is an EI record to the reader holding event" {
+ var s = try Session.initFile(std.testing.allocator, "replaced\n");
+ defer s.deinit();
+ const n = try s.focused();
+ const event = try s.hold(s.at("/pane/{d}/event", .{n}), 0);
+ defer s.clunk(event);
+ try s.write(s.at("/pane/{d}/body", .{n}), "event\n");
+ const record = try s.readFid(event);
+ try std.testing.expect(std.mem.startsWith(u8, record, "EI") and has(record, "event\n"));
+}
diff --git a/test/behaviour/settings.zig b/test/behaviour/settings.zig
index a24a3010..9a14ff50 100644
--- a/test/behaviour/settings.zig
+++ b/test/behaviour/settings.zig
@@ -269,3 +269,37 @@ test "settings: every on/off setting the root ctl reads flips when its word is w
try std.testing.expectEqualStrings("Theme acme", try setting(&s, "Theme"));
try std.testing.expectEqualStrings("Shell /bin/sh", try setting(&s, "Shell"));
}
+
+/// A cell's style (one of `Session.styles`) as its bold flag and ink.
+fn look(s: *Session, style: []const u8) !struct { bool, []const u8 } {
+ const a = s.arena.allocator();
+ const json = try std.json.parseFromSliceLeaky(std.json.Value, a, style, .{});
+ return .{ json.object.get("bold").?.bool, try std.json.Stringify.valueAlloc(a, json.object.get("fg").?, .{}) };
+}
+
+test "settings: a keyword is coloured apart from the text beside it, and not bold (SyntaxBold is off by default), at a long file's end" {
+ var s = try Session.initFile(std.testing.allocator, "initial\n");
+ defer s.deinit();
+ const n = try s.focused();
+ try s.write(s.at("/pane/{d}/name", .{n}), "keywords.zig\n");
+ var source: std.ArrayList(u8) = .empty;
+ for (0..9999) |_| try source.appendSlice(s.arena.allocator(), "// padding\n");
+ try source.appendSlice(s.arena.allocator(), "fn check() void {\n if (true) return;\n}\n");
+ try s.replace(s.at("/pane/{d}/body", .{n}), source.items);
+ const screen = try s.screen();
+ const styles = try s.styles();
+ const cols = std.mem.indexOfScalar(u8, screen, '\n').?;
+ try std.testing.expectEqual(styles.len, cols * (std.mem.count(u8, screen, "\n") + 1));
+ for ([_][]const u8{ "fn", "if" }) |word| {
+ const col, const row = try s.where(s.at("{s} ", .{word}));
+ const at = row * cols + col;
+ _, const ink = try look(&s, styles[at]);
+ for (styles[at..][0..word.len]) |cell| {
+ const bold, const each = try look(&s, cell);
+ try std.testing.expect(!bold);
+ try std.testing.expectEqualStrings(ink, each);
+ }
+ _, const plain = try look(&s, styles[at + word.len]);
+ try std.testing.expect(!std.mem.eql(u8, ink, plain));
+ }
+}
diff --git a/test/behaviour/tree.zig b/test/behaviour/tree.zig
index 7f9b37a4..56806589 100644
--- a/test/behaviour/tree.zig
+++ b/test/behaviour/tree.zig
@@ -42,3 +42,18 @@ test "tree: a terminal is listed as term with its directory as name, which a wri
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"));
}
+
+test "tree: a body takes a 60 KB write whole, a truncating one replaces it, and a pane not there is refused" {
+ var s = try Session.initFile(std.testing.allocator, "initial\n");
+ defer s.deinit();
+ var payload: std.ArrayList(u8) = .empty;
+ for (0..3000) |_| try payload.appendSlice(s.arena.allocator(), "const value = \"λ\";\n");
+ const n = try s.newPane();
+ const body = s.at("/pane/{d}/body", .{n});
+ try s.write(body, payload.items);
+ try s.expect(body, payload.items);
+ try s.replace(body, "replaced\n");
+ try s.expect(body, "replaced\n");
+ try std.testing.expectError(error.Refused, s.read("/pane/4294967295/body"));
+ try s.expect(body, "replaced\n");
+}