2014-08-23 21:57:52 +02:00
|
|
|
---------------------------------------------------------------------------
|
|
|
|
-- @author Uli Schlachter
|
|
|
|
-- @copyright 2014 Uli Schlachter
|
|
|
|
---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
local object = require("gears.object")
|
2015-06-13 16:55:10 +02:00
|
|
|
local cache = require("gears.cache")
|
2015-06-14 16:03:29 +02:00
|
|
|
local matrix_equals = require("gears.matrix").equals
|
2015-06-14 15:57:33 +02:00
|
|
|
local base = require("wibox.widget.base")
|
2014-08-23 21:57:52 +02:00
|
|
|
local say = require("say")
|
2015-02-18 12:49:21 +01:00
|
|
|
local assert = require("luassert")
|
2014-08-23 21:57:52 +02:00
|
|
|
|
|
|
|
-- {{{ Own widget-based assertions
|
|
|
|
local function widget_fit(state, arguments)
|
|
|
|
if #arguments ~= 3 then
|
2015-06-14 16:03:29 +02:00
|
|
|
error("Have " .. #arguments .. " arguments, but need 3")
|
2014-08-23 21:57:52 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
local widget = arguments[1]
|
|
|
|
local given = arguments[2]
|
|
|
|
local expected = arguments[3]
|
2015-06-14 15:57:33 +02:00
|
|
|
local w, h = base.fit_widget({ "fake context" }, widget, given[1], given[2])
|
2014-08-23 21:57:52 +02:00
|
|
|
|
|
|
|
local fits = expected[1] == w and expected[2] == h
|
|
|
|
if state.mod == fits then
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
-- For proper error message, mess with the arguments
|
|
|
|
arguments[1] = given[1]
|
|
|
|
arguments[2] = given[2]
|
|
|
|
arguments[3] = expected[1]
|
|
|
|
arguments[4] = expected[2]
|
|
|
|
arguments[5] = w
|
|
|
|
arguments[6] = h
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
say:set("assertion.widget_fit.positive", "Offering (%s, %s) to widget and expected (%s, %s), but got (%s, %s)")
|
|
|
|
assert:register("assertion", "widget_fit", widget_fit, "assertion.widget_fit.positive", "assertion.widget_fit.positive")
|
2015-06-14 16:03:29 +02:00
|
|
|
|
|
|
|
local function widget_layout(state, arguments)
|
|
|
|
if #arguments ~= 3 then
|
|
|
|
error("Have " .. #arguments .. " arguments, but need 3")
|
|
|
|
end
|
|
|
|
|
|
|
|
local widget = arguments[1]
|
|
|
|
local given = arguments[2]
|
|
|
|
local expected = arguments[3]
|
|
|
|
local children = widget.layout and widget:layout({ "fake context" }, given[1], given[2]) or {}
|
|
|
|
|
|
|
|
local fits = true
|
|
|
|
if #children ~= #expected then
|
|
|
|
fits = false
|
|
|
|
else
|
|
|
|
for i = 1, #children do
|
|
|
|
local child, expected = children[i], expected[i]
|
|
|
|
if child._widget ~= expected._widget or
|
|
|
|
child._width ~= expected._width or
|
|
|
|
child._height ~= expected._height or
|
|
|
|
not matrix_equals(child._matrix, expected._matrix) then
|
|
|
|
fits = false
|
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
if state.mod == fits then
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
|
|
|
-- For proper error message, mess with the arguments
|
|
|
|
arguments[1] = expected
|
|
|
|
arguments[2] = children
|
|
|
|
arguments[3] = given[1]
|
|
|
|
arguments[4] = given[2]
|
|
|
|
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
say:set("assertion.widget_layout.positive", "Expected:\n%s\nbut got:\n%s\nwhen offering (%s, %s) to widget")
|
|
|
|
assert:register("assertion", "widget_layout", widget_layout, "assertion.widget_layout.positive", "assertion.widget_layout.positive")
|
2014-08-23 21:57:52 +02:00
|
|
|
-- }}}
|
|
|
|
|
|
|
|
return {
|
|
|
|
widget_stub = function(width, height)
|
|
|
|
local w = object()
|
2015-09-06 10:00:27 +02:00
|
|
|
w:add_signal("widget::redraw_needed")
|
|
|
|
w:add_signal("widget::layout_changed")
|
2015-07-17 18:23:55 +02:00
|
|
|
w.visible = true
|
2015-09-06 10:00:27 +02:00
|
|
|
w.opacity = 1
|
2014-08-23 21:57:52 +02:00
|
|
|
w.fit = function()
|
|
|
|
return width or 10, height or 10
|
|
|
|
end
|
2015-06-13 16:55:10 +02:00
|
|
|
w._fit_geometry_cache = cache.new(w.fit)
|
2014-08-23 21:57:52 +02:00
|
|
|
|
|
|
|
return w
|
|
|
|
end,
|
|
|
|
}
|
|
|
|
|
|
|
|
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80
|