gluesql_test_suite/function/
repeat.rs1use {
2 crate::*,
3 gluesql_core::{
4 error::{EvaluateError, TranslateError},
5 prelude::{Payload, Value},
6 },
7};
8
9test_case!(repeat, {
10 let g = get_tester!();
11
12 let test_cases = [
13 (
14 "CREATE TABLE Item (name TEXT DEFAULT REPEAT('hello', 2))",
15 Ok(Payload::Create),
16 ),
17 ("INSERT INTO Item VALUES ('hello')", Ok(Payload::Insert(1))),
18 (
19 "SELECT REPEAT(name, 2) AS test FROM Item",
20 Ok(select!(
21 "test"
22 Value::Str;
23 "hellohello".to_owned()
24 )),
25 ),
26 (
27 "SELECT REPEAT('abcd') AS test FROM Item",
28 Err(TranslateError::FunctionArgsLengthNotMatching {
29 name: "REPEAT".to_owned(),
30 expected: 2,
31 found: 1,
32 }
33 .into()),
34 ),
35 (
36 "SELECT REPEAT('abcd', 2, 2) AS test FROM Item",
37 Err(TranslateError::FunctionArgsLengthNotMatching {
38 name: "REPEAT".to_owned(),
39 expected: 2,
40 found: 3,
41 }
42 .into()),
43 ),
44 (
45 "SELECT REPEAT(1, 1) AS test FROM Item",
46 Err(EvaluateError::FunctionRequiresStringValue("REPEAT".to_owned()).into()),
47 ),
48 (
49 "SELECT REPEAT(name, null) AS test FROM Item",
50 Ok(select_with_null!(test; Value::Null)),
51 ),
52 (
53 "CREATE TABLE NullTest (name TEXT null)",
54 Ok(Payload::Create),
55 ),
56 ("INSERT INTO NullTest VALUES (null)", Ok(Payload::Insert(1))),
57 (
58 "SELECT REPEAT(name, 2) AS test FROM NullTest",
59 Ok(select_with_null!(test; Value::Null)),
60 ),
61 ];
62
63 for (sql, expected) in test_cases {
64 g.test(sql, expected).await;
65 }
66});