diff --git a/package.json b/package.json index 526ab53..8d70f8e 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "type": "module", "scripts": { "start": "node src/index.js", - "test": "node --test ./tests" + "test": "node --test ./tests/**/*.test.js" }, "keywords": [], "author": "", diff --git a/src/query-parser/types.js b/src/query-parser/types.js index beecf88..e82ff1b 100644 --- a/src/query-parser/types.js +++ b/src/query-parser/types.js @@ -1,4 +1,4 @@ -import { assoc, assocPath, is, nth } from '../fn.js' +import { assocPath, is } from '../fn.js' class Value { #value diff --git a/tests/query-parser/use.test.js b/tests/query-parser/use.test.js index 3ade117..9ffd382 100644 --- a/tests/query-parser/use.test.js +++ b/tests/query-parser/use.test.js @@ -1,12 +1,12 @@ import { describe, it } from 'node:test' import assert from '../assert.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', () => { it('should select a graph to query', () => { assert.parseOk(useClause, 'USE default', ([actual]) => { - assert.deepEqual(actual.identifier, new Identifier('default')) + assert.deepEqual(actual, new SelectedGraph(new Identifier('default'))) }) }) diff --git a/tests/query.test.js b/tests/query.test.js index 1543656..132417c 100644 --- a/tests/query.test.js +++ b/tests/query.test.js @@ -88,12 +88,26 @@ describe('query', () => { // an unspecified component should return an Entity 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 } }] ) 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 } }] ) }) diff --git a/tests/utils.js b/tests/utils.js index 58d247f..2b80fd6 100644 --- a/tests/utils.js +++ b/tests/utils.js @@ -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 graphObject = (name, label, props = [], Type = Node) => new Type( - name && new Name(new Identifier(name)), - new Label(new Identifier(label)), - props.map(keyValuePair) + [new Component( + name && new Name(new Identifier(name)), + new Label(new Identifier(label)), + props.map(keyValuePair) + )] ) export const makeNode = graphObject