more query tests; make less talky :3

This commit is contained in:
Rowan 2024-11-28 02:08:37 -06:00
parent 8844f326b0
commit 604998324d
2 changed files with 25 additions and 19 deletions

View file

@ -75,8 +75,6 @@ describe('query', () => {
)
)
console.log(util.inspect(actual, { depth: null }))
console.log(util.inspect(expected, { depth: null }))
assert.deepEqual(actual, expected)
})
})

View file

@ -24,17 +24,20 @@ const update = (type, values, entity) => {
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', () => {
before(() => {
const world = { default: createWorld() }
const component = {
Player: defineComponent(null, 10),
NPC: defineComponent(null, 10),
Health: defineComponent({ current: Types.ui8, max: Types.ui8 }),
Knows: defineComponent({
from: Types.eid,
to: Types.eid
}, 10)
Player: defineComponent(null, 20),
NPC: defineComponent(null, 20),
Health: defineComponent({ current: Types.ui8, max: Types.ui8 }, 20),
Knows: defineComponent(EdgeDef, 20),
Damaged: defineEdge({
damage: Types.ui16
}, 20)
}
engine = { world, component }
@ -103,12 +106,14 @@ describe('query', () => {
it('should support filtering', () => {
const world = engine.world.default
const { Player, Health } = engine.component
const { Player, Health, Damaged } = engine.component
const player = create(world, Player, Health) // 12
const enemy = create(world, Health) // 13
update(Health, { max: 50, current: 25 }, player)
update(Health, { max: 50, current: 35 }, enemy)
const [edge] = relate(world, player, Damaged, enemy)
update(Damaged, { damage: 10 }, edge)
assert.deepEqual(
query('MATCH (e, h:Health) WHERE h.current < 30 RETURN e, h.max', engine).unwrap(),
@ -121,17 +126,20 @@ describe('query', () => {
)
assert.deepEqual(
query('MATCH (e, h:Health) WHERE h.max = 50 OR h.current > 45 RETURN e, h.max AS maxHealth', engine).unwrap(),
[
{ e: 12, maxHealth: 50 },
{ e: 13, maxHealth: 50 }
]
query('MATCH (e, h:Health) WHERE h.max = 50 OR h.current > 45 RETURN e, h.max AS maxHealth', engine).unwrap(),
[
{ e: 12, maxHealth: 50 },
{ e: 13, maxHealth: 50 }
]
)
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(),
[
{ e: 12, maxHealth: 50 }
]
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 }]
)
assert.deepEqual(
query('MATCH (:Player)-[d:Damaged]->(h:Health) RETURN h.current AS health, d.damage AS damage', engine).unwrap(),
[{ damage: 10, health: 35 }]
)
})
})