summaryrefslogtreecommitdiff
path: root/test/behaviour/callstack.zig
diff options
context:
space:
mode:
Diffstat (limited to 'test/behaviour/callstack.zig')
-rw-r--r--test/behaviour/callstack.zig61
1 files changed, 61 insertions, 0 deletions
diff --git a/test/behaviour/callstack.zig b/test/behaviour/callstack.zig
new file mode 100644
index 00000000..42448031
--- /dev/null
+++ b/test/behaviour/callstack.zig
@@ -0,0 +1,61 @@
+//! docs/typ/guide.typ, Call hierarchy <callstack>, asked of the scripted
+//! language server (test/lspmock.zig): `add` in lib.rs is called twice by
+//! `main` in main.rs, and `main` by itself.
+const std = @import("std");
+const Session = @import("session").Session;
+
+/// main.rs and lib.rs in a directory of their own, main.rs shown with its
+/// cursor on the first call of `add`; its pane's serial.
+fn openMain(s: *Session, tmp: *std.testing.TmpDir) !u32 {
+ try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "main.rs", .data = "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 = "lib.rs", .data = "// mock fixture\npub fn add(a: i32, b: i32) -> i32 {\n a + b\n}\n" });
+ var buf: [4096]u8 = undefined;
+ const dir = buf[0..try tmp.dir.realPath(std.testing.io, &buf)];
+ return s.lookFile(s.at("{s}/main.rs:4:13", .{dir}));
+}
+
+test "callstack: Callstack opens +Callstack, the outermost callers first, each with its signature and its call sites, a recursion marked" {
+ var tmp = std.testing.tmpDir(.{});
+ defer tmp.cleanup();
+ var s = try Session.initLanguage(std.testing.allocator);
+ defer s.deinit();
+ const main = try openMain(&s, &tmp);
+ try s.write(s.at("/pane/{d}/ctl", .{main}), "Callstack\n");
+ const tree = try s.focused();
+ try std.testing.expect(std.mem.endsWith(u8, try s.read(s.at("/pane/{d}/name", .{tree})), "/+Callstack\n"));
+ try s.expect(s.at("/pane/{d}/body", .{tree}),
+ \\╰──┬ main.rs:3:4-7
+ \\ │ fn main() {
+ \\ ├─ main.rs:4:13-15
+ \\ │ let x = add(1, 2);
+ \\ ├─ main.rs:5:13-15
+ \\ │ let y = add(3, 4);
+ \\ ╰──┬ main.rs:3:4-7
+ \\ │ fn main() { ↻ recursion
+ \\ ├─ main.rs:4:13-15
+ \\ │ let x = add(1, 2);
+ \\ ╰─ main.rs:5:13-15
+ \\ let y = add(3, 4);
+ \\
+ );
+}
+
+test "callstack: CallstackDepth bounds the walk, its last row inviting a Callstack from a function above" {
+ var tmp = std.testing.tmpDir(.{});
+ defer tmp.cleanup();
+ var s = try Session.initLanguage(std.testing.allocator);
+ defer s.deinit();
+ const main = try openMain(&s, &tmp);
+ try s.write("/ctl", "CallstackDepth 1\n");
+ try s.write(s.at("/pane/{d}/ctl", .{main}), "Callstack\n");
+ try s.expect(s.at("/pane/{d}/body", .{try s.focused()}),
+ \\╰──┬ main.rs:3:4-7
+ \\ │ fn main() {
+ \\ ├─ main.rs:4:13-15
+ \\ │ let x = add(1, 2);
+ \\ ╰─ main.rs:5:13-15
+ \\ let y = add(3, 4);
+ \\… continue from a function above with Callstack
+ \\
+ );
+}