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.zig95
1 files changed, 95 insertions, 0 deletions
diff --git a/test/behaviour/settings.zig b/test/behaviour/settings.zig
index df70dbe6..a24a3010 100644
--- a/test/behaviour/settings.zig
+++ b/test/behaviour/settings.zig
@@ -174,3 +174,98 @@ test "settings: Back and Forward written to exec keep to the focused file, and J
.{ "Forward", "/b.txt", 80 },
});
}
+
+const syntax = @import("pardes_config").syntax_highlighting;
+
+/// The style /screen draws the cell `into` cells into the first place
+/// `text` is drawn.
+fn styleOf(s: *Session, text: []const u8, into: usize) ![]const u8 {
+ const x, const y = try s.where(text);
+ const screen = try s.screen();
+ const cols = try std.unicode.utf8CountCodepoints(screen[0..std.mem.indexOfScalar(u8, screen, '\n').?]);
+ return (try s.styles())[y * cols + x + into];
+}
+
+/// How many ` fn ` and ` if ` keywords the screen draws, each of whose two
+/// cells must be drawn in `want`.
+fn keywordsIn(s: *Session, want: []const u8) !usize {
+ const screen = try s.screen();
+ const styles = try s.styles();
+ const cols = try std.unicode.utf8CountCodepoints(screen[0..std.mem.indexOfScalar(u8, screen, '\n').?]);
+ var seen: usize = 0;
+ var rows = std.mem.splitScalar(u8, screen, '\n');
+ var y: usize = 0;
+ while (rows.next()) |row| : (y += 1) for ([_][]const u8{ " fn ", " if " }) |word| {
+ var from: usize = 0;
+ while (std.mem.indexOfPos(u8, row, from, word)) |i| : (from = i + 1) {
+ const x = try std.unicode.utf8CountCodepoints(row[0..i]) + 1;
+ for (0..2) |k| try std.testing.expectEqualStrings(want, styles[y * cols + x + k]);
+ seen += 1;
+ }
+ };
+ return seen;
+}
+
+test "settings: Colors off draws a source plain, and on again colours its keywords, the layout as it was, an edit made while off included" {
+ if (!syntax) return error.SkipZigTest;
+ for ([_]bool{ false, true }) |edit_while_off| {
+ var s = try Session.initFile(std.testing.allocator, "pub fn first() void { if (true) {} }\n");
+ defer s.deinit();
+ const n = try s.focused();
+ try s.write(s.at("/pane/{d}/name", .{n}), "/colors.zig\n");
+ var ident: []const u8 = "first";
+ if (edit_while_off) {
+ try std.testing.expect(!std.mem.eql(u8, try styleOf(&s, " fn ", 1), try styleOf(&s, "first", 0)));
+ try s.write("/ctl", "Colors off\n");
+ try s.replace(s.at("/pane/{d}/body", .{n}), "pub fn edited() void { if (false) {} }\n");
+ ident = "edited";
+ } else try s.write("/ctl", "Colors off\n");
+ try std.testing.expectEqual(@as(usize, 2), try keywordsIn(&s, try styleOf(&s, ident, 0)));
+ const layout = try s.read("/layout");
+ try s.write("/ctl", "Colors on\n");
+ try s.expect("/layout", layout);
+ const kw = try styleOf(&s, " fn ", 1);
+ try std.testing.expect(!std.mem.eql(u8, kw, try styleOf(&s, ident, 0)));
+ try std.testing.expect(!has(kw, "\"bold\":true"));
+ try std.testing.expectEqual(@as(usize, 2), try keywordsIn(&s, kw));
+ }
+}
+
+test "settings: SyntaxBold keywords stay coloured and bold in every row a pane grows into" {
+ if (!syntax) return error.SkipZigTest;
+ var s = try Session.initFile(std.testing.allocator, std.mem.asBytes(&@as([100][33]u8, @splat("pub fn f() void { if (true) {} }\n".*))));
+ defer s.deinit();
+ try s.write(s.at("/pane/{d}/name", .{try s.focused()}), "/resize.zig\n");
+ try s.write("/ctl", "SyntaxBold on\n");
+ s.detach();
+ try s.write("/ctl", "size 80 8\n");
+ const kw = try styleOf(&s, " fn ", 1);
+ try std.testing.expect(has(kw, "\"bold\":true"));
+ for ([_]usize{ 50, 12, 70 }) |rows| {
+ try s.write("/ctl", s.at("size 80 {d}\n", .{rows}));
+ try std.testing.expect(try keywordsIn(&s, kw) >= 2 * (rows - 4));
+ }
+}
+
+test "settings: every on/off setting the root ctl reads flips when its word is written bare, and Theme and Shell take a value" {
+ var s = try Session.initFile(std.testing.allocator, "x\n");
+ defer s.deinit();
+ var lines = std.mem.tokenizeScalar(u8, try s.read("/ctl"), '\n');
+ var flipped: usize = 0;
+ while (lines.next()) |line| {
+ const space = std.mem.indexOfScalar(u8, line, ' ') orelse continue;
+ const word, const was = .{ line[0..space], line[space + 1 ..] };
+ const on = std.mem.eql(u8, was, "on");
+ if (!on and !std.mem.eql(u8, was, "off")) continue;
+ try s.write("/ctl", s.at("{s}\n", .{word}));
+ try std.testing.expectEqualStrings(s.at("{s} {s}", .{ word, if (on) "off" else "on" }), try setting(&s, word));
+ flipped += 1;
+ }
+ try std.testing.expect(flipped > 20);
+ for ([_][]const u8{ "Colors off", "Wrap off", "Tagbottom on", "Debug on" }) |want|
+ try std.testing.expectEqualStrings(want, try setting(&s, want[0..std.mem.indexOfScalar(u8, want, ' ').?]));
+ try s.write("/ctl", "Theme acme\n");
+ try s.write("/ctl", "Shell /bin/sh\n");
+ try std.testing.expectEqualStrings("Theme acme", try setting(&s, "Theme"));
+ try std.testing.expectEqualStrings("Shell /bin/sh", try setting(&s, "Shell"));
+}