neovim

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

command_spec.lua (22548B)


      1 local t = require('test.testutil')
      2 local n = require('test.functional.testnvim')()
      3 
      4 local NIL = vim.NIL
      5 local clear = n.clear
      6 local command = n.command
      7 local eq = t.eq
      8 local api = n.api
      9 local matches = t.matches
     10 local source = n.source
     11 local pcall_err = t.pcall_err
     12 local exec_lua = n.exec_lua
     13 local assert_alive = n.assert_alive
     14 local feed = n.feed
     15 local fn = n.fn
     16 
     17 describe('nvim_get_commands', function()
     18  local cmd_dict = {
     19    addr = NIL,
     20    bang = false,
     21    bar = false,
     22    complete = NIL,
     23    complete_arg = NIL,
     24    count = NIL,
     25    definition = 'echo "Hello World"',
     26    name = 'Hello',
     27    nargs = '1',
     28    range = NIL,
     29    register = false,
     30    keepscript = false,
     31    script_id = 0,
     32  }
     33  local cmd_dict2 = {
     34    addr = NIL,
     35    bang = false,
     36    bar = false,
     37    complete = NIL,
     38    complete_arg = NIL,
     39    count = NIL,
     40    definition = 'pwd',
     41    name = 'Pwd',
     42    nargs = '?',
     43    range = NIL,
     44    register = false,
     45    keepscript = false,
     46    script_id = 0,
     47  }
     48  before_each(clear)
     49 
     50  it('gets empty list if no commands were defined', function()
     51    eq({}, api.nvim_get_commands({ builtin = false }))
     52  end)
     53 
     54  it('validation', function()
     55    eq('builtin=true not implemented', pcall_err(api.nvim_get_commands, { builtin = true }))
     56    eq("Invalid key: 'foo'", pcall_err(api.nvim_get_commands, { foo = 'blah' }))
     57  end)
     58 
     59  it('gets global user-defined commands', function()
     60    -- Define a command.
     61    command('command -nargs=1 Hello echo "Hello World"')
     62    eq({ Hello = cmd_dict }, api.nvim_get_commands({ builtin = false }))
     63    -- Define another command.
     64    command('command -nargs=? Pwd pwd')
     65    eq({ Hello = cmd_dict, Pwd = cmd_dict2 }, api.nvim_get_commands({ builtin = false }))
     66    -- Delete a command.
     67    command('delcommand Pwd')
     68    eq({ Hello = cmd_dict }, api.nvim_get_commands({ builtin = false }))
     69  end)
     70 
     71  it('gets buffer-local user-defined commands', function()
     72    -- Define a buffer-local command.
     73    command('command -buffer -nargs=1 Hello echo "Hello World"')
     74    eq({ Hello = cmd_dict }, api.nvim_buf_get_commands(0, { builtin = false }))
     75    -- Define another buffer-local command.
     76    command('command -buffer -nargs=? Pwd pwd')
     77    eq({ Hello = cmd_dict, Pwd = cmd_dict2 }, api.nvim_buf_get_commands(0, { builtin = false }))
     78    -- Delete a command.
     79    command('delcommand Pwd')
     80    eq({ Hello = cmd_dict }, api.nvim_buf_get_commands(0, { builtin = false }))
     81 
     82    -- {builtin=true} always returns empty for buffer-local case.
     83    eq({}, api.nvim_buf_get_commands(0, { builtin = true }))
     84  end)
     85 
     86  it('gets various command attributes', function()
     87    local cmd0 = {
     88      addr = 'arguments',
     89      bang = false,
     90      bar = false,
     91      complete = 'dir',
     92      complete_arg = NIL,
     93      count = '10',
     94      definition = 'pwd <args>',
     95      name = 'TestCmd',
     96      nargs = '1',
     97      range = '10',
     98      register = false,
     99      keepscript = false,
    100      script_id = 0,
    101    }
    102    local cmd1 = {
    103      addr = NIL,
    104      bang = false,
    105      bar = false,
    106      complete = 'custom',
    107      complete_arg = 'ListUsers',
    108      count = NIL,
    109      definition = '!finger <args>',
    110      name = 'Finger',
    111      nargs = '+',
    112      range = NIL,
    113      register = false,
    114      keepscript = false,
    115      script_id = 1,
    116    }
    117    local cmd2 = {
    118      addr = NIL,
    119      bang = true,
    120      bar = false,
    121      complete = NIL,
    122      complete_arg = NIL,
    123      count = NIL,
    124      definition = 'call \128\253R2_foo(<q-args>)',
    125      name = 'Cmd2',
    126      nargs = '*',
    127      range = NIL,
    128      register = false,
    129      keepscript = false,
    130      script_id = 2,
    131    }
    132    local cmd3 = {
    133      addr = NIL,
    134      bang = false,
    135      bar = true,
    136      complete = NIL,
    137      complete_arg = NIL,
    138      count = NIL,
    139      definition = 'call \128\253R3_ohyeah()',
    140      name = 'Cmd3',
    141      nargs = '0',
    142      range = NIL,
    143      register = false,
    144      keepscript = false,
    145      script_id = 3,
    146    }
    147    local cmd4 = {
    148      addr = NIL,
    149      bang = false,
    150      bar = false,
    151      complete = NIL,
    152      complete_arg = NIL,
    153      count = NIL,
    154      definition = 'call \128\253R4_just_great()',
    155      name = 'Cmd4',
    156      nargs = '0',
    157      range = NIL,
    158      register = true,
    159      keepscript = false,
    160      script_id = 4,
    161    }
    162    local previewCmd = {
    163      addr = NIL,
    164      bang = false,
    165      bar = false,
    166      complete = 'customlist',
    167      complete_arg = 's:cpt',
    168      count = NIL,
    169      definition = '',
    170      name = 'PreviewCmd',
    171      nargs = '1',
    172      range = NIL,
    173      register = false,
    174      keepscript = false,
    175      script_id = 5,
    176    }
    177    local previewLuaCmd = {
    178      addr = NIL,
    179      bang = false,
    180      bar = false,
    181      callback = NIL, -- RPC serializes Lua callback as NIL.
    182      complete = NIL, -- RPC serializes Lua callback as NIL.
    183      preview = NIL, -- RPC serializes Lua callback as NIL.
    184      complete_arg = NIL,
    185      count = NIL,
    186      definition = '',
    187      name = 'PreviewLuaCmd',
    188      nargs = '1',
    189      range = NIL,
    190      register = false,
    191      keepscript = false,
    192      script_id = -8, -- Lua
    193    }
    194 
    195    source([[
    196      let s:foo = 1
    197      command -complete=custom,ListUsers -nargs=+ Finger !finger <args>
    198    ]])
    199    eq({ Finger = cmd1 }, api.nvim_get_commands({ builtin = false }))
    200    command('command -nargs=1 -complete=dir -addr=arguments -count=10 TestCmd pwd <args>')
    201    eq({ Finger = cmd1, TestCmd = cmd0 }, api.nvim_get_commands({ builtin = false }))
    202 
    203    source([[
    204      function! s:foo() abort
    205      endfunction
    206      command -bang -nargs=* Cmd2 call <SID>foo(<q-args>)
    207    ]])
    208    source([[
    209      function! s:ohyeah() abort
    210      endfunction
    211      command -bar -nargs=0 Cmd3 call <SID>ohyeah()
    212    ]])
    213    source([[
    214      function! s:just_great() abort
    215      endfunction
    216      command -register Cmd4 call <SID>just_great()
    217    ]])
    218    source([[
    219      function! s:cpt() abort
    220        return 1
    221      endfunction
    222      command -nargs=1 -complete=customlist,s:cpt PreviewCmd
    223    ]])
    224    source([[
    225      lua << EOF
    226      vim.api.nvim_create_user_command(
    227        'PreviewLuaCmd',
    228        function() end,
    229        {
    230          nargs = 1,
    231          complete = function() return 3 end,
    232          preview = function() return 4 end,
    233        }
    234      )
    235      EOF
    236    ]])
    237    -- TODO(justinmk): Order is stable but undefined. Sort before return?
    238    local commands = api.nvim_get_commands({ builtin = false })
    239    eq({
    240      Cmd2 = cmd2,
    241      Cmd3 = cmd3,
    242      Cmd4 = cmd4,
    243      Finger = cmd1,
    244      TestCmd = cmd0,
    245      PreviewCmd = previewCmd,
    246      PreviewLuaCmd = previewLuaCmd,
    247    }, commands)
    248  end)
    249 
    250  it('gets callbacks defined as Lua functions', function()
    251    exec_lua [[
    252      vim.api.nvim_create_user_command('CommandWithLuaCallback', function(opts)
    253        return 3
    254      end, {
    255        nargs = 1,
    256        preview = function() return 4 end,
    257        complete = function() return 5 end,
    258      })
    259 
    260      local cmd = vim.api.nvim_get_commands({})["CommandWithLuaCallback"]
    261      assert(cmd["callback"]() == 3)
    262      assert(cmd["preview"]() == 4)
    263      assert(cmd["complete"]() == 5)
    264    ]]
    265  end)
    266 end)
    267 
    268 describe('nvim_create_user_command', function()
    269  before_each(clear)
    270 
    271  it('works with strings', function()
    272    api.nvim_create_user_command('SomeCommand', 'let g:command_fired = <args>', { nargs = 1 })
    273    command('SomeCommand 42')
    274    eq(42, api.nvim_eval('g:command_fired'))
    275  end)
    276 
    277  it('works with Lua functions', function()
    278    exec_lua [[
    279      result = {}
    280      vim.api.nvim_create_user_command('CommandWithLuaCallback', function(opts)
    281        result = opts
    282      end, {
    283        nargs = "*",
    284        bang = true,
    285        count = 2,
    286      })
    287    ]]
    288 
    289    eq(
    290      {
    291        name = 'CommandWithLuaCallback',
    292        args = [[this\  is    a\ test]],
    293        fargs = { 'this ', 'is', 'a test' },
    294        bang = false,
    295        line1 = 1,
    296        line2 = 1,
    297        mods = '',
    298        nargs = '*',
    299        smods = {
    300          browse = false,
    301          confirm = false,
    302          emsg_silent = false,
    303          hide = false,
    304          horizontal = false,
    305          keepalt = false,
    306          keepjumps = false,
    307          keepmarks = false,
    308          keeppatterns = false,
    309          lockmarks = false,
    310          noautocmd = false,
    311          noswapfile = false,
    312          sandbox = false,
    313          silent = false,
    314          split = '',
    315          tab = -1,
    316          unsilent = false,
    317          verbose = -1,
    318          vertical = false,
    319        },
    320        range = 0,
    321        count = 2,
    322        reg = '',
    323      },
    324      exec_lua [=[
    325      vim.api.nvim_command([[CommandWithLuaCallback this\  is    a\ test]])
    326      return result
    327    ]=]
    328    )
    329 
    330    eq(
    331      {
    332        name = 'CommandWithLuaCallback',
    333        args = [[this   includes\ a backslash: \\]],
    334        fargs = { 'this', 'includes a', 'backslash:', '\\' },
    335        bang = false,
    336        line1 = 1,
    337        line2 = 1,
    338        mods = '',
    339        nargs = '*',
    340        smods = {
    341          browse = false,
    342          confirm = false,
    343          emsg_silent = false,
    344          hide = false,
    345          horizontal = false,
    346          keepalt = false,
    347          keepjumps = false,
    348          keepmarks = false,
    349          keeppatterns = false,
    350          lockmarks = false,
    351          noautocmd = false,
    352          noswapfile = false,
    353          sandbox = false,
    354          silent = false,
    355          split = '',
    356          tab = -1,
    357          unsilent = false,
    358          verbose = -1,
    359          vertical = false,
    360        },
    361        range = 0,
    362        count = 2,
    363        reg = '',
    364      },
    365      exec_lua [=[
    366      vim.api.nvim_command([[CommandWithLuaCallback this   includes\ a backslash: \\]])
    367      return result
    368    ]=]
    369    )
    370 
    371    eq(
    372      {
    373        name = 'CommandWithLuaCallback',
    374        args = 'a\\b',
    375        fargs = { 'a\\b' },
    376        bang = false,
    377        line1 = 1,
    378        line2 = 1,
    379        mods = '',
    380        nargs = '*',
    381        smods = {
    382          browse = false,
    383          confirm = false,
    384          emsg_silent = false,
    385          hide = false,
    386          horizontal = false,
    387          keepalt = false,
    388          keepjumps = false,
    389          keepmarks = false,
    390          keeppatterns = false,
    391          lockmarks = false,
    392          noautocmd = false,
    393          noswapfile = false,
    394          sandbox = false,
    395          silent = false,
    396          split = '',
    397          tab = -1,
    398          unsilent = false,
    399          verbose = -1,
    400          vertical = false,
    401        },
    402        range = 0,
    403        count = 2,
    404        reg = '',
    405      },
    406      exec_lua [=[
    407      vim.api.nvim_command('CommandWithLuaCallback a\\b')
    408      return result
    409    ]=]
    410    )
    411 
    412    eq(
    413      {
    414        name = 'CommandWithLuaCallback',
    415        args = 'h\tey ',
    416        fargs = { [[h]], [[ey]] },
    417        bang = true,
    418        line1 = 10,
    419        line2 = 10,
    420        mods = 'confirm unsilent botright horizontal',
    421        nargs = '*',
    422        smods = {
    423          browse = false,
    424          confirm = true,
    425          emsg_silent = false,
    426          hide = false,
    427          horizontal = true,
    428          keepalt = false,
    429          keepjumps = false,
    430          keepmarks = false,
    431          keeppatterns = false,
    432          lockmarks = false,
    433          noautocmd = false,
    434          noswapfile = false,
    435          sandbox = false,
    436          silent = false,
    437          split = 'botright',
    438          tab = -1,
    439          unsilent = true,
    440          verbose = -1,
    441          vertical = false,
    442        },
    443        range = 1,
    444        count = 10,
    445        reg = '',
    446      },
    447      exec_lua [=[
    448      vim.api.nvim_command('unsilent horizontal botright confirm 10CommandWithLuaCallback! h\tey ')
    449      return result
    450    ]=]
    451    )
    452 
    453    eq(
    454      {
    455        name = 'CommandWithLuaCallback',
    456        args = 'h',
    457        fargs = { 'h' },
    458        bang = false,
    459        line1 = 1,
    460        line2 = 42,
    461        mods = '',
    462        nargs = '*',
    463        smods = {
    464          browse = false,
    465          confirm = false,
    466          emsg_silent = false,
    467          hide = false,
    468          horizontal = false,
    469          keepalt = false,
    470          keepjumps = false,
    471          keepmarks = false,
    472          keeppatterns = false,
    473          lockmarks = false,
    474          noautocmd = false,
    475          noswapfile = false,
    476          sandbox = false,
    477          silent = false,
    478          split = '',
    479          tab = -1,
    480          unsilent = false,
    481          verbose = -1,
    482          vertical = false,
    483        },
    484        range = 1,
    485        count = 42,
    486        reg = '',
    487      },
    488      exec_lua [[
    489      vim.api.nvim_command('CommandWithLuaCallback 42 h')
    490      return result
    491    ]]
    492    )
    493 
    494    eq(
    495      {
    496        name = 'CommandWithLuaCallback',
    497        args = '',
    498        fargs = {}, -- fargs works without args
    499        bang = false,
    500        line1 = 1,
    501        line2 = 1,
    502        mods = '',
    503        nargs = '*',
    504        smods = {
    505          browse = false,
    506          confirm = false,
    507          emsg_silent = false,
    508          hide = false,
    509          horizontal = false,
    510          keepalt = false,
    511          keepjumps = false,
    512          keepmarks = false,
    513          keeppatterns = false,
    514          lockmarks = false,
    515          noautocmd = false,
    516          noswapfile = false,
    517          sandbox = false,
    518          silent = false,
    519          split = '',
    520          tab = -1,
    521          unsilent = false,
    522          verbose = -1,
    523          vertical = false,
    524        },
    525        range = 0,
    526        count = 2,
    527        reg = '',
    528      },
    529      exec_lua [[
    530      vim.api.nvim_command('CommandWithLuaCallback')
    531      return result
    532    ]]
    533    )
    534 
    535    -- f-args doesn't split when command nargs is 1 or "?"
    536    exec_lua [[
    537      result = {}
    538      vim.api.nvim_create_user_command('CommandWithOneOrNoArg', function(opts)
    539        result = opts
    540      end, {
    541        nargs = "?",
    542        bang = true,
    543        count = 2,
    544      })
    545    ]]
    546 
    547    eq(
    548      {
    549        name = 'CommandWithOneOrNoArg',
    550        args = "hello I'm one argument",
    551        fargs = { "hello I'm one argument" }, -- Doesn't split args
    552        bang = false,
    553        line1 = 1,
    554        line2 = 1,
    555        mods = '',
    556        nargs = '?',
    557        smods = {
    558          browse = false,
    559          confirm = false,
    560          emsg_silent = false,
    561          hide = false,
    562          horizontal = false,
    563          keepalt = false,
    564          keepjumps = false,
    565          keepmarks = false,
    566          keeppatterns = false,
    567          lockmarks = false,
    568          noautocmd = false,
    569          noswapfile = false,
    570          sandbox = false,
    571          silent = false,
    572          split = '',
    573          tab = -1,
    574          unsilent = false,
    575          verbose = -1,
    576          vertical = false,
    577        },
    578        range = 0,
    579        count = 2,
    580        reg = '',
    581      },
    582      exec_lua [[
    583      vim.api.nvim_command('CommandWithOneOrNoArg hello I\'m one argument')
    584      return result
    585    ]]
    586    )
    587 
    588    -- f-args is an empty table if no args were passed
    589    eq(
    590      {
    591        name = 'CommandWithOneOrNoArg',
    592        args = '',
    593        fargs = {},
    594        bang = false,
    595        line1 = 1,
    596        line2 = 1,
    597        mods = '',
    598        nargs = '?',
    599        smods = {
    600          browse = false,
    601          confirm = false,
    602          emsg_silent = false,
    603          hide = false,
    604          horizontal = false,
    605          keepalt = false,
    606          keepjumps = false,
    607          keepmarks = false,
    608          keeppatterns = false,
    609          lockmarks = false,
    610          noautocmd = false,
    611          noswapfile = false,
    612          sandbox = false,
    613          silent = false,
    614          split = '',
    615          tab = -1,
    616          unsilent = false,
    617          verbose = -1,
    618          vertical = false,
    619        },
    620        range = 0,
    621        count = 2,
    622        reg = '',
    623      },
    624      exec_lua [[
    625      vim.api.nvim_command('CommandWithOneOrNoArg')
    626      return result
    627    ]]
    628    )
    629 
    630    -- f-args is an empty table when the command nargs=0
    631    exec_lua [[
    632      result = {}
    633      vim.api.nvim_create_user_command('CommandWithNoArgs', function(opts)
    634        result = opts
    635      end, {
    636        nargs = 0,
    637        bang = true,
    638        count = 2,
    639        register = true,
    640      })
    641    ]]
    642    eq(
    643      {
    644        name = 'CommandWithNoArgs',
    645        args = '',
    646        fargs = {},
    647        bang = false,
    648        line1 = 1,
    649        line2 = 1,
    650        mods = '',
    651        nargs = '0',
    652        smods = {
    653          browse = false,
    654          confirm = false,
    655          emsg_silent = false,
    656          hide = false,
    657          horizontal = false,
    658          keepalt = false,
    659          keepjumps = false,
    660          keepmarks = false,
    661          keeppatterns = false,
    662          lockmarks = false,
    663          noautocmd = false,
    664          noswapfile = false,
    665          sandbox = false,
    666          silent = false,
    667          split = '',
    668          tab = -1,
    669          unsilent = false,
    670          verbose = -1,
    671          vertical = false,
    672        },
    673        range = 0,
    674        count = 2,
    675        reg = '',
    676      },
    677      exec_lua [[
    678      vim.cmd('CommandWithNoArgs')
    679      return result
    680    ]]
    681    )
    682    -- register can be specified
    683    eq(
    684      {
    685        name = 'CommandWithNoArgs',
    686        args = '',
    687        fargs = {},
    688        bang = false,
    689        line1 = 1,
    690        line2 = 1,
    691        mods = '',
    692        nargs = '0',
    693        smods = {
    694          browse = false,
    695          confirm = false,
    696          emsg_silent = false,
    697          hide = false,
    698          horizontal = false,
    699          keepalt = false,
    700          keepjumps = false,
    701          keepmarks = false,
    702          keeppatterns = false,
    703          lockmarks = false,
    704          noautocmd = false,
    705          noswapfile = false,
    706          sandbox = false,
    707          silent = false,
    708          split = '',
    709          tab = -1,
    710          unsilent = false,
    711          verbose = -1,
    712          vertical = false,
    713        },
    714        range = 0,
    715        count = 2,
    716        reg = '+',
    717      },
    718      exec_lua [[
    719      vim.cmd('CommandWithNoArgs +')
    720      return result
    721    ]]
    722    )
    723  end)
    724 
    725  it('can define buffer-local commands', function()
    726    local bufnr = api.nvim_create_buf(false, false)
    727    api.nvim_buf_create_user_command(bufnr, 'Hello', '', {})
    728    matches('Not an editor command: Hello', pcall_err(command, 'Hello'))
    729    api.nvim_set_current_buf(bufnr)
    730    command('Hello')
    731    assert_alive()
    732    eq(
    733      'Invalid buffer id: 1234',
    734      pcall_err(api.nvim_buf_create_user_command, 1234, 'Hello', '', {})
    735    )
    736    assert_alive()
    737  end)
    738 
    739  it('can use a Lua complete function', function()
    740    exec_lua [[
    741      vim.api.nvim_create_user_command('Test', '', {
    742        nargs = "*",
    743        complete = function(arg, cmdline, pos)
    744          local options = {"aaa", "bbb", "ccc"}
    745          local t = {}
    746          for _, v in ipairs(options) do
    747            if string.find(v, "^" .. arg) then
    748              table.insert(t, v)
    749            end
    750          end
    751          return t
    752        end,
    753      })
    754    ]]
    755 
    756    feed(':Test a<Tab>')
    757    eq('Test aaa', fn.getcmdline())
    758    feed('<C-U>Test b<Tab>')
    759    eq('Test bbb', fn.getcmdline())
    760  end)
    761 
    762  it('no crash when Lua complete function errors #33447', function()
    763    exec_lua([[
    764      vim.api.nvim_create_user_command('Test','', {
    765          nargs = 1,
    766          complete = function() error() end
    767      })
    768    ]])
    769    feed(':Test <Tab>')
    770    eq('E5108: Lua function: [NULL]', api.nvim_get_vvar('errmsg'))
    771    eq('Test ', fn.getcmdline())
    772    assert_alive()
    773  end)
    774 
    775  it('does not allow invalid command names', function()
    776    eq(
    777      "Invalid command name (must start with uppercase): 'test'",
    778      pcall_err(
    779        exec_lua,
    780        [[
    781      vim.api.nvim_create_user_command('test', 'echo "hi"', {})
    782    ]]
    783      )
    784    )
    785    eq(
    786      "Invalid command name: 't@'",
    787      pcall_err(
    788        exec_lua,
    789        [[
    790      vim.api.nvim_create_user_command('t@', 'echo "hi"', {})
    791    ]]
    792      )
    793    )
    794    eq(
    795      "Invalid command name: 'T@st'",
    796      pcall_err(
    797        exec_lua,
    798        [[
    799      vim.api.nvim_create_user_command('T@st', 'echo "hi"', {})
    800    ]]
    801      )
    802    )
    803    eq(
    804      "Invalid command name: 'Test!'",
    805      pcall_err(
    806        exec_lua,
    807        [[
    808      vim.api.nvim_create_user_command('Test!', 'echo "hi"', {})
    809    ]]
    810      )
    811    )
    812    eq(
    813      "Invalid command name: '💩'",
    814      pcall_err(
    815        exec_lua,
    816        [[
    817      vim.api.nvim_create_user_command('💩', 'echo "hi"', {})
    818    ]]
    819      )
    820    )
    821  end)
    822 
    823  it('smods can be used with nvim_cmd', function()
    824    exec_lua [[
    825      vim.api.nvim_create_user_command('MyEcho', function(opts)
    826        vim.api.nvim_cmd({ cmd = 'echo', args = { '&verbose' }, mods = opts.smods }, {})
    827      end, {})
    828    ]]
    829    eq('3', api.nvim_cmd({ cmd = 'MyEcho', mods = { verbose = 3 } }, { output = true }))
    830 
    831    eq(1, #api.nvim_list_tabpages())
    832    exec_lua [[
    833      vim.api.nvim_create_user_command('MySplit', function(opts)
    834        vim.api.nvim_cmd({ cmd = 'split', mods = opts.smods }, {})
    835      end, {})
    836    ]]
    837    api.nvim_cmd({ cmd = 'MySplit' }, {})
    838    eq(1, #api.nvim_list_tabpages())
    839    eq(2, #api.nvim_list_wins())
    840    api.nvim_cmd({ cmd = 'MySplit', mods = { tab = 1 } }, {})
    841    eq(2, #api.nvim_list_tabpages())
    842    eq(2, fn.tabpagenr())
    843    api.nvim_cmd({ cmd = 'MySplit', mods = { tab = 1 } }, {})
    844    eq(3, #api.nvim_list_tabpages())
    845    eq(2, fn.tabpagenr())
    846    api.nvim_cmd({ cmd = 'MySplit', mods = { tab = 3 } }, {})
    847    eq(4, #api.nvim_list_tabpages())
    848    eq(4, fn.tabpagenr())
    849    api.nvim_cmd({ cmd = 'MySplit', mods = { tab = 0 } }, {})
    850    eq(5, #api.nvim_list_tabpages())
    851    eq(1, fn.tabpagenr())
    852  end)
    853 
    854  it('"addr" flag allows ranges without explicit "range" flag', function()
    855    exec_lua([[
    856      vim.api.nvim_create_user_command('Test2', 'echo "hello <line1><line2>"', { addr = 'other' })
    857    ]])
    858    eq('hello 12', n.exec_capture('1,2Test2'))
    859  end)
    860 end)
    861 
    862 describe('nvim_del_user_command', function()
    863  before_each(clear)
    864 
    865  it('can delete global commands', function()
    866    api.nvim_create_user_command('Hello', 'echo "Hi"', {})
    867    command('Hello')
    868    api.nvim_del_user_command('Hello')
    869    matches('Not an editor command: Hello', pcall_err(command, 'Hello'))
    870  end)
    871 
    872  it('can delete buffer-local commands', function()
    873    api.nvim_buf_create_user_command(0, 'Hello', 'echo "Hi"', {})
    874    command('Hello')
    875    api.nvim_buf_del_user_command(0, 'Hello')
    876    matches('Not an editor command: Hello', pcall_err(command, 'Hello'))
    877    eq('Invalid command (not found): Hello', pcall_err(api.nvim_buf_del_user_command, 0, 'Hello'))
    878    eq('Invalid command (not found): Bye', pcall_err(api.nvim_buf_del_user_command, 0, 'Bye'))
    879    eq('Invalid buffer id: 1234', pcall_err(api.nvim_buf_del_user_command, 1234, 'Hello'))
    880    assert_alive()
    881  end)
    882 end)