1pub mod execution;
4pub mod planner;
5pub mod prelude {
6 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 assert!(true);
23 }
24
25 #[test]
26 fn test_gql_parser_creation() {
27 let parser = GqlParser::new();
28 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 assert!(result.is_ok() || result.is_err()); }
40
41 #[test]
42 fn test_expression_evaluation() {
43 use execution::executor::QueryExecutor;
44 let executor = QueryExecutor::new();
45
46 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 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 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 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 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 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 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 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 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}