Lua test cleanup

main
Zef Hemel 2025-01-08 11:23:30 +01:00
parent 076c296dfd
commit fc1ff7dc5b
1 changed files with 199 additions and 222 deletions

View File

@ -401,10 +401,8 @@ local final = counter.reset()
assert(final == 2, "Reset should return last value")
assert(counter.increment() == 0, "Counter should start fresh after reset")
print("All closure tests passed!")
-- Advanced closure tests with multiple functions sharing state
local function test_advanced_closures()
-- Counter that can count by custom steps
local function make_counter_with_step()
local count = 0
@ -436,10 +434,8 @@ local function test_advanced_closures()
c2.increment(5)
assert(c1.get() == 10, "First counter should be independent")
assert(c2.get() == 5, "Second counter should be independent")
end
-- Test varargs handling
local function test_varargs()
-- Basic varargs sum function
local function sum(...)
local total = 0
@ -460,13 +456,8 @@ local function test_varargs()
assert(pass_varargs() == 0, "Should propagate empty varargs")
assert(pass_varargs(1, 2, 3) == 6, "Should propagate varargs")
end
test_varargs()
print("All varargs tests passed!")
-- Test closure behavior
local function test_closures()
-- Counter that can count by custom steps
local function make_counter_with_step()
local count = 0
@ -498,10 +489,8 @@ local function test_closures()
c2.increment(5)
assert(c1.get() == 10, "First counter should be independent")
assert(c2.get() == 5, "Second counter should be independent")
end
-- Test closures with shared upvalues
local function test_shared_closures()
local function make_shared_counter()
local count = 0
local function inc()
@ -523,17 +512,9 @@ local function test_shared_closures()
assert(inc() == 2, "Second increment")
assert(dec() == 1, "First decrement")
assert(get() == 1, "Get should return current value")
end
-- Run all tests
test_varargs()
test_closures()
test_shared_closures()
test_advanced_closures()
print("All tests passed!")
-- Test custom iterators
local function test_custom_iterators()
-- Basic iterator that counts down from n to 1
local function countdown(n)
local count = n
@ -641,7 +622,3 @@ local function test_custom_iterators()
assert(#points == 6, "Grid should generate 6 points")
assert(points[1][1] == 1 and points[1][2] == 1, "First point should be (1,1)")
assert(points[6][1] == 2 and points[6][2] == 3, "Last point should be (2,3)")
end
test_custom_iterators()
print("All iterator tests passed!")