relate-parser 1.5.0

Cypher lexer, parser, and AST for the Relate graph database
Documentation
//! MERGE parse tests: the clause's action tail follows the openCypher
//! grammar's `(ON CREATE SET … | ON MATCH SET …)*` — the same kind may
//! repeat after one pattern, and every clause's items accumulate in
//! written order.

use super::*;

#[test]
fn test_parse_merge() {
    let stmt = parse("MERGE (n:Person {name: 'Bob'}) ON CREATE SET n.created = true ON MATCH SET n.updated = true").unwrap();
    match &stmt.clauses[0] {
        Clause::Merge(m) => {
            assert_eq!(m.on_create.len(), 1);
            assert_eq!(m.on_match.len(), 1);
        }
        _ => panic!("expected merge"),
    }
}

/// The same action kind may repeat after a MERGE: every clause's items
/// accumulate in written order — a repeat never drops the earlier
/// clause's items.
#[test]
fn test_parse_merge_repeated_action_clauses_accumulate() {
    let stmt = parse(
        "MERGE (n:Person {name: 'Bob'}) \
         ON CREATE SET n.created = true ON CREATE SET n.first = 'a' \
         ON MATCH SET n.updated = true ON MATCH SET n.count = 1",
    )
    .unwrap();
    match &stmt.clauses[0] {
        Clause::Merge(m) => {
            assert_eq!(m.on_create.len(), 2);
            assert_eq!(m.on_match.len(), 2);
        }
        _ => panic!("expected merge"),
    }
}

/// Interleaved action kinds keep their own accumulation: an `ON MATCH`
/// clause between two `ON CREATE` clauses drops neither.
#[test]
fn test_parse_merge_interleaved_action_clauses_accumulate() {
    let stmt = parse(
        "MERGE (n:Person {name: 'Bob'}) \
         ON CREATE SET n.x = 1 ON MATCH SET n.y = 2 ON CREATE SET n.z = 3",
    )
    .unwrap();
    match &stmt.clauses[0] {
        Clause::Merge(m) => {
            assert_eq!(m.on_create.len(), 2);
            assert_eq!(m.on_match.len(), 1);
        }
        _ => panic!("expected merge"),
    }
}