neovim

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

excmd_spec.lua (2560B)


      1 local t = require('test.testutil')
      2 local n = require('test.functional.testnvim')()
      3 
      4 local command = n.command
      5 local eq = t.eq
      6 local clear = n.clear
      7 local fn = n.fn
      8 local pcall_err = t.pcall_err
      9 local assert_alive = n.assert_alive
     10 
     11 describe('Ex cmds', function()
     12  before_each(function()
     13    clear()
     14  end)
     15 
     16  local function check_excmd_err(cmd, err)
     17    eq(err .. ': ' .. cmd, pcall_err(command, cmd))
     18  end
     19 
     20  it('handle integer overflow from user-input #5555', function()
     21    command(':9999999999999999999999999999999999999999')
     22    command(':later 9999999999999999999999999999999999999999')
     23    command(':echo expand("#<9999999999999999999999999999999999999999")')
     24    command(':lockvar 9999999999999999999999999999999999999999')
     25    command(
     26      ':winsize 9999999999999999999999999999999999999999 9999999999999999999999999999999999999999'
     27    )
     28    check_excmd_err(
     29      ':tabnext 9999999999999999999999999999999999999999',
     30      'Vim(tabnext):E475: Invalid argument: 9999999999999999999999999999999999999999'
     31    )
     32    eq(
     33      'Vim(Next):E163: There is only one file to edit',
     34      pcall_err(command, ':N 9999999999999999999999999999999999999999')
     35    )
     36    check_excmd_err(
     37      ':bdelete 9999999999999999999999999999999999999999',
     38      'Vim(bdelete):E516: No buffers were deleted'
     39    )
     40    eq(
     41      'Vim(menu):E329: No menu "9999999999999999999999999999999999999999"',
     42      pcall_err(command, ':menu 9999999999999999999999999999999999999999')
     43    )
     44    assert_alive()
     45  end)
     46 
     47  it('listing long user command does not crash', function()
     48    command('execute "command" repeat("T", 255) ":"')
     49    command('command')
     50  end)
     51 
     52  it(':def is an unknown command #23149', function()
     53    eq('Vim:E492: Not an editor command: def', pcall_err(command, 'def'))
     54    eq(1, fn.exists(':d'))
     55    eq('delete', fn.fullcommand('d'))
     56    eq(1, fn.exists(':de'))
     57    eq('delete', fn.fullcommand('de'))
     58    eq(0, fn.exists(':def'))
     59    eq('', fn.fullcommand('def'))
     60    eq(1, fn.exists(':defe'))
     61    eq('defer', fn.fullcommand('defe'))
     62    eq(2, fn.exists(':defer'))
     63    eq('defer', fn.fullcommand('defer'))
     64  end)
     65 
     66  it('various command abbreviations', function()
     67    -- :connect needs at least :conn
     68    eq('change', fn.fullcommand('c'))
     69    eq('copy', fn.fullcommand('co'))
     70    eq('continue', fn.fullcommand('con'))
     71    eq('connect', fn.fullcommand('conn'))
     72    -- :restart needs at least :rest
     73    eq('read', fn.fullcommand('r'))
     74    eq('read', fn.fullcommand('re'))
     75    eq('resize', fn.fullcommand('res'))
     76    eq('restart', fn.fullcommand('rest'))
     77  end)
     78 end)