diff options
author | Andrew Gallant <jamslam@gmail.com> | 2017-10-21 20:36:51 -0400 |
---|---|---|
committer | Andrew Gallant <jamslam@gmail.com> | 2017-10-21 22:40:10 -0400 |
commit | 2a14bf22491b01cabe882bfaa116a4aea048047f (patch) | |
tree | 99b921193b4b6c005f6ad3e47a865302404bd510 /tests | |
parent | f0028a66ecc9cd6caf864489c93b7f60624437e4 (diff) |
printer: fix colors on empty matches
This fixes a bug where a "match" color escape was erroneously emitted
after the new line character. This is because `^` is actually allowed to
match after the end of a trailing new line, which means `^$` matches both
before and after the trailing new line when multiline mode is enabled.
The trailing match was causing the phantom escape sequence to appear,
which we don't want.
Incidentally, this is the root cause of #441 as well, although this commit
doesn't fix that issue, since the line itself is printed before we detect
the phantom match.
Fixes #599
Diffstat (limited to 'tests')
-rw-r--r-- | tests/tests.rs | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/tests/tests.rs b/tests/tests.rs index 0c9446c1..2b1f3cc2 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -1146,6 +1146,29 @@ clean!(regression_493, " 're ", "input.txt", |wd: WorkDir, mut cmd: Command| { assert_eq!(lines, " 're \n"); }); +// See: https://github.com/BurntSushi/ripgrep/issues/599 +clean!(regression_599, "^$", "input.txt", |wd: WorkDir, mut cmd: Command| { + wd.create("input.txt", "\n\ntest\n"); + cmd.args(&[ + "--color", "ansi", + "--colors", "path:none", + "--colors", "line:none", + "--colors", "match:fg:red", + "--colors", "match:style:nobold", + "--line-number", + ]); + + let lines: String = wd.stdout(&mut cmd); + // Technically, the expected output should only be two lines, but: + // https://github.com/BurntSushi/ripgrep/issues/441 + let expected = "\ +[m1[m:[m[31m[m +[m2[m:[m[31m[m +[m4[m: +"; + assert_eq!(expected, lines); +}); + // See: https://github.com/BurntSushi/ripgrep/issues/1 clean!(feature_1_sjis, "Шерлок Холмс", ".", |wd: WorkDir, mut cmd: Command| { let sherlock = |