fix objectpath references in tests

This commit is contained in:
Rowan 2024-11-28 01:25:49 -06:00
parent b2de794ef1
commit 8844f326b0
3 changed files with 18 additions and 15 deletions

View file

@ -1,6 +1,6 @@
import { describe, it } from 'node:test'
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'
describe('common parser library', () => {
@ -38,7 +38,7 @@ describe('common parser library', () => {
})
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.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]) => {
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'))
assert.deepEqual(actual, alias)
})

View file

@ -1,11 +1,13 @@
import util from 'node:util'
import { describe, it } from 'node:test'
import assert from '../assert.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 { 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 identifier = n => new Identifier(n)
const graph = n => new SelectedGraph(identifier(n))
@ -68,11 +70,13 @@ describe('query', () => {
)),
[],
returnVals(
alias(path(identifier('kbity'), identifier('name')), identifier('name')),
alias(path('kbity', 'name'), identifier('name')),
alias(identifier('snacc'), identifier('food'))
)
)
console.log(util.inspect(actual, { depth: null }))
console.log(util.inspect(expected, { depth: null }))
assert.deepEqual(actual, expected)
})
})

View file

@ -83,24 +83,23 @@ describe('where operators', () => {
describe('WHERE keyword', () => {
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]) => {
const expected = [
new ObjectPath(new Identifier('h'), new Property('max')),
new ObjectPath(new Identifier('h'), new Property(new Identifier('max'))),
new Literal(500),
GreaterThan,
new ObjectPath(new Identifier('h'), new Property('current')),
new ObjectPath(new Identifier('h'), new Property(new Identifier('current'))),
new Literal(250),
LesserThan,
new ObjectPath(new Identifier('a'), new Property('value')),
Or,
new ObjectPath(new Identifier('a'), new Property(new Identifier('value'))),
new Literal(10),
Equal,
And,
new ObjectPath(new Identifier('a'), new Property('value')),
Or,
And,
new ObjectPath(new Identifier('a'), new Property(new Identifier('value'))),
new Literal(2),
LesserThanEqual
LesserThanEqual,
Or,
]
assert.deepEqual(actual.values, expected)
})