neovim

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

tabline_spec.lua (7664B)


      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, command, eq = n.clear, n.command, t.eq
      6 local insert = n.insert
      7 local api = n.api
      8 local assert_alive = n.assert_alive
      9 
     10 describe('ui/ext_tabline', function()
     11  local screen
     12  local event_tabs, event_curtab, event_curbuf, event_buffers
     13 
     14  before_each(function()
     15    clear()
     16    screen = Screen.new(25, 5, { rgb = true, ext_tabline = true })
     17    function screen:_handle_tabline_update(curtab, tabs, curbuf, buffers)
     18      event_curtab = curtab
     19      event_tabs = tabs
     20      event_curbuf = curbuf
     21      event_buffers = buffers
     22    end
     23  end)
     24 
     25  it('publishes UI events', function()
     26    command('tabedit another-tab')
     27 
     28    local expected_tabs = {
     29      { tab = 1, name = '[No Name]' },
     30      { tab = 2, name = 'another-tab' },
     31    }
     32    screen:expect {
     33      grid = [[
     34      ^                         |
     35      {1:~                        }|*3
     36                               |
     37    ]],
     38      condition = function()
     39        eq(2, event_curtab)
     40        eq(expected_tabs, event_tabs)
     41      end,
     42    }
     43 
     44    command('tabNext')
     45    screen:expect {
     46      grid = [[
     47      ^                         |
     48      {1:~                        }|*3
     49                               |
     50    ]],
     51      condition = function()
     52        eq(1, event_curtab)
     53        eq(expected_tabs, event_tabs)
     54      end,
     55    }
     56  end)
     57 
     58  it('buffer UI events', function()
     59    local expected_buffers_initial = {
     60      { buffer = 1, name = '[No Name]' },
     61    }
     62 
     63    screen:expect {
     64      grid = [[
     65      ^                         |
     66      {1:~                        }|*3
     67                               |
     68    ]],
     69      condition = function()
     70        eq(1, event_curbuf)
     71        eq(expected_buffers_initial, event_buffers)
     72      end,
     73    }
     74 
     75    command('badd another-buffer')
     76    command('bnext')
     77 
     78    local expected_buffers = {
     79      { buffer = 1, name = '[No Name]' },
     80      { buffer = 2, name = 'another-buffer' },
     81    }
     82    screen:expect {
     83      grid = [[
     84      ^                         |
     85      {1:~                        }|*3
     86                               |
     87    ]],
     88      condition = function()
     89        eq(2, event_curbuf)
     90        eq(expected_buffers, event_buffers)
     91      end,
     92    }
     93  end)
     94 end)
     95 
     96 describe('tabline', function()
     97  local screen
     98 
     99  before_each(function()
    100    clear()
    101    screen = Screen.new(42, 5)
    102  end)
    103 
    104  it('redraws when tabline option is set', function()
    105    command('set tabline=asdf')
    106    command('set showtabline=2')
    107    screen:expect {
    108      grid = [[
    109      {2:asdf                                      }|
    110      ^                                          |
    111      {1:~                                         }|*2
    112                                                |
    113    ]],
    114    }
    115    command('set tabline=jkl')
    116    screen:expect {
    117      grid = [[
    118      {2:jkl                                       }|
    119      ^                                          |
    120      {1:~                                         }|*2
    121                                                |
    122    ]],
    123    }
    124  end)
    125 
    126  it('combines highlight attributes', function()
    127    screen:set_default_attr_ids({
    128      [1] = { foreground = Screen.colors.Blue1, bold = true }, -- StatusLine
    129      [2] = { bold = true, italic = true }, -- StatusLine
    130      [3] = { bold = true, italic = true, foreground = Screen.colors.Red }, -- NonText combined with StatusLine
    131    })
    132    command('hi TabLineFill gui=bold,italic')
    133    command('hi Identifier guifg=red')
    134    command('set tabline=Test%#Identifier#here')
    135    command('set showtabline=2')
    136    screen:expect {
    137      grid = [[
    138      {2:Test}{3:here                                  }|
    139      ^                                          |
    140      {1:~                                         }|*2
    141                                                |
    142    ]],
    143    }
    144  end)
    145 
    146  it('click definitions do not leak memory #21765', function()
    147    command('set tabline=%@MyClickFunc@MyClickText%T')
    148    command('set showtabline=2')
    149    command('redrawtabline')
    150  end)
    151 
    152  it('clicks work with truncated double-width label #24187', function()
    153    insert('tab1')
    154    command('tabnew')
    155    insert('tab2')
    156    command('tabprev')
    157    api.nvim_set_option_value('tabline', '%1T口口%2Ta' .. ('b'):rep(38) .. '%999Xc', {})
    158    screen:expect {
    159      grid = [[
    160      {2:<abbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbc }|
    161      tab^1                                      |
    162      {1:~                                         }|*2
    163                                                |
    164    ]],
    165    }
    166    assert_alive()
    167    api.nvim_input_mouse('left', 'press', '', 0, 0, 1)
    168    screen:expect {
    169      grid = [[
    170      {2:<abbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbc }|
    171      tab^2                                      |
    172      {1:~                                         }|*2
    173                                                |
    174    ]],
    175    }
    176    api.nvim_input_mouse('left', 'press', '', 0, 0, 0)
    177    screen:expect {
    178      grid = [[
    179      {2:<abbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbc }|
    180      tab^1                                      |
    181      {1:~                                         }|*2
    182                                                |
    183    ]],
    184    }
    185    api.nvim_input_mouse('left', 'press', '', 0, 0, 39)
    186    screen:expect {
    187      grid = [[
    188      {2:<abbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbc }|
    189      tab^2                                      |
    190      {1:~                                         }|*2
    191                                                |
    192    ]],
    193    }
    194    api.nvim_input_mouse('left', 'press', '', 0, 0, 40)
    195    screen:expect {
    196      grid = [[
    197      tab^1                                      |
    198      {1:~                                         }|*3
    199                                                |
    200    ]],
    201    }
    202  end)
    203 
    204  it('middle-click closes tab', function()
    205    command('tabnew')
    206    command('tabnew')
    207    command('tabnew')
    208    command('tabprev')
    209    eq({ 3, 4 }, api.nvim_eval('[tabpagenr(), tabpagenr("$")]'))
    210    api.nvim_input_mouse('middle', 'press', '', 0, 0, 1)
    211    eq({ 2, 3 }, api.nvim_eval('[tabpagenr(), tabpagenr("$")]'))
    212    api.nvim_input_mouse('middle', 'press', '', 0, 0, 20)
    213    eq({ 2, 2 }, api.nvim_eval('[tabpagenr(), tabpagenr("$")]'))
    214    api.nvim_input_mouse('middle', 'press', '', 0, 0, 1)
    215    eq({ 1, 1 }, api.nvim_eval('[tabpagenr(), tabpagenr("$")]'))
    216  end)
    217 
    218  it('does not show floats with focusable=false', function()
    219    screen:set_default_attr_ids({
    220      [1] = { background = Screen.colors.Plum1 },
    221      [2] = { underline = true, background = Screen.colors.LightGrey },
    222      [3] = { bold = true },
    223      [4] = { reverse = true },
    224      [5] = { bold = true, foreground = Screen.colors.Blue1 },
    225      [6] = { foreground = Screen.colors.Fuchsia, bold = true },
    226      [7] = { foreground = Screen.colors.SeaGreen, bold = true },
    227    })
    228    command('tabnew')
    229    api.nvim_open_win(0, false, {
    230      focusable = false,
    231      relative = 'editor',
    232      height = 1,
    233      width = 1,
    234      row = 0,
    235      col = 0,
    236    })
    237    screen:expect {
    238      grid = [[
    239      {1: }{2:[No Name] }{3: [No Name] }{4:                   }{2:X}|
    240      ^                                          |
    241      {5:~                                         }|*2
    242                                                |
    243    ]],
    244    }
    245    command('tabs')
    246    screen:expect {
    247      grid = [[
    248      {6:Tab page 1}                                |
    249      #   [No Name]                             |
    250      {6:Tab page 2}                                |
    251      >   [No Name]                             |
    252      {7:Press ENTER or type command to continue}^   |
    253    ]],
    254    }
    255  end)
    256 end)