kotoba_execution/
lib.rs

1//! kotoba-execution - Kotoba Execution Components
2
3pub mod execution;
4pub mod planner;
5pub mod prelude {
6    // Re-export commonly used items
7    pub use crate::execution::*;
8    pub use crate::planner::*;
9}
10
11#[cfg(test)]
12mod tests {
13    use super::*;
14    use crate::prelude::*;
15    use kotoba_core::{types::*, ir::*};
16    use std::collections::HashMap;
17
18    #[test]
19    fn test_query_executor_creation() {
20        let executor = QueryExecutor::new();
21        // Just check that it can be created
22        assert!(true);
23    }
24
25    #[test]
26    fn test_gql_parser_creation() {
27        let parser = GqlParser::new();
28        // Just check that it can be created
29        assert!(true);
30    }
31
32    #[test]
33    fn test_gql_parser_tokenize() {
34        let mut parser = GqlParser::new();
35        let result = parser.parse("MATCH (n:Person) RETURN n");
36        // For now, just check that parsing doesn't panic
37        // TODO: Add proper test cases once implementation is complete
38        assert!(result.is_ok() || result.is_err()); // Accept both for now
39    }
40
41    #[test]
42    fn test_expression_evaluation() {
43        use execution::executor::QueryExecutor;
44        let executor = QueryExecutor::new();
45
46        // Create a test row
47        let mut row_data = HashMap::new();
48        row_data.insert("name".to_string(), Value::String("Alice".to_string()));
49        row_data.insert("age".to_string(), Value::Int(30));
50        let row = Row { values: row_data };
51
52        // Test variable evaluation
53        let expr = Expr::Var("name".to_string());
54        let result = executor.evaluate_expr(&row, &expr);
55        assert!(result.is_ok());
56        assert_eq!(result.unwrap(), Value::String("Alice".to_string()));
57
58        // Test constant evaluation
59        let expr = Expr::Const(Value::Int(42));
60        let result = executor.evaluate_expr(&row, &expr);
61        assert!(result.is_ok());
62        assert_eq!(result.unwrap(), Value::Int(42));
63    }
64
65    #[test]
66    fn test_math_functions() {
67        use execution::executor::QueryExecutor;
68        let executor = QueryExecutor::new();
69
70        let row = Row { values: HashMap::new() };
71
72        // Test abs function
73        let expr = Expr::Fn {
74            fn_: "abs".to_string(),
75            args: vec![Expr::Const(Value::Int(-5))],
76        };
77        let result = executor.evaluate_expr(&row, &expr);
78        assert!(result.is_ok());
79        assert_eq!(result.unwrap(), Value::Int(5));
80
81        // Test sqrt function
82        let expr = Expr::Fn {
83            fn_: "sqrt".to_string(),
84            args: vec![Expr::Const(Value::Int(9))],
85        };
86        let result = executor.evaluate_expr(&row, &expr);
87        assert!(result.is_ok());
88        assert_eq!(result.unwrap(), Value::Int(3));
89    }
90
91    #[test]
92    fn test_string_functions() {
93        use execution::executor::QueryExecutor;
94        let executor = QueryExecutor::new();
95
96        let row = Row { values: HashMap::new() };
97
98        // Test length function
99        let expr = Expr::Fn {
100            fn_: "length".to_string(),
101            args: vec![Expr::Const(Value::String("hello".to_string()))],
102        };
103        let result = executor.evaluate_expr(&row, &expr);
104        assert!(result.is_ok());
105        assert_eq!(result.unwrap(), Value::Int(5));
106
107        // Test toUpper function
108        let expr = Expr::Fn {
109            fn_: "toUpper".to_string(),
110            args: vec![Expr::Const(Value::String("hello".to_string()))],
111        };
112        let result = executor.evaluate_expr(&row, &expr);
113        assert!(result.is_ok());
114        assert_eq!(result.unwrap(), Value::String("HELLO".to_string()));
115    }
116
117    #[test]
118    fn test_conversion_functions() {
119        use execution::executor::QueryExecutor;
120        let executor = QueryExecutor::new();
121
122        let row = Row { values: HashMap::new() };
123
124        // Test toString function
125        let expr = Expr::Fn {
126            fn_: "toString".to_string(),
127            args: vec![Expr::Const(Value::Int(42))],
128        };
129        let result = executor.evaluate_expr(&row, &expr);
130        assert!(result.is_ok());
131        assert_eq!(result.unwrap(), Value::String("42".to_string()));
132
133        // Test toInteger function
134        let expr = Expr::Fn {
135            fn_: "toInteger".to_string(),
136            args: vec![Expr::Const(Value::String("123".to_string()))],
137        };
138        let result = executor.evaluate_expr(&row, &expr);
139        assert!(result.is_ok());
140        assert_eq!(result.unwrap(), Value::Int(123));
141    }
142}