mirror of
https://github.com/zoriya/lz.n.git
synced 2026-06-08 20:55:06 +00:00
tests: add basic API spec
This commit is contained in:
+2
-2
@@ -8,8 +8,6 @@ error("Cannot import a meta module")
|
|||||||
---
|
---
|
||||||
--- Whether to enable this plugin. Useful to disable plugins under certain conditions.
|
--- Whether to enable this plugin. Useful to disable plugins under certain conditions.
|
||||||
--- @field enabled? boolean|(fun():boolean)
|
--- @field enabled? boolean|(fun():boolean)
|
||||||
--- Whether to lazy-load this plugin. Defaults to `false`.
|
|
||||||
--- @field lazy? boolean
|
|
||||||
---
|
---
|
||||||
--- Only useful for lazy=false plugins to force loading certain plugins first.
|
--- Only useful for lazy=false plugins to force loading certain plugins first.
|
||||||
--- Default priority is 50
|
--- Default priority is 50
|
||||||
@@ -62,6 +60,8 @@ error("Cannot import a meta module")
|
|||||||
--- @field name string
|
--- @field name string
|
||||||
|
|
||||||
--- @class lz.n.Plugin: lz.n.PluginBase,lz.n.PluginHandlers,lz.n.PluginHooks
|
--- @class lz.n.Plugin: lz.n.PluginBase,lz.n.PluginHandlers,lz.n.PluginHooks
|
||||||
|
--- Whether to lazy-load this plugin. Defaults to `false`.
|
||||||
|
--- @field lazy? boolean
|
||||||
|
|
||||||
--- @class lz.n.PluginSpec: lz.n.PluginBase,lz.n.PluginSpecHandlers,lz.n.PluginHooks
|
--- @class lz.n.PluginSpec: lz.n.PluginBase,lz.n.PluginSpecHandlers,lz.n.PluginHooks
|
||||||
|
|
||||||
|
|||||||
@@ -65,6 +65,8 @@ local function parse(spec)
|
|||||||
local ft_spec = spec.ft
|
local ft_spec = spec.ft
|
||||||
if ft_spec then
|
if ft_spec then
|
||||||
result.event = result.event or {}
|
result.event = result.event or {}
|
||||||
|
---@diagnostic disable-next-line: inject-field
|
||||||
|
result.ft = nil
|
||||||
end
|
end
|
||||||
if type(ft_spec) == "string" then
|
if type(ft_spec) == "string" then
|
||||||
local ft = require("lz.n.handler.ft").parse(ft_spec)
|
local ft = require("lz.n.handler.ft").parse(ft_spec)
|
||||||
@@ -100,6 +102,7 @@ local function parse(spec)
|
|||||||
table.insert(result.cmd, _cmd_spec)
|
table.insert(result.cmd, _cmd_spec)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
result.lazy = result.lazy or result.event ~= nil or result.keys ~= nil or result.cmd ~= nil
|
||||||
return result
|
return result
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,46 @@
|
|||||||
|
local lz = require("lz.n")
|
||||||
|
local loader = require("lz.n.loader")
|
||||||
|
local spy = require("luassert.spy")
|
||||||
|
|
||||||
|
describe("lz.n", function()
|
||||||
|
it("load", function()
|
||||||
|
local spy_load = spy.on(loader, "_load")
|
||||||
|
lz.load({
|
||||||
|
{
|
||||||
|
name = "neorg",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name = "crates.nvim",
|
||||||
|
ft = { "toml", "rust" },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name = "telescope.nvim",
|
||||||
|
keys = "<leader>tt",
|
||||||
|
cmd = "Telescope",
|
||||||
|
},
|
||||||
|
})
|
||||||
|
assert.spy(spy_load).called(1)
|
||||||
|
assert.spy(spy_load).called_with({
|
||||||
|
name = "neorg",
|
||||||
|
lazy = false,
|
||||||
|
})
|
||||||
|
vim.api.nvim_exec_autocmds("FileType", { pattern = "toml" })
|
||||||
|
assert.spy(spy_load).called(2)
|
||||||
|
assert.spy(spy_load).called_with({
|
||||||
|
name = "crates.nvim",
|
||||||
|
lazy = true,
|
||||||
|
event = {
|
||||||
|
require("lz.n.handler.ft").parse("toml"),
|
||||||
|
require("lz.n.handler.ft").parse("rust"),
|
||||||
|
},
|
||||||
|
})
|
||||||
|
vim.cmd.Telescope()
|
||||||
|
assert.spy(spy_load).called(3)
|
||||||
|
assert.spy(spy_load).called_with({
|
||||||
|
name = "telescope.nvim",
|
||||||
|
lazy = true,
|
||||||
|
cmd = { "Telescope" },
|
||||||
|
keys = { require("lz.n.handler.keys").parse("<leader>tt") },
|
||||||
|
})
|
||||||
|
end)
|
||||||
|
end)
|
||||||
Reference in New Issue
Block a user