diff options
Diffstat (limited to 'core/Query.zig')
| -rw-r--r-- | core/Query.zig | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/core/Query.zig b/core/Query.zig index feebb6cd..3ac87dfb 100644 --- a/core/Query.zig +++ b/core/Query.zig @@ -2134,6 +2134,12 @@ pub fn paint(p: *Pardes, s: *Surface, pane: *Pane, r: pardes.Rect, body_h: u16) // ---- tests ---- +/// `/` and `typed` in the tag's prompt, kept as the query pane (Alt-Enter). +fn slash(p: *Pardes, typed: []const u8) void { + typeKeys(p, typed); + p.update(.{ .key = .{ .cp = Key.enter, .alt = true } }); +} + fn typeKeys(p: *Pardes, text: []const u8) void { for (text) |c| p.update(.{ .key = .{ .cp = c, .text = &[_]u8{c} } }); } @@ -2169,7 +2175,7 @@ test "a / query: keystroke by keystroke, the owner shows the set, rows from its // cursor on line 3 (row 2) pane.body.cur_row = 2; pane.body.cur_col = 0; - typeKeys(p, "/"); + slash(p, "/"); const qid = queryPane(p).?; const qp = p.panes[qid].?; try std.testing.expectEqual(@as(?usize, 0), layout.ownerOf(p, qid)); @@ -2226,7 +2232,7 @@ test "a dump holding a query pane, live or frozen, restores it as it was" { const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 100, .rows = 40 }); defer p.deinit(); _ = try p.setTestFile("alpha one\nbeta\nalphabet\n"); - typeKeys(p, "/alpha"); + slash(p, "/alpha"); for (0..2) |_| { const qid = queryPane(p).?; try pardes.dump.dumpState(p); @@ -2245,7 +2251,7 @@ test "a / query: Enter lands and freezes, the register filled, n and N step sile const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 100, .rows = 40 }); defer p.deinit(); const pane = try p.setTestFile("alpha one\nbeta\nalphabet\ngamma alpha\nalpha two\ndelta\n"); - typeKeys(p, "/alpha"); + slash(p, "/alpha"); const qid = queryPane(p).?; const qp = p.panes[qid].?; const q = qp.query.?; @@ -2274,7 +2280,7 @@ test "a / query: Enter lands and freezes, the register filled, n and N step sile typeKeys(p, "N"); try std.testing.expectEqual(@as(?usize, 3), pane.places.current); // a later `/` reuses the pane: line 1 fresh, the rows the new query's - typeKeys(p, "/"); + slash(p, "/"); try std.testing.expectEqual(qid, queryPane(p).?); try std.testing.expectEqual(qid, p.view().active); try std.testing.expect(!q.frozen); @@ -2419,11 +2425,12 @@ test "* seeds line 1 and keeps the keyboard; SPC b b picks a pane, SPC s s a dec const pane = try p.setTestFile("const alpha = 1;\nfn beta() void {\n _ = alpha;\n}\nfn gamma() void {}\n"); p.gpa.free(pane.file.?.path); pane.file.?.path = try p.gpa.dupe(u8, "/tmp/x.zig"); - // `*` on `const`: line 1 `/\bconst\b`, the keyboard still in the text + // `*` on `const`: its places and the pane's search word, no query + // pane, the keyboard still in the text (Prompt.zig) typeKeys(p, "e*"); - const qid = queryPane(p).?; + try std.testing.expect(queryPane(p) == null); try std.testing.expectEqual(@as(usize, 0), p.view().active); - try std.testing.expect(std.mem.startsWith(u8, lineOne(p.panes[qid].?.file.?.content), "/")); + try std.testing.expect(pane.trail.n == 1 and pane.trail.steps[0] == .search); try std.testing.expect(pane.places.started); typeKeys(p, "n"); try std.testing.expectEqual(@as(?usize, 0), pane.places.current); @@ -2433,7 +2440,6 @@ test "* seeds line 1 and keeps the keyboard; SPC b b picks a pane, SPC s s a dec p.view().active = 0; leader(p, "bb"); const bid = queryPane(p).?; - try std.testing.expectEqual(bid, qid); try std.testing.expectEqual(Source.panes, p.panes[bid].?.query.?.source); try std.testing.expect(p.panes[bid].?.query.?.total >= 1); // SPC s s: the declarations, fuzzy; Enter lands on the line @@ -2512,7 +2518,7 @@ test "B1 on a query pane's rows places the caret and selects, nothing else, the const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 100, .rows = 40 }); defer p.deinit(); const pane = try p.setTestFile("alpha one\nbeta\nalphabet\ngamma alpha\nalpha two\ndelta\n"); - typeKeys(p, "/alpha"); + slash(p, "/alpha"); const qid = queryPane(p).?; const qp = p.panes[qid].?; const q = qp.query.?; |
