mirror of
https://github.com/uutils/coreutils
synced 2024-11-16 17:58:06 +00:00
Merge pull request #3277 from jfinkels/split-line-bytes-no-trailing-newline
split: handle no final newline with --line-bytes
This commit is contained in:
commit
07b0bc6bb9
2 changed files with 17 additions and 1 deletions
|
@ -886,7 +886,7 @@ impl<'a> Write for LineBytesChunkWriter<'a> {
|
||||||
// then move on to the next chunk if necessary.
|
// then move on to the next chunk if necessary.
|
||||||
None => {
|
None => {
|
||||||
let end = self.num_bytes_remaining_in_current_chunk;
|
let end = self.num_bytes_remaining_in_current_chunk;
|
||||||
let num_bytes_written = self.inner.write(&buf[..end])?;
|
let num_bytes_written = self.inner.write(&buf[..end.min(buf.len())])?;
|
||||||
self.num_bytes_remaining_in_current_chunk -= num_bytes_written;
|
self.num_bytes_remaining_in_current_chunk -= num_bytes_written;
|
||||||
total_bytes_written += num_bytes_written;
|
total_bytes_written += num_bytes_written;
|
||||||
buf = &buf[num_bytes_written..];
|
buf = &buf[num_bytes_written..];
|
||||||
|
|
|
@ -618,3 +618,19 @@ fn test_line_bytes() {
|
||||||
assert_eq!(at.read("xac"), "cccc\ndd\n");
|
assert_eq!(at.read("xac"), "cccc\ndd\n");
|
||||||
assert_eq!(at.read("xad"), "ee\n");
|
assert_eq!(at.read("xad"), "ee\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_line_bytes_no_final_newline() {
|
||||||
|
let (at, mut ucmd) = at_and_ucmd!();
|
||||||
|
ucmd.args(&["-C", "2"])
|
||||||
|
.pipe_in("1\n2222\n3\n4")
|
||||||
|
.succeeds()
|
||||||
|
.no_stdout()
|
||||||
|
.no_stderr();
|
||||||
|
assert_eq!(at.read("xaa"), "1\n");
|
||||||
|
assert_eq!(at.read("xab"), "22");
|
||||||
|
assert_eq!(at.read("xac"), "22");
|
||||||
|
assert_eq!(at.read("xad"), "\n");
|
||||||
|
assert_eq!(at.read("xae"), "3\n");
|
||||||
|
assert_eq!(at.read("xaf"), "4");
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue