mirror of
https://github.com/folke/lazy.nvim.git
synced 2025-04-18 20:36:45 +00:00
feat: dependencies are opt=true by default if they only appear as a dep
This commit is contained in:
parent
5810635a26
commit
908b9adf9c
6 changed files with 128 additions and 26 deletions
|
@ -5,7 +5,7 @@ local assert = require("luassert")
|
|||
|
||||
Config.setup()
|
||||
|
||||
describe("plugin spec", function()
|
||||
describe("plugin spec uri/name", function()
|
||||
local tests = {
|
||||
{ { "~/foo" }, { [1] = "~/foo", name = "foo", uri = vim.fn.fnamemodify("~/foo", ":p") } },
|
||||
{ { "/tmp/foo" }, { [1] = "/tmp/foo", name = "foo", uri = "/tmp/foo" } },
|
||||
|
@ -19,7 +19,7 @@ describe("plugin spec", function()
|
|||
}
|
||||
|
||||
for _, test in ipairs(tests) do
|
||||
it("parses uri " .. vim.inspect(test[1]):gsub("%s+", " "), function()
|
||||
it("parses " .. vim.inspect(test[1]):gsub("%s+", " "), function()
|
||||
local spec = Plugin.Spec.new(test[1])
|
||||
local plugins = vim.tbl_values(spec.plugins)
|
||||
assert.equal(1, #plugins)
|
||||
|
@ -27,3 +27,67 @@ describe("plugin spec", function()
|
|||
end)
|
||||
end
|
||||
end)
|
||||
|
||||
describe("plugin spec opt", function()
|
||||
it("handles dependencies", function()
|
||||
local tests = {
|
||||
{ "foo/bar", dependencies = { "foo/dep1", "foo/dep2" } },
|
||||
{ "foo/bar", dependencies = { { "foo/dep1" }, "foo/dep2" } },
|
||||
{ { { "foo/bar", dependencies = { { "foo/dep1" }, "foo/dep2" } } } },
|
||||
}
|
||||
Config.options.opt = false
|
||||
for _, test in ipairs(tests) do
|
||||
local spec = Plugin.Spec.new(test)
|
||||
Plugin.update_state({ plugins = spec.plugins })
|
||||
assert(vim.tbl_count(spec.plugins) == 3)
|
||||
assert(#spec.plugins.bar.dependencies == 2)
|
||||
assert(spec.plugins.bar.dep ~= true)
|
||||
assert(spec.plugins.bar.opt == false)
|
||||
assert(spec.plugins.dep1.dep == true)
|
||||
assert(spec.plugins.dep1.opt == true)
|
||||
assert(spec.plugins.dep2.dep == true)
|
||||
assert(spec.plugins.dep2.opt == true)
|
||||
end
|
||||
end)
|
||||
|
||||
it("handles opt from dep", function()
|
||||
Config.options.opt = false
|
||||
local spec = Plugin.Spec.new({ "foo/dep1", { "foo/bar", dependencies = { "foo/dep1", "foo/dep2" } } })
|
||||
Plugin.update_state({ plugins = spec.plugins })
|
||||
assert.same(3, vim.tbl_count(spec.plugins))
|
||||
assert(spec.plugins.bar.dep ~= true)
|
||||
assert(spec.plugins.bar.opt == false)
|
||||
assert(spec.plugins.dep2.dep == true)
|
||||
assert(spec.plugins.dep2.opt == true)
|
||||
assert(spec.plugins.dep1.dep ~= true)
|
||||
assert(spec.plugins.dep1.opt == false)
|
||||
end)
|
||||
|
||||
it("merges lazy loaders", function()
|
||||
local tests = {
|
||||
{ { "foo/bar", module = "mod1" }, { "foo/bar", module = "mod2" } },
|
||||
{ { "foo/bar", module = { "mod1" } }, { "foo/bar", module = { "mod2" } } },
|
||||
{ { "foo/bar", module = "mod1" }, { "foo/bar", module = { "mod2" } } },
|
||||
}
|
||||
for _, test in ipairs(tests) do
|
||||
local spec = Plugin.Spec.new(test)
|
||||
assert(vim.tbl_count(spec.plugins) == 1)
|
||||
assert(type(spec.plugins.bar.module) == "table")
|
||||
assert(#spec.plugins.bar.module == 2)
|
||||
assert(vim.tbl_contains(spec.plugins.bar.module, "mod1"))
|
||||
assert(vim.tbl_contains(spec.plugins.bar.module, "mod2"))
|
||||
end
|
||||
end)
|
||||
|
||||
it("refuses to merge", function()
|
||||
assert.has.errors(function()
|
||||
Plugin.Spec.new({
|
||||
{ "foo/dep1", config = 1 },
|
||||
{
|
||||
"foo/bar",
|
||||
dependencies = { { "foo/dep1", config = 2 }, "foo/dep2" },
|
||||
},
|
||||
})
|
||||
end)
|
||||
end)
|
||||
end)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue