mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-08-27 17:34:05 +00:00
Extend one_statement_parses_to to also test parsing canonical SQL
It was an omission of the original implementation.
This commit is contained in:
parent
4128dfe1db
commit
d9e044aabb
1 changed files with 9 additions and 3 deletions
|
@ -69,13 +69,19 @@ impl TestedDialects {
|
||||||
// Parser::parse_sql(&**self.dialects.first().unwrap(), sql)
|
// Parser::parse_sql(&**self.dialects.first().unwrap(), sql)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Ensures that `sql` parses as a single statement, optionally checking
|
/// Ensures that `sql` parses as a single statement and returns it.
|
||||||
/// that converting AST back to string equals to `canonical` (unless an
|
/// If non-empty `canonical` SQL representation is provided,
|
||||||
/// empty canonical string is provided).
|
/// additionally asserts that parsing `sql` results in the same parse
|
||||||
|
/// tree as parsing `canonical`, and that serializing it back to string
|
||||||
|
/// results in the `canonical` representation.
|
||||||
pub fn one_statement_parses_to(&self, sql: &str, canonical: &str) -> Statement {
|
pub fn one_statement_parses_to(&self, sql: &str, canonical: &str) -> Statement {
|
||||||
let mut statements = self.parse_sql_statements(&sql).unwrap();
|
let mut statements = self.parse_sql_statements(&sql).unwrap();
|
||||||
assert_eq!(statements.len(), 1);
|
assert_eq!(statements.len(), 1);
|
||||||
|
|
||||||
|
if !canonical.is_empty() && sql != canonical {
|
||||||
|
assert_eq!(self.parse_sql_statements(&canonical).unwrap(), statements);
|
||||||
|
}
|
||||||
|
|
||||||
let only_statement = statements.pop().unwrap();
|
let only_statement = statements.pop().unwrap();
|
||||||
if !canonical.is_empty() {
|
if !canonical.is_empty() {
|
||||||
assert_eq!(canonical, only_statement.to_string())
|
assert_eq!(canonical, only_statement.to_string())
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue