diff --git a/src/search_stream.rs b/src/search_stream.rs index e558c2d3..b2b49d24 100644 --- a/src/search_stream.rs +++ b/src/search_stream.rs @@ -299,6 +299,15 @@ impl<'a, R: io::Read, W: WriteColor> Searcher<'a, R, W> { } } } + if self.after_context_remaining > 0 { + if self.last_printed == self.inp.lastnl { + try!(self.fill()); + } + let upto = self.inp.lastnl; + if upto > 0 { + self.print_after_context(upto); + } + } if self.match_count > 0 { if self.opts.count { self.printer.path_count(self.path, self.match_count); @@ -1247,6 +1256,23 @@ fn main() { "); } + #[test] + fn after_context_invert_one_max_count_two() { + let (count, out) = search_smallcap("Sherlock", SHERLOCK, |s| { + s.line_number(true) + .invert_match(true) + .after_context(1) + .max_count(Some(2)) + }); + assert_eq!(2, count); + assert_eq!(out, "\ +/baz.rs:2:Holmeses, success in the province of detective work must always +/baz.rs-3-be, to a very large extent, the result of luck. Sherlock Holmes +/baz.rs:4:can extract a clew from a wisp of straw or a flake of cigar ash; +/baz.rs-5-but Doctor Watson has to have it taken out for him and dusted, +"); + } + #[test] fn after_context_two1() { let (count, out) = search_smallcap("Sherlock", SHERLOCK, |s| { @@ -1290,6 +1316,23 @@ fn main() { "); } + #[test] + fn after_context_two_max_count_two() { + let (count, out) = search_smallcap( + "Doctor", SHERLOCK, |s| { + s.line_number(true).after_context(2).max_count(Some(2)) + }); + assert_eq!(2, count); + assert_eq!(out, "\ +/baz.rs:1:For the Doctor Watsons of this world, as opposed to the Sherlock +/baz.rs-2-Holmeses, success in the province of detective work must always +/baz.rs-3-be, to a very large extent, the result of luck. Sherlock Holmes +-- +/baz.rs:5:but Doctor Watson has to have it taken out for him and dusted, +/baz.rs-6-and exhibited clearly, with a label attached. +"); + } + #[test] fn after_context_three1() { let (count, out) = search_smallcap("Sherlock", SHERLOCK, |s| {