gluesql_test_suite/function/
take.rs1use {
2 crate::*,
3 gluesql_core::{executor::EvaluateError, prelude::Value::*},
4};
5
6test_case!(take, {
7 let g = get_tester!();
8
9 g.run(
10 "
11 CREATE TABLE Take (
12 items LIST
13 );
14 ",
15 )
16 .await;
17 g.run(
18 r#"
19 INSERT INTO Take VALUES
20 (TAKE(CAST('[1, 2, 3, 4, 5]' AS LIST), 5));
21 "#,
22 )
23 .await;
24 g.test(
25 r#"select take(items, 0) as mygoodtake from Take;"#,
26 Ok(select!(
27 mygoodtake
28 List;
29 vec![]
30 )),
31 )
32 .await;
33 g.test(
34 r#"select take(items, 3) as mygoodtake from Take;"#,
35 Ok(select!(
36 mygoodtake
37 List;
38 vec![I64(1), I64(2), I64(3)]
39 )),
40 )
41 .await;
42 g.test(
43 r#"select take(items, 5) as mygoodtake from Take;"#,
44 Ok(select!(
45 mygoodtake
46 List;
47 vec![I64(1), I64(2), I64(3), I64(4), I64(5)]
48 )),
49 )
50 .await;
51 g.test(
52 r#"select take(items, 10) as mygoodtake from Take;"#,
53 Ok(select!(
54 mygoodtake
55 List;
56 vec![I64(1), I64(2), I64(3), I64(4), I64(5)]
57 )),
58 )
59 .await;
60 g.test(
61 r#"select take(NULL, 3) as mynulltake from Take;"#,
62 Ok(select_with_null!(mynulltake; Null)),
63 )
64 .await;
65 g.test(
66 r#"select take(items, NULL) as mynulltake from Take;"#,
67 Ok(select_with_null!(mynulltake; Null)),
68 )
69 .await;
70
71 g.test(
72 r#"select take(items, -5) as mymistake from Take;"#,
73 Err(EvaluateError::FunctionRequiresUSizeValue("TAKE".to_owned()).into()),
74 )
75 .await;
76 g.test(
77 r#"select take(items, 'TEST') as mymistake from Take;"#,
78 Err(EvaluateError::FunctionRequiresIntegerValue("TAKE".to_owned()).into()),
79 )
80 .await;
81 g.test(
82 r#"select take(0, 3) as mymistake from Take;"#,
83 Err(EvaluateError::ListTypeRequired.into()),
84 )
85 .await;
86});