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

Code before:
      eq('', fn.getreg('/'))
      eq('', fn.histget('search'))
    end)
    it('result can be used directly by nvim_cmd #20051', function()
      eq('foo', api.nvim_cmd(api.nvim_parse_cmd('echo "foo"', {}), { output = true }))
      api.nvim_cmd(api.nvim_parse_cmd('set cursorline', {}), {})
      eq(true, api.nvim_get_option_value('cursorline', {}))
      -- Roundtrip on :bdelete which does not accept "range". #33394
      api.nvim_cmd(api.nvim_parse_cmd('bdelete', {}), {})
    end)
    it('no side-effects (error messages) in pcall() #20339', function()
      eq(
        { false, 'Parsing command-line: E16: Invalid range' },
        exec_lua([=[return {pcall(vim.api.nvim_parse_cmd, "'<,'>n", {})}]=])
      )
      eq('', eval('v:errmsg'))
    end)
    it('does not include count field when no count provided for builtin commands', function()
      local result = api.nvim_parse_cmd('copen', {})
      eq(nil, result.count)
      api.nvim_cmd(result, {})
      eq(10, api.nvim_win_get_height(0))
      result = api.nvim_parse_cmd('copen 5', {})
      eq(5, result.count)
    end)
    it('correctly parses nextcmd for commands #36029', function()
      local result = api.nvim_parse_cmd('exe "ls"|edit foo', {})
      eq({ '"ls"' }, result.args)
      eq('execute', result.cmd)
      eq('edit foo', result.nextcmd)
    end)
  end)

  describe('nvim_cmd', function()
    it('works', function()
      api.nvim_cmd({ cmd = 'set', args = { 'cursorline' } }, {})
      eq(true, api.nvim_get_option_value('cursorline', {}))
    end)

    it('validation', function()
      eq("Invalid 'cmd': expected non-empty String", pcall_err(api.nvim_cmd, { cmd = '' }, {}))
      eq("Invalid 'cmd': expected String, got Array", pcall_err(api.nvim_cmd, { cmd = {} }, {}))
      eq(
        "Invalid 'args': expected Array, got Boolean",
        pcall_err(api.nvim_cmd, { cmd = 'set', args = true }, {})
      )
      eq(
        'Invalid command arg: expected non-whitespace',
        pcall_err(api.nvim_cmd, { cmd = 'set', args = { '  ' } }, {})
      )
      eq(

Review comment (suggestion):
all tests are assumed to check for correctness.

```suggestion
    it('parses nextcmd for commands #36029', function()
```

Code after:
      eq('', fn.getreg('/'))
      eq('', fn.histget('search'))
    end)
    it('result can be used directly by nvim_cmd #20051', function()
      eq('foo', api.nvim_cmd(api.nvim_parse_cmd('echo "foo"', {}), { output = true }))
      api.nvim_cmd(api.nvim_parse_cmd('set cursorline', {}), {})
      eq(true, api.nvim_get_option_value('cursorline', {}))
      -- Roundtrip on :bdelete which does not accept "range". #33394
      api.nvim_cmd(api.nvim_parse_cmd('bdelete', {}), {})
    end)
    it('no side-effects (error messages) in pcall() #20339', function()
      eq(
        { false, 'Parsing command-line: E16: Invalid range' },
        exec_lua([=[return {pcall(vim.api.nvim_parse_cmd, "'<,'>n", {})}]=])
      )
      eq('', eval('v:errmsg'))
    end)
    it('does not include count field when no count provided for builtin commands', function()
      local result = api.nvim_parse_cmd('copen', {})
      eq(nil, result.count)
      api.nvim_cmd(result, {})
      eq(10, api.nvim_win_get_height(0))
      result = api.nvim_parse_cmd('copen 5', {})
      eq(5, result.count)
    end)
    it('parses nextcmd for commands #36029', function()
      local result = api.nvim_parse_cmd('exe "ls"|edit foo', {})
      eq({ '"ls"' }, result.args)
      eq('execute', result.cmd)
      eq('edit foo', result.nextcmd)
    end)
  end)

  describe('nvim_cmd', function()
    it('works', function()
      api.nvim_cmd({ cmd = 'set', args = { 'cursorline' } }, {})
      eq(true, api.nvim_get_option_value('cursorline', {}))
    end)

    it('validation', function()
      eq("Invalid 'cmd': expected non-empty String", pcall_err(api.nvim_cmd, { cmd = '' }, {}))
      eq("Invalid 'cmd': expected String, got Array", pcall_err(api.nvim_cmd, { cmd = {} }, {}))
      eq(
        "Invalid 'args': expected Array, got Boolean",
        pcall_err(api.nvim_cmd, { cmd = 'set', args = true }, {})
      )
      eq(
        'Invalid command arg: expected non-whitespace',
        pcall_err(api.nvim_cmd, { cmd = 'set', args = { '  ' } }, {})
      )
      eq(