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

Code before:
      result = exec_lua([[
        vim.cmd(vim.api.nvim_parse_cmd('edit +/Line\\ 2 testfile', {}))
        return vim.fn.line('.')
      ]])
      eq(2, result)

      -- Test +{command} command (execute a command after opening the file)
      result = exec_lua([[
        vim.cmd(vim.api.nvim_parse_cmd('edit +set nomodifiable testfile', {}))
        return vim.bo.modifiable
      ]])
      eq(false, result)

      -- Clean up
      os.remove('testfile')
    end)

    it('handles ++ff correctly', function()
      exec_lua [[
        vim.cmd(vim.api.nvim_parse_cmd('edit ++ff=mac test.txt', {}))
      ]]
      eq('mac', api.nvim_get_option_value('fileformat', {}))
      eq('test.txt', fn.fnamemodify(api.nvim_buf_get_name(0), ':t'))
    end)

    it('handles ++fileformat correctly', function()
      exec_lua [[
        vim.cmd(vim.api.nvim_parse_cmd('edit ++fileformat=unix test.txt', {}))
      ]]
      eq('unix', api.nvim_get_option_value('fileformat', {}))
      eq('test.txt', fn.fnamemodify(api.nvim_buf_get_name(0), ':t'))
    end)

    it('handles ++enc correctly', function()
      exec_lua [[
        vim.cmd(vim.api.nvim_parse_cmd('edit ++enc=utf-32 test.txt', {}))
      ]]
      eq('ucs-4', api.nvim_get_option_value('fileencoding', {}))
      eq('test.txt', fn.fnamemodify(api.nvim_buf_get_name(0), ':t'))
    end)

    it('handles ++bin correctly', function()
      exec_lua [[
        vim.cmd(vim.api.nvim_parse_cmd('edit ++bin test.txt', {}))
      ]]
      eq(true, api.nvim_get_option_value('binary', {}))
      eq('test.txt', fn.fnamemodify(api.nvim_buf_get_name(0), ':t'))
    end)

    it('handles ++nobin correctly', function()
      exec_lua [[

Review comment (suggestion):
these tests can be combined.

please look for similar opportunities in the other tests. avoid verbose, single-purpose tests when multiple related things can be covered in a single test.

Code after:
          _G.success = true
        end, {})
      ]])
      pcall_err(command, 'Test')
      assert_alive()
      eq(false, exec_lua('return _G.success'))
    end)

    it('handles +flags correctly', function()
      -- Write a file for testing +flags
      t.write_file('testfile', 'Line 1\nLine 2\nLine 3', false, false)

      -- Test + command (go to the last line)
      local result = exec_lua([[
        local parsed = vim.api.nvim_parse_cmd('edit + testfile', {})
        vim.cmd(parsed)
        return { vim.fn.line('.'), parsed.args, parsed.cmd }
      ]])
      eq({ 3, { '+ testfile' }, 'edit' }, result)

      -- Test +{num} command (go to line number)
      result = exec_lua([[
        vim.cmd(vim.api.nvim_parse_cmd('edit +1 testfile', {}))
        return vim.fn.line('.')
      ]])
      eq(1, result)

      -- Test +/{pattern} command (go to line with pattern)
      result = exec_lua([[
        local parsed = vim.api.nvim_parse_cmd('edit +/Line\\ 2 testfile', {})
        vim.cmd(parsed)
        return {vim.fn.line('.'), parsed.args}
      ]])
      eq({ 2, { '+/Line\\ 2 testfile' } }, result)

      -- Test +{command} command (execute a command after opening the file)
      result = exec_lua([[
        vim.cmd(vim.api.nvim_parse_cmd('edit +set\\ nomodifiable testfile', {}))
        return vim.bo.modifiable
      ]])
      eq(false, result)

      -- Test ++ flags structure in parsed command
      result = exec_lua([[
        local parsed = vim.api.nvim_parse_cmd('botright edit + testfile', {})
        vim.cmd(parsed)
        return { vim.fn.line('.'), parsed.cmd, parsed.args, parsed.mods.split }
      ]])
      eq({ 3, 'edit', { '+ testfile' }, 'botright' }, result)

      -- Clean up