LucaCappelletti94 commented on code in PR #2498:
URL: 
https://github.com/apache/datafusion-sqlparser-rs/pull/2498#discussion_r4093395597


##########
tests/sqlparser_duckdb.rs:
##########
@@ -925,3 +925,39 @@ fn test_duckdb_lambda_function() {
     let sql_transform = "SELECT list_transform([1, 2, 3], lambda x : x * 2)";
     duckdb().verified_stmt(sql_transform);
 }
+
+#[test]
+fn test_escape_string_literal() {
+    duckdb().verified_stmt(r#"SELECT E'a\nb' AS value"#);
+
+    assert_eq!(
+        duckdb().verified_expr(r#"E'a\nb'"#),
+        
Expr::Value((Value::EscapedStringLiteral("a\nb".to_string())).with_empty_span())
+    );
+    assert_eq!(
+        duckdb().verified_expr(r#"'a\nb'"#),
+        
Expr::Value((Value::SingleQuotedString(r#"a\nb"#.to_string())).with_empty_span())
+    );
+    duckdb().one_statement_parses_to(
+        r#"COPY data TO E'out\n.csv'"#,
+        r#"COPY data TO 'out
+.csv'"#,
+    );

Review Comment:
   You should run the positive cases through `all_dialects_where(|d| 
d.supports_string_escape_constant())` instead of `duckdb()` alone. Both parser 
guards now key on that flag, so Redshift's `SELECT E'a\nb'` and `COPY data TO 
E'out\n.csv'` go from a parse error to parsing, and nothing tests it. With this 
change the test fails if either guard stops covering Redshift, which the 
current test does not catch.
   
   ```suggestion
       let escaping = all_dialects_where(|d| 
d.supports_string_escape_constant());
       escaping.verified_stmt(r#"SELECT E'a\nb' AS value"#);
   
       assert_eq!(
           escaping.verified_expr(r#"E'a\nb'"#),
           
Expr::Value((Value::EscapedStringLiteral("a\nb".to_string())).with_empty_span())
       );
       assert_eq!(
           duckdb().verified_expr(r#"'a\nb'"#),
           
Expr::Value((Value::SingleQuotedString(r#"a\nb"#.to_string())).with_empty_span())
       );
       escaping.one_statement_parses_to(
           r#"COPY data TO E'out\n.csv'"#,
           r#"COPY data TO 'out
   .csv'"#,
       );
   ```



-- 
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]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to