@@ -44,25 +44,21 @@ fn count_named_placeholders() {
44
44
45
45
#[ test]
46
46
fn duplicate_column ( ) {
47
- expect_parser_err (
47
+ expect_parser_err_msg (
48
48
b"CREATE TABLE t (x TEXT, x TEXT)" ,
49
49
"duplicate column name: x" ,
50
50
) ;
51
51
}
52
52
53
53
#[ test]
54
54
fn create_table_without_column ( ) {
55
- let r = parse ( b"CREATE TABLE t ()" ) ;
56
- let Error :: ParserError (
55
+ expect_parser_err (
56
+ b"CREATE TABLE t ()" ,
57
57
ParserError :: SyntaxError {
58
58
token_type : "RP" ,
59
59
found : None ,
60
60
} ,
61
- _,
62
- ) = r. unwrap_err ( )
63
- else {
64
- panic ! ( "unexpected error type" )
65
- } ;
61
+ ) ;
66
62
}
67
63
68
64
#[ test]
@@ -147,44 +143,44 @@ fn extra_comments_between_statements() {
147
143
148
144
#[ test]
149
145
fn insert_mismatch_count ( ) {
150
- expect_parser_err ( b"INSERT INTO t (a, b) VALUES (1)" , "1 values for 2 columns" ) ;
146
+ expect_parser_err_msg ( b"INSERT INTO t (a, b) VALUES (1)" , "1 values for 2 columns" ) ;
151
147
}
152
148
153
149
#[ test]
154
150
fn insert_default_values ( ) {
155
- expect_parser_err (
151
+ expect_parser_err_msg (
156
152
b"INSERT INTO t (a) DEFAULT VALUES" ,
157
153
"0 values for 1 columns" ,
158
154
) ;
159
155
}
160
156
161
157
#[ test]
162
158
fn create_view_mismatch_count ( ) {
163
- expect_parser_err (
159
+ expect_parser_err_msg (
164
160
b"CREATE VIEW v (c1, c2) AS SELECT 1" ,
165
161
"expected 2 columns for v but got 1" ,
166
162
) ;
167
163
}
168
164
169
165
#[ test]
170
166
fn create_view_duplicate_column_name ( ) {
171
- expect_parser_err (
167
+ expect_parser_err_msg (
172
168
b"CREATE VIEW v (c1, c1) AS SELECT 1, 2" ,
173
169
"duplicate column name: c1" ,
174
170
) ;
175
171
}
176
172
177
173
#[ test]
178
174
fn create_table_without_rowid_missing_pk ( ) {
179
- expect_parser_err (
175
+ expect_parser_err_msg (
180
176
b"CREATE TABLE t (c1) WITHOUT ROWID" ,
181
177
"PRIMARY KEY missing on table t" ,
182
178
) ;
183
179
}
184
180
185
181
#[ test]
186
182
fn create_temporary_table_with_qualified_name ( ) {
187
- expect_parser_err (
183
+ expect_parser_err_msg (
188
184
b"CREATE TEMPORARY TABLE mem.x AS SELECT 1" ,
189
185
"temporary table name must be unqualified" ,
190
186
) ;
@@ -193,20 +189,20 @@ fn create_temporary_table_with_qualified_name() {
193
189
194
190
#[ test]
195
191
fn create_table_with_only_generated_column ( ) {
196
- expect_parser_err (
192
+ expect_parser_err_msg (
197
193
b"CREATE TABLE test(data AS (1))" ,
198
194
"must have at least one non-generated column" ,
199
195
) ;
200
196
}
201
197
202
198
#[ test]
203
199
fn create_strict_table_missing_datatype ( ) {
204
- expect_parser_err ( b"CREATE TABLE t (c1) STRICT" , "missing datatype for t.c1" ) ;
200
+ expect_parser_err_msg ( b"CREATE TABLE t (c1) STRICT" , "missing datatype for t.c1" ) ;
205
201
}
206
202
207
203
#[ test]
208
204
fn create_strict_table_unknown_datatype ( ) {
209
- expect_parser_err (
205
+ expect_parser_err_msg (
210
206
b"CREATE TABLE t (c1 BOOL) STRICT" ,
211
207
"unknown datatype for t.c1: \" BOOL\" " ,
212
208
) ;
@@ -225,76 +221,79 @@ fn create_strict_table_generated_column() {
225
221
226
222
#[ test]
227
223
fn selects_compound_mismatch_columns_count ( ) {
228
- expect_parser_err (
224
+ expect_parser_err_msg (
229
225
b"SELECT 1 UNION SELECT 1, 2" ,
230
226
"SELECTs to the left and right of UNION do not have the same number of result columns" ,
231
227
) ;
232
228
}
233
229
234
230
#[ test]
235
231
fn delete_order_by_without_limit ( ) {
236
- expect_parser_err (
232
+ expect_parser_err_msg (
237
233
b"DELETE FROM t ORDER BY x" ,
238
234
"ORDER BY without LIMIT on DELETE" ,
239
235
) ;
240
236
}
241
237
242
238
#[ test]
243
239
fn update_order_by_without_limit ( ) {
244
- expect_parser_err (
240
+ expect_parser_err_msg (
245
241
b"UPDATE t SET x = 1 ORDER BY x" ,
246
242
"ORDER BY without LIMIT on UPDATE" ,
247
243
) ;
248
244
}
249
245
250
246
#[ test]
251
247
fn values_mismatch_columns_count ( ) {
252
- expect_parser_err (
248
+ expect_parser_err_msg (
253
249
b"INSERT INTO t VALUES (1), (1,2)" ,
254
250
"all VALUES must have the same number of terms" ,
255
251
) ;
256
252
}
257
253
258
254
#[ test]
259
255
fn alter_add_column_primary_key ( ) {
260
- expect_parser_err (
256
+ expect_parser_err_msg (
261
257
b"ALTER TABLE t ADD COLUMN c PRIMARY KEY" ,
262
258
"Cannot add a PRIMARY KEY column" ,
263
259
) ;
264
260
}
265
261
266
262
#[ test]
267
263
fn alter_add_column_unique ( ) {
268
- expect_parser_err (
264
+ expect_parser_err_msg (
269
265
b"ALTER TABLE t ADD COLUMN c UNIQUE" ,
270
266
"Cannot add a UNIQUE column" ,
271
267
) ;
272
268
}
273
269
274
270
#[ test]
275
271
fn alter_rename_same ( ) {
276
- expect_parser_err (
272
+ expect_parser_err_msg (
277
273
b"ALTER TABLE t RENAME TO t" ,
278
274
"there is already another table or index with this name: t" ,
279
275
) ;
280
276
}
281
277
282
278
#[ test]
283
279
fn natural_join_on ( ) {
284
- expect_parser_err (
280
+ expect_parser_err_msg (
285
281
b"SELECT x FROM t NATURAL JOIN t USING (x)" ,
286
282
"a NATURAL join may not have an ON or USING clause" ,
287
283
) ;
288
- expect_parser_err (
284
+ expect_parser_err_msg (
289
285
b"SELECT x FROM t NATURAL JOIN t ON t.x = t.x" ,
290
286
"a NATURAL join may not have an ON or USING clause" ,
291
287
) ;
292
288
}
293
289
294
- fn expect_parser_err ( input : & [ u8 ] , error_msg : & str ) {
290
+ fn expect_parser_err_msg ( input : & [ u8 ] , error_msg : & str ) {
291
+ expect_parser_err ( input, ParserError :: Custom ( error_msg. to_owned ( ) ) )
292
+ }
293
+ fn expect_parser_err ( input : & [ u8 ] , err : ParserError ) {
295
294
let r = parse ( input) ;
296
- if let Error :: ParserError ( ParserError :: Custom ( ref msg ) , _) = r. unwrap_err ( ) {
297
- assert_eq ! ( msg , error_msg ) ;
295
+ if let Error :: ParserError ( e , _) = r. unwrap_err ( ) {
296
+ assert_eq ! ( e , err ) ;
298
297
} else {
299
298
panic ! ( "unexpected error type" )
300
299
} ;
0 commit comments