From 72c2f06c019cd0f10f25ae3d62f15efebff6273e Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Thu, 8 Jun 2017 16:37:00 +0200 Subject: [PATCH] Add tests for get_children of layouts Partially-fixes: https://github.com/awesomeWM/awesome/issues/1672 Signed-off-by: Uli Schlachter --- spec/wibox/layout/align_spec.lua | 22 ++++++++++++++++++++++ spec/wibox/layout/fixed_spec.lua | 15 +++++++++++++++ spec/wibox/layout/flex_spec.lua | 15 +++++++++++++++ spec/wibox/layout/grid_spec.lua | 30 ++++++++++++++++++++++++++++++ 4 files changed, 82 insertions(+) create mode 100644 spec/wibox/layout/grid_spec.lua diff --git a/spec/wibox/layout/align_spec.lua b/spec/wibox/layout/align_spec.lua index cd5d9b989..931acd10b 100644 --- a/spec/wibox/layout/align_spec.lua +++ b/spec/wibox/layout/align_spec.lua @@ -279,6 +279,28 @@ describe("wibox.layout.align", function() assert.is.equal(layout_changed, 0) end) end) + + it("set_children", function() + local w1, w2, w3 = { w1 = true }, { w2 = true }, { w3 = true } + local layout = align.vertical() + + assert.is.same({}, layout:get_children()) + + layout:set_second(w2) + assert.is.same({ w2 }, layout:get_children()) + + layout:set_first(w1) + assert.is.same({ w1, w2 }, layout:get_children()) + + layout:set_third(w3) + assert.is.same({ w1, w2, w3 }, layout:get_children()) + + layout:set_second(nil) + assert.is.same({ w1, w3 }, layout:get_children()) + + layout:reset() + assert.is.same({}, layout:get_children()) + end) end) -- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80 diff --git a/spec/wibox/layout/fixed_spec.lua b/spec/wibox/layout/fixed_spec.lua index 1da3d3b35..95d79767f 100644 --- a/spec/wibox/layout/fixed_spec.lua +++ b/spec/wibox/layout/fixed_spec.lua @@ -134,6 +134,21 @@ describe("wibox.layout.fixed", function() assert.is.equal(layout_changed, 2) end) end) + + it("set_children", function() + local w1, w2 = base.empty_widget(), base.empty_widget() + + assert.is.same({}, layout:get_children()) + + layout:add(w1) + assert.is.same({ w1 }, layout:get_children()) + + layout:add(w2) + assert.is.same({ w1, w2 }, layout:get_children()) + + layout:reset() + assert.is.same({}, layout:get_children()) + end) end) -- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80 diff --git a/spec/wibox/layout/flex_spec.lua b/spec/wibox/layout/flex_spec.lua index ff5a00d6f..9ed9ae37b 100644 --- a/spec/wibox/layout/flex_spec.lua +++ b/spec/wibox/layout/flex_spec.lua @@ -134,6 +134,21 @@ describe("wibox.layout.flex", function() assert.is.equal(layout_changed, 2) end) end) + + it("set_children", function() + local w1, w2 = base.empty_widget(), base.empty_widget() + + assert.is.same({}, layout:get_children()) + + layout:add(w1) + assert.is.same({ w1 }, layout:get_children()) + + layout:add(w2) + assert.is.same({ w1, w2 }, layout:get_children()) + + layout:reset() + assert.is.same({}, layout:get_children()) + end) end) -- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80 diff --git a/spec/wibox/layout/grid_spec.lua b/spec/wibox/layout/grid_spec.lua new file mode 100644 index 000000000..0c3d894a8 --- /dev/null +++ b/spec/wibox/layout/grid_spec.lua @@ -0,0 +1,30 @@ +--------------------------------------------------------------------------- +-- @author Uli Schlachter +-- @copyright 2017 Uli Schlachter +--------------------------------------------------------------------------- + +local grid = require("wibox.layout.grid") +local base = require("wibox.widget.base") + +describe("wibox.layout.grid", function() + it("set_children", function() + local layout = grid() + local w1, w2 = base.empty_widget(), base.empty_widget() + + assert.is.same({}, layout:get_children()) + + layout:add(w1) + assert.is.same({ w1 }, layout:get_children()) + + layout:add_widget_at(w2, 2, 2) + assert.is.same({ w1, w2 }, layout:get_children()) + + layout:add_widget_at(w1, 1, 2) + assert.is.same({ w1, w2, w1 }, layout:get_children()) + + layout:reset() + assert.is.same({}, layout:get_children()) + end) +end) + +-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80