use spg_engine::{Engine, QueryResult};
fn text(e: &mut Engine, sql: &str) -> String {
match e.execute(sql).unwrap_or_else(|x| panic!("{sql}: {x:?}")) {
QueryResult::Rows { rows, .. } => spg_engine::eval::value_to_text(&rows[0].values[0]),
other => panic!("{sql}: {other:?}"),
}
}
#[test]
fn variadic_array_spreads_into_the_call() {
let mut e = Engine::new();
assert_eq!(
text(&mut e, "SELECT concat(VARIADIC ARRAY['a','b','c'])"),
"abc"
);
assert_eq!(text(&mut e, "SELECT concat(VARIADIC ARRAY[1,2,3])"), "123");
assert_eq!(
text(&mut e, "SELECT concat_ws('-', VARIADIC ARRAY[1,2,3])"),
"1-2-3"
);
assert_eq!(
text(
&mut e,
"SELECT format('%s/%s/%s', VARIADIC ARRAY['x','y','z'])"
),
"x/y/z"
);
}
#[test]
fn variadic_empty_array_contributes_nothing() {
let mut e = Engine::new();
assert_eq!(
text(&mut e, "SELECT concat_ws(',', VARIADIC ARRAY[]::text[])"),
""
);
assert_eq!(text(&mut e, "SELECT concat(VARIADIC ARRAY[]::text[])"), "");
}
#[test]
fn variadic_round_trips_through_display() {
use spg_sql::parser::parse_statement;
let stmt = parse_statement("SELECT concat_ws(',', VARIADIC ARRAY[1, 2])").unwrap();
let rendered = stmt.to_string();
assert!(
rendered.contains("VARIADIC ARRAY[1, 2]"),
"unexpected Display: {rendered}"
);
}