tests: Improve gears.matcher tests.

This commit is contained in:
Emmanuel Lepage Vallee 2021-10-22 23:01:06 -07:00
parent 9db62b824c
commit ffb95eec8d
1 changed files with 93 additions and 0 deletions

View File

@ -41,6 +41,99 @@ describe("gears.matcher", function()
assert.is_false(matcher_instance:_match(test_obj, rule)) assert.is_false(matcher_instance:_match(test_obj, rule))
end) end)
describe("match_any positive", function()
local rule = {
foo={''},
spam={''},
}
assert.is_true(matcher_instance:_match_any(test_obj, rule))
end)
describe("match_any negative", function()
local rule = {
foo={''},
spam={'bar'},
}
assert.is_false(matcher_instance:_match_any(test_obj, rule))
end)
describe("match_every full negative", function()
local rule = {
foo={''},
spam={'bar'},
}
assert.is_false(matcher_instance:_match_every(test_obj, rule))
end)
describe("match_every partial negative", function()
local rule = {
foo={''},
spam={''},
}
assert.is_false(matcher_instance:_match_every(test_obj, rule))
end)
describe("match_every positive", function()
local rule = {
foo={'bar'},
spam={''},
}
assert.is_true(matcher_instance:_match_every(test_obj, rule))
end)
describe("check main vs. fallback rules", function()
local m = matcher()
local rules = {
{
id = "main",
fallback = false,
rule = {
foo = "bar"
},
properties = {
main_applied = true,
}
},
{
id = "fallback",
fallback = true,
rule = {
everything = 42
},
properties = {
fallback_applied = true,
}
},
}
m:append_rules("default", rules)
-- Matches `main` and `fallback`
local obj1 = {
foo = "bar",
everything = 42,
}
-- Only matches `fallback`.
local obj2 = {
foo = "baz",
everything = 42,
}
m:apply(obj1)
m:apply(obj2)
assert.is_true(m:_match(obj1, rules[1]["rule"]))
assert.is_true(m:_match(obj1, rules[2]["rule"]))
assert.is_true(m:_match(obj2, rules[2]["rule"]))
assert.is_false(m:_match(obj2, rules[1]["rule"]))
assert.is_true(obj1.main_applied)
assert.is_true(obj2.fallback_applied)
assert.is_nil(obj2.main_applied)
assert.is_nil(obj1.fallback_applied)
end)
end) end)
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80 -- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80