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

29 lines
1.3 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-18 23:06:58 +01:00
import { returnClause } from '../../src/query/return.js'
import { Alias, Identifier, Literal, ReturnValues } 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-18 23:06:58 +01:00
assert.parseOk(returnClause, 'RETURN folklore AS f', ([actual]) => {
assert.deepEqual(actual, new ReturnValues(new Alias(new Identifier('folklore'), new Identifier('f'))))
2024-11-13 20:24:29 +01:00
})
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', () => {
2024-11-18 23:06:58 +01:00
assert.parseOk(returnClause, 'RETURN sybil, mercury, rowan', ([actual]) => {
assert.deepStrictEqual(actual, new ReturnValues(...['sybil', 'mercury', 'rowan'].map(x => new Identifier(x))))
2024-11-13 20:24:29 +01:00
})
})
it('should accept mixed values and aliases', () => {
2024-11-18 23:06:58 +01:00
assert.parseOk(returnClause, 'RETURN 19589 AS sybil, mercury AS vex, rowan', ([actual]) => {
2024-11-13 20:24:29 +01:00
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')
2024-11-18 23:06:58 +01:00
assert.deepStrictEqual(actual, new ReturnValues(...[sybil, mercury, rowan]))
2024-11-13 20:24:29 +01:00
})
})
2024-11-10 10:15:43 +01:00
})