Skip to content

Commit

Permalink
test: add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
chenasraf committed May 4, 2024
1 parent d1692d4 commit 5c13d33
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 3 deletions.
5 changes: 5 additions & 0 deletions tests/helpers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
7 changes: 5 additions & 2 deletions tests/test_config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
63 changes: 63 additions & 0 deletions tests/test_popups.lua
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion tests/test_to_words.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 5c13d33

Please sign in to comment.