Skip to content

Commit

Permalink
Omit context separators when using a contextless option like -c or -l
Browse files Browse the repository at this point in the history
  • Loading branch information
okdana committed Nov 29, 2017
1 parent 7ae1f37 commit bc40535
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,14 +153,16 @@ impl Args {

/// Retrieve the configured file separator.
pub fn file_separator(&self) -> Option<Vec<u8>> {
let use_heading_sep =
self.heading
&& !self.count
&& !self.files_with_matches
&& !self.files_without_matches;
let contextless =
self.count
|| self.files_with_matches
|| self.files_without_matches;
let use_heading_sep = self.heading && !contextless;

if use_heading_sep {
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())
} else {
None
Expand Down
19 changes: 19 additions & 0 deletions tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1799,6 +1799,25 @@ fn regression_568_leading_hyphen_option_arguments() {
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]
fn type_list() {
let wd = WorkDir::new("type_list");
Expand Down

0 comments on commit bc40535

Please sign in to comment.