Skip to content

Commit

Permalink
[liked_list] false takes precedence over nil
Browse files Browse the repository at this point in the history
  • Loading branch information
mikz committed Jul 20, 2018
1 parent 123a170 commit c28ebb0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion gateway/src/apicast/linked_list.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ local noop = function() end

local empty_t = setmetatable({}, { __newindex = noop })
local __index = function(t,k)
return t.current[k] or t.next[k]
if t.current[k] == nil then return t.next[k] else return t.current[k] end
end

local ro_mt = {
Expand Down
14 changes: 14 additions & 0 deletions spec/linked_list_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ describe('linked_list', function()
assert.same({ b = 2 }, list.next.current)
assert.same({ c = 3 }, list.next.next)
end)

it('takes false over nil', function()
local list = linked_list.readonly({ a = false }, { a = 'value' })

assert.is_false(list.a)
end)
end)

describe('readwrite', function()
Expand Down Expand Up @@ -54,5 +60,13 @@ describe('linked_list', function()
assert.same({ b = 2 }, list.next.current)
assert.same({ c = 3 }, list.next.next)
end)

it('can override values with false', function()
local list = linked_list.readwrite({ }, { a = 'value' })

list.a = false

assert.is_false(list.a)
end)
end)
end)

0 comments on commit c28ebb0

Please sign in to comment.