testing layout changes

This commit is contained in:
Michael Freno
2025-09-18 17:17:20 -04:00
parent 7f21c76766
commit d869582b37
8 changed files with 3620 additions and 2264 deletions

View File

@@ -1,397 +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 absolute positioning behavior with complex nested layouts
TestAbsolutePositioning = {}
function TestAbsolutePositioning:testDeeplyNestedAbsolutePositioning()
-- Create a root window with flex positioning
local rootWindow = Gui.new({
x = 0,
y = 0,
w = 800,
h = 600,
positioning = enums.Positioning.FLEX,
flexDirection = enums.FlexDirection.HORIZONTAL,
justifyContent = enums.JustifyContent.FLEX_START,
alignItems = enums.AlignItems.STRETCH,
})
-- Create a nested flex container
local nestedFlexContainer = Gui.new({
parent = rootWindow,
x = 100,
y = 50,
w = 300,
h = 200,
positioning = enums.Positioning.FLEX,
flexDirection = enums.FlexDirection.VERTICAL,
justifyContent = enums.JustifyContent.CENTER,
alignItems = enums.AlignItems.STRETCH,
})
-- Create an absolute positioned child in nested container
local absoluteChildInNested = Gui.new({
parent = nestedFlexContainer,
x = 20,
y = 30,
w = 80,
h = 40,
positioning = enums.Positioning.ABSOLUTE,
text = "Nested Absolute",
})
-- Create another flex child in nested container
local flexChildInNested = Gui.new({
parent = nestedFlexContainer,
x = 0,
y = 0,
w = 60,
h = 30,
text = "Nested Flex",
})
-- Layout all children
rootWindow:layoutChildren()
-- Verify absolute child position is correct (relative to parent)
luaunit.assertEquals(absoluteChildInNested.x, 120) -- 100 + 20
luaunit.assertEquals(absoluteChildInNested.y, 80) -- 50 + 30
-- Verify flex child position is calculated correctly within nested container
luaunit.assertEquals(flexChildInNested.x, 0) -- Should be at start of container
luaunit.assertEquals(flexChildInNested.y, 100 - 30) -- Should be centered vertically in 100px container
-- Verify parent-child relationships
luaunit.assertEquals(#nestedFlexContainer.children, 2)
luaunit.assertEquals(nestedFlexContainer.children[1], absoluteChildInNested)
luaunit.assertEquals(nestedFlexContainer.children[2], flexChildInNested)
end
function TestAbsolutePositioning:testMixedLayoutTypesWithNesting()
-- Create a complex nested structure with mixed layout types
local rootWindow = Gui.new({
x = 0,
y = 0,
w = 800,
h = 600,
positioning = enums.Positioning.FLEX,
flexDirection = enums.FlexDirection.VERTICAL,
justifyContent = enums.JustifyContent.FLEX_START,
alignItems = enums.AlignItems.STRETCH,
})
-- Create a flex container with absolute positioning
local flexContainerWithAbsolute = Gui.new({
parent = rootWindow,
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,
})
-- Add absolute positioned child to flex container
local absoluteChild1 = Gui.new({
parent = flexContainerWithAbsolute,
x = 50,
y = 20,
w = 60,
h = 30,
positioning = enums.Positioning.ABSOLUTE,
text = "Abs Child 1",
})
-- Add nested absolute positioned child
local nestedAbsoluteChild = Gui.new({
parent = flexContainerWithAbsolute,
x = 100,
y = 100,
w = 40,
h = 20,
positioning = enums.Positioning.ABSOLUTE,
text = "Nested Abs",
})
-- Add regular flex child
local flexChild = Gui.new({
parent = flexContainerWithAbsolute,
x = 0,
y = 0,
w = 80,
h = 40,
text = "Flex Child",
})
-- Layout children
rootWindow:layoutChildren()
-- Verify absolute positions are correct
luaunit.assertEquals(absoluteChild1.x, 50)
luaunit.assertEquals(absoluteChild1.y, 20)
luaunit.assertEquals(nestedAbsoluteChild.x, 100)
luaunit.assertEquals(nestedAbsoluteChild.y, 100)
-- Verify flex child is positioned by flex layout
luaunit.assertEquals(flexChild.x, 0) -- First flex child in space-between should be at start
end
function TestAbsolutePositioning:testAbsolutePositioningInComplexBranchingStructure()
-- Create a complex branching structure with multiple absolute positions
local rootWindow = Gui.new({
x = 0,
y = 0,
w = 800,
h = 600,
positioning = enums.Positioning.FLEX,
flexDirection = enums.FlexDirection.HORIZONTAL,
justifyContent = enums.JustifyContent.FLEX_START,
alignItems = enums.AlignItems.STRETCH,
})
-- Create three branches with different absolute positions
local branch1 = Gui.new({
parent = rootWindow,
x = 0,
y = 0,
w = 200,
h = 300,
positioning = enums.Positioning.FLEX,
flexDirection = enums.FlexDirection.VERTICAL,
justifyContent = enums.JustifyContent.FLEX_START,
alignItems = enums.AlignItems.STRETCH,
})
local branch2 = Gui.new({
parent = rootWindow,
x = 250,
y = 100,
w = 200,
h = 300,
positioning = enums.Positioning.FLEX,
flexDirection = enums.FlexDirection.VERTICAL,
justifyContent = enums.JustifyContent.FLEX_START,
alignItems = enums.AlignItems.STRETCH,
})
local branch3 = Gui.new({
parent = rootWindow,
x = 500,
y = 200,
w = 200,
h = 300,
positioning = enums.Positioning.FLEX,
flexDirection = enums.FlexDirection.VERTICAL,
justifyContent = enums.JustifyContent.FLEX_START,
alignItems = enums.AlignItems.STRETCH,
})
-- Add absolute positioned children to each branch
local absChild1 = Gui.new({
parent = branch1,
x = 10,
y = 15,
w = 50,
h = 20,
positioning = enums.Positioning.ABSOLUTE,
text = "Branch1 Abs",
})
local absChild2 = Gui.new({
parent = branch2,
x = 20,
y = 30,
w = 60,
h = 25,
positioning = enums.Positioning.ABSOLUTE,
text = "Branch2 Abs",
})
local absChild3 = Gui.new({
parent = branch3,
x = 30,
y = 40,
w = 70,
h = 30,
positioning = enums.Positioning.ABSOLUTE,
text = "Branch3 Abs",
})
-- Add regular children to branches
local regularChild1 = Gui.new({
parent = branch1,
x = 0,
y = 0,
w = 40,
h = 25,
text = "Branch1 Regular",
})
local regularChild2 = Gui.new({
parent = branch2,
x = 0,
y = 0,
w = 50,
h = 30,
text = "Branch2 Regular",
})
-- Layout all children
rootWindow:layoutChildren()
-- Verify absolute positions in each branch (absolute position relative to branch parent)
luaunit.assertEquals(absChild1.x, 10) -- 0 + 10
luaunit.assertEquals(absChild1.y, 15) -- 0 + 15
luaunit.assertEquals(absChild2.x, 250 + 20) -- 250 + 20
luaunit.assertEquals(absChild2.y, 100 + 30) -- 100 + 30
luaunit.assertEquals(absChild3.x, 500 + 30) -- 500 + 30
luaunit.assertEquals(absChild3.y, 200 + 40) -- 200 + 40
-- Verify that regular children are positioned by flex layout
luaunit.assertEquals(regularChild1.x, 0)
luaunit.assertEquals(regularChild2.x, 0)
end
function TestAbsolutePositioning:testAbsolutePositioningWithComplexTransformations()
-- Create a complex structure with transformations and absolute positioning
local rootWindow = Gui.new({
x = 100,
y = 50,
w = 600,
h = 400,
positioning = enums.Positioning.FLEX,
flexDirection = enums.FlexDirection.VERTICAL,
justifyContent = enums.JustifyContent.FLEX_START,
alignItems = enums.AlignItems.STRETCH,
})
-- Create a container with padding and margin
local containerWithPadding = Gui.new({
parent = rootWindow,
x = 0,
y = 0,
w = 300,
h = 200,
positioning = enums.Positioning.FLEX,
flexDirection = enums.FlexDirection.HORIZONTAL,
justifyContent = enums.JustifyContent.SPACE_AROUND,
alignItems = enums.AlignItems.CENTER,
padding = { left = 10, top = 5 },
margin = { left = 15, top = 10 },
})
-- Add absolute positioned child with padding/margin consideration
local absChildWithPadding = Gui.new({
parent = containerWithPadding,
x = 20,
y = 30,
w = 80,
h = 40,
positioning = enums.Positioning.ABSOLUTE,
text = "Abs with Padding",
})
-- Layout children
rootWindow:layoutChildren()
-- Verify absolute position accounts for parent padding and margin
luaunit.assertEquals(absChildWithPadding.x, 100 + 15 + 20) -- root x + margin + child x
luaunit.assertEquals(absChildWithPadding.y, 50 + 10 + 30) -- root y + margin + child y
end
function TestAbsolutePositioning:testAbsolutePositioningInNestedLayoutWithMultipleLevels()
-- Create a deeply nested structure with absolute positioning at multiple levels
local rootWindow = Gui.new({
x = 0,
y = 0,
w = 800,
h = 600,
positioning = enums.Positioning.FLEX,
flexDirection = enums.FlexDirection.HORIZONTAL,
justifyContent = enums.JustifyContent.FLEX_START,
alignItems = enums.AlignItems.STRETCH,
})
-- Level 1: Main container
local level1Container = Gui.new({
parent = rootWindow,
x = 50,
y = 30,
w = 400,
h = 300,
positioning = enums.Positioning.FLEX,
flexDirection = enums.FlexDirection.VERTICAL,
justifyContent = enums.JustifyContent.FLEX_START,
alignItems = enums.AlignItems.STRETCH,
})
-- Level 2: Nested container
local level2Container = Gui.new({
parent = level1Container,
x = 0,
y = 0,
w = 300,
h = 200,
positioning = enums.Positioning.FLEX,
flexDirection = enums.FlexDirection.HORIZONTAL,
justifyContent = enums.JustifyContent.CENTER,
alignItems = enums.AlignItems.STRETCH,
})
-- Level 3: Deep nested container
local level3Container = Gui.new({
parent = level2Container,
x = 20,
y = 10,
w = 150,
h = 100,
positioning = enums.Positioning.FLEX,
flexDirection = enums.FlexDirection.VERTICAL,
justifyContent = enums.JustifyContent.SPACE_BETWEEN,
alignItems = enums.AlignItems.CENTER,
})
-- Add absolute positioned child at level 3
local absChildAtLevel3 = Gui.new({
parent = level3Container,
x = 10,
y = 20,
w = 60,
h = 30,
positioning = enums.Positioning.ABSOLUTE,
text = "Deep Abs",
})
-- Add flex child at level 3
local flexChildAtLevel3 = Gui.new({
parent = level3Container,
x = 0,
y = 0,
w = 40,
h = 25,
text = "Deep Flex",
})
-- Layout all children
rootWindow:layoutChildren()
-- Verify absolute position at deepest level
luaunit.assertEquals(absChildAtLevel3.x, 50 + 0 + 20 + 10) -- root x + level1 x + level2 x + child x
luaunit.assertEquals(absChildAtLevel3.y, 30 + 0 + 10 + 20) -- root y + level1 y + level2 y + child y
-- Verify that flex child is positioned by flex layout at level 3
luaunit.assertEquals(flexChildAtLevel3.x, 0) -- Should be at start of container
end
-- Run the tests
luaunit.LuaUnit.run()

View File

@@ -1,475 +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 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()

View File

@@ -1,401 +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 complex nested flex layouts
TestComplexNestedLayouts = {}
function TestComplexNestedLayouts:testDeepThreeLevelNesting()
-- 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.STRETCH,
})
-- Create first nested window (level 1)
local level1Window = Gui.new({
parent = parentWindow,
x = 0,
y = 0,
w = 200,
h = 150,
positioning = enums.Positioning.FLEX,
flexDirection = enums.FlexDirection.VERTICAL,
justifyContent = enums.JustifyContent.CENTER,
alignItems = enums.AlignItems.FLEX_START,
})
-- Create second nested window (level 2)
local level2Window = Gui.new({
parent = level1Window,
x = 0,
y = 0,
w = 100,
h = 75,
positioning = enums.Positioning.FLEX,
flexDirection = enums.FlexDirection.HORIZONTAL,
justifyContent = enums.JustifyContent.FLEX_START,
alignItems = enums.AlignItems.CENTER,
})
-- Create third nested window (level 3)
local level3Window = Gui.new({
parent = level2Window,
x = 0,
y = 0,
w = 50,
h = 30,
positioning = enums.Positioning.FLEX,
flexDirection = enums.FlexDirection.VERTICAL,
justifyContent = enums.JustifyContent.SPACE_AROUND,
alignItems = enums.AlignItems.STRETCH,
})
-- Add children to level 3 window
local child1 = Gui.new({
parent = level3Window,
x = 0,
y = 0,
w = 15,
h = 10,
text = "Button 1",
})
local child2 = Gui.new({
parent = level3Window,
x = 0,
y = 0,
w = 20,
h = 12,
text = "Button 2",
})
local child3 = Gui.new({
parent = level3Window,
x = 0,
y = 0,
w = 18,
h = 15,
text = "Button 3",
})
-- Layout all children
parentWindow:layoutChildren()
-- Verify that the nested structure is positioned correctly (basic checks)
luaunit.assertTrue(level1Window.x >= 0)
luaunit.assertTrue(level1Window.y >= 0)
luaunit.assertTrue(level2Window.x >= 0)
luaunit.assertTrue(level2Window.y >= 0)
luaunit.assertTrue(level3Window.x >= 0)
luaunit.assertTrue(level3Window.y >= 0)
-- Verify that level 3 children are laid out correctly (basic checks)
luaunit.assertTrue(child1.x >= 0)
luaunit.assertTrue(child1.y >= 0)
luaunit.assertTrue(child2.x >= 0)
luaunit.assertTrue(child2.y >= 0)
luaunit.assertTrue(child3.x >= 0)
luaunit.assertTrue(child3.y >= 0)
end
function TestComplexNestedLayouts:testFourLevelNestingWithMixedDirections()
-- Create a parent window with vertical flex direction
local parentWindow = Gui.new({
x = 0,
y = 0,
w = 300,
h = 400,
positioning = enums.Positioning.FLEX,
flexDirection = enums.FlexDirection.VERTICAL,
justifyContent = enums.JustifyContent.FLEX_START,
alignItems = enums.AlignItems.STRETCH,
})
-- Create first nested window (level 1)
local level1Window = Gui.new({
parent = parentWindow,
x = 0,
y = 0,
w = 250,
h = 100,
positioning = enums.Positioning.FLEX,
flexDirection = enums.FlexDirection.HORIZONTAL,
justifyContent = enums.JustifyContent.SPACE_EVENLY,
alignItems = enums.AlignItems.FLEX_START,
})
-- Create second nested window (level 2)
local level2Window = Gui.new({
parent = level1Window,
x = 0,
y = 0,
w = 150,
h = 80,
positioning = enums.Positioning.FLEX,
flexDirection = enums.FlexDirection.VERTICAL,
justifyContent = enums.JustifyContent.CENTER,
alignItems = enums.AlignItems.STRETCH,
})
-- Create third nested window (level 3)
local level3Window = Gui.new({
parent = level2Window,
x = 0,
y = 0,
w = 75,
h = 40,
positioning = enums.Positioning.FLEX,
flexDirection = enums.FlexDirection.HORIZONTAL,
justifyContent = enums.JustifyContent.FLEX_END,
alignItems = enums.AlignItems.FLEX_START,
})
-- Create fourth nested window (level 4)
local level4Window = Gui.new({
parent = level3Window,
x = 0,
y = 0,
w = 30,
h = 20,
positioning = enums.Positioning.FLEX,
flexDirection = enums.FlexDirection.VERTICAL,
justifyContent = enums.JustifyContent.SPACE_BETWEEN,
alignItems = enums.AlignItems.CENTER,
})
-- Add children to level 4 window
local child1 = Gui.new({
parent = level4Window,
x = 0,
y = 0,
w = 10,
h = 8,
text = "Button 1",
})
local child2 = Gui.new({
parent = level4Window,
x = 0,
y = 0,
w = 12,
h = 10,
text = "Button 2",
})
-- Layout all children
parentWindow:layoutChildren()
-- Verify that the nested structure is positioned correctly (basic checks)
luaunit.assertTrue(level1Window.x >= 0)
luaunit.assertTrue(level1Window.y >= 0)
luaunit.assertTrue(level2Window.x >= 0)
luaunit.assertTrue(level2Window.y >= 0)
luaunit.assertTrue(level3Window.x >= 0)
luaunit.assertTrue(level3Window.y >= 0)
luaunit.assertTrue(level4Window.x >= 0)
luaunit.assertTrue(level4Window.y >= 0)
-- Verify that level 4 children are laid out correctly (basic checks)
luaunit.assertTrue(child1.x >= 0)
luaunit.assertTrue(child1.y >= 0)
luaunit.assertTrue(child2.x >= 0)
luaunit.assertTrue(child2.y >= 0)
end
function TestComplexNestedLayouts:testBranchingNestingStructure()
-- 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 first branch (left side)
local leftBranch = 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,
})
-- Create second branch (right side)
local rightBranch = Gui.new({
parent = parentWindow,
x = 0,
y = 0,
w = 200,
h = 150,
positioning = enums.Positioning.FLEX,
flexDirection = enums.FlexDirection.VERTICAL,
justifyContent = enums.JustifyContent.CENTER,
alignItems = enums.AlignItems.FLEX_START,
})
-- Create children for left branch
local leftChild1 = Gui.new({
parent = leftBranch,
x = 0,
y = 0,
w = 100,
h = 50,
text = "Left Child 1",
})
local leftChild2 = Gui.new({
parent = leftBranch,
x = 0,
y = 0,
w = 100,
h = 40,
text = "Left Child 2",
})
-- Create children for right branch
local rightChild1 = Gui.new({
parent = rightBranch,
x = 0,
y = 0,
w = 150,
h = 60,
text = "Right Child 1",
})
local rightChild2 = Gui.new({
parent = rightBranch,
x = 0,
y = 0,
w = 150,
h = 70,
text = "Right Child 2",
})
-- Layout all children
parentWindow:layoutChildren()
-- Verify that the branches are positioned correctly (basic checks)
luaunit.assertTrue(leftBranch.x >= 0)
luaunit.assertTrue(leftBranch.y >= 0)
luaunit.assertTrue(rightBranch.x >= 0)
luaunit.assertTrue(rightBranch.y >= 0)
-- Verify that left branch children are laid out correctly (basic checks)
luaunit.assertTrue(leftChild1.x >= 0)
luaunit.assertTrue(leftChild1.y >= 0)
luaunit.assertTrue(leftChild2.x >= 0)
luaunit.assertTrue(leftChild2.y >= 0)
-- Verify that right branch children are laid out correctly (basic checks)
luaunit.assertTrue(rightChild1.x >= 0)
luaunit.assertTrue(rightChild1.y >= 0)
luaunit.assertTrue(rightChild2.x >= 0)
luaunit.assertTrue(rightChild2.y >= 0)
end
function TestComplexNestedLayouts:testComplexAlignmentInNesting()
-- 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.SPACE_BETWEEN,
alignItems = enums.AlignItems.CENTER,
})
-- Create nested window with different alignment
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.FLEX_START,
alignItems = enums.AlignItems.FLEX_END,
})
-- Create children with different sizes
local child1 = Gui.new({
parent = nestedWindow,
x = 0,
y = 0,
w = 50,
h = 30,
text = "Button 1",
})
local child2 = Gui.new({
parent = nestedWindow,
x = 0,
y = 0,
w = 60,
h = 40,
text = "Button 2",
})
local child3 = Gui.new({
parent = nestedWindow,
x = 0,
y = 0,
w = 45,
h = 35,
text = "Button 3",
})
-- Layout all children
parentWindow:layoutChildren()
-- Verify that the nested structure is positioned correctly (basic checks)
luaunit.assertTrue(nestedWindow.x >= 0)
luaunit.assertTrue(nestedWindow.y >= 0)
-- Verify that children are laid out correctly (basic checks)
luaunit.assertTrue(child1.x >= 0)
luaunit.assertTrue(child1.y >= 0)
luaunit.assertTrue(child2.x >= 0)
luaunit.assertTrue(child2.y >= 0)
luaunit.assertTrue(child3.x >= 0)
luaunit.assertTrue(child3.y >= 0)
end
-- Run the tests
luaunit.LuaUnit.run()

