gluesql_test_suite/function/
append.rs

1use {
2    crate::*,
3    gluesql_core::{
4        error::EvaluateError,
5        prelude::{Payload, Value::*},
6    },
7};
8test_case!(append, {
9    let g = get_tester!();
10
11    g.run(
12        "
13        CREATE TABLE Append (
14            id INTEGER,
15            items LIST,
16            element INTEGER,
17            element2 TEXT
18        );
19    ",
20    )
21    .await;
22    g.run(
23        r#"
24            INSERT INTO Append VALUES
25            (1, '[1, 2, 3]', 4, 'Foo');
26        "#,
27    )
28    .await;
29    g.test(
30        r#"select append(items, element) as myappend from Append;"#,
31        Ok(select!(
32           myappend
33           List;
34           vec![I64(1), I64(2), I64(3), I64(4)]
35        )),
36    )
37    .await;
38    g.test(
39        r#"select append(items, element2) as myappend from Append;"#,
40        Ok(select!(
41           myappend
42           List;
43           vec![I64(1), I64(2), I64(3), Str("Foo".into())]
44        )),
45    )
46    .await;
47
48    g.test(
49        r#"select append(element, element2) as myappend from Append"#,
50        Err(EvaluateError::ListTypeRequired.into()),
51    )
52    .await;
53
54    g.test(
55        r#"CREATE TABLE Foo (
56                elements LIST
57            );"#,
58        Ok(Payload::Create),
59    )
60    .await;
61
62    g.run(
63        r#"
64            INSERT INTO Foo VALUES (APPEND(CAST('[1, 2, 3]' AS LIST), 4));
65        "#,
66    )
67    .await;
68    g.test(
69        r#"select elements as myappend from Foo;"#,
70        Ok(select!(
71           myappend
72           List;
73           vec![I64(1), I64(2), I64(3), I64(4)]
74        )),
75    )
76    .await;
77});