diff options
Diffstat (limited to 'test/behaviour')
| -rw-r--r-- | test/behaviour/addons.zig | 159 | ||||
| -rw-r--r-- | test/behaviour/addons_pdf.zig | 30 | ||||
| -rw-r--r-- | test/behaviour/keys.zig | 6 | ||||
| -rw-r--r-- | test/behaviour/language_servers.zig | 82 | ||||
| -rw-r--r-- | test/behaviour/other_files.zig | 6 |
5 files changed, 278 insertions, 5 deletions
diff --git a/test/behaviour/addons.zig b/test/behaviour/addons.zig index ce3c7b02..0b0555c2 100644 --- a/test/behaviour/addons.zig +++ b/test/behaviour/addons.zig @@ -371,3 +371,162 @@ test "addons: an image pane whose file changes on disk shows the new picture, un try std.testing.expectEqual(n, try s.focused()); try std.testing.expect(has(try s.read("/screen"), "\"src\":[0,0,3,1]")); } + +/// A tmp directory's real path, kept in the session's arena. +fn dirOf(s: *Session, tmp: *std.testing.TmpDir) ![]const u8 { + var buf: [4096]u8 = undefined; + return s.arena.allocator().dupe(u8, buf[0..try tmp.dir.realPath(std.testing.io, &buf)]); +} + +test "addons: a picker shows a file of an addon's kind through its kind in the pane it lands in, Esc puts that pane back as it was, and Enter lands as a Look does" { + var tmp = std.testing.tmpDir(.{}); + defer tmp.cleanup(); + // A work tree of its own: Find searches it, not the one the test runs in. + try tmp.dir.createDir(std.testing.io, ".git", .default_dir); + try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "notes.txt", .data = "the notes\n" }); + try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "seven.fake", .data = "1234567" }); + var s = try Session.initFile(std.testing.allocator, "x\n"); + defer s.deinit(); + try load(&s, fake.ok); + defer unload(&s, "fake"); + const dir = try dirOf(&s, &tmp); + const pane = try s.lookFile(s.at("{s}/notes.txt", .{dir})); + const body = s.at("/pane/{d}/body", .{pane}); + const a = s.arena.allocator(); + const screen = try a.dupe(u8, try s.screen()); + const index = try a.dupe(u8, try s.read("/index")); + // Its kind's paint in the reading pane's body (the fake counts the + // file's 7 bytes), not the pane's own text, nor the file's bytes. + try s.keys(" ffseven"); + s.tick(); + const shown = try s.screen(); + try std.testing.expect(has(shown, "count 7")); + try std.testing.expect(!has(shown, "the notes") and !has(shown, "1234567")); + // Esc: the pane exactly as it was, and no pane more or less. + try s.keys("\x1b"); + s.tick(); + // (The notice row says the Find ran: the session's, not the pane's.) + const after = try s.screen(); + try std.testing.expectEqualStrings(screen[0..std.mem.lastIndexOfScalar(u8, screen, '\n').?], after[0..std.mem.lastIndexOfScalar(u8, after, '\n').?]); + try s.expect(body, "the notes\n"); + try std.testing.expectEqualStrings(index, try s.read("/index")); + // Enter: the kind's pane where a Look puts it; the reading pane keeps + // its text. (The listing is the next frame's, as for the keyboard.) + try s.keys(" ffseven"); + s.tick(); + try s.keys("\n"); + s.tick(); + const opened = try paneOf(&s, "fake"); + try std.testing.expect(opened != pane); + try s.expect(body, "the notes\n"); + try std.testing.expect(has(try s.screen(), "count 7")); +} + +test "addons: a picker's row of a file no kind takes and not text shows one line naming it, and the row before's file never stays in the body" { + var tmp = std.testing.tmpDir(.{}); + defer tmp.cleanup(); + // A work tree of its own: Find searches it, not the one the test runs in. + try tmp.dir.createDir(std.testing.io, ".git", .default_dir); + try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "notes.txt", .data = "the notes\n" }); + try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "other.txt", .data = "other text\n" }); + try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "seven.fake", .data = "1234567" }); + var blob: [3000]u8 = undefined; + for (&blob, 0..) |*b, i| b.* = @truncate(i *% 7); + try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "blob.bin", .data = &blob }); + var s = try Session.initFile(std.testing.allocator, "x\n"); + defer s.deinit(); + try load(&s, fake.ok); + defer unload(&s, "fake"); + const dir = try dirOf(&s, &tmp); + const pane = try s.lookFile(s.at("{s}/notes.txt", .{dir})); + try s.keys(" ffother"); + s.tick(); + try std.testing.expect(has(try s.screen(), "other text")); + // Onto the binary: its one line, never its bytes, nor other.txt. + try s.keys("\x08\x08\x08\x08\x08blob"); + s.tick(); + var shown = try s.screen(); + try std.testing.expect(has(shown, "blob.bin · binary · 3.0 kB")); + try std.testing.expect(!has(shown, "other text")); + // Onto a kind's file: its kind's paint, not the binary's line. + try s.keys("\x08\x08\x08\x08seven"); + s.tick(); + shown = try s.screen(); + try std.testing.expect(has(shown, "count 7")); + try std.testing.expect(!has(shown, "blob.bin · binary")); + // Back onto text, then Esc: the pane's own. + try s.keys("\x08\x08\x08\x08\x08other"); + s.tick(); + shown = try s.screen(); + try std.testing.expect(has(shown, "other text") and !has(shown, "count 7")); + try s.keys("\x1b"); + s.tick(); + try s.expect(s.at("/pane/{d}/body", .{pane}), "the notes\n"); + try std.testing.expect(has(try s.screen(), "the notes")); +} + +test "addons: moving the cursor over pictures in a picker draws only the one it rests on, and a draw of one passed by is dropped whenever it comes back" { + var tmp = std.testing.tmpDir(.{}); + defer tmp.cleanup(); + // A work tree of its own: Find searches it, not the one the test runs in. + try tmp.dir.createDir(std.testing.io, ".git", .default_dir); + const png = "\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x00\x01\x00\x00\x00\x01\x08\x02\x00\x00\x00\x90wS\xde\x00\x00\x00\x0cIDATx\x9cc\xf8\xcf\xc0\x00\x00\x03\x01\x01\x00\xc9\xfe\x92\xef\x00\x00\x00\x00IEND\xaeB`\x82"; + try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "notes.txt", .data = "the notes\n" }); + try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "pic1.png", .data = png }); + try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "pic2.png", .data = png }); + try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "pic3.ppm", .data = "P6\n2 1\n255\n\x0d\x4d\xe7\x0d\x4d\xe7" }); + var s = try Session.initFile(std.testing.allocator, "x\n"); + defer s.deinit(); + s.graphics(); + try load(&s, Session.image_addon); + defer unload(&s, "image"); + const dir = try dirOf(&s, &tmp); + const pane = try s.lookFile(s.at("{s}/notes.txt", .{dir})); + s.holdJobs(); + try s.keys(" ffpic"); + s.tick(); + // Until its picture is drawn, one line names it. + const first = try s.screen(); + try std.testing.expect(has(first, " · image · ")); + try std.testing.expectEqual(1, s.held.items.len); + // Two rows down with no frame between: only the row it rests on draws. + try s.keys("\u{F800}\u{F800}"); + s.tick(); + _ = try s.screen(); + try std.testing.expectEqual(2, s.held.items.len); + const rested = if (has(try s.screen(), "▶ pic3.ppm")) "\"src\":[0,0,2,1]" else "\"src\":[0,0,1,1]"; + const passed = if (std.mem.eql(u8, rested, "\"src\":[0,0,2,1]")) "\"src\":[0,0,1,1]" else "\"src\":[0,0,2,1]"; + // The rested one's answer first, the passed one's after: dropped. + std.mem.reverse(@TypeOf(s.held.items[0]), s.held.items); + s.releaseJobs(); + const screen = try s.read("/screen"); + try std.testing.expect(has(screen, s.at("\"serial\":{d},", .{pane})) and has(screen, rested)); + try std.testing.expect(!has(screen, passed)); +} + +test "addons: Enter on a picture in a picker opens its kind's pane, never its bytes as text in the reading pane (the user's report)" { + var tmp = std.testing.tmpDir(.{}); + defer tmp.cleanup(); + // A work tree of its own: Find searches it, not the one the test runs in. + try tmp.dir.createDir(std.testing.io, ".git", .default_dir); + try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "notes.txt", .data = "the notes\n" }); + try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "pic.ppm", .data = "P6\n2 1\n255\n\x0d\x4d\xe7\x0d\x4d\xe7" }); + var s = try Session.initFile(std.testing.allocator, "x\n"); + defer s.deinit(); + s.graphics(); + try load(&s, Session.image_addon); + defer unload(&s, "image"); + const dir = try dirOf(&s, &tmp); + const pane = try s.lookFile(s.at("{s}/notes.txt", .{dir})); + // The listing is the next frame's, as for the keyboard. + try s.keys(" ffpic"); + s.tick(); + try s.keys("\n"); + s.tick(); + try s.expect(s.at("/pane/{d}/body", .{pane}), "the notes\n"); + const image = try paneOf(&s, "image"); + try std.testing.expect(image != pane); + const screen = try s.read("/screen"); + try std.testing.expect(has(screen, s.at("\"serial\":{d},", .{image})) and has(screen, "\"src\":[0,0,2,1]")); + try std.testing.expect(!has(try s.screen(), "1 P6")); +} diff --git a/test/behaviour/addons_pdf.zig b/test/behaviour/addons_pdf.zig index dedf157a..7df5d5ee 100644 --- a/test/behaviour/addons_pdf.zig +++ b/test/behaviour/addons_pdf.zig @@ -299,3 +299,33 @@ test "addons: a PDF whose file changes on disk while a page of it renders: the p try s.keys("0"); try std.testing.expect((try shown(&s, n)).len >= 1); } + +test "addons: a PDF under a picker's cursor shows through the pdf addon in the pane it lands in, never its bytes as text, and Esc puts the pane's own text back" { + var s = try Session.initFile(std.testing.allocator, "x\n"); + defer s.deinit(); + s.graphics(); + try s.loadPdf(); + var tmp = std.testing.tmpDir(.{}); + defer tmp.cleanup(); + // A work tree of its own: Find searches it, not the one the test runs in. + try tmp.dir.createDir(std.testing.io, ".git", .default_dir); + const pdf = try std.Io.Dir.cwd().readFileAlloc(std.testing.io, "docs/design.pdf", s.arena.allocator(), .limited(4 << 20)); + try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "paper.pdf", .data = pdf }); + try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "notes.txt", .data = "the notes\n" }); + var buf: [4096]u8 = undefined; + const dir = buf[0..try tmp.dir.realPath(std.testing.io, &buf)]; + const pane = try s.lookFile(s.at("{s}/notes.txt", .{dir})); + try s.keys(" ffpaper"); + // (Its kind told its view at the frame after the one that opened it.) + s.tick(); + s.tick(); + const screen = try s.screen(); + try std.testing.expect(!has(screen, "%PDF") and !has(screen, "the notes")); + // Its pages pictures in that pane's body, as a PDF's pane shows them. + try std.testing.expect((try shown(&s, pane)).len > 0); + try s.keys("\x1b"); + s.tick(); + try s.expect(s.at("/pane/{d}/body", .{pane}), "the notes\n"); + try std.testing.expectEqual(0, (try shown(&s, pane)).len); + try std.testing.expect(has(try s.screen(), "the notes")); +} diff --git a/test/behaviour/keys.zig b/test/behaviour/keys.zig index 2274e73a..241468ac 100644 --- a/test/behaviour/keys.zig +++ b/test/behaviour/keys.zig @@ -237,7 +237,7 @@ test "keys: SPC j n and SPC j p walk Themes' rows, whole, never its section head // A heading, then a row a theme; each section after the first a blank // line and its heading. var lines = std.mem.splitScalar(u8, body, '\n'); - try std.testing.expectEqualStrings("# Pardes themes", lines.next().?); + try std.testing.expectEqualStrings("# Pardes", lines.next().?); var names: std.ArrayList([]const u8) = .empty; var first_break: ?usize = null; while (lines.next()) |line| { @@ -251,7 +251,7 @@ test "keys: SPC j n and SPC j p walk Themes' rows, whole, never its section head try names.append(s.arena.allocator(), line); } const brk = first_break orelse return error.NoSections; - try std.testing.expect(std.mem.indexOf(u8, body[0..std.mem.indexOf(u8, body, "\n\n").?], "\nTheme acme\n") != null); + try std.testing.expect(std.mem.indexOf(u8, body[0..std.mem.indexOf(u8, body, "\n\n").?], "\nTheme orchard\n") != null); // Across the first section's end and back, the theme as it was. for (names.items[0 .. brk + 1]) |row| { try s.keys(" jn"); @@ -354,7 +354,7 @@ test "keys: SPC j n from the pane a Look gave the keyboard walks back into the c const themes = try s.focused(); try std.testing.expect(themes != a); const sel = s.at("/pane/{d}/sel", .{themes}); - try s.expect(sel, "Theme orchard"); + try s.expect(sel, "Theme dark"); try s.write(s.at("/pane/{d}/exec", .{a}), "Look b.txt\n"); try std.testing.expect(try s.focused() != themes); try s.keys(" jn"); diff --git a/test/behaviour/language_servers.zig b/test/behaviour/language_servers.zig index 13e42fa6..d1b160ee 100644 --- a/test/behaviour/language_servers.zig +++ b/test/behaviour/language_servers.zig @@ -206,7 +206,7 @@ test "language-servers: Symbols lists the file's definitions by name, a local's try s.write(s.at("/pane/{d}/look", .{main}), s.at("{s}/lib.rs\n", .{std.fs.path.dirname(std.mem.trimEnd(u8, try s.read(s.at("/pane/{d}/name", .{main})), "\n")).?})); try s.write(s.at("/pane/{d}/ctl", .{try s.focused()}), "Symbols\n"); const rows = try bodyOf(&s, "+Search"); - for ([_][]const u8{ "lib.rs:1:11-15\nShape\n", "lib.rs:2:8-11\narea\n", "lib.rs:5:8-10\nadd\n", "lib.rs:8:12-17\nSquare\n", "lib.rs:10:8-11\narea\n" }) |row| + for ([_][]const u8{ "lib.rs:1:11-15 Shape\n", "lib.rs:2:8-11 area\n", "lib.rs:5:8-10 add\n", "lib.rs:8:12-17 Square\n", "lib.rs:10:8-11 area\n" }) |row| try std.testing.expect(has(rows, row)); try std.testing.expect(!has(rows, "lib.rs:5:12")); } @@ -323,3 +323,83 @@ test "language-servers: SPC l a lists the server's code actions in the pane's ta try s.keys("u"); try s.expect(body, before); } + +test "language-servers: a server's Symbols are the Symbols picker's rows: types, functions, fields, then the rest, each its kind's mark and its name in the ones it is in (UX DESIGN N)" { + var tmp = std.testing.tmpDir(.{}); + defer tmp.cleanup(); + var s = try Session.initLanguage(std.testing.allocator); + defer s.deinit(); + try s.write("/ctl", "Jumps new-pane\n"); + // No index: the server is asked. + try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "shapes.rs", .data = "const LIMIT: u32 = 4;\n\nfn main() {}\npub struct Shape {\n side: u32,\n fn area() {}\n}\nenum Kind {\n Round,\n}\nmod lib;\n" }); + var buf: [4096]u8 = undefined; + const dir = buf[0..try tmp.dir.realPath(std.testing.io, &buf)]; + const shapes = try s.lookFile(s.at("{s}/shapes.rs:1:1", .{dir})); + try s.write(s.at("/pane/{d}/ctl", .{shapes}), "Symbols\n"); + const rows = try bodyOf(&s, "+Search"); + var at: usize = 0; + for ([_][]const u8{ "shapes.rs:4:12-16 t Shape\n", "shapes.rs:8:6-9 t Kind\n", "shapes.rs:3:4-7 f main\n", "shapes.rs:6:8-11 f Shape.area\n", "shapes.rs:5:5-8 m Shape.side\n", "shapes.rs:9:5-9 m Kind.Round\n", "shapes.rs:1:7-11 c LIMIT\n", "shapes.rs:11:5-7 n lib\n" }) |row| { + const found = std.mem.indexOfPos(u8, rows, at, row) orelse { + std.debug.print("{s} not after {d} in\n{s}\n", .{ row, at, rows }); + return error.TestUnexpectedResult; + }; + at = found + row.len; + } +} + +extern "c" fn setenv(name: [*:0]const u8, value: [*:0]const u8, overwrite: c_int) c_int; + +/// The row of Lspinfo's report on the server `name` (`zls`), asked of the +/// pane with the keyboard, and how many queries its client has answered. +fn serverRow(s: *Session, name: []const u8) !struct { []const u8, []const u8 } { + try s.write(s.at("/pane/{d}/ctl", .{try s.focused()}), "Lspinfo\n"); + const info = try bodyOf(s, "+Lsp"); + const at = (std.mem.indexOf(u8, info, s.at("\n {s} ", .{name})) orelse return error.NoSuchServer) + 1; + const row = info[at .. std.mem.indexOfScalarPos(u8, info, at, '\n') orelse info.len]; + const log = std.mem.indexOf(u8, info, "client queries (") orelse return error.NoQueryLog; + return .{ row, info[log .. std.mem.indexOfPos(u8, info, log, " total") orelse return error.NoQueryLog] }; +} + +test "language-servers: a file of a server's language opened in a pane starts that server and tells it of the file, with no query asked; a picker's preview of one starts none, a second file no second server, and a server not installed is found silently" { + const io = std.testing.io; + var tmp = std.testing.tmpDir(.{}); + defer tmp.cleanup(); + // A work tree of its own: Find searches it, not the one the test runs in. + try tmp.dir.createDir(io, ".git", .default_dir); + try tmp.dir.writeFile(io, .{ .sub_path = "a.zig", .data = "const a = 1;\n" }); + try tmp.dir.writeFile(io, .{ .sub_path = "b.zig", .data = "const b = 2;\n" }); + try tmp.dir.writeFile(io, .{ .sub_path = "c.py", .data = "c = 3\n" }); + try tmp.dir.writeFile(io, .{ .sub_path = "d.py", .data = "d = 4\n" }); + try tmp.dir.writeFile(io, .{ .sub_path = "notes.txt", .data = "the notes\n" }); + var buf: [4096]u8 = undefined; + const dir = buf[0..try tmp.dir.realPath(io, &buf)]; + var s = try Session.initLanguage(std.testing.allocator); + defer s.deinit(); + _ = try s.lookFile(s.at("{s}/notes.txt", .{dir})); + // a.zig previewed by Find's picker (the session's jumps walk): its text + // shown, its server (the scripted one, the session's zls) not started. + try s.keys(" ffa.zig"); + s.tick(); + try std.testing.expect(has(try s.screen(), "const a = 1;")); + try s.keys("\x1b"); + const before, const asked = try serverRow(&s, "zls"); + try std.testing.expect(has(before, "not started yet")); + // Opened: started and told of a.zig, no query asked of it. + _ = try s.lookFile(s.at("{s}/a.zig", .{dir})); + const opened, const asked_open = try serverRow(&s, "zls"); + try std.testing.expect(has(opened, "ready") and has(opened, "docs 1")); + try std.testing.expectEqualStrings(asked, asked_open); + // A second file: the same server told of it too (a second would know one). + _ = try s.lookFile(s.at("{s}/b.zig", .{dir})); + const second, _ = try serverRow(&s, "zls"); + try std.testing.expect(has(second, "ready") and has(second, "docs 2")); + // Not installed: the language's server disabled at the first file's + // open, with no word at either (its first query says it is not found). + _ = setenv("PARDES_LSP_PY", "/nonexistent/pyright-langserver", 1); + _ = try s.lookFile(s.at("{s}/c.py", .{dir})); + _ = try s.lookFile(s.at("{s}/d.py", .{dir})); + const missing, const asked_missing = try serverRow(&s, "pyright"); + try std.testing.expect(has(missing, "disabled")); + try std.testing.expectEqualStrings(asked, asked_missing); + try std.testing.expect(!has(try s.screen(), "not found")); +} diff --git a/test/behaviour/other_files.zig b/test/behaviour/other_files.zig index e6c104c3..95d4de6d 100644 --- a/test/behaviour/other_files.zig +++ b/test/behaviour/other_files.zig @@ -25,6 +25,8 @@ test "other-files: kbdin types at the pane with the keyboard and mousein clicks, 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(); + // A work tree of its own: Find searches it, not the one the test runs in. + try tmp.dir.createDir(std.testing.io, ".git", .default_dir); 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"); @@ -33,7 +35,9 @@ test "other-files: kbdin's keys are the user's: SPC f f opens Find's picker in t _ = 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. + // Its rows under the tag of the pane typed at, the cursor on the first, + // the next frame, as the keyboard's: the listing is not the write's. + s.tick(); _ = try s.where("▶ a.txt"); _ = try s.where(" b.txt"); } |
