diff options
| author | Martin Fischer <martin@push-f.com> | 2023-09-03 17:16:44 +0200 | 
|---|---|---|
| committer | Martin Fischer <martin@push-f.com> | 2023-09-03 23:00:05 +0200 | 
| commit | 509ac6a8e3151c065a7ee609fcdabf8847fc0498 (patch) | |
| tree | cabea0c645234c68a80e23dbfc585442340917e3 | |
| parent | 890380c018c2396d1242e957b9d7db126f31488c (diff) | |
test: verify BufReadReader skips line on invalid UTF-8
| -rw-r--r-- | src/reader.rs | 20 | 
1 files changed, 20 insertions, 0 deletions
| diff --git a/src/reader.rs b/src/reader.rs index b08821f..a987b28 100644 --- a/src/reader.rs +++ b/src/reader.rs @@ -173,3 +173,23 @@ impl<'a, R: Read + 'a> IntoReader<'a> for BufReader<R> {          BufReadReader::new(self)      }  } + +#[cfg(test)] +mod tests { +    use std::io::{BufReader, ErrorKind}; +    use std::str::Utf8Error; + +    use super::{IntoReader, Reader}; + +    #[test] +    #[should_panic] // FIXME +    fn buf_read_reader_invalid_utf8() { +        let mut reader = BufReader::new(b" \xc3\x28" as &[u8]).into_reader(); +        assert_eq!(reader.read_char().unwrap(), Some(' ')); +        let error = reader.read_char().unwrap_err(); +        assert!(matches!(error.kind(), ErrorKind::InvalidData)); +        error.into_inner().unwrap().downcast::<Utf8Error>().unwrap(); +        assert_eq!(reader.read_char().unwrap(), Some('(')); +        assert_eq!(reader.read_char().unwrap(), None); +    } +} | 
