Rich-T-kid commented on code in PR #11931:
URL: https://github.com/apache/arrow-rs/pull/11931#discussion_r4520681611


##########
arrow-schema/src/datatype_parse.rs:
##########
@@ -1047,6 +1073,74 @@ impl Display for Token {
 mod test {
     use super::*;
 
+    #[test]
+    fn test_escaped_strings_round_trip() {
+        for name in [
+            "a\"b",
+            "a'b",
+            "a\\b",
+            "trailing\\",
+            "\\\"",
+            "\\\\\"",
+            "line\nbreak",
+            "tab\treturn\r",
+            "nul\0",
+            "control\u{7f}",
+            "unicode\u{200d}é",
+            r"\n",
+            r"trailing\\",
+            "\u{1}\u{8}\u{b}\u{c}\u{1b}",
+        ] {
+            let field = Arc::new(Field::new(name, DataType::Int32, true));
+            for data_type in [
+                DataType::Struct(vec![field.clone()].into()),
+                DataType::List(field.clone()),
+                DataType::LargeList(field.clone()),
+                DataType::ListView(field.clone()),
+                DataType::LargeListView(field.clone()),
+                DataType::FixedSizeList(field, 2),
+                DataType::Timestamp(TimeUnit::Second, Some(name.into())),
+            ] {
+                round_trip(data_type);
+            }
+        }
+    }
+
+    #[test]
+    fn test_parse_quoted_escapes() {
+        for (input, expected) in [
+            (r#""a\"b""#, "a\"b"),
+            (r"'a\'b'", "a'b"),
+            (r#""a\\b""#, "a\\b"),
+            (r#""\n\r\t\0""#, "\n\r\t\0"),
+            (r#""\u{1f980}""#, "🦀"),
+            (r#""\u{000061}""#, "a"),
+            (r#""\u{10ffff}""#, "\u{10ffff}"),
+        ] {
+            let token = Tokenizer::new(input).next().unwrap().unwrap();
+            assert!(
+                matches!(token, Token::DoubleQuotedString(s) | 
Token::SingleQuotedString(s) if s == expected)
+            );
+        }
+    }
+
+    #[test]
+    fn test_invalid_quoted_escapes() {
+        for input in [
+            r#""\q""#,
+            r#""trailing\"#,
+            r#""\u{}""#,
+            r#""\u{xyz}""#,
+            r#""\u{d800}""#,
+            r#""\u{110000}""#,
+            r#""\u{0000000}""#,
+            r#""\u1234""#,
+            r#""\u{1234""#,
+        ] {
+            assert!(Tokenizer::new(input).next().unwrap().is_err(), "{input}");

Review Comment:
   nit: we should assert that the error is `ArrowError::ParseError` not just 
any error



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to