This commit is contained in:
Michael Freno
2025-10-13 21:07:39 -04:00
parent c13c2c41ea
commit 8709dd26f9
6 changed files with 656 additions and 95 deletions

View File

@@ -269,7 +269,7 @@ function TestGridLayout:test_nested_grids()
-- Inner grid should be stretched to fill outer grid cell (200x200)
lu.assertAlmostEquals(innerGrid.width, 200, 1)
lu.assertAlmostEquals(innerGrid.height, 200, 1)
-- Items in inner grid should be positioned correctly
-- Each cell in inner grid is 100x100
lu.assertAlmostEquals(item1.x, 0, 1)
@@ -342,4 +342,4 @@ function TestGridLayout:test_single_cell_grid()
end
print("Running Simplified Grid Layout Tests...")
os.exit(lu.LuaUnit.run())
lu.LuaUnit.run()

View File

@@ -3,8 +3,8 @@
package.path = package.path .. ";?.lua"
local lu = require("testing/luaunit")
require("testing/loveStub") -- Required to mock LOVE functions
local lu = require("testing.luaunit")
require("testing.loveStub") -- Required to mock LOVE functions
local FlexLove = require("FlexLove")
local Gui = FlexLove.GUI
@@ -26,7 +26,7 @@ end
-- Test 1: Event object structure
function TestEventSystem:test_event_object_has_required_fields()
local eventReceived = nil
local button = Gui.new({
x = 100,
y = 100,
@@ -36,15 +36,15 @@ function TestEventSystem:test_event_object_has_required_fields()
eventReceived = event
end,
})
-- Simulate mouse press and release
love.mouse.setPosition(150, 150)
love.mouse.setDown(1, true)
button:update(0.016)
love.mouse.setDown(1, false)
button:update(0.016)
-- Verify event object structure
lu.assertNotNil(eventReceived, "Event should be received")
lu.assertNotNil(eventReceived.type, "Event should have type field")
@@ -59,28 +59,28 @@ end
-- Test 2: Left click event
function TestEventSystem:test_left_click_generates_click_event()
local eventsReceived = {}
local button = Gui.new({
x = 100,
y = 100,
width = 200,
height = 100,
callback = function(element, event)
table.insert(eventsReceived, {type = event.type, button = event.button})
table.insert(eventsReceived, { type = event.type, button = event.button })
end,
})
-- Simulate left click
love.mouse.setPosition(150, 150)
love.mouse.setDown(1, true)
button:update(0.016)
love.mouse.setDown(1, false)
button:update(0.016)
-- Should receive press, click, and release events
lu.assertTrue(#eventsReceived >= 2, "Should receive at least 2 events")
-- Check for click event
local hasClickEvent = false
for _, evt in ipairs(eventsReceived) do
@@ -95,25 +95,25 @@ end
-- Test 3: Right click event
function TestEventSystem:test_right_click_generates_rightclick_event()
local eventsReceived = {}
local button = Gui.new({
x = 100,
y = 100,
width = 200,
height = 100,
callback = function(element, event)
table.insert(eventsReceived, {type = event.type, button = event.button})
table.insert(eventsReceived, { type = event.type, button = event.button })
end,
})
-- Simulate right click
love.mouse.setPosition(150, 150)
love.mouse.setDown(2, true)
button:update(0.016)
love.mouse.setDown(2, false)
button:update(0.016)
-- Check for rightclick event
local hasRightClickEvent = false
for _, evt in ipairs(eventsReceived) do
@@ -128,25 +128,25 @@ end
-- Test 4: Middle click event
function TestEventSystem:test_middle_click_generates_middleclick_event()
local eventsReceived = {}
local button = Gui.new({
x = 100,
y = 100,
width = 200,
height = 100,
callback = function(element, event)
table.insert(eventsReceived, {type = event.type, button = event.button})
table.insert(eventsReceived, { type = event.type, button = event.button })
end,
})
-- Simulate middle click
love.mouse.setPosition(150, 150)
love.mouse.setDown(3, true)
button:update(0.016)
love.mouse.setDown(3, false)
button:update(0.016)
-- Check for middleclick event
local hasMiddleClickEvent = false
for _, evt in ipairs(eventsReceived) do
@@ -161,7 +161,7 @@ end
-- Test 5: Modifier keys detection
function TestEventSystem:test_modifier_keys_are_detected()
local eventReceived = nil
local button = Gui.new({
x = 100,
y = 100,
@@ -173,16 +173,16 @@ function TestEventSystem:test_modifier_keys_are_detected()
end
end,
})
-- Simulate shift + click
love.keyboard.setDown("lshift", true)
love.mouse.setPosition(150, 150)
love.mouse.setDown(1, true)
button:update(0.016)
love.mouse.setDown(1, false)
button:update(0.016)
lu.assertNotNil(eventReceived, "Should receive click event")
lu.assertTrue(eventReceived.modifiers.shift, "Shift modifier should be detected")
end
@@ -190,7 +190,7 @@ end
-- Test 6: Double click detection
function TestEventSystem:test_double_click_increments_click_count()
local clickEvents = {}
local button = Gui.new({
x = 100,
y = 100,
@@ -202,21 +202,21 @@ function TestEventSystem:test_double_click_increments_click_count()
end
end,
})
-- Simulate first click
love.mouse.setPosition(150, 150)
love.mouse.setDown(1, true)
button:update(0.016)
love.mouse.setDown(1, false)
button:update(0.016)
-- Simulate second click quickly (double-click)
love.timer.setTime(love.timer.getTime() + 0.1) -- 100ms later
love.mouse.setDown(1, true)
button:update(0.016)
love.mouse.setDown(1, false)
button:update(0.016)
lu.assertEquals(#clickEvents, 2, "Should receive 2 click events")
lu.assertEquals(clickEvents[1], 1, "First click should have clickCount = 1")
lu.assertEquals(clickEvents[2], 2, "Second click should have clickCount = 2")
@@ -225,7 +225,7 @@ end
-- Test 7: Press and release events
function TestEventSystem:test_press_and_release_events_are_fired()
local eventsReceived = {}
local button = Gui.new({
x = 100,
y = 100,
@@ -235,25 +235,29 @@ function TestEventSystem:test_press_and_release_events_are_fired()
table.insert(eventsReceived, event.type)
end,
})
-- Simulate click
love.mouse.setPosition(150, 150)
love.mouse.setDown(1, true)
button:update(0.016)
love.mouse.setDown(1, false)
button:update(0.016)
-- Should receive press, click, and release
lu.assertTrue(#eventsReceived >= 2, "Should receive multiple events")
local hasPress = false
local hasRelease = false
for _, eventType in ipairs(eventsReceived) do
if eventType == "press" then hasPress = true end
if eventType == "release" then hasRelease = true end
if eventType == "press" then
hasPress = true
end
if eventType == "release" then
hasRelease = true
end
end
lu.assertTrue(hasPress, "Should receive press event")
lu.assertTrue(hasRelease, "Should receive release event")
end
@@ -261,7 +265,7 @@ end
-- Test 8: Mouse position in event
function TestEventSystem:test_event_contains_mouse_position()
local eventReceived = nil
local button = Gui.new({
x = 100,
y = 100,
@@ -273,16 +277,16 @@ function TestEventSystem:test_event_contains_mouse_position()
end
end,
})
-- Simulate click at specific position
local mouseX, mouseY = 175, 125
love.mouse.setPosition(mouseX, mouseY)
love.mouse.setDown(1, true)
button:update(0.016)
love.mouse.setDown(1, false)
button:update(0.016)
lu.assertNotNil(eventReceived, "Should receive click event")
lu.assertEquals(eventReceived.x, mouseX, "Event should contain correct mouse X position")
lu.assertEquals(eventReceived.y, mouseY, "Event should contain correct mouse Y position")
@@ -291,7 +295,7 @@ end
-- Test 9: No callback when mouse outside element
function TestEventSystem:test_no_callback_when_clicking_outside_element()
local callbackCalled = false
local button = Gui.new({
x = 100,
y = 100,
@@ -301,22 +305,22 @@ function TestEventSystem:test_no_callback_when_clicking_outside_element()
callbackCalled = true
end,
})
-- Click outside element
love.mouse.setPosition(50, 50)
love.mouse.setDown(1, true)
button:update(0.016)
love.mouse.setDown(1, false)
button:update(0.016)
lu.assertFalse(callbackCalled, "Callback should not be called when clicking outside element")
end
-- Test 10: Multiple modifiers
function TestEventSystem:test_multiple_modifiers_detected()
local eventReceived = nil
local button = Gui.new({
x = 100,
y = 100,
@@ -328,20 +332,21 @@ function TestEventSystem:test_multiple_modifiers_detected()
end
end,
})
-- Simulate shift + ctrl + click
love.keyboard.setDown("lshift", true)
love.keyboard.setDown("lctrl", true)
love.mouse.setPosition(150, 150)
love.mouse.setDown(1, true)
button:update(0.016)
love.mouse.setDown(1, false)
button:update(0.016)
lu.assertNotNil(eventReceived, "Should receive click event")
lu.assertTrue(eventReceived.modifiers.shift, "Shift modifier should be detected")
lu.assertTrue(eventReceived.modifiers.ctrl, "Ctrl modifier should be detected")
end
return TestEventSystem
print("Running Event System Tests...")
lu.LuaUnit.run()

View File

@@ -1,15 +1,14 @@
-- Test: Sibling Space Reservation in Flex and Grid Layouts
-- Purpose: Verify that absolutely positioned siblings with explicit positioning
-- properly reserve space in flex and grid containers
package.path = package.path .. ";?.lua"
local lu = require("testing.luaunit")
local FlexLove = require("libs.FlexLove")
require("testing.loveStub") -- Required to mock LOVE functions
local FlexLove = require("FlexLove")
local Gui = FlexLove.GUI
local Color = FlexLove.Color
-- Mock love.graphics and love.window
_G.love = require("testing.loveStub")
TestSiblingSpaceReservation = {}
function TestSiblingSpaceReservation:setUp()
@@ -106,7 +105,7 @@ function TestSiblingSpaceReservation:test_flex_horizontal_right_positioned_sibli
-- The flex child (width 100) should fit within this space
-- Child should start at x = 0
lu.assertEquals(flexChild.x, 0, "Flex child should start at container left edge")
-- The absolutely positioned sibling should be at the right edge
-- x = container.x + container.width + padding.left - right - (width + padding)
-- = 0 + 1000 + 0 - 10 - 50 = 940
@@ -208,7 +207,7 @@ function TestSiblingSpaceReservation:test_flex_horizontal_multiple_positioned_si
-- Available space: 1000 - 45 - 45 = 910px
-- First flex child should start at x = 0 + 0 + 45 = 45
lu.assertEquals(flexChild1.x, 45, "First flex child should start after left sibling")
-- Second flex child should start at x = 45 + 100 + gap = 145 (assuming gap=10)
lu.assertIsTrue(flexChild2.x >= 145, "Second flex child should be positioned after first")
end
@@ -434,4 +433,5 @@ function TestSiblingSpaceReservation:test_absolute_without_positioning_offsets_d
lu.assertEquals(flexChild.x, 0, "Absolute children without positioning offsets should not reserve space")
end
return TestSiblingSpaceReservation
print("Running Sibling Space Reservation Tests...")
lu.LuaUnit.run()

View File

@@ -1,5 +1,7 @@
package.path = package.path .. ";?.lua"
local lu = require("testing.luaunit")
require("testing.loveStub")
require("testing.loveStub") -- Required to mock LOVE functions
local FlexLove = require("FlexLove")
TestFontFamilyInheritance = {}
@@ -219,4 +221,5 @@ function TestFontFamilyInheritance:testInheritanceDoesNotAffectSiblings()
lu.assertNotEquals(child2.fontFamily, child1.fontFamily, "Siblings should have independent fontFamily values")
end
return TestFontFamilyInheritance
print("Running Font Family Inheritance Tests...")
lu.LuaUnit.run()

View File

@@ -1,5 +1,7 @@
package.path = package.path .. ";?.lua"
local lu = require("testing.luaunit")
require("testing.loveStub")
require("testing.loveStub") -- Required to mock LOVE functions
local FlexLove = require("FlexLove")
TestNegativeMargin = {}
@@ -331,4 +333,5 @@ function TestNegativeMargin:testNegativeMarginInNestedElements()
lu.assertEquals(child.margin.left, -10)
end
return TestNegativeMargin
print("Running Negative Margin Tests...")
lu.LuaUnit.run()