| 375 | } |
| 376 | |
| 377 | void test_with() { |
| 378 | char *q = "MATCH (n),(m) WITH n as x RETURN x"; |
| 379 | AST *ast = buildAST(q); |
| 380 | uint *segmentIndices = getASTSegmentIndices(ast); |
| 381 | // two segments: first is the MATCH clause, the second is the WITH clause |
| 382 | TEST_ASSERT(2 == array_len(segmentIndices)); |
| 383 | |
| 384 | // only n is projected from the first segment |
| 385 | AST *astSegment = AST_NewSegment(ast, 0, segmentIndices[0]); |
| 386 | TEST_ASSERT(1 == raxSize(astSegment->referenced_entities)); |
| 387 | TEST_ASSERT(raxNotFound != raxFind(astSegment->referenced_entities, (unsigned char *)"n", 1)); |
| 388 | TEST_ASSERT(raxNotFound == raxFind(astSegment->referenced_entities, (unsigned char *)"x", 1)); |
| 389 | AST_Free(astSegment); |
| 390 | |
| 391 | // only x is projected from the second segment |
| 392 | astSegment = AST_NewSegment(ast, segmentIndices[0], segmentIndices[1]); |
| 393 | TEST_ASSERT(1 == raxSize(astSegment->referenced_entities)); |
| 394 | TEST_ASSERT(raxNotFound == raxFind(astSegment->referenced_entities, (unsigned char *)"n", 1)); |
| 395 | TEST_ASSERT(raxNotFound != raxFind(astSegment->referenced_entities, (unsigned char *)"x", 1)); |
| 396 | array_free(segmentIndices); |
| 397 | AST_Free(astSegment); |
| 398 | AST_Free(ast); |
| 399 | |
| 400 | q = "MATCH (n),(m) WITH n as x ORDER BY m.value RETURN x"; |
| 401 | ast = buildAST(q); |
| 402 | segmentIndices = getASTSegmentIndices(ast); |
| 403 | // two segments: first is the MATCH clause, the second is the WITH clause |
| 404 | TEST_ASSERT(2 == array_len(segmentIndices)); |
| 405 | |
| 406 | // only n and m projected from the first segment |
| 407 | astSegment = AST_NewSegment(ast, 0, segmentIndices[0]); |
| 408 | TEST_ASSERT(2 == raxSize(astSegment->referenced_entities)); |
| 409 | TEST_ASSERT(raxNotFound != raxFind(astSegment->referenced_entities, (unsigned char *)"n", 1)); |
| 410 | TEST_ASSERT(raxNotFound != raxFind(astSegment->referenced_entities, (unsigned char *)"m", 1)); |
| 411 | TEST_ASSERT(raxNotFound == raxFind(astSegment->referenced_entities, (unsigned char *)"x", 1)); |
| 412 | AST_Free(astSegment); |
| 413 | |
| 414 | // only m and x projected from the second segment |
| 415 | astSegment = AST_NewSegment(ast, segmentIndices[0], segmentIndices[1]); |
| 416 | TEST_ASSERT(2 == raxSize(astSegment->referenced_entities)); |
| 417 | TEST_ASSERT(raxNotFound == raxFind(astSegment->referenced_entities, (unsigned char *)"n", 1)); |
| 418 | TEST_ASSERT(raxNotFound != raxFind(astSegment->referenced_entities, (unsigned char *)"m", 1)); |
| 419 | TEST_ASSERT(raxNotFound != raxFind(astSegment->referenced_entities, (unsigned char *)"x", 1)); |
| 420 | array_free(segmentIndices); |
| 421 | AST_Free(astSegment); |
| 422 | AST_Free(ast); |
| 423 | } |
| 424 | |
| 425 | void test_return() { |
| 426 | char *q = "MATCH (n),(m) RETURN n as x"; |
nothing calls this directly
no test coverage detected