diff options
Diffstat (limited to 'test')
| -rw-r--r-- | test/behaviour/language_servers.zig | 25 | ||||
| -rw-r--r-- | test/behaviour/look_and_exec.zig | 23 | ||||
| -rw-r--r-- | test/behaviour/other_files.zig | 16 | ||||
| -rw-r--r-- | test/lspmock.zig | 11 | ||||
| -rw-r--r-- | test/process/window.zig | 31 | ||||
| -rw-r--r-- | test/snapshots/find.golden | 6 | ||||
| -rw-r--r-- | test/snapshots/leader.golden | 38 |
7 files changed, 121 insertions, 29 deletions
diff --git a/test/behaviour/language_servers.zig b/test/behaviour/language_servers.zig index 904fcfba..13e42fa6 100644 --- a/test/behaviour/language_servers.zig +++ b/test/behaviour/language_servers.zig @@ -298,3 +298,28 @@ test "language-servers: Index runs the language's indexer at the project's root, const dir = buf[0..try tmp.dir.realPath(std.testing.io, &buf)]; try std.testing.expect(std.mem.startsWith(u8, try bodyOf(&s, dir), s.at("% cd '{s}' && rust-analyzer scip .", .{dir}))); } + +test "language-servers: SPC l a lists the server's code actions in the pane's tag by their digits, the one under the cursor shown as its edit, and its digit applies it, one the server left to resolve resolved first" { + var tmp = std.testing.tmpDir(.{}); + defer tmp.cleanup(); + var s = try Session.initLanguage(std.testing.allocator); + defer s.deinit(); + const before = "mod lib;\n\nfn main() {\n let x = add(1, 2);\n let y = add(3, 4);\n let _ = x + y;\n}\n"; + try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "main.rs", .data = before }); + var buf: [4096]u8 = undefined; + const main = try s.lookFile(s.at("{s}/main.rs:4:13", .{buf[0..try tmp.dir.realPath(std.testing.io, &buf)]})); + const body = s.at("/pane/{d}/body", .{main}); + try s.keys(" la"); + try std.testing.expect(std.mem.indexOf(u8, try s.read("/index"), "+Lsp") == null); + _ = try s.where("▶ 1 mock action: extract"); + _ = try s.where(" 2 mock action: add a line"); + _ = try s.where(" 3 mock action: rename add to sum"); + // The third, its edit asked for with codeAction/resolve: the two calls. + try s.keys("\u{F800}\u{F800}"); + _ = try s.where("let x = sum(1, 2);"); + try s.expect(body, before); + try s.keys("3"); + try s.expect(body, "mod lib;\n\nfn main() {\n let x = sum(1, 2);\n let y = sum(3, 4);\n let _ = x + y;\n}\n"); + try s.keys("u"); + try s.expect(body, before); +} diff --git a/test/behaviour/look_and_exec.zig b/test/behaviour/look_and_exec.zig index a7de93cd..251b6325 100644 --- a/test/behaviour/look_and_exec.zig +++ b/test/behaviour/look_and_exec.zig @@ -790,3 +790,26 @@ test "look-and-exec: a look at a directory opens a pane listing it, as acme's di try std.testing.expectEqualStrings("later", again[1]); try std.testing.expectEqualStrings("sub/", again[2]); } + +test "look-and-exec: a reading pane that walks to another file is the same pane: its number, an open of its files reading the new text, /log's rename for it, the file it left in Recent" { + var tmp = std.testing.tmpDir(.{}); + defer tmp.cleanup(); + try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "a.txt", .data = "a\n" }); + try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "b.txt", .data = "b\n" }); + var s = try Session.initFile(std.testing.allocator, "x\n"); + defer s.deinit(); + var buf: [4096]u8 = undefined; + const dir = buf[0..try tmp.dir.realPath(std.testing.io, &buf)]; + const r = try s.lookFile(s.at("{s}/a.txt", .{dir})); + const body = try s.hold(s.at("/pane/{d}/body", .{r}), 0); + // A step in place: b.txt in the pane a.txt was in. + try s.write(s.at("/pane/{d}/look", .{r}), s.at("{s}/b.txt\n", .{dir})); + try expectEqual(r, try s.focused()); + try s.expect(s.at("/pane/{d}/name", .{r}), s.at("{s}/b.txt\n", .{dir})); + try std.testing.expectEqualStrings("b\n", try s.readFid(body)); + s.clunk(body); + const log = try s.read("/log"); + try std.testing.expect(std.mem.endsWith(u8, log, s.at("rename {d} {s}/b.txt\n", .{ r, dir }))); + try std.testing.expect(std.mem.indexOf(u8, log, s.at("del {d} ", .{r})) == null); + try std.testing.expect(std.mem.indexOf(u8, try s.read("/recent"), s.at("{s}/a.txt", .{dir})) != null); +} diff --git a/test/behaviour/other_files.zig b/test/behaviour/other_files.zig index b19ffa0f..e6c104c3 100644 --- a/test/behaviour/other_files.zig +++ b/test/behaviour/other_files.zig @@ -22,6 +22,22 @@ test "other-files: kbdin types at the pane with the keyboard and mousein clicks, try std.testing.expectError(error.Refused, s.read("/kbdin")); } +test "other-files: kbdin's keys are the user's: SPC f f opens Find's picker in the pane's tag where jumps walk, not the +Search a script's Find opens" { + var tmp = std.testing.tmpDir(.{}); + defer tmp.cleanup(); + try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "a.txt", .data = "a\n" }); + try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "b.txt", .data = "b\n" }); + var s = try Session.initFile(std.testing.allocator, "x\n"); + defer s.deinit(); + var buf: [4096]u8 = undefined; + _ = try s.lookFile(s.at("{s}/a.txt", .{buf[0..try tmp.dir.realPath(std.testing.io, &buf)]})); + try s.keys(" ff"); + try std.testing.expect(std.mem.indexOf(u8, try s.read("/index"), "+Search") == null); + // Its rows under the tag of the pane typed at, the cursor on the first. + _ = try s.where("▶ a.txt"); + _ = try s.where(" b.txt"); +} + test "other-files: kbdin's Kalt rune is Alt on the key after it alone, and an Alt key types nothing" { var s = try Session.initFile(std.testing.allocator, "x\n"); defer s.deinit(); diff --git a/test/lspmock.zig b/test/lspmock.zig index 8b5c73a8..0fd34677 100644 --- a/test/lspmock.zig +++ b/test/lspmock.zig @@ -207,7 +207,7 @@ fn handle(a: std.mem.Allocator, raw: []const u8) void { \\"referencesProvider":true,"documentHighlightProvider":true, \\"hoverProvider":true,"documentSymbolProvider":true, \\"workspaceSymbolProvider":true,"renameProvider":true, - \\"documentFormattingProvider":true,"codeActionProvider":true, + \\"documentFormattingProvider":true,"codeActionProvider":{{"resolveProvider":true}}, \\"completionProvider":{{}}, \\"callHierarchyProvider":true,"typeHierarchyProvider":true, \\"diagnosticProvider":{{"interFileDependencies":false,"workspaceDiagnostics":false}}, @@ -283,7 +283,14 @@ fn handle(a: std.mem.Allocator, raw: []const u8) void { } else if (std.mem.eql(u8, method, "textDocument/formatting")) { reply(a, rid, "[{{\"range\":{s},\"newText\":\"// formatted by mock\\n\"}}]", .{range(a, 0, 0, 0)}); } else if (std.mem.eql(u8, method, "textDocument/codeAction")) { - reply(a, rid, "[{{\"title\":\"mock action: extract\"}}]", .{}); + // A title alone (a command's), one with its edit (a line put in + // at the top), and one whose edit is resolved when asked (its + // `data` the document's uri). + reply(a, rid, "[{{\"title\":\"mock action: extract\"}},{{\"title\":\"mock action: add a line\",\"edit\":{{\"changes\":{{\"{s}\":[{{\"range\":{s},\"newText\":\"// added by mock\\n\"}}]}}}}}},{{\"title\":\"mock action: rename add to sum\",\"data\":\"{s}\"}}]", .{ uri, range(a, 0, 0, 0), uri }); + } else if (std.mem.eql(u8, method, "codeAction/resolve")) { + // main.rs's two calls of `add` (L3, L4) renamed. + const doc = str(get(params, "data")) orelse uri; + reply(a, rid, "{{\"title\":\"mock action: rename add to sum\",\"edit\":{{\"changes\":{{\"{s}\":[{{\"range\":{s},\"newText\":\"sum\"}},{{\"range\":{s},\"newText\":\"sum\"}}]}}}}}}", .{ doc, range(a, 3, 12, 15), range(a, 4, 12, 15) }); } else if (std.mem.eql(u8, method, "textDocument/completion")) { reply(a, rid, "{{\"items\":[{{\"label\":\"alpha\",\"detail\":\"fn alpha()\"}},{{\"label\":\"beta\",\"detail\":\"fn beta()\"}}]}}", .{}); } else if (std.mem.eql(u8, method, "textDocument/diagnostic")) { diff --git a/test/process/window.zig b/test/process/window.zig index 59c84616..292e0e00 100644 --- a/test/process/window.zig +++ b/test/process/window.zig @@ -8,6 +8,7 @@ const process = @import("../process.zig"); pub const cases = .{ .{ "window: a monkey over the effects: random clicks, drags, wheels, keys, columns, looks and themes, then it settles, alive, with no crash record", monkey }, .{ "window: its frame corpus, every kept frame and its sha256 into PARDES_GUI_CORPUS, to compare two builds on one machine", corpus }, + .{ "window: a lone Esc written to its test stdin is the Escape key at once, the key written after it its own", loneEscape }, }; fn envOr(name: [*:0]const u8, default: []const u8) []const u8 { @@ -193,6 +194,25 @@ fn bodyHas(f: *process.Files, serial: u32, word: []const u8) !void { if (process.nowMs() > deadline) return error.NoOutput; } +/// A lone Esc a driver writes to the window's stdin, as its keys come: +/// the Escape key at once. Held for the next write (DESIGN D15, POLISH 16), +/// that write's `A` came as Alt-A and its `y` was typed where insert mode +/// still was. +fn loneEscape(gpa: std.mem.Allocator, exe: [:0]const u8) !void { + try process.only(.gui); + var d = try process.Detached.start(gpa, exe, "loneesc", .{}); + defer d.deinit(); + const f = &d.files; + const pane = try paneWith(f, "loneesc.txt"); + try d.typeKeys("ix"); + try d.settle(gpa); + try d.typeKeys("\x1b"); + try d.settle(gpa); + try d.typeKeys("Ay"); + try d.settle(gpa); + try std.testing.expectEqualStrings("xinitialy\n", try f.read(f.at("/pane/{d}/body", .{pane}))); +} + extern "c" fn system(cmd: [*:0]const u8) c_int; extern "c" fn ioctl(fd: c_int, request: c_ulong, ...) c_int; @@ -402,10 +422,10 @@ fn corpus(gpa: std.mem.Allocator, exe: [:0]const u8) !void { defer arena.deinit(); const a = arena.allocator(); defer _ = system("rm -rf -- /tmp/pardes-gui-corpus"); - // Its Looks open panes and Del them by serial, as `Jumps new-pane` - // does (SPEC §6.6): under walk a file pane steps in place, a new - // serial, and the frames would not be the base's to compare. - const init = "Shell /bin/sh\nTheme forge\nMessageLinger 0\nCursorBlink off\nJumps new-pane\n"; + // Jumps walk, the default: the file pane's Looks at files step it in + // place, the same pane (its serial kept, Trail.show); a picture's and a + // PDF's open panes of their own. + const init = "Shell /bin/sh\nTheme forge\nMessageLinger 0\nCursorBlink off\n"; var k: Corpus = .{ .gpa = gpa, .a = a, .out = out }; { try corpusRoot(a); @@ -474,7 +494,8 @@ fn corpus(gpa: std.mem.Allocator, exe: [:0]const u8) !void { const image = try paneWith(f, "ramp.ppm"); try k.keep(&d, 0, "09 an image pane", false); try f.write(f.at("/pane/{d}/exec", .{image}), "Del\n"); - try f.write(f.at("/pane/{d}/exec", .{notes}), "Del\n"); + // The file pane walks back to shapes.zig (its trail's step). + try f.write(f.at("/pane/{d}/look", .{notes}), root ++ "/shapes.zig\n"); try f.write(f.at("/pane/{d}/look", .{first}), root ++ "/doc.pdf\n"); _ = try paneWith(f, "doc.pdf"); try k.keep(&d, 0, "09 a PDF pane", false); diff --git a/test/snapshots/find.golden b/test/snapshots/find.golden index b6521d31..5fe63c16 100644 --- a/test/snapshots/find.golden +++ b/test/snapshots/find.golden @@ -83,18 +83,18 @@ |4: rop | Grep Recent Panes Symbols All Jumplist |5: nothing matches |7: 1 beta body -|40: ⏎ lands here · its text is the preview · S-⏎ a new pane 2 messages · SPC h m +|40: ⏎ lands here · its text is the preview · S-⏎ a new pane 1 message · SPC h m == snap cancel grid=120x41 cursor=7,3 |2: here.txt:1 › Find zqm 2/3 › /tmp/pardes-snap/find/cwd/sub/ZQMARK-beta.txt Keep Save Term Collapse Follow Del |3: 1 beta body |4: |5: |7: -|40: ✓ /tmp/pardes-snap/find/cwd/sub/ZQMARK-beta.txt Find 2 messages · SPC h m +|40: ✓ /tmp/pardes-snap/find/cwd/sub/ZQMARK-beta.txt Find 1 message · SPC h m == snap topbar grid=120x41 cursor=84,2 |2: ^ · › Find zqm 2/3 › /tmp/pardes-snap/find/cwd/sub/ZQMARK-beta.txt Keep ␣ f Find bod 0/0 |3: │ │ Walk Look Split Newcol Grep Edit Copy Keep D |4: rop | Grep Recent Panes Symbols All Jumplist |5: nothing matches |7: 1 beta body -|40: ⏎ lands here · its text is the preview · S-⏎ a new pane 2 messages · SPC h m +|40: ⏎ lands here · its text is the preview · S-⏎ a new pane 1 message · SPC h m diff --git a/test/snapshots/leader.golden b/test/snapshots/leader.golden index c6a5460e..9b7c1048 100644 --- a/test/snapshots/leader.golden +++ b/test/snapshots/leader.golden @@ -195,25 +195,25 @@ |18: 13 List the subtypes of the type under the cursor in a +Search; a single one is a jump. |19: 14 |20: 15 SPC l a CodeAction -|21: 16 List the language server's code actions for the cursor, in a +Lsp. -|22: 17 -|23: 18 SPC l b Callstack -|24: 19 Show the callers of the function under the cursor as a tree, outermost first, in a +Callstac↩ -|25: k. -|26: 20 Each caller with its place to open and its signature, the line of each call under it; caller↩ -|27: s named for tests after the rest, a recursion marked `↻`. CallstackDepth sets how many level↩ -|28: s (8 by default); a deeper tree says where to go on from. `g c` does the same. -|29: 21 -|30: 22 SPC l c Callers -|31: 23 List the functions that call the one under the cursor, one level up; a single one is a jump. -|32: 24 -|33: 25 SPC l d Diagnostics -|34: 26 List this file's diagnostics in a +Search. -|35: 27 `] d` and `[ d` step through them in the text, `] D` and `[ D` to the last and the first. -|36: 28 -|37: 29 SPC l h SelectRefs -|38: 30 Select every reference to the symbol under the cursor. -|39: 31 +|21: 16 List the language server's code actions for the cursor, to apply one. +|22: 17 Typed where jumps walk, they are a picker in the pane's tag, the one under the cursor shown ↩ +|23: as its edit, applied by Enter or its digit; else a +Lsp lists them. +|24: 18 +|25: 19 SPC l b Callstack +|26: 20 Show the callers of the function under the cursor as a tree, outermost first, in a +Callstac↩ +|27: k. +|28: 21 Each caller with its place to open and its signature, the line of each call under it; caller↩ +|29: s named for tests after the rest, a recursion marked `↻`. CallstackDepth sets how many level↩ +|30: s (8 by default); a deeper tree says where to go on from. `g c` does the same. +|31: 22 +|32: 23 SPC l c Callers +|33: 24 List the functions that call the one under the cursor, one level up; a single one is a jump. +|34: 25 +|35: 26 SPC l d Diagnostics +|36: 27 List this file's diagnostics in a +Search. +|37: 28 `] d` and `[ d` step through them in the text, `] D` and `[ D` to the last and the first. +|38: 29 +|39: 30 SPC l h SelectRefs |40: ✓ /tmp/pardes-snap/leader/cwd/cmds.txt Help 16 messages · SPC h m == snap del-output grid=100x41 cursor=7,3 |5: |
