robin/laufey

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

Justin M. KeyesMerge #40865 from justinmk/fixcif907614088

master
3.1 KiB96 linesraw
1local t = require('test.testutil')
2local n = require('test.functional.testnvim')()
3
4local describe, it, before_each = t.describe, t.it, t.before_each
5local command = n.command
6local eq = t.eq
7local clear = n.clear
8local fn = n.fn
9local pcall_err = t.pcall_err
10local assert_alive = n.assert_alive
11
12describe('nlua_call_excmd excmds', function()
13  -- Exercise nlua_call_excmd by testing commands implemented with it (:log, :lsp).
14
15  before_each(function()
16    clear()
17  end)
18
19  it('error propagation, formatting', function()
20    t.eq('Vim(lsp):E5800: Invalid :lsp subcommand: bogus', pcall_err(command, 'lsp bogus'))
21    t.matches('Vim%(log%):E5200: No such log.*', pcall_err(command, 'log bogus'))
22  end)
23end)
24
25describe('excmds', function()
26  before_each(function()
27    clear()
28  end)
29
30  local function check_excmd_err(cmd, err)
31    eq(err .. ': ' .. cmd, pcall_err(command, cmd))
32  end
33
34  it('handle integer overflow from user-input #5555', function()
35    command(':9999999999999999999999999999999999999999')
36    command(':later 9999999999999999999999999999999999999999')
37    command(':echo expand("#<9999999999999999999999999999999999999999")')
38    command(':lockvar 9999999999999999999999999999999999999999')
39    command(
40      ':winsize 9999999999999999999999999999999999999999 9999999999999999999999999999999999999999'
41    )
42    check_excmd_err(
43      ':tabnext 9999999999999999999999999999999999999999',
44      'Vim(tabnext):E475: Invalid argument: 9999999999999999999999999999999999999999'
45    )
46    eq(
47      'Vim(Next):E163: There is only one file to edit',
48      pcall_err(command, ':N 9999999999999999999999999999999999999999')
49    )
50    check_excmd_err(
51      ':bdelete 9999999999999999999999999999999999999999',
52      'Vim(bdelete):E516: No buffers were deleted'
53    )
54    eq(
55      'Vim(menu):E329: No menu "9999999999999999999999999999999999999999"',
56      pcall_err(command, ':menu 9999999999999999999999999999999999999999')
57    )
58    eq(
59      'Vim(substitute):E1510: Value too large: 9999999999999999999999999999999999999999',
60      pcall_err(command, ':%s/./b/9999999999999999999999999999999999999999')
61    )
62    assert_alive()
63  end)
64
65  it('listing long user command does not crash', function()
66    command('execute "command" repeat("T", 255) ":"')
67    command('command')
68  end)
69
70  it(':def is an unknown command #23149', function()
71    eq('Vim:E492: Not an editor command: def', pcall_err(command, 'def'))
72    eq(1, fn.exists(':d'))
73    eq('delete', fn.fullcommand('d'))
74    eq(1, fn.exists(':de'))
75    eq('delete', fn.fullcommand('de'))
76    eq(0, fn.exists(':def'))
77    eq('', fn.fullcommand('def'))
78    eq(1, fn.exists(':defe'))
79    eq('defer', fn.fullcommand('defe'))
80    eq(2, fn.exists(':defer'))
81    eq('defer', fn.fullcommand('defer'))
82  end)
83
84  it('various command abbreviations', function()
85    -- :connect needs at least :conn
86    eq('change', fn.fullcommand('c'))
87    eq('copy', fn.fullcommand('co'))
88    eq('continue', fn.fullcommand('con'))
89    eq('connect', fn.fullcommand('conn'))
90    -- :restart needs at least :rest
91    eq('read', fn.fullcommand('r'))
92    eq('read', fn.fullcommand('re'))
93    eq('resize', fn.fullcommand('res'))
94    eq('restart', fn.fullcommand('rest'))
95  end)
96end)