summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorAndrew Gallant <jamslam@gmail.com>2021-05-15 08:23:01 -0400
committerAndrew Gallant <jamslam@gmail.com>2021-05-15 08:27:59 -0400
commit94e4b8e301302097dad48b292560ce135c4d4926 (patch)
treec1999f9b418c734607f5905a44399f1937159404 /tests
parent2af77242c5b5186ea5ad6d05fa9aaef3d93c1603 (diff)
printer: fix --vimgrep for multi-line mode
It turned out that --vimgrep wasn't quite getting the column of each match correctly. Instead of printing column numbers relative to the current line, it was printing column numbers as byte offsets relative to where the match began. To fix this, we simply subtract the offset of the line number from the beginning of the match. If the beginning of the match came before the start of the current line, then there's really nothing sensible we can do other than to use a column number of 1, which we now document. Interestingly, existing tests were checking that the previous behavior was intended. My only defense is that I somehow tricked myself into thinking it was a byte offset instead of a column number. Kudos to @bfrg for calling this out in #1866: https://github.com/BurntSushi/ripgrep/issues/1866#issuecomment-841635553
Diffstat (limited to 'tests')
-rw-r--r--tests/multiline.rs2
-rw-r--r--tests/regression.rs18
2 files changed, 19 insertions, 1 deletions
diff --git a/tests/multiline.rs b/tests/multiline.rs
index 67fa650d..eb9cb4d5 100644
--- a/tests/multiline.rs
+++ b/tests/multiline.rs
@@ -77,7 +77,7 @@ 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:57:Holmeses, success in the province of detective work must always
+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 b34fb0ff..2935a43e 100644
--- a/tests/regression.rs
+++ b/tests/regression.rs
@@ -864,3 +864,21 @@ use B;
]);
eqnice!("2\n", cmd.stdout());
});
+
+rgtest!(r1866, |dir: Dir, mut cmd: TestCommand| {
+ dir.create("test", "foobar\nfoobar\nfoo quux");
+ cmd.args(&[
+ "--multiline",
+ "--vimgrep",
+ r"foobar\nfoobar\nfoo|quux",
+ "test",
+ ]);
+
+ let expected = "\
+test:1:1:foobar
+test:2:1:foobar
+test:3:1:foo quux
+test:3:5:foo quux
+";
+ eqnice!(expected, cmd.stdout());
+});