diff options
| -rw-r--r-- | test/behaviour/keys.zig | 57 | ||||
| -rw-r--r-- | test/behaviour/tags.zig | 31 | ||||
| -rw-r--r-- | test/panes.zig | 76 |
3 files changed, 93 insertions, 71 deletions
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); |
