Merge commit 'd803bfe2b1fe7f5e219e50ac20d6801a0a58ac75' as 'vendor/ruvector'

This commit is contained in:
ruv
2026-02-28 14:39:40 -05:00
7854 changed files with 3522914 additions and 0 deletions

View File

@@ -0,0 +1,121 @@
//! Standalone example demonstrating the Cypher parser
//! Run with: cargo run --example test_cypher_parser
use ruvector_graph::cypher::{ast::*, parse_cypher};
fn main() {
println!("=== Cypher Parser Test Suite ===\n");
// Test 1: Simple MATCH
println!("Test 1: Simple MATCH query");
let query1 = "MATCH (n:Person) RETURN n";
match parse_cypher(query1) {
Ok(ast) => {
println!("✓ Parsed successfully");
println!(" Statements: {}", ast.statements.len());
println!(" Read-only: {}", ast.is_read_only());
}
Err(e) => println!("✗ Parse error: {}", e),
}
println!();
// Test 2: MATCH with WHERE
println!("Test 2: MATCH with WHERE clause");
let query2 = "MATCH (n:Person) WHERE n.age > 30 RETURN n.name";
match parse_cypher(query2) {
Ok(_) => println!("✓ Parsed successfully"),
Err(e) => println!("✗ Parse error: {}", e),
}
println!();
// Test 3: Relationship pattern
println!("Test 3: Relationship pattern");
let query3 = "MATCH (a:Person)-[r:KNOWS]->(b:Person) RETURN a, r, b";
match parse_cypher(query3) {
Ok(_) => println!("✓ Parsed successfully"),
Err(e) => println!("✗ Parse error: {}", e),
}
println!();
// Test 4: CREATE node
println!("Test 4: CREATE node");
let query4 = "CREATE (n:Person {name: 'Alice', age: 30})";
match parse_cypher(query4) {
Ok(ast) => {
println!("✓ Parsed successfully");
println!(" Read-only: {}", ast.is_read_only());
}
Err(e) => println!("✗ Parse error: {}", e),
}
println!();
// Test 5: Hyperedge (N-ary relationship)
println!("Test 5: Hyperedge pattern");
let query5 = "MATCH (a)-[r:TRANSACTION]->(b, c, d) RETURN a, r, b, c, d";
match parse_cypher(query5) {
Ok(ast) => {
println!("✓ Parsed successfully");
println!(" Has hyperedges: {}", ast.has_hyperedges());
}
Err(e) => println!("✗ Parse error: {}", e),
}
println!();
// Test 6: Aggregation functions
println!("Test 6: Aggregation functions");
let query6 = "MATCH (n:Person) RETURN COUNT(n), AVG(n.age), MAX(n.salary)";
match parse_cypher(query6) {
Ok(_) => println!("✓ Parsed successfully"),
Err(e) => println!("✗ Parse error: {}", e),
}
println!();
// Test 7: Complex query with ORDER BY and LIMIT
println!("Test 7: Complex query with ORDER BY and LIMIT");
let query7 = r#"
MATCH (a:Person)-[r:KNOWS]->(b:Person)
WHERE a.age > 30 AND b.name = 'Alice'
RETURN a.name, b.name, r.since
ORDER BY r.since DESC
LIMIT 10
"#;
match parse_cypher(query7) {
Ok(_) => println!("✓ Parsed successfully"),
Err(e) => println!("✗ Parse error: {}", e),
}
println!();
// Test 8: MERGE with ON CREATE
println!("Test 8: MERGE with ON CREATE");
let query8 = "MERGE (n:Person {name: 'Bob'}) ON CREATE SET n.created = 2024";
match parse_cypher(query8) {
Ok(_) => println!("✓ Parsed successfully"),
Err(e) => println!("✗ Parse error: {}", e),
}
println!();
// Test 9: WITH clause (query chaining)
println!("Test 9: WITH clause");
let query9 = r#"
MATCH (n:Person)
WITH n, n.age AS age
WHERE age > 30
RETURN n.name, age
"#;
match parse_cypher(query9) {
Ok(_) => println!("✓ Parsed successfully"),
Err(e) => println!("✗ Parse error: {}", e),
}
println!();
// Test 10: Variable-length path
println!("Test 10: Variable-length path");
let query10 = "MATCH p = (a:Person)-[*1..3]->(b:Person) RETURN p";
match parse_cypher(query10) {
Ok(_) => println!("✓ Parsed successfully"),
Err(e) => println!("✗ Parse error: {}", e),
}
println!();
println!("=== All tests completed ===");
}