Skip to content

Commit

Permalink
tests: add basic API spec
Browse files Browse the repository at this point in the history
  • Loading branch information
mrcjkb committed Jun 10, 2024
1 parent 6740178 commit 3deb6bb
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lua/lz/n/meta.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ error("Cannot import a meta module")
---
--- Whether to enable this plugin. Useful to disable plugins under certain conditions.
--- @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.
--- Default priority is 50
Expand Down Expand Up @@ -62,6 +60,8 @@ error("Cannot import a meta module")
--- @field name string

--- @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

Expand Down
3 changes: 3 additions & 0 deletions lua/lz/n/spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ local function parse(spec)
local ft_spec = spec.ft
if ft_spec then
result.event = result.event or {}
---@diagnostic disable-next-line: inject-field
result.ft = nil
end
if type(ft_spec) == "string" then
local ft = require("lz.n.handler.ft").parse(ft_spec)
Expand Down Expand Up @@ -100,6 +102,7 @@ local function parse(spec)
table.insert(result.cmd, _cmd_spec)
end
end
result.lazy = result.lazy or result.event ~= nil or result.keys ~= nil or result.cmd ~= nil
return result
end

Expand Down
46 changes: 46 additions & 0 deletions spec/lz_n_spec.lua
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 3deb6bb

Please sign in to comment.