summaryrefslogtreecommitdiff
path: root/test/panes.zig
diff options
context:
space:
mode:
Diffstat (limited to 'test/panes.zig')
-rw-r--r--test/panes.zig1017
1 files changed, 0 insertions, 1017 deletions
diff --git a/test/panes.zig b/test/panes.zig
index fc3f7804..db816d41 100644
--- a/test/panes.zig
+++ b/test/panes.zig
@@ -182,393 +182,6 @@ fn tagY(p: *Pardes, r: anytype) u16 {
return p.tagTop(paneAt(p, r), r);
}
-test "a tag with a newline in it is as tall as its lines, and each line is typed into and pointed at" {
- for ([_]bool{ false, true }) |bottom| {
- const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 80, .rows = 14 });
- defer p.deinit();
- const pane = try p.setTestFile("body\n");
- p.presentation.enabled = false;
- p.settings.tag_bottom = bottom;
- p.update(.tick);
- try std.testing.expectEqual(@as(u16, 1), pane.tag_rows);
- const height = p.rects[0].h;
- const body_rows = pane.rows;
- // Insert mode in a tag is a body's: Enter is a new line.
- p.update(.{ .key = .{ .cp = ':' } });
- p.update(.{ .key = .{ .cp = 'A' } });
- p.update(.{ .key = .{ .cp = Key.enter } });
- p.update(.{ .key = .{ .cp = 'S', .text = "Second" } });
- try std.testing.expect(std.mem.endsWith(u8, pardes.tagline.curTail(pane), "\nSecond"));
- try std.testing.expectEqual(@as(u16, 2), pane.tag_rows);
- // The pane keeps its height; the body gives the tag its row.
- try std.testing.expectEqual(height, p.rects[0].h);
- try std.testing.expectEqual(body_rows - 1, pane.rows);
- var frame = std.heap.ArenaAllocator.init(std.testing.allocator);
- defer frame.deinit();
- const surface = try p.render(frame.allocator());
- const r = p.rects[0];
- const tag_y = p.tagTop(pane, r);
- const x = r.x + pardes.TAG_TEXT_INSET;
- try std.testing.expectEqualStrings("/", surface.at(x, tag_y).grapheme());
- for ("Second", 0..) |byte, i| try std.testing.expectEqual(byte, surface.at(x + @as(u16, @intCast(i)), tag_y + 1).text[0]);
- try std.testing.expectEqual(pardes.FontRole.tagline, surface.at(x, tag_y + 1).style.font_role);
- // the caret is on the second line, after what was typed
- try std.testing.expectEqual(tag_y + 1, surface.cursor.?.y);
- try std.testing.expectEqual(x + 6, surface.cursor.?.x);
- // the body starts under (or over) the whole tag
- const body_y = p.bodyTop(pane, r);
- try std.testing.expectEqual(if (bottom) r.y else r.y + 2, body_y);
- try std.testing.expectEqualStrings("b", surface.at(r.x + config.GUTTER + panes.File.gutterWidth(pane), body_y).grapheme());
- // one layer, a row to each line, for a pixel shell
- var layers: usize = 0;
- for (p.surface.tagLayers()) |*layer| {
- if (layer.rows == 0 or layer.kind != .pane or layer.id != 0) continue;
- try std.testing.expectEqual(tag_y, layer.viewport.y);
- try std.testing.expectEqual(@as(u16, 2), layer.rows);
- try std.testing.expectEqual(@as(u16, 2), layer.viewport.h);
- layers += 1;
- }
- try std.testing.expectEqual(@as(usize, 1), layers);
- // a click on the second line puts the tag's cursor on it
- p.update(.{ .key = .{ .cp = Key.escape } });
- p.update(.{ .key = .{ .cp = ':' } });
- ClickCursorTests.click(p, .left, x + 2, tag_y + 1);
- try std.testing.expect(pane.focus == .tag);
- try std.testing.expectEqual(@as(i32, 1), pane.tag.cur_row);
- try std.testing.expectEqual(@as(i32, 2), pane.tag.cur_col);
- // and the pane's text, a row to a screen row, has both of its lines
- const text = try pardes.edit.paneText(p, pane);
- try std.testing.expect(std.mem.startsWith(u8, modal.lineSlice(text, 0), "/test.txt"));
- try std.testing.expectEqualStrings("Second", modal.lineSlice(text, 1));
- try std.testing.expectEqualStrings("body\n", pane.file.?.content);
- }
-}
-
-test "a tag with more lines than rows scrolls to keep its caret in view" {
- const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 80, .rows = 30 });
- defer p.deinit();
- const pane = try p.setTestFile("body\n");
- p.presentation.enabled = false;
- var many: std.ArrayList(u8) = .empty;
- defer many.deinit(std.testing.allocator);
- for (1..21) |n| try many.print(std.testing.allocator, "\nL{d}", .{n});
- try pane.appendTag(many.items);
- p.update(.tick);
- try std.testing.expectEqual(@as(u16, pardes.MAX_TAG_ROWS), pane.tag_rows);
- var frame = std.heap.ArenaAllocator.init(std.testing.allocator);
- defer frame.deinit();
- const r = p.rects[0];
- const x = r.x + pardes.TAG_TEXT_INSET;
- // To the last line: the tag scrolls so it is the bottom row, caret on it.
- p.update(.{ .key = .{ .cp = ':' } });
- p.update(.{ .key = .{ .cp = 'g' } });
- p.update(.{ .key = .{ .cp = 'e' } });
- try std.testing.expectEqual(@as(i32, 20), pane.tag.cur_row);
- const bottom = try p.render(frame.allocator());
- const tag_y = p.tagTop(pane, r);
- const last_row = tag_y + pardes.MAX_TAG_ROWS - 1;
- try std.testing.expectEqual(last_row, bottom.cursor.?.y);
- try std.testing.expectEqualStrings("L", bottom.at(x, last_row).grapheme());
- try std.testing.expectEqualStrings("2", bottom.at(x + 1, last_row).grapheme());
- try std.testing.expectEqualStrings("0", bottom.at(x + 2, last_row).grapheme());
- // what the pointer sees is what is shown: its first row is line 13
- const text = try pardes.edit.paneText(p, pane);
- try std.testing.expectEqualStrings("L13", modal.lineSlice(text, 0));
- ClickCursorTests.click(p, .left, x + 1, tag_y + 1);
- try std.testing.expectEqual(@as(i32, 14), pane.tag.cur_row);
- try std.testing.expectEqual(@as(i32, 1), pane.tag.cur_col);
- // Back to the first line brings the prefix back into view.
- p.update(.{ .key = .{ .cp = Key.escape } });
- p.update(.{ .key = .{ .cp = 'g' } });
- p.update(.{ .key = .{ .cp = 'g' } });
- const top = try p.render(frame.allocator());
- try std.testing.expectEqual(@as(u16, 0), pane.tag_top);
- try std.testing.expectEqual(tag_y, top.cursor.?.y);
- try std.testing.expectEqualStrings("/", top.at(x, tag_y).grapheme());
-
- // A column tag is one row, as acme's: its lines are joined.
- many.clearRetainingCapacity();
- try many.appendSlice(std.testing.allocator, "New");
- for (1..21) |n| try many.print(std.testing.allocator, "\nC{d}", .{n});
- p.col_tags[0].own = try p.gpa.dupe(u8, many.items);
- p.update(.tick);
- try std.testing.expectEqual(pardes.COLBAR_H, p.columnBarHeight());
- try std.testing.expect(std.mem.indexOfScalar(u8, p.col_tags[0].own.?, '\n') == null);
-}
-
-const TagNavigationTests = struct {
- fn key(p: *Pardes, cp: u21) void {
- p.update(.{ .key = .{ .cp = cp } });
- }
-
- test "s, S and | in a tag answer for the tag's own text; / still searches the body" {
- const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 100, .rows = 20 });
- defer p.deinit();
- const pane = try p.setTestFile("Some body\n");
- try setTag(pane, " Save Del Snarf");
- key(p, ':');
- key(p, 'x'); // the tag's line
- key(p, 's');
- try std.testing.expect(pane.prompt == .search and pane.prompt_for == .tag and pane.focus == .tag);
- p.update(.{ .key = .{ .cp = 'S', .text = "S" } });
- key(p, Key.enter);
- try std.testing.expect(pane.focus == .tag and pane.prompt == .none);
- var ranges: [panes.Text.max_selections]modal.Selection = undefined;
- const text = try pardes.edit.flatSurface(p, &pane.tag);
- const got = pane.tag.ranges(text, 0, &ranges);
- try std.testing.expectEqual(@as(usize, 2), got.n);
- for (ranges[0..got.n]) |range| try std.testing.expectEqualStrings("S", text[@min(range.anchor, range.head)..@max(range.anchor, range.head)]);
- // the body's selection is its own
- try std.testing.expectEqual(@as(u16, 0), pane.body.nsel);
- // `/` from the tag is the body's search, as acme's Look from a tag is
- key(p, ',');
- key(p, '/');
- try std.testing.expect(pane.prompt == .search and pane.prompt_for == .body and pane.focus == .body);
- key(p, Key.escape);
- try std.testing.expect(pane.prompt == .none and pane.focus == .body);
- }
-
- test "ms and md edit a tag's own text, and the text the edit made is read back whole" {
- const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 100, .rows = 20 });
- defer p.deinit();
- const pane = try p.setTestFile("body\n");
- p.update(.tick);
- key(p, ':'); // the tag, on `Save` the first time
- for ("miwms(") |cp| key(p, cp);
- try std.testing.expect(std.mem.indexOf(u8, pardes.tagline.curTail(pane), "(Save)") != null);
- for ("md(") |cp| key(p, cp);
- try std.testing.expect(std.mem.indexOf(u8, pardes.tagline.curTail(pane), " Save ") != null);
- try std.testing.expect(std.mem.indexOf(u8, pardes.tagline.curTail(pane), "(") == null);
- }
-
- test "the keyboard reaches a tag's path, which it can select and yank but not edit" {
- const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 100, .rows = 20 });
- defer p.deinit();
- const pane = try p.setTestFile("body\n");
- p.update(.tick);
- key(p, ':');
- // `0` is the line's start, as in acme, where the name is ordinary text
- key(p, '0');
- try std.testing.expectEqual(@as(i32, 0), pane.tag.cur_col);
- key(p, 'E');
- key(p, 'y');
- try std.testing.expectEqualStrings("/test.txt", p.registers.text(p.gpa, '"').?);
- // an edit that reaches into it is refused, the cursor with it
- const before = try std.testing.allocator.dupe(u8, try pardes.edit.flatSurface(p, &pane.tag));
- defer std.testing.allocator.free(before);
- const cursor = pane.tag.cur_col;
- key(p, 'd');
- try std.testing.expectEqualStrings(before, try pardes.edit.flatSurface(p, &pane.tag));
- try std.testing.expectEqual(cursor, pane.tag.cur_col);
- try std.testing.expect(pane.tag.vsel.active);
- // typed into, the path drafts a name there, as a click on it does
- key(p, ';');
- key(p, '0');
- key(p, 'i');
- p.update(.{ .key = .{ .cp = 'x', .text = "x" } });
- try std.testing.expect(pane.prompt == .name);
- try std.testing.expectEqualStrings("x/test.txt", pane.input.own.?);
- // Esc keeps the draft pending; a second drops it.
- key(p, Key.escape);
- key(p, Key.escape);
- try std.testing.expect(pane.prompt == .none);
- try std.testing.expectEqualStrings("/test.txt", pane.file.?.path);
- // after the path, the text is the tag's own to edit
- key(p, ':');
- key(p, 'A');
- p.update(.{ .key = .{ .cp = '!', .text = "!" } });
- try std.testing.expect(std.mem.endsWith(u8, pardes.tagline.curTail(pane), "!"));
- try std.testing.expectEqualStrings("body\n", pane.file.?.content);
- }
-
- fn window(p: *Pardes, letter: u21) void {
- p.update(.{ .key = .{ .cp = 'w', .ctrl = true } });
- key(p, letter);
- key(p, Key.enter);
- }
-
- test "a tag remembers its cursor, starts on Save, and a click moves it" {
- const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 100, .rows = 20 });
- defer p.deinit();
- const first = try p.setTestFile("body\n");
- p.presentation.enabled = false;
- try std.testing.expect(p.executeBuiltinLine(0, "New"));
- const second_id = p.active;
- const second = p.panes[second_id].?;
- try std.testing.expect(layout.splitColumn(p, second_id, second_id, false));
- p.update(.tick);
- p.active = 0;
- // Nothing to remember yet: `:` lands on Save, in normal mode.
- key(p, ':');
- try std.testing.expect(first.focus == .tag and first.tag.mode == .normal);
- const shown = try pardes.edit.flatSurface(p, &first.tag);
- try std.testing.expectEqualStrings("Save", shown[@intCast(first.tag.cur_col)..][0..4]);
- // Home is the line's start, the path's: the keyboard reaches it.
- key(p, Key.home);
- for (0..3) |_| key(p, Key.right);
- try std.testing.expectEqual(@as(i32, 3), first.tag.cur_col);
- // `:` in the tag's normal mode is the way back to the body.
- key(p, ':');
- try std.testing.expect(first.focus == .body);
- p.active = second_id;
- key(p, ':');
- key(p, Key.home);
- for (0..5) |_| key(p, Key.right);
- key(p, ':');
- p.active = 0;
- key(p, ':');
- try std.testing.expectEqual(@as(i32, 3), first.tag.cur_col);
- key(p, ':');
- p.active = second_id;
- key(p, ':');
- try std.testing.expectEqual(@as(i32, 5), second.tag.cur_col);
- key(p, ':');
- var frame = std.heap.ArenaAllocator.init(p.gpa);
- defer frame.deinit();
- _ = try p.render(frame.allocator());
- const rect = p.rects[0];
- const y = tagY(p, rect);
- const prefix: u16 = @intCast(panes.File.displayWidth(try pardes.tagline.tagPrefix(p, first)));
- ClickCursorTests.click(p, .left, rect.x + pardes.TAG_TEXT_INSET + prefix + 6, y);
- try std.testing.expectEqual(@as(usize, 0), p.active);
- try std.testing.expect(first.focus == .tag and first.tag.mode == .insert);
- try std.testing.expectEqual(@as(i32, prefix + 6), first.tag.cur_col);
- key(p, Key.escape);
- key(p, ':');
- p.startPrompt(first, &first.body, .{ .search = config.search_marker });
- key(p, Key.escape);
- key(p, ':');
- try std.testing.expectEqual(@as(i32, prefix + 6), first.tag.cur_col);
- key(p, ':');
- try std.testing.expectEqualStrings("body\n", first.file.?.content);
- }
-
- test "executing a word from the tag runs it and gives the keyboard back to the body" {
- for ([_]u21{ Key.tab, Key.enter }) |chord| {
- const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 100, .rows = 20 });
- defer p.deinit();
- const pane = try p.setTestFile("body\n");
- p.update(.{ .key = .{ .cp = 'i' } });
- p.update(.{ .key = .{ .cp = 'x', .text = "x" } });
- p.update(.{ .key = .{ .cp = Key.escape } });
- while (p.nextEffect()) |_| {}
- // `:` lands on Save; the execute key runs it, the look key looks
- // it up. Either way the tag lets go of the keyboard first.
- key(p, ':');
- try std.testing.expect(pane.focus == .tag);
- key(p, chord);
- try std.testing.expect(pane.focus == .body);
- try std.testing.expectEqual(.normal, pane.body.mode);
- var saved = false;
- while (p.nextEffect()) |effect| {
- if (effect == .save_file) saved = true;
- }
- try std.testing.expectEqual(chord == Key.tab, saved);
- // ...and the tag still knows where it was.
- key(p, ':');
- try std.testing.expectEqualStrings("Save", (try pardes.edit.flatSurface(p, &pane.tag))[@intCast(pane.tag.cur_col)..][0..4]);
- }
- }
-
- test "a renamed path moves the tag's cursor with the text after it and a shorter tag pulls it back" {
- const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 80, .rows = 14 });
- defer p.deinit();
- const pane = try p.setTestFile("body\n");
- key(p, ':'); // on Save
- key(p, ':');
- p.gpa.free(pane.file.?.path);
- pane.file.?.path = try p.gpa.dupe(u8, "/界.zig");
- p.update(.tick);
- key(p, ':');
- const shown = try pardes.edit.flatSurface(p, &pane.tag);
- try std.testing.expectEqualStrings("Save", shown[@intCast(pane.tag.cur_col)..][0..4]);
- key(p, ':');
- try setTag(pane, "é");
- p.update(.tick);
- key(p, ':');
- // `/界.zig é`: the cursor is pulled back onto the last character
- try std.testing.expectEqual(@as(i32, "/界.zig ".len), pane.tag.cur_col);
- try std.testing.expectEqualStrings("body\n", pane.file.?.content);
- }
-
- test "window keys move between panes from a tag and each tag keeps its cursor" {
- for ([_]bool{ false, true }) |bottom| {
- const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 80, .rows = 24 });
- defer p.deinit();
- const first = try p.setTestFile("body\n");
- p.presentation.enabled = false;
- p.settings.tag_bottom = bottom;
- try std.testing.expect(p.executeBuiltinLine(0, "New"));
- const second_id = p.active;
- const second = p.panes[second_id].?;
- p.update(.tick);
- p.active = 0;
- key(p, ':');
- key(p, Key.home);
- key(p, 'l');
- key(p, 'l');
- window(p, 'j');
- try std.testing.expectEqual(second_id, p.active);
- try std.testing.expect(first.focus == .body and second.focus == .body);
- key(p, ':');
- key(p, Key.home);
- for (0..4) |_| key(p, 'l');
- window(p, 'k');
- try std.testing.expectEqual(@as(usize, 0), p.active);
- try std.testing.expect(second.focus == .body);
- key(p, ':');
- try std.testing.expectEqual(@as(i32, 2), first.tag.cur_col);
- window(p, 'j');
- key(p, ':');
- try std.testing.expectEqual(@as(i32, 4), second.tag.cur_col);
- }
- }
-
- test "a tag's normal mode is the body's: motions stay in the tag and insert types into it" {
- for ([_]bool{ false, true }) |bottom| {
- const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 100, .rows = 20 });
- defer p.deinit();
- _ = try p.setTestFile("body\n");
- p.presentation.enabled = false;
- p.settings.tag_bottom = bottom;
- try std.testing.expect(p.executeBuiltinLine(0, "New"));
- const right = p.active;
- try std.testing.expect(layout.splitColumn(p, right, right, false));
- p.update(.tick);
- p.active = 0;
- key(p, ':');
- const pane = p.panes[0].?;
- key(p, Key.home);
- key(p, 'l');
- try std.testing.expectEqual(@as(i32, 1), pane.tag.cur_col);
- key(p, 'h');
- key(p, 'k');
- key(p, 'j');
- try std.testing.expectEqual(@as(i32, 0), pane.tag.cur_col);
- try std.testing.expectEqual(@as(usize, 0), p.active);
- try std.testing.expect(pane.focus == .tag and !p.header_focus);
- window(p, 'l');
- try std.testing.expectEqual(right, p.active);
- try std.testing.expect(pane.focus == .body and p.panes[right].?.focus == .body);
- window(p, 'h');
- try std.testing.expectEqual(@as(usize, 0), p.active);
- key(p, ':');
- key(p, 'i');
- key(p, Key.end);
- const before = pardes.tagline.curTail(pane).len;
- try std.testing.expect(pane.focus == .tag and pane.tag.mode == .insert and pane.body.mode == .normal);
- for ("hjklHJKL:") |letter| {
- const text = [_]u8{letter};
- p.update(.{ .key = .{ .cp = letter, .text = &text } });
- try std.testing.expect(pane.focus == .tag and pane.tag.mode == .insert);
- }
- try std.testing.expectEqualStrings("hjklHJKL:", pardes.tagline.curTail(pane)[before..]);
- try std.testing.expectEqualStrings("body\n", pane.file.?.content);
- try std.testing.expectEqual(@as(usize, 0), p.active);
- }
- }
-};
-
const BodyHitTests = struct {
fn mouse(layer: *const pardes.Layer, row: u16, col: u16, kind: pardes.Mouse.Kind) pardes.Mouse {
const width: f32 = if (row < layer.context_rows) 8 else 10;
@@ -1119,159 +732,6 @@ const ClickCursorTests = struct {
try std.testing.expect(std.mem.count(u8, got, "\n") > 20);
}
- test "everything a B1 chord does while B1 is down is one undo step" {
- const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 60, .rows = 12 });
- defer p.deinit();
- const pane = try p.setTestFile("one two three\n");
- var frame = std.heap.ArenaAllocator.init(p.gpa);
- defer frame.deinit();
- _ = try p.render(frame.allocator());
- const rect = p.rects[0];
- const x = rect.x + config.GUTTER + panes.File.gutterWidth(pane);
- const y = p.bodyTop(pane, rect);
- const M = struct {
- fn ev(pp: *Pardes, b: pardes.Mouse.Button, k: pardes.Mouse.Kind, cx: u16, cy: u16) void {
- pp.update(.{ .mouse = .{ .button = b, .kind = k, .col = cx, .row = cy } });
- }
- };
- // B1-B2 then B1-B3: cut, then paste back: a copy, one step.
- const before = pane.file.?.history.undo_len;
- M.ev(p, .left, .press, x + 4, y);
- M.ev(p, .left, .drag, x + 6, y);
- M.ev(p, .middle, .press, x + 6, y);
- M.ev(p, .middle, .release, x + 6, y);
- M.ev(p, .right, .press, x + 6, y);
- M.ev(p, .right, .release, x + 6, y);
- M.ev(p, .left, .release, x + 6, y);
- try std.testing.expectEqualStrings("one two three\n", pane.file.?.content);
- try std.testing.expectEqualStrings("two", p.registers.text(p.gpa, '"').?);
- try std.testing.expect(pane.file.?.history.undo_len <= before + 1);
- // A cut alone comes back with one Undo.
- M.ev(p, .left, .press, x + 4, y);
- M.ev(p, .left, .drag, x + 6, y);
- M.ev(p, .middle, .press, x + 6, y);
- M.ev(p, .middle, .release, x + 6, y);
- M.ev(p, .left, .release, x + 6, y);
- try std.testing.expectEqualStrings("one three\n", pane.file.?.content);
- try std.testing.expect(p.executeBuiltinLine(0, "Undo"));
- try std.testing.expectEqualStrings("one two three\n", pane.file.?.content);
- }
-
- test "a double-click selects a word, a line, a bracketed or quoted text, as acme's" {
- const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 60, .rows = 12 });
- defer p.deinit();
- const pane = try p.setTestFile("call foo_bar(a, b)\nsay \"hi there\"\n");
- var frame = std.heap.ArenaAllocator.init(p.gpa);
- defer frame.deinit();
- _ = try p.render(frame.allocator());
- const rect = p.rects[0];
- const x = rect.x + config.GUTTER + panes.File.gutterWidth(pane);
- const y = p.bodyTop(pane, rect);
- const Want = struct { col: u16, row: u16, text: []const u8 };
- for ([_]Want{
- .{ .col = 6, .row = 0, .text = "foo_bar" },
- .{ .col = 13, .row = 0, .text = "a, b" },
- .{ .col = 0, .row = 0, .text = "call foo_bar(a, b)\n" },
- .{ .col = 5, .row = 1, .text = "hi there" },
- }) |w| {
- click(p, .left, x + w.col, y + w.row);
- click(p, .left, x + w.col, y + w.row);
- try std.testing.expectEqualStrings(w.text, pardes.edit.currentSelText(p, pane).?);
- // A third click is a plain click again: the caret, no selection.
- click(p, .left, x + w.col, y + w.row);
- try std.testing.expect(!pane.body.vsel.active);
- }
- // In the tag too.
- const tag_text = try pardes.tagline.tagText(p, frame.allocator(), pane);
- const del: u16 = @intCast(std.mem.indexOf(u8, tag_text, "Del").? + 1);
- const tag_x = rect.x + pardes.TAG_TEXT_INSET + del;
- click(p, .left, tag_x, p.tagTop(pane, rect));
- click(p, .left, tag_x, p.tagTop(pane, rect));
- try std.testing.expect(pane.tag.vsel.active);
- const tag_now = try pardes.tagline.tagText(p, frame.allocator(), pane);
- const a = modal.offsetAt(tag_now, .{ .row = @intCast(pane.tag.vsel.row), .col = @intCast(pane.tag.vsel.col) });
- const h = modal.offsetAt(tag_now, .{ .row = @intCast(pane.tag.cur_row), .col = @intCast(pane.tag.cur_col) });
- try std.testing.expectEqualStrings("Del", tag_now[a .. h + 1]);
- }
-
- test "click cursor and insertion agree beyond line and file ends" {
- for ([_]bool{ false, true }) |already_insert| {
- for ([_]bool{ false, true }) |bottom_tag| {
- for ([_]struct { text: []const u8, click_row: u16, row: i32, col: i32, result: []const u8 }{
- .{ .text = "abc\nxy", .click_row = 0, .row = 0, .col = 3, .result = "abcZ\nxy" },
- .{ .text = "abc\nxy", .click_row = 5, .row = 1, .col = 2, .result = "abc\nxyZ" },
- .{ .text = "abc\n", .click_row = 5, .row = 1, .col = 0, .result = "abc\nZ" },
- .{ .text = "", .click_row = 5, .row = 0, .col = 0, .result = "Z" },
- }) |case| {
- const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 40, .rows = 12 });
- defer p.deinit();
- p.settings.tag_bottom = bottom_tag;
- const pane = try p.setTestFile(case.text);
- p.presentation.enabled = false;
- if (already_insert) p.update(.{ .key = .{ .cp = 'i' } });
- var frame = std.heap.ArenaAllocator.init(p.gpa);
- defer frame.deinit();
- _ = try p.render(frame.allocator());
- const rect = p.rects[0];
- const x = rect.x + config.GUTTER + panes.File.gutterWidth(pane);
- const y = bodyY(p, rect);
- click(p, .left, x + 15, y + case.click_row);
- try std.testing.expectEqual(case.row, pane.body.cur_row);
- try std.testing.expectEqual(case.col, pane.body.cur_col);
- const clicked = (try p.render(frame.allocator())).cursor orelse return error.MissingClickCursor;
- try std.testing.expectEqual(x + @as(u16, @intCast(case.col)), clicked.x);
- try std.testing.expectEqual(y + @as(u16, @intCast(case.row)), clicked.y);
- if (!already_insert) p.update(.{ .key = .{ .cp = 'i' } });
- try std.testing.expectEqual(panes.Text.Mode.insert, pane.body.mode);
- const insert = (try p.render(frame.allocator())).cursor orelse return error.MissingInsertCursor;
- try std.testing.expectEqual(clicked.x, insert.x);
- try std.testing.expectEqual(clicked.y, insert.y);
- p.update(.{ .key = .{ .cp = 'Z', .text = "Z" } });
- try std.testing.expectEqualStrings(case.result, pane.file.?.content);
- }
- }
- }
- }
-
- test "click cursor snaps tab and wrapped wide glyph cells before insertion" {
- for ([_]bool{ false, true }) |already_insert| {
- for ([_]bool{ false, true }) |wrap| {
- const source = if (wrap) "012345678901234567890123456789界tail\n" else "\t界tail\n";
- const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 24, .rows = 12 });
- defer p.deinit();
- const pane = try p.setTestFile(source);
- p.settings.wrap = wrap;
- p.presentation.enabled = false;
- if (already_insert) p.update(.{ .key = .{ .cp = 'i' } });
- var frame = std.heap.ArenaAllocator.init(p.gpa);
- defer frame.deinit();
- const surface = try p.render(frame.allocator());
- var target: ?struct { x: u16, y: u16 } = null;
- for (0..surface.rows) |row| for (0..surface.cols) |col| {
- if (std.mem.eql(u8, surface.at(@intCast(col), @intCast(row)).grapheme(), "界"))
- target = .{ .x = @intCast(col), .y = @intCast(row) };
- };
- const glyph = target orelse return error.MissingWideGlyph;
- if (wrap) try std.testing.expect(glyph.y > p.rects[0].y + pardes.BOX_H);
- click(p, .left, glyph.x + 1, glyph.y);
- const byte = std.mem.indexOf(u8, source, "界").?;
- try std.testing.expectEqual(@as(i32, @intCast(byte)), pane.body.cur_col);
- const clicked = (try p.render(frame.allocator())).cursor orelse return error.MissingClickCursor;
- try std.testing.expectEqual(glyph.x, clicked.x);
- try std.testing.expectEqual(glyph.y, clicked.y);
- if (!already_insert) p.update(.{ .key = .{ .cp = 'i' } });
- try std.testing.expectEqual(panes.Text.Mode.insert, pane.body.mode);
- const insert = (try p.render(frame.allocator())).cursor orelse return error.MissingInsertCursor;
- try std.testing.expectEqual(clicked.x, insert.x);
- try std.testing.expectEqual(clicked.y, insert.y);
- p.update(.{ .key = .{ .cp = 'Z', .text = "Z" } });
- const expected = try std.fmt.allocPrint(p.gpa, "{s}Z{s}", .{ source[0..byte], source[byte..] });
- defer p.gpa.free(expected);
- try std.testing.expectEqualStrings(expected, pane.file.?.content);
- }
- }
- }
-
test "click operands and hover follow the scrolled source selection" {
const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 40, .rows = 14 });
defer p.deinit();
@@ -1387,39 +847,6 @@ const JumpSelectionTests = struct {
try std.testing.expectEqual(@as(i32, 0), pane.body.cur_col);
}
- test "a B1 sweep over several lines is a stream, as acme's, in a body and a tag" {
- const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 60, .rows = 12 });
- defer p.deinit();
- const pane = try p.setTestFile("alpha\nbravo\ncharlie\n");
- var frame = std.heap.ArenaAllocator.init(p.gpa);
- defer frame.deinit();
- _ = try p.render(frame.allocator());
- const rect = p.rects[0];
- const x = rect.x + config.GUTTER + panes.File.gutterWidth(pane);
- const y = p.bodyTop(pane, rect);
- // From the press to the end of its line, the line between whole, the
- // last from its start: no line numbers, no rectangle.
- drag(p, x + 2, y, x + 1, y + 2);
- try std.testing.expectEqualStrings("pha\nbravo\nch", pardes.exec.heldSelection(p, 0).?);
- // Upward, the same text.
- drag(p, x + 1, y + 2, x + 2, y);
- try std.testing.expectEqualStrings("pha\nbravo\nch", pardes.exec.heldSelection(p, 0).?);
- // A tag of several rows sweeps the same way.
- if (pane.tag.own) |own| p.gpa.free(own);
- pane.tag.own = try p.gpa.dupe(u8, "Save Del\nLook Edit");
- p.sync();
- _ = try p.render(frame.allocator());
- p.sync();
- try std.testing.expectEqual(@as(u16, 2), pane.tag_rows);
- const sl: panes.Pane.Sel = .{ .state = .done, .r0 = 0, .c0 = 3, .r1 = 1, .c1 = 1 };
- const text = try pardes.edit.paneText(p, pane);
- const swept = try pardes.edit.selectionText(p, pane, sl);
- const first_line = text[0 .. std.mem.indexOfScalar(u8, text, '\n') orelse text.len];
- const second = std.mem.sliceTo(text[first_line.len + 1 ..], '\n');
- const want = try std.fmt.allocPrint(frame.allocator(), "{s}\n{s}", .{ first_line[3..], second[0..@min(2, second.len)] });
- try std.testing.expectEqualStrings(want, swept);
- }
-
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");
@@ -1606,138 +1033,6 @@ fn redraft(pane: *Pane, name: []const u8) void {
pane.input.cur_col = @intCast(name.len);
}
-/// Click the tagline at the end of the path: a name draft, caret there.
-fn clickPathEnd(p: *Pardes, pane: *Pane) void {
- const rect = p.rects[p.active];
- const y = tagY(p, rect);
- const x = rect.x + pardes.TAG_TEXT_INSET + @as(u16, @intCast(panes.File.displayWidth(pane.file.?.path) - 1));
- ClickCursorTests.click(p, .left, x, y);
- std.debug.assert(pane.prompt == .name);
- pane.input.cur_col = @intCast(pane.input.own.?.len);
-}
-
-test "pane filename drafts commit and cancel without changing body or command tail" {
- const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 70, .rows = 12 });
- defer p.deinit();
- const pane = try p.setTestFile("original body\n");
- const original = try p.gpa.dupe(u8, pane.file.?.path);
- defer p.gpa.free(original);
- try pane.appendTag(" SyntaxBold");
- const tail = try p.gpa.dupe(u8, pardes.tagline.curTail(pane));
- defer p.gpa.free(tail);
- for ([_]bool{ false, true }) |commit| {
- clickPathEnd(p, pane);
- p.update(.{ .key = .{ .cp = 'u', .ctrl = true } });
- p.update(.{ .paste = "/new name.zig" });
- try std.testing.expectEqualStrings(original, pane.file.?.path);
- try std.testing.expectEqualStrings("/new name.zig", pane.input.own.?);
- try std.testing.expectEqualStrings(tail, pardes.tagline.curTail(pane));
- try std.testing.expectEqualStrings("original body\n", pane.file.?.content);
- // Esc keeps the draft pending; a second drops it.
- p.update(.{ .key = .{ .cp = if (commit) Key.enter else Key.escape } });
- if (!commit) p.update(.{ .key = .{ .cp = Key.escape } });
- try std.testing.expect(pane.focus == .body);
- try std.testing.expect(pane.prompt == .none);
- try std.testing.expectEqualStrings(if (commit) "/new name.zig" else original, pane.file.?.path);
- try std.testing.expectEqualStrings(tail, pardes.tagline.curTail(pane));
- while (p.nextEffect()) |effect| try std.testing.expect(std.meta.activeTag(effect) != .save_file);
- }
- // A name alone is no edit: the pane stays clean.
- try std.testing.expect(pane.file.?.revision == pane.file.?.saved_revision);
-}
-
-test "pane filename grapheme edits and invalid empty commits preserve the buffer" {
- const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true });
- defer p.deinit();
- const pane = try p.setTestFile("untouched\n");
- clickPathEnd(p, pane);
- p.update(.{ .key = .{ .cp = 'u', .ctrl = true } });
- p.update(.{ .paste = "/café界" });
- p.update(.{ .key = .{ .cp = Key.backspace } });
- try std.testing.expectEqualStrings("/café", pane.input.own.?);
- p.update(.{ .key = .{ .cp = Key.backspace } });
- try std.testing.expectEqualStrings("/caf", pane.input.own.?);
- p.update(.{ .key = .{ .cp = 'u', .ctrl = true } });
- try std.testing.expectEqualStrings("", pane.input.own.?);
- p.update(.{ .key = .{ .cp = Key.enter } });
- try std.testing.expect(pane.prompt == .name);
- try std.testing.expectEqualStrings("/test.txt", pane.file.?.path);
- try std.testing.expectEqualStrings("untouched\n", pane.file.?.content);
- // Esc keeps the draft pending; a second drops it.
- p.update(.{ .key = .{ .cp = Key.escape } });
- try std.testing.expect(pane.prompt == .name);
- p.update(.{ .key = .{ .cp = Key.escape } });
- try std.testing.expect(pane.prompt == .none);
-}
-
-test "leaving a pane or entering a header cancels an uncommitted filename" {
- const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true });
- defer p.deinit();
- const pane = try p.setTestFile("untouched\n");
- for ([_]bool{ false, true }) |header| {
- p.active = 0;
- pardes.tagline.exitHeader(p);
- p.update(.tick);
- clickPathEnd(p, pane);
- p.update(.{ .paste = "/draft" });
- try std.testing.expect(pane.prompt == .name);
- if (header) {
- pardes.tagline.enterHeader(p, null);
- p.update(.tick);
- } else {
- try std.testing.expect(p.executeBuiltinLine(0, "New"));
- p.update(.tick);
- }
- try std.testing.expect(pane.prompt == .none);
- try std.testing.expect(pane.focus == .body);
- try std.testing.expectEqualStrings("/test.txt", pane.file.?.path);
- }
-}
-
-test "middle clicking Save commits the drafted filename before issuing a save" {
- const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 70, .rows = 12 });
- defer p.deinit();
- const pane = try p.setTestFile("untouched\n");
- clickPathEnd(p, pane);
- p.update(.{ .key = .{ .cp = 'u', .ctrl = true } });
- p.update(.{ .paste = "/renamed.txt" });
- var arena = std.heap.ArenaAllocator.init(p.gpa);
- defer arena.deinit();
- _ = try p.render(arena.allocator());
- const text = try pardes.tagline.tagText(p, arena.allocator(), pane);
- const save_at = std.mem.indexOf(u8, text, "Save").?;
- const x: u16 = @intCast(p.rects[0].x + pardes.TAG_TEXT_INSET + save_at - pane.tag_scroll);
- const y = p.rects[0].y;
- while (p.nextEffect()) |_| {}
- p.update(.{ .mouse = .{ .col = x, .row = y, .button = config.exec_button, .kind = .press } });
- p.update(.{ .mouse = .{ .col = x, .row = y, .button = config.exec_button, .kind = .release } });
- try std.testing.expectEqualStrings("/renamed.txt", pane.file.?.path);
- try std.testing.expect(pane.prompt == .none);
- try std.testing.expectEqualStrings("untouched\n", pane.file.?.content);
- var saves: usize = 0;
- while (p.nextEffect()) |effect| if (effect == .save_file) {
- try std.testing.expectEqual(@as(u8, 0), effect.save_file.pane);
- saves += 1;
- };
- try std.testing.expectEqual(@as(usize, 1), saves);
-}
-
-test "an oversized drafted name is refused at commit and the draft stays to correct" {
- const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true });
- defer p.deinit();
- const pane = try p.setTestFile("untouched\n");
- clickPathEnd(p, pane);
- const excess = try p.gpa.alloc(u8, 5000);
- defer p.gpa.free(excess);
- @memset(excess, 'x');
- excess[0] = '/';
- p.update(.{ .paste = excess });
- p.update(.{ .key = .{ .cp = Key.enter } });
- try std.testing.expect(pane.prompt == .name);
- try std.testing.expectEqualStrings("/test.txt", pane.file.?.path);
- try std.testing.expectEqualStrings("untouched\n", pane.file.?.content);
-}
-
test "paste into pane commands and prompts never inserts into the body" {
const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true });
defer p.deinit();
@@ -1783,60 +1078,6 @@ test "a tag that exactly fills its row stays one row, its caret at the edge as a
try std.testing.expectEqual(p.rects[0].x + p.rects[0].w - 1, surface.cursor.?.x);
}
-test "a long pane tag wraps onto rows, and a click on a wrapped row maps to the whole tag's address" {
- const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 50, .rows = 12 });
- defer p.deinit();
- const pane = try p.setTestFile("body\n");
- p.gpa.free(pane.file.?.path);
- pane.file.?.path = try p.gpa.dupe(u8, "/an/especially/deep/project/path/with/a/long/component/filename.zig");
- try pane.appendTag(" SyntaxBold");
- p.update(.{ .key = .{ .cp = ':' } });
- p.update(.{ .key = .{ .cp = 'A' } });
- var arena = std.heap.ArenaAllocator.init(p.gpa);
- defer arena.deinit();
- const surface = try p.render(arena.allocator());
- try std.testing.expect(pane.tag_rows > 1);
- try std.testing.expect(surface.cursor.?.x < p.rects[0].x + p.rects[0].w);
- const text = try pardes.tagline.tagText(p, p.gpa, pane);
- defer p.gpa.free(text);
- const shown = try pardes.tagline.shownTag(p, arena.allocator(), pane);
- const at = shown.fromReal(std.mem.indexOf(u8, text, "SyntaxBold").?);
- const pos = modal.positionAt(shown.text, at);
- const x: u16 = @intCast(p.rects[0].x + pardes.TAG_TEXT_INSET + panes.File.rawDisplayCol(modal.lineSlice(shown.text, pos.row), pos.col));
- const y = p.tagTop(pane, p.rects[0]) + @as(u16, @intCast(pos.row));
- const before = p.settings.syntax_bold;
- p.update(.{ .mouse = .{ .col = x, .row = y, .button = config.exec_button, .kind = .press } });
- p.update(.{ .mouse = .{ .col = x, .row = y, .button = config.exec_button, .kind = .release } });
- try std.testing.expectEqual(!before, p.settings.syntax_bold);
- try std.testing.expectEqualStrings(text, try pardes.tagline.tagText(p, p.scratch.allocator(), pane));
-}
-
-test "a word the tag's wrapping breaks across rows is still one word to a click" {
- const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 50, .rows = 12 });
- defer p.deinit();
- const pane = try p.setTestFile("body\n");
- try pane.appendTag(" SyntaxBold");
- var arena = std.heap.ArenaAllocator.init(p.gpa);
- defer arena.deinit();
- // Lengthen the path until the wrap splits the word after "Synt".
- var pad: usize = 1;
- const shown = while (pad < 80) : (pad += 1) {
- p.gpa.free(pane.file.?.path);
- const path = try std.fmt.allocPrint(arena.allocator(), "/{s}/f.zig", .{(&@as([80]u8, @splat('a')))[0..pad]});
- pane.file.?.path = try p.gpa.dupe(u8, path);
- p.sync();
- const s = try pardes.tagline.shownTag(p, arena.allocator(), pane);
- if (std.mem.indexOf(u8, s.text, "Synt\n") != null) break s;
- } else return error.NoSplit;
- const pos = modal.positionAt(shown.text, std.mem.indexOf(u8, shown.text, "Synt").?);
- const x: u16 = @intCast(p.rects[0].x + pardes.TAG_TEXT_INSET + pos.col + 1);
- const y = p.tagTop(pane, p.rects[0]) + @as(u16, @intCast(pos.row));
- const before = p.settings.syntax_bold;
- p.update(.{ .mouse = .{ .col = x, .row = y, .button = config.exec_button, .kind = .press } });
- p.update(.{ .mouse = .{ .col = x, .row = y, .button = config.exec_button, .kind = .release } });
- try std.testing.expectEqual(!before, p.settings.syntax_bold);
-}
-
test "terminal overlay recoloring never materializes unrelated history" {
const testing = std.testing;
const p = try Pardes.init(testing.allocator, .{ .tty_only = true, .cols = 32, .rows = 8 });
@@ -2107,86 +1348,6 @@ test "terminal eviction and lower-region scrolling in one read preserve a surviv
try std.testing.expectEqualStrings("kept edit", pane.ovl.?.text);
}
-test "a prompt's entry and cancellation leave the tag, the body and its cursor as they were" {
- const Case = struct { key: ?Key = null, save: bool = false, marker: []const u8 };
- const cases = [_]Case{
- .{ .marker = config.search_marker },
- .{ .save = true, .marker = config.save_marker ++ "/dír space/" },
- .{ .key = .{ .cp = '|' }, .marker = config.pipe_marker },
- .{ .key = .{ .cp = '|', .alt = true }, .marker = config.pipe_marker_to },
- .{ .key = .{ .cp = '!' }, .marker = config.pipe_marker_insert },
- .{ .key = .{ .cp = '!', .alt = true }, .marker = config.pipe_marker_append },
- };
- const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 40, .rows = 12 });
- defer p.deinit();
- const pane = try p.setTestFile("one\ntwo\n");
- try pane.setOwnedCwd("/dír space");
- const tail = " keep";
- for (cases) |case| {
- try setTag(pane, tail);
- pane.body.cur_row = 1;
- pane.body.cur_col = 2;
- pane.body.cur_pinned = true;
- if (case.key) |key| {
- p.update(.{ .key = key });
- } else if (case.save) {
- p.startPrompt(pane, &pane.body, .save);
- } else {
- p.startPrompt(pane, &pane.body, .{ .search = config.search_marker });
- }
- // The answer is typed into the prompt's own line, never the tag.
- try std.testing.expect(pane.focus == .body);
- try std.testing.expectEqual(.insert, pane.input.mode);
- try std.testing.expectEqualStrings(case.marker, pane.promptText().?);
- try std.testing.expectEqual(@as(i32, @intCast(case.marker.len)), pane.input.cur_col);
- try std.testing.expectEqualStrings(tail, pane.tag.own.?);
- try std.testing.expectEqualDeep(modal.Normal.State{}, pane.body.normal);
- p.update(.{ .key = .{ .cp = Key.escape } });
- try std.testing.expect(pane.prompt == .none);
- try std.testing.expect(pane.input.own == null);
- try std.testing.expectEqual(.normal, pane.body.mode);
- try std.testing.expectEqualStrings(tail, pane.tag.own.?);
- try std.testing.expectEqual(@as(i32, 1), pane.body.cur_row);
- try std.testing.expectEqual(@as(i32, 2), pane.body.cur_col);
- try std.testing.expectEqualStrings("one\ntwo\n", pane.file.?.content);
- }
-}
-
-test "a prompt opens whatever the tag already holds" {
- const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true });
- defer p.deinit();
- const pane = try p.setTestFile("one\n");
- const full = try p.gpa.alloc(u8, pardes.memory.limits.max_tag_tail);
- defer p.gpa.free(full);
- @memset(full, 'x');
- try setTag(pane, full);
- for (0..3) |case| {
- switch (case) {
- 0 => p.startPrompt(pane, &pane.body, .{ .search = config.search_marker }),
- 1 => p.startPrompt(pane, &pane.body, .save),
- else => p.update(.{ .key = .{ .cp = '|' } }),
- }
- try std.testing.expect(pane.prompt != .none);
- try std.testing.expectEqualStrings(full, pane.tag.own.?);
- p.update(.{ .key = .{ .cp = Key.escape } });
- }
-}
-
-test "generated output refuses every pipe prompt before seeding the tag" {
- const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true });
- defer p.deinit();
- const content = try p.gpa.dupe(u8, "generated\n");
- const pane = try panes.Output.open(p, p.freeSlot().?, "/", .{ .cmd = .Help }, "", content);
- p.active = 1;
- for ([_]Key{ .{ .cp = '|' }, .{ .cp = '|', .alt = true }, .{ .cp = '!' }, .{ .cp = '!', .alt = true } }) |key| {
- p.update(.{ .key = key });
- try std.testing.expect(pane.prompt == .none);
- try std.testing.expect(pane.tag.own == null);
- try std.testing.expect(pane.focus == .body);
- try std.testing.expectEqualStrings("generated\n", pane.file.?.content);
- }
-}
-
test "a prompt owns the pipe behavior through cancellation and submission" {
const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true });
defer p.deinit();
@@ -2214,34 +1375,6 @@ test "a prompt owns the pipe behavior through cancellation and submission" {
}
}
-test "prompt cancellation restores the selection before regex previews" {
- const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true });
- defer p.deinit();
- const pane = try p.setTestFile("one two one");
- const cases = [_]struct { key: u21, pattern: []const u8, secondary: u8 }{
- .{ .key = 's', .pattern = "one", .secondary = 1 },
- .{ .key = 'S', .pattern = " ", .secondary = 2 },
- };
- for (cases) |case| {
- pane.body.cur_row = 0;
- pane.body.cur_col = 10;
- pane.body.cur_pinned = true;
- pane.body.vsel = .{ .active = true, .row = 0, .col = 0, .explicit = true };
- pane.body.nsel = 0;
- p.update(.{ .key = .{ .cp = case.key } });
- try std.testing.expect(pane.prompt == .search);
- p.update(.{ .key = .{ .cp = case.pattern[0], .text = case.pattern } });
- try std.testing.expectEqual(case.secondary, pane.body.nsel);
- p.update(.{ .key = .{ .cp = Key.escape } });
- try std.testing.expectEqual(@as(u16, 0), pane.body.nsel);
- try std.testing.expectEqual(@as(u16, 0), pane.nsel_snap);
- try std.testing.expectEqual(@as(i32, 10), pane.body.cur_col);
- try std.testing.expectEqual(@as(i32, 0), pane.body.vsel.col);
- try std.testing.expect(pane.body.vsel.active and pane.body.vsel.explicit);
- try std.testing.expectEqualStrings("one two one", pane.file.?.content);
- }
-}
-
test "a prompt that cannot be opened leaves the open one as it was" {
const Request = @typeInfo(@TypeOf(Pardes.startPrompt)).@"fn".param_types[3].?;
for ([_]Request{ .{ .search = config.search_marker }, .save, .{ .pipe = .replace }, .{ .pipe = .ignore }, .{ .pipe = .insert }, .{ .pipe = .append } }) |request| {
@@ -4600,7 +3733,6 @@ const TerminalTests = struct {
};
test {
- _ = TagNavigationTests;
_ = TagLayerTests;
_ = TagNameTintTests;
_ = TreeContextTests;
@@ -4622,83 +3754,6 @@ test {
_ = TerminalTests;
}
-test "an empty counted paste leaves no count for the next motion" {
- for ([_]bool{ false, true }) |empty_register| {
- const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 60, .rows = 12 });
- defer p.deinit();
- const pane = try p.setTestFile("abcdefgh\n");
- if (empty_register) p.registers.put(p.gpa, '"', "", 0, 1, true);
- for ("3p") |cp| p.update(.{ .key = .{ .cp = cp } });
- try std.testing.expectEqual(modal.Normal.State{}, pane.body.normal);
- p.update(.{ .key = .{ .cp = 'l' } });
- try std.testing.expectEqual(@as(i32, 1), pane.body.cur_col);
- try std.testing.expectEqualStrings("abcdefgh\n", pane.file.?.content);
- }
-}
-
-test "cancelled normal gestures leave no count or subprefix after mouse and focus changes" {
- const Gesture = enum { body, tag, focus, last };
- for ([_][]const u8{ "3", "3g", "mr(" }) |keys| {
- for ([_]Gesture{ .body, .tag, .focus, .last }) |gesture| {
- errdefer std.debug.print("\nkeys={s} gesture={s}\n", .{ keys, @tagName(gesture) });
- const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 100, .rows = 16 });
- defer p.deinit();
- const pane = try p.setTestFile("abcdefghij\n");
- p.settings.colors = false;
- p.presentation.enabled = false;
- try std.testing.expect(p.executeBuiltinLine(0, "New"));
- const other = p.active;
- try std.testing.expect(layout.splitColumn(p, other, other, false));
- p.active = 0;
- p.update(.tick);
- var frame = std.heap.ArenaAllocator.init(std.testing.allocator);
- defer frame.deinit();
- _ = try p.render(frame.allocator());
- for (keys) |cp| p.update(.{ .key = .{ .cp = cp } });
- try std.testing.expect(!std.meta.eql(modal.Normal.State{}, pane.body.normal));
- switch (gesture) {
- .body, .tag => {
- const rect = p.rects[0];
- const tag_y = tagY(p, rect);
- const body_y = p.bodyTop(pane, rect);
- const x = if (gesture == .tag)
- rect.x + pardes.TAG_TEXT_INSET + @as(u16, @intCast(panes.File.displayWidth(try pardes.tagline.tagPrefix(p, pane)))) + 3
- else
- rect.x + config.GUTTER + @as(u16, @intCast(panes.File.gutterWidth(pane))) + 3;
- const y = if (gesture == .tag) tag_y else body_y;
- p.update(.{ .mouse = .{ .button = config.select_button, .kind = .press, .col = x, .row = y } });
- p.update(.{ .mouse = .{ .button = config.select_button, .kind = .release, .col = x, .row = y } });
- if (gesture == .tag) {
- try std.testing.expect(pane.focus == .tag);
- p.update(.{ .key = .{ .cp = Key.escape } });
- p.update(.{ .key = .{ .cp = ':' } });
- try std.testing.expect(pane.focus == .body);
- }
- },
- .focus, .last => {
- p.update(.{ .key = .{ .cp = 'w', .ctrl = true } });
- p.update(.{ .key = .{ .cp = 'l' } });
- p.update(.{ .key = .{ .cp = Key.enter } });
- try std.testing.expectEqual(other, p.active);
- if (gesture == .last) {
- p.update(.{ .key = .{ .cp = Key.escape } });
- } else {
- p.update(.{ .key = .{ .cp = 'w', .ctrl = true } });
- p.update(.{ .key = .{ .cp = 'h' } });
- p.update(.{ .key = .{ .cp = Key.enter } });
- }
- try std.testing.expectEqual(@as(usize, 0), p.active);
- },
- }
- try std.testing.expectEqual(modal.Normal.State{}, pane.body.normal);
- const col = pane.body.cur_col;
- p.update(.{ .key = .{ .cp = 'l' } });
- try std.testing.expectEqual(col + 1, pane.body.cur_col);
- try std.testing.expectEqualStrings("abcdefghij\n", pane.file.?.content);
- }
- }
-}
-
test "cancelled normal gestures leave no count or subprefix through raw tty mode" {
for ([_][]const u8{ "3", "3g", "mr(" }) |keys| {
const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 80, .rows = 12 });
@@ -4963,78 +4018,6 @@ const LookResetTests = struct {
for (pane.sel) |selection| try std.testing.expectEqual(.none, selection.state);
for (pane.pointer_selections) |selection| try std.testing.expect(selection == null);
}
-
- fn selected(pane: *const Pane) []const u8 {
- if (!pane.body.vsel.active or pane.body.cur_row != pane.body.vsel.row) return "";
- const line = modal.lineSlice(pane.file.?.content, @intCast(pane.body.cur_row));
- const lo: usize = @intCast(@min(pane.body.cur_col, pane.body.vsel.col));
- const hi: usize = @intCast(@max(pane.body.cur_col, pane.body.vsel.col));
- return line[lo..modal.nextGrapheme(line, hi)];
- }
-
- test "Look replaces old selection for same-pane addresses ranges and text fallback" {
- const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 80, .rows = 24 });
- defer p.deinit();
- const pane = try p.setTestFile("alpha\nbravo\ncharlie\nneedle\n");
- try seed(pane, "/test.txt:3:2");
- // This operand is released by Look's selection cleanup.
- pardes.look.lookAt(p, 0, pane.pointer_selections[0].?.raw_text.?);
- try cleared(pane);
- try std.testing.expectEqual(@as(usize, 0), p.active);
- try std.testing.expectEqual(@as(i32, 2), pane.body.cur_row);
- try std.testing.expectEqual(@as(i32, 1), pane.body.cur_col);
- try std.testing.expect(!pane.body.vsel.active);
-
- try seed(pane, "/test.txt:2:2-4");
- pardes.look.lookAt(p, 0, pane.pointer_selections[0].?.raw_text.?);
- try cleared(pane);
- try std.testing.expectEqual(@as(i32, 1), pane.body.cur_row);
- try std.testing.expectEqualStrings("rav", selected(pane));
-
- p.gpa.free(pane.file.?.path);
- pane.file.?.path = try p.gpa.dupe(u8, "/tmp/look-selection-source.txt");
- try seed(pane, "needle");
- pardes.look.lookAt(p, 0, pane.pointer_selections[0].?.raw_text.?);
- try cleared(pane);
- try std.testing.expectEqual(@as(i32, 3), pane.body.cur_row);
- try std.testing.expectEqualStrings("needle", selected(pane));
- }
-
- test "Look clears the source's click highlight, not its dot, and the destination's selections before focus" {
- const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 100, .rows = 30 });
- defer p.deinit();
- const source = try p.setTestFile("source\nlines\n");
- const id = p.freeSlot().?;
- const destination = try p.newDocPane(id);
- destination.file = .{
- .path = try p.gpa.dupe(u8, "/look-destination.txt"),
- .content = try p.gpa.dupe(u8, "alpha\nbravo\ncharlie\n"),
- .history = try panes.File.History.create(p.gpa),
- };
- layout.insert(p, 0, 1, id);
- layout.compute(p);
- for ([_]bool{ false, true }) |range| {
- p.active = 0;
- try seed(source, if (range) "/look-destination.txt:2:2-4" else "/look-destination.txt:3:2");
- try seed(destination, "previous destination");
- pardes.look.lookAt(p, 0, source.pointer_selections[0].?.raw_text.?);
- try std.testing.expectEqual(id, p.active);
- // The source keeps its dot (acme's look leaves it); the click's
- // highlight goes.
- for (source.sel) |selection| try std.testing.expectEqual(.none, selection.state);
- for (source.pointer_selections) |selection| try std.testing.expect(selection == null);
- try std.testing.expect(source.body.vsel.active);
- try cleared(destination);
- if (range) {
- try std.testing.expectEqual(@as(i32, 1), destination.body.cur_row);
- try std.testing.expectEqualStrings("rav", selected(destination));
- } else {
- try std.testing.expectEqual(@as(i32, 2), destination.body.cur_row);
- try std.testing.expectEqual(@as(i32, 1), destination.body.cur_col);
- try std.testing.expect(!destination.body.vsel.active);
- }
- }
- }
};
test {