core: don't let context flags override eachother

This matches the behavior of GNU grep which does not ignore
before-context and after-context completely if the context flag is also
provided.

Note that this change wasn't done just to match GNU grep. In this case,
GNU grep has the more sensible behavior.

Fixes #2288, Closes #2451
This commit is contained in:
Andrew Gallant
2023-07-07 10:51:51 -04:00
parent 54e609d657
commit d675844510
4 changed files with 34 additions and 14 deletions

View File

@@ -921,6 +921,23 @@ rgtest!(f1842_field_match_separator, |dir: Dir, _: TestCommand| {
eqnice!(expected, dir.command().args(&args).stdout());
});
// See: https://github.com/BurntSushi/ripgrep/issues/2288
rgtest!(f2288_context_partial_override, |dir: Dir, mut cmd: TestCommand| {
dir.create("test", "1\n2\n3\n4\n5\n6\n7\n8\n9\n");
cmd.args(&["-C1", "-A2", "5", "test"]);
eqnice!("4\n5\n6\n7\n", cmd.stdout());
});
// See: https://github.com/BurntSushi/ripgrep/issues/2288
rgtest!(
f2288_context_partial_override_rev,
|dir: Dir, mut cmd: TestCommand| {
dir.create("test", "1\n2\n3\n4\n5\n6\n7\n8\n9\n");
cmd.args(&["-A2", "-C1", "5", "test"]);
eqnice!("4\n5\n6\n7\n", cmd.stdout());
}
);
rgtest!(no_context_sep, |dir: Dir, mut cmd: TestCommand| {
dir.create("test", "foo\nctx\nbar\nctx\nfoo\nctx");
cmd.args(&["-A1", "--no-context-separator", "foo", "test"]);