diff options
Diffstat (limited to 'core/Stream.zig')
| -rw-r--r-- | core/Stream.zig | 51 |
1 files changed, 49 insertions, 2 deletions
diff --git a/core/Stream.zig b/core/Stream.zig index 7956e4f2..7f9ad012 100644 --- a/core/Stream.zig +++ b/core/Stream.zig @@ -832,13 +832,13 @@ const Worker = struct { const ln = std.mem.trimEnd(u8, raw, " \t\r\n"); var cut = @min(ln.len, 400); while (cut > 0 and cut < ln.len and ln[cut] & 0xc0 == 0x80) cut -= 1; - try w.rows.print(w.gpa, "{s}:{d}:{d}{c}{d} {s}\n", .{ path, line, from + 1, config.range_sep, end, ln[0..cut] }); + try w.rows.print(w.gpa, "{f}:{d}:{d}{c}{d} {s}\n", .{ look.quoted(path), line, from + 1, config.range_sep, end, ln[0..cut] }); w.total += 1; } /// A listing's file: its name, relative to the base. fn file(w: *Worker, path: []const u8) !bool { - try w.rows.print(w.gpa, "{s}\n", .{path}); + try w.rows.print(w.gpa, "{f}\n", .{look.quoted(path)}); w.total += 1; try w.maybeSend(); return w.checkCap(); @@ -1275,6 +1275,53 @@ test "Stream: the listing of files for Find on a worker, a cap of hits stops the try testing.expectEqual(State.done, p.stream.state); } +test "Stream: a file named `a\\nb:1:1` is one Grep row and one Find name, its own, for the walk and rg; a row is a line" { + var tmp = testing.tmpDir(.{}); + defer tmp.cleanup(); + var root_buf: [4096]u8 = undefined; + // Up to 2026-11-23 its row, `a\nb:1:1:1:1-6 needle`, was two: `a` + // (no place) and a hit in a file `b`, line 1, that has none. + const odd = "a\nb:1:1"; + try tmp.dir.writeFile(testing.io, .{ .sub_path = odd, .data = "needle\n" }); + try tmp.dir.writeFile(testing.io, .{ .sub_path = "b", .data = "hay\n" }); + const root = root_buf[0..try tmp.dir.realPath(testing.io, &root_buf)]; + for ([_]Engine{ .walk, .rg }) |engine| { + const p = try Pardes.init(testing.allocator, .{ .tty_only = true, .cols = 120, .rows = 40 }); + defer p.deinit(); + const pane = try p.setTestFile("x\n"); + p.gpa.free(pane.file.?.path); + pane.file.?.path = try std.Io.Dir.path.join(p.gpa, &.{ root, "main.txt" }); + p.advance(1); + p.stream.engine = engine; + // No host workers: the search runs on the loop at the next tick. + panes.Query.open(p, 0, .grep, "", false); + const qp = for (p.panes) |slot| { + if (slot) |qp| if (qp.query != null) break qp; + } else return error.NoQueryPane; + const q = qp.query.?; + try query(p, qp.serial, .grep, "needle", root, .now); + p.update(.tick); + p.update(.tick); + if (engine == .rg and p.stream.used != .rg) return; // no rg here + try testing.expectEqual(@as(usize, 1), q.found.items.len); + const fd = q.found.items[0]; + try testing.expectEqualStrings(odd, q.found_bytes.items[fd.path..][0..fd.path_len]); + try testing.expectEqual(@as(u32, 1), fd.line); + // The pane's rows: a line each, its name's newline written `\n`. + const f = &qp.file.?; + try testing.expectEqual(std.mem.count(u8, f.content, "\n"), f.location_rows.len); + try testing.expect(std.mem.indexOf(u8, f.content, "\"a\\nb:1:1\"") != null); + // Find: the same name, once, opening that file. + panes.Query.open(p, 0, .find, "", false); + p.update(.tick); + p.update(.tick); + const fq = for (p.panes) |slot| { + if (slot) |fp| if (fp.query) |got| if (got.source == .find) break got; + } else return error.NoFindPane; + try testing.expectEqual(@as(usize, 2), fq.names.cands.items.len); + } +} + test "Stream: a big text's declarations are parsed on a worker, never the loop, and the rows of its / regroup under them" { if (comptime !syntax.minimal_grammars) return error.SkipZigTest; const p = try Pardes.init(testing.allocator, .{ .tty_only = true, .cols = 120, .rows = 40 }); |
