File tree 1 file changed +28
-0
lines changed
library/std/src/io/buffered
1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -400,6 +400,34 @@ fn test_read_until() {
400
400
assert_eq ! ( v, [ ] ) ;
401
401
}
402
402
403
+ #[ test]
404
+ fn test_skip_until ( ) {
405
+ let bytes: & [ u8 ] = b"read\0 ignore\0 read\0 ignore\0 read\0 ignore" ;
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
+
403
431
#[ test]
404
432
fn test_line_buffer ( ) {
405
433
let mut writer = LineWriter :: new ( Vec :: new ( ) ) ;
You can’t perform that action at this time.
0 commit comments