Skip to content

Commit 3b33870

Browse files
committed
ripgrep alignment
1 parent f43f106 commit 3b33870

File tree

8 files changed

+121
-124
lines changed

8 files changed

+121
-124
lines changed

src/commands/rg/imported-tests/binary.test.ts

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ describe("rg binary: basic detection", () => {
2727
expect(result.exitCode).toBe(0);
2828
// Should only find match in text file, not binary
2929
expect(result.stdout).toBe("text.txt:1:hello world\n");
30-
expect(result.stdout).not.toContain("binary.bin");
3130
});
3231

3332
it("should skip binary files when searching single explicit file", async () => {
@@ -64,7 +63,7 @@ describe("rg binary: basic detection", () => {
6463
});
6564
const result = await bash.exec("rg pattern");
6665
expect(result.exitCode).toBe(0);
67-
expect(result.stdout).toContain("pattern");
66+
expect(result.stdout).toBe("late.txt:1:pattern\n");
6867
});
6968
});
7069

@@ -108,11 +107,11 @@ describe("rg binary: mixed content", () => {
108107
"/home/user/script.sh": "echo documentation\n",
109108
},
110109
});
111-
const result = await bash.exec("rg documentation");
110+
const result = await bash.exec("rg --sort path documentation");
112111
expect(result.exitCode).toBe(0);
113-
expect(result.stdout).toContain("readme.md");
114-
expect(result.stdout).toContain("script.sh");
115-
expect(result.stdout).not.toContain("image.png");
112+
expect(result.stdout).toBe(
113+
"readme.md:1:documentation\nscript.sh:1:echo documentation\n",
114+
);
116115
});
117116

118117
it("should handle multiple binary and text files", async () => {
@@ -248,10 +247,7 @@ describe("rg binary: with other flags", () => {
248247
});
249248
const result = await bash.exec("rg -C1 match");
250249
expect(result.exitCode).toBe(0);
251-
expect(result.stdout).toContain("before");
252-
expect(result.stdout).toContain("match");
253-
expect(result.stdout).toContain("after");
254-
expect(result.stdout).not.toContain("binary.bin");
250+
expect(result.stdout).toBe("text.txt-1-before\ntext.txt:2:match\ntext.txt-3-after\n");
255251
});
256252

257253
it("should work with -m flag", async () => {
@@ -278,10 +274,10 @@ describe("rg binary: subdirectories", () => {
278274
"/home/user/lib/util.ts": "export function foo() {}\n",
279275
},
280276
});
281-
const result = await bash.exec("rg export");
277+
const result = await bash.exec("rg --sort path export");
282278
expect(result.exitCode).toBe(0);
283-
expect(result.stdout).toContain("src/code.ts");
284-
expect(result.stdout).toContain("lib/util.ts");
285-
expect(result.stdout).not.toContain("assets/image.bin");
279+
expect(result.stdout).toBe(
280+
"lib/util.ts:1:export function foo() {}\nsrc/code.ts:1:export const x = 1;\n",
281+
);
286282
});
287283
});

src/commands/rg/imported-tests/feature.test.ts

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -263,8 +263,7 @@ describe("rg feature: multiple patterns", () => {
263263
});
264264
const result = await bash.exec("rg -e foo -e bar");
265265
expect(result.exitCode).toBe(0);
266-
expect(result.stdout).toContain("foo");
267-
expect(result.stdout).toContain("bar");
266+
expect(result.stdout).toBe("file:1:foo\nfile:2:bar\n");
268267
});
269268
});
270269

@@ -292,10 +291,9 @@ describe("rg feature: gitignore handling", () => {
292291
"/home/user/ignored.txt": "test\n",
293292
},
294293
});
295-
const result = await bash.exec("rg --no-ignore test");
294+
const result = await bash.exec("rg --no-ignore --sort path test");
296295
expect(result.exitCode).toBe(0);
297-
expect(result.stdout).toContain("visible.txt");
298-
expect(result.stdout).toContain("ignored.txt");
296+
expect(result.stdout).toBe("ignored.txt:1:test\nvisible.txt:1:test\n");
299297
});
300298
});
301299

