starting refactor for sanity
This commit is contained in:
@@ -7,6 +7,10 @@ require("testing.loveStub")
|
||||
|
||||
-- Import the Color module
|
||||
local Color = require("modules.Color")
|
||||
local ErrorHandler = require("modules.ErrorHandler")
|
||||
local ErrorCodes = require("modules.ErrorCodes")
|
||||
ErrorHandler.init({ ErrorCodes })
|
||||
Color.init({ ErrorHandler })
|
||||
|
||||
-- Test Suite for Color Validation
|
||||
TestColorValidation = {}
|
||||
|
||||
@@ -20,27 +20,47 @@ function TestEasing:testAllEasingFunctionsExist()
|
||||
-- Linear
|
||||
"linear",
|
||||
-- Quad
|
||||
"easeInQuad", "easeOutQuad", "easeInOutQuad",
|
||||
"easeInQuad",
|
||||
"easeOutQuad",
|
||||
"easeInOutQuad",
|
||||
-- Cubic
|
||||
"easeInCubic", "easeOutCubic", "easeInOutCubic",
|
||||
"easeInCubic",
|
||||
"easeOutCubic",
|
||||
"easeInOutCubic",
|
||||
-- Quart
|
||||
"easeInQuart", "easeOutQuart", "easeInOutQuart",
|
||||
"easeInQuart",
|
||||
"easeOutQuart",
|
||||
"easeInOutQuart",
|
||||
-- Quint
|
||||
"easeInQuint", "easeOutQuint", "easeInOutQuint",
|
||||
"easeInQuint",
|
||||
"easeOutQuint",
|
||||
"easeInOutQuint",
|
||||
-- Expo
|
||||
"easeInExpo", "easeOutExpo", "easeInOutExpo",
|
||||
"easeInExpo",
|
||||
"easeOutExpo",
|
||||
"easeInOutExpo",
|
||||
-- Sine
|
||||
"easeInSine", "easeOutSine", "easeInOutSine",
|
||||
"easeInSine",
|
||||
"easeOutSine",
|
||||
"easeInOutSine",
|
||||
-- Circ
|
||||
"easeInCirc", "easeOutCirc", "easeInOutCirc",
|
||||
"easeInCirc",
|
||||
"easeOutCirc",
|
||||
"easeInOutCirc",
|
||||
-- Back
|
||||
"easeInBack", "easeOutBack", "easeInOutBack",
|
||||
"easeInBack",
|
||||
"easeOutBack",
|
||||
"easeInOutBack",
|
||||
-- Elastic
|
||||
"easeInElastic", "easeOutElastic", "easeInOutElastic",
|
||||
"easeInElastic",
|
||||
"easeOutElastic",
|
||||
"easeInOutElastic",
|
||||
-- Bounce
|
||||
"easeInBounce", "easeOutBounce", "easeInOutBounce",
|
||||
"easeInBounce",
|
||||
"easeOutBounce",
|
||||
"easeInOutBounce",
|
||||
}
|
||||
|
||||
|
||||
for _, name in ipairs(easings) do
|
||||
luaunit.assertNotNil(Easing[name], "Easing function " .. name .. " should exist")
|
||||
luaunit.assertEquals(type(Easing[name]), "function", name .. " should be a function")
|
||||
@@ -239,7 +259,7 @@ function TestEasing:testList()
|
||||
local list = Easing.list()
|
||||
luaunit.assertEquals(type(list), "table")
|
||||
luaunit.assertEquals(#list, 31, "Should have exactly 31 easing functions")
|
||||
|
||||
|
||||
-- Check that linear is in the list
|
||||
local hasLinear = false
|
||||
for _, name in ipairs(list) do
|
||||
@@ -257,7 +277,7 @@ function TestEasing:testGet()
|
||||
luaunit.assertNotNil(linear)
|
||||
luaunit.assertEquals(type(linear), "function")
|
||||
luaunit.assertEquals(linear(0.5), 0.5)
|
||||
|
||||
|
||||
-- Test non-existent easing
|
||||
local nonExistent = Easing.get("nonExistentEasing")
|
||||
luaunit.assertNil(nonExistent)
|
||||
@@ -266,11 +286,18 @@ end
|
||||
-- Test that all InOut easings are symmetric around 0.5
|
||||
function TestEasing:testInOutSymmetry()
|
||||
local inOutEasings = {
|
||||
"easeInOutQuad", "easeInOutCubic", "easeInOutQuart", "easeInOutQuint",
|
||||
"easeInOutExpo", "easeInOutSine", "easeInOutCirc", "easeInOutBack",
|
||||
"easeInOutElastic", "easeInOutBounce"
|
||||
"easeInOutQuad",
|
||||
"easeInOutCubic",
|
||||
"easeInOutQuart",
|
||||
"easeInOutQuint",
|
||||
"easeInOutExpo",
|
||||
"easeInOutSine",
|
||||
"easeInOutCirc",
|
||||
"easeInOutBack",
|
||||
"easeInOutElastic",
|
||||
"easeInOutBounce",
|
||||
}
|
||||
|
||||
|
||||
for _, name in ipairs(inOutEasings) do
|
||||
local easing = Easing[name]
|
||||
-- At t=0.5, all InOut easings should be close to 0.5
|
||||
@@ -283,28 +310,50 @@ end
|
||||
function TestEasing:testBoundaryConditions()
|
||||
local easings = {
|
||||
"linear",
|
||||
"easeInQuad", "easeOutQuad", "easeInOutQuad",
|
||||
"easeInCubic", "easeOutCubic", "easeInOutCubic",
|
||||
"easeInQuart", "easeOutQuart", "easeInOutQuart",
|
||||
"easeInQuint", "easeOutQuint", "easeInOutQuint",
|
||||
"easeInExpo", "easeOutExpo", "easeInOutExpo",
|
||||
"easeInSine", "easeOutSine", "easeInOutSine",
|
||||
"easeInCirc", "easeOutCirc", "easeInOutCirc",
|
||||
"easeInBack", "easeOutBack", "easeInOutBack",
|
||||
"easeInElastic", "easeOutElastic", "easeInOutElastic",
|
||||
"easeInBounce", "easeOutBounce", "easeInOutBounce",
|
||||
"easeInQuad",
|
||||
"easeOutQuad",
|
||||
"easeInOutQuad",
|
||||
"easeInCubic",
|
||||
"easeOutCubic",
|
||||
"easeInOutCubic",
|
||||
"easeInQuart",
|
||||
"easeOutQuart",
|
||||
"easeInOutQuart",
|
||||
"easeInQuint",
|
||||
"easeOutQuint",
|
||||
"easeInOutQuint",
|
||||
"easeInExpo",
|
||||
"easeOutExpo",
|
||||
"easeInOutExpo",
|
||||
"easeInSine",
|
||||
"easeOutSine",
|
||||
"easeInOutSine",
|
||||
"easeInCirc",
|
||||
"easeOutCirc",
|
||||
"easeInOutCirc",
|
||||
"easeInBack",
|
||||
"easeOutBack",
|
||||
"easeInOutBack",
|
||||
"easeInElastic",
|
||||
"easeOutElastic",
|
||||
"easeInOutElastic",
|
||||
"easeInBounce",
|
||||
"easeOutBounce",
|
||||
"easeInOutBounce",
|
||||
}
|
||||
|
||||
|
||||
for _, name in ipairs(easings) do
|
||||
local easing = Easing[name]
|
||||
-- All easings should start at 0
|
||||
local start = easing(0)
|
||||
luaunit.assertAlmostEquals(start, 0, 0.01, name .. " should start at 0")
|
||||
|
||||
|
||||
-- All easings should end at 1
|
||||
local finish = easing(1)
|
||||
luaunit.assertAlmostEquals(finish, 1, 0.01, name .. " should end at 1")
|
||||
end
|
||||
end
|
||||
|
||||
os.exit(luaunit.LuaUnit.run())
|
||||
if not _G.RUNNING_ALL_TESTS then
|
||||
os.exit(luaunit.LuaUnit.run())
|
||||
end
|
||||
|
||||
@@ -524,7 +524,7 @@ function TestEventHandler:test_onEventDeferred()
|
||||
local MockFlexLove = {
|
||||
deferCallback = function(callback)
|
||||
table.insert(deferredCallbacks, callback)
|
||||
end
|
||||
end,
|
||||
}
|
||||
package.loaded["FlexLove"] = MockFlexLove
|
||||
|
||||
@@ -533,7 +533,7 @@ function TestEventHandler:test_onEventDeferred()
|
||||
onEventDeferred = true,
|
||||
onEvent = function(el, event)
|
||||
table.insert(eventsReceived, event)
|
||||
end
|
||||
end,
|
||||
})
|
||||
local element = createMockElement()
|
||||
handler:initialize(element)
|
||||
@@ -545,12 +545,14 @@ function TestEventHandler:test_onEventDeferred()
|
||||
|
||||
-- Press and release mouse button
|
||||
handler:processMouseEvents(50, 50, true, true)
|
||||
love.mouse.isDown = function() return false end
|
||||
love.mouse.isDown = function()
|
||||
return false
|
||||
end
|
||||
handler:processMouseEvents(50, 50, true, true)
|
||||
|
||||
-- Events should not be immediately executed
|
||||
luaunit.assertEquals(#eventsReceived, 0)
|
||||
|
||||
|
||||
-- Should have deferred callbacks queued
|
||||
luaunit.assertTrue(#deferredCallbacks > 0)
|
||||
|
||||
@@ -561,7 +563,7 @@ function TestEventHandler:test_onEventDeferred()
|
||||
|
||||
-- Now events should be received
|
||||
luaunit.assertTrue(#eventsReceived > 0)
|
||||
|
||||
|
||||
-- Check that we got a click event
|
||||
local hasClick = false
|
||||
for _, event in ipairs(eventsReceived) do
|
||||
@@ -583,7 +585,7 @@ function TestEventHandler:test_onEventDeferred_false()
|
||||
onEventDeferred = false,
|
||||
onEvent = function(el, event)
|
||||
table.insert(eventsReceived, event)
|
||||
end
|
||||
end,
|
||||
})
|
||||
local element = createMockElement()
|
||||
handler:initialize(element)
|
||||
@@ -595,12 +597,14 @@ function TestEventHandler:test_onEventDeferred_false()
|
||||
|
||||
-- Press and release mouse button
|
||||
handler:processMouseEvents(50, 50, true, true)
|
||||
love.mouse.isDown = function() return false end
|
||||
love.mouse.isDown = function()
|
||||
return false
|
||||
end
|
||||
handler:processMouseEvents(50, 50, true, true)
|
||||
|
||||
-- Events should be immediately executed
|
||||
luaunit.assertTrue(#eventsReceived > 0)
|
||||
|
||||
|
||||
-- Check that we got a click event
|
||||
local hasClick = false
|
||||
for _, event in ipairs(eventsReceived) do
|
||||
|
||||
@@ -642,19 +642,19 @@ end
|
||||
-- Test: deferCallback() queues callback
|
||||
function TestFlexLove:testDeferCallbackQueuesCallback()
|
||||
FlexLove.setMode("retained")
|
||||
|
||||
|
||||
local called = false
|
||||
FlexLove.deferCallback(function()
|
||||
called = true
|
||||
end)
|
||||
|
||||
|
||||
-- Callback should not be called immediately
|
||||
luaunit.assertFalse(called)
|
||||
|
||||
|
||||
-- Callback should be called after executeDeferredCallbacks
|
||||
FlexLove.draw()
|
||||
luaunit.assertFalse(called) -- Still not called
|
||||
|
||||
|
||||
FlexLove.executeDeferredCallbacks()
|
||||
luaunit.assertTrue(called) -- Now called
|
||||
end
|
||||
@@ -662,7 +662,7 @@ end
|
||||
-- Test: deferCallback() with multiple callbacks
|
||||
function TestFlexLove:testDeferCallbackMultiple()
|
||||
FlexLove.setMode("retained")
|
||||
|
||||
|
||||
local order = {}
|
||||
FlexLove.deferCallback(function()
|
||||
table.insert(order, 1)
|
||||
@@ -673,10 +673,10 @@ function TestFlexLove:testDeferCallbackMultiple()
|
||||
FlexLove.deferCallback(function()
|
||||
table.insert(order, 3)
|
||||
end)
|
||||
|
||||
|
||||
FlexLove.draw()
|
||||
FlexLove.executeDeferredCallbacks()
|
||||
|
||||
|
||||
luaunit.assertEquals(#order, 3)
|
||||
luaunit.assertEquals(order[1], 1)
|
||||
luaunit.assertEquals(order[2], 2)
|
||||
@@ -686,12 +686,12 @@ end
|
||||
-- Test: deferCallback() with non-function argument
|
||||
function TestFlexLove:testDeferCallbackInvalidArgument()
|
||||
FlexLove.setMode("retained")
|
||||
|
||||
|
||||
-- Should warn but not crash
|
||||
FlexLove.deferCallback("not a function")
|
||||
FlexLove.deferCallback(123)
|
||||
FlexLove.deferCallback(nil)
|
||||
|
||||
|
||||
FlexLove.draw()
|
||||
luaunit.assertTrue(true)
|
||||
end
|
||||
@@ -699,16 +699,16 @@ end
|
||||
-- Test: deferCallback() clears queue after execution
|
||||
function TestFlexLove:testDeferCallbackClearsQueue()
|
||||
FlexLove.setMode("retained")
|
||||
|
||||
|
||||
local callCount = 0
|
||||
FlexLove.deferCallback(function()
|
||||
callCount = callCount + 1
|
||||
end)
|
||||
|
||||
|
||||
FlexLove.draw()
|
||||
FlexLove.executeDeferredCallbacks() -- First execution
|
||||
luaunit.assertEquals(callCount, 1)
|
||||
|
||||
|
||||
FlexLove.draw()
|
||||
FlexLove.executeDeferredCallbacks() -- Second execution should not call again
|
||||
luaunit.assertEquals(callCount, 1)
|
||||
@@ -717,7 +717,7 @@ end
|
||||
-- Test: deferCallback() handles callback errors gracefully
|
||||
function TestFlexLove:testDeferCallbackWithError()
|
||||
FlexLove.setMode("retained")
|
||||
|
||||
|
||||
local called = false
|
||||
FlexLove.deferCallback(function()
|
||||
error("Intentional error")
|
||||
@@ -725,7 +725,7 @@ function TestFlexLove:testDeferCallbackWithError()
|
||||
FlexLove.deferCallback(function()
|
||||
called = true
|
||||
end)
|
||||
|
||||
|
||||
-- Should not crash, second callback should still execute
|
||||
FlexLove.draw()
|
||||
FlexLove.executeDeferredCallbacks()
|
||||
@@ -1329,4 +1329,6 @@ function TestFlexLoveUnhappyPaths:testImmediateModeFrameEdgeCases()
|
||||
luaunit.assertTrue(true)
|
||||
end
|
||||
|
||||
return TestFlexLove
|
||||
if not _G.RUNNING_ALL_TESTS then
|
||||
os.exit(luaunit.LuaUnit.run())
|
||||
end
|
||||
|
||||
@@ -29,13 +29,13 @@ function TestFontCache:testCacheHitOnRepeatedAccess()
|
||||
local stats1 = utils.getFontCacheStats()
|
||||
luaunit.assertEquals(stats1.misses, 1)
|
||||
luaunit.assertEquals(stats1.hits, 0)
|
||||
|
||||
|
||||
-- Second access should be a hit
|
||||
utils.FONT_CACHE.get(16, nil)
|
||||
local stats2 = utils.getFontCacheStats()
|
||||
luaunit.assertEquals(stats2.hits, 1)
|
||||
luaunit.assertEquals(stats2.misses, 1)
|
||||
|
||||
|
||||
-- Third access should also be a hit
|
||||
utils.FONT_CACHE.get(16, nil)
|
||||
local stats3 = utils.getFontCacheStats()
|
||||
@@ -46,17 +46,17 @@ end
|
||||
function TestFontCache:testCacheMissOnFirstAccess()
|
||||
utils.clearFontCache()
|
||||
utils.resetFontCacheStats()
|
||||
|
||||
|
||||
utils.FONT_CACHE.get(24, nil)
|
||||
local stats = utils.getFontCacheStats()
|
||||
|
||||
|
||||
luaunit.assertEquals(stats.misses, 1)
|
||||
luaunit.assertEquals(stats.hits, 0)
|
||||
end
|
||||
|
||||
function TestFontCache:testLRUEviction()
|
||||
utils.setFontCacheSize(3)
|
||||
|
||||
|
||||
-- Load 3 fonts (fills cache) with time steps to ensure different timestamps
|
||||
utils.FONT_CACHE.get(10, nil)
|
||||
love.timer.step(0.001)
|
||||
@@ -64,34 +64,34 @@ function TestFontCache:testLRUEviction()
|
||||
love.timer.step(0.001)
|
||||
utils.FONT_CACHE.get(14, nil)
|
||||
love.timer.step(0.001)
|
||||
|
||||
|
||||
local stats1 = utils.getFontCacheStats()
|
||||
luaunit.assertEquals(stats1.size, 3)
|
||||
luaunit.assertEquals(stats1.evictions, 0)
|
||||
|
||||
|
||||
-- Load 4th font (triggers eviction of font 10 - the oldest)
|
||||
utils.FONT_CACHE.get(16, nil)
|
||||
|
||||
|
||||
local stats2 = utils.getFontCacheStats()
|
||||
luaunit.assertEquals(stats2.size, 3)
|
||||
luaunit.assertEquals(stats2.evictions, 1)
|
||||
|
||||
|
||||
-- Access first font again - it should have been evicted (miss)
|
||||
local initialMisses = stats2.misses
|
||||
utils.FONT_CACHE.get(10, nil)
|
||||
|
||||
|
||||
local stats3 = utils.getFontCacheStats()
|
||||
luaunit.assertEquals(stats3.misses, initialMisses + 1) -- Should be a miss
|
||||
end
|
||||
|
||||
function TestFontCache:testCacheSizeLimitEnforced()
|
||||
utils.setFontCacheSize(5)
|
||||
|
||||
|
||||
-- Load 10 fonts
|
||||
for i = 1, 10 do
|
||||
utils.FONT_CACHE.get(10 + i, nil)
|
||||
end
|
||||
|
||||
|
||||
local stats = utils.getFontCacheStats()
|
||||
luaunit.assertEquals(stats.size, 5)
|
||||
luaunit.assertTrue(stats.evictions >= 5)
|
||||
@@ -102,7 +102,7 @@ function TestFontCache:testFontRounding()
|
||||
utils.FONT_CACHE.get(14.5, nil)
|
||||
local stats1 = utils.getFontCacheStats()
|
||||
luaunit.assertEquals(stats1.misses, 1)
|
||||
|
||||
|
||||
utils.FONT_CACHE.get(14.7, nil)
|
||||
local stats2 = utils.getFontCacheStats()
|
||||
luaunit.assertEquals(stats2.hits, 1) -- Should be a hit because both round to 15
|
||||
@@ -112,12 +112,12 @@ end
|
||||
function TestFontCache:testCacheClear()
|
||||
utils.FONT_CACHE.get(16, nil)
|
||||
utils.FONT_CACHE.get(18, nil)
|
||||
|
||||
|
||||
local stats1 = utils.getFontCacheStats()
|
||||
luaunit.assertEquals(stats1.size, 2)
|
||||
|
||||
|
||||
utils.clearFontCache()
|
||||
|
||||
|
||||
local stats2 = utils.getFontCacheStats()
|
||||
luaunit.assertEquals(stats2.size, 0)
|
||||
end
|
||||
@@ -126,7 +126,7 @@ function TestFontCache:testCacheKeyWithPath()
|
||||
-- Different cache keys for same size, different paths
|
||||
utils.FONT_CACHE.get(16, nil)
|
||||
utils.FONT_CACHE.get(16, "fonts/custom.ttf")
|
||||
|
||||
|
||||
local stats = utils.getFontCacheStats()
|
||||
luaunit.assertEquals(stats.misses, 2) -- Both should be misses
|
||||
luaunit.assertEquals(stats.size, 2)
|
||||
@@ -135,14 +135,14 @@ end
|
||||
function TestFontCache:testPreloadFont()
|
||||
utils.clearFontCache()
|
||||
utils.resetFontCacheStats()
|
||||
|
||||
|
||||
-- Preload multiple sizes
|
||||
utils.preloadFont(nil, {12, 14, 16, 18})
|
||||
|
||||
utils.preloadFont(nil, { 12, 14, 16, 18 })
|
||||
|
||||
local stats1 = utils.getFontCacheStats()
|
||||
luaunit.assertEquals(stats1.size, 4)
|
||||
luaunit.assertEquals(stats1.misses, 4) -- All preloads are misses
|
||||
|
||||
|
||||
-- Now access one - should be a hit
|
||||
utils.FONT_CACHE.get(16, nil)
|
||||
local stats2 = utils.getFontCacheStats()
|
||||
@@ -152,31 +152,31 @@ end
|
||||
function TestFontCache:testCacheHitRate()
|
||||
utils.clearFontCache()
|
||||
utils.resetFontCacheStats()
|
||||
|
||||
|
||||
-- 1 miss, 9 hits = 90% hit rate
|
||||
utils.FONT_CACHE.get(16, nil)
|
||||
for i = 1, 9 do
|
||||
utils.FONT_CACHE.get(16, nil)
|
||||
end
|
||||
|
||||
|
||||
local stats = utils.getFontCacheStats()
|
||||
luaunit.assertEquals(stats.hitRate, 0.9)
|
||||
end
|
||||
|
||||
function TestFontCache:testSetCacheSizeEvictsExcess()
|
||||
utils.setFontCacheSize(10)
|
||||
|
||||
|
||||
-- Load 10 fonts
|
||||
for i = 1, 10 do
|
||||
utils.FONT_CACHE.get(10 + i, nil)
|
||||
end
|
||||
|
||||
|
||||
local stats1 = utils.getFontCacheStats()
|
||||
luaunit.assertEquals(stats1.size, 10)
|
||||
|
||||
|
||||
-- Reduce cache size - should trigger evictions
|
||||
utils.setFontCacheSize(5)
|
||||
|
||||
|
||||
local stats2 = utils.getFontCacheStats()
|
||||
luaunit.assertEquals(stats2.size, 5)
|
||||
luaunit.assertTrue(stats2.evictions >= 5)
|
||||
@@ -186,14 +186,11 @@ function TestFontCache:testMinimalCacheSize()
|
||||
-- Minimum cache size is 1
|
||||
utils.setFontCacheSize(0)
|
||||
utils.FONT_CACHE.get(16, nil)
|
||||
|
||||
|
||||
local stats = utils.getFontCacheStats()
|
||||
luaunit.assertEquals(stats.size, 1)
|
||||
end
|
||||
|
||||
-- Run tests if executed directly
|
||||
if arg and arg[0]:find("font_cache_test%.lua$") then
|
||||
if not _G.RUNNING_ALL_TESTS then
|
||||
os.exit(luaunit.LuaUnit.run())
|
||||
end
|
||||
|
||||
return TestFontCache
|
||||
|
||||
@@ -21,11 +21,11 @@ function TestKeyframeAnimation:testCreateKeyframeAnimation()
|
||||
local anim = Animation.keyframes({
|
||||
duration = 2,
|
||||
keyframes = {
|
||||
{at = 0, values = {x = 0, opacity = 0}},
|
||||
{at = 1, values = {x = 100, opacity = 1}},
|
||||
}
|
||||
{ at = 0, values = { x = 0, opacity = 0 } },
|
||||
{ at = 1, values = { x = 100, opacity = 1 } },
|
||||
},
|
||||
})
|
||||
|
||||
|
||||
luaunit.assertNotNil(anim)
|
||||
luaunit.assertEquals(type(anim), "table")
|
||||
luaunit.assertEquals(anim.duration, 2)
|
||||
@@ -38,13 +38,13 @@ function TestKeyframeAnimation:testMultipleWaypoints()
|
||||
local anim = Animation.keyframes({
|
||||
duration = 3,
|
||||
keyframes = {
|
||||
{at = 0, values = {x = 0, opacity = 0}},
|
||||
{at = 0.25, values = {x = 50, opacity = 1}},
|
||||
{at = 0.75, values = {x = 150, opacity = 1}},
|
||||
{at = 1, values = {x = 200, opacity = 0}},
|
||||
}
|
||||
{ at = 0, values = { x = 0, opacity = 0 } },
|
||||
{ at = 0.25, values = { x = 50, opacity = 1 } },
|
||||
{ at = 0.75, values = { x = 150, opacity = 1 } },
|
||||
{ at = 1, values = { x = 200, opacity = 0 } },
|
||||
},
|
||||
})
|
||||
|
||||
|
||||
luaunit.assertEquals(#anim.keyframes, 4)
|
||||
luaunit.assertEquals(anim.keyframes[1].at, 0)
|
||||
luaunit.assertEquals(anim.keyframes[2].at, 0.25)
|
||||
@@ -57,12 +57,12 @@ function TestKeyframeAnimation:testKeyframeSorting()
|
||||
local anim = Animation.keyframes({
|
||||
duration = 1,
|
||||
keyframes = {
|
||||
{at = 1, values = {x = 100}},
|
||||
{at = 0, values = {x = 0}},
|
||||
{at = 0.5, values = {x = 50}},
|
||||
}
|
||||
{ at = 1, values = { x = 100 } },
|
||||
{ at = 0, values = { x = 0 } },
|
||||
{ at = 0.5, values = { x = 50 } },
|
||||
},
|
||||
})
|
||||
|
||||
|
||||
-- Should be sorted by 'at' position
|
||||
luaunit.assertEquals(anim.keyframes[1].at, 0)
|
||||
luaunit.assertEquals(anim.keyframes[2].at, 0.5)
|
||||
@@ -74,14 +74,14 @@ function TestKeyframeAnimation:testInterpolationAtStart()
|
||||
local anim = Animation.keyframes({
|
||||
duration = 1,
|
||||
keyframes = {
|
||||
{at = 0, values = {x = 0, opacity = 0}},
|
||||
{at = 1, values = {x = 100, opacity = 1}},
|
||||
}
|
||||
{ at = 0, values = { x = 0, opacity = 0 } },
|
||||
{ at = 1, values = { x = 100, opacity = 1 } },
|
||||
},
|
||||
})
|
||||
|
||||
|
||||
anim.elapsed = 0
|
||||
local result = anim:interpolate()
|
||||
|
||||
|
||||
luaunit.assertNotNil(result.x)
|
||||
luaunit.assertNotNil(result.opacity)
|
||||
luaunit.assertAlmostEquals(result.x, 0, 0.01)
|
||||
@@ -93,14 +93,14 @@ function TestKeyframeAnimation:testInterpolationAtEnd()
|
||||
local anim = Animation.keyframes({
|
||||
duration = 1,
|
||||
keyframes = {
|
||||
{at = 0, values = {x = 0, opacity = 0}},
|
||||
{at = 1, values = {x = 100, opacity = 1}},
|
||||
}
|
||||
{ at = 0, values = { x = 0, opacity = 0 } },
|
||||
{ at = 1, values = { x = 100, opacity = 1 } },
|
||||
},
|
||||
})
|
||||
|
||||
|
||||
anim.elapsed = 1
|
||||
local result = anim:interpolate()
|
||||
|
||||
|
||||
luaunit.assertAlmostEquals(result.x, 100, 0.01)
|
||||
luaunit.assertAlmostEquals(result.opacity, 1, 0.01)
|
||||
end
|
||||
@@ -110,14 +110,14 @@ function TestKeyframeAnimation:testInterpolationAtMidpoint()
|
||||
local anim = Animation.keyframes({
|
||||
duration = 1,
|
||||
keyframes = {
|
||||
{at = 0, values = {x = 0}},
|
||||
{at = 1, values = {x = 100}},
|
||||
}
|
||||
{ at = 0, values = { x = 0 } },
|
||||
{ at = 1, values = { x = 100 } },
|
||||
},
|
||||
})
|
||||
|
||||
|
||||
anim.elapsed = 0.5
|
||||
local result = anim:interpolate()
|
||||
|
||||
|
||||
luaunit.assertAlmostEquals(result.x, 50, 0.01)
|
||||
end
|
||||
|
||||
@@ -126,22 +126,22 @@ function TestKeyframeAnimation:testPerKeyframeEasing()
|
||||
local anim = Animation.keyframes({
|
||||
duration = 1,
|
||||
keyframes = {
|
||||
{at = 0, values = {x = 0}, easing = "easeInQuad"},
|
||||
{at = 0.5, values = {x = 50}, easing = "linear"},
|
||||
{at = 1, values = {x = 100}},
|
||||
}
|
||||
{ at = 0, values = { x = 0 }, easing = "easeInQuad" },
|
||||
{ at = 0.5, values = { x = 50 }, easing = "linear" },
|
||||
{ at = 1, values = { x = 100 } },
|
||||
},
|
||||
})
|
||||
|
||||
|
||||
-- At t=0.25 (middle of first segment with easeInQuad)
|
||||
anim.elapsed = 0.25
|
||||
anim._resultDirty = true -- Mark dirty to force recalculation
|
||||
anim._resultDirty = true -- Mark dirty to force recalculation
|
||||
local result1 = anim:interpolate()
|
||||
-- easeInQuad at 0.5 should give 0.25, so x = 0 + (50-0) * 0.25 = 12.5
|
||||
luaunit.assertTrue(result1.x < 25, "easeInQuad should slow start")
|
||||
|
||||
|
||||
-- At t=0.75 (middle of second segment with linear)
|
||||
anim.elapsed = 0.75
|
||||
anim._resultDirty = true -- Mark dirty to force recalculation
|
||||
anim._resultDirty = true -- Mark dirty to force recalculation
|
||||
local result2 = anim:interpolate()
|
||||
-- linear at 0.5 should give 0.5, so x = 50 + (100-50) * 0.5 = 75
|
||||
luaunit.assertAlmostEquals(result2.x, 75, 1)
|
||||
@@ -152,22 +152,22 @@ function TestKeyframeAnimation:testFindKeyframes()
|
||||
local anim = Animation.keyframes({
|
||||
duration = 1,
|
||||
keyframes = {
|
||||
{at = 0, values = {x = 0}},
|
||||
{at = 0.25, values = {x = 25}},
|
||||
{at = 0.75, values = {x = 75}},
|
||||
{at = 1, values = {x = 100}},
|
||||
}
|
||||
{ at = 0, values = { x = 0 } },
|
||||
{ at = 0.25, values = { x = 25 } },
|
||||
{ at = 0.75, values = { x = 75 } },
|
||||
{ at = 1, values = { x = 100 } },
|
||||
},
|
||||
})
|
||||
|
||||
|
||||
-- Test finding keyframes at different progress values
|
||||
local prev1, next1 = anim:findKeyframes(0.1)
|
||||
luaunit.assertEquals(prev1.at, 0)
|
||||
luaunit.assertEquals(next1.at, 0.25)
|
||||
|
||||
|
||||
local prev2, next2 = anim:findKeyframes(0.5)
|
||||
luaunit.assertEquals(prev2.at, 0.25)
|
||||
luaunit.assertEquals(next2.at, 0.75)
|
||||
|
||||
|
||||
local prev3, next3 = anim:findKeyframes(0.9)
|
||||
luaunit.assertEquals(prev3.at, 0.75)
|
||||
luaunit.assertEquals(next3.at, 1)
|
||||
@@ -178,18 +178,18 @@ function TestKeyframeAnimation:testKeyframeAnimationUpdate()
|
||||
local anim = Animation.keyframes({
|
||||
duration = 1,
|
||||
keyframes = {
|
||||
{at = 0, values = {opacity = 0}},
|
||||
{at = 1, values = {opacity = 1}},
|
||||
}
|
||||
{ at = 0, values = { opacity = 0 } },
|
||||
{ at = 1, values = { opacity = 1 } },
|
||||
},
|
||||
})
|
||||
|
||||
|
||||
-- Update halfway through
|
||||
anim:update(0.5)
|
||||
local result = anim:interpolate()
|
||||
|
||||
|
||||
luaunit.assertAlmostEquals(result.opacity, 0.5, 0.01)
|
||||
luaunit.assertFalse(anim:update(0)) -- Not complete yet
|
||||
|
||||
|
||||
-- Update to completion
|
||||
luaunit.assertTrue(anim:update(0.6)) -- Should complete
|
||||
luaunit.assertEquals(anim:getState(), "completed")
|
||||
@@ -200,23 +200,29 @@ function TestKeyframeAnimation:testKeyframeAnimationCallbacks()
|
||||
local startCalled = false
|
||||
local updateCalled = false
|
||||
local completeCalled = false
|
||||
|
||||
|
||||
local anim = Animation.keyframes({
|
||||
duration = 1,
|
||||
keyframes = {
|
||||
{at = 0, values = {x = 0}},
|
||||
{at = 1, values = {x = 100}},
|
||||
{ at = 0, values = { x = 0 } },
|
||||
{ at = 1, values = { x = 100 } },
|
||||
},
|
||||
onStart = function() startCalled = true end,
|
||||
onUpdate = function() updateCalled = true end,
|
||||
onComplete = function() completeCalled = true end,
|
||||
onStart = function()
|
||||
startCalled = true
|
||||
end,
|
||||
onUpdate = function()
|
||||
updateCalled = true
|
||||
end,
|
||||
onComplete = function()
|
||||
completeCalled = true
|
||||
end,
|
||||
})
|
||||
|
||||
|
||||
anim:update(0.5)
|
||||
luaunit.assertTrue(startCalled)
|
||||
luaunit.assertTrue(updateCalled)
|
||||
luaunit.assertFalse(completeCalled)
|
||||
|
||||
|
||||
anim:update(0.6)
|
||||
luaunit.assertTrue(completeCalled)
|
||||
end
|
||||
@@ -226,9 +232,9 @@ function TestKeyframeAnimation:testMissingKeyframes()
|
||||
-- Should create default keyframes with warning
|
||||
local anim = Animation.keyframes({
|
||||
duration = 1,
|
||||
keyframes = {}
|
||||
keyframes = {},
|
||||
})
|
||||
|
||||
|
||||
luaunit.assertNotNil(anim)
|
||||
luaunit.assertEquals(#anim.keyframes, 2) -- Should have default start and end
|
||||
end
|
||||
@@ -239,10 +245,10 @@ function TestKeyframeAnimation:testSingleKeyframe()
|
||||
local anim = Animation.keyframes({
|
||||
duration = 1,
|
||||
keyframes = {
|
||||
{at = 0.5, values = {x = 50}}
|
||||
}
|
||||
{ at = 0.5, values = { x = 50 } },
|
||||
},
|
||||
})
|
||||
|
||||
|
||||
luaunit.assertNotNil(anim)
|
||||
luaunit.assertTrue(#anim.keyframes >= 2) -- Should have at least 2 keyframes
|
||||
end
|
||||
@@ -252,11 +258,11 @@ function TestKeyframeAnimation:testKeyframesWithoutStart()
|
||||
local anim = Animation.keyframes({
|
||||
duration = 1,
|
||||
keyframes = {
|
||||
{at = 0.5, values = {x = 50}},
|
||||
{at = 1, values = {x = 100}},
|
||||
}
|
||||
{ at = 0.5, values = { x = 50 } },
|
||||
{ at = 1, values = { x = 100 } },
|
||||
},
|
||||
})
|
||||
|
||||
|
||||
-- Should auto-add keyframe at 0
|
||||
luaunit.assertEquals(anim.keyframes[1].at, 0)
|
||||
luaunit.assertEquals(anim.keyframes[1].values.x, 50) -- Should copy first keyframe values
|
||||
@@ -267,11 +273,11 @@ function TestKeyframeAnimation:testKeyframesWithoutEnd()
|
||||
local anim = Animation.keyframes({
|
||||
duration = 1,
|
||||
keyframes = {
|
||||
{at = 0, values = {x = 0}},
|
||||
{at = 0.5, values = {x = 50}},
|
||||
}
|
||||
{ at = 0, values = { x = 0 } },
|
||||
{ at = 0.5, values = { x = 50 } },
|
||||
},
|
||||
})
|
||||
|
||||
|
||||
-- Should auto-add keyframe at 1
|
||||
luaunit.assertEquals(anim.keyframes[#anim.keyframes].at, 1)
|
||||
luaunit.assertEquals(anim.keyframes[#anim.keyframes].values.x, 50) -- Should copy last keyframe values
|
||||
@@ -282,9 +288,9 @@ function TestKeyframeAnimation:testInvalidKeyframeProps()
|
||||
-- Should handle gracefully with warnings
|
||||
local anim = Animation.keyframes({
|
||||
duration = 0, -- Invalid
|
||||
keyframes = "not a table" -- Invalid
|
||||
keyframes = "not a table", -- Invalid
|
||||
})
|
||||
|
||||
|
||||
luaunit.assertNotNil(anim)
|
||||
luaunit.assertEquals(anim.duration, 1) -- Should use default
|
||||
end
|
||||
@@ -294,22 +300,22 @@ function TestKeyframeAnimation:testMultiPropertyKeyframes()
|
||||
local anim = Animation.keyframes({
|
||||
duration = 2,
|
||||
keyframes = {
|
||||
{at = 0, values = {x = 0, y = 0, opacity = 0, width = 50}},
|
||||
{at = 0.33, values = {x = 100, y = 50, opacity = 1, width = 100}},
|
||||
{at = 0.66, values = {x = 200, y = 100, opacity = 1, width = 150}},
|
||||
{at = 1, values = {x = 300, y = 150, opacity = 0, width = 200}},
|
||||
}
|
||||
{ at = 0, values = { x = 0, y = 0, opacity = 0, width = 50 } },
|
||||
{ at = 0.33, values = { x = 100, y = 50, opacity = 1, width = 100 } },
|
||||
{ at = 0.66, values = { x = 200, y = 100, opacity = 1, width = 150 } },
|
||||
{ at = 1, values = { x = 300, y = 150, opacity = 0, width = 200 } },
|
||||
},
|
||||
})
|
||||
|
||||
|
||||
-- Test interpolation at 0.5 (middle of second segment)
|
||||
anim.elapsed = 1.0 -- t = 0.5
|
||||
local result = anim:interpolate()
|
||||
|
||||
|
||||
luaunit.assertNotNil(result.x)
|
||||
luaunit.assertNotNil(result.y)
|
||||
luaunit.assertNotNil(result.opacity)
|
||||
luaunit.assertNotNil(result.width)
|
||||
|
||||
|
||||
-- Should be interpolating between keyframes at 0.33 and 0.66
|
||||
luaunit.assertTrue(result.x > 100 and result.x < 200)
|
||||
luaunit.assertTrue(result.y > 50 and result.y < 100)
|
||||
@@ -317,19 +323,21 @@ end
|
||||
|
||||
-- Test keyframe with easing function (not string)
|
||||
function TestKeyframeAnimation:testKeyframeWithEasingFunction()
|
||||
local customEasing = function(t) return t * t end
|
||||
|
||||
local customEasing = function(t)
|
||||
return t * t
|
||||
end
|
||||
|
||||
local anim = Animation.keyframes({
|
||||
duration = 1,
|
||||
keyframes = {
|
||||
{at = 0, values = {x = 0}, easing = customEasing},
|
||||
{at = 1, values = {x = 100}},
|
||||
}
|
||||
{ at = 0, values = { x = 0 }, easing = customEasing },
|
||||
{ at = 1, values = { x = 100 } },
|
||||
},
|
||||
})
|
||||
|
||||
|
||||
anim.elapsed = 0.5
|
||||
local result = anim:interpolate()
|
||||
|
||||
|
||||
-- At t=0.5, easing(0.5) = 0.25, so x = 0 + 100 * 0.25 = 25
|
||||
luaunit.assertAlmostEquals(result.x, 25, 1)
|
||||
end
|
||||
@@ -339,16 +347,18 @@ function TestKeyframeAnimation:testKeyframeCaching()
|
||||
local anim = Animation.keyframes({
|
||||
duration = 1,
|
||||
keyframes = {
|
||||
{at = 0, values = {x = 0}},
|
||||
{at = 1, values = {x = 100}},
|
||||
}
|
||||
{ at = 0, values = { x = 0 } },
|
||||
{ at = 1, values = { x = 100 } },
|
||||
},
|
||||
})
|
||||
|
||||
|
||||
anim.elapsed = 0.5
|
||||
local result1 = anim:interpolate()
|
||||
local result2 = anim:interpolate() -- Should return cached result
|
||||
|
||||
|
||||
luaunit.assertEquals(result1, result2) -- Should be same table
|
||||
end
|
||||
|
||||
os.exit(luaunit.LuaUnit.run())
|
||||
if not _G.RUNNING_ALL_TESTS then
|
||||
os.exit(luaunit.LuaUnit.run())
|
||||
end
|
||||
|
||||
@@ -11,10 +11,10 @@ TestTouchEvents = {}
|
||||
-- Test: InputEvent.fromTouch creates valid touch event
|
||||
function TestTouchEvents:testInputEvent_FromTouch()
|
||||
local InputEvent = package.loaded["modules.InputEvent"]
|
||||
|
||||
|
||||
local touchId = "touch1"
|
||||
local event = InputEvent.fromTouch(touchId, 100, 200, "began", 0.8)
|
||||
|
||||
|
||||
lu.assertEquals(event.type, "touchpress")
|
||||
lu.assertEquals(event.x, 100)
|
||||
lu.assertEquals(event.y, 200)
|
||||
@@ -27,9 +27,9 @@ end
|
||||
-- Test: Touch event with moved phase
|
||||
function TestTouchEvents:testInputEvent_FromTouch_Moved()
|
||||
local InputEvent = package.loaded["modules.InputEvent"]
|
||||
|
||||
|
||||
local event = InputEvent.fromTouch("touch1", 150, 250, "moved", 1.0)
|
||||
|
||||
|
||||
lu.assertEquals(event.type, "touchmove")
|
||||
lu.assertEquals(event.phase, "moved")
|
||||
end
|
||||
@@ -37,9 +37,9 @@ end
|
||||
-- Test: Touch event with ended phase
|
||||
function TestTouchEvents:testInputEvent_FromTouch_Ended()
|
||||
local InputEvent = package.loaded["modules.InputEvent"]
|
||||
|
||||
|
||||
local event = InputEvent.fromTouch("touch1", 150, 250, "ended", 1.0)
|
||||
|
||||
|
||||
lu.assertEquals(event.type, "touchrelease")
|
||||
lu.assertEquals(event.phase, "ended")
|
||||
end
|
||||
@@ -47,9 +47,9 @@ end
|
||||
-- Test: Touch event with cancelled phase
|
||||
function TestTouchEvents:testInputEvent_FromTouch_Cancelled()
|
||||
local InputEvent = package.loaded["modules.InputEvent"]
|
||||
|
||||
|
||||
local event = InputEvent.fromTouch("touch1", 150, 250, "cancelled", 1.0)
|
||||
|
||||
|
||||
lu.assertEquals(event.type, "touchcancel")
|
||||
lu.assertEquals(event.phase, "cancelled")
|
||||
end
|
||||
@@ -57,7 +57,7 @@ end
|
||||
-- Test: EventHandler tracks touch began
|
||||
function TestTouchEvents:testEventHandler_TouchBegan()
|
||||
FlexLove.beginFrame()
|
||||
|
||||
|
||||
local touchEvents = {}
|
||||
local element = FlexLove.new({
|
||||
width = 200,
|
||||
@@ -66,21 +66,25 @@ function TestTouchEvents:testEventHandler_TouchBegan()
|
||||
table.insert(touchEvents, event)
|
||||
end,
|
||||
})
|
||||
|
||||
|
||||
FlexLove.endFrame()
|
||||
|
||||
|
||||
-- Simulate touch began
|
||||
love.touch.getTouches = function() return {"touch1"} end
|
||||
love.touch.getTouches = function()
|
||||
return { "touch1" }
|
||||
end
|
||||
love.touch.getPosition = function(id)
|
||||
if id == "touch1" then return 100, 100 end
|
||||
if id == "touch1" then
|
||||
return 100, 100
|
||||
end
|
||||
return 0, 0
|
||||
end
|
||||
|
||||
|
||||
-- Trigger touch event processing
|
||||
FlexLove.beginFrame()
|
||||
element._eventHandler:processTouchEvents()
|
||||
FlexLove.endFrame()
|
||||
|
||||
|
||||
-- Should have received a touchpress event
|
||||
lu.assertEquals(#touchEvents, 1)
|
||||
lu.assertEquals(touchEvents[1].type, "touchpress")
|
||||
@@ -90,7 +94,7 @@ end
|
||||
-- Test: EventHandler tracks touch moved
|
||||
function TestTouchEvents:testEventHandler_TouchMoved()
|
||||
FlexLove.beginFrame()
|
||||
|
||||
|
||||
local touchEvents = {}
|
||||
local element = FlexLove.new({
|
||||
width = 200,
|
||||
@@ -99,31 +103,37 @@ function TestTouchEvents:testEventHandler_TouchMoved()
|
||||
table.insert(touchEvents, event)
|
||||
end,
|
||||
})
|
||||
|
||||
|
||||
FlexLove.endFrame()
|
||||
|
||||
|
||||
-- Simulate touch began
|
||||
love.touch.getTouches = function() return {"touch1"} end
|
||||
love.touch.getTouches = function()
|
||||
return { "touch1" }
|
||||
end
|
||||
love.touch.getPosition = function(id)
|
||||
if id == "touch1" then return 100, 100 end
|
||||
if id == "touch1" then
|
||||
return 100, 100
|
||||
end
|
||||
return 0, 0
|
||||
end
|
||||
|
||||
|
||||
-- First touch
|
||||
FlexLove.beginFrame()
|
||||
element._eventHandler:processTouchEvents()
|
||||
FlexLove.endFrame()
|
||||
|
||||
|
||||
-- Move touch
|
||||
love.touch.getPosition = function(id)
|
||||
if id == "touch1" then return 150, 150 end
|
||||
if id == "touch1" then
|
||||
return 150, 150
|
||||
end
|
||||
return 0, 0
|
||||
end
|
||||
|
||||
|
||||
FlexLove.beginFrame()
|
||||
element._eventHandler:processTouchEvents()
|
||||
FlexLove.endFrame()
|
||||
|
||||
|
||||
-- Should have received touchpress and touchmove events
|
||||
lu.assertEquals(#touchEvents, 2)
|
||||
lu.assertEquals(touchEvents[1].type, "touchpress")
|
||||
@@ -135,7 +145,7 @@ end
|
||||
-- Test: EventHandler tracks touch ended
|
||||
function TestTouchEvents:testEventHandler_TouchEnded()
|
||||
FlexLove.beginFrame()
|
||||
|
||||
|
||||
local touchEvents = {}
|
||||
local element = FlexLove.new({
|
||||
width = 200,
|
||||
@@ -144,28 +154,34 @@ function TestTouchEvents:testEventHandler_TouchEnded()
|
||||
table.insert(touchEvents, event)
|
||||
end,
|
||||
})
|
||||
|
||||
|
||||
FlexLove.endFrame()
|
||||
|
||||
|
||||
-- Simulate touch began
|
||||
love.touch.getTouches = function() return {"touch1"} end
|
||||
love.touch.getTouches = function()
|
||||
return { "touch1" }
|
||||
end
|
||||
love.touch.getPosition = function(id)
|
||||
if id == "touch1" then return 100, 100 end
|
||||
if id == "touch1" then
|
||||
return 100, 100
|
||||
end
|
||||
return 0, 0
|
||||
end
|
||||
|
||||
|
||||
-- First touch
|
||||
FlexLove.beginFrame()
|
||||
element._eventHandler:processTouchEvents()
|
||||
FlexLove.endFrame()
|
||||
|
||||
|
||||
-- End touch
|
||||
love.touch.getTouches = function() return {} end
|
||||
|
||||
love.touch.getTouches = function()
|
||||
return {}
|
||||
end
|
||||
|
||||
FlexLove.beginFrame()
|
||||
element._eventHandler:processTouchEvents()
|
||||
FlexLove.endFrame()
|
||||
|
||||
|
||||
-- Should have received touchpress and touchrelease events
|
||||
lu.assertEquals(#touchEvents, 2)
|
||||
lu.assertEquals(touchEvents[1].type, "touchpress")
|
||||
@@ -175,7 +191,7 @@ end
|
||||
-- Test: EventHandler tracks multiple simultaneous touches
|
||||
function TestTouchEvents:testEventHandler_MultiTouch()
|
||||
FlexLove.beginFrame()
|
||||
|
||||
|
||||
local touchEvents = {}
|
||||
local element = FlexLove.new({
|
||||
width = 200,
|
||||
@@ -184,26 +200,32 @@ function TestTouchEvents:testEventHandler_MultiTouch()
|
||||
table.insert(touchEvents, event)
|
||||
end,
|
||||
})
|
||||
|
||||
|
||||
FlexLove.endFrame()
|
||||
|
||||
|
||||
-- Simulate two touches
|
||||
love.touch.getTouches = function() return {"touch1", "touch2"} end
|
||||
love.touch.getTouches = function()
|
||||
return { "touch1", "touch2" }
|
||||
end
|
||||
love.touch.getPosition = function(id)
|
||||
if id == "touch1" then return 50, 50 end
|
||||
if id == "touch2" then return 150, 150 end
|
||||
if id == "touch1" then
|
||||
return 50, 50
|
||||
end
|
||||
if id == "touch2" then
|
||||
return 150, 150
|
||||
end
|
||||
return 0, 0
|
||||
end
|
||||
|
||||
|
||||
FlexLove.beginFrame()
|
||||
element._eventHandler:processTouchEvents()
|
||||
FlexLove.endFrame()
|
||||
|
||||
|
||||
-- Should have received two touchpress events
|
||||
lu.assertEquals(#touchEvents, 2)
|
||||
lu.assertEquals(touchEvents[1].type, "touchpress")
|
||||
lu.assertEquals(touchEvents[2].type, "touchpress")
|
||||
|
||||
|
||||
-- Different touch IDs
|
||||
lu.assertNotEquals(touchEvents[1].touchId, touchEvents[2].touchId)
|
||||
end
|
||||
@@ -213,24 +235,26 @@ function TestTouchEvents:testGestureRecognizer_Tap()
|
||||
local GestureRecognizer = package.loaded["modules.GestureRecognizer"]
|
||||
local InputEvent = package.loaded["modules.InputEvent"]
|
||||
local utils = package.loaded["modules.utils"]
|
||||
|
||||
|
||||
local recognizer = GestureRecognizer.new({}, {
|
||||
InputEvent = InputEvent,
|
||||
utils = utils,
|
||||
})
|
||||
|
||||
|
||||
-- Simulate tap (press and quick release)
|
||||
local touchId = "touch1"
|
||||
local pressEvent = InputEvent.fromTouch(touchId, 100, 100, "began", 1.0)
|
||||
local releaseEvent = InputEvent.fromTouch(touchId, 102, 102, "ended", 1.0)
|
||||
|
||||
|
||||
recognizer:processTouchEvent(pressEvent)
|
||||
local gesture = recognizer:processTouchEvent(releaseEvent)
|
||||
|
||||
-- Note: The gesture detection returns from internal methods,
|
||||
|
||||
-- Note: The gesture detection returns from internal methods,
|
||||
-- needs to be captured from the event processing
|
||||
-- This is a basic structural test
|
||||
lu.assertNotNil(recognizer)
|
||||
end
|
||||
|
||||
os.exit(lu.LuaUnit.run())
|
||||
if not _G.RUNNING_ALL_TESTS then
|
||||
os.exit(lu.LuaUnit.run())
|
||||
end
|
||||
|
||||
@@ -19,29 +19,37 @@ local luaunit = require("testing.luaunit")
|
||||
local testFiles = {
|
||||
"testing/__tests__/animation_test.lua",
|
||||
"testing/__tests__/animation_properties_test.lua",
|
||||
"testing/__tests__/transform_test.lua",
|
||||
"testing/__tests__/blur_test.lua",
|
||||
"testing/__tests__/color_validation_test.lua",
|
||||
"testing/__tests__/critical_failures_test.lua",
|
||||
"testing/__tests__/easing_test.lua",
|
||||
"testing/__tests__/element_test.lua",
|
||||
"testing/__tests__/error_handler_test.lua",
|
||||
"testing/__tests__/event_handler_test.lua",
|
||||
"testing/__tests__/flexlove_test.lua",
|
||||
"testing/__tests__/font_cache_test.lua",
|
||||
"testing/__tests__/grid_test.lua",
|
||||
"testing/__tests__/image_cache_test.lua",
|
||||
"testing/__tests__/image_renderer_test.lua",
|
||||
"testing/__tests__/image_scaler_test.lua",
|
||||
"testing/__tests__/image_tiling_test.lua",
|
||||
"testing/__tests__/input_event_test.lua",
|
||||
"testing/__tests__/keyframe_animation_test.lua",
|
||||
"testing/__tests__/layout_edge_cases_test.lua",
|
||||
"testing/__tests__/layout_engine_test.lua",
|
||||
"testing/__tests__/ninepatch_parser_test.lua",
|
||||
"testing/__tests__/ninepatch_test.lua",
|
||||
"testing/__tests__/overflow_test.lua",
|
||||
"testing/__tests__/path_validation_test.lua",
|
||||
"testing/__tests__/performance_instrumentation_test.lua",
|
||||
"testing/__tests__/performance_warnings_test.lua",
|
||||
"testing/__tests__/renderer_test.lua",
|
||||
"testing/__tests__/roundedrect_test.lua",
|
||||
"testing/__tests__/sanitization_test.lua",
|
||||
"testing/__tests__/text_editor_test.lua",
|
||||
"testing/__tests__/theme_test.lua",
|
||||
"testing/__tests__/touch_events_test.lua",
|
||||
"testing/__tests__/transform_test.lua",
|
||||
"testing/__tests__/units_test.lua",
|
||||
"testing/__tests__/utils_test.lua",
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user