neovim

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

options_spec.lua (6116B)


      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 eq = t.eq
      8 local shallowcopy = t.shallowcopy
      9 local eval = n.eval
     10 
     11 describe('UI receives option updates', function()
     12  local screen
     13 
     14  local function reset(screen_opts, clear_opts)
     15    local defaults = {
     16      ambiwidth = 'single',
     17      arabicshape = true,
     18      emoji = true,
     19      guifont = '',
     20      guifontwide = '',
     21      linespace = 0,
     22      pumblend = 0,
     23      mousefocus = false,
     24      mousehide = true,
     25      mousemoveevent = false,
     26      showtabline = 1,
     27      termguicolors = false,
     28      termsync = true,
     29      ttimeout = true,
     30      ttimeoutlen = 50,
     31      verbose = 0,
     32      ext_cmdline = false,
     33      ext_popupmenu = false,
     34      ext_tabline = false,
     35      ext_wildmenu = false,
     36      ext_linegrid = false,
     37      ext_hlstate = false,
     38      ext_multigrid = false,
     39      ext_messages = false,
     40      ext_termcolors = false,
     41    }
     42 
     43    clear_opts = shallowcopy(clear_opts or {})
     44    clear_opts.args_rm = clear_opts.args_rm or {}
     45    table.insert(clear_opts.args_rm or {}, '--cmd')
     46    clear(clear_opts)
     47    screen = Screen.new(20, 5, screen_opts)
     48    defaults.guifont = eval('&guifont')
     49    -- NB: UI test suite can be run in both "linegrid" and legacy grid mode.
     50    -- In both cases check that the received value is the one requested.
     51    defaults.ext_linegrid = screen._options.ext_linegrid or false
     52    return defaults
     53  end
     54 
     55  it('for defaults', function()
     56    local expected = reset()
     57    screen:expect(function()
     58      eq(expected, screen.options)
     59    end)
     60  end)
     61 
     62  it('on attach #11372', function()
     63    clear { args_rm = { '--headless' } }
     64    local evs = {}
     65    screen = Screen.new(20, 5)
     66    -- Override mouse_on/mouse_off handlers.
     67    function screen:_handle_mouse_on()
     68      table.insert(evs, 'mouse_on')
     69    end
     70    function screen:_handle_mouse_off()
     71      table.insert(evs, 'mouse_off')
     72    end
     73    screen:expect(function()
     74      eq({ 'mouse_on' }, evs)
     75    end)
     76    command('set mouse=')
     77    screen:expect(function()
     78      eq({ 'mouse_on', 'mouse_off' }, evs)
     79    end)
     80    command('set mouse&')
     81    screen:expect(function()
     82      eq({ 'mouse_on', 'mouse_off', 'mouse_on' }, evs)
     83    end)
     84    screen:detach()
     85    eq({ 'mouse_on', 'mouse_off', 'mouse_on' }, evs)
     86    screen:attach()
     87    screen:expect(function()
     88      eq({ 'mouse_on', 'mouse_off', 'mouse_on', 'mouse_on' }, evs)
     89    end)
     90  end)
     91 
     92  it('when setting options', function()
     93    local expected = reset()
     94    local defaults = shallowcopy(expected)
     95 
     96    command('set termguicolors')
     97    expected.termguicolors = true
     98    screen:expect(function()
     99      eq(expected, screen.options)
    100    end)
    101 
    102    command('set pumblend=50')
    103    expected.pumblend = 50
    104    screen:expect(function()
    105      eq(expected, screen.options)
    106    end)
    107 
    108    -- check handling of out-of-bounds value
    109    command('set pumblend=-1')
    110    expected.pumblend = 0
    111    screen:expect(function()
    112      eq(expected, screen.options)
    113    end)
    114 
    115    command('set guifont=Comic\\ Sans')
    116    expected.guifont = 'Comic Sans'
    117    screen:expect(function()
    118      eq(expected, screen.options)
    119    end)
    120 
    121    command('set showtabline=0')
    122    expected.showtabline = 0
    123    screen:expect(function()
    124      eq(expected, screen.options)
    125    end)
    126 
    127    command('set linespace=13')
    128    expected.linespace = 13
    129    screen:expect(function()
    130      eq(expected, screen.options)
    131    end)
    132 
    133    command('set linespace=-11')
    134    expected.linespace = -11
    135    screen:expect(function()
    136      eq(expected, screen.options)
    137    end)
    138 
    139    command('set mousefocus')
    140    expected.mousefocus = true
    141    screen:expect(function()
    142      eq(expected, screen.options)
    143    end)
    144 
    145    command('set nomousehide')
    146    expected.mousehide = false
    147    screen:expect(function()
    148      eq(expected, screen.options)
    149    end)
    150 
    151    command('set mousemoveevent')
    152    expected.mousemoveevent = true
    153    screen:expect(function()
    154      eq(expected, screen.options)
    155    end)
    156 
    157    command('set nottimeout')
    158    expected.ttimeout = false
    159    screen:expect(function()
    160      eq(expected, screen.options)
    161    end)
    162 
    163    command('set ttimeoutlen=100')
    164    expected.ttimeoutlen = 100
    165    screen:expect(function()
    166      eq(expected, screen.options)
    167    end)
    168 
    169    command('set all&')
    170    screen:expect(function()
    171      eq(defaults, screen.options)
    172    end)
    173  end)
    174 
    175  it('with UI extensions', function()
    176    local expected = reset({ ext_cmdline = true, ext_wildmenu = true })
    177 
    178    expected.ext_cmdline = true
    179    expected.ext_wildmenu = true
    180    screen:expect(function()
    181      eq(expected, screen.options)
    182    end)
    183 
    184    screen:set_option('ext_popupmenu', true)
    185    expected.ext_popupmenu = true
    186    screen:expect(function()
    187      eq(expected, screen.options)
    188    end)
    189 
    190    screen:set_option('ext_wildmenu', false)
    191    expected.ext_wildmenu = false
    192    screen:expect(function()
    193      eq(expected, screen.options)
    194    end)
    195  end)
    196 
    197  local function startup_test(headless)
    198    local expected = reset(nil, {
    199      args_rm = (headless and {} or { '--headless' }),
    200      args = { '--cmd', 'set guifont=Comic\\ Sans\\ 12' },
    201    })
    202    expected.guifont = 'Comic Sans 12'
    203    screen:expect(function()
    204      eq(expected, screen.options)
    205    end)
    206  end
    207 
    208  it('from startup options with --headless', function()
    209    startup_test(true)
    210  end)
    211  it('from startup options with --embed', function()
    212    startup_test(false)
    213  end)
    214 end)
    215 
    216 describe('UI can set terminal option', function()
    217  before_each(function()
    218    -- by default we implicitly "--cmd 'set bg=light'" which ruins everything
    219    clear { args_rm = { '--cmd' } }
    220  end)
    221 
    222  it('term_name', function()
    223    eq('nvim', eval '&term')
    224 
    225    local _ = Screen.new(20, 5, { term_name = 'xterm' })
    226    eq('xterm', eval '&term')
    227  end)
    228 
    229  it('term_colors', function()
    230    eq('256', eval '&t_Co')
    231 
    232    local screen = Screen.new(20, 5, { term_colors = 8 })
    233    eq('8', eval '&t_Co')
    234    screen:detach()
    235 
    236    screen = Screen.new(20, 5, { term_colors = 16777216 })
    237    eq('16777216', eval '&t_Co')
    238    screen:detach()
    239  end)
    240 end)