Skip to content

Commit

Permalink
fix: fixed parsing of the last line without trailing new-line charact…
Browse files Browse the repository at this point in the history
…ers (#177)
  • Loading branch information
pamburus authored Mar 25, 2024
1 parent 0b4842e commit 2931fa4
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ categories = ["command-line-utilities"]
description = "Utility for viewing json-formatted log files."
keywords = ["cli", "human", "log"]
name = "hl"
version = "0.27.1-alpha.3"
version = "0.27.1-alpha.4"
edition = "2021"
build = "build.rs"

Expand Down
26 changes: 23 additions & 3 deletions src/scanning.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,10 +280,11 @@ impl<'a, 'b, S: Search> Iterator for SplitIter<'a, 'b, S> {
let range = self.searcher.search_l(buf, true);
if let Some(range) = range {
self.pos += range.end;
return Some(&buf[..range.start]);
Some(&buf[..range.start])
} else {
self.pos = self.buf.len();
Some(buf)
}

None
}
}

Expand Down Expand Up @@ -837,6 +838,25 @@ impl<'a, 'b, D: Delimit> Iterator for ScannerJumboIter<'a, 'b, D> {
mod tests {
use super::*;

#[test]
fn test_empty() {
let searcher = b'/'.into_searcher();
let buf = b"";
let mut iter = searcher.split(buf);

assert_eq!(iter.next(), None);
}

#[test]
fn test_no_delim() {
let searcher = b'/'.into_searcher();
let buf = b"some";
let mut iter = searcher.split(buf);

assert_eq!(iter.next(), Some(&b"some"[..]));
assert_eq!(iter.next(), None);
}

#[test]
fn test_split_iter() {
let searcher = b'/'.into_searcher();
Expand Down

0 comments on commit 2931fa4

Please sign in to comment.