Support for postgres String Constants with Unicode Escapes (#1355)

This commit is contained in:
Ophir LOJKINE 2024-07-29 23:18:16 +02:00 committed by GitHub
parent c3ba2f33c6
commit bc15f7b4ce
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 180 additions and 0 deletions

View file

@ -4441,3 +4441,35 @@ fn test_table_unnest_with_ordinality() {
_ => panic!("Expecting TableFactor::UNNEST with ordinality"),
}
}
#[test]
fn test_escaped_string_literal() {
match pg().verified_expr(r#"E'\n'"#) {
Expr::Value(Value::EscapedStringLiteral(s)) => {
assert_eq!("\n", s);
}
_ => unreachable!(),
}
}
#[test]
fn test_unicode_string_literal() {
let pairs = [
// Example from the postgres docs
(r#"U&'\0441\043B\043E\043D'"#, "слон"),
// High unicode code point (> 0xFFFF)
(r#"U&'\+01F418'"#, "🐘"),
// Escaped backslash
(r#"U&'\\'"#, r#"\"#),
// Escaped single quote
(r#"U&''''"#, "'"),
];
for (input, expected) in pairs {
match pg_and_generic().verified_expr(input) {
Expr::Value(Value::UnicodeStringLiteral(s)) => {
assert_eq!(expected, s);
}
_ => unreachable!(),
}
}
}