From 923d0b87674b84e693f1b724f4d16dcde80d9365 Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Sun, 28 Feb 2016 11:09:21 +0100 Subject: [PATCH] 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 --- spec/wibox/widget/base_spec.lua | 39 +++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/spec/wibox/widget/base_spec.lua b/spec/wibox/widget/base_spec.lua index d24c25d3..91be5918 100644 --- a/spec/wibox/widget/base_spec.lua +++ b/spec/wibox/widget/base_spec.lua @@ -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