From d5dd3fc79425f15d672d5da02aaad2adbe8957ca Mon Sep 17 00:00:00 2001 From: Emmanuel Lepage Vallee Date: Wed, 26 Dec 2018 17:38:05 -0500 Subject: [PATCH] tests: Test root.buttons Try both legacy and standardized code paths. Also try invalid mixes of them in case some modules abuse of rc.lua and ingest the wrong format by accident. --- tests/examples/shims/root.lua | 3 +++ tests/test-miss-handlers.lua | 50 ++++++++++++++++++++++++++++++++++- 2 files changed, 52 insertions(+), 1 deletion(-) diff --git a/tests/examples/shims/root.lua b/tests/examples/shims/root.lua index 78ca955e1..ef7031567 100644 --- a/tests/examples/shims/root.lua +++ b/tests/examples/shims/root.lua @@ -128,6 +128,9 @@ function root.fake_input(event_type, detail, x, y) fake_input_handlers[event_type](detail, x, y) end +function root._buttons() + return {} +end -- Send an artificial set of key events to trigger a key combination. -- It only works in the shims and should not be used with UTF-8 chars. diff --git a/tests/test-miss-handlers.lua b/tests/test-miss-handlers.lua index c6b2baffa..7bbfea256 100644 --- a/tests/test-miss-handlers.lua +++ b/tests/test-miss-handlers.lua @@ -4,7 +4,10 @@ local mouse = mouse local class = tag local obj = class({}) local handler = require("gears.object.properties") +local abutton = require("awful.button") +local gtable = require("gears.table") local wibox = require("wibox") +local runner = require("_runner") awesome.connect_signal("debug::index::miss", error) awesome.connect_signal("debug::newindex::miss", error) @@ -68,6 +71,51 @@ assert(w2:get_children_by_id("main_textbox")[1]) assert(w2.main_background.main_textbox) assert(w2.main_background == w2:get_children_by_id("main_background")[1]) -require("_runner").run_steps({ function() return true end }) +-- You can't retry this, so if the assert above were false, assume it never +-- reaches this. + +local steps = { function() return true end } + +-- Try each combinations of current and legacy style accessors. +table.insert(steps, function()local b1, b2 = button({}, 1, function() end), button({}, 2, function() end) + root.buttons = {b1} + + assert(#root.buttons == 1 ) + assert(#root.buttons() == 1 ) + assert(root.buttons[1] == b1) + + root.buttons{b2} + + assert(#root.buttons == 1 ) + assert(#root.buttons() == 1 ) + assert(root.buttons()[1] == b2) + + local ab1, ab2 = abutton({}, 1, function() end), abutton({}, 2, function() end) + + root.buttons = {ab1} + assert(#root.buttons == 1) + assert(#root.buttons() == 4) + for i=1, 4 do + assert(root.buttons()[i] == ab1[i]) + end + + root.buttons(gtable.join(ab2)) + assert(#root.buttons == 1) + assert(#root.buttons() == 4) + for i=1, 4 do + assert(root.buttons()[i] == ab2[i]) + end + + root.buttons{ab1} + assert(#root.buttons == 1) + assert(#root.buttons() == 4) + for i=1, 4 do + assert(root.buttons()[i] == ab1[i]) + end + + return true +end) + +runner.run_steps(steps) -- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80