graph-ecs/tests/query-parser/return.test.js
2024-11-20 13:21:41 -06:00

28 lines
1.3 KiB
JavaScript

import { describe, it } from 'node:test'
import assert from '../assert.js'
import { returnClause } from '../../src/query-parser/return.js'
import { Alias, Identifier, Literal, ReturnValues } from '../../src/query-parser/types.js'
describe('RETURN keyword', () => {
it('should collect a single value for a query to return', () => {
assert.parseOk(returnClause, 'RETURN folklore AS f', ([actual]) => {
assert.deepEqual(actual, new ReturnValues(new Alias(new Identifier('folklore'), new Identifier('f'))))
})
})
it('should collect multiple values for a query to return', () => {
assert.parseOk(returnClause, 'RETURN sybil, mercury, rowan', ([actual]) => {
assert.deepStrictEqual(actual, new ReturnValues(...['sybil', 'mercury', 'rowan'].map(x => new Identifier(x))))
})
})
it('should accept mixed values and aliases', () => {
assert.parseOk(returnClause, 'RETURN 19589 AS sybil, mercury AS vex, rowan', ([actual]) => {
const sybil = new Alias(new Literal(19589), new Identifier('sybil'))
const mercury = new Alias(new Identifier('mercury'), new Identifier('vex'))
const rowan = new Identifier('rowan')
assert.deepStrictEqual(actual, new ReturnValues(...[sybil, mercury, rowan]))
})
})
})