use expect_test::expect;
use toasty_core::{
schema::db::Schema,
stmt::{self, BinaryOp, Expr, ExprAllOp, ExprAnyOp},
};
use toasty_sql::{Serializer, Statement as SqlStatement};
fn render(expr: Expr) -> String {
let values = stmt::Values::new(vec![Expr::record([expr])]);
let core_stmt: stmt::Statement = stmt::Query::values(values).into();
let stmt = SqlStatement::from(core_stmt);
let schema = Schema::default();
Serializer::postgresql(&schema).serialize(&stmt)
}
#[test]
fn any_op_eq() {
let expr = ExprAnyOp {
lhs: Box::new(Expr::arg(0)),
op: BinaryOp::Eq,
rhs: Box::new(Expr::arg(1)),
}
.into();
expect!["VALUES ($1 = ANY($2));"].assert_eq(&render(expr));
}
#[test]
fn all_op_ne() {
let expr = ExprAllOp {
lhs: Box::new(Expr::arg(0)),
op: BinaryOp::Ne,
rhs: Box::new(Expr::arg(1)),
}
.into();
expect!["VALUES ($1 <> ALL($2));"].assert_eq(&render(expr));
}
#[test]
fn any_op_gt_generalizes_to_other_operators() {
let expr = ExprAnyOp {
lhs: Box::new(Expr::arg(0)),
op: BinaryOp::Gt,
rhs: Box::new(Expr::arg(1)),
}
.into();
expect!["VALUES ($1 > ANY($2));"].assert_eq(&render(expr));
}