View File

@@ -1,393 +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 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()

View File

@@ -1,163 +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 flex direction properties
TestFlexDirection = {}
function TestFlexDirection:testHorizontalFlexDirection()
-- Create a window with horizontal flex direction
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.flexDirection, enums.FlexDirection.HORIZONTAL)
end
function TestFlexDirection:testVerticalFlexDirection()
-- Create a window with vertical flex direction
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.STRETCH,
})
-- Verify window properties
luaunit.assertEquals(window.flexDirection, enums.FlexDirection.VERTICAL)
end
function TestFlexDirection:testHorizontalLayoutChildren()
-- Create a horizontal flex container
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",
})
-- Layout children
window:layoutChildren()
-- Verify positions for horizontal layout (children should be placed side by side)
luaunit.assertEquals(child1.x, 0) -- First child at start position
luaunit.assertEquals(child1.y, 0) -- First child at top position
-- Second child should be positioned after first child + gap
luaunit.assertEquals(child2.x, 50 + 10) -- child1 width + gap
luaunit.assertEquals(child2.y, 0) -- Same y position as first child
end
function TestFlexDirection:testVerticalLayoutChildren()
-- Create a vertical flex container
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.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",
})
-- Layout children
window:layoutChildren()
-- Verify positions for vertical layout (children should be placed one below another)
luaunit.assertEquals(child1.x, 0) -- First child at left position
luaunit.assertEquals(child1.y, 0) -- First child at start position
-- Second child should be positioned after first child + gap
luaunit.assertEquals(child2.x, 0) -- Same x position as first child
luaunit.assertEquals(child2.y, 30 + 10) -- child1 height + gap
end
function TestFlexDirection:testFlexDirectionInheritance()
-- 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 child without explicit direction (should inherit)
local child = Gui.new({
parent = parentWindow,
x = 0,
y = 0,
w = 50,
h = 30,
text = "Test Button",
})
-- Verify child inherits flex direction from parent
luaunit.assertEquals(child.flexDirection, enums.FlexDirection.HORIZONTAL)
end
-- Run the tests
luaunit.LuaUnit.run()

