Add some unit tests for errors in :setup()

This adds a test that checks that :setup{ false } filters out the false, just
like it already filters out nil values. Then, this also adds a test that checks
that properties (:setup{ foo = false }) are not filtered out, because the first
version of me check did that accidentally.

Signed-off-by: Uli Schlachter <psychon@znc.in>
This commit is contained in:
Uli Schlachter 2016-02-28 11:09:21 +01:00
parent 9900cdacd6
commit 923d0b8767
1 changed files with 39 additions and 0 deletions

View File

@ -48,6 +48,45 @@ describe("wibox.widget.base", function()
assert.is.equal(0, #alive)
end)
end)
describe("setup", function()
it("Filters out 'false'", function()
-- Regression test: There was a bug where "nil"s where correctly
-- skipped, but "false" entries survived
local layout1, layout2 = base.make_widget(), base.make_widget()
local called = false
function layout1:set_widget(w)
called = true
assert.equals(w, layout2)
end
function layout2:set_children(children)
assert.is_same({nil, widget1, nil, widget2}, children)
end
layout2.allow_empty_widget = true
layout1:setup{ layout = layout2, false, widget1, nil, widget2 }
assert.is_true(called)
end)
it("Attribute 'false' works", function()
-- Regression test: I introduced a bug with the above fix
local layout1, layout2 = base.make_widget(), base.make_widget()
local called1, called2 = false, false
function layout1:set_widget(w)
called1 = true
assert.equals(w, layout2)
end
function layout2:set_children(children)
assert.is_same({}, children)
end
function layout2:set_foo(foo)
called2 = true
assert.is_false(foo)
end
layout1:setup{ layout = layout2, foo = false }
assert.is_true(called1)
assert.is_true(called2)
end)
end)
end)
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80