fix tests

This commit is contained in:
Rowan 2024-11-26 15:38:27 -06:00
parent 28ea665212
commit 1ea6b9c713
5 changed files with 26 additions and 10 deletions

View file

@ -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": "",

View file

@ -1,4 +1,4 @@
import { assoc, assocPath, is, nth } from '../fn.js' import { assocPath, is } from '../fn.js'
class Value { class Value {
#value #value

View file

@ -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')))
}) })
}) })

View file

@ -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 } }]
) )
}) })

View file

@ -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(
name && new Name(new Identifier(name)), [new Component(
new Label(new Identifier(label)), name && new Name(new Identifier(name)),
props.map(keyValuePair) new Label(new Identifier(label)),
props.map(keyValuePair)
)]
) )
export const makeNode = graphObject export const makeNode = graphObject