robin/laufey

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

Justin M. KeyesMerge #40865 from justinmk/fixcif907614088

master
7.2 KiB255 linesraw
1local t = require('test.testutil')
2local n = require('test.functional.testnvim')()
3local Screen = require('test.functional.ui.screen')
4
5local describe, it, before_each = t.describe, t.it, t.before_each
6local eq = t.eq
7local exec = n.exec
8local exec_capture = n.exec_capture
9local feed = n.feed
10local api = n.api
11local clear = n.clear
12local command = n.command
13local expect = n.expect
14local insert = n.insert
15local eval = n.eval
16
17describe(':*map', function()
18  before_each(clear)
19
20  it('are not affected by &isident', function()
21    api.nvim_set_var('counter', 0)
22    command('nnoremap <C-x> :let counter+=1<CR>')
23    api.nvim_set_option_value('isident', ('%u'):format(('>'):byte()), {})
24    command('nnoremap <C-y> :let counter+=1<CR>')
25    -- &isident used to disable keycode parsing here as well
26    feed('\24\25<C-x><C-y>')
27    eq(4, api.nvim_get_var('counter'))
28  end)
29
30  it(':imap <M-">', function()
31    command('imap <M-"> foo')
32    feed('i-<M-">-')
33    expect('-foo-')
34  end)
35
36  it('shows <Nop> as mapping rhs', function()
37    command('nmap asdf <Nop>')
38    eq(
39      [[
40
41n  asdf          <Nop>]],
42      exec_capture('nmap asdf')
43    )
44  end)
45
46  it('mappings with description can be filtered', function()
47    api.nvim_set_keymap('n', 'asdf1', 'qwert', { desc = 'do the one thing' })
48    api.nvim_set_keymap('n', 'asdf2', 'qwert', { desc = 'doesnot really do anything' })
49    api.nvim_set_keymap('n', 'asdf3', 'qwert', { desc = 'do the other thing' })
50    eq(
51      [[
52
53n  asdf3         qwert
54                 do the other thing
55n  asdf1         qwert
56                 do the one thing]],
57      exec_capture('filter the nmap')
58    )
59  end)
60
61  it('<Plug> mappings ignore nore', function()
62    command('let x = 0')
63    eq(0, api.nvim_eval('x'))
64    command [[
65      nnoremap <Plug>(Increase_x) <cmd>let x+=1<cr>
66      nmap increase_x_remap <Plug>(Increase_x)
67      nnoremap increase_x_noremap <Plug>(Increase_x)
68    ]]
69    feed('increase_x_remap')
70    eq(1, api.nvim_eval('x'))
71    feed('increase_x_noremap')
72    eq(2, api.nvim_eval('x'))
73  end)
74
75  it("Doesn't auto ignore nore for keys before or after <Plug> mapping", function()
76    command('let x = 0')
77    eq(0, api.nvim_eval('x'))
78    command [[
79      nnoremap x <nop>
80      nnoremap <Plug>(Increase_x) <cmd>let x+=1<cr>
81      nmap increase_x_remap x<Plug>(Increase_x)x
82      nnoremap increase_x_noremap x<Plug>(Increase_x)x
83    ]]
84    insert('Some text')
85    eq('Some text', eval("getline('.')"))
86
87    feed('increase_x_remap')
88    eq(1, api.nvim_eval('x'))
89    eq('Some text', eval("getline('.')"))
90    feed('increase_x_noremap')
91    eq(2, api.nvim_eval('x'))
92    eq('Some te', eval("getline('.')"))
93  end)
94
95  it(':unmap with rhs works when lhs is in another bucket #21530', function()
96    command('map F <Plug>Foo')
97    command('unmap <Plug>Foo')
98    eq('\nNo mapping found', exec_capture('map F'))
99  end)
100end)
101
102describe('Screen', function()
103  local screen
104  before_each(function()
105    clear()
106    screen = Screen.new(20, 5)
107  end)
108
109  it('cursor is restored after :map <expr> which calls input()', function()
110    command('map <expr> x input("> ")')
111    screen:expect([[
112      ^                    |
113      {1:~                   }|*3
114                          |
115    ]])
116    feed('x')
117    screen:expect([[
118                          |
119      {1:~                   }|*3
120      > ^                  |
121    ]])
122    feed('\n')
123    screen:expect([[
124      ^                    |
125      {1:~                   }|*3
126      >                   |
127    ]])
128  end)
129
130  it('cursor is restored after :imap <expr> which calls input()', function()
131    command('imap <expr> x input("> ")')
132    feed('i')
133    screen:expect([[
134      ^                    |
135      {1:~                   }|*3
136      {5:-- INSERT --}        |
137    ]])
138    feed('x')
139    screen:expect([[
140                          |
141      {1:~                   }|*3
142      > ^                  |
143    ]])
144    feed('\n')
145    screen:expect([[
146      ^                    |
147      {1:~                   }|*3
148      {5:-- INSERT --}        |
149    ]])
150  end)
151
152  it('cursor position does not move after empty-string :cmap <expr> #19046', function()
153    command([[cnoremap <expr> <F2> '']])
154    feed(':<F2>')
155    screen:expect([[
156                          |
157      {1:~                   }|*3
158      :^                   |
159    ]])
160  end)
161
162  -- oldtest: Test_expr_map_restore_cursor()
163  it('cursor is restored after :map <expr> which redraws statusline vim-patch:8.1.2336', function()
164    exec([[
165      call setline(1, ['one', 'two', 'three'])
166      2
167      set ls=2
168      hi! link StatusLine ErrorMsg
169      noremap <expr> <C-B> Func()
170      func Func()
171          let g:on = !get(g:, 'on', 0)
172          redraws
173          return ''
174      endfunc
175      func Status()
176          return get(g:, 'on', 0) ? '[on]' : ''
177      endfunc
178      set stl=%{Status()}
179    ]])
180    feed('<C-B>')
181    screen:expect([[
182      one                 |
183      ^two                 |
184      three               |
185      {9:[on]                }|
186                          |
187    ]])
188  end)
189
190  it('error in :nmap <expr> does not mess up display vim-patch:4.2.4338', function()
191    screen:try_resize(40, 5)
192    command('nmap <expr> <F2> execute("throw 42")')
193    feed('<F2>')
194    screen:expect([[
195                                              |
196      {3:                                        }|
197      {9:Error in :}                              |
198      {9:E605: Exception not caught: 42}          |
199      {6:Press ENTER or type command to continue}^ |
200    ]])
201    feed('<CR>')
202    screen:expect([[
203      ^                                        |
204      {1:~                                       }|*3
205                                              |
206    ]])
207  end)
208
209  it('error in :cmap <expr> handled correctly vim-patch:4.2.4338', function()
210    screen:try_resize(40, 5)
211    command('cmap <expr> <F2> execute("throw 42")')
212    feed(':echo "foo')
213    screen:expect([[
214                                              |
215      {1:~                                       }|*3
216      :echo "foo^                              |
217    ]])
218    feed('<F2>')
219    screen:expect([[
220      {3:                                        }|
221      :echo "foo                              |
222      {9:Error in :}                              |
223      {9:E605: Exception not caught: 42}          |
224      :echo "foo^                              |
225    ]])
226    feed('"')
227    screen:expect([[
228      {3:                                        }|
229      :echo "foo                              |
230      {9:Error in :}                              |
231      {9:E605: Exception not caught: 42}          |
232      :echo "foo"^                             |
233    ]])
234    feed('\n')
235    screen:expect([[
236      :echo "foo                              |
237      {9:Error in :}                              |
238      {9:E605: Exception not caught: 42}          |
239      foo                                     |
240      {6:Press ENTER or type command to continue}^ |
241    ]])
242  end)
243
244  -- oldtest: Test_map_listing()
245  it('listing mappings clears command line vim-patch:8.2.4401', function()
246    screen:try_resize(40, 5)
247    command('nmap a b')
248    feed(':                      nmap a<CR>')
249    screen:expect([[
250      ^                                        |
251      {1:~                                       }|*3
252      n  a             b                      |
253    ]])
254  end)
255end)