@@ -321,10 +319,9 @@ describe("rg feature: hidden files", () => {
321319
"/home/user/visible": "test\n",
322320
},
323321
});
324-
const result = await bash.exec("rg --hidden test");
322+
const result = await bash.exec("rg --hidden --sort path test");
325323
expect(result.exitCode).toBe(0);
326-
expect(result.stdout).toContain(".hidden");
327-
expect(result.stdout).toContain("visible");
324+
expect(result.stdout).toBe(".hidden:1:test\nvisible:1:test\n");
328325
});
329326
});
330327

@@ -550,7 +547,7 @@ describe("rg feature: combined flags", () => {
550547
});
551548
const result = await bash.exec("rg -iw foo");
552549
expect(result.exitCode).toBe(0);
553-
expect(result.stdout).toContain("FOO");
550+
expect(result.stdout).toBe("file:1:FOO foobar\n");
554551
});
555552

556553
it("should combine -c and -i", async () => {

src/commands/rg/imported-tests/regression.test.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -377,10 +377,9 @@ describe("rg regression: issue #693 - context in count mode", () => {
377377
"/home/user/foo": "xyz\n",
378378
},
379379
});
380-
const result = await bash.exec("rg -C1 -c xyz");
380+
const result = await bash.exec("rg -C1 -c --sort path xyz");
381381
expect(result.exitCode).toBe(0);
382-
expect(result.stdout).toContain("bar:1");
383-
expect(result.stdout).toContain("foo:1");
382+
expect(result.stdout).toBe("bar:1\nfoo:1\n");
384383
});
385384
});
386385

@@ -410,9 +409,7 @@ describe("rg regression: misc patterns", () => {
410409
});
411410
const result = await bash.exec("rg '[a-z]+@[a-z]+\\.[a-z]+' email.txt");
412411
expect(result.exitCode).toBe(0);
413-
expect(result.stdout).toContain("test@example.com");
414-
expect(result.stdout).toContain("foo@bar.org");
415-
expect(result.stdout).not.toContain("invalid\n");
412+
expect(result.stdout).toBe("test@example.com\nfoo@bar.org\n");
416413
});
417414

418415
it("should match multiple patterns on same line", async () => {
@@ -450,7 +447,6 @@ describe("rg regression: edge cases", () => {
450447
});
451448
const result = await bash.exec("rg -e foo -e bar");
452449
expect(result.exitCode).toBe(0);
453-
expect(result.stdout).toContain("foo");
454-
expect(result.stdout).toContain("bar");
450+
expect(result.stdout).toBe("file:1:foo\nfile:2:bar\n");
455451
});
456452
});

