mirror of
https://github.com/TangentFoxy/lume.git
synced 2025-07-27 18:42:20 +00:00
Fixed lume.ripairs() for falsey values; added test
This commit is contained in:
4
lume.lua
4
lume.lua
@@ -724,7 +724,9 @@ end
|
||||
local ripairs_iter = function(t, i)
|
||||
i = i - 1
|
||||
local v = t[i]
|
||||
if v then return i, v end
|
||||
if v ~= nil then
|
||||
return i, v
|
||||
end
|
||||
end
|
||||
|
||||
function lume.ripairs(t)
|
||||
|
@@ -581,12 +581,12 @@ end
|
||||
|
||||
-- lume.ripairs
|
||||
tests["lume.ripairs"] = function()
|
||||
local t = { "a", "b", "c" }
|
||||
local t = { "a", "b", false, "c" }
|
||||
local r = {}
|
||||
for i, v in lume.ripairs(t) do
|
||||
table.insert(r, { i, v })
|
||||
end
|
||||
testeq( r, { { 3, "c" }, { 2, "b" }, { 1, "a" } })
|
||||
testeq( r, { { 4, "c" }, { 3, false }, { 2, "b" }, { 1, "a" } })
|
||||
tester.test.error(lume.ripairs, nil)
|
||||
end
|
||||
|
||||
|
Reference in New Issue
Block a user