@@ -68,17 +68,25 @@ impl TestedDialects {
68
68
} )
69
69
}
70
70
71
+ /// Parses a single SQL string into multiple statements, ensuring
72
+ /// the result is the same for all tested dialects.
71
73
pub fn parse_sql_statements ( & self , sql : & str ) -> Result < Vec < Statement > , ParserError > {
72
74
self . one_of_identical_results ( |dialect| Parser :: parse_sql ( dialect, sql) )
73
75
// To fail the `ensure_multiple_dialects_are_tested` test:
74
76
// Parser::parse_sql(&**self.dialects.first().unwrap(), sql)
75
77
}
76
78
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
82
90
pub fn one_statement_parses_to ( & self , sql : & str , canonical : & str ) -> Statement {
83
91
let mut statements = self . parse_sql_statements ( sql) . unwrap ( ) ;
84
92
assert_eq ! ( statements. len( ) , 1 ) ;
@@ -94,32 +102,36 @@ impl TestedDialects {
94
102
only_statement
95
103
}
96
104
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)
101
110
}
102
111
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).
105
115
pub fn verified_query ( & self , sql : & str ) -> Query {
106
116
match self . verified_stmt ( sql) {
107
117
Statement :: Query ( query) => * query,
108
118
_ => panic ! ( "Expected Query" ) ,
109
119
}
110
120
}
111
121
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).
114
125
pub fn verified_only_select ( & self , query : & str ) -> Select {
115
126
match * self . verified_query ( query) . body {
116
127
SetExpr :: Select ( s) => * s,
117
128
_ => panic ! ( "Expected SetExpr::Select" ) ,
118
129
}
119
130
}
120
131
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).
123
135
pub fn verified_expr ( & self , sql : & str ) -> Expr {
124
136
let ast = self
125
137
. run_parser_method ( sql, |parser| parser. parse_expr ( ) )
0 commit comments