mirror of
https://github.com/zoriya/lz.n.git
synced 2025-12-23 15:15:11 +00:00
tests: add ft_spec
This commit is contained in:
@@ -23,4 +23,9 @@ function M.add(plugin)
|
||||
event.add(plugin)
|
||||
end
|
||||
|
||||
---@param plugin LzPlugin
|
||||
function M.del(plugin)
|
||||
event.del(plugin)
|
||||
end
|
||||
|
||||
return M
|
||||
|
||||
@@ -33,7 +33,6 @@ error("Cannot import a meta module")
|
||||
|
||||
---@class LzPluginHandlers
|
||||
---@field event? LzEvent[]
|
||||
---@field ft? LzEvent[]
|
||||
---@field keys? LzKeys[]
|
||||
---@field cmd? string[]
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ local state = require("lz.n.state")
|
||||
local loader = require("lz.n.loader")
|
||||
local spy = require("luassert.spy")
|
||||
|
||||
describe("cmd", function()
|
||||
describe("handlers.cmd", function()
|
||||
it("Command only loads plugin once and executes plugin command", function()
|
||||
---@type LzPlugin
|
||||
local plugin = {
|
||||
|
||||
@@ -4,7 +4,7 @@ local state = require("lz.n.state")
|
||||
local loader = require("lz.n.loader")
|
||||
local spy = require("luassert.spy")
|
||||
|
||||
describe("event", function()
|
||||
describe("handlers.event", function()
|
||||
it("can parse from string", function()
|
||||
assert.same({
|
||||
event = "VimEnter",
|
||||
|
||||
28
spec/ft_spec.lua
Normal file
28
spec/ft_spec.lua
Normal file
@@ -0,0 +1,28 @@
|
||||
---@diagnostic disable: invisible
|
||||
local ft = require("lz.n.handler.ft")
|
||||
local state = require("lz.n.state")
|
||||
local loader = require("lz.n.loader")
|
||||
local spy = require("luassert.spy")
|
||||
|
||||
describe("handlers.ft", function()
|
||||
it("can parse from string", function()
|
||||
assert.same({
|
||||
event = "FileType",
|
||||
id = "rust",
|
||||
pattern = "rust",
|
||||
}, ft.parse("rust"))
|
||||
end)
|
||||
it("filetype event loads plugins", function()
|
||||
---@type LzPlugin
|
||||
local plugin = {
|
||||
name = "Foo",
|
||||
event = { ft.parse("rust") },
|
||||
}
|
||||
local spy_load = spy.on(loader, "_load")
|
||||
state.plugins[plugin.name] = plugin
|
||||
ft.add(plugin)
|
||||
vim.api.nvim_exec_autocmds("FileType", { pattern = "rust" })
|
||||
vim.api.nvim_exec_autocmds("FileType", { pattern = "rust" })
|
||||
assert.spy(spy_load).called(1)
|
||||
end)
|
||||
end)
|
||||
@@ -4,7 +4,7 @@ local state = require("lz.n.state")
|
||||
local loader = require("lz.n.loader")
|
||||
local spy = require("luassert.spy")
|
||||
|
||||
describe("keys", function()
|
||||
describe("handlers.keys", function()
|
||||
it("parses ids correctly", function()
|
||||
local tests = {
|
||||
{ "<C-/>", "<c-/>", true },
|
||||
|
||||
Reference in New Issue
Block a user