more query tests; make less talky :3
This commit is contained in:
parent
8844f326b0
commit
604998324d
2 changed files with 25 additions and 19 deletions
|
@ -75,8 +75,6 @@ describe('query', () => {
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
console.log(util.inspect(actual, { depth: null }))
|
|
||||||
console.log(util.inspect(expected, { depth: null }))
|
|
||||||
assert.deepEqual(actual, expected)
|
assert.deepEqual(actual, expected)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
@ -24,17 +24,20 @@ const update = (type, values, entity) => {
|
||||||
Object.entries(values).forEach(([k, v]) => { type[k][entity] = v })
|
Object.entries(values).forEach(([k, v]) => { type[k][entity] = v })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const EdgeDef = { from: Types.eid, to: Types.eid }
|
||||||
|
const defineEdge = (schema, max) => defineComponent({ ...EdgeDef, ...schema }, max)
|
||||||
|
|
||||||
describe('query', () => {
|
describe('query', () => {
|
||||||
before(() => {
|
before(() => {
|
||||||
const world = { default: createWorld() }
|
const world = { default: createWorld() }
|
||||||
const component = {
|
const component = {
|
||||||
Player: defineComponent(null, 10),
|
Player: defineComponent(null, 20),
|
||||||
NPC: defineComponent(null, 10),
|
NPC: defineComponent(null, 20),
|
||||||
Health: defineComponent({ current: Types.ui8, max: Types.ui8 }),
|
Health: defineComponent({ current: Types.ui8, max: Types.ui8 }, 20),
|
||||||
Knows: defineComponent({
|
Knows: defineComponent(EdgeDef, 20),
|
||||||
from: Types.eid,
|
Damaged: defineEdge({
|
||||||
to: Types.eid
|
damage: Types.ui16
|
||||||
}, 10)
|
}, 20)
|
||||||
}
|
}
|
||||||
|
|
||||||
engine = { world, component }
|
engine = { world, component }
|
||||||
|
@ -103,12 +106,14 @@ describe('query', () => {
|
||||||
|
|
||||||
it('should support filtering', () => {
|
it('should support filtering', () => {
|
||||||
const world = engine.world.default
|
const world = engine.world.default
|
||||||
const { Player, Health } = engine.component
|
const { Player, Health, Damaged } = engine.component
|
||||||
const player = create(world, Player, Health) // 12
|
const player = create(world, Player, Health) // 12
|
||||||
const enemy = create(world, Health) // 13
|
const enemy = create(world, Health) // 13
|
||||||
|
|
||||||
update(Health, { max: 50, current: 25 }, player)
|
update(Health, { max: 50, current: 25 }, player)
|
||||||
update(Health, { max: 50, current: 35 }, enemy)
|
update(Health, { max: 50, current: 35 }, enemy)
|
||||||
|
const [edge] = relate(world, player, Damaged, enemy)
|
||||||
|
update(Damaged, { damage: 10 }, edge)
|
||||||
|
|
||||||
assert.deepEqual(
|
assert.deepEqual(
|
||||||
query('MATCH (e, h:Health) WHERE h.current < 30 RETURN e, h.max', engine).unwrap(),
|
query('MATCH (e, h:Health) WHERE h.current < 30 RETURN e, h.max', engine).unwrap(),
|
||||||
|
@ -129,9 +134,12 @@ describe('query', () => {
|
||||||
)
|
)
|
||||||
assert.deepEqual(
|
assert.deepEqual(
|
||||||
query('MATCH (e, :Player, h:Health) WHERE (h.max = 50 OR h.current > 45) AND e = 12 RETURN e, h.max AS maxHealth', engine).unwrap(),
|
query('MATCH (e, :Player, h:Health) WHERE (h.max = 50 OR h.current > 45) AND e = 12 RETURN e, h.max AS maxHealth', engine).unwrap(),
|
||||||
[
|
[{ e: 12, maxHealth: 50 }]
|
||||||
{ e: 12, maxHealth: 50 }
|
)
|
||||||
]
|
|
||||||
|
assert.deepEqual(
|
||||||
|
query('MATCH (:Player)-[d:Damaged]->(h:Health) RETURN h.current AS health, d.damage AS damage', engine).unwrap(),
|
||||||
|
[{ damage: 10, health: 35 }]
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in a new issue