mirror of https://github.com/folke/lazy.nvim.git
test: fixed tests
This commit is contained in:
parent
47dafaed64
commit
c6831d2126
|
@ -48,12 +48,7 @@ end
|
||||||
function M.enable(plugin)
|
function M.enable(plugin)
|
||||||
if not plugin._.loaded then
|
if not plugin._.loaded then
|
||||||
if not plugin._.handlers then
|
if not plugin._.handlers then
|
||||||
plugin._.handlers = {}
|
M.load(plugin)
|
||||||
for type, handler in pairs(M.handlers) do
|
|
||||||
if plugin[type] then
|
|
||||||
handler:load(plugin)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
for type in pairs(plugin._.handlers or {}) do
|
for type in pairs(plugin._.handlers or {}) do
|
||||||
M.handlers[type]:add(plugin)
|
M.handlers[type]:add(plugin)
|
||||||
|
@ -103,9 +98,14 @@ function M:_values(values, plugin)
|
||||||
end
|
end
|
||||||
|
|
||||||
---@param plugin LazyPlugin
|
---@param plugin LazyPlugin
|
||||||
function M:load(plugin)
|
function M.load(plugin)
|
||||||
local Plugin = require("lazy.core.plugin")
|
local Plugin = require("lazy.core.plugin")
|
||||||
plugin._.handlers[self.type] = self:_values(Plugin.values(plugin, self.type, true), plugin)
|
plugin._.handlers = {}
|
||||||
|
for type, handler in pairs(M.handlers) do
|
||||||
|
if plugin[type] then
|
||||||
|
plugin._.handlers[type] = handler:_values(Plugin.values(plugin, type, true), plugin)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
---@param plugin LazyPlugin
|
---@param plugin LazyPlugin
|
||||||
|
|
|
@ -24,7 +24,7 @@ local Util = require("lazy.core.util")
|
||||||
---@class LazyKeysHandler:LazyHandler
|
---@class LazyKeysHandler:LazyHandler
|
||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
local skip = { mode = true, id = true, ft = true, rhs = true, lhs = true, name = true }
|
local skip = { mode = true, id = true, ft = true, rhs = true, lhs = true }
|
||||||
|
|
||||||
---@param value string|LazyKeysSpec
|
---@param value string|LazyKeysSpec
|
||||||
---@param mode? string
|
---@param mode? string
|
||||||
|
@ -40,15 +40,18 @@ function M.parse(value, mode)
|
||||||
ret[2] = nil
|
ret[2] = nil
|
||||||
ret.mode = mode or "n"
|
ret.mode = mode or "n"
|
||||||
ret.id = vim.api.nvim_replace_termcodes(ret.lhs, true, true, true)
|
ret.id = vim.api.nvim_replace_termcodes(ret.lhs, true, true, true)
|
||||||
ret.name = ret.lhs
|
|
||||||
|
|
||||||
if ret.mode ~= "n" then
|
if ret.mode ~= "n" then
|
||||||
ret.id = ret.id .. " (" .. ret.mode .. ")"
|
ret.id = ret.id .. " (" .. ret.mode .. ")"
|
||||||
ret.name = ret.name .. " (" .. ret.mode .. ")"
|
|
||||||
end
|
end
|
||||||
return ret
|
return ret
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---@param keys LazyKeys
|
||||||
|
function M.to_string(keys)
|
||||||
|
return keys.lhs .. (keys.mode == "n" and "" or " (" .. keys.mode .. ")")
|
||||||
|
end
|
||||||
|
|
||||||
---@param lhs string
|
---@param lhs string
|
||||||
---@param mode? string
|
---@param mode? string
|
||||||
function M:have(lhs, mode)
|
function M:have(lhs, mode)
|
||||||
|
@ -109,8 +112,9 @@ function M:_add(keys)
|
||||||
self.active[keys.id] = nil
|
self.active[keys.id] = nil
|
||||||
|
|
||||||
if plugins then
|
if plugins then
|
||||||
Util.track({ keys = keys.name })
|
local name = M.to_string(keys)
|
||||||
Loader.load(plugins, { keys = keys.name })
|
Util.track({ keys = name })
|
||||||
|
Loader.load(plugins, { keys = name })
|
||||||
Util.track()
|
Util.track()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
local Config = require("lazy.core.config")
|
local Config = require("lazy.core.config")
|
||||||
local Git = require("lazy.manage.git")
|
local Git = require("lazy.manage.git")
|
||||||
local Handler = require("lazy.core.handler")
|
local Handler = require("lazy.core.handler")
|
||||||
|
local Keys = require("lazy.core.handler.keys")
|
||||||
local Plugin = require("lazy.core.plugin")
|
local Plugin = require("lazy.core.plugin")
|
||||||
local Sections = require("lazy.view.sections")
|
local Sections = require("lazy.view.sections")
|
||||||
local Util = require("lazy.util")
|
local Util = require("lazy.util")
|
||||||
|
@ -546,7 +547,7 @@ function M:handlers(plugin, types)
|
||||||
types = types and types or vim.tbl_keys(Handler.types)
|
types = types and types or vim.tbl_keys(Handler.types)
|
||||||
for _, t in ipairs(types) do
|
for _, t in ipairs(types) do
|
||||||
for id, value in pairs(plugin._.handlers[t] or {}) do
|
for id, value in pairs(plugin._.handlers[t] or {}) do
|
||||||
value = t == "keys" and value.name or id
|
value = t == "keys" and Keys.to_string(value) or id
|
||||||
self:reason({ [t] = value })
|
self:reason({ [t] = value })
|
||||||
self:append(" ")
|
self:append(" ")
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
local Config = require("lazy.core.config")
|
local Config = require("lazy.core.config")
|
||||||
|
local Handler = require("lazy.core.handler")
|
||||||
local Plugin = require("lazy.core.plugin")
|
local Plugin = require("lazy.core.plugin")
|
||||||
|
|
||||||
local assert = require("luassert")
|
local assert = require("luassert")
|
||||||
|
@ -142,6 +143,9 @@ describe("plugin spec opt", function()
|
||||||
end)
|
end)
|
||||||
|
|
||||||
describe("deps", function()
|
describe("deps", function()
|
||||||
|
before_each(function()
|
||||||
|
Handler.init()
|
||||||
|
end)
|
||||||
it("handles dep names", function()
|
it("handles dep names", function()
|
||||||
Config.options.defaults.lazy = false
|
Config.options.defaults.lazy = false
|
||||||
local tests = {
|
local tests = {
|
||||||
|
@ -237,11 +241,13 @@ describe("plugin spec opt", function()
|
||||||
local spec = Plugin.Spec.new(test)
|
local spec = Plugin.Spec.new(test)
|
||||||
assert(#spec.notifs == 0)
|
assert(#spec.notifs == 0)
|
||||||
assert(vim.tbl_count(spec.plugins) == 1)
|
assert(vim.tbl_count(spec.plugins) == 1)
|
||||||
Plugin.values(spec.plugins.bar, "event", true)
|
Handler.load(spec.plugins.bar)
|
||||||
assert(type(spec.plugins.bar.event) == "table")
|
vim.print(spec.plugins.bar._.handlers)
|
||||||
assert(#spec.plugins.bar.event == 2)
|
local events = vim.tbl_keys(spec.plugins.bar._.handlers.event or {})
|
||||||
assert(vim.tbl_contains(spec.plugins.bar.event, "mod1"))
|
assert(type(events) == "table")
|
||||||
assert(vim.tbl_contains(spec.plugins.bar.event, "mod2"))
|
assert(#events == 2)
|
||||||
|
assert(vim.tbl_contains(events, "mod1"))
|
||||||
|
assert(vim.tbl_contains(events, "mod2"))
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
|
@ -297,14 +303,16 @@ describe("plugin spec opt", function()
|
||||||
{ { "foo/bar", event = "mod1" }, { "foo/bar", event = { "mod2" } } },
|
{ { "foo/bar", event = "mod1" }, { "foo/bar", event = { "mod2" } } },
|
||||||
}
|
}
|
||||||
for _, test in ipairs(tests) do
|
for _, test in ipairs(tests) do
|
||||||
|
Handler.init()
|
||||||
local spec = Plugin.Spec.new(test)
|
local spec = Plugin.Spec.new(test)
|
||||||
assert(#spec.notifs == 0)
|
assert(#spec.notifs == 0)
|
||||||
assert(vim.tbl_count(spec.plugins) == 1)
|
assert(vim.tbl_count(spec.plugins) == 1)
|
||||||
Plugin.values(spec.plugins.bar, "event", true)
|
Handler.load(spec.plugins.bar)
|
||||||
assert(type(spec.plugins.bar.event) == "table")
|
local events = spec.plugins.bar._.handlers.event
|
||||||
assert(#spec.plugins.bar.event == 2)
|
assert(type(events) == "table")
|
||||||
assert(vim.tbl_contains(spec.plugins.bar.event, "mod1"))
|
assert(vim.tbl_count(events) == 2)
|
||||||
assert(vim.tbl_contains(spec.plugins.bar.event, "mod2"))
|
assert(events["mod1"])
|
||||||
|
assert(events["mod2"])
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue