Rename tests files

This commit is contained in:
Ukendio 2024-07-14 01:27:47 +02:00
parent 7e6b555e51
commit 87615de289

View file

@ -520,37 +520,23 @@ TEST("world", function()
local Bob = world:component()
local helloBob = world:entity()
world:add(helloBob, jecs.pair(Hello, Bob))
world:add(helloBob, ECS_PAIR(Hello, Bob))
world:add(helloBob, Bob)
local withoutCount = 0
for _ in world
:query(jecs.pair(Hello, Bob))
:without(Bob)
do
for _ in world:query(ECS_PAIR(Hello, Bob)):without(Bob) do
withoutCount += 1
end
CHECK(withoutCount == 0)
end
end)
do CASE "should allow change tracking"
TEST("changetracker", function()
local world = jecs.World.new()
local Previous = world:component()
local ChangeTracker = {}
ChangeTracker.__index = ChangeTracker
function ChangeTracker.new(component)
return setmetatable({
addedComponents = {}, -- Map<Entity, T>
removedComponents = {}, -- Vec<Entity>
component = component,
previous = jecs.pair(Previous, component),
isTrivial = nil,
}, ChangeTracker)
end
local function shallowEq(a, b)
for k, v in a do
if b[k] ~= v then
@ -560,18 +546,18 @@ TEST("world", function()
return true
end
function ChangeTracker.track(tracker, world, fn)
local function ChangeTracker(world, component)
local addedComponents = {}
local removedComponents = {}
local previous = jecs.pair(Previous, component)
local isTrivial = nil
local function track(fn)
local added = false
local removed = false
local addedComponents = tracker.addedComponents
local removedComponents = tracker.removedComponents
local component = tracker.component
local previous = tracker.previous
local isTrivial = tracker.isTrivial
local changes = {}
function changes:added()
function changes.added()
added = true
local q = world:query(component):without(previous)
return function()
@ -582,7 +568,6 @@ TEST("world", function()
if isTrivial == nil then
isTrivial = typeof(data) ~= "table"
tracker.isTrivial = isTrivial
end
if not isTrivial then
@ -594,7 +579,7 @@ TEST("world", function()
end
end
function changes:changed()
function changes.changed()
local q = world:query(component, previous)
return function()
@ -615,17 +600,16 @@ TEST("world", function()
id, new, old = q:next()
end
print("nil?", id)
addedComponents[id] = new
return id, old, new
end
end
function changes:removed()
function changes.removed()
removed = true
local q = world:query(tracker.previous):without(tracker.component)
local q = world:query(previous):without(component)
return function()
local id = q:next()
if id then
@ -637,12 +621,12 @@ TEST("world", function()
fn(changes)
if not added then
for _ in changes:added() do
for _ in changes.added() do
end
end
if not removed then
for _ in changes:removed() do
for _ in changes.removed() do
end
end
@ -655,8 +639,14 @@ TEST("world", function()
end
end
return {
track = track
}
end
do CASE "should allow change tracking"
local Test = world:component()
local TestTracker = ChangeTracker.new(Test)
local TestTracker = ChangeTracker(world, Test)
local e = world:entity()
world:set(e, Test, { foo = 11 })
@ -664,7 +654,7 @@ TEST("world", function()
test.foo = test.foo + 1
end
TestTracker:track(world, function(changes)
TestTracker.track(function(changes)
local added = 0
local changed = 0
local removed = 0
@ -686,10 +676,11 @@ TEST("world", function()
test.foo = test.foo + 1
end
TestTracker:track(world, function(changes)
TestTracker.track(function(changes)
local added = 0
local changed = 0
local removed = 0
for e, data in changes.added() do
added+=1
end
@ -706,7 +697,7 @@ TEST("world", function()
world:remove(e, Test)
TestTracker:track(world, function(changes)
TestTracker.track(function(changes)
local added = 0
local changed = 0
local removed = 0