summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorAndrew Gallant <jamslam@gmail.com>2021-05-30 21:36:35 -0400
committerAndrew Gallant <jamslam@gmail.com>2021-05-31 21:51:18 -0400
commitfc31aedcf3cae7a773c94a79775396759af10dd8 (patch)
tree71627aaa0397f1165e2ce214745df6dda2f99ce0 /tests
parent578e1992fa21d3612d3e613d8869dbbb16e33cbe (diff)
printer: vimgrep now only prints one line
It turns out that the vimgrep format really only wants one line per match, even when that match spans multiple lines. We continue to support the previous behavior (print all lines in a match) in the `grep-printer` crate. We add a new option to enable the "only print the first line" behavior, and unconditionally enable it in ripgrep. We can do that because the option has no effect in single-line mode, since, well, in that case matches are guaranteed to span one line anyway. Fixes #1866
Diffstat (limited to 'tests')
-rw-r--r--tests/multiline.rs6
-rw-r--r--tests/regression.rs6
2 files changed, 9 insertions, 3 deletions
diff --git a/tests/multiline.rs b/tests/multiline.rs
index eb9cb4d5..d084c96b 100644
--- a/tests/multiline.rs
+++ b/tests/multiline.rs
@@ -64,6 +64,11 @@ rgtest!(only_matching, |dir: Dir, mut cmd: TestCommand| {
});
// Tests that --vimgrep works in multiline mode.
+//
+// In particular, we test that only the first line of each match is printed,
+// even when a match spans multiple lines.
+//
+// See: https://github.com/BurntSushi/ripgrep/issues/1866
rgtest!(vimgrep, |dir: Dir, mut cmd: TestCommand| {
dir.create("sherlock", SHERLOCK);
cmd.args(&[
@@ -77,7 +82,6 @@ rgtest!(vimgrep, |dir: Dir, mut cmd: TestCommand| {
let expected = "\
sherlock:1:16:For the Doctor Watsons of this world, as opposed to the Sherlock
sherlock:1:57:For the Doctor Watsons of this world, as opposed to the Sherlock
-sherlock:2:1:Holmeses, success in the province of detective work must always
sherlock:3:49:be, to a very large extent, the result of luck. Sherlock Holmes
sherlock:5:12:but Doctor Watson has to have it taken out for him and dusted,
";
diff --git a/tests/regression.rs b/tests/regression.rs
index 8c132795..203ac140 100644
--- a/tests/regression.rs
+++ b/tests/regression.rs
@@ -917,10 +917,12 @@ rgtest!(r1866, |dir: Dir, mut cmd: TestCommand| {
"test",
]);
+ // vimgrep only wants the first line of each match, even when a match
+ // spans multiple lines.
+ //
+ // See: https://github.com/BurntSushi/ripgrep/issues/1866
let expected = "\
test:1:1:foobar
-test:2:1:foobar
-test:3:1:foo quux
test:3:5:foo quux
";
eqnice!(expected, cmd.stdout());