Fixed lume.ripairs() for falsey values; added test

This commit is contained in:
rxi 2018-04-08 15:22:13 +01:00
parent 09035882f1
commit 0980d07eaa
2 changed files with 5 additions and 3 deletions

View File

@ -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)

View File

@ -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