fix objectpath references in tests
This commit is contained in:
parent
b2de794ef1
commit
8844f326b0
3 changed files with 18 additions and 15 deletions
|
@ -1,6 +1,6 @@
|
||||||
import { describe, it } from 'node:test'
|
import { describe, it } from 'node:test'
|
||||||
import assert from '../assert.js'
|
import assert from '../assert.js'
|
||||||
import { Alias, Identifier, Literal, ObjectPath } from '../../src/query-parser/types.js'
|
import { Alias, Identifier, Literal, ObjectPath, Property } from '../../src/query-parser/types.js'
|
||||||
import { baseValue, literal, value } from '../../src/query-parser/common.js'
|
import { baseValue, literal, value } from '../../src/query-parser/common.js'
|
||||||
|
|
||||||
describe('common parser library', () => {
|
describe('common parser library', () => {
|
||||||
|
@ -38,7 +38,7 @@ describe('common parser library', () => {
|
||||||
})
|
})
|
||||||
|
|
||||||
assert.parseOk(baseValue, 'ginger.snaps', ([actual]) => {
|
assert.parseOk(baseValue, 'ginger.snaps', ([actual]) => {
|
||||||
assert.deepEqual(actual, new ObjectPath(new Identifier('ginger'), new Identifier('snaps')))
|
assert.deepEqual(actual, new ObjectPath(new Identifier('ginger'), new Property(new Identifier('snaps'))))
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -56,7 +56,7 @@ describe('common parser library', () => {
|
||||||
})
|
})
|
||||||
|
|
||||||
assert.parseOk(baseValue, 'monster.girl', ([actual]) => {
|
assert.parseOk(baseValue, 'monster.girl', ([actual]) => {
|
||||||
assert.deepEqual(actual, new ObjectPath(new Identifier('monster'), new Identifier('girl')))
|
assert.deepEqual(actual, new ObjectPath(new Identifier('monster'), new Property(new Identifier('girl'))))
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -74,7 +74,7 @@ describe('common parser library', () => {
|
||||||
})
|
})
|
||||||
|
|
||||||
assert.parseOk(value, 'rowan.containment.isBreached AS rawrnEscaped', ([actual]) => {
|
assert.parseOk(value, 'rowan.containment.isBreached AS rawrnEscaped', ([actual]) => {
|
||||||
const obj = new ObjectPath(new Identifier('rowan'), new Identifier('containment'), new Identifier('isBreached'))
|
const obj = new ObjectPath(new Identifier('rowan'), new Property(new Identifier('containment')), new Property(new Identifier('isBreached')))
|
||||||
const alias = new Alias(obj, new Identifier('rawrnEscaped'))
|
const alias = new Alias(obj, new Identifier('rawrnEscaped'))
|
||||||
assert.deepEqual(actual, alias)
|
assert.deepEqual(actual, alias)
|
||||||
})
|
})
|
||||||
|
|
|
@ -1,11 +1,13 @@
|
||||||
|
import util from 'node:util'
|
||||||
import { describe, it } from 'node:test'
|
import { describe, it } from 'node:test'
|
||||||
import assert from '../assert.js'
|
import assert from '../assert.js'
|
||||||
import { query } from '../../src/query-parser/index.js'
|
import { query } from '../../src/query-parser/index.js'
|
||||||
import { Alias, Identifier, Match, ObjectPath, Query, ReturnValues, SelectedGraph } from '../../src/query-parser/types.js'
|
import { Alias, Identifier, Match, ObjectPath, Property, Query, ReturnValues, SelectedGraph } from '../../src/query-parser/types.js'
|
||||||
import { makeNode, makeRelationship, makeRightEdge } from '../utils.js'
|
import { makeNode, makeRelationship, makeRightEdge } from '../utils.js'
|
||||||
import { map } from '../../src/fn.js'
|
import { map } from '../../src/fn.js'
|
||||||
|
|
||||||
const path = (...x) => new ObjectPath(...x)
|
const path = (...args) => new ObjectPath(identifier(args[0]), ...args.slice(1).map(prop))
|
||||||
|
const prop = x => new Property(identifier(x))
|
||||||
const alias = (...x) => new Alias(...x)
|
const alias = (...x) => new Alias(...x)
|
||||||
const identifier = n => new Identifier(n)
|
const identifier = n => new Identifier(n)
|
||||||
const graph = n => new SelectedGraph(identifier(n))
|
const graph = n => new SelectedGraph(identifier(n))
|
||||||
|
@ -68,11 +70,13 @@ describe('query', () => {
|
||||||
)),
|
)),
|
||||||
[],
|
[],
|
||||||
returnVals(
|
returnVals(
|
||||||
alias(path(identifier('kbity'), identifier('name')), identifier('name')),
|
alias(path('kbity', 'name'), identifier('name')),
|
||||||
alias(identifier('snacc'), identifier('food'))
|
alias(identifier('snacc'), identifier('food'))
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
console.log(util.inspect(actual, { depth: null }))
|
||||||
|
console.log(util.inspect(expected, { depth: null }))
|
||||||
assert.deepEqual(actual, expected)
|
assert.deepEqual(actual, expected)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
@ -83,24 +83,23 @@ describe('where operators', () => {
|
||||||
|
|
||||||
describe('WHERE keyword', () => {
|
describe('WHERE keyword', () => {
|
||||||
it('handles complex filters', () => {
|
it('handles complex filters', () => {
|
||||||
parse(whereClause, 'WHERE h.max > 500 AND (h.current < 250 OR a.value = 10) OR a.value <= 2')
|
|
||||||
assert.parseOk(whereClause, 'WHERE h.max > 500 AND (h.current < 250 OR a.value = 10) OR a.value <= 2', ([actual]) => {
|
assert.parseOk(whereClause, 'WHERE h.max > 500 AND (h.current < 250 OR a.value = 10) OR a.value <= 2', ([actual]) => {
|
||||||
const expected = [
|
const expected = [
|
||||||
new ObjectPath(new Identifier('h'), new Property('max')),
|
new ObjectPath(new Identifier('h'), new Property(new Identifier('max'))),
|
||||||
new Literal(500),
|
new Literal(500),
|
||||||
GreaterThan,
|
GreaterThan,
|
||||||
new ObjectPath(new Identifier('h'), new Property('current')),
|
new ObjectPath(new Identifier('h'), new Property(new Identifier('current'))),
|
||||||
new Literal(250),
|
new Literal(250),
|
||||||
LesserThan,
|
LesserThan,
|
||||||
new ObjectPath(new Identifier('a'), new Property('value')),
|
new ObjectPath(new Identifier('a'), new Property(new Identifier('value'))),
|
||||||
Or,
|
|
||||||
new Literal(10),
|
new Literal(10),
|
||||||
Equal,
|
Equal,
|
||||||
And,
|
|
||||||
new ObjectPath(new Identifier('a'), new Property('value')),
|
|
||||||
Or,
|
Or,
|
||||||
|
And,
|
||||||
|
new ObjectPath(new Identifier('a'), new Property(new Identifier('value'))),
|
||||||
new Literal(2),
|
new Literal(2),
|
||||||
LesserThanEqual
|
LesserThanEqual,
|
||||||
|
Or,
|
||||||
]
|
]
|
||||||
assert.deepEqual(actual.values, expected)
|
assert.deepEqual(actual.values, expected)
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in a new issue