Add tests for SQL array::group() function

This commit is contained in:
Tobie Morgan Hitchcock 2023-01-07 20:02:49 +00:00
parent 44f064a686
commit 9c5178ef0a
2 changed files with 28 additions and 1 deletions

View file

@ -53,7 +53,7 @@ pub fn flatten((arg,): (Value,)) -> Result<Value, Error> {
pub fn group((arg,): (Value,)) -> Result<Value, Error> { pub fn group((arg,): (Value,)) -> Result<Value, Error> {
Ok(match arg { Ok(match arg {
Value::Array(v) => v.uniq().flatten().into(), Value::Array(v) => v.flatten().uniq().into(),
_ => Value::None, _ => Value::None,
}) })
} }

View file

@ -172,6 +172,33 @@ async fn function_array_flatten() -> Result<(), Error> {
Ok(()) Ok(())
} }
#[tokio::test]
async fn function_array_group() -> Result<(), Error> {
let sql = r#"
RETURN array::group([]);
RETURN array::group(3);
RETURN array::group([ [1,2,3,4], [3,4,5,6] ]);
"#;
let dbs = Datastore::new("memory").await?;
let ses = Session::for_kv().with_ns("test").with_db("test");
let res = &mut dbs.execute(&sql, &ses, None, false).await?;
assert_eq!(res.len(), 3);
//
let tmp = res.remove(0).result?;
let val = Value::parse("[]");
assert_eq!(tmp, val);
//
let tmp = res.remove(0).result?;
let val = Value::None;
assert_eq!(tmp, val);
//
let tmp = res.remove(0).result?;
let val = Value::parse("[1,2,3,4,5,6]");
assert_eq!(tmp, val);
//
Ok(())
}
#[tokio::test] #[tokio::test]
async fn function_array_insert() -> Result<(), Error> { async fn function_array_insert() -> Result<(), Error> {
let sql = r#" let sql = r#"