neovim

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

autocmd_spec.lua (4118B)


      1 local t = require('test.testutil')
      2 local n = require('test.functional.testnvim')()
      3 local Screen = require('test.functional.ui.screen')
      4 
      5 local clear = n.clear
      6 local write_file = t.write_file
      7 local command = n.command
      8 local feed = n.feed
      9 local api = n.api
     10 local eq = t.eq
     11 
     12 before_each(clear)
     13 
     14 local function expected_empty()
     15  eq({}, api.nvim_get_vvar('errors'))
     16 end
     17 
     18 -- oldtest: Test_get_Visual_selection_in_curbuf_autocmd()
     19 it('autocmd can get Visual selection when using setbufvar() on curbuf', function()
     20  n.exec([[
     21    new
     22    autocmd OptionSet list let b:text = getregion(getpos('.'), getpos('v'))
     23    call setline(1, 'foo bar baz')
     24 
     25    normal! gg0fbvtb
     26    setlocal list
     27    call assert_equal(['bar '], b:text)
     28    exe "normal! \<Esc>"
     29 
     30    normal! v0
     31    call setbufvar('%', '&list', v:false)
     32    call assert_equal(['foo bar '], b:text)
     33    exe "normal! \<Esc>"
     34  ]])
     35  expected_empty()
     36 end)
     37 
     38 -- oldtest: Test_autocmd_invalidates_undo_on_textchanged()
     39 it('no E440 in quickfix window when autocommand invalidates undo', function()
     40  write_file(
     41    'XTest_autocmd_invalidates_undo_on_textchanged',
     42    [[
     43    set hidden
     44    " create quickfix list (at least 2 lines to move line)
     45    vimgrep /u/j %
     46 
     47    " enter quickfix window
     48    cwindow
     49 
     50    " set modifiable
     51    setlocal modifiable
     52 
     53    " set autocmd to clear quickfix list
     54 
     55    autocmd! TextChanged <buffer> call setqflist([])
     56    " move line
     57    move+1
     58    ]]
     59  )
     60  finally(function()
     61    os.remove('XTest_autocmd_invalidates_undo_on_textchanged')
     62  end)
     63  command('edit XTest_autocmd_invalidates_undo_on_textchanged')
     64  command('so %')
     65  feed('G')
     66  eq('', api.nvim_get_vvar('errmsg'))
     67 end)
     68 
     69 -- oldtest: Test_WinScrolled_Resized_eiw()
     70 it('WinScrolled and WinResized events can be ignored in a window', function()
     71  local screen = Screen.new()
     72  n.exec([[
     73    call setline(1, ['foo']->repeat(32))
     74    set eventignorewin=WinScrolled,WinResized
     75    split
     76    let [g:afile,g:resized,g:scrolled] = ['none',0,0]
     77    au WinScrolled * let [g:afile,g:scrolled] = [expand('<afile>'),g:scrolled+1]
     78    au WinResized * let [g:afile,g:resized] = [expand('<afile>'),g:resized+1]
     79  ]])
     80  feed('<C-W>-')
     81  screen:expect([[
     82    ^foo                                                  |
     83    foo                                                  |*4
     84    {3:[No Name] [+]                                        }|
     85    foo                                                  |*6
     86    {2:[No Name] [+]                                        }|
     87                                                         |
     88  ]])
     89  feed(':echo g:afile g:resized g:scrolled<CR>')
     90  screen:expect({ any = 'none 0 0.*' })
     91  feed('G')
     92  screen:expect([[
     93    foo                                                  |*4
     94    ^foo                                                  |
     95    {3:[No Name] [+]                                        }|
     96    foo                                                  |*6
     97    {2:[No Name] [+]                                        }|
     98    none 0 0                                             |
     99  ]])
    100  feed('gg')
    101  screen:expect([[
    102    ^foo                                                  |
    103    foo                                                  |*4
    104    {3:[No Name] [+]                                        }|
    105    foo                                                  |*6
    106    {2:[No Name] [+]                                        }|
    107    none 0 0                                             |
    108  ]])
    109  feed(':echo g:afile g:resized g:scrolled')
    110  screen:expect({ any = ':echo g:afile g:resized g:scrolled.*' })
    111  feed('<CR>')
    112  screen:expect({ any = 'none 0 0.*' })
    113  feed(':set eventignorewin=<CR><C-W>w<C-W>+')
    114  screen:expect({ any = ':set eventignorewin=.*' })
    115  feed(':echo win_getid() g:afile g:resized g:scrolled<CR>')
    116  screen:expect({ any = '1000 1001 1 1.*' })
    117 end)
    118 
    119 -- oldtest: Test_CmdlineLeavePre_cabbr()
    120 it(':cabbr does not cause a spurious CmdlineLeavePre', function()
    121  command('let g:a = 0')
    122  command('cabbr v v')
    123  command('command! -nargs=* Foo echo')
    124  command('au! CmdlineLeavePre * let g:a += 1')
    125  feed(':Foo v<CR>')
    126  eq(1, api.nvim_get_var('a'))
    127 end)