Simplify arrow_cast tests (#1367)

This commit is contained in:
Andrew Lamb 2024-08-08 16:58:31 -04:00 committed by GitHub
parent 68a04cd402
commit 1e209d8741
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -4479,112 +4479,50 @@ fn test_unicode_string_literal() {
fn check_arrow_precedence(sql: &str, arrow_operator: BinaryOperator) { fn check_arrow_precedence(sql: &str, arrow_operator: BinaryOperator) {
assert_eq!( assert_eq!(
pg().verified_stmt(sql), pg().verified_expr(sql),
Statement::Query(Box::new(Query { Expr::BinaryOp {
with: None, left: Box::new(Expr::BinaryOp {
body: Box::new(SetExpr::Select(Box::new(Select { left: Box::new(Expr::Identifier(Ident {
distinct: None, value: "foo".to_string(),
top: None, quote_style: None,
projection: vec![SelectItem::UnnamedExpr(Expr::BinaryOp { })),
left: Box::new(Expr::BinaryOp { op: arrow_operator,
left: Box::new(Expr::Identifier(Ident { right: Box::new(Expr::Value(Value::SingleQuotedString("bar".to_string()))),
value: "foo".to_string(), }),
quote_style: None, op: BinaryOperator::Eq,
})), right: Box::new(Expr::Value(Value::SingleQuotedString("spam".to_string()))),
op: arrow_operator, }
right: Box::new(Expr::Value(Value::SingleQuotedString("bar".to_string()))),
}),
op: BinaryOperator::Eq,
right: Box::new(Expr::Value(Value::SingleQuotedString("spam".to_string()))),
})],
into: None,
from: vec![],
lateral_views: vec![],
prewhere: None,
selection: None,
group_by: GroupByExpr::Expressions(vec![], vec![]),
cluster_by: vec![],
distribute_by: vec![],
sort_by: vec![],
having: None,
named_window: vec![],
qualify: None,
window_before_qualify: false,
value_table_mode: None,
connect_by: None,
}))),
order_by: None,
limit: None,
limit_by: vec![],
offset: None,
fetch: None,
locks: vec![],
for_clause: None,
settings: None,
format_clause: None,
}))
) )
} }
#[test] #[test]
fn arrow_precedence() { fn arrow_precedence() {
check_arrow_precedence("SELECT foo -> 'bar' = 'spam'", BinaryOperator::Arrow); check_arrow_precedence("foo -> 'bar' = 'spam'", BinaryOperator::Arrow);
} }
#[test] #[test]
fn long_arrow_precedence() { fn long_arrow_precedence() {
check_arrow_precedence("SELECT foo ->> 'bar' = 'spam'", BinaryOperator::LongArrow); check_arrow_precedence("foo ->> 'bar' = 'spam'", BinaryOperator::LongArrow);
} }
#[test] #[test]
fn arrow_cast_precedence() { fn arrow_cast_precedence() {
// check this matches postgres where you would need `(foo -> 'bar')::TEXT` // check this matches postgres where you would need `(foo -> 'bar')::TEXT`
let stmt = pg().verified_stmt("SELECT foo -> 'bar'::TEXT"); let stmt = pg().verified_expr("foo -> 'bar'::TEXT");
assert_eq!( assert_eq!(
stmt, stmt,
Statement::Query(Box::new(Query { Expr::BinaryOp {
with: None, left: Box::new(Expr::Identifier(Ident {
body: Box::new(SetExpr::Select(Box::new(Select { value: "foo".to_string(),
distinct: None, quote_style: None,
top: None, })),
projection: vec![SelectItem::UnnamedExpr(Expr::BinaryOp { op: BinaryOperator::Arrow,
left: Box::new(Expr::Identifier(Ident { right: Box::new(Expr::Cast {
value: "foo".to_string(), kind: CastKind::DoubleColon,
quote_style: None, expr: Box::new(Expr::Value(Value::SingleQuotedString("bar".to_string()))),
})), data_type: DataType::Text,
op: BinaryOperator::Arrow, format: None,
right: Box::new(Expr::Cast { }),
kind: CastKind::DoubleColon, }
expr: Box::new(Expr::Value(Value::SingleQuotedString("bar".to_string()))),
data_type: DataType::Text,
format: None,
}),
})],
into: None,
from: vec![],
lateral_views: vec![],
prewhere: None,
selection: None,
group_by: GroupByExpr::Expressions(vec![], vec![]),
cluster_by: vec![],
distribute_by: vec![],
sort_by: vec![],
having: None,
named_window: vec![],
qualify: None,
window_before_qualify: false,
value_table_mode: None,
connect_by: None,
}))),
order_by: None,
limit: None,
limit_by: vec![],
offset: None,
fetch: None,
locks: vec![],
for_clause: None,
settings: None,
format_clause: None,
}))
) )
} }