2022-11-29 13:27:58 +00:00
|
|
|
local Config = require("lazy.core.config")
|
|
|
|
local Plugin = require("lazy.core.plugin")
|
|
|
|
|
|
|
|
local assert = require("luassert")
|
|
|
|
|
|
|
|
Config.setup()
|
|
|
|
|
2022-12-06 10:12:54 +00:00
|
|
|
describe("plugin spec url/name", function()
|
2022-11-29 13:27:58 +00:00
|
|
|
local tests = {
|
2022-12-06 10:12:54 +00:00
|
|
|
{ { "~/foo" }, { [1] = "~/foo", name = "foo", url = vim.fn.fnamemodify("~/foo", ":p") } },
|
|
|
|
{ { "/tmp/foo" }, { [1] = "/tmp/foo", name = "foo", url = "/tmp/foo" } },
|
|
|
|
{ { "foo/bar" }, { [1] = "foo/bar", name = "bar", url = "https://github.com/foo/bar.git" } },
|
|
|
|
{ { "foo/bar", name = "foobar" }, { [1] = "foo/bar", name = "foobar", url = "https://github.com/foo/bar.git" } },
|
|
|
|
{ { "foo/bar", url = "123" }, { [1] = "foo/bar", name = "bar", url = "123" } },
|
|
|
|
{ { "https://foobar" }, { [1] = "https://foobar", name = "foobar", url = "https://foobar" } },
|
|
|
|
{ { "ssh://foobar" }, { [1] = "ssh://foobar", name = "foobar", url = "ssh://foobar" } },
|
|
|
|
{ "foo/bar", { [1] = "foo/bar", name = "bar", url = "https://github.com/foo/bar.git" } },
|
|
|
|
{ { { { "foo/bar" } } }, { [1] = "foo/bar", name = "bar", url = "https://github.com/foo/bar.git" } },
|
2022-11-29 13:27:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, test in ipairs(tests) do
|
2022-12-02 16:09:40 +00:00
|
|
|
test[2]._ = {}
|
2022-11-29 18:51:37 +00:00
|
|
|
it("parses " .. vim.inspect(test[1]):gsub("%s+", " "), function()
|
2022-11-29 13:27:58 +00:00
|
|
|
local spec = Plugin.Spec.new(test[1])
|
|
|
|
local plugins = vim.tbl_values(spec.plugins)
|
|
|
|
assert.equal(1, #plugins)
|
|
|
|
assert.same(test[2], plugins[1])
|
|
|
|
end)
|
|
|
|
end
|
|
|
|
end)
|
2022-11-29 18:51:37 +00:00
|
|
|
|
|
|
|
describe("plugin spec opt", function()
|
|
|
|
it("handles dependencies", function()
|
2022-12-01 10:06:44 +00:00
|
|
|
Config.options.defaults.lazy = false
|
2022-11-29 18:51:37 +00:00
|
|
|
local tests = {
|
|
|
|
{ "foo/bar", dependencies = { "foo/dep1", "foo/dep2" } },
|
|
|
|
{ "foo/bar", dependencies = { { "foo/dep1" }, "foo/dep2" } },
|
|
|
|
{ { { "foo/bar", dependencies = { { "foo/dep1" }, "foo/dep2" } } } },
|
|
|
|
}
|
|
|
|
for _, test in ipairs(tests) do
|
|
|
|
local spec = Plugin.Spec.new(test)
|
2022-11-29 23:18:59 +00:00
|
|
|
Config.plugins = spec.plugins
|
|
|
|
Plugin.update_state()
|
2022-11-29 18:51:37 +00:00
|
|
|
assert(vim.tbl_count(spec.plugins) == 3)
|
|
|
|
assert(#spec.plugins.bar.dependencies == 2)
|
2022-12-02 16:09:40 +00:00
|
|
|
assert(spec.plugins.bar._.dep ~= true)
|
2022-12-01 10:06:44 +00:00
|
|
|
assert(spec.plugins.bar.lazy == false)
|
2022-12-02 16:09:40 +00:00
|
|
|
assert(spec.plugins.dep1._.dep == true)
|
2022-12-01 10:06:44 +00:00
|
|
|
assert(spec.plugins.dep1.lazy == true)
|
2022-12-02 16:09:40 +00:00
|
|
|
assert(spec.plugins.dep2._.dep == true)
|
2022-12-01 10:06:44 +00:00
|
|
|
assert(spec.plugins.dep2.lazy == true)
|
2022-11-29 18:51:37 +00:00
|
|
|
end
|
|
|
|
end)
|
|
|
|
|
|
|
|
it("handles opt from dep", function()
|
2022-12-01 10:06:44 +00:00
|
|
|
Config.options.defaults.lazy = false
|
2022-11-29 18:51:37 +00:00
|
|
|
local spec = Plugin.Spec.new({ "foo/dep1", { "foo/bar", dependencies = { "foo/dep1", "foo/dep2" } } })
|
2022-11-29 23:18:59 +00:00
|
|
|
Config.plugins = spec.plugins
|
|
|
|
Plugin.update_state()
|
2022-11-29 18:51:37 +00:00
|
|
|
assert.same(3, vim.tbl_count(spec.plugins))
|
2022-12-02 16:09:40 +00:00
|
|
|
assert(spec.plugins.bar._.dep ~= true)
|
2022-12-01 10:06:44 +00:00
|
|
|
assert(spec.plugins.bar.lazy == false)
|
2022-12-02 16:09:40 +00:00
|
|
|
assert(spec.plugins.dep2._.dep == true)
|
2022-12-01 10:06:44 +00:00
|
|
|
assert(spec.plugins.dep2.lazy == true)
|
2022-12-02 16:09:40 +00:00
|
|
|
assert(spec.plugins.dep1._.dep ~= true)
|
2022-12-01 10:06:44 +00:00
|
|
|
assert(spec.plugins.dep1.lazy == false)
|
2022-11-29 18:51:37 +00:00
|
|
|
end)
|
|
|
|
|
2022-11-30 22:14:16 +00:00
|
|
|
it("handles defaults opt", function()
|
|
|
|
do
|
2022-12-01 10:06:44 +00:00
|
|
|
Config.options.defaults.lazy = true
|
2022-11-30 22:14:16 +00:00
|
|
|
local spec = Plugin.Spec.new({ "foo/bar" })
|
|
|
|
Config.plugins = spec.plugins
|
|
|
|
Plugin.update_state()
|
2022-12-01 10:06:44 +00:00
|
|
|
assert(spec.plugins.bar.lazy == true)
|
2022-11-30 22:14:16 +00:00
|
|
|
end
|
|
|
|
do
|
2022-12-01 10:06:44 +00:00
|
|
|
Config.options.defaults.lazy = false
|
2022-11-30 22:14:16 +00:00
|
|
|
local spec = Plugin.Spec.new({ "foo/bar" })
|
|
|
|
Config.plugins = spec.plugins
|
|
|
|
Plugin.update_state()
|
2022-12-01 10:06:44 +00:00
|
|
|
assert(spec.plugins.bar.lazy == false)
|
2022-11-30 22:14:16 +00:00
|
|
|
end
|
|
|
|
end)
|
|
|
|
|
2022-11-29 18:58:23 +00:00
|
|
|
it("handles opt from dep", function()
|
2022-12-01 10:06:44 +00:00
|
|
|
Config.options.defaults.lazy = false
|
2022-12-02 08:23:27 +00:00
|
|
|
local spec = Plugin.Spec.new({ "foo/bar", event = "foo" })
|
2022-11-29 23:18:59 +00:00
|
|
|
Config.plugins = spec.plugins
|
|
|
|
Plugin.update_state()
|
2022-11-29 18:58:23 +00:00
|
|
|
assert.same(1, vim.tbl_count(spec.plugins))
|
2022-12-02 16:09:40 +00:00
|
|
|
assert(spec.plugins.bar._.dep ~= true)
|
2022-12-01 10:06:44 +00:00
|
|
|
assert(spec.plugins.bar.lazy == true)
|
2022-11-29 18:58:23 +00:00
|
|
|
end)
|
|
|
|
|
2022-11-29 18:51:37 +00:00
|
|
|
it("merges lazy loaders", function()
|
|
|
|
local tests = {
|
2022-12-02 08:23:27 +00:00
|
|
|
{ { "foo/bar", event = "mod1" }, { "foo/bar", event = "mod2" } },
|
|
|
|
{ { "foo/bar", event = { "mod1" } }, { "foo/bar", event = { "mod2" } } },
|
|
|
|
{ { "foo/bar", event = "mod1" }, { "foo/bar", event = { "mod2" } } },
|
2022-11-29 18:51:37 +00:00
|
|
|
}
|
|
|
|
for _, test in ipairs(tests) do
|
|
|
|
local spec = Plugin.Spec.new(test)
|
|
|
|
assert(vim.tbl_count(spec.plugins) == 1)
|
2022-12-02 08:23:27 +00:00
|
|
|
assert(type(spec.plugins.bar.event) == "table")
|
|
|
|
assert(#spec.plugins.bar.event == 2)
|
|
|
|
assert(vim.tbl_contains(spec.plugins.bar.event, "mod1"))
|
|
|
|
assert(vim.tbl_contains(spec.plugins.bar.event, "mod2"))
|
2022-11-29 18:51:37 +00:00
|
|
|
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)
|