From 112b3c5e0ae232fdbce90cd505c57f2c4abc4a22 Mon Sep 17 00:00:00 2001 From: Andrew Gallant Date: Mon, 29 May 2017 09:51:58 -0400 Subject: Fix another bug in -o/--only-matching. The handling of the -o/--only-matching was incorrect. We cannot ever re-run regexes on a *subset* of a matched line, because it doesn't take into account zero width assertions on the edges of the regex. This occurs whenever an end user uses an assertion explicity, but also occurs when one is used implicitly, e.g., with the `-w` flag. This instead reuses the initial matched range from the first regex match. We also apply this fix to coloring. Fixes #493 --- tests/tests.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/tests.rs b/tests/tests.rs index 930aa165..d9c843ad 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -1079,7 +1079,8 @@ clean!(regression_428_color_context_path, "foo", ".", |wd: WorkDir, mut cmd: Com }); // See: https://github.com/BurntSushi/ripgrep/issues/428 -clean!(regression_428_unrecognized_style, "Sherlok", ".", |wd: WorkDir, mut cmd: Command| { +clean!(regression_428_unrecognized_style, "Sherlok", ".", +|wd: WorkDir, mut cmd: Command| { cmd.arg("--colors=match:style:"); wd.assert_err(&mut cmd); @@ -1091,6 +1092,15 @@ Unrecognized style attribute ''. Choose from: nobold, bold, nointense, intense. assert_eq!(err, expected); }); +// See: https://github.com/BurntSushi/ripgrep/issues/493 +clean!(regression_493, " 're ", "input.txt", |wd: WorkDir, mut cmd: Command| { + wd.create("input.txt", "peshwaship 're seminomata"); + cmd.arg("-o").arg("-w"); + + let lines: String = wd.stdout(&mut cmd); + assert_eq!(lines, " 're \n"); +}); + // See: https://github.com/BurntSushi/ripgrep/issues/1 clean!(feature_1_sjis, "Шерлок Холмс", ".", |wd: WorkDir, mut cmd: Command| { let sherlock = -- cgit v1.2.3