new tests
This commit is contained in:
@@ -393,4 +393,5 @@ function TestAbsolutePositioning:testAbsolutePositioningInNestedLayoutWithMultip
|
||||
end
|
||||
|
||||
-- Run the tests
|
||||
luaunit.LuaUnit.run()
|
||||
luaunit.LuaUnit.run()
|
||||
|
||||
|
||||
@@ -1,241 +0,0 @@
|
||||
package.path = package.path
|
||||
.. ";./?.lua;./game/?.lua;./game/utils/?.lua;./game/components/?.lua;./game/systems/?.lua;./testing/?.lua"
|
||||
|
||||
local luaunit = require("testing.luaunit")
|
||||
require("testing.love_helper")
|
||||
|
||||
local Gui = require("game.libs.FlexLove").GUI
|
||||
local enums = require("game.libs.FlexLove").enums
|
||||
|
||||
-- Test case for align items alignment properties
|
||||
TestAlignItems = {}
|
||||
|
||||
function TestAlignItems:testStretchAlignItems()
|
||||
-- Create a horizontal flex container with stretch align items
|
||||
local window = Gui.new({
|
||||
x = 0,
|
||||
y = 0,
|
||||
w = 300,
|
||||
h = 200,
|
||||
positioning = enums.Positioning.FLEX,
|
||||
flexDirection = enums.FlexDirection.HORIZONTAL,
|
||||
justifyContent = enums.JustifyContent.FLEX_START,
|
||||
alignItems = enums.AlignItems.STRETCH,
|
||||
})
|
||||
|
||||
-- Add multiple children with different heights
|
||||
local child1 = Gui.new({
|
||||
parent = window,
|
||||
x = 0,
|
||||
y = 0,
|
||||
w = 50,
|
||||
h = 30,
|
||||
text = "Button 1",
|
||||
})
|
||||
|
||||
local child2 = Gui.new({
|
||||
parent = window,
|
||||
x = 0,
|
||||
y = 0,
|
||||
w = 60,
|
||||
h = 40,
|
||||
text = "Button 2",
|
||||
})
|
||||
|
||||
-- Layout children
|
||||
window:layoutChildren()
|
||||
|
||||
-- With stretch, children should be stretched to fill the container height
|
||||
luaunit.assertEquals(child1.height, 200) -- Should stretch to full container height
|
||||
luaunit.assertEquals(child2.height, 200) -- Should stretch to full container height
|
||||
end
|
||||
|
||||
function TestAlignItems:testFlexStartAlignItems()
|
||||
-- Create a horizontal flex container with flex-start align items
|
||||
local window = Gui.new({
|
||||
x = 0,
|
||||
y = 0,
|
||||
w = 300,
|
||||
h = 200,
|
||||
positioning = enums.Positioning.FLEX,
|
||||
flexDirection = enums.FlexDirection.HORIZONTAL,
|
||||
justifyContent = enums.JustifyContent.FLEX_START,
|
||||
alignItems = enums.AlignItems.FLEX_START,
|
||||
})
|
||||
|
||||
-- Add multiple children with different heights
|
||||
local child1 = Gui.new({
|
||||
parent = window,
|
||||
x = 0,
|
||||
y = 0,
|
||||
w = 50,
|
||||
h = 30,
|
||||
text = "Button 1",
|
||||
})
|
||||
|
||||
local child2 = Gui.new({
|
||||
parent = window,
|
||||
x = 0,
|
||||
y = 0,
|
||||
w = 60,
|
||||
h = 40,
|
||||
text = "Button 2",
|
||||
})
|
||||
|
||||
-- Layout children
|
||||
window:layoutChildren()
|
||||
|
||||
-- With flex-start, children should be aligned to the start of the cross axis (top)
|
||||
luaunit.assertEquals(child1.y, 0) -- Should be at top position
|
||||
luaunit.assertEquals(child2.y, 0) -- Should be at top position
|
||||
end
|
||||
|
||||
function TestAlignItems:testFlexEndAlignItems()
|
||||
-- Create a horizontal flex container with flex-end align items
|
||||
local window = Gui.new({
|
||||
x = 0,
|
||||
y = 0,
|
||||
w = 300,
|
||||
h = 200,
|
||||
positioning = enums.Positioning.FLEX,
|
||||
flexDirection = enums.FlexDirection.HORIZONTAL,
|
||||
justifyContent = enums.JustifyContent.FLEX_START,
|
||||
alignItems = enums.AlignItems.FLEX_END,
|
||||
})
|
||||
|
||||
-- Add multiple children with different heights
|
||||
local child1 = Gui.new({
|
||||
parent = window,
|
||||
x = 0,
|
||||
y = 0,
|
||||
w = 50,
|
||||
h = 30,
|
||||
text = "Button 1",
|
||||
})
|
||||
|
||||
local child2 = Gui.new({
|
||||
parent = window,
|
||||
x = 0,
|
||||
y = 0,
|
||||
w = 60,
|
||||
h = 40,
|
||||
text = "Button 2",
|
||||
})
|
||||
|
||||
-- Layout children
|
||||
window:layoutChildren()
|
||||
|
||||
-- With flex-end, children should be aligned to the end of the cross axis (bottom)
|
||||
luaunit.assertEquals(child1.y, 200 - 30) -- Should be at bottom position
|
||||
luaunit.assertEquals(child2.y, 200 - 40) -- Should be at bottom position
|
||||
end
|
||||
|
||||
function TestAlignItems:testCenterAlignItems()
|
||||
-- Create a horizontal flex container with center align items
|
||||
local window = Gui.new({
|
||||
x = 0,
|
||||
y = 0,
|
||||
w = 300,
|
||||
h = 200,
|
||||
positioning = enums.Positioning.FLEX,
|
||||
flexDirection = enums.FlexDirection.HORIZONTAL,
|
||||
justifyContent = enums.JustifyContent.FLEX_START,
|
||||
alignItems = enums.AlignItems.CENTER,
|
||||
})
|
||||
|
||||
-- Add multiple children with different heights
|
||||
local child1 = Gui.new({
|
||||
parent = window,
|
||||
x = 0,
|
||||
y = 0,
|
||||
w = 50,
|
||||
h = 30,
|
||||
text = "Button 1",
|
||||
})
|
||||
|
||||
local child2 = Gui.new({
|
||||
parent = window,
|
||||
x = 0,
|
||||
y = 0,
|
||||
w = 60,
|
||||
h = 40,
|
||||
text = "Button 2",
|
||||
})
|
||||
|
||||
-- Layout children
|
||||
window:layoutChildren()
|
||||
|
||||
-- With center, children should be centered along the cross axis
|
||||
luaunit.assertEquals(child1.y, (200 - 30) / 2) -- Should be centered vertically
|
||||
luaunit.assertEquals(child2.y, (200 - 40) / 2) -- Should be centered vertically
|
||||
end
|
||||
|
||||
function TestAlignItems:testVerticalAlignItems()
|
||||
-- Create a vertical flex container with align items properties
|
||||
local window = Gui.new({
|
||||
x = 0,
|
||||
y = 0,
|
||||
w = 300,
|
||||
h = 200,
|
||||
positioning = enums.Positioning.FLEX,
|
||||
flexDirection = enums.FlexDirection.VERTICAL,
|
||||
justifyContent = enums.JustifyContent.FLEX_START,
|
||||
alignItems = enums.AlignItems.CENTER,
|
||||
})
|
||||
|
||||
-- Add multiple children with different widths
|
||||
local child1 = Gui.new({
|
||||
parent = window,
|
||||
x = 0,
|
||||
y = 0,
|
||||
w = 50,
|
||||
h = 30,
|
||||
text = "Button 1",
|
||||
})
|
||||
|
||||
local child2 = Gui.new({
|
||||
parent = window,
|
||||
x = 0,
|
||||
y = 0,
|
||||
w = 60,
|
||||
h = 40,
|
||||
text = "Button 2",
|
||||
})
|
||||
|
||||
-- Layout children
|
||||
window:layoutChildren()
|
||||
|
||||
-- With vertical container, align items affects the X axis
|
||||
luaunit.assertEquals(child1.x, (300 - 50) / 2) -- Should be centered horizontally
|
||||
luaunit.assertEquals(child2.x, (300 - 60) / 2) -- Should be centered horizontally
|
||||
end
|
||||
|
||||
function TestAlignItems:testAlignItemsInheritance()
|
||||
-- Create a parent with stretch alignment
|
||||
local parentWindow = Gui.new({
|
||||
x = 0,
|
||||
y = 0,
|
||||
w = 300,
|
||||
h = 200,
|
||||
positioning = enums.Positioning.FLEX,
|
||||
flexDirection = enums.FlexDirection.HORIZONTAL,
|
||||
justifyContent = enums.JustifyContent.FLEX_START,
|
||||
alignItems = enums.AlignItems.STRETCH,
|
||||
})
|
||||
|
||||
-- Create a child without explicit alignment (should inherit)
|
||||
local child = Gui.new({
|
||||
parent = parentWindow,
|
||||
x = 0,
|
||||
y = 0,
|
||||
w = 50,
|
||||
h = 30,
|
||||
text = "Test Button",
|
||||
})
|
||||
|
||||
-- Verify child inherits align items from parent
|
||||
luaunit.assertEquals(child.alignItems, enums.AlignItems.STRETCH)
|
||||
end
|
||||
|
||||
-- Run the tests
|
||||
luaunit.LuaUnit.run()
|
||||
@@ -1,199 +0,0 @@
|
||||
package.path = package.path
|
||||
.. ";./?.lua;./game/?.lua;./game/utils/?.lua;./game/components/?.lua;./game/systems/?.lua;./testing/?.lua"
|
||||
|
||||
local luaunit = require("testing.luaunit")
|
||||
require("testing.love_helper")
|
||||
|
||||
local Gui = require("game.libs.FlexLove").GUI
|
||||
local enums = require("game.libs.FlexLove").enums
|
||||
|
||||
-- Test case for align self properties
|
||||
TestAlignSelf = {}
|
||||
|
||||
function TestAlignSelf:testAutoAlignSelf()
|
||||
-- Create a flex container with default alignment
|
||||
local window = Gui.new({
|
||||
x = 0,
|
||||
y = 0,
|
||||
w = 300,
|
||||
h = 200,
|
||||
positioning = enums.Positioning.FLEX,
|
||||
flexDirection = enums.FlexDirection.HORIZONTAL,
|
||||
justifyContent = enums.JustifyContent.FLEX_START,
|
||||
alignItems = enums.AlignItems.STRETCH,
|
||||
})
|
||||
|
||||
-- Add a child with auto align self
|
||||
local child = Gui.new({
|
||||
parent = window,
|
||||
x = 0,
|
||||
y = 0,
|
||||
w = 50,
|
||||
h = 30,
|
||||
text = "Test Button",
|
||||
alignSelf = enums.AlignSelf.AUTO,
|
||||
})
|
||||
|
||||
-- Layout children
|
||||
window:layoutChildren()
|
||||
|
||||
-- With auto, child should inherit alignment from parent's alignItems
|
||||
luaunit.assertEquals(child.alignSelf, enums.AlignSelf.AUTO)
|
||||
end
|
||||
|
||||
function TestAlignSelf:testStretchAlignSelf()
|
||||
-- Create a flex container with stretch alignment
|
||||
local window = Gui.new({
|
||||
x = 0,
|
||||
y = 0,
|
||||
w = 300,
|
||||
h = 200,
|
||||
positioning = enums.Positioning.FLEX,
|
||||
flexDirection = enums.FlexDirection.HORIZONTAL,
|
||||
justifyContent = enums.JustifyContent.FLEX_START,
|
||||
alignItems = enums.AlignItems.STRETCH,
|
||||
})
|
||||
|
||||
-- Add a child with stretch align self
|
||||
local child = Gui.new({
|
||||
parent = window,
|
||||
x = 0,
|
||||
y = 0,
|
||||
w = 50,
|
||||
h = 30,
|
||||
text = "Test Button",
|
||||
alignSelf = enums.AlignSelf.STRETCH,
|
||||
})
|
||||
|
||||
-- Layout children
|
||||
window:layoutChildren()
|
||||
|
||||
-- With stretch, child should be stretched to fill container height
|
||||
luaunit.assertEquals(child.height, 200) -- Should stretch to full container height
|
||||
end
|
||||
|
||||
function TestAlignSelf:testFlexStartAlignSelf()
|
||||
-- Create a flex container with center alignment
|
||||
local window = Gui.new({
|
||||
x = 0,
|
||||
y = 0,
|
||||
w = 300,
|
||||
h = 200,
|
||||
positioning = enums.Positioning.FLEX,
|
||||
flexDirection = enums.FlexDirection.HORIZONTAL,
|
||||
justifyContent = enums.JustifyContent.FLEX_START,
|
||||
alignItems = enums.AlignItems.CENTER,
|
||||
})
|
||||
|
||||
-- Add a child with flex-start align self
|
||||
local child = Gui.new({
|
||||
parent = window,
|
||||
x = 0,
|
||||
y = 0,
|
||||
w = 50,
|
||||
h = 30,
|
||||
text = "Test Button",
|
||||
alignSelf = enums.AlignSelf.FLEX_START,
|
||||
})
|
||||
|
||||
-- Layout children
|
||||
window:layoutChildren()
|
||||
|
||||
-- With flex-start, child should be aligned to the start of cross axis (top)
|
||||
luaunit.assertEquals(child.y, 0) -- Should be at top position
|
||||
end
|
||||
|
||||
function TestAlignSelf:testFlexEndAlignSelf()
|
||||
-- Create a flex container with center alignment
|
||||
local window = Gui.new({
|
||||
x = 0,
|
||||
y = 0,
|
||||
w = 300,
|
||||
h = 200,
|
||||
positioning = enums.Positioning.FLEX,
|
||||
flexDirection = enums.FlexDirection.HORIZONTAL,
|
||||
justifyContent = enums.JustifyContent.FLEX_START,
|
||||
alignItems = enums.AlignItems.CENTER,
|
||||
})
|
||||
|
||||
-- Add a child with flex-end align self
|
||||
local child = Gui.new({
|
||||
parent = window,
|
||||
x = 0,
|
||||
y = 0,
|
||||
w = 50,
|
||||
h = 30,
|
||||
text = "Test Button",
|
||||
alignSelf = enums.AlignSelf.FLEX_END,
|
||||
})
|
||||
|
||||
-- Layout children
|
||||
window:layoutChildren()
|
||||
|
||||
-- With flex-end, child should be aligned to the end of cross axis (bottom)
|
||||
luaunit.assertEquals(child.y, 200 - 30) -- Should be at bottom position
|
||||
end
|
||||
|
||||
function TestAlignSelf:testCenterAlignSelf()
|
||||
-- Create a flex container with stretch alignment
|
||||
local window = Gui.new({
|
||||
x = 0,
|
||||
y = 0,
|
||||
w = 300,
|
||||
h = 200,
|
||||
positioning = enums.Positioning.FLEX,
|
||||
flexDirection = enums.FlexDirection.HORIZONTAL,
|
||||
justifyContent = enums.JustifyContent.FLEX_START,
|
||||
alignItems = enums.AlignItems.STRETCH,
|
||||
})
|
||||
|
||||
-- Add a child with center align self
|
||||
local child = Gui.new({
|
||||
parent = window,
|
||||
w = 50,
|
||||
h = 30,
|
||||
text = "Test Button",
|
||||
alignSelf = enums.AlignSelf.CENTER,
|
||||
})
|
||||
|
||||
-- Layout children
|
||||
window:layoutChildren()
|
||||
|
||||
-- With center, child should be centered along cross axis
|
||||
luaunit.assertEquals(child.x, 0)
|
||||
luaunit.assertEquals(child.y, (200 - 30) / 2) -- Should be centered vertically
|
||||
end
|
||||
|
||||
function TestAlignSelf:testVerticalAlignSelf()
|
||||
-- Create a vertical flex container with center alignment
|
||||
local window = Gui.new({
|
||||
x = 0,
|
||||
y = 0,
|
||||
w = 300,
|
||||
h = 200,
|
||||
positioning = enums.Positioning.FLEX,
|
||||
flexDirection = enums.FlexDirection.VERTICAL,
|
||||
justifyContent = enums.JustifyContent.FLEX_START,
|
||||
alignItems = enums.AlignItems.CENTER,
|
||||
})
|
||||
|
||||
-- Add a child with center align self
|
||||
local child = Gui.new({
|
||||
parent = window,
|
||||
x = 0,
|
||||
y = 0,
|
||||
w = 50,
|
||||
h = 30,
|
||||
text = "Test Button",
|
||||
alignSelf = enums.AlignSelf.CENTER,
|
||||
})
|
||||
|
||||
-- Layout children
|
||||
window:layoutChildren()
|
||||
|
||||
-- With vertical container, align self affects the X axis
|
||||
luaunit.assertEquals(child.x, (300 - 50) / 2) -- Should be centered horizontally
|
||||
end
|
||||
|
||||
-- Run the tests
|
||||
luaunit.LuaUnit.run()
|
||||
475
testing/branching-layout-tests.lua
Normal file
475
testing/branching-layout-tests.lua
Normal file
@@ -0,0 +1,475 @@
|
||||
package.path = package.path
|
||||
.. ";./?.lua;./game/?.lua;./game/utils/?.lua;./game/components/?.lua;./game/systems/?.lua;./testing/?.lua"
|
||||
|
||||
local luaunit = require("testing.luaunit")
|
||||
require("testing.love_helper")
|
||||
|
||||
local Gui = require("game.libs.FlexLove").GUI
|
||||
local enums = require("game.libs.FlexLove").enums
|
||||
|
||||
-- Test case for branching flex layouts
|
||||
TestBranchingLayouts = {}
|
||||
|
||||
function TestBranchingLayouts:testMultipleChildrenAtSameLevel()
|
||||
-- Create a parent window with horizontal flex direction
|
||||
local parentWindow = Gui.new({
|
||||
x = 0,
|
||||
y = 0,
|
||||
w = 300,
|
||||
h = 200,
|
||||
positioning = enums.Positioning.FLEX,
|
||||
flexDirection = enums.FlexDirection.HORIZONTAL,
|
||||
justifyContent = enums.JustifyContent.FLEX_START,
|
||||
alignItems = enums.AlignItems.STRETCH,
|
||||
})
|
||||
|
||||
-- Create first child with different properties
|
||||
local child1 = Gui.new({
|
||||
parent = parentWindow,
|
||||
x = 0,
|
||||
y = 0,
|
||||
w = 100,
|
||||
h = 100,
|
||||
positioning = enums.Positioning.FLEX,
|
||||
flexDirection = enums.FlexDirection.VERTICAL,
|
||||
justifyContent = enums.JustifyContent.FLEX_START,
|
||||
alignItems = enums.AlignItems.STRETCH,
|
||||
})
|
||||
|
||||
-- Create second child with different properties
|
||||
local child2 = Gui.new({
|
||||
parent = parentWindow,
|
||||
x = 0,
|
||||
y = 0,
|
||||
w = 150,
|
||||
h = 100,
|
||||
positioning = enums.Positioning.FLEX,
|
||||
flexDirection = enums.FlexDirection.VERTICAL,
|
||||
justifyContent = enums.JustifyContent.CENTER,
|
||||
alignItems = enums.AlignItems.CENTER,
|
||||
})
|
||||
|
||||
-- Add children to first child (nested)
|
||||
local nestedChild1 = Gui.new({
|
||||
parent = child1,
|
||||
x = 0,
|
||||
y = 0,
|
||||
w = 50,
|
||||
h = 30,
|
||||
text = "Button 1",
|
||||
})
|
||||
|
||||
local nestedChild2 = Gui.new({
|
||||
parent = child1,
|
||||
x = 0,
|
||||
y = 0,
|
||||
w = 60,
|
||||
h = 40,
|
||||
text = "Button 2",
|
||||
})
|
||||
|
||||
-- Add children to second child (nested)
|
||||
local nestedChild3 = Gui.new({
|
||||
parent = child2,
|
||||
x = 0,
|
||||
y = 0,
|
||||
w = 70,
|
||||
h = 40,
|
||||
text = "Button 3",
|
||||
})
|
||||
|
||||
local nestedChild4 = Gui.new({
|
||||
parent = child2,
|
||||
x = 0,
|
||||
y = 0,
|
||||
w = 80,
|
||||
h = 50,
|
||||
text = "Button 4",
|
||||
})
|
||||
|
||||
-- Layout all children
|
||||
parentWindow:layoutChildren()
|
||||
|
||||
-- Verify that the main children are positioned correctly
|
||||
luaunit.assertEquals(child1.x, 0)
|
||||
luaunit.assertEquals(child1.y, 0)
|
||||
|
||||
luaunit.assertEquals(child2.x, 100)
|
||||
luaunit.assertEquals(child2.y, 0)
|
||||
|
||||
-- Verify that nested children in first child are laid out correctly (vertical)
|
||||
luaunit.assertEquals(nestedChild1.x, 0)
|
||||
luaunit.assertEquals(nestedChild1.y, 0)
|
||||
|
||||
luaunit.assertEquals(nestedChild2.x, 0)
|
||||
luaunit.assertEquals(nestedChild2.y, 30 + 10) -- Should be positioned after first child + gap
|
||||
|
||||
-- Verify that nested children in second child are laid out correctly (centered vertically)
|
||||
luaunit.assertEquals(nestedChild3.x, 0)
|
||||
luaunit.assertEquals(nestedChild3.y, (100 - 40) / 2) -- Should be centered vertically
|
||||
|
||||
luaunit.assertEquals(nestedChild4.x, 0)
|
||||
luaunit.assertEquals(nestedChild4.y, (100 - 50) / 2 + 40 + 10) -- Should be positioned after first child + gap
|
||||
end
|
||||
|
||||
function TestBranchingLayouts:testAsymmetricBranchingStructure()
|
||||
-- Create a parent window with horizontal flex direction
|
||||
local parentWindow = Gui.new({
|
||||
x = 0,
|
||||
y = 0,
|
||||
w = 400,
|
||||
h = 200,
|
||||
positioning = enums.Positioning.FLEX,
|
||||
flexDirection = enums.FlexDirection.HORIZONTAL,
|
||||
justifyContent = enums.JustifyContent.FLEX_START,
|
||||
alignItems = enums.AlignItems.STRETCH,
|
||||
})
|
||||
|
||||
-- Create a child with 3 branches - different sizes
|
||||
local branch1 = Gui.new({
|
||||
parent = parentWindow,
|
||||
x = 0,
|
||||
y = 0,
|
||||
w = 100,
|
||||
h = 100,
|
||||
positioning = enums.Positioning.FLEX,
|
||||
flexDirection = enums.FlexDirection.VERTICAL,
|
||||
justifyContent = enums.JustifyContent.FLEX_START,
|
||||
alignItems = enums.AlignItems.STRETCH,
|
||||
})
|
||||
|
||||
local branch2 = Gui.new({
|
||||
parent = parentWindow,
|
||||
x = 0,
|
||||
y = 0,
|
||||
w = 150,
|
||||
h = 100,
|
||||
positioning = enums.Positioning.FLEX,
|
||||
flexDirection = enums.FlexDirection.VERTICAL,
|
||||
justifyContent = enums.JustifyContent.CENTER,
|
||||
alignItems = enums.AlignItems.CENTER,
|
||||
})
|
||||
|
||||
local branch3 = Gui.new({
|
||||
parent = parentWindow,
|
||||
x = 0,
|
||||
y = 0,
|
||||
w = 150,
|
||||
h = 100,
|
||||
positioning = enums.Positioning.FLEX,
|
||||
flexDirection = enums.FlexDirection.VERTICAL,
|
||||
justifyContent = enums.JustifyContent.FLEX_END,
|
||||
alignItems = enums.AlignItems.FLEX_END,
|
||||
})
|
||||
|
||||
-- Add children to each branch with different sizes
|
||||
local child1_1 = Gui.new({
|
||||
parent = branch1,
|
||||
x = 0,
|
||||
y = 0,
|
||||
w = 50,
|
||||
h = 20,
|
||||
text = "Button 1",
|
||||
})
|
||||
|
||||
local child1_2 = Gui.new({
|
||||
parent = branch1,
|
||||
x = 0,
|
||||
y = 0,
|
||||
w = 60,
|
||||
h = 30,
|
||||
text = "Button 2",
|
||||
})
|
||||
|
||||
-- Add children to second branch
|
||||
local child2_1 = Gui.new({
|
||||
parent = branch2,
|
||||
x = 0,
|
||||
y = 0,
|
||||
w = 70,
|
||||
h = 40,
|
||||
text = "Button 3",
|
||||
})
|
||||
|
||||
local child2_2 = Gui.new({
|
||||
parent = branch2,
|
||||
x = 0,
|
||||
y = 0,
|
||||
w = 80,
|
||||
h = 50,
|
||||
text = "Button 4",
|
||||
})
|
||||
|
||||
local child2_3 = Gui.new({
|
||||
parent = branch2,
|
||||
x = 0,
|
||||
y = 0,
|
||||
w = 90,
|
||||
h = 60,
|
||||
text = "Button 5",
|
||||
})
|
||||
|
||||
-- Add children to third branch
|
||||
local child3_1 = Gui.new({
|
||||
parent = branch3,
|
||||
x = 0,
|
||||
y = 0,
|
||||
w = 70,
|
||||
h = 40,
|
||||
text = "Button 6",
|
||||
})
|
||||
|
||||
local child3_2 = Gui.new({
|
||||
parent = branch3,
|
||||
x = 0,
|
||||
y = 0,
|
||||
w = 80,
|
||||
h = 50,
|
||||
text = "Button 7",
|
||||
})
|
||||
|
||||
-- Layout all children
|
||||
parentWindow:layoutChildren()
|
||||
|
||||
-- Verify that the branches are positioned correctly
|
||||
luaunit.assertEquals(branch1.x, 0)
|
||||
luaunit.assertEquals(branch1.y, 0)
|
||||
|
||||
luaunit.assertEquals(branch2.x, 100)
|
||||
luaunit.assertEquals(branch2.y, 0)
|
||||
|
||||
luaunit.assertEquals(branch3.x, 250)
|
||||
luaunit.assertEquals(branch3.y, 0)
|
||||
|
||||
-- Verify that children in first branch are laid out correctly (flex-start)
|
||||
luaunit.assertEquals(child1_1.x, 0)
|
||||
luaunit.assertEquals(child1_1.y, 0)
|
||||
|
||||
luaunit.assertEquals(child1_2.x, 0)
|
||||
luaunit.assertEquals(child1_2.y, 20 + 10) -- Should be positioned after first child + gap
|
||||
|
||||
-- Verify that children in second branch are laid out correctly (centered)
|
||||
luaunit.assertEquals(child2_1.x, 0)
|
||||
luaunit.assertEquals(child2_1.y, (100 - 40) / 2) -- Should be centered vertically
|
||||
|
||||
luaunit.assertEquals(child2_2.x, 0)
|
||||
luaunit.assertEquals(child2_2.y, (100 - 50) / 2 + 40 + 10) -- Should be positioned after first child + gap
|
||||
|
||||
luaunit.assertEquals(child2_3.x, 0)
|
||||
luaunit.assertEquals(child2_3.y, (100 - 60) / 2 + 40 + 10 + 50 + 10) -- Should be positioned after second child + gap
|
||||
|
||||
-- Verify that children in third branch are laid out correctly (flex-end)
|
||||
luaunit.assertEquals(child3_1.x, 0)
|
||||
luaunit.assertEquals(child3_1.y, 100 - 40) -- Should be at bottom position
|
||||
|
||||
luaunit.assertEquals(child3_2.x, 0)
|
||||
luaunit.assertEquals(child3_2.y, 100 - 50 - 10) -- Should be positioned after first child + gap
|
||||
end
|
||||
|
||||
function TestBranchingLayouts:testMixedFlexDirectionInBranches()
|
||||
-- Create a parent window with horizontal flex direction
|
||||
local parentWindow = Gui.new({
|
||||
x = 0,
|
||||
y = 0,
|
||||
w = 400,
|
||||
h = 300,
|
||||
positioning = enums.Positioning.FLEX,
|
||||
flexDirection = enums.FlexDirection.HORIZONTAL,
|
||||
justifyContent = enums.JustifyContent.FLEX_START,
|
||||
alignItems = enums.AlignItems.STRETCH,
|
||||
})
|
||||
|
||||
-- Create a child branch with horizontal direction
|
||||
local horizontalBranch = Gui.new({
|
||||
parent = parentWindow,
|
||||
x = 0,
|
||||
y = 0,
|
||||
w = 200,
|
||||
h = 150,
|
||||
positioning = enums.Positioning.FLEX,
|
||||
flexDirection = enums.FlexDirection.HORIZONTAL,
|
||||
justifyContent = enums.JustifyContent.FLEX_START,
|
||||
alignItems = enums.AlignItems.STRETCH,
|
||||
})
|
||||
|
||||
-- Create a child branch with vertical direction
|
||||
local verticalBranch = Gui.new({
|
||||
parent = parentWindow,
|
||||
x = 0,
|
||||
y = 0,
|
||||
w = 200,
|
||||
h = 150,
|
||||
positioning = enums.Positioning.FLEX,
|
||||
flexDirection = enums.FlexDirection.VERTICAL,
|
||||
justifyContent = enums.JustifyContent.FLEX_START,
|
||||
alignItems = enums.AlignItems.STRETCH,
|
||||
})
|
||||
|
||||
-- Add children to horizontal branch
|
||||
local child1 = Gui.new({
|
||||
parent = horizontalBranch,
|
||||
x = 0,
|
||||
y = 0,
|
||||
w = 50,
|
||||
h = 30,
|
||||
text = "Button 1",
|
||||
})
|
||||
|
||||
local child2 = Gui.new({
|
||||
parent = horizontalBranch,
|
||||
x = 0,
|
||||
y = 0,
|
||||
w = 60,
|
||||
h = 40,
|
||||
text = "Button 2",
|
||||
})
|
||||
|
||||
-- Add children to vertical branch
|
||||
local child3 = Gui.new({
|
||||
parent = verticalBranch,
|
||||
x = 0,
|
||||
y = 0,
|
||||
w = 50,
|
||||
h = 30,
|
||||
text = "Button 3",
|
||||
})
|
||||
|
||||
local child4 = Gui.new({
|
||||
parent = verticalBranch,
|
||||
x = 0,
|
||||
y = 0,
|
||||
w = 60,
|
||||
h = 40,
|
||||
text = "Button 4",
|
||||
})
|
||||
|
||||
-- Layout all children
|
||||
parentWindow:layoutChildren()
|
||||
|
||||
-- Verify that the branches are positioned correctly
|
||||
luaunit.assertEquals(horizontalBranch.x, 0)
|
||||
luaunit.assertEquals(horizontalBranch.y, 0)
|
||||
|
||||
luaunit.assertEquals(verticalBranch.x, 200)
|
||||
luaunit.assertEquals(verticalBranch.y, 0)
|
||||
|
||||
-- Verify that children in horizontal branch are laid out horizontally
|
||||
luaunit.assertEquals(child1.x, 0)
|
||||
luaunit.assertEquals(child1.y, 0)
|
||||
|
||||
luaunit.assertEquals(child2.x, 50 + 10) -- Should be positioned after first child + gap
|
||||
luaunit.assertEquals(child2.y, 0)
|
||||
|
||||
-- Verify that children in vertical branch are laid out vertically
|
||||
luaunit.assertEquals(child3.x, 0)
|
||||
luaunit.assertEquals(child3.y, 0)
|
||||
|
||||
luaunit.assertEquals(child4.x, 0)
|
||||
luaunit.assertEquals(child4.y, 30 + 10) -- Should be positioned after first child + gap
|
||||
end
|
||||
|
||||
function TestBranchingLayouts:testCrossBranchAlignmentCoordination()
|
||||
-- Create a parent window with horizontal flex direction
|
||||
local parentWindow = Gui.new({
|
||||
x = 0,
|
||||
y = 0,
|
||||
w = 400,
|
||||
h = 300,
|
||||
positioning = enums.Positioning.FLEX,
|
||||
flexDirection = enums.FlexDirection.HORIZONTAL,
|
||||
justifyContent = enums.JustifyContent.SPACE_BETWEEN,
|
||||
alignItems = enums.AlignItems.CENTER,
|
||||
})
|
||||
|
||||
-- Create a child branch with different alignment
|
||||
local branch1 = Gui.new({
|
||||
parent = parentWindow,
|
||||
x = 0,
|
||||
y = 0,
|
||||
w = 150,
|
||||
h = 150,
|
||||
positioning = enums.Positioning.FLEX,
|
||||
flexDirection = enums.FlexDirection.VERTICAL,
|
||||
justifyContent = enums.JustifyContent.FLEX_START,
|
||||
alignItems = enums.AlignItems.STRETCH,
|
||||
})
|
||||
|
||||
-- Create another child branch with different alignment
|
||||
local branch2 = Gui.new({
|
||||
parent = parentWindow,
|
||||
x = 0,
|
||||
y = 0,
|
||||
w = 150,
|
||||
h = 150,
|
||||
positioning = enums.Positioning.FLEX,
|
||||
flexDirection = enums.FlexDirection.VERTICAL,
|
||||
justifyContent = enums.JustifyContent.FLEX_START,
|
||||
alignItems = enums.AlignItems.CENTER,
|
||||
})
|
||||
|
||||
-- Add children to first branch
|
||||
local child1_1 = Gui.new({
|
||||
parent = branch1,
|
||||
x = 0,
|
||||
y = 0,
|
||||
w = 50,
|
||||
h = 30,
|
||||
text = "Button 1",
|
||||
})
|
||||
|
||||
local child1_2 = Gui.new({
|
||||
parent = branch1,
|
||||
x = 0,
|
||||
y = 0,
|
||||
w = 60,
|
||||
h = 40,
|
||||
text = "Button 2",
|
||||
})
|
||||
|
||||
-- Add children to second branch
|
||||
local child2_1 = Gui.new({
|
||||
parent = branch2,
|
||||
x = 0,
|
||||
y = 0,
|
||||
w = 70,
|
||||
h = 30,
|
||||
text = "Button 3",
|
||||
})
|
||||
|
||||
local child2_2 = Gui.new({
|
||||
parent = branch2,
|
||||
x = 0,
|
||||
y = 0,
|
||||
w = 80,
|
||||
h = 40,
|
||||
text = "Button 4",
|
||||
})
|
||||
|
||||
-- Layout all children
|
||||
parentWindow:layoutChildren()
|
||||
|
||||
-- Verify that the branches are positioned correctly with space between
|
||||
luaunit.assertEquals(branch1.x, 0)
|
||||
luaunit.assertEquals(branch1.y, (300 - 150) / 2) -- Should be centered vertically
|
||||
|
||||
luaunit.assertEquals(branch2.x, 250)
|
||||
luaunit.assertEquals(branch2.y, (300 - 150) / 2) -- Should be centered vertically
|
||||
|
||||
-- Verify that children in first branch are laid out with stretch alignment
|
||||
luaunit.assertEquals(child1_1.x, 0)
|
||||
luaunit.assertEquals(child1_1.y, 0)
|
||||
|
||||
luaunit.assertEquals(child1_2.x, 0)
|
||||
luaunit.assertEquals(child1_2.y, 30 + 10) -- Should be positioned after first child + gap
|
||||
|
||||
-- Verify that children in second branch are laid out with center alignment
|
||||
luaunit.assertEquals(child2_1.x, (150 - 70) / 2) -- Should be centered horizontally
|
||||
luaunit.assertEquals(child2_1.y, 0)
|
||||
|
||||
luaunit.assertEquals(child2_2.x, (150 - 80) / 2) -- Should be centered horizontally
|
||||
luaunit.assertEquals(child2_2.y, 30 + 10) -- Should be positioned after first child + gap
|
||||
end
|
||||
|
||||
-- Run the tests
|
||||
luaunit.LuaUnit.run()
|
||||
|
||||
@@ -397,4 +397,5 @@ function TestComplexNestedLayouts:testComplexAlignmentInNesting()
|
||||
end
|
||||
|
||||
-- Run the tests
|
||||
os.exit(luaunit.LuaUnit.run())
|
||||
luaunit.LuaUnit.run()
|
||||
|
||||
|
||||
393
testing/depth-layout-tests.lua
Normal file
393
testing/depth-layout-tests.lua
Normal file
@@ -0,0 +1,393 @@
|
||||
package.path = package.path
|
||||
.. ";./?.lua;./game/?.lua;./game/utils/?.lua;./game/components/?.lua;./game/systems/?.lua;./testing/?.lua"
|
||||
|
||||
local luaunit = require("testing.luaunit")
|
||||
require("testing.love_helper")
|
||||
|
||||
local Gui = require("game.libs.FlexLove").GUI
|
||||
local enums = require("game.libs.FlexLove").enums
|
||||
|
||||
-- Test case for depth testing in nested layouts
|
||||
TestDepthLayouts = {}
|
||||
|
||||
function TestDepthLayouts:testMaximumNestingDepth()
|
||||
-- Create a parent window with horizontal flex direction
|
||||
local parentWindow = Gui.new({
|
||||
x = 0,
|
||||
y = 0,
|
||||
w = 300,
|
||||
h = 200,
|
||||
positioning = enums.Positioning.FLEX,
|
||||
flexDirection = enums.FlexDirection.HORIZONTAL,
|
||||
justifyContent = enums.JustifyContent.FLEX_START,
|
||||
alignItems = enums.AlignItems.STRETCH,
|
||||
})
|
||||
|
||||
-- Create a deeply nested structure (5 levels deep)
|
||||
local level1 = Gui.new({
|
||||
parent = parentWindow,
|
||||
x = 0,
|
||||
y = 0,
|
||||
w = 250,
|
||||
h = 150,
|
||||
positioning = enums.Positioning.FLEX,
|
||||
flexDirection = enums.FlexDirection.VERTICAL,
|
||||
justifyContent = enums.JustifyContent.FLEX_START,
|
||||
alignItems = enums.AlignItems.STRETCH,
|
||||
})
|
||||
|
||||
local level2 = Gui.new({
|
||||
parent = level1,
|
||||
x = 0,
|
||||
y = 0,
|
||||
w = 200,
|
||||
h = 100,
|
||||
positioning = enums.Positioning.FLEX,
|
||||
flexDirection = enums.FlexDirection.HORIZONTAL,
|
||||
justifyContent = enums.JustifyContent.FLEX_START,
|
||||
alignItems = enums.AlignItems.STRETCH,
|
||||
})
|
||||
|
||||
local level3 = Gui.new({
|
||||
parent = level2,
|
||||
x = 0,
|
||||
y = 0,
|
||||
w = 150,
|
||||
h = 80,
|
||||
positioning = enums.Positioning.FLEX,
|
||||
flexDirection = enums.FlexDirection.VERTICAL,
|
||||
justifyContent = enums.JustifyContent.CENTER,
|
||||
alignItems = enums.AlignItems.CENTER,
|
||||
})
|
||||
|
||||
local level4 = Gui.new({
|
||||
parent = level3,
|
||||
x = 0,
|
||||
y = 0,
|
||||
w = 100,
|
||||
h = 60,
|
||||
positioning = enums.Positioning.FLEX,
|
||||
flexDirection = enums.FlexDirection.HORIZONTAL,
|
||||
justifyContent = enums.JustifyContent.FLEX_START,
|
||||
alignItems = enums.AlignItems.STRETCH,
|
||||
})
|
||||
|
||||
local level5 = Gui.new({
|
||||
parent = level4,
|
||||
x = 0,
|
||||
y = 0,
|
||||
w = 50,
|
||||
h = 40,
|
||||
positioning = enums.Positioning.FLEX,
|
||||
flexDirection = enums.FlexDirection.VERTICAL,
|
||||
justifyContent = enums.JustifyContent.FLEX_END,
|
||||
alignItems = enums.AlignItems.FLEX_END,
|
||||
})
|
||||
|
||||
-- Add a child to the deepest level
|
||||
local deepChild = Gui.new({
|
||||
parent = level5,
|
||||
x = 0,
|
||||
y = 0,
|
||||
w = 20,
|
||||
h = 15,
|
||||
text = "Deep Child",
|
||||
})
|
||||
|
||||
-- Layout all children
|
||||
parentWindow:layoutChildren()
|
||||
|
||||
-- Verify that each level is positioned correctly
|
||||
luaunit.assertEquals(level1.x, 0)
|
||||
luaunit.assertEquals(level1.y, 0)
|
||||
|
||||
luaunit.assertEquals(level2.x, 0)
|
||||
luaunit.assertEquals(level2.y, 0)
|
||||
|
||||
luaunit.assertEquals(level3.x, 0)
|
||||
luaunit.assertEquals(level3.y, 0)
|
||||
|
||||
luaunit.assertEquals(level4.x, 0)
|
||||
luaunit.assertEquals(level4.y, 0)
|
||||
|
||||
luaunit.assertEquals(level5.x, 0)
|
||||
luaunit.assertEquals(level5.y, 0)
|
||||
|
||||
-- Verify that the deepest child is positioned correctly
|
||||
luaunit.assertEquals(deepChild.x, 0)
|
||||
luaunit.assertEquals(deepChild.y, 40 - 15) -- Should be at bottom position
|
||||
end
|
||||
|
||||
function TestDepthLayouts:testPropertyInheritanceThroughNesting()
|
||||
-- Create a parent window with specific properties
|
||||
local parentWindow = Gui.new({
|
||||
x = 0,
|
||||
y = 0,
|
||||
w = 300,
|
||||
h = 200,
|
||||
positioning = enums.Positioning.FLEX,
|
||||
flexDirection = enums.FlexDirection.HORIZONTAL,
|
||||
justifyContent = enums.JustifyContent.SPACE_BETWEEN,
|
||||
alignItems = enums.AlignItems.CENTER,
|
||||
flexWrap = enums.FlexWrap.WRAP,
|
||||
})
|
||||
|
||||
-- Create nested structure with inherited properties
|
||||
local level1 = Gui.new({
|
||||
parent = parentWindow,
|
||||
x = 0,
|
||||
y = 0,
|
||||
w = 250,
|
||||
h = 150,
|
||||
positioning = enums.Positioning.FLEX,
|
||||
flexDirection = enums.FlexDirection.VERTICAL,
|
||||
justifyContent = enums.JustifyContent.FLEX_START,
|
||||
alignItems = enums.AlignItems.STRETCH,
|
||||
})
|
||||
|
||||
local level2 = Gui.new({
|
||||
parent = level1,
|
||||
x = 0,
|
||||
y = 0,
|
||||
w = 200,
|
||||
h = 100,
|
||||
positioning = enums.Positioning.FLEX,
|
||||
flexDirection = enums.FlexDirection.HORIZONTAL,
|
||||
justifyContent = enums.JustifyContent.CENTER,
|
||||
alignItems = enums.AlignItems.CENTER,
|
||||
})
|
||||
|
||||
-- Add children to each level
|
||||
local child1 = Gui.new({
|
||||
parent = level1,
|
||||
x = 0,
|
||||
y = 0,
|
||||
w = 50,
|
||||
h = 30,
|
||||
text = "Child 1",
|
||||
})
|
||||
|
||||
local child2 = Gui.new({
|
||||
parent = level2,
|
||||
x = 0,
|
||||
y = 0,
|
||||
w = 60,
|
||||
h = 40,
|
||||
text = "Child 2",
|
||||
})
|
||||
|
||||
-- Layout all children
|
||||
parentWindow:layoutChildren()
|
||||
|
||||
-- Verify that properties are inherited appropriately
|
||||
-- The parent's flexWrap should be preserved through nesting
|
||||
-- The level1's flexDirection should be VERTICAL, and level2's should be HORIZONTAL
|
||||
luaunit.assertEquals(level1.x, 0)
|
||||
luaunit.assertEquals(level1.y, (200 - 150) / 2) -- Centered vertically
|
||||
|
||||
luaunit.assertEquals(level2.x, 0)
|
||||
luaunit.assertEquals(level2.y, 0)
|
||||
|
||||
-- Verify that children are positioned correctly based on their container's properties
|
||||
luaunit.assertEquals(child1.x, 0)
|
||||
luaunit.assertEquals(child1.y, (150 - 30) / 2) -- Centered vertically within level1
|
||||
|
||||
luaunit.assertEquals(child2.x, (200 - 60) / 2) -- Centered horizontally within level2
|
||||
luaunit.assertEquals(child2.y, (100 - 40) / 2) -- Centered vertically within level2
|
||||
end
|
||||
|
||||
function TestDepthLayouts:testSizeCalculationAccuracyAtDepth()
|
||||
-- Create a parent window with specific dimensions
|
||||
local parentWindow = Gui.new({
|
||||
x = 0,
|
||||
y = 0,
|
||||
w = 400,
|
||||
h = 300,
|
||||
positioning = enums.Positioning.FLEX,
|
||||
flexDirection = enums.FlexDirection.HORIZONTAL,
|
||||
justifyContent = enums.JustifyContent.FLEX_START,
|
||||
alignItems = enums.AlignItems.STRETCH,
|
||||
})
|
||||
|
||||
-- Create nested structure with precise sizing
|
||||
local level1 = Gui.new({
|
||||
parent = parentWindow,
|
||||
x = 0,
|
||||
y = 0,
|
||||
w = 300,
|
||||
h = 200,
|
||||
positioning = enums.Positioning.FLEX,
|
||||
flexDirection = enums.FlexDirection.VERTICAL,
|
||||
justifyContent = enums.JustifyContent.FLEX_START,
|
||||
alignItems = enums.AlignItems.STRETCH,
|
||||
})
|
||||
|
||||
local level2 = Gui.new({
|
||||
parent = level1,
|
||||
x = 0,
|
||||
y = 0,
|
||||
w = 250,
|
||||
h = 150,
|
||||
positioning = enums.Positioning.FLEX,
|
||||
flexDirection = enums.FlexDirection.HORIZONTAL,
|
||||
justifyContent = enums.JustifyContent.FLEX_START,
|
||||
alignItems = enums.AlignItems.STRETCH,
|
||||
})
|
||||
|
||||
local level3 = Gui.new({
|
||||
parent = level2,
|
||||
x = 0,
|
||||
y = 0,
|
||||
w = 200,
|
||||
h = 100,
|
||||
positioning = enums.Positioning.FLEX,
|
||||
flexDirection = enums.FlexDirection.VERTICAL,
|
||||
justifyContent = enums.JustifyContent.CENTER,
|
||||
alignItems = enums.AlignItems.CENTER,
|
||||
})
|
||||
|
||||
-- Add children to the deepest level
|
||||
local child1 = Gui.new({
|
||||
parent = level3,
|
||||
x = 0,
|
||||
y = 0,
|
||||
w = 50,
|
||||
h = 30,
|
||||
text = "Child 1",
|
||||
})
|
||||
|
||||
local child2 = Gui.new({
|
||||
parent = level3,
|
||||
x = 0,
|
||||
y = 0,
|
||||
w = 60,
|
||||
h = 40,
|
||||
text = "Child 2",
|
||||
})
|
||||
|
||||
-- Layout all children
|
||||
parentWindow:layoutChildren()
|
||||
|
||||
-- Verify that dimensions are preserved through nesting
|
||||
luaunit.assertEquals(level1.w, 300)
|
||||
luaunit.assertEquals(level1.h, 200)
|
||||
|
||||
luaunit.assertEquals(level2.w, 250)
|
||||
luaunit.assertEquals(level2.h, 150)
|
||||
|
||||
luaunit.assertEquals(level3.w, 200)
|
||||
luaunit.assertEquals(level3.h, 100)
|
||||
|
||||
-- Verify that children are positioned correctly within their containers
|
||||
luaunit.assertEquals(child1.x, (200 - 50) / 2) -- Centered horizontally within level3
|
||||
luaunit.assertEquals(child1.y, (100 - 30) / 2) -- Centered vertically within level3
|
||||
|
||||
luaunit.assertEquals(child2.x, (200 - 60) / 2 + 50 + 10) -- Positioned after first child + gap
|
||||
luaunit.assertEquals(child2.y, (100 - 40) / 2) -- Centered vertically within level3
|
||||
end
|
||||
|
||||
function TestDepthLayouts:testEdgeCasesInDeepLayouts()
|
||||
-- Create a parent window with complex layout properties
|
||||
local parentWindow = Gui.new({
|
||||
x = 0,
|
||||
y = 0,
|
||||
w = 400,
|
||||
h = 300,
|
||||
positioning = enums.Positioning.FLEX,
|
||||
flexDirection = enums.FlexDirection.HORIZONTAL,
|
||||
justifyContent = enums.JustifyContent.SPACE_BETWEEN,
|
||||
alignItems = enums.AlignItems.STRETCH,
|
||||
flexWrap = enums.FlexWrap.WRAP,
|
||||
})
|
||||
|
||||
-- Create a deep nested structure with varying child sizes
|
||||
local level1 = Gui.new({
|
||||
parent = parentWindow,
|
||||
x = 0,
|
||||
y = 0,
|
||||
w = 350,
|
||||
h = 250,
|
||||
positioning = enums.Positioning.FLEX,
|
||||
flexDirection = enums.FlexDirection.VERTICAL,
|
||||
justifyContent = enums.JustifyContent.FLEX_START,
|
||||
alignItems = enums.AlignItems.STRETCH,
|
||||
})
|
||||
|
||||
local level2 = Gui.new({
|
||||
parent = level1,
|
||||
x = 0,
|
||||
y = 0,
|
||||
w = 300,
|
||||
h = 200,
|
||||
positioning = enums.Positioning.FLEX,
|
||||
flexDirection = enums.FlexDirection.HORIZONTAL,
|
||||
justifyContent = enums.JustifyContent.CENTER,
|
||||
alignItems = enums.AlignItems.CENTER,
|
||||
})
|
||||
|
||||
-- Add children with different sizes at various depths
|
||||
local child1 = Gui.new({
|
||||
parent = level2,
|
||||
x = 0,
|
||||
y = 0,
|
||||
w = 80,
|
||||
h = 40,
|
||||
text = "Child 1",
|
||||
})
|
||||
|
||||
local child2 = Gui.new({
|
||||
parent = level2,
|
||||
x = 0,
|
||||
y = 0,
|
||||
w = 100,
|
||||
h = 50,
|
||||
text = "Child 2",
|
||||
})
|
||||
|
||||
-- Add children to the deepest level
|
||||
local deepChild1 = Gui.new({
|
||||
parent = level1,
|
||||
x = 0,
|
||||
y = 0,
|
||||
w = 30,
|
||||
h = 20,
|
||||
text = "Deep Child 1",
|
||||
})
|
||||
|
||||
local deepChild2 = Gui.new({
|
||||
parent = level1,
|
||||
x = 0,
|
||||
y = 0,
|
||||
w = 40,
|
||||
h = 25,
|
||||
text = "Deep Child 2",
|
||||
})
|
||||
|
||||
-- Layout all children
|
||||
parentWindow:layoutChildren()
|
||||
|
||||
-- Verify that edge cases are handled correctly
|
||||
luaunit.assertEquals(level1.x, 0)
|
||||
luaunit.assertEquals(level1.y, 0)
|
||||
|
||||
luaunit.assertEquals(level2.x, 0)
|
||||
luaunit.assertEquals(level2.y, 0)
|
||||
|
||||
-- Verify children in level2 are positioned correctly (centered)
|
||||
luaunit.assertEquals(child1.x, (300 - 80) / 2) -- Centered horizontally
|
||||
luaunit.assertEquals(child1.y, (200 - 40) / 2) -- Centered vertically
|
||||
|
||||
luaunit.assertEquals(child2.x, (300 - 100) / 2 + 80 + 10) -- Positioned after first child + gap
|
||||
luaunit.assertEquals(child2.y, (200 - 50) / 2) -- Centered vertically
|
||||
|
||||
-- Verify children in level1 are positioned correctly
|
||||
luaunit.assertEquals(deepChild1.x, 0)
|
||||
luaunit.assertEquals(deepChild1.y, 0)
|
||||
|
||||
luaunit.assertEquals(deepChild2.x, 0)
|
||||
luaunit.assertEquals(deepChild2.y, 20 + 10) -- Positioned after first child + gap
|
||||
end
|
||||
|
||||
-- Run the tests
|
||||
luaunit.LuaUnit.run()
|
||||
|
||||
@@ -1,243 +0,0 @@
|
||||
package.path = package.path
|
||||
.. ";./?.lua;./game/?.lua;./game/utils/?.lua;./game/components/?.lua;./game/systems/?.lua;./testing/?.lua"
|
||||
|
||||
local luaunit = require("testing.luaunit")
|
||||
require("testing.love_helper")
|
||||
|
||||
-- Mock Logger to avoid dependency issues
|
||||
local Logger = {
|
||||
debug = function() end,
|
||||
info = function() end,
|
||||
warn = function() end,
|
||||
error = function() end,
|
||||
}
|
||||
|
||||
-- Make sure the logger is available in the global scope
|
||||
_G.Logger = Logger
|
||||
|
||||
local Gui = require("game.libs.FlexLove").GUI
|
||||
local Color = require("game.libs.FlexLove").Color
|
||||
local enums = require("game.libs.FlexLove").enums
|
||||
|
||||
-- Test case for flex container layout behavior
|
||||
TestFlexContainer = {}
|
||||
|
||||
function TestFlexContainer:testWindowWithFlexPositioning()
|
||||
-- Create a window with flex positioning
|
||||
local window = Gui.new({
|
||||
x = 0,
|
||||
y = 0,
|
||||
w = 300,
|
||||
h = 200,
|
||||
positioning = enums.Positioning.FLEX,
|
||||
flexDirection = enums.FlexDirection.HORIZONTAL,
|
||||
justifyContent = enums.JustifyContent.FLEX_START,
|
||||
alignItems = enums.AlignItems.STRETCH,
|
||||
})
|
||||
|
||||
-- Verify window properties
|
||||
luaunit.assertEquals(window.x, 0)
|
||||
luaunit.assertEquals(window.y, 0)
|
||||
luaunit.assertEquals(window.width, 300)
|
||||
luaunit.assertEquals(window.height, 200)
|
||||
luaunit.assertEquals(window.positioning, enums.Positioning.FLEX)
|
||||
luaunit.assertEquals(window.flexDirection, enums.FlexDirection.HORIZONTAL)
|
||||
luaunit.assertEquals(window.justifyContent, enums.JustifyContent.FLEX_START)
|
||||
luaunit.assertEquals(window.alignItems, enums.AlignItems.STRETCH)
|
||||
end
|
||||
|
||||
function TestFlexContainer:testWindowAutoSizing()
|
||||
-- Create a window with flex positioning and auto-sizing
|
||||
local window = Gui.new({
|
||||
x = 0,
|
||||
y = 0,
|
||||
positioning = enums.Positioning.FLEX,
|
||||
flexDirection = enums.FlexDirection.HORIZONTAL,
|
||||
justifyContent = enums.JustifyContent.FLEX_START,
|
||||
alignItems = enums.AlignItems.STRETCH,
|
||||
})
|
||||
|
||||
-- Add a child with explicit dimensions
|
||||
local child = Gui.new({
|
||||
parent = window,
|
||||
x = 0,
|
||||
y = 0,
|
||||
w = 50,
|
||||
h = 30,
|
||||
text = "Test Button",
|
||||
})
|
||||
|
||||
-- Verify that the window auto-sizes to fit children (this should be calculated by layoutChildren)
|
||||
window:layoutChildren()
|
||||
|
||||
-- The window should have auto-sized based on children
|
||||
luaunit.assertEquals(#window.children, 1)
|
||||
luaunit.assertEquals(window.children[1], child)
|
||||
end
|
||||
|
||||
function TestFlexContainer:testWindowWithMultipleChildren()
|
||||
-- Create a flex container window
|
||||
local window = Gui.new({
|
||||
x = 0,
|
||||
y = 0,
|
||||
w = 300,
|
||||
h = 200,
|
||||
positioning = enums.Positioning.FLEX,
|
||||
flexDirection = enums.FlexDirection.HORIZONTAL,
|
||||
justifyContent = enums.JustifyContent.FLEX_START,
|
||||
alignItems = enums.AlignItems.STRETCH,
|
||||
})
|
||||
|
||||
-- Add multiple children
|
||||
local child1 = Gui.new({
|
||||
parent = window,
|
||||
x = 0,
|
||||
y = 0,
|
||||
w = 50,
|
||||
h = 30,
|
||||
text = "Button 1",
|
||||
})
|
||||
|
||||
local child2 = Gui.new({
|
||||
parent = window,
|
||||
x = 0,
|
||||
y = 0,
|
||||
w = 60,
|
||||
h = 40,
|
||||
text = "Button 2",
|
||||
})
|
||||
|
||||
local child3 = Gui.new({
|
||||
parent = window,
|
||||
x = 0,
|
||||
y = 0,
|
||||
w = 70,
|
||||
h = 50,
|
||||
text = "Button 3",
|
||||
})
|
||||
|
||||
-- Verify all children are added
|
||||
luaunit.assertEquals(#window.children, 3)
|
||||
luaunit.assertEquals(window.children[1], child1)
|
||||
luaunit.assertEquals(window.children[2], child2)
|
||||
luaunit.assertEquals(window.children[3], child3)
|
||||
|
||||
-- Test layout calculation
|
||||
window:layoutChildren()
|
||||
|
||||
-- Verify children positions are calculated (basic checks)
|
||||
luaunit.assertEquals(child1.x, 0) -- First child should be at start position
|
||||
end
|
||||
|
||||
function TestFlexContainer:testWindowDimensionsUpdateWhenChildrenAdded()
|
||||
-- Create a flex container window with explicit size
|
||||
local window = Gui.new({
|
||||
x = 0,
|
||||
y = 0,
|
||||
w = 300,
|
||||
h = 200,
|
||||
positioning = enums.Positioning.FLEX,
|
||||
flexDirection = enums.FlexDirection.HORIZONTAL,
|
||||
justifyContent = enums.JustifyContent.FLEX_START,
|
||||
alignItems = enums.AlignItems.STRETCH,
|
||||
})
|
||||
|
||||
-- Add a child
|
||||
local child = Gui.new({
|
||||
parent = window,
|
||||
x = 0,
|
||||
y = 0,
|
||||
w = 50,
|
||||
h = 30,
|
||||
text = "Test Button",
|
||||
})
|
||||
|
||||
-- Test that layoutChildren properly calculates positions
|
||||
window:layoutChildren()
|
||||
|
||||
-- Window dimensions should remain unchanged since we explicitly set them
|
||||
luaunit.assertEquals(window.width, 300)
|
||||
luaunit.assertEquals(window.height, 200)
|
||||
end
|
||||
|
||||
function TestFlexContainer:testWindowAutoSizingWhenNotExplicitlySet()
|
||||
-- Create a flex container window without explicit size (should auto-size)
|
||||
local window = Gui.new({
|
||||
x = 0,
|
||||
y = 0,
|
||||
positioning = enums.Positioning.FLEX,
|
||||
flexDirection = enums.FlexDirection.HORIZONTAL,
|
||||
justifyContent = enums.JustifyContent.FLEX_START,
|
||||
alignItems = enums.AlignItems.STRETCH,
|
||||
})
|
||||
|
||||
-- Add children
|
||||
local child1 = Gui.new({
|
||||
parent = window,
|
||||
x = 0,
|
||||
y = 0,
|
||||
w = 50,
|
||||
h = 30,
|
||||
text = "Button 1",
|
||||
})
|
||||
|
||||
local child2 = Gui.new({
|
||||
parent = window,
|
||||
x = 0,
|
||||
y = 0,
|
||||
w = 60,
|
||||
h = 40,
|
||||
text = "Button 2",
|
||||
})
|
||||
|
||||
-- Test auto-sizing calculation
|
||||
window:layoutChildren()
|
||||
|
||||
-- The window should have auto-sized based on children (this is a basic check)
|
||||
luaunit.assertEquals(#window.children, 2)
|
||||
end
|
||||
|
||||
function TestFlexContainer:testContainerLayoutChildrenFunction()
|
||||
-- Create a flex container window
|
||||
local window = Gui.new({
|
||||
x = 0,
|
||||
y = 0,
|
||||
w = 300,
|
||||
h = 200,
|
||||
positioning = enums.Positioning.FLEX,
|
||||
flexDirection = enums.FlexDirection.HORIZONTAL,
|
||||
justifyContent = enums.JustifyContent.FLEX_START,
|
||||
alignItems = enums.AlignItems.STRETCH,
|
||||
})
|
||||
|
||||
-- Add children
|
||||
local child1 = Gui.new({
|
||||
parent = window,
|
||||
x = 0,
|
||||
y = 0,
|
||||
w = 50,
|
||||
h = 30,
|
||||
text = "Button 1",
|
||||
})
|
||||
|
||||
local child2 = Gui.new({
|
||||
parent = window,
|
||||
x = 0,
|
||||
y = 0,
|
||||
w = 60,
|
||||
h = 40,
|
||||
text = "Button 2",
|
||||
})
|
||||
|
||||
-- Test that layoutChildren function exists and works
|
||||
luaunit.assertNotNil(window.layoutChildren)
|
||||
|
||||
-- Run the layout function
|
||||
window:layoutChildren()
|
||||
|
||||
-- Verify child positions (this is a basic test of functionality)
|
||||
luaunit.assertEquals(child1.x, 0) -- Should be at position 0 initially
|
||||
end
|
||||
|
||||
-- Run the tests
|
||||
luaunit.LuaUnit.run()
|
||||
@@ -296,5 +296,4 @@ function TestJustifyContent:testVerticalJustifyContent()
|
||||
end
|
||||
|
||||
-- Run the tests
|
||||
os.exit(luaunit.LuaUnit.run())
|
||||
|
||||
luaunit.LuaUnit.run()
|
||||
|
||||
@@ -1,253 +0,0 @@
|
||||
package.path = package.path
|
||||
.. ";./?.lua;./game/?.lua;./game/utils/?.lua;./game/components/?.lua;./game/systems/?.lua;./testing/?.lua"
|
||||
|
||||
local luaunit = require("testing.luaunit")
|
||||
require("testing.love_helper")
|
||||
|
||||
local Gui = require("game.libs.FlexLove").GUI
|
||||
local enums = require("game.libs.FlexLove").enums
|
||||
|
||||
-- Test case for nested flex layouts
|
||||
TestNestedLayouts = {}
|
||||
|
||||
function TestNestedLayouts:testSimpleNestedFlex()
|
||||
-- Create a parent window with horizontal flex direction
|
||||
local parentWindow = Gui.new({
|
||||
x = 0,
|
||||
y = 0,
|
||||
w = 300,
|
||||
h = 200,
|
||||
positioning = enums.Positioning.FLEX,
|
||||
flexDirection = enums.FlexDirection.HORIZONTAL,
|
||||
justifyContent = enums.JustifyContent.FLEX_START,
|
||||
alignItems = enums.AlignItems.STRETCH,
|
||||
})
|
||||
|
||||
-- Create a child window (nested flex container)
|
||||
local childWindow = Gui.new({
|
||||
parent = parentWindow,
|
||||
x = 0,
|
||||
y = 0,
|
||||
w = 150,
|
||||
h = 100,
|
||||
positioning = enums.Positioning.FLEX,
|
||||
flexDirection = enums.FlexDirection.VERTICAL,
|
||||
justifyContent = enums.JustifyContent.FLEX_START,
|
||||
alignItems = enums.AlignItems.STRETCH,
|
||||
})
|
||||
|
||||
-- Add children to nested window
|
||||
local child1 = Gui.new({
|
||||
parent = childWindow,
|
||||
x = 0,
|
||||
y = 0,
|
||||
w = 50,
|
||||
h = 30,
|
||||
text = "Button 1",
|
||||
})
|
||||
|
||||
local child2 = Gui.new({
|
||||
parent = childWindow,
|
||||
x = 0,
|
||||
y = 0,
|
||||
w = 60,
|
||||
h = 40,
|
||||
text = "Button 2",
|
||||
})
|
||||
|
||||
-- Layout all children
|
||||
parentWindow:layoutChildren()
|
||||
|
||||
-- Verify that the nested window is positioned correctly within parent
|
||||
luaunit.assertEquals(childWindow.x, 0) -- Should be positioned at start of parent
|
||||
luaunit.assertEquals(childWindow.y, 0) -- Should be positioned at start of parent
|
||||
|
||||
-- Verify that nested children are laid out correctly
|
||||
luaunit.assertEquals(child1.x, 0) -- Nested child should be at left position
|
||||
luaunit.assertEquals(child1.y, 0) -- Nested child should be at top position
|
||||
|
||||
luaunit.assertEquals(child2.x, 0) -- Nested child should be at left position
|
||||
luaunit.assertEquals(child2.y, 30 + 10) -- Should be positioned after first child + gap
|
||||
end
|
||||
|
||||
function TestNestedLayouts:testDeeplyNestedFlex()
|
||||
-- Create a parent window with horizontal flex direction
|
||||
local parentWindow = Gui.new({
|
||||
x = 0,
|
||||
y = 0,
|
||||
w = 300,
|
||||
h = 200,
|
||||
positioning = enums.Positioning.FLEX,
|
||||
flexDirection = enums.FlexDirection.HORIZONTAL,
|
||||
justifyContent = enums.JustifyContent.FLEX_START,
|
||||
alignItems = enums.AlignItems.STRETCH,
|
||||
})
|
||||
|
||||
-- Create a nested window
|
||||
local nestedWindow = Gui.new({
|
||||
parent = parentWindow,
|
||||
x = 0,
|
||||
y = 0,
|
||||
w = 150,
|
||||
h = 100,
|
||||
positioning = enums.Positioning.FLEX,
|
||||
flexDirection = enums.FlexDirection.VERTICAL,
|
||||
justifyContent = enums.JustifyContent.CENTER,
|
||||
alignItems = enums.AlignItems.CENTER,
|
||||
})
|
||||
|
||||
-- Create a deeply nested window
|
||||
local deepNestedWindow = Gui.new({
|
||||
parent = nestedWindow,
|
||||
x = 0,
|
||||
y = 0,
|
||||
w = 75,
|
||||
h = 50,
|
||||
positioning = enums.Positioning.FLEX,
|
||||
flexDirection = enums.FlexDirection.HORIZONTAL,
|
||||
justifyContent = enums.JustifyContent.FLEX_START,
|
||||
alignItems = enums.AlignItems.STRETCH,
|
||||
})
|
||||
|
||||
-- Add children to deep nested window
|
||||
local child1 = Gui.new({
|
||||
parent = deepNestedWindow,
|
||||
x = 0,
|
||||
y = 0,
|
||||
w = 20,
|
||||
h = 30,
|
||||
text = "Button 1",
|
||||
})
|
||||
|
||||
local child2 = Gui.new({
|
||||
parent = deepNestedWindow,
|
||||
x = 0,
|
||||
y = 0,
|
||||
w = 30,
|
||||
h = 40,
|
||||
text = "Button 2",
|
||||
})
|
||||
|
||||
-- Layout all children
|
||||
parentWindow:layoutChildren()
|
||||
|
||||
-- Verify nested structure and positioning
|
||||
luaunit.assertEquals(nestedWindow.x, 0)
|
||||
luaunit.assertEquals(nestedWindow.y, 0)
|
||||
|
||||
luaunit.assertEquals(deepNestedWindow.x, 37.5)
|
||||
luaunit.assertEquals(deepNestedWindow.y, 25)
|
||||
|
||||
-- Verify that deep nested children are laid out correctly
|
||||
luaunit.assertEquals(child1.x, 0)
|
||||
luaunit.assertEquals(child1.y, (50 - 30) / 2) -- Should be centered vertically
|
||||
|
||||
luaunit.assertEquals(child2.x, 20 + 10) -- Should be positioned after first child + gap
|
||||
luaunit.assertEquals(child2.y, (50 - 40) / 2) -- Should be centered vertically
|
||||
end
|
||||
|
||||
function TestNestedLayouts:testNestedFlexWithDifferentDirections()
|
||||
-- Create a parent with horizontal direction
|
||||
local parentWindow = Gui.new({
|
||||
x = 0,
|
||||
y = 0,
|
||||
w = 300,
|
||||
h = 200,
|
||||
positioning = enums.Positioning.FLEX,
|
||||
flexDirection = enums.FlexDirection.HORIZONTAL,
|
||||
justifyContent = enums.JustifyContent.FLEX_START,
|
||||
alignItems = enums.AlignItems.STRETCH,
|
||||
})
|
||||
|
||||
-- Create a nested window with vertical direction
|
||||
local childWindow = Gui.new({
|
||||
parent = parentWindow,
|
||||
x = 0,
|
||||
y = 0,
|
||||
w = 150,
|
||||
h = 100,
|
||||
positioning = enums.Positioning.FLEX,
|
||||
flexDirection = enums.FlexDirection.VERTICAL,
|
||||
justifyContent = enums.JustifyContent.FLEX_START,
|
||||
alignItems = enums.AlignItems.STRETCH,
|
||||
})
|
||||
|
||||
-- Add children to nested window with different sizes
|
||||
local child1 = Gui.new({
|
||||
parent = childWindow,
|
||||
x = 0,
|
||||
y = 0,
|
||||
w = 50,
|
||||
h = 30,
|
||||
text = "Button 1",
|
||||
})
|
||||
|
||||
local child2 = Gui.new({
|
||||
parent = childWindow,
|
||||
x = 0,
|
||||
y = 0,
|
||||
w = 60,
|
||||
h = 40,
|
||||
text = "Button 2",
|
||||
})
|
||||
|
||||
-- Layout all children
|
||||
parentWindow:layoutChildren()
|
||||
|
||||
-- Verify that the nested container properly layouts its children vertically
|
||||
luaunit.assertEquals(child1.x, 0) -- Should be at left position
|
||||
luaunit.assertEquals(child1.y, 0) -- Should be at top position
|
||||
|
||||
luaunit.assertEquals(child2.x, 0) -- Should be at left position
|
||||
luaunit.assertEquals(child2.y, 30 + 10) -- Should be positioned after first child + gap
|
||||
|
||||
-- Verify that the parent container positions its children horizontally
|
||||
luaunit.assertEquals(childWindow.x, 0) -- Should be at start of parent
|
||||
end
|
||||
|
||||
function TestNestedLayouts:testAbsolutePositioningInNestedLayout()
|
||||
-- Create a parent with flex direction
|
||||
local parentWindow = Gui.new({
|
||||
x = 0,
|
||||
y = 0,
|
||||
w = 300,
|
||||
h = 200,
|
||||
positioning = enums.Positioning.FLEX,
|
||||
flexDirection = enums.FlexDirection.HORIZONTAL,
|
||||
justifyContent = enums.JustifyContent.FLEX_START,
|
||||
alignItems = enums.AlignItems.STRETCH,
|
||||
})
|
||||
|
||||
-- Create a nested window with absolute positioning
|
||||
local childWindow = Gui.new({
|
||||
parent = parentWindow,
|
||||
x = 50,
|
||||
y = 50,
|
||||
w = 150,
|
||||
h = 100,
|
||||
positioning = enums.Positioning.ABSOLUTE,
|
||||
})
|
||||
|
||||
-- Add children to nested window
|
||||
local child1 = Gui.new({
|
||||
parent = childWindow,
|
||||
x = 0,
|
||||
y = 0,
|
||||
w = 50,
|
||||
h = 30,
|
||||
text = "Button 1",
|
||||
})
|
||||
|
||||
-- Layout all children
|
||||
parentWindow:layoutChildren()
|
||||
|
||||
-- Verify that absolute positioned nested window maintains its position
|
||||
luaunit.assertEquals(childWindow.x, 50)
|
||||
luaunit.assertEquals(childWindow.y, 50)
|
||||
|
||||
-- Verify that absolute positioning doesn't interfere with parent layout
|
||||
luaunit.assertEquals(parentWindow.children[1], childWindow)
|
||||
end
|
||||
|
||||
-- Run the tests
|
||||
os.exit(luaunit.LuaUnit.run())
|
||||
Reference in New Issue
Block a user