Skip to content

Commit 9ea396d

Browse files
authored
Improve documentation on verified_* methods (#828)
1 parent 5f815c2 commit 9ea396d

File tree

1 file changed

+27
-15
lines changed

1 file changed

+27
-15
lines changed

src/test_utils.rs

+27-15
Original file line numberDiff line numberDiff line change
@@ -68,17 +68,25 @@ impl TestedDialects {
6868
})
6969
}
7070

71+
/// Parses a single SQL string into multiple statements, ensuring
72+
/// the result is the same for all tested dialects.
7173
pub fn parse_sql_statements(&self, sql: &str) -> Result<Vec<Statement>, ParserError> {
7274
self.one_of_identical_results(|dialect| Parser::parse_sql(dialect, sql))
7375
// To fail the `ensure_multiple_dialects_are_tested` test:
7476
// Parser::parse_sql(&**self.dialects.first().unwrap(), sql)
7577
}
7678

77-
/// Ensures that `sql` parses as a single statement and returns it.
78-
/// If non-empty `canonical` SQL representation is provided,
79-
/// additionally asserts that parsing `sql` results in the same parse
80-
/// tree as parsing `canonical`, and that serializing it back to string
81-
/// results in the `canonical` representation.
79+
/// Ensures that `sql` parses as a single [Statement] for all tested
80+
/// dialects.
81+
///
82+
/// If `canonical` is non empty,this function additionally asserts
83+
/// that:
84+
///
85+
/// 1. parsing `sql` results in the same [`Statement`] as parsing
86+
/// `canonical`.
87+
///
88+
/// 2. re-serializing the result of parsing `sql` produces the same
89+
/// `canonical` sql string
8290
pub fn one_statement_parses_to(&self, sql: &str, canonical: &str) -> Statement {
8391
let mut statements = self.parse_sql_statements(sql).unwrap();
8492
assert_eq!(statements.len(), 1);
@@ -94,32 +102,36 @@ impl TestedDialects {
94102
only_statement
95103
}
96104

97-
/// Ensures that `sql` parses as a single [Statement], and is not modified
98-
/// after a serialization round-trip.
99-
pub fn verified_stmt(&self, query: &str) -> Statement {
100-
self.one_statement_parses_to(query, query)
105+
/// Ensures that `sql` parses as a single [Statement], and that
106+
/// re-serializing the parse result produces the same `sql`
107+
/// string (is not modified after a serialization round-trip).
108+
pub fn verified_stmt(&self, sql: &str) -> Statement {
109+
self.one_statement_parses_to(sql, sql)
101110
}
102111

103-
/// Ensures that `sql` parses as a single [Query], and is not modified
104-
/// after a serialization round-trip.
112+
/// Ensures that `sql` parses as a single [Query], and that
113+
/// re-serializing the parse result produces the same `sql`
114+
/// string (is not modified after a serialization round-trip).
105115
pub fn verified_query(&self, sql: &str) -> Query {
106116
match self.verified_stmt(sql) {
107117
Statement::Query(query) => *query,
108118
_ => panic!("Expected Query"),
109119
}
110120
}
111121

112-
/// Ensures that `sql` parses as a single [Select], and is not modified
113-
/// after a serialization round-trip.
122+
/// Ensures that `sql` parses as a single [Select], and that
123+
/// re-serializing the parse result produces the same `sql`
124+
/// string (is not modified after a serialization round-trip).
114125
pub fn verified_only_select(&self, query: &str) -> Select {
115126
match *self.verified_query(query).body {
116127
SetExpr::Select(s) => *s,
117128
_ => panic!("Expected SetExpr::Select"),
118129
}
119130
}
120131

121-
/// Ensures that `sql` parses as an expression, and is not modified
122-
/// after a serialization round-trip.
132+
/// Ensures that `sql` parses as an [`Expr`], and that
133+
/// re-serializing the parse result produces the same `sql`
134+
/// string (is not modified after a serialization round-trip).
123135
pub fn verified_expr(&self, sql: &str) -> Expr {
124136
let ast = self
125137
.run_parser_method(sql, |parser| parser.parse_expr())

0 commit comments

Comments
 (0)