mirror of
https://github.com/chenasraf/text-transform.nvim.git
synced 2026-05-18 01:48:57 +00:00
test: split into separate files
This commit is contained in:
78
tests/test_config.lua
Normal file
78
tests/test_config.lua
Normal file
@@ -0,0 +1,78 @@
|
||||
local helpers = dofile("tests/helpers.lua")
|
||||
|
||||
-- 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["setup()"] = MiniTest.new_set()
|
||||
|
||||
T["setup()"]["sets exposed methods and default options value"] = function()
|
||||
child.lua([[require('text-transform').setup()]])
|
||||
|
||||
-- global object that holds your plugin information
|
||||
eq_type_global(child, "_G.TextTransform", "table")
|
||||
|
||||
-- public methods
|
||||
eq_type_global(child, "_G.TextTransform.toggle", "function")
|
||||
eq_type_global(child, "_G.TextTransform.disable", "function")
|
||||
eq_type_global(child, "_G.TextTransform.enable", "function")
|
||||
|
||||
-- config
|
||||
eq_type_global(child, "_G.TextTransform.config", "table")
|
||||
|
||||
-- assert the value, and the type
|
||||
eq_type_config(child, "debug", "boolean")
|
||||
eq_config(child, "debug", false)
|
||||
|
||||
eq_type_config(child, "keymap", "table")
|
||||
|
||||
eq_type_config(child, "keymap.v", "string")
|
||||
eq_config(child, "keymap.v", "<Leader>~")
|
||||
|
||||
eq_type_config(child, "keymap.n", "string")
|
||||
eq_config(child, "keymap.n", "<Leader>~")
|
||||
end
|
||||
|
||||
T["setup()"]["overrides default values"] = function()
|
||||
child.lua([[require('text-transform').setup({
|
||||
-- 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")
|
||||
eq_config(child, "debug", true)
|
||||
|
||||
eq_type_config(child, "keymap", "table")
|
||||
|
||||
eq_type_config(child, "keymap.v", "string")
|
||||
eq_config(child, "keymap.v", "<leader>c")
|
||||
|
||||
eq_type_config(child, "keymap.n", "string")
|
||||
eq_config(child, "keymap.n", "<leader>c")
|
||||
end
|
||||
|
||||
return T
|
||||
60
tests/test_into_words.lua
Normal file
60
tests/test_into_words.lua
Normal file
@@ -0,0 +1,60 @@
|
||||
local helpers = dofile("tests/helpers.lua")
|
||||
|
||||
-- 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,
|
||||
},
|
||||
})
|
||||
|
||||
T["into_words()"] = MiniTest.new_set()
|
||||
|
||||
T["into_words()"]["should split two words with spaces"] = function()
|
||||
child.lua([[require('text-transform').setup()]])
|
||||
child.lua([[result = require('text-transform').into_words("hello world")]])
|
||||
eq_type_global(child, "result", "table")
|
||||
eq_global(child, "result[1]", "hello")
|
||||
eq_global(child, "result[2]", "world")
|
||||
end
|
||||
|
||||
T["into_words()"]["should split two words with no spaces"] = function()
|
||||
child.lua([[require('text-transform').setup()]])
|
||||
child.lua([[result = require('text-transform').into_words("helloWorld")]])
|
||||
eq_type_global(child, "result", "table")
|
||||
eq_global(child, "result[1]", "hello")
|
||||
eq_global(child, "result[2]", "World")
|
||||
end
|
||||
|
||||
T["into_words()"]["should split two words with dots"] = function()
|
||||
child.lua([[require('text-transform').setup()]])
|
||||
child.lua([[result = require('text-transform').into_words("hello.world")]])
|
||||
eq_type_global(child, "result", "table")
|
||||
eq_global(child, "result[1]", "hello")
|
||||
eq_global(child, "result[2]", "world")
|
||||
end
|
||||
|
||||
T["into_words()"]["should split two words with a number inside"] = function()
|
||||
child.lua([[require('text-transform').setup()]])
|
||||
child.lua([[result = require('text-transform').into_words("helloWorld123")]])
|
||||
eq_type_global(child, "result", "table")
|
||||
eq_global(child, "result[1]", "hello")
|
||||
eq_global(child, "result[2]", "World")
|
||||
eq_global(child, "result[3]", "123")
|
||||
end
|
||||
|
||||
return T
|
||||
@@ -22,59 +22,6 @@ local T = MiniTest.new_set({
|
||||
},
|
||||
})
|
||||
|
||||
-- Tests related to the `setup` method.
|
||||
T["setup()"] = MiniTest.new_set()
|
||||
|
||||
T["setup()"]["sets exposed methods and default options value"] = function()
|
||||
child.lua([[require('text-transform').setup()]])
|
||||
|
||||
-- global object that holds your plugin information
|
||||
eq_type_global(child, "_G.TextTransform", "table")
|
||||
|
||||
-- public methods
|
||||
eq_type_global(child, "_G.TextTransform.toggle", "function")
|
||||
eq_type_global(child, "_G.TextTransform.disable", "function")
|
||||
eq_type_global(child, "_G.TextTransform.enable", "function")
|
||||
|
||||
-- config
|
||||
eq_type_global(child, "_G.TextTransform.config", "table")
|
||||
|
||||
-- assert the value, and the type
|
||||
eq_config(child, "debug", false)
|
||||
eq_type_config(child, "debug", "boolean")
|
||||
|
||||
eq_type_config(child, "keymap", "table")
|
||||
|
||||
eq_config(child, "keymap.v", "<Leader>~")
|
||||
eq_type_config(child, "keymap.v", "string")
|
||||
|
||||
eq_config(child, "keymap.n", "<Leader>~")
|
||||
eq_type_config(child, "keymap.n", "string")
|
||||
end
|
||||
|
||||
T["setup()"]["overrides default values"] = function()
|
||||
child.lua([[require('text-transform').setup({
|
||||
-- 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")
|
||||
eq_config(child, "debug", true)
|
||||
|
||||
eq_type_config(child, "keymap", "table")
|
||||
|
||||
eq_config(child, "keymap.v", "<leader>c")
|
||||
eq_type_config(child, "keymap.v", "string")
|
||||
|
||||
eq_config(child, "keymap.n", "<leader>c")
|
||||
eq_type_config(child, "keymap.n", "string")
|
||||
end
|
||||
|
||||
local function make_transform_test(fn_name, input, expected)
|
||||
return function()
|
||||
child.lua([[require('text-transform').setup()]])
|
||||
@@ -83,33 +30,6 @@ local function make_transform_test(fn_name, input, expected)
|
||||
end
|
||||
end
|
||||
|
||||
T["into_words()"] = MiniTest.new_set()
|
||||
|
||||
T["into_words()"]["should split two words with spaces"] = function()
|
||||
child.lua([[require('text-transform').setup()]])
|
||||
child.lua([[result = require('text-transform').into_words("helloWorld")]])
|
||||
eq_type_global(child, "result", "table")
|
||||
eq_global(child, "result[1]", "hello")
|
||||
eq_global(child, "result[2]", "World")
|
||||
end
|
||||
|
||||
T["into_words()"]["should split two words with dots"] = function()
|
||||
child.lua([[require('text-transform').setup()]])
|
||||
child.lua([[result = require('text-transform').into_words("hello.world")]])
|
||||
eq_type_global(child, "result", "table")
|
||||
eq_global(child, "result[1]", "hello")
|
||||
eq_global(child, "result[2]", "world")
|
||||
end
|
||||
|
||||
T["into_words()"]["should split two words with a number inside"] = function()
|
||||
child.lua([[require('text-transform').setup()]])
|
||||
child.lua([[result = require('text-transform').into_words("helloWorld123")]])
|
||||
eq_type_global(child, "result", "table")
|
||||
eq_global(child, "result[1]", "hello")
|
||||
eq_global(child, "result[2]", "World")
|
||||
eq_global(child, "result[3]", "123")
|
||||
end
|
||||
|
||||
local map = {
|
||||
["camel_case"] = {
|
||||
{ "hello_world", "helloWorld" },
|
||||
Reference in New Issue
Block a user