From 5157579ff7f9ae0cfc3c7629e953da05bce340fc Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Mon, 9 Nov 2026 00:52:52 -0300 Subject: tests: at the end of their files: every top-level test block of the 46 files that had one mid-file (the locality analysis's 45 and test/hxdiff.zig; gui.zig, macos.zig, look, host_io, 9p_io, terminal, tui, mouse, fs, replica, layout among them, 11,429 test lines), with the functions only tests call, moved after the file's code in their order, a mechanical move (.scratch/suites/tests_to_end.py), zig fmt'd; the unit suites pass as before (tui 1486/1487, gui 1536/1537, core 956/956 on both), macos.zig only parse-checked here Co-Authored-By: Claude Fable 5.1 Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge --- src/Output.zig | 256 ++++++++++++++++++++++++++++----------------------------- 1 file changed, 128 insertions(+), 128 deletions(-) (limited to 'src/Output.zig') diff --git a/src/Output.zig b/src/Output.zig index f1ce7ab9..0161878e 100644 --- a/src/Output.zig +++ b/src/Output.zig @@ -144,103 +144,6 @@ pub fn decorateRow(output: ?State, line: []const u8, metadata: ?locations.Row) R return row; } -test "callstack guides and Look locations share result decoration" { - const from: State = .{ .from = .{ .query = .callstack } }; - const loc = decorateRow(from, "╰──┬ lib.rs:2:8-10 fn add() {", null); - try std.testing.expectEqual(@as(usize, "╰──┬ lib.rs:2:8-10".len), loc.location_end); - try std.testing.expect(!loc.declaration); - try std.testing.expect(!usesLocationsConfig(from.from)); - try std.testing.expect(!traits(from.from).jumps); - const call_line = " lib.rs:12:12-20 return calculate(value);"; - const call = decorateRow(from, call_line, null); - try std.testing.expectEqualStrings("calculate", call_line[call.mark_start..call.mark_end]); - const reference = decorateRow(.{ .from = .{ .query = .references } }, call_line[4..], null); - try std.testing.expectEqual(reference.mark_start + 4, call.mark_start); - try std.testing.expectEqual(reference.mark_end + 4, call.mark_end); - try std.testing.expectEqual(reference.location_end + 4, call.location_end); - const tab_line = " tab.zig:4:9-11 \treturn run();"; - const tab_call = decorateRow(from, tab_line, null); - try std.testing.expectEqualStrings("run", tab_line[tab_call.mark_start..tab_call.mark_end]); -} - -test "result decoration follows source byte ranges and diagnostic provenance" { - const row = decorateRow(.{ .from = .search }, "src/a.rs:3:5-7 let abc = 1;", null); - try std.testing.expectEqualStrings("abc", "src/a.rs:3:5-7 let abc = 1;"[row.mark_start..row.mark_end]); - const prose = decorateRow(.{ .from = .{ .query = .hover } }, "src/a.rs:3:5-7 error: prose", null); - try std.testing.expectEqual(@as(usize, 0), prose.mark_end); - const diagnostic = decorateRow(.{ .from = .{ .query = .diagnostics } }, "src/a.rs:3:5-7 warning: unused", null); - try std.testing.expectEqual(.warning, diagnostic.severity); - try std.testing.expectEqualStrings("warning:", "src/a.rs:3:5-7 warning: unused"[diagnostic.mark_start..diagnostic.mark_end]); - const malformed = decorateRow(.{ .from = .search }, "src/a.rs:3:99999999999999999999-99999999999999999999 text", null); - try std.testing.expect(malformed.mark_end <= "src/a.rs:3:99999999999999999999-99999999999999999999 text".len); - const snippet = "src/a.rs:3:14-16 \t\tfoo + 界 + foo"; - for ([_]lsp.Kind{ .definition, .declaration, .type_definition, .implementation, .references }) |kind| { - const occurrence = decorateRow(.{ .from = .{ .query = kind } }, snippet, null); - try std.testing.expectEqualStrings("foo", snippet[occurrence.mark_start..occurrence.mark_end]); - } - for ([_]lsp.Kind{ .document_symbols, .workspace_symbols, .completion, .incoming_calls, .outgoing_calls, .supertypes, .subtypes, .rename }) |kind| { - const label = decorateRow(.{ .from = .{ .query = kind } }, snippet, null); - try std.testing.expectEqual(@as(usize, 0), label.mark_end); - } -} - -test "stacked empty previews distinguish separators from trailing newlines" { - var path = [_]u8{ 'x', '.', 'c' }; - const rows = [_]locations.Row{ - .{ .kind = .match, .path = &path, .at = .{ .line = 1, .col = 1 }, .location_end = 7, .code_start = 7 }, - .{ .kind = .preview, .path = &path, .at = .{ .line = 1, .col = 1 }, .location_end = 0, .code_start = 0 }, - }; - try std.testing.expect(locations.sameInput("x.c:1:1 ", "x.c:1:1\n", &rows, .stacked)); - try std.testing.expect(locations.sameInput("x.c:1:1 \n", "x.c:1:1\n\n", &rows, .stacked)); - try std.testing.expect(!locations.sameInput("x.c:1:1 ", "x.c:1:1\n\n", &rows, .stacked)); - try std.testing.expect(!locations.sameInput("x.c:1:1 \n", "x.c:1:1\n", &rows, .stacked)); -} - -test "two words looked for in a terminal share the directory's one +Search" { - const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true }); - defer p.deinit(); - const term = for (p.panes, 0..) |slot, id| { - if (slot) |pane| if (pane.isTerminal()) break id; - } else return error.SkipZigTest; - p.word_look = true; - defer p.word_look = false; - try fillResults(p, term, "/work", .search, "foo", try p.gpa.dupe(u8, "a.txt:1:1 foo\n"), null); - try fillResults(p, term, "/work", .search, "bar", try p.gpa.dupe(u8, "a.txt:2:1 bar\n"), null); - var searches: usize = 0; - for (p.panes) |slot| { - const f = (slot orelse continue).file orelse continue; - searches += @intFromBool(std.mem.eql(u8, f.path, "/work/+Search")); - } - try std.testing.expectEqual(@as(usize, 1), searches); -} - -test "Lspinfo and Lspwhy fill one +Lsp in a directory" { - const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true }); - defer p.deinit(); - _ = try p.setTestFile("x\n"); - try fillResults(p, 0, "/work", .{ .query = .status }, "", try p.gpa.dupe(u8, "servers\n"), null); - try fillResults(p, 0, "/work", .{ .query = .explain }, "", try p.gpa.dupe(u8, "why\n"), null); - var lsp_panes: usize = 0; - for (p.panes) |slot| { - const f = (slot orelse continue).file orelse continue; - if (std.mem.eql(u8, f.path, "/work/+Lsp")) { - lsp_panes += 1; - try std.testing.expectEqualStrings("why\n", f.content); - } - } - try std.testing.expectEqual(@as(usize, 1), lsp_panes); -} - -test "plain output does not opt into location decoration" { - const report = decorateRow(.{ .from = .{ .cmd = .LocationsConfig } }, "LocationsConfig context:5 tscontext:on", null); - try std.testing.expectEqualDeep(RowDecoration{}, report); - const prose = decorateRow(.{ .from = .{ .query = .hover } }, "src/a.rs:3:5-7 error: prose", null); - try std.testing.expectEqualDeep(RowDecoration{}, prose); - const errors = decorateRow(.{ .from = .errors }, "src/a.rs:3:5-7 error: prose", null); - try std.testing.expectEqualDeep(RowDecoration{}, errors); - try std.testing.expect(traits(.{ .query = .completion }).locations); -} - pub fn setArg(o: *State, text: []const u8) error{ArgumentTooLong}!void { if (text.len > max_arg) return error.ArgumentTooLong; o.arg_len = @intCast(text.len); @@ -950,37 +853,6 @@ pub fn openHelp(p: *Pardes, id: usize, prefix: []const u8) !void { return openRead(p, id, .{ .cmd = .Help }, prefix, content); } -test "full Help renders builtin rows, a call hierarchy guide, then language keys" { - const core = try Pardes.init(std.testing.allocator, .{ .tty_only = true }); - defer core.deinit(); - const content = try helpContent(core, std.testing.allocator, ""); - defer std.testing.allocator.free(content); - - // FIRST blank line: the end of the header (the footer opens with one too) - const body = content[(std.mem.indexOf(u8, content, "\n\n") orelse - return error.MissingHelpHeader) + 2 ..]; - var lines = std.mem.splitScalar(u8, body, '\n'); - for (pardes.builtin_rows) |row| if (builtins.registry.here(core, row.cmd)) - try std.testing.expectEqualStrings(row.line, lines.next() orelse - return error.MissingBuiltinHelpRow); - // The short call guide disambiguates the three related commands. - try std.testing.expectEqualStrings("", lines.next() orelse return error.MissingCallHelp); - try std.testing.expectEqualStrings("Callstack: static caller chains,", lines.next() orelse return error.MissingCallHelp); - try std.testing.expectEqualStrings("with signatures and clickable call sites.", lines.next() orelse return error.MissingCallHelp); - try std.testing.expectEqualStrings("Callers / Callees: one direction at a time.", lines.next() orelse return error.MissingCallHelp); - // The language keys close the page. - try std.testing.expectEqualStrings("", lines.next() orelse - return error.MissingLanguageKeys); - try std.testing.expectEqualStrings("language keys (motions, not words):", lines.next() orelse - return error.MissingLanguageKeys); - try std.testing.expect(std.mem.indexOf(u8, body, "\ngd gD gy gi gr goto: definition,\n") != null); - // The language group also explains call commands, without the motion footer. - const group = try helpContent(core, std.testing.allocator, "l"); - defer std.testing.allocator.free(group); - try std.testing.expect(std.mem.indexOf(u8, group, "language keys") == null); - try std.testing.expect(std.mem.indexOf(u8, group, "Callstack: static caller chains") != null); -} - /// Where a dump goes by default, as the session's environment says (the /// authority's, `tape.authority`): in `buf`. fn dumpDirectory(buf: []u8) []const u8 { @@ -1118,3 +990,131 @@ fn openRead(p: *Pardes, id: usize, from: Origin, arg: []const u8, content: []u8) exec.placeNew(p, id, id, free, if (from == .errors) .errors else .doc); p.view().active = free; } + +test "callstack guides and Look locations share result decoration" { + const from: State = .{ .from = .{ .query = .callstack } }; + const loc = decorateRow(from, "╰──┬ lib.rs:2:8-10 fn add() {", null); + try std.testing.expectEqual(@as(usize, "╰──┬ lib.rs:2:8-10".len), loc.location_end); + try std.testing.expect(!loc.declaration); + try std.testing.expect(!usesLocationsConfig(from.from)); + try std.testing.expect(!traits(from.from).jumps); + const call_line = " lib.rs:12:12-20 return calculate(value);"; + const call = decorateRow(from, call_line, null); + try std.testing.expectEqualStrings("calculate", call_line[call.mark_start..call.mark_end]); + const reference = decorateRow(.{ .from = .{ .query = .references } }, call_line[4..], null); + try std.testing.expectEqual(reference.mark_start + 4, call.mark_start); + try std.testing.expectEqual(reference.mark_end + 4, call.mark_end); + try std.testing.expectEqual(reference.location_end + 4, call.location_end); + const tab_line = " tab.zig:4:9-11 \treturn run();"; + const tab_call = decorateRow(from, tab_line, null); + try std.testing.expectEqualStrings("run", tab_line[tab_call.mark_start..tab_call.mark_end]); +} + +test "result decoration follows source byte ranges and diagnostic provenance" { + const row = decorateRow(.{ .from = .search }, "src/a.rs:3:5-7 let abc = 1;", null); + try std.testing.expectEqualStrings("abc", "src/a.rs:3:5-7 let abc = 1;"[row.mark_start..row.mark_end]); + const prose = decorateRow(.{ .from = .{ .query = .hover } }, "src/a.rs:3:5-7 error: prose", null); + try std.testing.expectEqual(@as(usize, 0), prose.mark_end); + const diagnostic = decorateRow(.{ .from = .{ .query = .diagnostics } }, "src/a.rs:3:5-7 warning: unused", null); + try std.testing.expectEqual(.warning, diagnostic.severity); + try std.testing.expectEqualStrings("warning:", "src/a.rs:3:5-7 warning: unused"[diagnostic.mark_start..diagnostic.mark_end]); + const malformed = decorateRow(.{ .from = .search }, "src/a.rs:3:99999999999999999999-99999999999999999999 text", null); + try std.testing.expect(malformed.mark_end <= "src/a.rs:3:99999999999999999999-99999999999999999999 text".len); + const snippet = "src/a.rs:3:14-16 \t\tfoo + 界 + foo"; + for ([_]lsp.Kind{ .definition, .declaration, .type_definition, .implementation, .references }) |kind| { + const occurrence = decorateRow(.{ .from = .{ .query = kind } }, snippet, null); + try std.testing.expectEqualStrings("foo", snippet[occurrence.mark_start..occurrence.mark_end]); + } + for ([_]lsp.Kind{ .document_symbols, .workspace_symbols, .completion, .incoming_calls, .outgoing_calls, .supertypes, .subtypes, .rename }) |kind| { + const label = decorateRow(.{ .from = .{ .query = kind } }, snippet, null); + try std.testing.expectEqual(@as(usize, 0), label.mark_end); + } +} + +test "stacked empty previews distinguish separators from trailing newlines" { + var path = [_]u8{ 'x', '.', 'c' }; + const rows = [_]locations.Row{ + .{ .kind = .match, .path = &path, .at = .{ .line = 1, .col = 1 }, .location_end = 7, .code_start = 7 }, + .{ .kind = .preview, .path = &path, .at = .{ .line = 1, .col = 1 }, .location_end = 0, .code_start = 0 }, + }; + try std.testing.expect(locations.sameInput("x.c:1:1 ", "x.c:1:1\n", &rows, .stacked)); + try std.testing.expect(locations.sameInput("x.c:1:1 \n", "x.c:1:1\n\n", &rows, .stacked)); + try std.testing.expect(!locations.sameInput("x.c:1:1 ", "x.c:1:1\n\n", &rows, .stacked)); + try std.testing.expect(!locations.sameInput("x.c:1:1 \n", "x.c:1:1\n", &rows, .stacked)); +} + +test "two words looked for in a terminal share the directory's one +Search" { + const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true }); + defer p.deinit(); + const term = for (p.panes, 0..) |slot, id| { + if (slot) |pane| if (pane.isTerminal()) break id; + } else return error.SkipZigTest; + p.word_look = true; + defer p.word_look = false; + try fillResults(p, term, "/work", .search, "foo", try p.gpa.dupe(u8, "a.txt:1:1 foo\n"), null); + try fillResults(p, term, "/work", .search, "bar", try p.gpa.dupe(u8, "a.txt:2:1 bar\n"), null); + var searches: usize = 0; + for (p.panes) |slot| { + const f = (slot orelse continue).file orelse continue; + searches += @intFromBool(std.mem.eql(u8, f.path, "/work/+Search")); + } + try std.testing.expectEqual(@as(usize, 1), searches); +} + +test "Lspinfo and Lspwhy fill one +Lsp in a directory" { + const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true }); + defer p.deinit(); + _ = try p.setTestFile("x\n"); + try fillResults(p, 0, "/work", .{ .query = .status }, "", try p.gpa.dupe(u8, "servers\n"), null); + try fillResults(p, 0, "/work", .{ .query = .explain }, "", try p.gpa.dupe(u8, "why\n"), null); + var lsp_panes: usize = 0; + for (p.panes) |slot| { + const f = (slot orelse continue).file orelse continue; + if (std.mem.eql(u8, f.path, "/work/+Lsp")) { + lsp_panes += 1; + try std.testing.expectEqualStrings("why\n", f.content); + } + } + try std.testing.expectEqual(@as(usize, 1), lsp_panes); +} + +test "plain output does not opt into location decoration" { + const report = decorateRow(.{ .from = .{ .cmd = .LocationsConfig } }, "LocationsConfig context:5 tscontext:on", null); + try std.testing.expectEqualDeep(RowDecoration{}, report); + const prose = decorateRow(.{ .from = .{ .query = .hover } }, "src/a.rs:3:5-7 error: prose", null); + try std.testing.expectEqualDeep(RowDecoration{}, prose); + const errors = decorateRow(.{ .from = .errors }, "src/a.rs:3:5-7 error: prose", null); + try std.testing.expectEqualDeep(RowDecoration{}, errors); + try std.testing.expect(traits(.{ .query = .completion }).locations); +} + +test "full Help renders builtin rows, a call hierarchy guide, then language keys" { + const core = try Pardes.init(std.testing.allocator, .{ .tty_only = true }); + defer core.deinit(); + const content = try helpContent(core, std.testing.allocator, ""); + defer std.testing.allocator.free(content); + + // FIRST blank line: the end of the header (the footer opens with one too) + const body = content[(std.mem.indexOf(u8, content, "\n\n") orelse + return error.MissingHelpHeader) + 2 ..]; + var lines = std.mem.splitScalar(u8, body, '\n'); + for (pardes.builtin_rows) |row| if (builtins.registry.here(core, row.cmd)) + try std.testing.expectEqualStrings(row.line, lines.next() orelse + return error.MissingBuiltinHelpRow); + // The short call guide disambiguates the three related commands. + try std.testing.expectEqualStrings("", lines.next() orelse return error.MissingCallHelp); + try std.testing.expectEqualStrings("Callstack: static caller chains,", lines.next() orelse return error.MissingCallHelp); + try std.testing.expectEqualStrings("with signatures and clickable call sites.", lines.next() orelse return error.MissingCallHelp); + try std.testing.expectEqualStrings("Callers / Callees: one direction at a time.", lines.next() orelse return error.MissingCallHelp); + // The language keys close the page. + try std.testing.expectEqualStrings("", lines.next() orelse + return error.MissingLanguageKeys); + try std.testing.expectEqualStrings("language keys (motions, not words):", lines.next() orelse + return error.MissingLanguageKeys); + try std.testing.expect(std.mem.indexOf(u8, body, "\ngd gD gy gi gr goto: definition,\n") != null); + // The language group also explains call commands, without the motion footer. + const group = try helpContent(core, std.testing.allocator, "l"); + defer std.testing.allocator.free(group); + try std.testing.expect(std.mem.indexOf(u8, group, "language keys") == null); + try std.testing.expect(std.mem.indexOf(u8, group, "Callstack: static caller chains") != null); +} -- cgit v1.3