Repository: neovim/neovim
File: test/functional/api/command_spec.lua (Lua)

Code before:
      count = NIL,
      definition = 'call \128\253R3_ohyeah()',
      name = 'Cmd3',
      nargs = '0',
      range = NIL,
      register = false,
      keepscript = false,
      script_id = 3,
    }
    local cmd4 = {
      addr = NIL,
      bang = false,
      bar = false,
      complete = NIL,
      complete_arg = NIL,
      count = NIL,
      definition = 'call \128\253R4_just_great()',
      name = 'Cmd4',
      nargs = '0',
      range = NIL,
      register = true,
      keepscript = false,
      script_id = 4,
    }
    source([[
      let s:foo = 1
      command -complete=custom,ListUsers -nargs=+ Finger !finger <args>
    ]])
    eq({ Finger = cmd1 }, api.nvim_get_commands({ builtin = false }))
    command('command -nargs=1 -complete=dir -addr=arguments -count=10 TestCmd pwd <args>')
    eq({ Finger = cmd1, TestCmd = cmd0 }, api.nvim_get_commands({ builtin = false }))

    source([[
      function! s:foo() abort
      endfunction
      command -bang -nargs=* Cmd2 call <SID>foo(<q-args>)
    ]])
    source([[
      function! s:ohyeah() abort
      endfunction
      command -bar -nargs=0 Cmd3 call <SID>ohyeah()
    ]])
    source([[
      function! s:just_great() abort
      endfunction
      command -register Cmd4 call <SID>just_great()
    ]])
    -- TODO(justinmk): Order is stable but undefined. Sort before return?
    eq(
      { Cmd2 = cmd2, Cmd3 = cmd3, Cmd4 = cmd4, Finger = cmd1, TestCmd = cmd0 },
      api.nvim_get_commands({ builtin = false })

Review comment (suggestion):
I was going to ask what is the behavior when called via RPC. It looks like the API automatically omits the Lua function results, correct?

Actually, all of these cases were `preview=false`, so maybe this test needs a tweak to confirm what happens in the "truthy" case. (I.e. define a `preview` function, and perhaps also a string command if that is not already tested.)

Code after:
      count = NIL,
      definition = 'call \128\253R3_ohyeah()',
      name = 'Cmd3',
      nargs = '0',
      range = NIL,
      register = false,
      keepscript = false,
      script_id = 3,
    }
    local cmd4 = {
      addr = NIL,
      bang = false,
      bar = false,
      complete = NIL,
      complete_arg = NIL,
      count = NIL,
      definition = 'call \128\253R4_just_great()',
      name = 'Cmd4',
      nargs = '0',
      range = NIL,
      register = true,
      keepscript = false,
      script_id = 4,
    }
    source([[
      let s:foo = 1
      command -complete=custom,ListUsers -nargs=+ Finger !finger <args>
    ]])
    eq({ Finger = cmd1 }, api.nvim_get_commands({ builtin = false }))
    command('command -nargs=1 -complete=dir -addr=arguments -count=10 TestCmd pwd <args>')
    eq({ Finger = cmd1, TestCmd = cmd0 }, api.nvim_get_commands({ builtin = false }))

    source([[
      function! s:foo() abort
      endfunction
      command -bang -nargs=* Cmd2 call <SID>foo(<q-args>)
    ]])
    source([[
      function! s:ohyeah() abort
      endfunction
      command -bar -nargs=0 Cmd3 call <SID>ohyeah()
    ]])
    source([[
      function! s:just_great() abort
      endfunction
      command -register Cmd4 call <SID>just_great()
    ]])
    source([[
      function! s:cpt() abort
        return 1
      endfunction