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

Code before:

    it('returns list of available plugins', function()
      -- Should work just after installation
      exec_lua(function()
        vim.pack.add({ repos_src.defbranch, repos_src.basic })
      end)
      eq({
        -- Should preserve order in which plugins were `vim.pack.add()`ed
        { active = true, path = defbranch_path, spec = defbranch_spec },
        { active = true, path = basic_path, spec = basic_spec },
      }, exec_lua('return vim.pack.get()'))

      -- Should also list non-active plugins
      n.clear()

      exec_lua(function()
        vim.pack.add({ repos_src.basic })
      end)
      eq({
        -- Should first list active, then non-active
        { active = true, path = basic_path, spec = basic_spec },
        { active = false, path = defbranch_path, spec = defbranch_spec },
      }, exec_lua('return vim.pack.get()'))
    end)

    it('vim.pack.add passes extra spec values through to vim.pack.get()', function()
      eq(true, exec_lua(function()
        vim.pack.add {
          { src = repos_src.basic, data = { test = "value" } },
        }
        for _, p in ipairs(vim.pack.get()) do
          if p.spec.name == 'basic' and p.spec.data.test == "value" then
            return true
          end
        end
        return false
      end))
    end)

    it('works with `del()`', function()
      exec_lua(function()
        vim.pack.add({ repos_src.defbranch, repos_src.basic })
      end)

      exec_lua(function()
        _G.get_log = {}
        vim.api.nvim_create_autocmd({ 'PackChangedPre', 'PackChanged' }, {
          callback = function()
            table.insert(_G.get_log, vim.pack.get())
          end,
        })

Review comment (suggestion):
```suggestion
    it('respects extra spec fields', function()
```

Code after:
        vim.pack.update({})
      end)
      eq('vim.pack: Nothing to update', n.exec_capture('messages'))
    end)
  end)

  describe('get()', function()
    local basic_spec = { name = 'basic', src = repos_src.basic, version = 'main' }
    local basic_path = pack_get_plug_path('basic')
    local defbranch_spec = { name = 'defbranch', src = repos_src.defbranch, version = 'dev' }
    local defbranch_path = pack_get_plug_path('defbranch')

    it('returns list of available plugins', function()
      -- Should work just after installation
      exec_lua(function()
        vim.pack.add({ repos_src.defbranch, repos_src.basic })
      end)
      eq({
        -- Should preserve order in which plugins were `vim.pack.add()`ed
        { active = true, path = defbranch_path, spec = defbranch_spec },
        { active = true, path = basic_path, spec = basic_spec },
      }, exec_lua('return vim.pack.get()'))

      -- Should also list non-active plugins
      n.clear()

      exec_lua(function()
        vim.pack.add({ repos_src.basic })
      end)
      eq({
        -- Should first list active, then non-active
        { active = true, path = basic_path, spec = basic_spec },
        { active = false, path = defbranch_path, spec = defbranch_spec },
      }, exec_lua('return vim.pack.get()'))
    end)

    it('respects data field', function()
      eq(
        true,
        exec_lua(function()
          vim.pack.add {
            { src = repos_src.basic, data = { test = 'value' } },
          }
          for _, p in ipairs(vim.pack.get()) do
            if p.spec.name == 'basic' and p.spec.data.test == 'value' then
              return true
            end
          end
          return false
        end)
      )