From 5406ac6fe1a646ceab1025414ac7ce0fc7223d1e Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Sun, 21 Jun 2015 15:46:19 +0200 Subject: [PATCH] Add some tests for the textbox Signed-off-by: Uli Schlachter --- spec/wibox/widget/textbox_spec.lua | 127 +++++++++++++++++++++++++++++ 1 file changed, 127 insertions(+) create mode 100644 spec/wibox/widget/textbox_spec.lua diff --git a/spec/wibox/widget/textbox_spec.lua b/spec/wibox/widget/textbox_spec.lua new file mode 100644 index 000000000..9200a6b64 --- /dev/null +++ b/spec/wibox/widget/textbox_spec.lua @@ -0,0 +1,127 @@ +--------------------------------------------------------------------------- +-- @author Uli Schlachter +-- @copyright 2015 Uli Schlachter +--------------------------------------------------------------------------- + +-- Grml... +_G.awesome = { + xrdb_get_value = function(a, b) + if a ~= "" then error() end + if b ~= "Xft.dpi" then error() end + return nil + end +} + +local textbox = require("wibox.widget.textbox") + +describe("wibox.widget.textbox", function() + local widget + before_each(function() + widget = textbox() + end) + + describe("emitting signals", function() + local redraw_needed, layout_changed + before_each(function() + widget:connect_signal("widget::redraw_needed", function() + redraw_needed = redraw_needed + 1 + end) + widget:connect_signal("widget::layout_changed", function() + layout_changed = layout_changed + 1 + end) + redraw_needed, layout_changed = 0, 0 + end) + + it("text and markup", function() + assert.is.equal(0, redraw_needed) + assert.is.equal(0, layout_changed) + + widget:set_text("text") + assert.is.equal(1, redraw_needed) + assert.is.equal(1, layout_changed) + + widget:set_text("text") + assert.is.equal(1, redraw_needed) + assert.is.equal(1, layout_changed) + + widget:set_text("text") + assert.is.equal(2, redraw_needed) + assert.is.equal(2, layout_changed) + + widget:set_markup("text") + assert.is.equal(3, redraw_needed) + assert.is.equal(3, layout_changed) + + widget:set_markup("text") + assert.is.equal(3, redraw_needed) + assert.is.equal(3, layout_changed) + end) + + it("set_ellipsize", function() + assert.is.equal(0, redraw_needed) + assert.is.equal(0, layout_changed) + + widget:set_ellipsize("end") + assert.is.equal(0, redraw_needed) + assert.is.equal(0, layout_changed) + + widget:set_ellipsize("none") + assert.is.equal(1, redraw_needed) + assert.is.equal(1, layout_changed) + end) + + it("set_wrap", function() + assert.is.equal(0, redraw_needed) + assert.is.equal(0, layout_changed) + + widget:set_wrap("word_char") + assert.is.equal(0, redraw_needed) + assert.is.equal(0, layout_changed) + + widget:set_wrap("char") + assert.is.equal(1, redraw_needed) + assert.is.equal(1, layout_changed) + end) + + it("set_valign", function() + assert.is.equal(0, redraw_needed) + assert.is.equal(0, layout_changed) + + widget:set_valign("center") + assert.is.equal(0, redraw_needed) + assert.is.equal(0, layout_changed) + + widget:set_valign("top") + assert.is.equal(1, redraw_needed) + assert.is.equal(1, layout_changed) + end) + + it("set_align", function() + assert.is.equal(0, redraw_needed) + assert.is.equal(0, layout_changed) + + widget:set_align("left") + assert.is.equal(0, redraw_needed) + assert.is.equal(0, layout_changed) + + widget:set_align("right") + assert.is.equal(1, redraw_needed) + assert.is.equal(1, layout_changed) + end) + + it("set_font", function() + assert.is.equal(0, redraw_needed) + assert.is.equal(0, layout_changed) + + widget:set_font("foo") + assert.is.equal(1, redraw_needed) + assert.is.equal(1, layout_changed) + + widget:set_font("bar") + assert.is.equal(2, redraw_needed) + assert.is.equal(2, layout_changed) + end) + end) +end) + +-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80