Exemplo n.º 1
0
END_TEST


START_TEST (parse_merge_with_on_match_action)
{
    struct cypher_input_position last = cypher_input_position_zero;
    result = cypher_parse("MERGE (n:Foo) ON MATCH SET n.bar = 'baz' RETURN n;",
            &last, NULL, 0);
    ck_assert_ptr_ne(result, NULL);
    ck_assert_int_eq(last.offset, 50);

    ck_assert(cypher_parse_result_fprint_ast(result, memstream, 0, NULL, 0) == 0);
    fflush(memstream);
    const char *expected = "\n"
" @0   0..50  statement               body=@1\n"
" @1   0..50  > query                 clauses=[@2, @13]\n"
" @2   0..41  > > MERGE               path=@3, action[@7]\n"
" @3   6..13  > > > pattern path      (@4)\n"
" @4   6..13  > > > > node pattern    (@5:@6)\n"
" @5   7..8   > > > > > identifier    `n`\n"
" @6   8..12  > > > > > label         :`Foo`\n"
" @7  14..41  > > > ON MATCH          items=[@8]\n"
" @8  27..41  > > > > set property    @9 = @12\n"
" @9  27..33  > > > > > property      @10.@11\n"
"@10  27..28  > > > > > > identifier  `n`\n"
"@11  29..32  > > > > > > prop name   `bar`\n"
"@12  35..40  > > > > > string        \"baz\"\n"
"@13  41..49  > > RETURN              projections=[@14]\n"
"@14  48..49  > > > projection        expression=@15\n"
"@15  48..49  > > > > identifier      `n`\n";
    ck_assert_str_eq(memstream_buffer, expected);

    const cypher_astnode_t *ast = cypher_parse_result_get_directive(result, 0);
    ck_assert_int_eq(cypher_astnode_type(ast), CYPHER_AST_STATEMENT);
    const cypher_astnode_t *query = cypher_ast_statement_get_body(ast);
    ck_assert_int_eq(cypher_astnode_type(query), CYPHER_AST_QUERY);
    const cypher_astnode_t *merge = cypher_ast_query_get_clause(query, 0);
    ck_assert_int_eq(cypher_astnode_type(merge), CYPHER_AST_MERGE);

    const cypher_astnode_t *path = cypher_ast_merge_get_pattern_path(merge);
    ck_assert_int_eq(cypher_astnode_type(path), CYPHER_AST_PATTERN_PATH);
    ck_assert_int_eq(cypher_ast_pattern_path_nelements(path), 1);

    ck_assert_int_eq(cypher_ast_merge_nactions(merge), 1);
    ck_assert_ptr_eq(cypher_ast_merge_get_action(merge, 1), NULL);

    const cypher_astnode_t *action = cypher_ast_merge_get_action(merge, 0);
    ck_assert(cypher_astnode_instanceof(action, CYPHER_AST_MERGE_ACTION));
    ck_assert_int_eq(cypher_astnode_type(action), CYPHER_AST_ON_MATCH);

    ck_assert_int_eq(cypher_ast_on_match_nitems(action), 1);
    ck_assert_ptr_eq(cypher_ast_on_match_get_item(action, 1), NULL);

    const cypher_astnode_t *item = cypher_ast_on_match_get_item(action, 0);
    ck_assert_int_eq(cypher_astnode_type(item), CYPHER_AST_SET_PROPERTY);
}
Exemplo n.º 2
0
int main(int argc, char *argv[])
{
    cypher_parse_result_t *result = cypher_parse(
            "MATCH (n) RETURN n", NULL, NULL, CYPHER_PARSE_ONLY_STATEMENTS);
    if (result == NULL)
    {
        perror("cypher_parse");
        return EXIT_FAILURE;
    }
    printf("Parsed %d AST nodes\n", cypher_parse_result_node_count(result));
    cypher_parse_result_free(result);
    return 0;
}
Exemplo n.º 3
0
cypher_parse_result_t *run(const char * s)
{
    cypher_parse_result_t *result = cypher_parse(s, NULL, NULL, CYPHER_PARSE_ONLY_STATEMENTS);
    return result;
}