mirror of
https://github.com/chenasraf/text-transform.nvim.git
synced 2026-05-17 17:48:04 +00:00
test: add tests
This commit is contained in:
@@ -162,4 +162,9 @@ Helpers.new_child_neovim = function()
|
||||
return child
|
||||
end
|
||||
|
||||
function Helpers.init_plugin(child, config)
|
||||
config = config or ""
|
||||
child.lua([[require('text-transform').setup(]] .. config .. [[)]])
|
||||
end
|
||||
|
||||
return Helpers
|
||||
|
||||
@@ -55,14 +55,17 @@ T["setup()"]["sets exposed methods and default options value"] = function()
|
||||
end
|
||||
|
||||
T["setup()"]["overrides default values"] = function()
|
||||
child.lua([[require('text-transform').setup({
|
||||
helpers.init_plugin(
|
||||
child,
|
||||
[[{
|
||||
-- write all the options with a value different than the default ones
|
||||
debug = true,
|
||||
keymap = {
|
||||
["v"] = "<leader>c",
|
||||
["n"] = "<leader>c",
|
||||
},
|
||||
})]])
|
||||
}]]
|
||||
)
|
||||
|
||||
-- assert the value, and the type
|
||||
eq_type_config(child, "debug", "boolean")
|
||||
|
||||
63
tests/test_popups.lua
Normal file
63
tests/test_popups.lua
Normal file
@@ -0,0 +1,63 @@
|
||||
local helpers = dofile("tests/helpers.lua")
|
||||
local MiniTest = require("mini.test")
|
||||
|
||||
-- See https://github.com/echasnovski/mini.nvim/blob/main/lua/mini/test.lua for more documentation
|
||||
|
||||
local child = helpers.new_child_neovim()
|
||||
local eq_global, eq_config, eq_state =
|
||||
helpers.expect.global_equality, helpers.expect.config_equality, helpers.expect.state_equality
|
||||
local eq_type_global, eq_type_config, eq_type_state =
|
||||
helpers.expect.global_type_equality,
|
||||
helpers.expect.config_type_equality,
|
||||
helpers.expect.state_type_equality
|
||||
|
||||
local T = MiniTest.new_set({
|
||||
hooks = {
|
||||
-- This will be executed before every (even nested) case
|
||||
pre_case = function()
|
||||
-- Restart child process with custom 'init.lua' script
|
||||
child.restart({ "-u", "scripts/minimal_init.lua" })
|
||||
end,
|
||||
-- This will be executed one after all tests from this set are finished
|
||||
post_once = child.stop,
|
||||
},
|
||||
})
|
||||
|
||||
-- Tests related to the `setup` method.
|
||||
T["popups"] = MiniTest.new_set()
|
||||
|
||||
T["popups"]["exposes show_popup"] = function()
|
||||
helpers.init_plugin(child)
|
||||
|
||||
eq_type_global(child, "_G.TextTransform", "table")
|
||||
|
||||
eq_type_global(child, "_G.TextTransform.show_popup", "function")
|
||||
|
||||
eq_type_global(child, "_G.TextTransform.telescope_popup", "nil")
|
||||
end
|
||||
|
||||
T["popups"]["telescope exposes telescope_popup"] = function()
|
||||
helpers.init_plugin(child)
|
||||
|
||||
eq_type_global(child, "_G.TextTransform", "table")
|
||||
|
||||
eq_type_global(child, "_G.TextTransform.telescope_popup", "nil")
|
||||
|
||||
child.lua([[Telescope = require('text-transform.telescope')]])
|
||||
|
||||
eq_type_global(child, "Telescope.telescope_popup", "function")
|
||||
end
|
||||
|
||||
T["popups"]["select exposes select_popup"] = function()
|
||||
helpers.init_plugin(child)
|
||||
|
||||
eq_type_global(child, "_G.TextTransform", "table")
|
||||
|
||||
eq_type_global(child, "_G.TextTransform.select_popup", "nil")
|
||||
|
||||
child.lua([[Select = require('text-transform.select')]])
|
||||
|
||||
eq_type_global(child, "Select.select_popup", "function")
|
||||
end
|
||||
|
||||
return T
|
||||
@@ -24,7 +24,7 @@ local T = MiniTest.new_set({
|
||||
})
|
||||
|
||||
local function test_string(child, str)
|
||||
child.lua([[require('text-transform').setup()]])
|
||||
helpers.init_plugin(child)
|
||||
child.lua([[result = require('text-transform').to_words("]] .. str .. [[")]])
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user