robin/laufey

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

robinmerge: 8c77b5be50c50ab119

master
15.3 KiB378 linesraw
1-- Tests for (protocol-driven) ui2, intended to replace the legacy message grid UI.
2
3local t = require('test.testutil')
4local n = require('test.functional.testnvim')()
5local Screen = require('test.functional.ui.screen')
6
7local describe, it, before_each = t.describe, t.it, t.before_each
8local clear, exec, exec_lua, feed = n.clear, n.exec, n.exec_lua, n.feed
9
10describe('cmdline2', function()
11  local screen
12  before_each(function()
13    clear()
14    screen = Screen.new()
15    screen:add_extra_attr_ids({
16      [100] = { foreground = Screen.colors.Magenta1, bold = true },
17      [101] = { background = Screen.colors.Yellow, foreground = Screen.colors.Grey0 },
18      [102] = { background = Screen.colors.Cyan1, foreground = Screen.colors.SlateBlue },
19    })
20    exec_lua(function()
21      require('vim._core.ui2').enable({})
22    end)
23  end)
24
25  it("no crash for invalid grid after 'cmdheight' OptionSet", function()
26    exec('tabnew | tabprev')
27    feed(':set ch=0')
28    screen:expect([[
29      {5: [No Name] }{24: [No Name] }{2:                              }{24:X}|
30                                                           |
31      {1:~                                                    }|*11
32      {16::}{15:set} {16:ch}{15:=}0^                                            |
33    ]])
34    feed('<CR>')
35    exec('tabnext')
36    screen:expect([[
37      {24: [No Name] }{5: [No Name] }{2:                              }{24:X}|
38      ^                                                     |
39      {1:~                                                    }|*11
40      {16::}{15:set} {16:ch}{15:=}0                                            |
41    ]])
42    exec('tabnext')
43    screen:expect([[
44      {5: [No Name] }{24: [No Name] }{2:                              }{24:X}|
45      ^                                                     |
46      {1:~                                                    }|*12
47    ]])
48    n.assert_alive()
49  end)
50
51  it("redraw does not clear 'incsearch' highlight with conceal", function()
52    exec('call setline(1, ["foo", "foobar"]) | set conceallevel=1 concealcursor=c')
53    feed('/foo')
54    screen:expect([[
55      {10:foo}                                                  |
56      {2:foo}bar                                               |
57      {1:~                                                    }|*11
58      /foo^                                                 |
59    ]])
60  end)
61
62  it('block mode', function()
63    feed(':if 1<CR>')
64    screen:expect([[
65                                                           |
66      {1:~                                                    }|*11
67      {16::}{15:if} {26:1}                                                |
68      {16::}  ^                                                  |
69    ]])
70    feed('echo "foo"')
71    screen:expect([[
72                                                           |
73      {1:~                                                    }|*11
74      {16::}{15:if} {26:1}                                                |
75      {16::}  {15:echo} {26:"foo"}^                                        |
76    ]])
77    feed('<CR>')
78    screen:expect([[
79                                                           |
80      {1:~                                                    }|*9
81      {16::}{15:if} {26:1}                                                |
82      {16::}  {15:echo} {26:"foo"}                                        |
83      foo                                                  |
84      {16::}  ^                                                  |
85    ]])
86    feed([[echo input("foo\nbar:")<CR>]])
87    screen:expect([[
88                                                           |
89      {1:~                                                    }|*7
90      {16::}{15:if} {26:1}                                                |
91      {16::}  {15:echo} {26:"foo"}                                        |
92      foo                                                  |
93      {16::}  {15:echo} {25:input}{16:(}{26:"foo\nbar:"}{16:)}                           |
94      foo                                                  |
95      bar:^                                                 |
96    ]])
97    feed('baz')
98    screen:expect([[
99                                                           |
100      {1:~                                                    }|*7
101      {16::}{15:if} {26:1}                                                |
102      {16::}  {15:echo} {26:"foo"}                                        |
103      foo                                                  |
104      {16::}  {15:echo} {25:input}{16:(}{26:"foo\nbar:"}{16:)}                           |
105      foo                                                  |
106      bar:baz^                                              |
107    ]])
108    feed('<CR>')
109    screen:expect([[
110                                                           |
111      {1:~                                                    }|*5
112      {16::}{15:if} {26:1}                                                |
113      {16::}  {15:echo} {26:"foo"}                                        |
114      foo                                                  |
115      {16::}  {15:echo} {25:input}{16:(}{26:"foo\nbar:"}{16:)}                           |
116      foo                                                  |
117      bar:baz                                              |
118      baz                                                  |
119      {16::}  ^                                                  |
120    ]])
121    feed('endif')
122    screen:expect([[
123                                                           |
124      {1:~                                                    }|*5
125      {16::}{15:if} {26:1}                                                |
126      {16::}  {15:echo} {26:"foo"}                                        |
127      foo                                                  |
128      {16::}  {15:echo} {25:input}{16:(}{26:"foo\nbar:"}{16:)}                           |
129      foo                                                  |
130      bar:baz                                              |
131      baz                                                  |
132      {16::}  {15:endif}^                                             |
133    ]])
134    feed('<CR>')
135    screen:expect([[
136      ^                                                     |
137      {1:~                                                    }|*12
138                                                           |
139    ]])
140  end)
141
142  it('handles empty prompt', function()
143    feed(":call input('')<CR>")
144    screen:expect([[
145                                                           |
146      {1:~                                                    }|*12
147      ^                                                     |
148    ]])
149    -- Message moved to dialog with empty prompt
150    feed("<CR>:echo 'foo' | call input('')<CR>")
151    screen:expect([[
152                                                           |
153      {1:~                                                    }|*10
154      {3:                                                     }|
155      foo                                                  |
156      ^                                                     |
157    ]])
158  end)
159
160  it('highlights after deleting buffer', function()
161    feed(':sil %bw!<CR>:call foo()')
162    screen:expect([[
163                                                           |
164      {1:~                                                    }|*12
165      {16::}{15:call} {25:foo}{16:()}^                                          |
166    ]])
167  end)
168
169  it('can change cmdline buffer during textlock', function()
170    exec([[
171      func Foo(a, b)
172        redrawstatus!
173      endfunc
174      set wildoptions=pum findfunc=Foo wildmode=noselect:lastused,full
175      au CmdlineChanged * call wildtrigger()
176    ]])
177    feed(':find ')
178    screen:expect([[
179                                                           |
180      {1:~                                                    }|*12
181      {16::}{15:find} ^                                               |
182    ]])
183    t.eq("E1514: 'findfunc' did not return a List type", n.eval('v:errmsg'))
184  end)
185
186  it('substitution match, empty message does not clear active cmdline', function()
187    exec('call setline(1, "foo")')
188    feed(':s/f')
189    screen:expect([[
190      {10:f}oo                                                  |
191      {1:~                                                    }|*12
192      {16::}{15:s}{16:/f^ }                                                |
193    ]])
194    feed('<Esc>:foo')
195    screen:expect([[
196      foo                                                  |
197      {1:~                                                    }|*12
198      {16::}{15:foo}^                                                 |
199    ]])
200    exec('echo')
201    screen:expect_unchanged(true)
202  end)
203
204  it('keeps the confirmation match highlighted with nohlsearch #41039', function()
205    exec('call setline(1, "test test") | set nohlsearch')
206    feed('/te<CR>')
207    screen:expect([[
208      test ^test                                            |
209      {1:~                                                    }|*12
210      /te                                                  |
211    ]])
212
213    feed(':%s/te/t/gc<CR>')
214    screen:expect([[
215      {2:te}st test                                            |
216      {1:~                                                    }|*11
217      {6:replace with t? (y)es/(n)o/(a)ll/(q)uit/(l)ast/scroll}|
218      {6: up(^E)/down(^Y)}^                                     |
219    ]])
220  end)
221
222  it('dialog position is adjusted for toggled non-pum wildmenu', function()
223    exec([[
224      set wildmode=list:full,full wildoptions-=pum
225      func Foo()
226      endf
227      func Fooo()
228      endf
229    ]])
230    feed(':call Fo<C-Z>')
231    screen:expect([[
232                                                           |
233      {1:~                                                    }|*8
234      {3:                                                     }|
235      Foo()   Fooo()                                       |
236                                                           |
237      {101:Foo()}{3:  Fooo()                                        }|
238      {16::}{15:call} {25:Foo}{16:()}^                                          |
239    ]])
240    feed('<BS><BS>')
241    exec('set wildoptions+=pum laststatus=2')
242    screen:expect([[
243                                                           |
244      {1:~                                                    }|*9
245      {3:                                                     }|
246      Foo()   Fooo()                                       |
247                                                           |
248      {16::}{15:call} Foo^                                            |
249    ]])
250    feed('<C-Z>')
251    screen:expect([[
252                                                           |
253      {1:~                                                    }|*9
254      {3:                                                     }|
255      Foo(){12: Foo()          }                                |
256           {4: Fooo()         }                                |
257      {16::}{15:call} {25:Foo}{16:()}^                                          |
258    ]])
259  end)
260
261  it('updated after setcmdline() #38764', function()
262    -- Also check that command-preview is updated.
263    exec('call setline(1, "foo")')
264    feed(':%s/foo')
265    screen:expect([[
266      {10:foo}                                                  |
267      {1:~                                                    }|*12
268      {16::}%{15:s}{16:/foo^ }                                             |
269    ]])
270    exec_lua(function()
271      _G.events = {}
272      vim.api.nvim_create_autocmd({ 'CmdlineChanged', 'CursorMovedC' }, {
273        callback = function(ev)
274          _G.events[ev.event] = (_G.events[ev.event] or 0) + 1
275        end,
276      })
277    end)
278    exec('call setcmdline("%s/fo")')
279    screen:expect([[
280      {10:fo}o                                                  |
281      {1:~                                                    }|*12
282      {16::}%{15:s}{16:/fo^ }                                              |
283    ]])
284    t.eq({ CmdlineChanged = 1, CursorMovedC = 1 }, exec_lua('return _G.events'))
285  end)
286
287  it("no 'incsearch' recursion with 'verbose' regex message", function()
288    exec('set verbose=1')
289    feed([[:%s/.\{//}]])
290    screen:expect([[
291                                                           |
292      {1:~                                                    }|*9
293      {3:                                                     }|
294      Switching to backtracking RE engine for pattern: .\{ |*2
295      {16::}%{15:s}{16:/.\{//}^ }                                          |
296    ]])
297  end)
298
299  it('is empty after backspace', function()
300    feed(':')
301    screen:expect([[
302                                                           |
303      {1:~                                                    }|*12
304      {16::}^                                                    |
305    ]])
306
307    feed('<BS>')
308    screen:expect([[
309      ^                                                     |
310      {1:~                                                    }|*12
311                                                           |
312    ]])
313  end)
314
315  it('matchparen highlights', function()
316    exec('source $VIMRUNTIME/plugin/matchparen.lua')
317    feed(':call foo(bar())')
318    screen:expect([[
319                                                           |
320      {1:~                                                    }|*12
321      {16::}{15:call} {25:foo}{102:(}{25:bar}{16:()}{102:)}^                                     |
322    ]])
323    feed('<Left>')
324    screen:expect([[
325                                                           |
326      {1:~                                                    }|*12
327      {16::}{15:call} {25:foo}{16:(}{25:bar}{102:()}{16:^)}                                     |
328    ]])
329    feed('<Right><BS><BS>')
330    screen:expect([[
331                                                           |
332      {1:~                                                    }|*12
333      {16::}{15:call} {25:foo}{16:(}{25:bar}{16:(}^                                       |
334    ]])
335  end)
336
337  it("doesn't interfere with :$q", function()
338    exec('split b')
339    exec('wincmd J')
340    exec('wincmd p')
341    exec('$q') -- this would close a ui2 window, not the second visible window
342
343    local nwins = vim.fn.winnr('$')
344    assert(nwins == 1)
345  end)
346end)
347
348describe('cmdline2', function()
349  it('resizing during startup shows confirm prompt #36439', function()
350    clear({
351      args = {
352        '--clean',
353        '+lua require("vim._core.ui2").enable({})',
354        "+call feedkeys(':')",
355      },
356    })
357    local screen = Screen.new()
358    feed('call confirm("Ok?")<CR>')
359    screen:try_resize(screen._width + 1, screen._height)
360    screen:expect([[
361                                                            |*10
362      {3:                                                      }|
363                                                            |
364      {6:Ok?}                                                   |
365      {6:[O]k: }^                                                |
366    ]])
367    -- And resizing the next event loop iteration also works.
368    feed('k')
369    screen:try_resize(screen._width, screen._height + 1)
370    screen:expect([[
371                                                            |*11
372      {3:                                                      }|
373                                                            |
374      {6:Ok?}                                                   |
375      {6:[O]k: }^                                                |
376    ]])
377  end)
378end)