graph-ecs/tests/query/return.test.js

29 lines
1.2 KiB
JavaScript
Raw Normal View History

2024-11-10 10:15:43 +01:00
import { describe, it } from 'node:test'
2024-11-13 20:24:29 +01:00
import assert from '../assert.js'
2024-11-10 10:15:43 +01:00
import { statement } from '../../src/query/return.js'
2024-11-13 20:24:29 +01:00
import { Alias, Identifier, Literal } from '../../src/query/types.js'
2024-11-10 10:15:43 +01:00
2024-11-14 00:32:46 +01:00
describe('RETURN keyword', () => {
2024-11-10 10:15:43 +01:00
it('should collect a single value for a query to return', () => {
2024-11-14 00:32:46 +01:00
assert.parseOk(statement, 'RETURN folklore AS f', ([actual]) => {
2024-11-13 20:24:29 +01:00
assert.deepEqual(actual, new Alias(new Identifier('folklore'), new Identifier('f')))
})
2024-11-10 10:15:43 +01:00
})
2024-11-13 20:24:29 +01:00
it('should collect multiple values for a query to return', () => {
assert.parseOk(statement, 'RETURN sybil, mercury, rowan', actual => {
assert.deepStrictEqual(actual, ['sybil', 'mercury', 'rowan'].map(x => new Identifier(x)))
})
})
it('should accept mixed values and aliases', () => {
assert.parseOk(statement, '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, [sybil, mercury, rowan])
})
})
2024-11-10 10:15:43 +01:00
})