src/commands/rg/rg-search.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,7 @@ async function searchFiles(
547547
maxCount: options.maxCount,
548548
contextSeparator: options.contextSeparator,
549549
showColumn: options.column,
550+
vimgrep: options.vimgrep,
550551
showByteOffset: options.byteOffset,
551552
replace: options.replace,
552553
passthru: options.passthru,

src/commands/rg/rg.flags.test.ts

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ describe("rg -L (follow symlinks)", () => {
4444
const result = await bash.exec("rg hello");
4545
expect(result.exitCode).toBe(0);
4646
expect(result.stdout).toBe("real.txt:1:hello\n");
47-
expect(result.stdout).not.toContain("link.txt");
4847
});
4948

5049
it("should follow symlinks with -L in directory search", async () => {
@@ -56,10 +55,9 @@ describe("rg -L (follow symlinks)", () => {
5655
});
5756
await bash.exec("ln -s real.txt /home/user/link.txt");
5857

59-
const result = await bash.exec("rg -L hello");
58+
const result = await bash.exec("rg -L --sort path hello");
6059
expect(result.exitCode).toBe(0);
61-
expect(result.stdout).toContain("real.txt");
62-
expect(result.stdout).toContain("link.txt");
60+
expect(result.stdout).toBe("link.txt:1:hello\nreal.txt:1:hello\n");
6361
});
6462

6563
it("should follow symlinks to directories with -L", async () => {
@@ -77,10 +75,11 @@ describe("rg -L (follow symlinks)", () => {
7775
expect(result.stdout).toBe("subdir/file.txt:1:hello\n");
7876

7977
// With -L, should find file through both paths
80-
result = await bash.exec("rg -L hello");
78+
result = await bash.exec("rg -L --sort path hello");
8179
expect(result.exitCode).toBe(0);
82-
expect(result.stdout).toContain("subdir/file.txt");
83-
expect(result.stdout).toContain("linkdir/file.txt");
80+
expect(result.stdout).toBe(
81+
"linkdir/file.txt:1:hello\nsubdir/file.txt:1:hello\n",
82+
);
8483
});
8584
});
8685

@@ -99,9 +98,8 @@ describe("rg -u (unrestricted)", () => {
9998
expect(result.stdout).toBe("visible.txt:1:hello\n");
10099

101100
// With -u, ignored.txt should be searched
102-
result = await bash.exec("rg -u hello");
103-
expect(result.stdout).toContain("ignored.txt");
104-
expect(result.stdout).toContain("visible.txt");
101+
result = await bash.exec("rg -u --sort path hello");
102+
expect(result.stdout).toBe("ignored.txt:1:hello\nvisible.txt:1:hello\n");
105103
});
106104

107105
it("should search hidden files with -uu", async () => {
@@ -117,9 +115,8 @@ describe("rg -u (unrestricted)", () => {
117115
expect(result.stdout).toBe("visible.txt:1:hello\n");
118116

119117
// With -uu (--no-ignore --hidden), .hidden should be searched
120-
result = await bash.exec("rg -uu hello");
121-
expect(result.stdout).toContain(".hidden");
122-
expect(result.stdout).toContain("visible.txt");
118+
result = await bash.exec("rg -uu --sort path hello");
119+
expect(result.stdout).toBe(".hidden:1:hello\nvisible.txt:1:hello\n");
123120
});
124121

125122
it("-u should be equivalent to --no-ignore", async () => {
@@ -164,6 +161,6 @@ describe("rg -a (text/binary)", () => {
164161
// With -a, binary should be searched
165162
result = await bash.exec("rg -a hello");
166163
expect(result.exitCode).toBe(0);
167-
expect(result.stdout).toContain("binary.bin");
164+
expect(result.stdout).toBe("binary.bin:1:hello\x00world\n");
168165
});
169166
});

src/commands/rg/rg.no-filename.test.ts

Lines changed: 7 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ describe("rg -I/--no-filename basic functionality", () => {
1717
const result = await bash.exec("rg -I hello");
1818
expect(result.exitCode).toBe(0);
1919
expect(result.stdout).toBe("1:hello world\n");
20-
expect(result.stdout).not.toContain("file.txt");
2120
});
2221

2322
it("should hide filename with --no-filename in directory search", async () => {
@@ -30,7 +29,6 @@ describe("rg -I/--no-filename basic functionality", () => {
3029
const result = await bash.exec("rg --no-filename test");
3130
expect(result.exitCode).toBe(0);
3231
expect(result.stdout).toBe("1:test line\n");
33-
expect(result.stdout).not.toContain("data.txt");
3432
});
3533

3634
it("should work without line numbers when combined with -N", async () => {
@@ -56,7 +54,6 @@ describe("rg -I/--no-filename basic functionality", () => {
5654
const result = await bash.exec("rg -I foo test.txt");
5755
expect(result.exitCode).toBe(0);
5856
expect(result.stdout).toBe("foo bar\n");
59-
expect(result.stdout).not.toContain("test.txt");
6057
});
6158
});
6259

@@ -73,9 +70,6 @@ describe("rg -I with multiple files", () => {
7370
const result = await bash.exec("rg -I found");
7471
expect(result.exitCode).toBe(0);
7572
expect(result.stdout).toBe("1:found\n1:found\n1:found\n");
76-
expect(result.stdout).not.toContain("a.txt");
77-
expect(result.stdout).not.toContain("b.txt");
78-
expect(result.stdout).not.toContain("c.txt");
7973
});
8074

8175
it("should still show line numbers with multiple files", async () => {
@@ -86,12 +80,9 @@ describe("rg -I with multiple files", () => {
8680
"/home/user/second.txt": "line three\n",
8781
},
8882
});
89-
const result = await bash.exec("rg -I line");
83+
const result = await bash.exec("rg -I --sort path line");
9084
expect(result.exitCode).toBe(0);
91-
expect(result.stdout).toContain("1:");
92-
expect(result.stdout).toContain("2:");
93-
expect(result.stdout).not.toContain("first.txt");
94-
expect(result.stdout).not.toContain("second.txt");
85+
expect(result.stdout).toBe("1:line one\n2:line two\n1:line three\n");
9586
});
9687

9788
it("should hide filenames in subdirectories", async () => {
@@ -107,10 +98,6 @@ describe("rg -I with multiple files", () => {
10798
expect(result.stdout).toBe(
10899
"1:export const y = 2;\n1:export const x = 1;\n",
109100
);
110-
expect(result.stdout).not.toContain("app.ts");
111-
expect(result.stdout).not.toContain("util.ts");
112-
expect(result.stdout).not.toContain("src/");
113-
expect(result.stdout).not.toContain("lib/");
114101
});
115102
});
116103

@@ -139,8 +126,6 @@ describe("rg -I with other flags", () => {
139126
const result = await bash.exec("rg -I -c x");
140127
expect(result.exitCode).toBe(0);
141128
expect(result.stdout).toBe("2\n3\n");
142-
expect(result.stdout).not.toContain("a.txt");
143-
expect(result.stdout).not.toContain("b.txt");
144129
});
145130

146131
it("should work with -o (only matching)", async () => {
@@ -153,7 +138,6 @@ describe("rg -I with other flags", () => {
153138
const result = await bash.exec("rg -I -o '[0-9]+'");
154139
expect(result.exitCode).toBe(0);
155140
expect(result.stdout).toBe("123\n456\n");
156-
expect(result.stdout).not.toContain("nums.txt");
157141
});
158142

159143
it("should work with -v (invert match)", async () => {
@@ -166,7 +150,6 @@ describe("rg -I with other flags", () => {
166150
const result = await bash.exec("rg -I -v remove");
167151
expect(result.exitCode).toBe(0);
168152
expect(result.stdout).toBe("1:keep\n3:keep\n");
169-
expect(result.stdout).not.toContain("file.txt");
170153
});
171154

172155
it("should work with -i (case insensitive)", async () => {
@@ -179,7 +162,6 @@ describe("rg -I with other flags", () => {
179162
const result = await bash.exec("rg -I -i hello");
180163
expect(result.exitCode).toBe(0);
181164
expect(result.stdout).toBe("1:Hello\n2:HELLO\n3:hello\n");
182-
expect(result.stdout).not.toContain("file.txt");
183165
});
184166

185167
it("should work with -w (word match)", async () => {
@@ -192,7 +174,6 @@ describe("rg -I with other flags", () => {
192174
const result = await bash.exec("rg -I -w foo");
193175
expect(result.exitCode).toBe(0);
194176
expect(result.stdout).toBe("1:foo bar\n3:bar foo baz\n");
195-
expect(result.stdout).not.toContain("file.txt");
196177
});
197178

198179
it("should work with -m (max count)", async () => {
@@ -205,7 +186,6 @@ describe("rg -I with other flags", () => {
205186
const result = await bash.exec("rg -I -m2 test");
206187
expect(result.exitCode).toBe(0);
207188
expect(result.stdout).toBe("1:test\n2:test\n");
208-
expect(result.stdout).not.toContain("file.txt");
209189
});
210190

211191
it("should NOT affect -l (files with matches)", async () => {
@@ -249,7 +229,6 @@ describe("rg -I with context lines", () => {
249229
const result = await bash.exec("rg -I -A1 match");
250230
expect(result.exitCode).toBe(0);
251231
expect(result.stdout).toBe("2:match\n3-after\n");
252-
expect(result.stdout).not.toContain("file.txt");
253232
});
254233

255234
it("should hide filename with -B (before context)", async () => {
@@ -262,7 +241,6 @@ describe("rg -I with context lines", () => {
262241
const result = await bash.exec("rg -I -B1 match");
263242
expect(result.exitCode).toBe(0);
264243
expect(result.stdout).toBe("1-before\n2:match\n");
265-
expect(result.stdout).not.toContain("file.txt");
266244
});
267245

268246
it("should hide filename with -C (context)", async () => {
@@ -275,7 +253,6 @@ describe("rg -I with context lines", () => {
275253
const result = await bash.exec("rg -I -C1 match");
276254
expect(result.exitCode).toBe(0);
277255
expect(result.stdout).toBe("2-b\n3:match\n4-c\n");
278-
expect(result.stdout).not.toContain("file.txt");
279256
});
280257

281258
it("should hide filename in context across multiple files", async () => {
@@ -286,11 +263,12 @@ describe("rg -I with context lines", () => {
286263
"/home/user/b.txt": "ctx\nmatch\nctx\n",
287264
},
288265
});
289-
const result = await bash.exec("rg -I -C1 match");
266+
const result = await bash.exec("rg -I -C1 --sort path match");
290267
expect(result.exitCode).toBe(0);
291-
expect(result.stdout).not.toContain("a.txt");
292-
expect(result.stdout).not.toContain("b.txt");
293-
expect(result.stdout).toContain("match");
268+
// No separator between files when -I is used since there's no filename prefix
269+
expect(result.stdout).toBe(
270+
"1-ctx\n2:match\n3-ctx\n1-ctx\n2:match\n3-ctx\n",
271+
);
294272
});
295273
});
296274

@@ -306,7 +284,6 @@ describe("rg -I with file filters", () => {
306284
const result = await bash.exec("rg -I -t js const");
307285
expect(result.exitCode).toBe(0);
308286
expect(result.stdout).toBe("1:const x = 1;\n");
309-
expect(result.stdout).not.toContain("code.js");
310287
});
311288

312289
it("should work with -g (glob filter)", async () => {
@@ -320,7 +297,6 @@ describe("rg -I with file filters", () => {
320297
const result = await bash.exec("rg -I -g '*.log' error");
321298
expect(result.exitCode).toBe(0);
322299
expect(result.stdout).toBe("1:error occurred\n");
323-
expect(result.stdout).not.toContain("test.log");
324300
});
325301
});
326302

@@ -359,7 +335,6 @@ describe("rg -I edge cases", () => {
359335
const result = await bash.exec("rg -I --hidden secret");
360336
expect(result.exitCode).toBe(0);
361337
expect(result.stdout).toBe("1:secret\n");
362-
expect(result.stdout).not.toContain(".hidden");
363338
});
364339

365340
it("should work combined with other short flags", async () => {
@@ -373,7 +348,6 @@ describe("rg -I edge cases", () => {
373348
const result = await bash.exec("rg -Iin test");
374349
expect(result.exitCode).toBe(0);
375350
expect(result.stdout).toBe("1:Test\n2:test\n3:TEST\n");
376-
expect(result.stdout).not.toContain("file.txt");
377351
});
378352

379353
it("should output just line numbers with -In", async () => {

0 commit comments

Comments
 (0)