Repository: neovim/neovim
File: test/functional/plugin/pack_spec.lua (Lua)

Code before:
      it('updates lockfile', function()
        exec_lua(function()
          vim.pack.add({ repos_src.fetch })
        end)
        local ref_fetch_lock = { rev = hashes.fetch_head, src = repos_src.fetch }
        eq(ref_fetch_lock, get_lock_tbl().plugins.fetch)

        exec_lua('vim.pack.update()')
        n.exec('write')

        ref_fetch_lock.rev = git_get_hash('main', 'fetch')
        eq(ref_fetch_lock, get_lock_tbl().plugins.fetch)
      end)
    end)

    it('works with not active plugins', function()
      -- No plugins are added, but they are installed in `before_each()`
      exec_lua(function()
        -- By default should also include not active plugins
        vim.pack.update()
      end)
      eq({ 'return "fetch main"' }, fn.readfile(fetch_lua_file))
      n.exec('write')
      eq({ 'return "fetch new 2"' }, fn.readfile(fetch_lua_file))
    end)

    it('can force update', function()
      exec_lua(function()
        vim.pack.add({ repos_src.fetch })
        vim.pack.update({ 'fetch' }, { force = true })
      end)

      -- Apply changes immediately
      local fetch_src = repos_src.fetch
      local fetch_path = pack_get_plug_path('fetch')
      eq({ 'return "fetch new 2"' }, fn.readfile(fetch_lua_file))

      -- No special buffer/window/tabpage
      eq(1, #api.nvim_list_tabpages())
      eq(1, #api.nvim_list_wins())
      eq('', api.nvim_get_option_value('filetype', {}))

      -- Write to log file
      hashes.fetch_new = git_get_hash('main', 'fetch')
      hashes.fetch_new_prev = git_get_hash('main~', 'fetch')

      local log_path = vim.fs.joinpath(fn.stdpath('log'), 'nvim-pack.log')
      local log_lines = fn.readfile(log_path)
      matches('========== Update %d%d%d%d%-%d%d%-%d%d %d%d:%d%d:%d%d ==========', log_lines[1])
      local ref_log_lines = {
        '# Update ───────────────────────────────────────────────────────────────────────',

Review comment (suggestion):
If these are test assertions let's always use `assert`. We are pretty consistent about that (in some places we use `expect`, but `assert` everywhere else). And we are consistent about "validate" denoting parameter/input validation (not a test concept).
```suggestion
        assert_action({ 1, 1 }, {}, 0)
```

Code after:
        end)

        local ref_lockfile = get_lock_tbl() --- @type vim.pack.Lock

        local function validate_action(pos, action_titles, select_idx)
          api.nvim_win_set_cursor(0, pos)

          local lines = api.nvim_buf_get_lines(0, 0, -1, false)
          n.exec_lua(function()
            _G.select_items = nil
            _G.select_idx = select_idx
            vim.lsp.buf.code_action()
          end)
          local titles = vim.tbl_map(function(x) --- @param x table
            return x.action.title
          end, n.exec_lua('return _G.select_items or {}'))
          eq(titles, action_titles)

          -- If no action is asked (like via cancel), should not delete lines
          if select_idx <= 0 then
            eq(lines, api.nvim_buf_get_lines(0, 0, -1, false))
          end
        end

        -- - Should not include "namespace" header as "plugin at cursor"
        validate_action({ 1, 1 }, {}, 0)
        validate_action({ 2, 0 }, {}, 0)
        -- - Only deletion should be available on errored plugin
        validate_action({ 3, 1 }, { 'Delete `defbranch`' }, 0)
        validate_action({ 7, 0 }, { 'Delete `defbranch`' }, 0)
        -- - Should not include separator blank line as "plugin at cursor"
        validate_action({ 8, 0 }, {}, 0)
        validate_action({ 9, 0 }, {}, 0)
        validate_action({ 10, 0 }, {}, 0)
        -- - Should also suggest updating related actions if updates available
        local fetch_actions = { 'Update `fetch`', 'Skip updating `fetch`', 'Delete `fetch`' }
        validate_action({ 11, 0 }, fetch_actions, 0)
        validate_action({ 14, 0 }, fetch_actions, 0)
        validate_action({ 20, 0 }, fetch_actions, 0)
        validate_action({ 21, 0 }, {}, 0)
        validate_action({ 22, 0 }, {}, 0)
        validate_action({ 23, 0 }, {}, 0)
        -- - Only deletion should be available on plugins without update
        validate_action({ 24, 0 }, { 'Delete `semver`' }, 0)
        validate_action({ 28, 0 }, { 'Delete `semver`' }, 0)
        validate_action({ 32, 0 }, { 'Delete `semver`' }, 0)

        -- - Should correctly perform action and remove plugin's lines
        local function line_match(lnum, pattern)
          matches(pattern, api.nvim_buf_get_lines(0, lnum - 1, lnum, false)[1])
        end