more testing

This commit is contained in:
Michael Freno
2025-11-15 02:02:02 -05:00
parent f8fddb7ffa
commit 472bf358f4
14 changed files with 2584 additions and 394 deletions

View File

@@ -16,7 +16,7 @@ function TestLayoutEdgeCases:setUp()
self.warnings = {}
self.originalWarn = ErrorHandler.warn
ErrorHandler.warn = function(module, message)
table.insert(self.warnings, {module = module, message = message})
table.insert(self.warnings, { module = module, message = message })
end
end
@@ -35,22 +35,22 @@ function TestLayoutEdgeCases:test_percentage_width_with_auto_parent_warns()
-- width not specified - auto-sizing width
height = 200,
positioning = "flex",
flexDirection = "horizontal"
flexDirection = "horizontal",
})
FlexLove.new({
id = "child_with_percentage",
parent = container,
width = "50%", -- Percentage width with auto-sizing parent - should warn
height = 100
width = "50%", -- Percentage width with auto-sizing parent - should warn
height = 100,
})
FlexLove.endFrame()
FlexLove.beginFrame()
-- Check that a warning was issued
luaunit.assertTrue(#self.warnings > 0, "Should issue warning for percentage width with auto-sizing parent")
local found = false
for _, warning in ipairs(self.warnings) do
if warning.message:match("percentage width") and warning.message:match("auto%-sizing") then
@@ -58,7 +58,7 @@ function TestLayoutEdgeCases:test_percentage_width_with_auto_parent_warns()
break
end
end
luaunit.assertTrue(found, "Warning should mention percentage width and auto-sizing")
end
@@ -71,22 +71,22 @@ function TestLayoutEdgeCases:test_percentage_height_with_auto_parent_warns()
width = 200,
-- height not specified - auto-sizing height
positioning = "flex",
flexDirection = "vertical"
flexDirection = "vertical",
})
FlexLove.new({
id = "child_with_percentage",
parent = container,
width = 100,
height = "50%" -- Percentage height with auto-sizing parent - should warn
height = "50%", -- Percentage height with auto-sizing parent - should warn
})
FlexLove.endFrame()
FlexLove.beginFrame()
-- Check that a warning was issued
luaunit.assertTrue(#self.warnings > 0, "Should issue warning for percentage height with auto-sizing parent")
local found = false
for _, warning in ipairs(self.warnings) do
if warning.message:match("percentage height") and warning.message:match("auto%-sizing") then
@@ -94,7 +94,7 @@ function TestLayoutEdgeCases:test_percentage_height_with_auto_parent_warns()
break
end
end
luaunit.assertTrue(found, "Warning should mention percentage height and auto-sizing")
end
@@ -107,19 +107,19 @@ function TestLayoutEdgeCases:test_pixel_width_with_auto_parent_no_warn()
-- width not specified - auto-sizing
height = 200,
positioning = "flex",
flexDirection = "horizontal"
flexDirection = "horizontal",
})
FlexLove.new({
id = "child_with_pixels",
parent = container,
width = 100, -- Pixel width - should NOT warn
height = 100
width = 100, -- Pixel width - should NOT warn
height = 100,
})
FlexLove.endFrame()
FlexLove.beginFrame()
-- Check that NO warning was issued about percentage sizing
for _, warning in ipairs(self.warnings) do
local hasPercentageWarning = warning.message:match("percentage") and warning.message:match("auto%-sizing")
@@ -135,23 +135,23 @@ function TestLayoutEdgeCases:test_css_positioning_top_offset()
y = 100,
width = 400,
height = 400,
positioning = "absolute"
positioning = "absolute",
})
local child = FlexLove.new({
id = "child",
parent = container,
positioning = "absolute",
top = 50, -- 50px from top
top = 50, -- 50px from top
left = 0,
width = 100,
height = 100
height = 100,
})
-- Trigger layout by ending and restarting frame
FlexLove.endFrame()
FlexLove.beginFrame()
-- Child should be positioned 50px from container's top edge (accounting for padding)
local expectedY = container.y + container.padding.top + 50
luaunit.assertEquals(child.y, expectedY, "Child should be positioned with top offset")
@@ -165,22 +165,22 @@ function TestLayoutEdgeCases:test_css_positioning_bottom_offset()
y = 100,
width = 400,
height = 400,
positioning = "absolute"
positioning = "absolute",
})
local child = FlexLove.new({
id = "child",
parent = container,
positioning = "absolute",
bottom = 50, -- 50px from bottom
bottom = 50, -- 50px from bottom
left = 0,
width = 100,
height = 100
height = 100,
})
FlexLove.endFrame()
FlexLove.beginFrame()
-- Child should be positioned 50px from container's bottom edge
local expectedY = container.y + container.padding.top + container.height - 50 - child:getBorderBoxHeight()
luaunit.assertEquals(child.y, expectedY, "Child should be positioned with bottom offset")
@@ -194,22 +194,22 @@ function TestLayoutEdgeCases:test_css_positioning_left_offset()
y = 100,
width = 400,
height = 400,
positioning = "absolute"
positioning = "absolute",
})
local child = FlexLove.new({
id = "child",
parent = container,
positioning = "absolute",
top = 0,
left = 50, -- 50px from left
left = 50, -- 50px from left
width = 100,
height = 100
height = 100,
})
FlexLove.endFrame()
FlexLove.beginFrame()
-- Child should be positioned 50px from container's left edge
local expectedX = container.x + container.padding.left + 50
luaunit.assertEquals(child.x, expectedX, "Child should be positioned with left offset")
@@ -223,22 +223,22 @@ function TestLayoutEdgeCases:test_css_positioning_right_offset()
y = 100,
width = 400,
height = 400,
positioning = "absolute"
positioning = "absolute",
})
local child = FlexLove.new({
id = "child",
parent = container,
positioning = "absolute",
top = 0,
right = 50, -- 50px from right
right = 50, -- 50px from right
width = 100,
height = 100
height = 100,
})
FlexLove.endFrame()
FlexLove.beginFrame()
-- Child should be positioned 50px from container's right edge
local expectedX = container.x + container.padding.left + container.width - 50 - child:getBorderBoxWidth()
luaunit.assertEquals(child.x, expectedX, "Child should be positioned with right offset")
@@ -252,23 +252,23 @@ function TestLayoutEdgeCases:test_css_positioning_top_and_bottom()
y = 100,
width = 400,
height = 400,
positioning = "absolute"
positioning = "absolute",
})
local child = FlexLove.new({
id = "child",
parent = container,
positioning = "absolute",
top = 10,
bottom = 20, -- Both specified - last one wins in current implementation
bottom = 20, -- Both specified - last one wins in current implementation
left = 0,
width = 100,
height = 100
height = 100,
})
FlexLove.endFrame()
FlexLove.beginFrame()
-- Bottom should override top
local expectedY = container.y + container.padding.top + container.height - 20 - child:getBorderBoxHeight()
luaunit.assertEquals(child.y, expectedY, "Bottom offset should override top when both specified")
@@ -282,23 +282,23 @@ function TestLayoutEdgeCases:test_css_positioning_left_and_right()
y = 100,
width = 400,
height = 400,
positioning = "absolute"
positioning = "absolute",
})
local child = FlexLove.new({
id = "child",
parent = container,
positioning = "absolute",
top = 0,
left = 10,
right = 20, -- Both specified - last one wins in current implementation
right = 20, -- Both specified - last one wins in current implementation
width = 100,
height = 100
height = 100,
})
FlexLove.endFrame()
FlexLove.beginFrame()
-- Right should override left
local expectedX = container.x + container.padding.left + container.width - 20 - child:getBorderBoxWidth()
luaunit.assertEquals(child.x, expectedX, "Right offset should override left when both specified")
@@ -313,9 +313,9 @@ function TestLayoutEdgeCases:test_css_positioning_with_padding()
width = 400,
height = 400,
padding = { top = 20, right = 20, bottom = 20, left = 20 },
positioning = "absolute"
positioning = "absolute",
})
local child = FlexLove.new({
id = "child",
parent = container,
@@ -323,16 +323,16 @@ function TestLayoutEdgeCases:test_css_positioning_with_padding()
top = 10,
left = 10,
width = 100,
height = 100
height = 100,
})
FlexLove.endFrame()
FlexLove.beginFrame()
-- Offsets should be relative to content area (after padding)
local expectedX = container.x + container.padding.left + 10
local expectedY = container.y + container.padding.top + 10
luaunit.assertEquals(child.x, expectedX, "Left offset should account for container padding")
luaunit.assertEquals(child.y, expectedY, "Top offset should account for container padding")
end
@@ -346,21 +346,21 @@ function TestLayoutEdgeCases:test_css_positioning_ignored_in_flex()
width = 400,
height = 400,
positioning = "flex",
flexDirection = "horizontal"
flexDirection = "horizontal",
})
local child = FlexLove.new({
id = "child",
parent = container,
top = 100, -- This should be IGNORED in flex layout
left = 100, -- This should be IGNORED in flex layout
top = 100, -- This should be IGNORED in flex layout
left = 100, -- This should be IGNORED in flex layout
width = 100,
height = 100
height = 100,
})
FlexLove.endFrame()
FlexLove.beginFrame()
-- In flex layout, child should be positioned by flex rules, not CSS offsets
-- Child should be at (0, 0) relative to container content area
luaunit.assertEquals(child.x, 0, "CSS offsets should be ignored in flex layout")
@@ -375,9 +375,9 @@ function TestLayoutEdgeCases:test_css_positioning_in_relative_container()
y = 100,
width = 400,
height = 400,
positioning = "relative"
positioning = "relative",
})
local child = FlexLove.new({
id = "child",
parent = container,
@@ -385,16 +385,16 @@ function TestLayoutEdgeCases:test_css_positioning_in_relative_container()
top = 30,
left = 30,
width = 100,
height = 100
height = 100,
})
FlexLove.endFrame()
FlexLove.beginFrame()
-- Should work the same as absolute container
local expectedX = container.x + container.padding.left + 30
local expectedY = container.y + container.padding.top + 30
luaunit.assertEquals(child.x, expectedX, "CSS positioning should work in relative containers")
luaunit.assertEquals(child.y, expectedY, "CSS positioning should work in relative containers")
end