diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-03 17:09:37 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-03 17:14:31 -0300 |
| commit | 4d4d9fcba44798340184f865d119e49c63709b70 (patch) | |
| tree | 3ca041dd9ff0271b042357d65395a305f100152c /test/panes.zig | |
| parent | 63e62131aaedb91a8fa995b8e00ced808e053519 (diff) | |
| download | pardes-4d4d9fcba44798340184f865d119e49c63709b70.tar.gz pardes-4d4d9fcba44798340184f865d119e49c63709b70.zip | |
test: test/panes.zig's eight tag-navigation tests through the 9P tree alone (test/behaviour/tags.zig, guide.typ's Tags): s and S in a tag selecting its own text (a c changing both S's) while / searches the body (its +Search lists the match), ms and md read back from the tag file, the path the keyboard reaches, yanks (pasted into the body) and cannot edit, a name drafted by typing into it, a tag remembering its cursor across panes and a prompt, starting on Save and moved by a click, Tab and Enter from a tag giving the body the keyboard back (a Save counted, the next keys typed into the body), the cursor after a rename and a shorter tag, window keys from a tag, a tag's normal and insert modes; Session.cursor (the screen's cursor cell, read from /screen) and Session.replace (a write truncating first, a shell's >); each checked to fail against a break (a tag's s prompt answering for the body, ms closing a character early, a tag edit into the path taken, enterTag always landing on Save, a truncated tag's cursor left at 0, the execute key leaving the tag the keyboard, a tag the keyboard left keeping it)
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge
Diffstat (limited to 'test/panes.zig')
| -rw-r--r-- | test/panes.zig | 274 |
1 files changed, 0 insertions, 274 deletions
diff --git a/test/panes.zig b/test/panes.zig index 6970cbb5..e1be67b9 100644 --- a/test/panes.zig +++ b/test/panes.zig @@ -296,279 +296,6 @@ test "a tag with more lines than rows scrolls to keep its caret in view" { 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; @@ -4414,7 +4141,6 @@ const TerminalTests = struct { }; test { - _ = TagNavigationTests; _ = TagLayerTests; _ = TagNameTintTests; _ = TreeContextTests; |
