From ff0b8a382de7a1994a6912dc71ba28a8ecdaf474 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Wed, 4 Nov 2026 10:45:36 -0300 Subject: test: syntax colours and Save's prompt through the 9P tree alone, Session.styles added (each cell's style as /screen draws it, as JSON text): in test/behaviour/settings.zig Colors off drawing a source plain and on again colouring its fn and if, the layout as it was, an edit made while off included, and SyntaxBold keywords coloured and bold in every row a detached session's size grows a pane into; in panes.zig a rename colouring a source in its new name's language, its text unchanged; in keys.zig Save's prompt on a scratch made by New from a file's pane starting from its directory, one slash after it (/dír space/, and / alone); each checked to fail against a break (the Colors toggle not marking syntax dirty, the painted stretch four rows from the scroll, a rename not marking syntax dirty, the prompt's slash always added, the prompt from the session's directory); test/panes.zig's Colors and growing tests and pane.zig's cached-syntax rename test deleted, and the Save prompt test trimmed to an owned directory ending in a slash or empty (a shell's, T2) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge --- test/panes.zig | 101 +++------------------------------------------------------ 1 file changed, 4 insertions(+), 97 deletions(-) (limited to 'test/panes.zig') diff --git a/test/panes.zig b/test/panes.zig index db816d41..c996ca00 100644 --- a/test/panes.zig +++ b/test/panes.zig @@ -1397,11 +1397,13 @@ test "a prompt that cannot be opened leaves the open one as it was" { } } -test "Save's prompt starts from the pane's directory" { +// A file's directory is test/behaviour/keys.zig's; an owned directory (a +// shell's) ending in a slash, or none, only a real shell gives. +test "Save's prompt starts from an owned directory ending in a slash, or none" { const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true }); defer p.deinit(); const pane = try p.setTestFile("one\n"); - for ([_][]const u8{ "/dír space", "/dír space/", "" }) |dir| { + for ([_][]const u8{ "/dír space/", "" }) |dir| { try pane.setOwnedCwd(dir); const slash = if (dir.len == 0 or dir[dir.len - 1] != '/') "/" else ""; p.startPrompt(pane, &pane.body, .save); @@ -3772,101 +3774,6 @@ test "cancelled normal gestures leave no count or subprefix through raw tty mode } } -test "Colors restores syntax after rendering disabled files and disabled edits" { - if (!syntax.enabled) return error.SkipZigTest; - const gpa = std.testing.allocator; - for ([_]bool{ false, true }) |edit_while_disabled| { - const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 80, .rows = 12 }); - defer p.deinit(); - const pane = try p.setTestFile("pub fn first() void { if (true) {} }\n"); - const file = &pane.file.?; - gpa.free(file.path); - file.path = try gpa.dupe(u8, "/colors.zig"); - p.settings.colors = edit_while_disabled; - p.presentation.enabled = false; - var frame = std.heap.ArenaAllocator.init(gpa); - defer frame.deinit(); - _ = try p.render(frame.allocator()); - if (edit_while_disabled) { - try std.testing.expect(file.highlights.len > 0); - p.update(.{ .command = "Colors" }); - panes.File.setContent(p, file, try gpa.dupe(u8, "pub fn edited() void { if (false) {} }\n")); - _ = frame.reset(.retain_capacity); - _ = try p.render(frame.allocator()); - } - try std.testing.expect(!p.settings.colors); - try std.testing.expectEqual(@as(usize, 0), file.highlights.len); - try std.testing.expect(!file.syntax_dirty); - const rect = p.rects[0]; - const cols = pane.cols; - const rows = pane.rows; - p.update(.{ .command = "Colors" }); - try std.testing.expectEqual(rect, p.rects[0]); - try std.testing.expectEqual(cols, pane.cols); - try std.testing.expectEqual(rows, pane.rows); - _ = frame.reset(.retain_capacity); - const surface = try p.render(frame.allocator()); - try std.testing.expect(p.settings.colors); - try std.testing.expect(file.highlights.len > 0); - try std.testing.expect(!file.syntax_dirty); - var seen: usize = 0; - for (surface.cells[0 .. surface.cells.len - 1], 0..) |*first, i| { - const second = &surface.cells[i + 1]; - if (!(std.mem.eql(u8, first.grapheme(), "f") and std.mem.eql(u8, second.grapheme(), "n")) and - !(std.mem.eql(u8, first.grapheme(), "i") and std.mem.eql(u8, second.grapheme(), "f"))) continue; - seen += 1; - for ([_]*pardes.Cell{ first, second }) |cell| { - try std.testing.expectEqual(pardes.Color{ .rgb = p.theme().kw }, cell.style.fg); - try std.testing.expect(!cell.style.bold); - } - } - try std.testing.expectEqual(@as(usize, 2), seen); - } -} - -test "growing a file pane colors every newly visible Zig keyword" { - if (!syntax.enabled) return error.SkipZigTest; - const gpa = std.testing.allocator; - const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 80, .rows = 8 }); - defer p.deinit(); - const pane = try p.setTestFile(std.mem.asBytes(&@as([100][33]u8, @splat("pub fn f() void { if (true) {} }\n".*)))); - const file = &pane.file.?; - gpa.free(file.path); - file.path = try gpa.dupe(u8, "/resize.zig"); - p.update(.{ .command = "SyntaxBold" }); - try std.testing.expect(p.settings.syntax_bold); - p.settings.colors = true; - p.presentation.enabled = false; - var frame = std.heap.ArenaAllocator.init(gpa); - defer frame.deinit(); - _ = try p.render(frame.allocator()); - const initial_end = file.highlight_start + file.highlights.len; - for ([_]u16{ 50, 12, 70 }) |rows| { - p.update(.{ .resize = .{ .cols = 80, .rows = rows } }); - _ = frame.reset(.retain_capacity); - const surface = try p.render(frame.allocator()); - const rect = p.rects[0]; - const body_y = bodyY(p, rect); - var seen: usize = 0; - for (body_y..body_y + bodyH(p, rect)) |y| { - for (rect.x + config.GUTTER..rect.x + rect.w - 1) |x| { - const first = surface.at(@intCast(x), @intCast(y)); - const second = surface.at(@intCast(x + 1), @intCast(y)); - if (!(std.mem.eql(u8, first.grapheme(), "f") and std.mem.eql(u8, second.grapheme(), "n")) and - !(std.mem.eql(u8, first.grapheme(), "i") and std.mem.eql(u8, second.grapheme(), "f"))) continue; - seen += 1; - for ([_]*pardes.Cell{ first, second }) |cell| { - try std.testing.expectEqual(pardes.Color{ .rgb = p.theme().kw }, cell.style.fg); - try std.testing.expect(cell.style.bold); - } - } - } - try std.testing.expect(seen >= 2 * (rows - 4)); - try std.testing.expect(file.highlight_start + file.highlights.len > initial_end); - try std.testing.expect(!file.syntax_dirty); - } -} - test "Zig keywords keep every rendered byte colored across line-number widths" { if (!syntax.enabled) return error.SkipZigTest; const gpa = std.testing.allocator; -- cgit v1.3 From 9cfebaeca67301a8925eaa44c71859b42b676e59 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Wed, 4 Nov 2026 10:49:58 -0300 Subject: test: a tag's file-name tint and Back and Forward through the 9P tree alone: in test/behaviour/tags.zig a file pane's tag tinting its name (界file.zig) and not its directory, dirty marker or words, the tag at the top or the bottom (Session.styles); in keys.zig Ctrl-o and Ctrl-i (Kctl o, i) jumping between line 60 and line 1 made by 60G1G, dot empty where the jump lands and no B1 sweep drawn after either, a wrapped Unicode and tab sweep included, swept either way; each checked to fail against a break (the tint starting at the last slash, focusPaneLine not moving the caret; clearNavigationSelection returning at once is not caught, the key's own path dropping the sweep too); test/panes.zig's two one-pane jump tests deleted, the tint test trimmed to its search pane (fillResults), the cross-pane jump test kept (it seeds held selections) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge --- test/behaviour/keys.zig | 57 +++++++++++++++++++++++++++++++++++++ test/behaviour/tags.zig | 31 ++++++++++++++++++++ test/panes.zig | 76 ++++--------------------------------------------- 3 files changed, 93 insertions(+), 71 deletions(-) (limited to 'test/panes.zig') diff --git a/test/behaviour/keys.zig b/test/behaviour/keys.zig index 989489d7..0c2c0a43 100644 --- a/test/behaviour/keys.zig +++ b/test/behaviour/keys.zig @@ -240,3 +240,60 @@ test "keys: Save's prompt on a scratch starts from the scratch's directory, one try s.keys("\x1b"); } } + +/// A B1 sweep from cell (x0, y0) to (x1, y1). +fn sweep(s: *Session, x0: usize, y0: usize, x1: usize, y1: usize) !void { + try s.write("/mousein", s.at("m {d} {d} 1\nm {d} {d} 1\nm {d} {d} 0\n", .{ x0, y0, x1, y1, x1, y1 })); +} + +/// Whether any cell /screen draws is in `style`. +fn drawsIn(s: *Session, style: []const u8) !bool { + for (try s.styles()) |cell| if (std.mem.eql(u8, cell, style)) return true; + return false; +} + +test "keys: Ctrl-o and Ctrl-i jump back and forth, leaving no sweep drawn, a wrapped Unicode and tab one included" { + const ctl = "\u{F017}"; + for ([_]struct { []const u8, []const u8, bool }{ + .{ "alpha\nbravo\n", "alpha", false }, + .{ "界\tabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789\n", "界", true }, + }) |c| for ([_]bool{ false, true }) |reverse| { + const prefix, const first, const wrap = c; + var buf: [4096]u8 = undefined; + @memcpy(buf[0..prefix.len], prefix); + for (0..80) |i| @memcpy(buf[prefix.len + i * 27 ..][0..27], "unrelated destination text\n"); + var s = try Session.initFile(std.testing.allocator, buf[0 .. prefix.len + 80 * 27]); + defer s.deinit(); + const n = try s.focused(); + s.detach(); + try s.write("/ctl", "size 34 10\n"); + try s.write("/ctl", if (wrap) "Wrap on\n" else "Wrap off\n"); + const dot = s.at("/pane/{d}/dot", .{n}); + const addr = s.at("/pane/{d}/addr", .{n}); + // Two places in the jump list: line 60, then line 1. + try s.keys("60G1G"); + const x, const y = try s.where(first); + const plain = (try s.styles())[0]; + if (reverse) try sweep(&s, x + 3, y + 1, x + 1, y) else try sweep(&s, x + 1, y, x + 3, y + 1); + const screen = try s.screen(); + const cols = try std.unicode.utf8CountCodepoints(screen[0..std.mem.indexOfScalar(u8, screen, '\n').?]); + const swept = (try s.styles())[(y + 1) * cols + x]; + try std.testing.expect(!std.mem.eql(u8, swept, plain)); + try s.keys(ctl ++ "o"); + try s.write(addr, "60"); + const line60 = (try s.range(addr))[0]; + try std.testing.expectEqual(.{ line60, line60 }, try s.range(dot)); + try std.testing.expectError(error.NotOnScreen, s.where(first)); + try std.testing.expect(!try drawsIn(&s, swept)); + // A sweep made after Back is gone after Forward. + const x2, const y2 = try s.where("unrelated"); + try sweep(&s, x2 + 1, y2, x2 + 3, y2 + 1); + try std.testing.expect(try drawsIn(&s, swept)); + try s.keys(ctl ++ "i"); + // Back where the sweep left the caret, nothing selected. + const q0, const q1 = try s.range(dot); + try std.testing.expect(q0 == q1 and q1 < line60); + _ = try s.where(first); + try std.testing.expect(!try drawsIn(&s, swept)); + }; +} diff --git a/test/behaviour/tags.zig b/test/behaviour/tags.zig index f4a5a469..39ca3a05 100644 --- a/test/behaviour/tags.zig +++ b/test/behaviour/tags.zig @@ -450,3 +450,34 @@ test "tags: truncating a tag clears its own text, u in the tag undoes it, and > try s.write(path, " Tail\n"); try std.testing.expectEqualStrings("/test.txt Make\nMore\n Tail\n", try tag(&s, n)); } + +test "tags: a pane tag's file name is tinted, its directory, dirty marker and words not, the tag at the top or the bottom" { + for ([_]bool{ false, true }) |bottom| { + var s = try Session.initFile(std.testing.allocator, "body\n"); + defer s.deinit(); + const n = try s.focused(); + try s.write("/ctl", "FocusTint off\n"); + if (bottom) try s.write("/ctl", "Tagbottom\n"); + try s.write(s.at("/pane/{d}/name", .{n}), "/project/界file.zig\n"); + try s.write(s.at("/pane/{d}/dirty", .{n}), "1"); + const x0, const y = try s.where("/project/"); + 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 rows = std.mem.splitScalar(u8, screen, '\n'); + for (0..y) |_| _ = rows.next(); + var cells = (try std.unicode.Utf8View.init(rows.next().?)).iterator(); + var x: usize = 0; + var tinted: ?[]const u8 = null; + var ink: ?[]const u8 = null; + while (cells.nextCodepointSlice()) |cell| : (x += 1) { + if (x < x0 or std.mem.eql(u8, cell, " ")) continue; + // `界file.zig`: the wide glyph's two cells, then eight. + const in_name = x >= x0 + "/project/".len and x < x0 + "/project/".len + 10; + const want = if (in_name) &tinted else &ink; + if (want.* == null) want.* = styles[y * cols + x]; + try std.testing.expectEqualStrings(want.*.?, styles[y * cols + x]); + } + try std.testing.expect(!std.mem.eql(u8, tinted.?, ink.?)); + } +} diff --git a/test/panes.zig b/test/panes.zig index c996ca00..a7ecf994 100644 --- a/test/panes.zig +++ b/test/panes.zig @@ -788,75 +788,8 @@ const JumpSelectionTests = struct { p.update(.{ .mouse = .{ .button = .left, .kind = .release, .col = col1, .row = row1 } }); } - fn exercise(prefix: []const u8, wrap: bool, reverse: bool, first_col: u16, last_col: u16, expected: ?[]const u8) !void { - const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 34, .rows = 10 }); - defer p.deinit(); - p.settings.wrap = wrap; - const text = try std.fmt.allocPrint(p.gpa, "{s}{s}", .{ prefix, std.mem.asBytes(&@as([80][27]u8, @splat("unrelated destination text\n".*))) }); - defer p.gpa.free(text); - const pane = try p.setTestFile(text); - var frame = std.heap.ArenaAllocator.init(p.gpa); - defer frame.deinit(); - _ = try p.render(frame.allocator()); - if (wrap) try std.testing.expectEqual(pane.wrap_line[0], pane.wrap_line[1]); - const rect = p.rects[0]; - const x = rect.x + config.GUTTER + panes.File.gutterWidth(pane); - const y = p.bodyTop(pane, rect); - if (reverse) - drag(p, x + last_col, y + 1, x + first_col, y) - else - drag(p, x + first_col, y, x + last_col, y + 1); - - const selected = try p.gpa.dupe(u8, pardes.exec.heldSelection(p, 0) orelse return error.MissingMouseSelection); - defer p.gpa.free(selected); - if (expected) |want| try std.testing.expectEqualStrings(want, selected); - try std.testing.expect(std.mem.indexOfScalar(u8, selected, '\n') != null); - if (wrap) try std.testing.expect(std.mem.indexOf(u8, selected, "界") != null); - - // Seed two actual locations after the drag, so both history directions - // must scroll and discard the previous selection. - p.njumps = 2; - p.jcur = 1; - p.jumps[0] = .{ .pane = 0, .serial = pane.serial, .line = 60, .col = 1 }; - p.jumps[1] = .{ .pane = 0, .serial = pane.serial, .line = 1, .col = 1 }; - p.update(.{ .key = .{ .cp = 'o', .ctrl = true } }); - _ = frame.reset(.retain_capacity); - _ = try p.render(frame.allocator()); - try std.testing.expectEqual(@as(usize, 0), p.jcur); - try std.testing.expect(pane.file.?.scroll > 20); - try LookResetTests.cleared(pane); - try std.testing.expect(!pane.body.vsel.active); - try std.testing.expect(pardes.exec.heldSelection(p, 0) == null); - try std.testing.expectEqual(@as(i32, 59), pane.body.cur_row); - try std.testing.expectEqual(@as(i32, 0), pane.body.cur_col); - - // A selection created after Back must also disappear on Forward. - // Back announces itself, so the body sits under a notice band now. - const y2 = p.bodyTop(pane, p.rects[0]); - drag(p, x + 1, y2, x + 3, y2 + 1); - try std.testing.expect(pardes.exec.heldSelection(p, 0) != null); - p.update(.{ .key = .{ .cp = 'i', .ctrl = true } }); - _ = frame.reset(.retain_capacity); - _ = try p.render(frame.allocator()); - try std.testing.expectEqual(@as(usize, 1), p.jcur); - try std.testing.expectEqual(@as(usize, 0), pane.file.?.scroll); - try LookResetTests.cleared(pane); - try std.testing.expect(!pane.body.vsel.active); - try std.testing.expect(pardes.exec.heldSelection(p, 0) == null); - try std.testing.expectEqual(@as(i32, 0), pane.body.cur_row); - try std.testing.expectEqual(@as(i32, 0), pane.body.cur_col); - } - - test "jump selection clears copied sweeps in both history directions" { - for ([_]bool{ false, true }) |reverse| - try exercise("alpha\nbravo\n", false, reverse, 1, 3, "lpha\nbrav"); - } - - test "jump selection clears wrapped Unicode and tab rectangles" { - for ([_]bool{ false, true }) |reverse| - try exercise("界\tabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789\n", true, reverse, 0, 8, null); - } - + // One pane's Back and Forward are test/behaviour/keys.zig's; this + // one seeds held selections in two panes, which only internals reach. test "jump selection clears source and destination state across panes" { const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 100, .rows = 30 }); defer p.deinit(); @@ -947,7 +880,9 @@ const TagNameTintTests = struct { return visible_name; } - test "tag filename tint excludes directories dirty marker and output commands" { + // A file pane's is test/behaviour/tags.zig's; a search pane's needs + // results put in through fillResults. + test "tag filename tint of a search pane excludes its directory and command" { for ([_]bool{ false, true }) |bottom| { const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 100, .rows = 24 }); defer p.deinit(); @@ -959,7 +894,6 @@ const TagNameTintTests = struct { configure(p); defer p.custom_theme = null; p.settings.tag_bottom = bottom; - try std.testing.expect((try check(p, 0, pane.file.?.path)) > 0); try panes.Output.fillResults(p, 0, "/project", .search, "tint", try p.gpa.dupe(u8, "no matches\n"), null); const id = pane.search_pane.?; p.update(.tick); -- cgit v1.3