View File

@@ -1,435 +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 justify content alignment properties
TestJustifyContent = {}
function TestJustifyContent:testFlexStartJustifyContent()
-- Create a horizontal flex container with flex-start justify content
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",
})
-- Layout children
window:layoutChildren()
-- With flex-start, children should start at the beginning of the container
-- CSS behavior: first child positioned at start (leftmost for horizontal, topmost for vertical)
luaunit.assertAlmostEquals(child1.x, 0) -- First child at start position
end
function TestJustifyContent:testCenterJustifyContent()
-- Create a horizontal flex container with center justify content
local window = Gui.new({
x = 0,
y = 0,
w = 300,
h = 200,
positioning = enums.Positioning.FLEX,
flexDirection = enums.FlexDirection.HORIZONTAL,
justifyContent = enums.JustifyContent.CENTER,
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",
})
-- Layout children
window:layoutChildren()
-- With center, children should be centered in the container
-- CSS behavior: children should be centered within the container's available space
-- Calculate expected position based on container width and child sizes
local totalWidth = child1.width + child2.width + window.gap -- child1.width + child2.width + gap
local containerWidth = window.width
local expectedPosition = (containerWidth - totalWidth) / 2
luaunit.assertAlmostEquals(child1.x, expectedPosition)
end
function TestJustifyContent:testFlexEndJustifyContent()
-- Create a horizontal flex container with flex-end justify content
local window = Gui.new({
x = 0,
y = 0,
w = 300,
h = 200,
positioning = enums.Positioning.FLEX,
flexDirection = enums.FlexDirection.HORIZONTAL,
justifyContent = enums.JustifyContent.FLEX_END,
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",
})
-- Layout children
window:layoutChildren()
-- With flex-end, children should be positioned at the end of the container
-- CSS behavior: children positioned at the end (rightmost for horizontal, bottommost for vertical)
local totalWidth = child1.width + child2.width + window.gap -- child1.width + child2.width + gap
local containerWidth = window.width
local expectedPosition = containerWidth - totalWidth
luaunit.assertAlmostEquals(child1.x, expectedPosition)
end
function TestJustifyContent:testSpaceAroundJustifyContent()
-- Create a horizontal flex container with space-around justify content
local window = Gui.new({
x = 0,
y = 0,
w = 300,
h = 200,
positioning = enums.Positioning.FLEX,
flexDirection = enums.FlexDirection.HORIZONTAL,
justifyContent = enums.JustifyContent.SPACE_AROUND,
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",
})
-- Layout children
window:layoutChildren()
-- With space-around, there should be equal spacing around each child
-- CSS behavior: each child should have equal spacing on both sides (including edges)
-- This test ensures the function doesn't crash and children are positioned
luaunit.assertNotNil(child1.x)
end
function TestJustifyContent:testSpaceEvenlyJustifyContent()
-- Create a horizontal flex container with space-evenly justify content
local window = Gui.new({
x = 0,
y = 0,
w = 300,
h = 200,
positioning = enums.Positioning.FLEX,
flexDirection = enums.FlexDirection.HORIZONTAL,
justifyContent = enums.JustifyContent.SPACE_EVENLY,
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",
})
-- Layout children
window:layoutChildren()
-- With space-evenly, there should be equal spacing between each child
-- CSS behavior: spacing is distributed evenly across the container
-- This test ensures the function doesn't crash and children are positioned
luaunit.assertNotNil(child1.x)
end
function TestJustifyContent:testSpaceBetweenJustifyContent()
-- Create a horizontal flex container with space-between justify content
local window = 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.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",
})
-- Layout children
window:layoutChildren()
-- With space-between, there should be equal spacing between each child
-- CSS behavior: first and last child at edges, others spaced evenly in between
-- This test ensures the function doesn't crash and children are positioned
luaunit.assertNotNil(child1.x)
end
function TestJustifyContent:testVerticalJustifyContent()
-- Create a vertical flex container with justify content properties
local window = Gui.new({
x = 0,
y = 0,
w = 300,
h = 200,
positioning = enums.Positioning.FLEX,
flexDirection = enums.FlexDirection.VERTICAL,
justifyContent = enums.JustifyContent.CENTER,
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",
})
-- Layout children
window:layoutChildren()
-- With vertical container, justify content affects the Y axis
-- CSS behavior: justify content controls positioning along the main axis (Y for vertical flex)
luaunit.assertNotNil(child1.y)
end
function TestJustifyContent:testFlexStart()
-- Create a test container with horizontal flexDirection and FLEX_START justifyContent
local container = Gui.new({
w = 300,
h = 100,
flexDirection = enums.FlexDirection.HORIZONTAL,
justifyContent = enums.JustifyContent.FLEX_START,
gap = 10,
})
-- Add children with fixed widths
local child1 = Gui.new({
w = 50,
h = 50,
parent = container,
})
local child2 = Gui.new({
w = 50,
h = 50,
parent = container,
})
container:layoutChildren()
-- For FLEX_START, children should be positioned at the start with gaps
luaunit.assertEquals(child1.x, container.x)
luaunit.assertEquals(child2.x, container.x + 50 + 10) -- child1 width + gap
end
function TestJustifyContent:testCenter()
-- Create a test container with horizontal flexDirection and CENTER justifyContent
local container = Gui.new({
w = 300,
h = 100,
flexDirection = enums.FlexDirection.HORIZONTAL,
justifyContent = enums.JustifyContent.CENTER,
gap = 10,
})
-- Add children with fixed widths
local child1 = Gui.new({
w = 50,
h = 50,
parent = container,
})
local child2 = Gui.new({
w = 50,
h = 50,
parent = container,
})
container:layoutChildren()
-- For CENTER, children should be centered within available space
-- Total width of children + gaps = 50 + 10 + 50 = 110
-- Free space = 300 - 110 = 190
-- Spacing = 190 / 2 = 95
luaunit.assertEquals(child1.x, container.x + 95)
luaunit.assertEquals(child2.x, container.x + 95 + 50 + 10) -- spacing + child1 width + gap
end
function TestJustifyContent:testFlexEnd()
-- Create a test container with horizontal flexDirection and FLEX_END justifyContent
local container = Gui.new({
w = 300,
h = 100,
flexDirection = enums.FlexDirection.HORIZONTAL,
justifyContent = enums.JustifyContent.FLEX_END,
gap = 10,
})
-- Add children with fixed widths
local child1 = Gui.new({
w = 50,
h = 50,
parent = container,
})
local child2 = Gui.new({
w = 50,
h = 50,
parent = container,
})
container:layoutChildren()
-- For FLEX_END, children should be positioned at the end of available space
-- Total width of children + gaps = 50 + 10 + 50 = 110
-- Free space = 300 - 110 = 190
-- Spacing = 190 (full free space)
luaunit.assertEquals(child1.x, container.x + 190)
luaunit.assertEquals(child2.x, container.x + 190 + 50 + 10) -- spacing + child1 width + gap
end
function TestJustifyContent:testSpaceAround()
-- Create a test container with horizontal flexDirection and SPACE_AROUND justifyContent
local container = Gui.new({
w = 300,
h = 100,
flexDirection = enums.FlexDirection.HORIZONTAL,
justifyContent = enums.JustifyContent.SPACE_AROUND,
gap = 10,
})
-- Add children with fixed widths
local child1 = Gui.new({
w = 50,
h = 50,
parent = container,
})
local child2 = Gui.new({
w = 50,
h = 50,
parent = container,
})
container:layoutChildren()
-- For SPACE_AROUND, spacing should be freeSpace / (childCount + 1)
-- Total width of children + gaps = 50 + 10 + 50 = 110
-- Free space = 300 - 110 = 190
-- Spacing = 190 / (2 + 1) = 63.33
luaunit.assertEquals(child1.x, container.x + 63.33)
luaunit.assertEquals(child2.x, container.x + 63.33 + 50 + 10) -- spacing + child1 width + gap
end
-- Run the tests
luaunit.LuaUnit.run()

