want things simpler
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
--[[
|
||||
Test: Retained Elements with Varying Props (ID Stability)
|
||||
|
||||
|
||||
This test verifies that retained-mode elements return the same instance
|
||||
across frames even when props vary slightly (e.g., different Color instances).
|
||||
]]
|
||||
@@ -30,33 +30,33 @@ end
|
||||
-- Test that retained elements persist despite creating new Color instances
|
||||
function TestRetainedPropStability:test_retainedElementIgnoresColorInstanceChanges()
|
||||
FlexLove.beginFrame()
|
||||
|
||||
|
||||
-- Frame 1: Create retained element with Color instance
|
||||
local backdrop1 = FlexLove.new({
|
||||
mode = "retained",
|
||||
width = "100%",
|
||||
height = "100%",
|
||||
backgroundColor = Color.new(1, 1, 1, 0.1), -- NEW Color instance
|
||||
backgroundColor = Color.new(1, 1, 1, 0.1), -- NEW Color instance
|
||||
})
|
||||
|
||||
|
||||
local id1 = backdrop1.id
|
||||
|
||||
|
||||
FlexLove.endFrame()
|
||||
|
||||
|
||||
-- Frame 2: Same props but NEW Color instance (common pattern in user code)
|
||||
FlexLove.beginFrame()
|
||||
|
||||
|
||||
local backdrop2 = FlexLove.new({
|
||||
mode = "retained",
|
||||
width = "100%",
|
||||
height = "100%",
|
||||
backgroundColor = Color.new(1, 1, 1, 0.1), -- NEW Color instance (different table)
|
||||
backgroundColor = Color.new(1, 1, 1, 0.1), -- NEW Color instance (different table)
|
||||
})
|
||||
|
||||
|
||||
-- Should return SAME element despite different Color instance
|
||||
luaunit.assertEquals(backdrop2.id, id1, "ID should be stable across frames")
|
||||
luaunit.assertEquals(backdrop2, backdrop1, "Should return same element instance")
|
||||
|
||||
|
||||
FlexLove.endFrame()
|
||||
end
|
||||
|
||||
@@ -81,23 +81,23 @@ function TestRetainedPropStability:test_retainedElementWithComplexProps()
|
||||
gap = 10,
|
||||
})
|
||||
end
|
||||
|
||||
|
||||
FlexLove.beginFrame()
|
||||
|
||||
|
||||
local window1 = createWindow()
|
||||
local id1 = window1.id
|
||||
|
||||
|
||||
FlexLove.endFrame()
|
||||
|
||||
|
||||
-- Frame 2: Same function, same props
|
||||
FlexLove.beginFrame()
|
||||
|
||||
|
||||
local window2 = createWindow()
|
||||
|
||||
|
||||
-- Should return same element
|
||||
luaunit.assertEquals(window2.id, id1)
|
||||
luaunit.assertEquals(window2, window1)
|
||||
|
||||
|
||||
FlexLove.endFrame()
|
||||
end
|
||||
|
||||
@@ -108,27 +108,27 @@ function TestRetainedPropStability:test_retainedElementWithBackdropBlur()
|
||||
mode = "retained",
|
||||
width = "100%",
|
||||
height = "100%",
|
||||
backdropBlur = { radius = 10 }, -- Table prop
|
||||
backdropBlur = { radius = 10 }, -- Table prop
|
||||
backgroundColor = Color.new(1, 1, 1, 0.1),
|
||||
})
|
||||
end
|
||||
|
||||
|
||||
FlexLove.beginFrame()
|
||||
|
||||
|
||||
local backdrop1 = createBackdrop()
|
||||
local id1 = backdrop1.id
|
||||
|
||||
|
||||
FlexLove.endFrame()
|
||||
|
||||
|
||||
-- Frame 2
|
||||
FlexLove.beginFrame()
|
||||
|
||||
|
||||
local backdrop2 = createBackdrop()
|
||||
|
||||
|
||||
-- Should return same element
|
||||
luaunit.assertEquals(backdrop2.id, id1)
|
||||
luaunit.assertEquals(backdrop2, backdrop1)
|
||||
|
||||
|
||||
FlexLove.endFrame()
|
||||
end
|
||||
|
||||
@@ -143,7 +143,7 @@ function TestRetainedPropStability:test_multipleRetainedElementsWithVaryingProps
|
||||
backdropBlur = { radius = 10 },
|
||||
backgroundColor = Color.new(1, 1, 1, 0.1),
|
||||
})
|
||||
|
||||
|
||||
local window = FlexLove.new({
|
||||
mode = "retained",
|
||||
z = 100,
|
||||
@@ -154,31 +154,32 @@ function TestRetainedPropStability:test_multipleRetainedElementsWithVaryingProps
|
||||
themeComponent = "framev3",
|
||||
padding = { horizontal = "5%", vertical = "3%" },
|
||||
})
|
||||
|
||||
|
||||
return backdrop, window
|
||||
end
|
||||
|
||||
|
||||
FlexLove.beginFrame()
|
||||
|
||||
|
||||
local backdrop1, window1 = createUI()
|
||||
local backdropId = backdrop1.id
|
||||
local windowId = window1.id
|
||||
|
||||
|
||||
FlexLove.endFrame()
|
||||
|
||||
|
||||
-- Frame 2: New Color instances, new table instances for props
|
||||
FlexLove.beginFrame()
|
||||
|
||||
|
||||
local backdrop2, window2 = createUI()
|
||||
|
||||
|
||||
-- Both should return existing elements
|
||||
luaunit.assertEquals(backdrop2.id, backdropId)
|
||||
luaunit.assertEquals(window2.id, windowId)
|
||||
luaunit.assertEquals(backdrop2, backdrop1)
|
||||
luaunit.assertEquals(window2, window1)
|
||||
|
||||
|
||||
FlexLove.endFrame()
|
||||
end
|
||||
|
||||
-- Run tests
|
||||
os.exit(luaunit.LuaUnit.run())
|
||||
if not _G.RUNNING_ALL_TESTS then
|
||||
os.exit(luaunit.LuaUnit.run())
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user