gluesql_test_suite/function/
floor.rs

1use {
2    crate::*,
3    gluesql_core::{
4        error::{EvaluateError, TranslateError},
5        prelude::Value::*,
6    },
7};
8
9test_case!(floor, {
10    let g = get_tester!();
11
12    let test_cases = [
13        (
14            r#"
15            SELECT 
16                FLOOR(0.3) as floor1, 
17                FLOOR(-0.8) as floor2, 
18                FLOOR(10) as floor3, 
19                FLOOR(6.87421) as floor4 
20            ;"#,
21            Ok(select!(
22                floor1 | floor2              | floor3 | floor4
23                F64    | F64                 | F64    | F64;
24                0.0      f64::from(-1)   10.0     6.0
25            )),
26        ),
27        (
28            "SELECT FLOOR('string') AS floor",
29            Err(EvaluateError::FunctionRequiresFloatValue(String::from("FLOOR")).into()),
30        ),
31        (
32            "SELECT FLOOR(NULL) AS floor",
33            Ok(select_with_null!(floor; Null)),
34        ),
35        (
36            "SELECT FLOOR(TRUE) AS floor",
37            Err(EvaluateError::FunctionRequiresFloatValue(String::from("FLOOR")).into()),
38        ),
39        (
40            "SELECT FLOOR(FALSE) AS floor",
41            Err(EvaluateError::FunctionRequiresFloatValue(String::from("FLOOR")).into()),
42        ),
43        (
44            "SELECT FLOOR('string' TO DAY) AS floor",
45            Err(TranslateError::UnsupportedExpr("FLOOR('string' TO DAY)".to_owned()).into()),
46        ),
47    ];
48
49    for (sql, expected) in test_cases {
50        g.test(sql, expected).await;
51    }
52});