fix tests
This commit is contained in:
parent
28ea665212
commit
1ea6b9c713
5 changed files with 26 additions and 10 deletions
|
@ -5,7 +5,7 @@
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "node src/index.js",
|
"start": "node src/index.js",
|
||||||
"test": "node --test ./tests"
|
"test": "node --test ./tests/**/*.test.js"
|
||||||
},
|
},
|
||||||
"keywords": [],
|
"keywords": [],
|
||||||
"author": "",
|
"author": "",
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { assoc, assocPath, is, nth } from '../fn.js'
|
import { assocPath, is } from '../fn.js'
|
||||||
|
|
||||||
class Value {
|
class Value {
|
||||||
#value
|
#value
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
import { describe, it } from 'node:test'
|
import { describe, it } from 'node:test'
|
||||||
import assert from '../assert.js'
|
import assert from '../assert.js'
|
||||||
import { useClause } from '../../src/query-parser/use.js'
|
import { useClause } from '../../src/query-parser/use.js'
|
||||||
import { Identifier } from '../../src/query-parser/types.js'
|
import { Identifier, SelectedGraph } from '../../src/query-parser/types.js'
|
||||||
|
|
||||||
describe('USE keyword', () => {
|
describe('USE keyword', () => {
|
||||||
it('should select a graph to query', () => {
|
it('should select a graph to query', () => {
|
||||||
assert.parseOk(useClause, 'USE default', ([actual]) => {
|
assert.parseOk(useClause, 'USE default', ([actual]) => {
|
||||||
assert.deepEqual(actual.identifier, new Identifier('default'))
|
assert.deepEqual(actual, new SelectedGraph(new Identifier('default')))
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -88,12 +88,26 @@ describe('query', () => {
|
||||||
|
|
||||||
// an unspecified component should return an Entity
|
// an unspecified component should return an Entity
|
||||||
assert.deepEqual(
|
assert.deepEqual(
|
||||||
query('MATCH (e, h:Health) return e, h.max', engine).unwrap(),
|
query('MATCH (e, h:Health) WHERE e, h.max', engine).unwrap(),
|
||||||
[{ e: 11, h: { max: 50 } }]
|
[{ e: 11, h: { max: 50 } }]
|
||||||
)
|
)
|
||||||
|
|
||||||
assert.deepEqual(
|
assert.deepEqual(
|
||||||
query('MATCH (e:Entity, h:Health) return e, h.max', engine).unwrap(),
|
query('MATCH (e:Entity, h:Health) WHERE e, h.max', engine).unwrap(),
|
||||||
|
[{ e: 11, h: { max: 50 } }]
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should support filtering', () => {
|
||||||
|
const world = engine.world.default
|
||||||
|
const { Player, Health } = engine.component
|
||||||
|
const player = create(world, Player, Health)
|
||||||
|
|
||||||
|
Health.max[player] = 50
|
||||||
|
Health.current[player] = 25
|
||||||
|
|
||||||
|
assert.deepEqual(
|
||||||
|
query('MATCH (h:Health) WHERE h.current < 30 RETURN h.max', engine).unwrap(),
|
||||||
[{ e: 11, h: { max: 50 } }]
|
[{ e: 11, h: { max: 50 } }]
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
|
@ -1,11 +1,13 @@
|
||||||
import { KeyValuePair, Name, Label, Identifier, Literal, Edge, Node, DirectedEdge, Relationship } from '../src/query-parser/types.js'
|
import { KeyValuePair, Name, Label, Identifier, Literal, Edge, Node, DirectedEdge, Relationship, Component } from '../src/query-parser/types.js'
|
||||||
|
|
||||||
export const keyValuePair = ([k, v]) => new KeyValuePair(new Name(new Identifier(k)), new Literal(v))
|
export const keyValuePair = ([k, v]) => new KeyValuePair(new Name(new Identifier(k)), new Literal(v))
|
||||||
|
|
||||||
export const graphObject = (name, label, props = [], Type = Node) => new Type(
|
export const graphObject = (name, label, props = [], Type = Node) => new Type(
|
||||||
|
[new Component(
|
||||||
name && new Name(new Identifier(name)),
|
name && new Name(new Identifier(name)),
|
||||||
new Label(new Identifier(label)),
|
new Label(new Identifier(label)),
|
||||||
props.map(keyValuePair)
|
props.map(keyValuePair)
|
||||||
|
)]
|
||||||
)
|
)
|
||||||
|
|
||||||
export const makeNode = graphObject
|
export const makeNode = graphObject
|
||||||
|
|
Loading…
Reference in a new issue