use std::error::Error;

use sqlx::{Postgres, QueryBuilder};

use crate::Expr;

#[test]
fn sql_converts_to_query_builder() -> Result<(), Box<dyn Error>> {
    let expr = Expr::try_from("3 + 5 < 10")?;
    assert_eq!(
        QueryBuilder::<'_, Postgres>::from(expr).sql(),
        "(($1) + ($2)) < ($3)",
    );
    Ok(())
}

#[test]
fn cmp_array_modifier_round_trips() -> Result<(), Box<dyn Error>> {
    let expr = Expr::try_from("1 = 2 and 3 < any(array[4])")?;
    assert_eq!(
        QueryBuilder::<'_, Postgres>::from(expr).sql(),
        "(($1) = ($2)) and (($3) < any (array[($4)]))",
    );
    Ok(())
}
