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