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