robin/laufey

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

Justin M. KeyesMerge #40865 from justinmk/fixcif907614088

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