Skip to content

Commit 9f57adf

Browse files
committed
test: cover multi-byte input in NBReader::try_read
1 parent f21a254 commit 9f57adf

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

src/reader.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,4 +457,20 @@ mod tests {
457457
assert_eq!(None, r.try_read());
458458
assert_eq!(None, r.try_read());
459459
}
460+
461+
#[test]
462+
fn test_try_read_multibyte_byte() {
463+
// bytes >= 0x80 decode to multi-byte chars in the buffer, so draining one byte used to panic
464+
let f = io::Cursor::new("é");
465+
let mut r = NBReader::new(f, Options::default());
466+
let mut count = 0;
467+
loop {
468+
match r.try_read() {
469+
Some(_) => count += 1,
470+
None if count == "é".len() => break,
471+
None => thread::sleep(time::Duration::from_millis(10)),
472+
}
473+
}
474+
assert_eq!(count, "é".len());
475+
}
460476
}

0 commit comments

Comments
 (0)