robin/laufey

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

Justin M. KeyesMerge #40865 from justinmk/fixcif907614088

master
11.2 KiB348 linesraw
1--
2-- Tests for default autocmds, mappings, commands, and menus.
3--
4-- See options/defaults_spec.lua for default options and environment decisions.
5--
6
7local t = require('test.testutil')
8local n = require('test.functional.testnvim')()
9local Screen = require('test.functional.ui.screen')
10
11local describe, it = t.describe, t.it
12describe('default', function()
13  describe('autocommands', function()
14    it('nvim.terminal.TermClose closes terminal with default shell on success', function()
15      n.clear()
16      n.api.nvim_set_option_value('shell', n.testprg('shell-test'), {})
17      n.command('set shellcmdflag=EXIT shellredir= shellpipe= shellquote= shellxquote=')
18
19      -- Should not block other events
20      n.command('let g:n=0')
21      n.command('au BufEnter * let g:n = g:n + 1')
22
23      t.eq(1, n.exec_lua('vim.cmd.terminal(); return vim.g.n'))
24
25      t.retry(nil, 1000, function()
26        t.neq('terminal', n.api.nvim_get_option_value('buftype', { buf = 0 }))
27        t.eq(2, n.eval('g:n'))
28      end)
29    end)
30  end)
31
32  describe('popupmenu', function()
33    it('can be disabled by user', function()
34      n.clear {
35        args = { '+autocmd! nvim.popupmenu', '+aunmenu PopUp' },
36      }
37      local screen = Screen.new(40, 8)
38      n.insert([[
39        1 line 1
40        2 https://example.com
41        3 line 3
42        4 line 4]])
43
44      n.api.nvim_input_mouse('right', 'press', '', 0, 1, 4)
45      screen:expect({
46        grid = [[
47          1 line 1                                |
48          2 ht^tps://example.com                   |
49          3 line 3                                |
50          4 line 4                                |
51          {1:~                                       }|*3
52                                                  |
53        ]],
54      })
55    end)
56
57    it('right-click on URL shows "Open in web browser"', function()
58      n.clear()
59      local screen = Screen.new(40, 8)
60      n.insert([[
61        1 line 1
62        2 https://example.com
63        3 line 3
64        4 line 4]])
65
66      n.api.nvim_input_mouse('right', 'press', '', 0, 3, 4)
67      screen:expect({
68        grid = [[
69          1 line 1                                |
70          2 https://example.com                   |
71          3 line 3                                |
72          4 li^ne 4                                |
73          {1:~  }{4: Inspect              }{1:               }|
74          {1:~  }{4:                      }{1:               }|
75          {1:~  }{4: Paste                }{1:               }|
76             {4: Select All           }               |
77        ]],
78      })
79
80      n.api.nvim_input_mouse('right', 'press', '', 0, 1, 4)
81      screen:expect({
82        grid = [[
83          1 line 1                                |
84          2 ht^tps://example.com                   |
85          3 l{4: Open in web browser  }               |
86          4 l{4: Inspect              }               |
87          {1:~  }{4:                      }{1:               }|
88          {1:~  }{4: Paste                }{1:               }|
89          {1:~  }{4: Select All           }{1:               }|
90             {4:                      }               |
91        ]],
92      })
93    end)
94  end)
95
96  describe('key mappings', function()
97    describe('Visual mode search mappings', function()
98      it('handle various chars properly', function()
99        n.clear({ args_rm = { '--cmd' } })
100        local screen = Screen.new(60, 8)
101        screen:set_default_attr_ids({
102          [1] = { foreground = Screen.colors.NvimDarkGray4 },
103          [2] = {
104            foreground = Screen.colors.NvimLightGray2,
105            background = Screen.colors.NvimDarkGray4,
106          },
107          [3] = {
108            foreground = Screen.colors.NvimLightGrey1,
109            background = Screen.colors.NvimDarkYellow,
110          },
111          [4] = {
112            foreground = Screen.colors.NvimDarkGrey1,
113            background = Screen.colors.NvimLightYellow,
114          },
115        })
116        n.api.nvim_buf_set_lines(0, 0, -1, true, {
117          [[testing <CR> /?\!1]],
118          [[testing <CR> /?\!2]],
119          [[testing <CR> /?\!3]],
120          [[testing <CR> /?\!4]],
121        })
122        n.feed('gg0vf!')
123        n.poke_eventloop()
124        n.feed('*')
125        screen:expect([[
126          {3:testing <CR> /?\!}1                                          |
127          {4:^testing <CR> /?\!}2                                          |
128          {3:testing <CR> /?\!}3                                          |
129          {3:testing <CR> /?\!}4                                          |
130          {1:~                                                           }|*2
131          {2:[No Name] [+]                             2,1            All}|
132          /\Vtesting <CR> /?\\!                     [2/4]             |
133        ]])
134        n.feed('n')
135        screen:expect([[
136          {3:testing <CR> /?\!}1                                          |
137          {3:testing <CR> /?\!}2                                          |
138          {4:^testing <CR> /?\!}3                                          |
139          {3:testing <CR> /?\!}4                                          |
140          {1:~                                                           }|*2
141          {2:[No Name] [+]                             3,1            All}|
142          /\Vtesting <CR> /?\\!                     [3/4]             |
143        ]])
144        n.feed('G0vf!')
145        n.poke_eventloop()
146        n.feed('#')
147        screen:expect([[
148          {3:testing <CR> /?\!}1                                          |
149          {3:testing <CR> /?\!}2                                          |
150          {4:^testing <CR> /?\!}3                                          |
151          {3:testing <CR> /?\!}4                                          |
152          {1:~                                                           }|*2
153          {2:[No Name] [+]                             3,1            All}|
154          ?\Vtesting <CR> /?\\!                     [3/4]             |
155        ]])
156        n.feed('n')
157        screen:expect([[
158          {3:testing <CR> /?\!}1                                          |
159          {4:^testing <CR> /?\!}2                                          |
160          {3:testing <CR> /?\!}3                                          |
161          {3:testing <CR> /?\!}4                                          |
162          {1:~                                                           }|*2
163          {2:[No Name] [+]                             2,1            All}|
164          ?\Vtesting <CR> /?\\!                     [2/4]             |
165        ]])
166      end)
167    end)
168
169    describe('unimpaired-style mappings', function()
170      it('show the command output when successful', function()
171        n.clear({ args_rm = { '--cmd' } })
172        local screen = Screen.new(40, 8)
173        n.fn.setqflist({
174          { filename = 'file1', text = 'item1' },
175          { filename = 'file2', text = 'item2' },
176        })
177
178        n.feed(']q')
179
180        screen:set_default_attr_ids({
181          [1] = { foreground = Screen.colors.NvimDarkGrey4 },
182          [2] = {
183            background = Screen.colors.NvimDarkGrey4,
184            foreground = Screen.colors.NvimLightGray2,
185          },
186        })
187        screen:expect({
188          grid = [[
189            ^                                        |
190            {1:~                                       }|*5
191            {2:file2                 0,0-1          All}|
192            (2 of 2): item2                         |
193          ]],
194        })
195      end)
196
197      it('do not show a full stack trace when unsuccessful #30625', function()
198        n.clear({ args_rm = { '--cmd' } })
199        local screen = Screen.new(40, 8)
200        screen:set_default_attr_ids({
201          [1] = { foreground = Screen.colors.NvimDarkGray4 },
202          [2] = {
203            background = Screen.colors.NvimDarkGray4,
204            foreground = Screen.colors.NvimLightGrey2,
205          },
206          [3] = { foreground = Screen.colors.NvimLightRed },
207          [4] = { foreground = Screen.colors.NvimLightCyan },
208        })
209
210        n.feed('[a')
211        screen:expect({
212          grid = [[
213                                                    |
214            {1:~                                       }|*4
215            {2:                                        }|
216            {3:E163: There is only one file to edit}    |
217            {4:Press ENTER or type command to continue}^ |
218          ]],
219        })
220
221        n.feed('[q')
222        screen:expect({
223          grid = [[
224            ^                                        |
225            {1:~                                       }|*5
226            {2:[No Name]             0,0-1          All}|
227            {3:E42: No Errors}                          |
228          ]],
229        })
230
231        n.feed('[l')
232        screen:expect({
233          grid = [[
234            ^                                        |
235            {1:~                                       }|*5
236            {2:[No Name]             0,0-1          All}|
237            {3:E776: No location list}                  |
238          ]],
239        })
240
241        n.feed('[t')
242        screen:expect({
243          grid = [[
244            ^                                        |
245            {1:~                                       }|*5
246            {2:[No Name]             0,0-1          All}|
247            {3:E73: Tag stack empty}                    |
248          ]],
249        })
250      end)
251
252      describe('[<Space>', function()
253        it('adds an empty line above the current line', function()
254          n.clear({ args_rm = { '--cmd' } })
255          n.insert([[first line]])
256          n.feed('[<Space>')
257          n.expect([[
258
259          first line]])
260        end)
261
262        it('works with a count', function()
263          n.clear({ args_rm = { '--cmd' } })
264          n.insert([[first line]])
265          n.feed('5[<Space>')
266          n.expect([[
267
268
269
270
271
272          first line]])
273        end)
274
275        it('supports dot repetition', function()
276          n.clear({ args_rm = { '--cmd' } })
277          n.insert([[first line]])
278          n.feed('[<Space>')
279          n.feed('.')
280          n.expect([[
281
282
283          first line]])
284        end)
285
286        it('supports dot repetition and a count', function()
287          n.clear({ args_rm = { '--cmd' } })
288          n.insert([[first line]])
289          n.feed('[<Space>')
290          n.feed('3.')
291          n.expect([[
292
293
294
295
296          first line]])
297        end)
298      end)
299
300      describe(']<Space>', function()
301        it('adds an empty line below the current line', function()
302          n.clear({ args_rm = { '--cmd' } })
303          n.insert([[first line]])
304          n.feed(']<Space>')
305          n.expect([[
306          first line
307          ]])
308        end)
309
310        it('works with a count', function()
311          n.clear({ args_rm = { '--cmd' } })
312          n.insert([[first line]])
313          n.feed('5]<Space>')
314          n.expect([[
315          first line
316
317
318
319
320          ]])
321        end)
322
323        it('supports dot repetition', function()
324          n.clear({ args_rm = { '--cmd' } })
325          n.insert([[first line]])
326          n.feed(']<Space>')
327          n.feed('.')
328          n.expect([[
329          first line
330
331          ]])
332        end)
333
334        it('supports dot repetition and a count', function()
335          n.clear({ args_rm = { '--cmd' } })
336          n.insert([[first line]])
337          n.feed(']<Space>')
338          n.feed('2.')
339          n.expect([[
340          first line
341
342
343          ]])
344        end)
345      end)
346    end)
347  end)
348end)