diff --git a/lib/init.spec.lua b/lib/init.spec.lua index 553c9a4..8de8de9 100644 --- a/lib/init.spec.lua +++ b/lib/init.spec.lua @@ -309,12 +309,74 @@ return function() elseif id == eAB then expect(data[A]).to.be.ok() expect(data[B]).to.be.ok() - else - error("unknown entity", id) end end - expect(count).to.equal(3) + expect(count).to.equal(5) end) + + it("should allow querying for relations", function() + local world = jecs.World.new() + local Eats = world:entity() + local Apples = world:entity() + local bob = world:entity() + + world:set(bob, jecs.pair(Eats, Apples), true) + for e, bool in world:query(jecs.pair(Eats, Apples)) do + expect(e).to.equal(bob) + expect(bool).to.equal(bool) + end + end) + + it("should allow wildcards in queries", function() + local world = jecs.World.new() + local Eats = world:entity() + local Apples = world:entity() + local bob = world:entity() + + world:set(bob, jecs.pair(Eats, Apples), "bob eats apples") + for e, data in world:query(jecs.pair(Eats, jecs.w)) do + expect(e).to.equal(bob) + expect(data).to.equal("bob eats apples") + end + for e, data in world:query(jecs.pair(jecs.w, Apples)) do + expect(e).to.equal(bob) + expect(data).to.equal("bob eats apples") + end + end) + + it("should match against multiple pairs", function() + local world = jecs.World.new() + local pair = jecs.pair + local Eats = world:entity() + local Apples = world:entity() + local Oranges =world:entity() + local bob = world:entity() + local alice = world:entity() + + world:set(bob, pair(Eats, Apples), "bob eats apples") + world:set(alice, pair(Eats, Oranges), "alice eats oranges") + + local w = jecs.Wildcard + + local count = 0 + for e, data in world:query(pair(Eats, w)) do + count += 1 + if e == bob then + expect(data).to.equal("bob eats apples") + else + expect(data).to.equal("alice eats oranges") + end + end + + expect(count).to.equal(2) + count = 0 + + for e, data in world:query(pair(w, Apples)) do + count += 1 + expect(data).to.equal("bob eats apples") + end + expect(count).to.equal(1) + end) end) end \ No newline at end of file diff --git a/test.project.json b/test.project.json index a6f15d4..bdcbd0b 100644 --- a/test.project.json +++ b/test.project.json @@ -22,6 +22,9 @@ }, "mirror": { "$path": "mirror" + }, + "DevPackages": { + "$path": "DevPackages" } }, "TestService": { diff --git a/wally.toml b/wally.toml index 7102c41..f17e660 100644 --- a/wally.toml +++ b/wally.toml @@ -6,4 +6,5 @@ realm = "shared" include = ["default.project.json", "lib/**", "lib", "wally.toml", "README.md"] exclude = ["**"] -[dev-dependencies] \ No newline at end of file +[dev-dependencies] +TestEZ = "roblox/testez@0.4.1" \ No newline at end of file