aboutsummaryrefslogtreecommitdiff
path: root/test/functional/api/command_spec.lua
blob: db03edf6d2f89a64529d8f3cd32b4ce8e73ce157 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
local helpers = require('test.functional.helpers')(after_each)

local clear = helpers.clear
local command = helpers.command
local curbufmeths = helpers.curbufmeths
local eq = helpers.eq
local meths = helpers.meths

describe('nvim_get_commands', function()
  local dummy_dict = {dummy=''}
  local cmd_string = 'command Hello echo "Hello World"'
  local cmd_string2 = 'command Pwd pwd'
  local cmd_dict = {
    name='Hello',
    nargs='0',
    script_id=0,
    definition='echo "Hello World"',
  }
  local cmd_dict2 = {
    name='Pwd',
    nargs='0',
    script_id=0,
    definition='pwd',
  }
  before_each(clear)
  it('gets empty list if no commands were defined', function()
    eq({}, meths.get_commands(dummy_dict))
  end)
  it('gets user-def commands', function()
    -- Insert a command
    command(cmd_string)
    eq({cmd_dict}, meths.get_commands(dummy_dict))
    -- Insert a another command
    command(cmd_string2);
    eq({cmd_dict, cmd_dict2}, meths.get_commands(dummy_dict))
    -- Delete a command
    command('delcommand Pwd')
    eq({cmd_dict}, meths.get_commands(dummy_dict))
  end)
  it('considers different buffers', function()
    -- Insert a command
    command('command -buffer Hello echo "Hello World"')
    eq({cmd_dict}, curbufmeths.get_commands(dummy_dict))
    -- Insert a another command
    command('command -buffer Pwd pwd')
    eq({cmd_dict, cmd_dict2}, curbufmeths.get_commands(dummy_dict))
    -- Delete a command
    command('delcommand Pwd')
    eq({cmd_dict}, curbufmeths.get_commands(dummy_dict))
  end)
  it('gets different attributes of different commands', function()
    local cmd1 = {
      complete='custom',
      nargs='1',
      name='Finger',
      script_id=0,
      complete_arg='ListUsers',
      definition='!finger <args>',
    }
    local cmd2 = {
      complete='dir',
      nargs='0',
      name='TestCmd',
      range='10c',
      addr='arguments',
      script_id=0,
      definition='pwd <args>',
    }
    command('command -complete=custom,ListUsers -nargs=1 Finger !finger <args>')
    eq({cmd1}, meths.get_commands(dummy_dict))
    command('command -complete=dir -addr=arguments -count=10 TestCmd pwd <args>')
    eq({cmd1, cmd2}, meths.get_commands(dummy_dict))
  end)
end)