summaryrefslogtreecommitdiff
path: root/test/process/builtins.zig
diff options
context:
space:
mode:
Diffstat (limited to 'test/process/builtins.zig')
-rw-r--r--test/process/builtins.zig52
1 files changed, 52 insertions, 0 deletions
diff --git a/test/process/builtins.zig b/test/process/builtins.zig
new file mode 100644
index 00000000..410a3f54
--- /dev/null
+++ b/test/process/builtins.zig
@@ -0,0 +1,52 @@
+//! docs/typ/reference.typ, Builtins <builtins> a real session runs, detached
+//! and in a pty.
+const std = @import("std");
+const process = @import("../process.zig");
+const Conn = process.Conn;
+const has = process.has;
+const check = process.check;
+
+pub const cases = .{
+ .{ "builtins: Lspinfo opens one +Lsp pane saying the backend and its servers, detached and in a pty", lspinfo },
+};
+
+fn lspinfo(gpa: std.mem.Allocator, exe: [:0]const u8) !void {
+ for ([_]bool{ false, true }) |tty| {
+ var arena = std.heap.ArenaAllocator.init(gpa);
+ defer arena.deinit();
+ const a = arena.allocator();
+ const name = if (tty) "lsp-tty" else "lsp-detached";
+ var d = try process.Detached.start(gpa, exe, if (tty) "lsp-root" else name, .{});
+ defer d.deinit();
+ var term: ?process.Child = null;
+ defer if (term) |*t| t.deinit();
+ if (tty) term = try d.startTty(exe, name, &.{});
+ const address = d.abs(try std.fmt.allocPrint(a, "pardes-9p-{s}.sock", .{name}));
+ const c = try Conn.dial(gpa, address);
+ defer c.deinit(gpa);
+ const control = try c.newPane();
+ try c.exec(control, "Lspinfo\n");
+ const deadline = process.nowMs() + 3_000;
+ const lsp = while (true) {
+ var found: ?u32 = null;
+ var count: usize = 0;
+ var rows = std.mem.tokenizeScalar(u8, try c.read(a, "/index"), '\n');
+ while (rows.next()) |row| if (has(row, "+Lsp")) {
+ count += 1;
+ found = try std.fmt.parseInt(u32, row[0..std.mem.indexOfScalar(u8, row, ' ').?], 10);
+ };
+ if (found) |n| {
+ try check(count == 1, "{s}: {d} +Lsp panes", .{ name, count });
+ break n;
+ }
+ if (process.nowMs() > deadline) return error.LspinfoNeverDone;
+ process.nap(5);
+ };
+ const body = try c.pane(a, lsp, "body");
+ try check(std.mem.startsWith(u8, body, "backend: lsp-client\n") and has(body, "protocol servers (lsp-client):"), "{s}", .{body});
+ try std.testing.expectEqualStrings("initial\n", try c.read(a, "/pane/1/body"));
+ var f: process.Files = .init(gpa, address);
+ defer f.deinit();
+ try check(has(try f.screen(), "+Lsp"), "+Lsp not drawn", .{});
+ }
+}