]> Repositorios git - scryer-prolog.git/commitdiff
add a test with bad utf-8
authorSkgland <[email protected]>
Thu, 30 Apr 2026 17:01:34 +0000 (19:01 +0200)
committerSkgland <[email protected]>
Thu, 30 Apr 2026 17:01:34 +0000 (19:01 +0200)
src/parser/char_reader.rs

index 1ad6971ebeaf39932b50efb13c11bf0219eb1e51..caffc7c1d20c52fba4184291d21bc116cc65d238 100644 (file)
@@ -380,6 +380,33 @@ mod tests {
         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]
     fn greek_string() {
         let mut read_string = CharReader::new(Cursor::new("λέξη"));