test_string_funcs/
test_string_funcs.rs

1//! Test String Functions
2
3use qail_core::parse;
4use qail_core::transpiler::ToSql;
5
6fn main() {
7    println!("=== Testing String Functions ===\n");
8    
9    // Test 1: SUBSTRING
10    let query1 = "get users fields substring(phone from 2) as phone_trimmed";
11    println!("Query 1 (SUBSTRING):");
12    match parse(query1) {
13        Ok(cmd) => println!("  SQL: {}\n", cmd.to_sql()),
14        Err(e) => println!("  Error: {}\n", e),
15    }
16    
17    // Test 2: String concatenation
18    let query2 = "get users fields first_name || ' ' || last_name as full_name";
19    println!("Query 2 (Concat ||):");
20    match parse(query2) {
21        Ok(cmd) => println!("  SQL: {}\n", cmd.to_sql()),
22        Err(e) => println!("  Error: {}\n", e),
23    }
24    
25    // Test 2b: Simple function with one arg
26    let query2b = "get x fields upper(name)";
27    println!("Query 2b (UPPER - simple):");
28    match parse(query2b) {
29        Ok(cmd) => println!("  SQL: {}\n", cmd.to_sql()),
30        Err(e) => println!("  Error: {}\n", e),
31    }
32    
33    // Test 2c: Function with two identifier args
34    let query2c = "get x fields coalesce(a, b)";
35    println!("Query 2c (COALESCE - two idents):");
36    match parse(query2c) {
37        Ok(cmd) => println!("  SQL: {}\n", cmd.to_sql()),
38        Err(e) => println!("  Error: {}\n", e),
39    }
40    
41    // Test 2d: Function with string literal arg
42    let query2d = "get x fields coalesce(name, 'Unknown')";
43    println!("Query 2d (COALESCE - with string literal):");
44    match parse(query2d) {
45        Ok(cmd) => println!("  SQL: {}\n", cmd.to_sql()),
46        Err(e) => println!("  Error: {}\n", e),
47    }
48    
49    // Test 3: REPLACE with only identifiers
50    let query3a = "get users fields replace(phone, old, new)";
51    println!("Query 3a (REPLACE - identifiers only):");
52    match parse(query3a) {
53        Ok(cmd) => println!("  SQL: {}\n", cmd.to_sql()),
54        Err(e) => println!("  Error: {}\n", e),
55    }
56    
57    // Test 3b: REPLACE with string literals
58    let query3 = "get users fields replace(phone, '+', '')";
59    println!("Query 3 (REPLACE - with strings):");
60    match parse(query3) {
61        Ok(cmd) => println!("  SQL: {}\n", cmd.to_sql()),
62        Err(e) => println!("  Error: {}\n", e),
63    }
64}