Skip to content

Commit 9ce5a7b

Browse files
committed
Add unit test for all(), #30
1 parent 6fa0cce commit 9ce5a7b

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

tests/tests.lua

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,25 @@ function test_tables()
333333
foreach(tbl, foreach_test)
334334
assert_equal(tmp, 0, "foreach(tbl, foreach_test)")
335335

336+
tbl = {}
337+
tbl = { 1, 2, 3, 4, nil, 5, 6, 7, 8, 9, 10 }
338+
local result = {}
339+
340+
for v in all(tbl) do
341+
add(result, v)
342+
end
343+
344+
-- Expected table should skip the nil value.
345+
local expected = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
346+
347+
-- Check that result has the same length.
348+
assert_equal(#result, #expected, "test_all_length")
349+
350+
-- Check that all elements are the same.
351+
for i = 1, #expected do
352+
assert_equal(result[i], expected[i], "test_all_value_" .. i)
353+
end
354+
336355
tbl = {}
337356
end
338357

0 commit comments

Comments
 (0)