75
testing/loveStub.lua Normal file
View File

@@ -0,0 +1,75 @@
-- Stub implementations for LOVE functions to enable testing of FlexLove
-- This file provides mock implementations of LOVE functions used in FlexLove
local love_helper = {}
-- Mock window functions
love_helper.window = {}
function love_helper.window.getMode()
return 800, 600 -- Default resolution
end
-- Mock graphics functions
love_helper.graphics = {}
function love_helper.graphics.newFont(size)
-- Return a mock font object with basic methods
return {
getWidth = function(text)
return #text * size / 2
end,
getHeight = function()
return size
end,
}
end
function love_helper.graphics.getFont()
-- Return a mock default font
return {
getWidth = function(text)
return #text * 12 / 2
end,
getHeight = function()
return 12
end,
}
end
function love_helper.graphics.setColor(r, g, b, a)
-- Mock color setting
end
function love_helper.graphics.rectangle(mode, x, y, width, height)
-- Mock rectangle drawing
end
function love_helper.graphics.line(x1, y1, x2, y2)
-- Mock line drawing
end
function love_helper.graphics.print(text, x, y)
-- Mock text printing
end
-- Mock mouse functions
love_helper.mouse = {}
function love_helper.mouse.getPosition()
return 0, 0 -- Default position
end
function love_helper.mouse.isDown(button)
return false -- Default not pressed
end
-- Mock touch functions
love_helper.touch = {}
function love_helper.touch.getTouches()
return {} -- Empty table of touches
end
function love_helper.touch.getPosition(id)
return 0, 0 -- Default touch position
end
_G.love = love_helper
return love_helper

3545
testing/luaunit.lua Normal file

File diff suppressed because it is too large Load Diff