robin/laufey

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

robinmerge: 1dc9728daa1d8a2702

master
33.0 KiB731 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 command = n.command
8local insert = n.insert
9local api = n.api
10local eq = t.eq
11local poke_eventloop = n.poke_eventloop
12local feed = n.feed
13local fn = n.fn
14local pcall_err = t.pcall_err
15
16describe('winbar', function()
17  local screen
18
19  before_each(function()
20    clear()
21    screen = Screen.new(60, 13)
22    screen:set_default_attr_ids({
23      [1] = { bold = true },
24      [2] = { reverse = true },
25      [3] = { bold = true, foreground = Screen.colors.Blue },
26      [4] = { bold = true, reverse = true },
27      [5] = { bold = true, foreground = Screen.colors.Red },
28      [6] = { foreground = Screen.colors.Blue },
29      [7] = { foreground = Screen.colors.Black, background = Screen.colors.LightGrey },
30      [8] = { background = Screen.colors.LightMagenta },
31      [9] = {
32        bold = true,
33        foreground = Screen.colors.Blue,
34        background = Screen.colors.LightMagenta,
35      },
36      [10] = { background = Screen.colors.LightGrey, underline = true },
37      [11] = {
38        background = Screen.colors.LightGrey,
39        underline = true,
40        bold = true,
41        foreground = Screen.colors.Magenta,
42      },
43      [12] = {
44        underline = true,
45        background = Screen.colors.Red,
46      },
47      [13] = {
48        underline = true,
49        bold = true,
50        foreground = Screen.colors.Blue,
51        background = Screen.colors.Red,
52      },
53    })
54    api.nvim_set_option_value('winbar', 'Set Up The Bars', {})
55  end)
56
57  it('works', function()
58    screen:expect([[
59      {1:Set Up The Bars                                             }|
60      ^                                                            |
61      {3:~                                                           }|*10
62                                                                  |
63    ]])
64    -- winbar is excluded from the heights returned by winheight() and getwininfo()
65    eq(11, fn.winheight(0))
66    local win_info = fn.getwininfo(api.nvim_get_current_win())[1]
67    eq(11, win_info.height)
68    eq(1, win_info.winbar)
69  end)
70
71  it("works with custom 'fillchars' value", function()
72    command('set fillchars=wbr:+')
73    screen:expect([[
74      {1:Set Up The Bars+++++++++++++++++++++++++++++++++++++++++++++}|
75      ^                                                            |
76      {3:~                                                           }|*10
77                                                                  |
78    ]])
79  end)
80
81  it('works with custom highlight', function()
82    command('hi WinBar guifg=red')
83    screen:expect([[
84      {5:Set Up The Bars                                             }|
85      ^                                                            |
86      {3:~                                                           }|*10
87                                                                  |
88    ]])
89  end)
90
91  it('works with splits', function()
92    command('hi WinBar guifg=red')
93    command('hi WinBarNC guifg=blue')
94    command('belowright vsplit | split | split')
95    screen:expect([[
96      {6:Set Up The Bars              }│{5:Set Up The Bars               }|
97                                   │^                              |
98      {3:~                            }│{3:~                             }|
99      {3:~                            }│{4:[No Name]                     }|
100      {3:~                            }│{6:Set Up The Bars               }|
101      {3:~                            }│                              |
102      {3:~                            }│{3:~                             }|
103      {3:~                            }│{2:[No Name]                     }|
104      {3:~                            }│{6:Set Up The Bars               }|
105      {3:~                            }│                              |
106      {3:~                            }│{3:~                             }|
107      {2:[No Name]                     [No Name]                     }|
108                                                                  |
109    ]])
110    -- 'showcmdloc' "statusline" should not interfere with winbar redrawing #23030
111    command('set showcmd showcmdloc=statusline')
112    feed('<C-W>w')
113    feed('<C-W>')
114    screen:expect([[
115      {6:Set Up The Bars              }│{6:Set Up The Bars               }|
116                                   │                              |
117      {3:~                            }│{3:~                             }|
118      {3:~                            }│{2:[No Name]                     }|
119      {3:~                            }│{5:Set Up The Bars               }|
120      {3:~                            }│^                              |
121      {3:~                            }│{3:~                             }|
122      {3:~                            }│{4:[No Name]          ^W         }|
123      {3:~                            }│{6:Set Up The Bars               }|
124      {3:~                            }│                              |
125      {3:~                            }│{3:~                             }|
126      {2:[No Name]                     [No Name]                     }|
127                                                                  |
128    ]])
129    feed('w<C-W>W')
130    screen:expect([[
131      {6:Set Up The Bars              }│{6:Set Up The Bars               }|
132                                   │                              |
133      {3:~                            }│{3:~                             }|
134      {3:~                            }│{2:[No Name]                     }|
135      {3:~                            }│{5:Set Up The Bars               }|
136      {3:~                            }│^                              |
137      {3:~                            }│{3:~                             }|
138      {3:~                            }│{4:[No Name]                     }|
139      {3:~                            }│{6:Set Up The Bars               }|
140      {3:~                            }│                              |
141      {3:~                            }│{3:~                             }|
142      {2:[No Name]                     [No Name]                     }|
143                                                                  |
144    ]])
145  end)
146
147  it("works when switching value of 'winbar'", function()
148    command('belowright vsplit | split | split | set winbar=')
149    screen:expect([[
150                                   │^                              |
151      {3:~                            }│{3:~                             }|*2
152      {3:~                            }│{4:[No Name]                     }|
153      {3:~                            }│                              |
154      {3:~                            }│{3:~                             }|*2
155      {3:~                            }│{2:[No Name]                     }|
156      {3:~                            }│                              |
157      {3:~                            }│{3:~                             }|*2
158      {2:[No Name]                     [No Name]                     }|
159                                                                  |
160    ]])
161    command('set winbar=All\\ Your\\ Bar\\ Are\\ Belong\\ To\\ Us')
162    screen:expect([[
163      {1:All Your Bar Are Belong To Us}│{1:All Your Bar Are Belong To Us }|
164                                   │^                              |
165      {3:~                            }│{3:~                             }|
166      {3:~                            }│{4:[No Name]                     }|
167      {3:~                            }│{1:All Your Bar Are Belong To Us }|
168      {3:~                            }│                              |
169      {3:~                            }│{3:~                             }|
170      {3:~                            }│{2:[No Name]                     }|
171      {3:~                            }│{1:All Your Bar Are Belong To Us }|
172      {3:~                            }│                              |
173      {3:~                            }│{3:~                             }|
174      {2:[No Name]                     [No Name]                     }|
175                                                                  |
176    ]])
177    command('set winbar=Changed\\ winbar')
178    screen:expect([[
179      {1:Changed winbar               }│{1:Changed winbar                }|
180                                   │^                              |
181      {3:~                            }│{3:~                             }|
182      {3:~                            }│{4:[No Name]                     }|
183      {3:~                            }│{1:Changed winbar                }|
184      {3:~                            }│                              |
185      {3:~                            }│{3:~                             }|
186      {3:~                            }│{2:[No Name]                     }|
187      {3:~                            }│{1:Changed winbar                }|
188      {3:~                            }│                              |
189      {3:~                            }│{3:~                             }|
190      {2:[No Name]                     [No Name]                     }|
191                                                                  |
192    ]])
193  end)
194
195  it('works with combined highlight attributes', function()
196    command('hi Winbar guibg=red gui=underline')
197    command('hi Identifier guifg=blue gui=bold')
198    command('set winbar=Lookatmy%#Identifier#highlights')
199    screen:expect([[
200      {12:Lookatmy}{13:highlights                                          }|
201      ^                                                            |
202      {3:~                                                           }|*10
203                                                                  |
204    ]])
205  end)
206
207  it('can be ruler', function()
208    insert [[
209      just some
210      random text]]
211    api.nvim_set_option_value('winbar', 'Hello, I am a ruler: %l,%c', {})
212    screen:expect {
213      grid = [[
214      {1:Hello, I am a ruler: 2,11                                   }|
215      just some                                                   |
216      random tex^t                                                 |
217      {3:~                                                           }|*9
218                                                                  |
219    ]],
220    }
221    feed 'b'
222    screen:expect {
223      grid = [[
224      {1:Hello, I am a ruler: 2,8                                    }|
225      just some                                                   |
226      random ^text                                                 |
227      {3:~                                                           }|*9
228                                                                  |
229    ]],
230    }
231    feed 'k'
232    screen:expect {
233      grid = [[
234      {1:Hello, I am a ruler: 1,8                                    }|
235      just so^me                                                   |
236      random text                                                 |
237      {3:~                                                           }|*9
238                                                                  |
239    ]],
240    }
241  end)
242
243  it('works with laststatus=3', function()
244    command('set laststatus=3')
245    screen:expect([[
246      {1:Set Up The Bars                                             }|
247      ^                                                            |
248      {3:~                                                           }|*9
249      {4:[No Name]                                                   }|
250                                                                  |
251    ]])
252    command('belowright vsplit | split | split')
253    screen:expect([[
254      {1:Set Up The Bars              }│{1:Set Up The Bars               }|
255                                   │^                              |
256      {3:~                            }│{3:~                             }|
257      {3:~                            }├──────────────────────────────|
258      {3:~                            }│{1:Set Up The Bars               }|
259      {3:~                            }│                              |
260      {3:~                            }│{3:~                             }|
261      {3:~                            }├──────────────────────────────|
262      {3:~                            }│{1:Set Up The Bars               }|
263      {3:~                            }│                              |
264      {3:~                            }│{3:~                             }|
265      {4:[No Name]                                                   }|
266                                                                  |
267    ]])
268    -- Test for issue #18791
269    command('tabnew')
270    screen:expect([[
271      {10: }{11:4}{10: [No Name] }{1: [No Name] }{2:                                   }{10:X}|
272      {1:Set Up The Bars                                             }|
273      ^                                                            |
274      {3:~                                                           }|*8
275      {4:[No Name]                                                   }|
276                                                                  |
277    ]])
278  end)
279
280  it('mouse click and drag work correctly in buffer', function()
281    insert([[
282      line 1
283      line 2
284      line 3
285      line 4
286      line -42
287      line i
288      line sin(theta)
289      line 8]])
290
291    api.nvim_input_mouse('left', 'press', '', 0, 5, 1)
292    screen:expect([[
293      {1:Set Up The Bars                                             }|
294      line 1                                                      |
295      line 2                                                      |
296      line 3                                                      |
297      line 4                                                      |
298      l^ine -42                                                    |
299      line i                                                      |
300      line sin(theta)                                             |
301      line 8                                                      |
302      {3:~                                                           }|*3
303                                                                  |
304    ]])
305    eq({ 5, 1 }, api.nvim_win_get_cursor(0))
306
307    api.nvim_input_mouse('left', 'drag', '', 0, 6, 2)
308    screen:expect([[
309      {1:Set Up The Bars                                             }|
310      line 1                                                      |
311      line 2                                                      |
312      line 3                                                      |
313      line 4                                                      |
314      l{7:ine -42}                                                    |
315      {7:li^n}e i                                                      |
316      line sin(theta)                                             |
317      line 8                                                      |
318      {3:~                                                           }|*3
319      {1:-- VISUAL --}                                                |
320    ]])
321    eq({ 6, 2 }, api.nvim_win_get_cursor(0))
322
323    api.nvim_input_mouse('left', 'drag', '', 0, 1, 2)
324    screen:expect([[
325      {1:Set Up The Bars                                             }|
326      li{7:^ne 1}                                                      |
327      {7:line 2}                                                      |
328      {7:line 3}                                                      |
329      {7:line 4}                                                      |
330      {7:li}ne -42                                                    |
331      line i                                                      |
332      line sin(theta)                                             |
333      line 8                                                      |
334      {3:~                                                           }|*3
335      {1:-- VISUAL --}                                                |
336    ]])
337    eq({ 1, 2 }, api.nvim_win_get_cursor(0))
338
339    api.nvim_input_mouse('left', 'drag', '', 0, 0, 2)
340    screen:expect_unchanged()
341    eq({ 1, 2 }, api.nvim_win_get_cursor(0))
342  end)
343
344  it('dragging statusline with mouse works correctly', function()
345    command('split')
346    screen:expect([[
347      {1:Set Up The Bars                                             }|
348      ^                                                            |
349      {3:~                                                           }|*3
350      {4:[No Name]                                                   }|
351      {1:Set Up The Bars                                             }|
352                                                                  |
353      {3:~                                                           }|*3
354      {2:[No Name]                                                   }|
355                                                                  |
356    ]])
357
358    api.nvim_input_mouse('left', 'press', '', 1, 5, 10)
359    poke_eventloop()
360    api.nvim_input_mouse('left', 'drag', '', 1, 6, 10)
361    screen:expect([[
362      {1:Set Up The Bars                                             }|
363      ^                                                            |
364      {3:~                                                           }|*4
365      {4:[No Name]                                                   }|
366      {1:Set Up The Bars                                             }|
367                                                                  |
368      {3:~                                                           }|*2
369      {2:[No Name]                                                   }|
370                                                                  |
371    ]])
372
373    api.nvim_input_mouse('left', 'drag', '', 1, 4, 10)
374    screen:expect([[
375      {1:Set Up The Bars                                             }|
376      ^                                                            |
377      {3:~                                                           }|*2
378      {4:[No Name]                                                   }|
379      {1:Set Up The Bars                                             }|
380                                                                  |
381      {3:~                                                           }|*4
382      {2:[No Name]                                                   }|
383                                                                  |
384    ]])
385
386    api.nvim_input_mouse('left', 'press', '', 1, 11, 10)
387    poke_eventloop()
388    api.nvim_input_mouse('left', 'drag', '', 1, 9, 10)
389    screen:expect([[
390      {1:Set Up The Bars                                             }|
391      ^                                                            |
392      {3:~                                                           }|*2
393      {4:[No Name]                                                   }|
394      {1:Set Up The Bars                                             }|
395                                                                  |
396      {3:~                                                           }|*2
397      {2:[No Name]                                                   }|
398                                                                  |*3
399    ]])
400    eq(3, api.nvim_get_option_value('cmdheight', {}))
401
402    api.nvim_input_mouse('left', 'drag', '', 1, 11, 10)
403    screen:expect([[
404      {1:Set Up The Bars                                             }|
405      ^                                                            |
406      {3:~                                                           }|*2
407      {4:[No Name]                                                   }|
408      {1:Set Up The Bars                                             }|
409                                                                  |
410      {3:~                                                           }|*4
411      {2:[No Name]                                                   }|
412                                                                  |
413    ]])
414    eq(1, api.nvim_get_option_value('cmdheight', {}))
415  end)
416
417  it('properly equalizes window height for window-local value', function()
418    command('set equalalways | set winbar= | setlocal winbar=a | split')
419    command('setlocal winbar= | split')
420    command('setlocal winbar=b | split')
421    screen:expect([[
422      {1:b                                                           }|
423      ^                                                            |
424      {4:[No Name]                                                   }|
425      {1:b                                                           }|
426                                                                  |
427      {2:[No Name]                                                   }|
428                                                                  |
429      {3:~                                                           }|
430      {2:[No Name]                                                   }|
431      {1:a                                                           }|
432                                                                  |
433      {2:[No Name]                                                   }|
434                                                                  |
435    ]])
436  end)
437
438  it('requires window-local value for floating windows', function()
439    local win = api.nvim_open_win(
440      0,
441      false,
442      { relative = 'editor', row = 2, col = 10, height = 7, width = 30 }
443    )
444    api.nvim_set_option_value('winbar', 'bar', {})
445    screen:expect {
446      grid = [[
447      {1:bar                                                         }|
448      ^                                                            |
449      {3:~         }{8:                              }{3:                    }|
450      {3:~         }{9:~                             }{3:                    }|*6
451      {3:~                                                           }|*3
452                                                                  |
453    ]],
454    }
455    api.nvim_set_option_value('winbar', 'floaty bar', { scope = 'local', win = win })
456    screen:expect {
457      grid = [[
458      {1:bar                                                         }|
459      ^                                                            |
460      {3:~         }{1:floaty bar                    }{3:                    }|
461      {3:~         }{8:                              }{3:                    }|
462      {3:~         }{9:~                             }{3:                    }|*5
463      {3:~                                                           }|*3
464                                                                  |
465    ]],
466    }
467  end)
468
469  it('works correctly when moving a split', function()
470    screen:try_resize(45, 6)
471    command('set winbar=')
472    command('vsplit')
473    command('setlocal winbar=foo')
474    screen:expect([[
475      {1:foo                   }│                      |
476      ^                      │{3:~                     }|
477      {3:~                     }│{3:~                     }|*2
478      {4:[No Name]              }{2:[No Name]             }|
479                                                   |
480    ]])
481
482    command('wincmd L')
483    screen:expect([[
484                            │{1:foo                   }|
485      {3:~                     }│^                      |
486      {3:~                     }│{3:~                     }|*2
487      {2:[No Name]              }{4:[No Name]             }|
488                                                   |
489    ]])
490
491    command('wincmd w')
492    command('wincmd L')
493    screen:expect([[
494      {1:foo                   }│^                      |
495                            │{3:~                     }|
496      {3:~                     }│{3:~                     }|*2
497      {2:[No Name]              }{4:[No Name]             }|
498                                                   |
499    ]])
500  end)
501
502  it('properly resizes window when there is no space in it', function()
503    command('set winbar= | 1split')
504    screen:expect([[
505      ^                                                            |
506      {4:[No Name]                                                   }|
507                                                                  |
508      {3:~                                                           }|*8
509      {2:[No Name]                                                   }|
510                                                                  |
511    ]])
512    command('set winbar=a')
513    screen:expect([[
514      {1:a                                                           }|
515      ^                                                            |
516      {4:[No Name]                                                   }|
517      {1:a                                                           }|
518                                                                  |
519      {3:~                                                           }|*6
520      {2:[No Name]                                                   }|
521                                                                  |
522    ]])
523  end)
524
525  it('cannot be added unless there is room', function()
526    command('set winbar= | split | split | split | split | split')
527    screen:expect([[
528      ^                                                            |
529      {4:[No Name]                                                   }|
530                                                                  |
531      {2:[No Name]                                                   }|
532                                                                  |
533      {2:[No Name]                                                   }|
534                                                                  |
535      {2:[No Name]                                                   }|
536                                                                  |
537      {2:[No Name]                                                   }|
538                                                                  |
539      {2:[No Name]                                                   }|
540                                                                  |
541    ]])
542    eq('Vim(set):E36: Not enough room', pcall_err(command, 'set winbar=test'))
543  end)
544
545  it('does not crash due to negative grid height #33176', function()
546    screen:try_resize(screen._width, 20)
547    command('botright split | belowright vsplit | 2wincmd w')
548    api.nvim_set_option_value('winfixheight', true, { scope = 'local', win = 0 })
549    api.nvim_win_resize(0, -1, 8, {})
550    feed('q:')
551    n.assert_alive()
552  end)
553
554  it('draws vertical separator of a window that only has a winbar #41142', function()
555    n.exec([[
556      set laststatus=3 winminheight=0
557      topleft vsplit
558      setlocal winbar=bottom
559      aboveleft split
560      setlocal winbar=top
561      resize 1000
562    ]])
563    screen:expect([[
564      {1:top                           }│{1:Set Up The Bars              }|
565      ^                              │                             |
566      {3:~                             }│{3:~                            }|*7
567      ──────────────────────────────┤{3:~                            }|
568      {1:bottom                        }│{3:~                            }|
569      {4:[No Name]                                                   }|
570                                                                  |
571    ]])
572  end)
573
574  it('making room for a winbar does not overlap the global statusline #41140', function()
575    n.exec([[
576      set winbar= laststatus=3
577      vsplit
578      split
579      resize 1
580      setlocal winbar=top
581      resize 1000
582    ]])
583    screen:expect([[
584      {1:top                           }│                             |
585      ^                              │{3:~                            }|
586      {3:~                             }│{3:~                            }|*7
587      ──────────────────────────────┤{3:~                            }|
588                                    │{3:~                            }|
589      {4:[No Name]                                                   }|
590                                                                  |
591    ]])
592  end)
593end)
594
595describe('local winbar with tabs', function()
596  local screen
597  before_each(function()
598    clear()
599    screen = Screen.new(60, 10)
600    api.nvim_set_option_value('winbar', 'foo', { scope = 'local', win = 0 })
601  end)
602
603  it('works', function()
604    command('tabnew')
605    screen:expect([[
606      {24: [No Name] }{5: [No Name] }{2:                                     }{24:X}|
607      ^                                                            |
608      {1:~                                                           }|*7
609                                                                  |
610    ]])
611    command('tabnext')
612    screen:expect {
613      grid = [[
614      {5: [No Name] }{24: [No Name] }{2:                                     }{24:X}|
615      {5:foo                                                         }|
616      ^                                                            |
617      {1:~                                                           }|*6
618                                                                  |
619    ]],
620    }
621  end)
622
623  it('can edit new empty buffer #19458', function()
624    insert [[
625      some
626      goofy
627      text]]
628    screen:expect {
629      grid = [[
630      {5:foo                                                         }|
631      some                                                        |
632      goofy                                                       |
633      tex^t                                                        |
634      {1:~                                                           }|*5
635                                                                  |
636    ]],
637    }
638
639    -- this used to throw an E315 ml_get error
640    command 'tabedit'
641    screen:expect {
642      grid = [[
643      {24: + [No Name] }{5: [No Name] }{2:                                   }{24:X}|
644      ^                                                            |
645      {1:~                                                           }|*7
646                                                                  |
647    ]],
648    }
649
650    command 'tabprev'
651    screen:expect {
652      grid = [[
653      {5: + [No Name] }{24: [No Name] }{2:                                   }{24:X}|
654      {5:foo                                                         }|
655      some                                                        |
656      goofy                                                       |
657      tex^t                                                        |
658      {1:~                                                           }|*4
659                                                                  |
660    ]],
661    }
662  end)
663end)
664
665describe('global winbar with tabs', function()
666  local screen
667  before_each(function()
668    clear()
669    screen = Screen.new(60, 10)
670  end)
671
672  it('updates hidden tabs when enabled #28641', function()
673    command('tabnew')
674    command('tabprev')
675    command('set winbar=my-winbar')
676    command('tabnext')
677    screen:expect([[
678      {24: [No Name] }{5: [No Name] }{2:                                     }{24:X}|
679      {5:my-winbar                                                   }|
680      ^                                                            |
681      {1:~                                                           }|*6
682                                                                  |
683    ]])
684    eq(1, fn.getwininfo(api.nvim_get_current_win())[1].winbar)
685  end)
686
687  it('updates hidden tabs when disabled #28641', function()
688    command('setglobal winbar=my-winbar')
689    command('tabnew')
690    command('tabprev')
691    command('setglobal winbar=')
692    command('tabnext')
693    screen:expect([[
694      {24: [No Name] }{5: [No Name] }{2:                                     }{24:X}|
695      ^                                                            |
696      {1:~                                                           }|*7
697                                                                  |
698    ]])
699    eq(0, fn.getwininfo(api.nvim_get_current_win())[1].winbar)
700  end)
701
702  it('updates hidden tabs when current tab has no room #28641', function()
703    command('tabnew')
704    command('tabprev')
705    command('set winbar= | split | split | split')
706    eq('Vim(set):E36: Not enough room', pcall_err(command, 'set winbar=test'))
707    command('tabnext')
708    eq(1, fn.getwininfo(api.nvim_get_current_win())[1].winbar)
709  end)
710end)
711
712it('winbar works properly when redrawing is postponed #23534', function()
713  clear({
714    args = {
715      '-c',
716      'set laststatus=2 lazyredraw',
717      '-c',
718      'setlocal statusline=(statusline) winbar=(winbar)',
719      '-c',
720      'call nvim_input(":<Esc>")',
721    },
722  })
723  local screen = Screen.new(60, 6)
724  screen:expect([[
725    {5:(winbar)                                                    }|
726    ^                                                            |
727    {1:~                                                           }|*2
728    {3:(statusline)                                                }|
729                                                                |
730  ]])
731end)