use spg_engine::{Engine, QueryResult};
fn one(e: &mut Engine, sql: &str) -> String {
match e
.execute(sql)
.unwrap_or_else(|err| panic!("{sql}: {err:?}"))
{
QueryResult::Rows { rows, .. } => match &rows[0].values[0] {
spg_storage::Value::Text(s) => s.to_string(),
spg_storage::Value::Null => "NULL".to_string(),
other => panic!("{sql}: expected Text/Null, got {other:?}"),
},
other => panic!("{sql}: expected Rows, got {other:?}"),
}
}
#[test]
fn any_all_over_unknown_string_array() {
let mut e = Engine::new();
assert_eq!(one(&mut e, "SELECT (3 = ANY('{1,2,3}'))::text"), "true");
assert_eq!(one(&mut e, "SELECT (5 = ANY('{1,2,3}'))::text"), "false");
assert_eq!(one(&mut e, "SELECT ('x' = ANY('{x,y}'))::text"), "true");
assert_eq!(one(&mut e, "SELECT (5 = ALL('{5,5}'))::text"), "true");
assert_eq!(one(&mut e, "SELECT (3 > ANY('{1,2}'))::text"), "true");
assert_eq!(one(&mut e, "SELECT (5 > ALL('{1,2,3}'))::text"), "true");
assert_eq!(one(&mut e, "SELECT (2.5 = ANY('{1.5,2.5}'))::text"), "true");
assert_eq!(one(&mut e, "SELECT (true = ANY('{t,f}'))::text"), "true");
assert_eq!(
one(
&mut e,
"SELECT ('2020-01-01'::date = ANY('{2020-01-01,2021-06-15}'))::text"
),
"true"
);
assert_eq!(one(&mut e, "SELECT (NULL = ANY('{1,2}'))::text"), "NULL");
assert_eq!(one(&mut e, "SELECT (1 = ANY('{}'))::text"), "false");
assert_eq!(
one(&mut e, "SELECT (3 = ANY('{1,2,3}'::int[]))::text"),
"true"
);
assert_eq!(one(&mut e, "SELECT (3 = ANY(ARRAY[1,2,3]))::text"), "true");
}