add a test with bad utf-8
This commit is contained in:
@@ -380,6 +380,33 @@ mod tests {
|
|||||||
assert!(read_string.read_char().is_none());
|
assert!(read_string.read_char().is_none());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn interspersed_bad_utf8() {
|
||||||
|
let mut read_string = CharReader::new(Cursor::new(b"a string\xffmore_text\xff"));
|
||||||
|
|
||||||
|
for c in "a string".chars() {
|
||||||
|
assert_eq!(read_string.peek_char().unwrap().ok(), Some(c));
|
||||||
|
assert_eq!(read_string.read_char().unwrap().ok(), Some(c));
|
||||||
|
}
|
||||||
|
|
||||||
|
assert_eq!(
|
||||||
|
read_string.peek_char().unwrap().unwrap_err().kind(),
|
||||||
|
std::io::ErrorKind::InvalidData
|
||||||
|
);
|
||||||
|
|
||||||
|
for c in "more_text".chars() {
|
||||||
|
assert_eq!(read_string.peek_char().unwrap().ok(), Some(c));
|
||||||
|
assert_eq!(read_string.read_char().unwrap().ok(), Some(c));
|
||||||
|
}
|
||||||
|
|
||||||
|
assert_eq!(
|
||||||
|
read_string.peek_char().unwrap().unwrap_err().kind(),
|
||||||
|
std::io::ErrorKind::InvalidData
|
||||||
|
);
|
||||||
|
|
||||||
|
assert!(read_string.read_char().is_none());
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn greek_string() {
|
fn greek_string() {
|
||||||
let mut read_string = CharReader::new(Cursor::new("λέξη"));
|
let mut read_string = CharReader::new(Cursor::new("λέξη"));
|
||||||
|
|||||||
Reference in New Issue
Block a user