Skip to content

Commit 008d821

Browse files
committed
Further simplify test cases to use verified_stmt
1 parent 011005e commit 008d821

File tree

1 file changed

+15
-209
lines changed

1 file changed

+15
-209
lines changed

Diff for: tests/sqlparser_mssql.rs

+15-209
Original file line numberDiff line numberDiff line change
@@ -246,160 +246,22 @@ fn parse_create_function() {
246246
RETURN @foo; \
247247
END\
248248
";
249-
assert_eq!(
250-
ms().verified_stmt(multi_statement_function),
251-
sqlparser::ast::Statement::CreateFunction(CreateFunction {
252-
or_alter: false,
253-
or_replace: false,
254-
temporary: false,
255-
if_not_exists: false,
256-
name: ObjectName::from(vec![Ident::new("some_scalar_udf")]),
257-
args: Some(vec![
258-
OperateFunctionArg {
259-
mode: None,
260-
name: Some(Ident::new("@foo")),
261-
data_type: DataType::Int(None),
262-
default_expr: None,
263-
},
264-
OperateFunctionArg {
265-
mode: None,
266-
name: Some(Ident::new("@bar")),
267-
data_type: DataType::Varchar(Some(CharacterLength::IntegerLength {
268-
length: 256,
269-
unit: None
270-
})),
271-
default_expr: None,
272-
},
273-
]),
274-
return_type: Some(DataType::Int(None)),
275-
function_body: Some(CreateFunctionBody::AsBeginEnd(BeginEndStatements {
276-
begin_token: AttachedToken::empty(),
277-
statements: vec![
278-
Statement::Set(Set::SingleAssignment {
279-
scope: None,
280-
hivevar: false,
281-
variable: ObjectName::from(vec!["@foo".into()]),
282-
values: vec![sqlparser::ast::Expr::BinaryOp {
283-
left: Box::new(sqlparser::ast::Expr::Identifier(Ident::new("@foo"))),
284-
op: sqlparser::ast::BinaryOperator::Plus,
285-
right: Box::new(Expr::Value(number("1").with_empty_span())),
286-
}],
287-
}),
288-
Statement::Return(ReturnStatement {
289-
value: Some(ReturnStatementValue::Expr(Expr::Identifier(Ident::new(
290-
"@foo"
291-
)))),
292-
}),
293-
],
294-
end_token: AttachedToken::empty(),
295-
})),
296-
behavior: None,
297-
called_on_null: None,
298-
parallel: None,
299-
using: None,
300-
language: None,
301-
determinism_specifier: None,
302-
options: None,
303-
remote_connection: None,
304-
}),
305-
);
249+
let _ = ms().verified_stmt(multi_statement_function);
306250

307-
let create_function_with_conditional = r#"
308-
CREATE FUNCTION some_scalar_udf()
309-
RETURNS INT
310-
AS
311-
BEGIN
312-
IF 1=2
313-
BEGIN
314-
RETURN 1;
315-
END
316-
317-
RETURN 0;
318-
END
319-
"#;
320-
let create_stmt = ms().one_statement_parses_to(create_function_with_conditional, "");
321-
assert_eq!(
322-
create_stmt,
323-
Statement::CreateFunction(CreateFunction {
324-
or_alter: false,
325-
or_replace: false,
326-
temporary: false,
327-
if_not_exists: false,
328-
name: ObjectName::from(vec![Ident::new("some_scalar_udf")]),
329-
args: Some(vec![]),
330-
return_type: Some(DataType::Int(None)),
331-
function_body: Some(CreateFunctionBody::AsBeginEnd(BeginEndStatements {
332-
begin_token: AttachedToken::empty(),
333-
statements: vec![
334-
Statement::If(IfStatement {
335-
if_block: ConditionalStatementBlock {
336-
start_token: AttachedToken(TokenWithSpan::wrap(
337-
sqlparser::tokenizer::Token::Word(sqlparser::tokenizer::Word {
338-
value: "IF".to_string(),
339-
quote_style: None,
340-
keyword: Keyword::IF
341-
})
342-
)),
343-
condition: Some(Expr::BinaryOp {
344-
left: Box::new(Expr::Value(number("1").with_empty_span())),
345-
op: sqlparser::ast::BinaryOperator::Eq,
346-
right: Box::new(Expr::Value(number("2").with_empty_span())),
347-
}),
348-
then_token: None,
349-
conditional_statements: ConditionalStatements::BeginEnd(
350-
BeginEndStatements {
351-
begin_token: AttachedToken(TokenWithSpan::wrap(
352-
sqlparser::tokenizer::Token::Word(
353-
sqlparser::tokenizer::Word {
354-
value: "BEGIN".to_string(),
355-
quote_style: None,
356-
keyword: Keyword::BEGIN
357-
}
358-
)
359-
)),
360-
statements: vec![Statement::Return(ReturnStatement {
361-
value: Some(ReturnStatementValue::Expr(Expr::Value(
362-
(number("1")).with_empty_span()
363-
))),
364-
})],
365-
end_token: AttachedToken(TokenWithSpan::wrap(
366-
sqlparser::tokenizer::Token::Word(
367-
sqlparser::tokenizer::Word {
368-
value: "END".to_string(),
369-
quote_style: None,
370-
keyword: Keyword::END
371-
}
372-
)
373-
)),
374-
}
375-
),
376-
},
377-
elseif_blocks: vec![],
378-
else_block: None,
379-
end_token: None,
380-
}),
381-
Statement::Return(ReturnStatement {
382-
value: Some(ReturnStatementValue::Expr(Expr::Value(
383-
(number("0")).with_empty_span()
384-
))),
385-
}),
386-
],
387-
end_token: AttachedToken::empty(),
388-
})),
389-
behavior: None,
390-
called_on_null: None,
391-
parallel: None,
392-
using: None,
393-
language: None,
394-
determinism_specifier: None,
395-
options: None,
396-
remote_connection: None,
397-
})
398-
);
399-
}
251+
let create_function_with_conditional = "\
252+
CREATE FUNCTION some_scalar_udf() \
253+
RETURNS INT \
254+
AS \
255+
BEGIN \
256+
IF 1 = 2 \
257+
BEGIN \
258+
RETURN 1; \
259+
END; \
260+
RETURN 0; \
261+
END\
262+
";
263+
let _ = ms().verified_stmt(create_function_with_conditional);
400264

