Skip to content

Commit 1e209d8

Browse files
authored
Simplify arrow_cast tests (#1367)
1 parent 68a04cd commit 1e209d8

File tree

1 file changed

+29
-91
lines changed

1 file changed

+29
-91
lines changed

tests/sqlparser_postgres.rs

+29-91
Original file line numberDiff line numberDiff line change
@@ -4479,112 +4479,50 @@ fn test_unicode_string_literal() {
44794479

44804480
fn check_arrow_precedence(sql: &str, arrow_operator: BinaryOperator) {
44814481
assert_eq!(
4482-
pg().verified_stmt(sql),
4483-
Statement::Query(Box::new(Query {
4484-
with: None,
4485-
body: Box::new(SetExpr::Select(Box::new(Select {
4486-
distinct: None,
4487-
top: None,
4488-
projection: vec![SelectItem::UnnamedExpr(Expr::BinaryOp {
4489-
left: Box::new(Expr::BinaryOp {
4490-
left: Box::new(Expr::Identifier(Ident {
4491-
value: "foo".to_string(),
4492-
quote_style: None,
4493-
})),
4494-
op: arrow_operator,
4495-
right: Box::new(Expr::Value(Value::SingleQuotedString("bar".to_string()))),
4496-
}),
4497-
op: BinaryOperator::Eq,
4498-
right: Box::new(Expr::Value(Value::SingleQuotedString("spam".to_string()))),
4499-
})],
4500-
into: None,
4501-
from: vec![],
4502-
lateral_views: vec![],
4503-
prewhere: None,
4504-
selection: None,
4505-
group_by: GroupByExpr::Expressions(vec![], vec![]),
4506-
cluster_by: vec![],
4507-
distribute_by: vec![],
4508-
sort_by: vec![],
4509-
having: None,
4510-
named_window: vec![],
4511-
qualify: None,
4512-
window_before_qualify: false,
4513-
value_table_mode: None,
4514-
connect_by: None,
4515-
}))),
4516-
order_by: None,
4517-
limit: None,
4518-
limit_by: vec![],
4519-
offset: None,
4520-
fetch: None,
4521-
locks: vec![],
4522-
for_clause: None,
4523-
settings: None,
4524-
format_clause: None,
4525-
}))
4482+
pg().verified_expr(sql),
4483+
Expr::BinaryOp {
4484+
left: Box::new(Expr::BinaryOp {
4485+
left: Box::new(Expr::Identifier(Ident {
4486+
value: "foo".to_string(),
4487+
quote_style: None,
4488+
})),
4489+
op: arrow_operator,
4490+
right: Box::new(Expr::Value(Value::SingleQuotedString("bar".to_string()))),
4491+
}),
4492+
op: BinaryOperator::Eq,
4493+
right: Box::new(Expr::Value(Value::SingleQuotedString("spam".to_string()))),
4494+
}
45264495
)
45274496
}
45284497

45294498
#[test]
45304499
fn arrow_precedence() {
4531-
check_arrow_precedence("SELECT foo -> 'bar' = 'spam'", BinaryOperator::Arrow);
4500+
check_arrow_precedence("foo -> 'bar' = 'spam'", BinaryOperator::Arrow);
45324501
}
45334502

45344503
#[test]
45354504
fn long_arrow_precedence() {
4536-
check_arrow_precedence("SELECT foo ->> 'bar' = 'spam'", BinaryOperator::LongArrow);
4505+
check_arrow_precedence("foo ->> 'bar' = 'spam'", BinaryOperator::LongArrow);
45374506
}
45384507

45394508
#[test]
45404509
fn arrow_cast_precedence() {
45414510
// check this matches postgres where you would need `(foo -> 'bar')::TEXT`
4542-
let stmt = pg().verified_stmt("SELECT foo -> 'bar'::TEXT");
4511+
let stmt = pg().verified_expr("foo -> 'bar'::TEXT");
45434512
assert_eq!(
45444513
stmt,
4545-
Statement::Query(Box::new(Query {
4546-
with: None,
4547-
body: Box::new(SetExpr::Select(Box::new(Select {
4548-
distinct: None,
4549-
top: None,
4550-
projection: vec![SelectItem::UnnamedExpr(Expr::BinaryOp {
4551-
left: Box::new(Expr::Identifier(Ident {
4552-
value: "foo".to_string(),
4553-
quote_style: None,
4554-
})),
4555-
op: BinaryOperator::Arrow,
4556-
right: Box::new(Expr::Cast {
4557-
kind: CastKind::DoubleColon,
4558-
expr: Box::new(Expr::Value(Value::SingleQuotedString("bar".to_string()))),
4559-
data_type: DataType::Text,
4560-
format: None,
4561-
}),
4562-
})],
4563-
into: None,
4564-
from: vec![],
4565-
lateral_views: vec![],
4566-
prewhere: None,
4567-
selection: None,
4568-
group_by: GroupByExpr::Expressions(vec![], vec![]),
4569-
cluster_by: vec![],
4570-
distribute_by: vec![],
4571-
sort_by: vec![],
4572-
having: None,
4573-
named_window: vec![],
4574-
qualify: None,
4575-
window_before_qualify: false,
4576-
value_table_mode: None,
4577-
connect_by: None,
4578-
}))),
4579-
order_by: None,
4580-
limit: None,
4581-
limit_by: vec![],
4582-
offset: None,
4583-
fetch: None,
4584-
locks: vec![],
4585-
for_clause: None,
4586-
settings: None,
4587-
format_clause: None,
4588-
}))
4514+
Expr::BinaryOp {
4515+
left: Box::new(Expr::Identifier(Ident {
4516+
value: "foo".to_string(),
4517+
quote_style: None,
4518+
})),
4519+
op: BinaryOperator::Arrow,
4520+
right: Box::new(Expr::Cast {
4521+
kind: CastKind::DoubleColon,
4522+
expr: Box::new(Expr::Value(Value::SingleQuotedString("bar".to_string()))),
4523+
data_type: DataType::Text,
4524+
format: None,
4525+
}),
4526+
}
45894527
)
45904528
}

0 commit comments

Comments
 (0)