Skip to content

Commit f1e8ac7

Browse files
committed
Add statements_parse_to helper
1 parent ac298a6 commit f1e8ac7

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

src/test_utils.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,8 @@ impl TestedDialects {
151151
///
152152
/// 2. re-serializing the result of parsing `sql` produces the same
153153
/// `canonical` sql string
154+
///
155+
/// For multiple statements, use [`statements_parse_to`].
154156
pub fn one_statement_parses_to(&self, sql: &str, canonical: &str) -> Statement {
155157
let mut statements = self.parse_sql_statements(sql).expect(sql);
156158
assert_eq!(statements.len(), 1);
@@ -166,6 +168,30 @@ impl TestedDialects {
166168
only_statement
167169
}
168170

171+
/// The same as [`one_statement_parses_to`] but it works for a multiple statements
172+
pub fn statements_parse_to(
173+
&self,
174+
sql: &str,
175+
statement_count: usize,
176+
canonical: &str,
177+
) -> Vec<Statement> {
178+
let statements = self.parse_sql_statements(sql).expect(sql);
179+
assert_eq!(statements.len(), statement_count);
180+
if !canonical.is_empty() && sql != canonical {
181+
assert_eq!(self.parse_sql_statements(canonical).unwrap(), statements);
182+
} else {
183+
assert_eq!(
184+
sql,
185+
statements
186+
.iter()
187+
.map(|s| s.to_string())
188+
.collect::<Vec<_>>()
189+
.join("; ")
190+
);
191+
}
192+
statements
193+
}
194+
169195
/// Ensures that `sql` parses as an [`Expr`], and that
170196
/// re-serializing the parse result produces canonical
171197
pub fn expr_parses_to(&self, sql: &str, canonical: &str) -> Expr {

0 commit comments

Comments
 (0)