#![cfg(feature = "std")]
use graphitesql::{Connection, Value};
fn col(c: &Connection, sql: &str) -> Vec<String> {
c.query(sql)
.unwrap()
.rows
.into_iter()
.map(|mut r| match r.remove(0) {
Value::Text(s) => s,
Value::Null => String::from("<null>"),
other => panic!("unexpected {other:?}"),
})
.collect()
}
#[test]
fn windowed_group_concat_separator() {
let mut c = Connection::open_memory().unwrap();
c.execute("CREATE TABLE t(x)").unwrap();
c.execute("INSERT INTO t VALUES(1),(2),(3)").unwrap();
assert_eq!(
col(&c, "SELECT group_concat(x,'-') OVER (ORDER BY x) FROM t"),
vec!["1", "1-2", "1-2-3"]
);
assert_eq!(
col(&c, "SELECT group_concat(x,'|') OVER () FROM t"),
vec!["1|2|3", "1|2|3", "1|2|3"]
);
assert_eq!(
col(&c, "SELECT group_concat(x) OVER (ORDER BY x) FROM t"),
vec!["1", "1,2", "1,2,3"]
);
assert_eq!(
col(
&c,
"SELECT string_agg(CAST(x AS TEXT),'') OVER (ORDER BY x) FROM t"
),
vec!["1", "12", "123"]
);
}