Skip to content

Commit 169ea91

Browse files
committed
test: capture try_read panic on multi-byte input
1 parent f21a254 commit 169ea91

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

src/reader.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,4 +457,19 @@ mod tests {
457457
assert_eq!(None, r.try_read());
458458
assert_eq!(None, r.try_read());
459459
}
460+
461+
// Multi-byte UTF-8 characters in the buffer cause `drain(..1)` to panic at
462+
// the char boundary. Marked `should_panic` to capture the current behavior;
463+
// the follow-up fix commit removes the attribute and asserts correct decode.
464+
#[test]
465+
#[should_panic = "is_char_boundary"]
466+
fn test_try_read_multibyte() {
467+
let f = io::Cursor::new("\u{c3}");
468+
let mut r = NBReader::new(f, Options::default());
469+
// pump bytes from the reader thread into the buffer
470+
for _ in 0..10 {
471+
let _ = r.try_read();
472+
thread::sleep(time::Duration::from_millis(5));
473+
}
474+
}
460475
}

0 commit comments

Comments
 (0)