mirror of
https://github.com/BurntSushi/ripgrep.git
synced 2024-12-12 19:18:24 +02:00
Omit context separators when using a contextless option like -c or -l
Fixes #693
This commit is contained in:
parent
7ae1f373c2
commit
d73a75d6cd
14
src/args.rs
14
src/args.rs
@ -153,14 +153,16 @@ impl Args {
|
|||||||
|
|
||||||
/// Retrieve the configured file separator.
|
/// Retrieve the configured file separator.
|
||||||
pub fn file_separator(&self) -> Option<Vec<u8>> {
|
pub fn file_separator(&self) -> Option<Vec<u8>> {
|
||||||
let use_heading_sep =
|
let contextless =
|
||||||
self.heading
|
self.count
|
||||||
&& !self.count
|
|| self.files_with_matches
|
||||||
&& !self.files_with_matches
|
|| self.files_without_matches;
|
||||||
&& !self.files_without_matches;
|
let use_heading_sep = self.heading && !contextless;
|
||||||
|
|
||||||
if use_heading_sep {
|
if use_heading_sep {
|
||||||
Some(b"".to_vec())
|
Some(b"".to_vec())
|
||||||
} else if self.before_context > 0 || self.after_context > 0 {
|
} else if !contextless
|
||||||
|
&& (self.before_context > 0 || self.after_context > 0) {
|
||||||
Some(self.context_separator.clone())
|
Some(self.context_separator.clone())
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
|
@ -1799,6 +1799,25 @@ fn regression_568_leading_hyphen_option_arguments() {
|
|||||||
assert_eq!(lines, "foo -n -baz\n");
|
assert_eq!(lines, "foo -n -baz\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// See: https://github.com/BurntSushi/ripgrep/issues/693
|
||||||
|
#[test]
|
||||||
|
fn regression_693_context_option_in_contextless_mode() {
|
||||||
|
let wd = WorkDir::new("regression_693_context_option_in_contextless_mode");
|
||||||
|
|
||||||
|
wd.create("foo", "xyz\n");
|
||||||
|
wd.create("bar", "xyz\n");
|
||||||
|
|
||||||
|
let mut cmd = wd.command();
|
||||||
|
cmd.arg("-C1").arg("-c").arg("--sort-files").arg("xyz");
|
||||||
|
|
||||||
|
let lines: String = wd.stdout(&mut cmd);
|
||||||
|
let expected = "\
|
||||||
|
bar:1
|
||||||
|
foo:1
|
||||||
|
";
|
||||||
|
assert_eq!(lines, expected);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn type_list() {
|
fn type_list() {
|
||||||
let wd = WorkDir::new("type_list");
|
let wd = WorkDir::new("type_list");
|
||||||
|
Loading…
Reference in New Issue
Block a user