robin/laufey

git clone https://git.robinwobin.dev/robin/laufey

Justin M. KeyesMerge #40865 from justinmk/fixcif907614088

master
1.9 KiB68 linesraw
1-- To run this test:
2--    make functionaltest TEST_FILE=test/functional/example_spec.lua
3
4local t = require('test.testutil')
5local n = require('test.functional.testnvim')()
6local Screen = require('test.functional.ui.screen')
7local describe, it, before_each = t.describe, t.it, t.before_each
8local clear = n.clear
9local command = n.command
10local eq = t.eq
11local feed = n.feed
12
13describe('example', function()
14  local screen
15  before_each(function()
16    clear()
17    screen = Screen.new(20, 5)
18  end)
19
20  it('screen test', function()
21    -- Do some stuff.
22    feed('iline1<cr>line2<esc>')
23
24    -- For debugging only: prints the current screen.
25    -- screen:snapshot_util()
26
27    -- Assert the expected state.
28    screen:expect([[
29      line1               |
30      line^2               |
31      {1:~                   }|*2
32                          |
33    ]])
34  end)
35
36  it('override UI event-handler', function()
37    -- Example: override the "tabline_update" UI event handler.
38    --
39    -- screen.lua defines default handlers for UI events, but tests
40    -- may sometimes want to override a handler.
41
42    -- The UI must declare that it wants to handle the UI events.
43    -- For this example, we enable `ext_tabline`:
44    screen:detach()
45    screen = Screen.new(25, 5, { rgb = true, ext_tabline = true })
46
47    -- From ":help ui" we find that `tabline_update` receives `curtab` and
48    -- `tabs` objects. So we declare the UI handler like this:
49    local event_tabs, event_curtab
50    function screen:_handle_tabline_update(curtab, tabs)
51      event_curtab, event_tabs = curtab, tabs
52    end
53
54    -- Create a tabpage...
55    command('tabedit foo')
56
57    -- Use screen:expect{condition=…} to check the result.
58    screen:expect {
59      condition = function()
60        eq(2, event_curtab)
61        eq({
62          { tab = 1, name = '[No Name]' },
63          { tab = 2, name = 'foo' },
64        }, event_tabs)
65      end,
66    }
67  end)
68end)