robin/laufey

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

Justin M. KeyesMerge #41114 from epithet/default-ruler-as-expressiondab5fab948

master
18.5 KiB434 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 clear = n.clear
7local eq = t.eq
8local exec = n.exec
9local exec_lua = n.exec_lua
10local command = n.command
11local feed = n.feed
12local fn = n.fn
13
14-- oldtest: Test_window_cmd_ls0_split_scrolling()
15it('scrolling with laststatus=0 and :botright split', function()
16  clear('--cmd', 'set ruler')
17  local screen = Screen.new(40, 10)
18  exec([[
19    set laststatus=0
20    call setline(1, range(1, 100))
21    normal! G
22  ]])
23  command('botright split')
24  screen:expect([[
25    97                                      |
26    98                                      |
27    99                                      |
28    100                                     |
29    {2:[No Name] [+]         100,1          Bot}|
30    97                                      |
31    98                                      |
32    99                                      |
33    ^100                                     |
34                          100,1          Bot|
35  ]])
36end)
37
38describe('splitkeep', function()
39  local screen
40
41  before_each(function()
42    clear('--cmd', 'set splitkeep=screen')
43    screen = Screen.new()
44  end)
45
46  -- oldtest: Test_splitkeep_cursor()
47  it('does not adjust cursor in window that did not change size', function()
48    screen:try_resize(75, 8)
49    -- FIXME: bottom window is different without the "vsplit | close"
50    exec([[
51      vsplit | close
52      set scrolloff=5
53      set splitkeep=screen
54      autocmd CursorMoved * wincmd p | wincmd p
55      call setline(1, range(1, 200))
56      func CursorEqualize()
57        call cursor(100, 1)
58        wincmd =
59      endfunc
60      wincmd s
61      call CursorEqualize()
62    ]])
63
64    screen:expect([[
65      99                                                                         |
66      ^100                                                                        |
67      101                                                                        |
68      {3:[No Name] [+]                                                              }|
69      5                                                                          |
70      6                                                                          |
71      {2:[No Name] [+]                                                              }|
72                                                                                 |
73    ]])
74
75    feed('j')
76    screen:expect([[
77      100                                                                        |
78      ^101                                                                        |
79      102                                                                        |
80      {3:[No Name] [+]                                                              }|
81      5                                                                          |
82      6                                                                          |
83      {2:[No Name] [+]                                                              }|
84                                                                                 |
85    ]])
86
87    command('set scrolloff=0')
88    feed('G')
89    screen:expect([[
90      198                                                                        |
91      199                                                                        |
92      ^200                                                                        |
93      {3:[No Name] [+]                                                              }|
94      5                                                                          |
95      6                                                                          |
96      {2:[No Name] [+]                                                              }|
97                                                                                 |
98    ]])
99  end)
100
101  -- oldtest: Test_splitkeep_callback()
102  it('does not scroll when split in callback', function()
103    exec([[
104      call setline(1, range(&lines))
105      function C1(a, b, c)
106        split | wincmd p
107      endfunction
108      function C2(a, b, c)
109        close | split
110      endfunction
111    ]])
112    exec_lua([[
113      vim.api.nvim_set_keymap("n", "j", "", { callback = function()
114        vim.cmd("call jobstart([&sh, &shcf, 'true'], { 'on_exit': 'C1' })")
115      end
116    })]])
117    exec_lua([[
118      vim.api.nvim_set_keymap("n", "t", "", { callback = function()
119        vim.api.nvim_set_current_win(
120          vim.api.nvim_open_win(vim.api.nvim_create_buf(false, {}), false, {
121          width = 10,
122            relative = "cursor",
123            height = 4,
124            row = 0,
125            col = 0,
126          }))
127          vim.cmd("call jobstart([&sh, &shcf, 'true'], { 'term': v:true, 'on_exit': 'C2' })")
128      end
129    })]])
130    feed('j')
131    screen:expect([[
132      0                                                    |
133      1                                                    |
134      2                                                    |
135      3                                                    |
136      4                                                    |
137      5                                                    |
138      {2:[No Name] [+]                                        }|
139      ^7                                                    |
140      8                                                    |
141      9                                                    |
142      10                                                   |
143      11                                                   |
144      {3:[No Name] [+]                                        }|
145                                                           |
146    ]])
147    feed(':quit<CR>Ht')
148    screen:expect([[
149      ^0                                                    |
150      1                                                    |
151      2                                                    |
152      3                                                    |
153      4                                                    |
154      5                                                    |
155      {3:[No Name] [+]                                        }|
156      7                                                    |
157      8                                                    |
158      9                                                    |
159      10                                                   |
160      11                                                   |
161      {2:[No Name] [+]                                        }|
162      :quit                                                |
163    ]])
164    feed(':set sb<CR>:quit<CR>Gj')
165    screen:expect([[
166      1                                                    |
167      2                                                    |
168      3                                                    |
169      4                                                    |
170      ^5                                                    |
171      {3:[No Name] [+]                                        }|
172      7                                                    |
173      8                                                    |
174      9                                                    |
175      10                                                   |
176      11                                                   |
177      12                                                   |
178      {2:[No Name] [+]                                        }|
179      :quit                                                |
180    ]])
181    feed(':quit<CR>Gt')
182    screen:expect([[
183      1                                                    |
184      2                                                    |
185      3                                                    |
186      4                                                    |
187      5                                                    |
188      {2:[No Name] [+]                                        }|
189      7                                                    |
190      8                                                    |
191      9                                                    |
192      10                                                   |
193      11                                                   |
194      ^12                                                   |
195      {3:[No Name] [+]                                        }|
196      :quit                                                |
197    ]])
198  end)
199
200  -- oldtest: Test_splitkeep_fold()
201  it('does not scroll when window has closed folds', function()
202    exec([[
203      set commentstring=/*%s*/
204      set splitkeep=screen
205      set foldmethod=marker
206      set number
207      let line = 1
208      for n in range(1, &lines)
209        call setline(line, ['int FuncName() {/*{{{*/', 1, 2, 3, 4, 5, '}/*}}}*/',
210              \ 'after fold'])
211        let line += 8
212      endfor
213    ]])
214    feed('L:wincmd s<CR>')
215    screen:expect([[
216      {8:  1 }{13:+--  7 lines: int FuncName() {···················}|
217      {8:  8 }after fold                                       |
218      {8:  9 }{13:+--  7 lines: int FuncName() {···················}|
219      {8: 16 }after fold                                       |
220      {8: 17 }{13:+--  7 lines: int FuncName() {···················}|
221      {8: 24 }^after fold                                       |
222      {3:[No Name] [+]                                        }|
223      {8: 32 }after fold                                       |
224      {8: 33 }{13:+--  7 lines: int FuncName() {···················}|
225      {8: 40 }after fold                                       |
226      {8: 41 }{13:+--  7 lines: int FuncName() {···················}|
227      {8: 48 }after fold                                       |
228      {2:[No Name] [+]                                        }|
229      :wincmd s                                            |
230    ]])
231    feed(':quit<CR>')
232    screen:expect([[
233      {8:  1 }{13:+--  7 lines: int FuncName() {···················}|
234      {8:  8 }after fold                                       |
235      {8:  9 }{13:+--  7 lines: int FuncName() {···················}|
236      {8: 16 }after fold                                       |
237      {8: 17 }{13:+--  7 lines: int FuncName() {···················}|
238      {8: 24 }after fold                                       |
239      {8: 25 }{13:+--  7 lines: int FuncName() {···················}|
240      {8: 32 }after fold                                       |
241      {8: 33 }{13:+--  7 lines: int FuncName() {···················}|
242      {8: 40 }after fold                                       |
243      {8: 41 }{13:+--  7 lines: int FuncName() {···················}|
244      {8: 48 }after fold                                       |
245      {8: 49 }{13:^+--  7 lines: int FuncName() {···················}|
246      :quit                                                |
247    ]])
248    feed('H:below split<CR>')
249    screen:expect([[
250      {8:  1 }{13:+--  7 lines: int FuncName() {···················}|
251      {8:  8 }after fold                                       |
252      {8:  9 }{13:+--  7 lines: int FuncName() {···················}|
253      {8: 16 }after fold                                       |
254      {8: 17 }{13:+--  7 lines: int FuncName() {···················}|
255      {2:[No Name] [+]                                        }|
256      {8: 25 }{13:^+--  7 lines: int FuncName() {···················}|
257      {8: 32 }after fold                                       |
258      {8: 33 }{13:+--  7 lines: int FuncName() {···················}|
259      {8: 40 }after fold                                       |
260      {8: 41 }{13:+--  7 lines: int FuncName() {···················}|
261      {8: 48 }after fold                                       |
262      {3:[No Name] [+]                                        }|
263      :below split                                         |
264    ]])
265    feed(':wincmd k<CR>:quit<CR>')
266    screen:expect([[
267      {8:  1 }{13:+--  7 lines: int FuncName() {···················}|
268      {8:  8 }after fold                                       |
269      {8:  9 }{13:+--  7 lines: int FuncName() {···················}|
270      {8: 16 }after fold                                       |
271      {8: 17 }{13:+--  7 lines: int FuncName() {···················}|
272      {8: 24 }after fold                                       |
273      {8: 25 }{13:^+--  7 lines: int FuncName() {···················}|
274      {8: 32 }after fold                                       |
275      {8: 33 }{13:+--  7 lines: int FuncName() {···················}|
276      {8: 40 }after fold                                       |
277      {8: 41 }{13:+--  7 lines: int FuncName() {···················}|
278      {8: 48 }after fold                                       |
279      {8: 49 }{13:+--  7 lines: int FuncName() {···················}|
280      :quit                                                |
281    ]])
282  end)
283
284  -- oldtest: Test_splitkeep_status()
285  it('does not scroll when split in callback', function()
286    exec([[
287      call setline(1, ['a', 'b', 'c'])
288      set nomodified
289      set splitkeep=screen
290      let win = winnr()
291      wincmd s
292      wincmd j
293    ]])
294    feed(':call win_move_statusline(win, 1)<CR>')
295    screen:expect([[
296      a                                                    |
297      b                                                    |
298      c                                                    |
299      {1:~                                                    }|*4
300      {2:[No Name]                                            }|
301      ^a                                                    |
302      b                                                    |
303      c                                                    |
304      {1:~                                                    }|
305      {3:[No Name]                                            }|
306      :call win_move_statusline(win, 1)                    |
307    ]])
308  end)
309
310  -- oldtest: Test_splitkeep_skipcol()
311  it('skipcol is not reset unnecessarily and is copied to new window', function()
312    screen:try_resize(40, 12)
313    exec([[
314      set splitkeep=topline smoothscroll splitbelow scrolloff=0
315      call setline(1, 'with lots of text in one line '->repeat(6))
316      norm 2
317      wincmd s
318    ]])
319    screen:expect([[
320      {1:<<<}e line with lots of text in one line |
321      with lots of text in one line with lots |
322      of text in one line                     |
323      {1:~                                       }|
324      {2:[No Name] [+]                           }|
325      {1:<<<}e line with lots of text in one line |
326      ^with lots of text in one line with lots |
327      of text in one line                     |
328      {1:~                                       }|*2
329      {3:[No Name] [+]                           }|
330                                              |
331    ]])
332  end)
333
334  -- oldtest: Test_splitkeep_line()
335  it("no scrolling with 'splitkeep' and line()", function()
336    screen:try_resize(40, 6)
337    exec([[
338      set splitkeep=screen nosplitbelow
339      autocmd WinResized * call line('w0', 1000)
340      call setline(1, range(1000))
341    ]])
342    screen:expect([[
343      ^0                                       |
344      1                                       |
345      2                                       |
346      3                                       |
347      4                                       |
348                                              |
349    ]])
350    feed(':wincmd s<CR>')
351    screen:expect([[
352      ^0                                       |
353      1                                       |
354      {3:[No Name] [+]                           }|
355      3                                       |
356      {2:[No Name] [+]                           }|
357      :wincmd s                               |
358    ]])
359  end)
360end)
361
362-- oldtest: Test_winfixsize_vsep_statusline()
363it("'winfixwidth/height' does not leave stray vseps/statuslines", function()
364  clear()
365  local screen = Screen.new(75, 8)
366  exec([[
367    set noequalalways splitbelow splitright
368    vsplit
369    setlocal winfixwidth
370    vsplit
371  ]])
372  eq(16, fn.winwidth(1))
373  eq(37, fn.winwidth(2))
374  eq(20, fn.winwidth(3))
375
376  command('quit')
377  screen:expect([[
378    ^                                    │                                      |
379    {1:~                                   }│{1:~                                     }|*5
380    {3:[No Name]                            }{2:[No Name]                             }|
381                                                                               |
382  ]])
383  -- Checks w_view_width in Nvim; especially important as the screen test may still pass if only
384  -- w_width changed to make room for the vsep.
385  eq(36, fn.winwidth(1))
386  eq(38, fn.winwidth(2))
387
388  exec([[
389    set laststatus=0
390    only
391    split
392    set winfixheight
393    split
394  ]])
395  eq(1, fn.winheight(1))
396  eq(3, fn.winheight(2))
397  eq(1, fn.winheight(3))
398
399  command('quit')
400  screen:expect([[
401    ^                                                                           |
402    {1:~                                                                          }|
403    {3:[No Name]                                                                  }|
404                                                                               |
405    {1:~                                                                          }|*3
406                                                                               |
407  ]])
408  eq(2, fn.winheight(1))
409  eq(4, fn.winheight(2))
410end)
411
412-- oldtest: Test_resize_from_another_tabpage()
413it('resizing window from another tabpage', function()
414  clear()
415  local screen = Screen.new(75, 8)
416  screen:add_extra_attr_ids({
417    [100] = { foreground = Screen.colors.Magenta1, bold = true },
418  })
419  exec([[
420    set laststatus=2
421    vnew
422    let w = win_getid()
423    tabnew
424    call win_execute(w, 'vertical resize 20')
425    tabprev
426  ]])
427  screen:expect([[
428    {5: }{100:2}{5: [No Name] }{24: [No Name] }{2:                                                  }{24:X}|
429    ^                    │                                                      |
430    {1:~                   }│{1:~                                                     }|*4
431    {3:[No Name]            }{2:[No Name]                                             }|
432                                                                               |
433  ]])
434end)