401-
#[test]
402-
fn parse_mssql_create_function() {
403265
let create_or_alter_function = "\
404266
CREATE OR ALTER FUNCTION some_scalar_udf(@foo INT, @bar VARCHAR(256)) \
405267
RETURNS INT \
@@ -409,63 +271,7 @@ fn parse_mssql_create_function() {
409271
RETURN @foo; \
410272
END\
411273
";
412-
assert_eq!(
413-
ms().verified_stmt(create_or_alter_function),
414-
sqlparser::ast::Statement::CreateFunction(CreateFunction {
415-
or_alter: true,
416-
or_replace: false,
417-
temporary: false,
418-
if_not_exists: false,
419-
name: ObjectName::from(vec![Ident::new("some_scalar_udf")]),
420-
args: Some(vec![
421-
OperateFunctionArg {
422-
mode: None,
423-
name: Some(Ident::new("@foo")),
424-
data_type: DataType::Int(None),
425-
default_expr: None,
426-
},
427-
OperateFunctionArg {
428-
mode: None,
429-
name: Some(Ident::new("@bar")),
430-
data_type: DataType::Varchar(Some(CharacterLength::IntegerLength {
431-
length: 256,
432-
unit: None
433-
})),
434-
default_expr: None,
435-
},
436-
]),
437-
return_type: Some(DataType::Int(None)),
438-
function_body: Some(CreateFunctionBody::AsBeginEnd(BeginEndStatements {
439-
begin_token: AttachedToken::empty(),
440-
statements: vec![
441-
Statement::Set(Set::SingleAssignment {
442-
scope: None,
443-
hivevar: false,
444-
variable: ObjectName::from(vec!["@foo".into()]),
445-
values: vec![sqlparser::ast::Expr::BinaryOp {
446-
left: Box::new(sqlparser::ast::Expr::Identifier(Ident::new("@foo"))),
447-
op: sqlparser::ast::BinaryOperator::Plus,
448-
right: Box::new(Expr::Value(number("1").with_empty_span())),
449-
}],
450-
}),
451-
Statement::Return(ReturnStatement {
452-
value: Some(ReturnStatementValue::Expr(Expr::Identifier(Ident::new(
453-
"@foo"
454-
)))),
455-
}),
456-
],
457-
end_token: AttachedToken::empty(),
458-
})),
459-
behavior: None,
460-
called_on_null: None,
461-
parallel: None,
462-
using: None,
463-
language: None,
464-
determinism_specifier: None,
465-
options: None,
466-
remote_connection: None,
467-
}),
468-
);
274+
let _ = ms().verified_stmt(create_or_alter_function);
469275
}
470276

471277
#[test]

0 commit comments

Comments
 (0)