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)
|
event.add(plugin)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---@param plugin LzPlugin
|
||||||
|
function M.del(plugin)
|
||||||
|
event.del(plugin)
|
||||||
|
end
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
|||||||
@@ -33,7 +33,6 @@ error("Cannot import a meta module")
|
|||||||
|
|
||||||
---@class LzPluginHandlers
|
---@class LzPluginHandlers
|
||||||
---@field event? LzEvent[]
|
---@field event? LzEvent[]
|
||||||
---@field ft? LzEvent[]
|
|
||||||
---@field keys? LzKeys[]
|
---@field keys? LzKeys[]
|
||||||
---@field cmd? string[]
|
---@field cmd? string[]
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ local state = require("lz.n.state")
|
|||||||
local loader = require("lz.n.loader")
|
local loader = require("lz.n.loader")
|
||||||
local spy = require("luassert.spy")
|
local spy = require("luassert.spy")
|
||||||
|
|
||||||
describe("cmd", function()
|
describe("handlers.cmd", function()
|
||||||
it("Command only loads plugin once and executes plugin command", function()
|
it("Command only loads plugin once and executes plugin command", function()
|
||||||
---@type LzPlugin
|
---@type LzPlugin
|
||||||
local plugin = {
|
local plugin = {
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ local state = require("lz.n.state")
|
|||||||
local loader = require("lz.n.loader")
|
local loader = require("lz.n.loader")
|
||||||
local spy = require("luassert.spy")
|
local spy = require("luassert.spy")
|
||||||
|
|
||||||
describe("event", function()
|
describe("handlers.event", function()
|
||||||
it("can parse from string", function()
|
it("can parse from string", function()
|
||||||
assert.same({
|
assert.same({
|
||||||
event = "VimEnter",
|
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 loader = require("lz.n.loader")
|
||||||
local spy = require("luassert.spy")
|
local spy = require("luassert.spy")
|
||||||
|
|
||||||
describe("keys", function()
|
describe("handlers.keys", function()
|
||||||
it("parses ids correctly", function()
|
it("parses ids correctly", function()
|
||||||
local tests = {
|
local tests = {
|
||||||
{ "<C-/>", "<c-/>", true },
|
{ "<C-/>", "<c-/>", true },
|
||||||
|
|||||||
Reference in New Issue
Block a user