Skip to content

Commit 4eea976

Browse files
committed
Add BufRead::skip_until test
1 parent 7d91039 commit 4eea976

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

library/std/src/io/buffered/tests.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,34 @@ fn test_read_until() {
400400
assert_eq!(v, []);
401401
}
402402

403+
#[test]
404+
fn test_skip_until() {
405+
let bytes: &[u8] = b"read\0ignore\0read\0ignore\0read\0ignore";
406+
let mut reader = BufReader::new(bytes);
407+
408+
// read from the bytes, alternating between
409+
// consuming `read\0`s and skipping `ignore\0`s
410+
loop {
411+
// consume `read\0`
412+
let mut out = Vec::new();
413+
let read = reader.read_until(0, &mut out).unwrap();
414+
if read == 0 {
415+
// eof
416+
break;
417+
} else {
418+
assert_eq!(out, b"read\0");
419+
}
420+
421+
// skip past `ignore\0`
422+
reader.skip_until(0).unwrap();
423+
}
424+
425+
// ensure we are at the end of the byte slice and that we can skip no further
426+
// also ensure skip_until matches the behavior of read_until at EOF
427+
let skipped = reader.skip_until(0).unwrap();
428+
assert_eq!(skipped, 0);
429+
}
430+
403431
#[test]
404432
fn test_line_buffer() {
405433
let mut writer = LineWriter::new(Vec::new());

0 commit comments

Comments
 (0)