diff --git a/tests/helpers.lua b/tests/helpers.lua index 1582bdd..89742f9 100644 --- a/tests/helpers.lua +++ b/tests/helpers.lua @@ -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 diff --git a/tests/test_config.lua b/tests/test_config.lua index 7997a61..0a10a3c 100644 --- a/tests/test_config.lua +++ b/tests/test_config.lua @@ -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"] = "c", ["n"] = "c", }, - })]]) + }]] + ) -- assert the value, and the type eq_type_config(child, "debug", "boolean") diff --git a/tests/test_popups.lua b/tests/test_popups.lua new file mode 100644 index 0000000..5d5d0c2 --- /dev/null +++ b/tests/test_popups.lua @@ -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 diff --git a/tests/test_to_words.lua b/tests/test_to_words.lua index f748151..33a7cd4 100644 --- a/tests/test_to_words.lua +++ b/tests/test_to_words.lua @@ -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