neovim

Neovim text editor
git clone https://git.dasho.dev/neovim.git
Log | Files | Refs | README

example_spec.lua (2052B)


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