MCPcopy Create free account
hub / github.com/RedisGraph/RedisGraph / test_with

Function test_with

tests/unit/test_referenced_entities.c:377–423  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

375}
376
377void 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
425void test_return() {
426 char *q = "MATCH (n),(m) RETURN n as x";

Callers

nothing calls this directly

Calls 6

buildASTFunction · 0.85
getASTSegmentIndicesFunction · 0.85
array_lenFunction · 0.85
AST_NewSegmentFunction · 0.85
AST_FreeFunction · 0.85
array_freeFunction · 0.85

Tested by

no test coverage detected