neovim

Neovim text editor
git clone https://git.dasho.dev/neovim.git
Log | Files | Refs | README

winbar_spec.lua (30332B)


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