Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,8 @@ impl Controller<'_> {
// Buffer needs to be 1 greater than the offset to have a look-ahead line for EOF
let buffer_size: usize = line_ranges.largest_offset_from_end() + 1;
// Buffers multiple line data and line number
let mut buffered_lines: VecDeque<(Vec<u8>, usize)> = VecDeque::with_capacity(buffer_size);
let mut buffered_lines: VecDeque<(Vec<u8>, usize)> =
VecDeque::with_capacity(buffer_size.min(1024));

let mut reached_eof: bool = false;
let mut first_range: bool = true;
Expand Down
19 changes: 19 additions & 0 deletions tests/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,16 @@ fn line_range_context_very_large() {
);
}

#[test]
fn line_range_huge_negative_does_not_panic() {
bat()
.arg("multiline.txt")
.arg("--line-range=:-999999999999999999")
.assert()
.success()
.stdout("");
}

#[test]
fn piped_output_with_implicit_auto_style() {
bat()
Expand All @@ -585,6 +595,15 @@ fn piped_output_with_implicit_auto_style() {
.stdout("hello\nworld\n");
}

#[test]
fn piped_output_with_line_range() {
bat()
.arg("--line-range=2:3")
.write_stdin("line 1\nline 2\nline 3\nline 4\n")
.assert()
.success()
.stdout("line 2\nline 3\n");
}
#[test]
fn piped_output_with_line_number_flag() {
bat()
Expand Down
Loading