Add a couple basic gui tests

develop
lethosor 2020-03-27 01:38:40 -04:00
parent 500426ea25
commit bb02c9f639
2 changed files with 34 additions and 0 deletions

@ -0,0 +1,19 @@
local gui = require('gui')
function test.getKeyDisplay()
expect.eq(gui.getKeyDisplay(df.interface_key.CUSTOM_A), 'a')
expect.eq(gui.getKeyDisplay('CUSTOM_A'), 'a')
expect.eq(gui.getKeyDisplay(df.interface_key._first_item - 1), '?')
expect.eq(gui.getKeyDisplay(df.interface_key._last_item + 1), '?')
expect.eq(gui.getKeyDisplay(df.interface_key.KEYBINDING_COMPLETE), '?')
end
function test.clear_pen()
expect.table_eq(gui.CLEAR_PEN, {
ch = string.byte(' '),
fg = COLOR_BLACK,
bg = COLOR_BLACK,
bold = false,
tile_color = false,
})
end

@ -27,6 +27,21 @@ end
function expect.ne(a, b, comment) function expect.ne(a, b, comment)
return a ~= b, comment, ('%s == %s'):format(a, b) return a ~= b, comment, ('%s == %s'):format(a, b)
end end
function expect.table_eq(a, b, comment)
local checked = {}
for k, v in pairs(a) do
if a[k] ~= b[k] then
return false, comment, ('key "%s": %s ~= %s'):format(k, a[k], b[k])
end
checked[k] = true
end
for k in pairs(b) do
if not checked[k] then
return false, comment, ('key "%s": %s ~= %s'):format(k, a[k], b[k])
end
end
return true
end
function expect.error(func, ...) function expect.error(func, ...)
local ok, ret = pcall(func, ...) local ok, ret = pcall(func, ...)
if ok then if ok then