2019-03-18 17:36:24 -07:00
|
|
|
-- To run this test:
|
|
|
|
-- TEST_FILE=test/functional/example_spec.lua make functionaltest
|
|
|
|
|
2024-04-09 04:26:16 -07:00
|
|
|
local t = require('test.functional.testutil')()
|
2019-03-18 17:36:24 -07:00
|
|
|
local Screen = require('test.functional.ui.screen')
|
2024-04-08 02:03:20 -07:00
|
|
|
local clear = t.clear
|
|
|
|
local command = t.command
|
|
|
|
local eq = t.eq
|
|
|
|
local feed = t.feed
|
2019-03-18 17:36:24 -07:00
|
|
|
|
|
|
|
describe('example', function()
|
|
|
|
local screen
|
|
|
|
before_each(function()
|
|
|
|
clear()
|
|
|
|
screen = Screen.new(20, 5)
|
|
|
|
screen:attach()
|
|
|
|
screen:set_default_attr_ids({
|
|
|
|
[0] = { bold = true, foreground = Screen.colors.Blue },
|
|
|
|
[1] = { bold = true, foreground = Screen.colors.Brown },
|
|
|
|
})
|
|
|
|
end)
|
|
|
|
|
2019-03-19 04:24:41 -07:00
|
|
|
it('screen test', function()
|
2019-03-18 17:36:24 -07:00
|
|
|
-- Do some stuff.
|
|
|
|
feed('iline1<cr>line2<esc>')
|
|
|
|
|
|
|
|
-- For debugging only: prints the current screen.
|
|
|
|
-- screen:snapshot_util()
|
|
|
|
|
|
|
|
-- Assert the expected state.
|
|
|
|
screen:expect([[
|
|
|
|
line1 |
|
|
|
|
line^2 |
|
|
|
|
{0:~ }|
|
|
|
|
{0:~ }|
|
|
|
|
|
|
|
|
|
]])
|
|
|
|
end)
|
2019-12-01 02:06:10 -07:00
|
|
|
|
|
|
|
it('override UI event-handler', function()
|
|
|
|
-- Example: override the "tabline_update" UI event handler.
|
|
|
|
--
|
|
|
|
-- screen.lua defines default handlers for UI events, but tests
|
|
|
|
-- may sometimes want to override a handler.
|
|
|
|
|
|
|
|
-- The UI must declare that it wants to handle the UI events.
|
|
|
|
-- For this example, we enable `ext_tabline`:
|
|
|
|
screen:detach()
|
|
|
|
screen = Screen.new(25, 5)
|
|
|
|
screen:attach({ rgb = true, ext_tabline = true })
|
|
|
|
|
|
|
|
-- From ":help ui" we find that `tabline_update` receives `curtab` and
|
|
|
|
-- `tabs` objects. So we declare the UI handler like this:
|
|
|
|
local event_tabs, event_curtab
|
|
|
|
function screen:_handle_tabline_update(curtab, tabs)
|
|
|
|
event_curtab, event_tabs = curtab, tabs
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Create a tabpage...
|
|
|
|
command('tabedit foo')
|
|
|
|
|
|
|
|
-- Use screen:expect{condition=…} to check the result.
|
|
|
|
screen:expect {
|
|
|
|
condition = function()
|
2024-01-16 06:26:21 -07:00
|
|
|
eq(2, event_curtab)
|
2019-12-01 02:06:10 -07:00
|
|
|
eq({
|
2024-01-16 06:26:21 -07:00
|
|
|
{ tab = 1, name = '[No Name]' },
|
|
|
|
{ tab = 2, name = 'foo' },
|
2019-12-01 02:06:10 -07:00
|
|
|
}, event_tabs)
|
|
|
|
end,
|
|
|
|
}
|
|
|
|
end)
|
2019-03-18 17:36:24 -07:00
|
|
|
end)
|