mirror of
https://github.com/chenasraf/text-transform.nvim.git
synced 2026-05-18 01:48:57 +00:00
test: fix most tests
This commit is contained in:
6
Makefile
6
Makefile
@@ -14,6 +14,8 @@ test:
|
||||
deps:
|
||||
@mkdir -p deps
|
||||
git clone --depth 1 https://github.com/echasnovski/mini.nvim deps/mini.nvim
|
||||
git clone --depth 1 https://github.com/nvim-lua/plenary.nvim deps/plenary.nvim
|
||||
git clone --depth 1 https://github.com/nvim-telescope/telescope.nvim deps/telescope.nvim
|
||||
echo "#!/usr/bin/env bash\n\nmake precommit" > .git/hooks/pre-commit
|
||||
chmod +x .git/hooks/pre-commit
|
||||
|
||||
@@ -31,10 +33,6 @@ documentation-ci: deps documentation
|
||||
lint:
|
||||
stylua .
|
||||
|
||||
precommit-install:
|
||||
echo "#!/usr/bin/env bash\n\nmake precommit" > .git/hooks/pre-commit
|
||||
chmod +x .git/hooks/pre-commit
|
||||
|
||||
# precommit
|
||||
precommit:
|
||||
./precommit.sh
|
||||
|
||||
@@ -11,6 +11,7 @@ end
|
||||
|
||||
merge(tt)
|
||||
merge(replacers)
|
||||
TextTransform.state = state
|
||||
merge(state)
|
||||
-- TextTransform.state = state
|
||||
|
||||
return TextTransform
|
||||
|
||||
@@ -12,6 +12,7 @@ function transformers.to_words(string)
|
||||
local words = {}
|
||||
local word = ""
|
||||
local last_is_upper = false
|
||||
local last_is_digit = false
|
||||
for i = 1, #string do
|
||||
local char = string:sub(i, i)
|
||||
if char:match(transformers.WORD_BOUNDRY) then
|
||||
@@ -22,8 +23,20 @@ function transformers.to_words(string)
|
||||
else
|
||||
if not last_is_upper and char:match("%u") and word ~= "" then
|
||||
table.insert(words, word:lower())
|
||||
last_is_upper = true
|
||||
word = ""
|
||||
end
|
||||
if char:match("%l") then
|
||||
last_is_upper = false
|
||||
end
|
||||
if not last_is_digit and char:match("%d") and word ~= "" then
|
||||
table.insert(words, word:lower())
|
||||
last_is_digit = true
|
||||
word = ""
|
||||
end
|
||||
if char:match("%D") then
|
||||
last_is_digit = false
|
||||
end
|
||||
word = word .. char
|
||||
-- word = word .. string:sub(i)
|
||||
-- break
|
||||
|
||||
@@ -6,6 +6,8 @@ if #vim.api.nvim_list_uis() == 0 then
|
||||
-- Add 'mini.nvim' to 'runtimepath' to be able to use 'mini.test'
|
||||
-- Assumed that 'mini.nvim' is stored in 'deps/mini.nvim'
|
||||
vim.cmd("set rtp+=deps/mini.nvim")
|
||||
vim.cmd("set rtp+=deps/telescope.nvim")
|
||||
vim.cmd("set rtp+=deps/plenary.nvim")
|
||||
|
||||
-- Set up 'mini.test'
|
||||
require("mini.test").setup()
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
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
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
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
|
||||
|
||||
@@ -22,44 +23,44 @@ local T = MiniTest.new_set({
|
||||
},
|
||||
})
|
||||
|
||||
T["into_words()"] = MiniTest.new_set()
|
||||
T["to_words()"] = MiniTest.new_set()
|
||||
|
||||
T["into_words()"]["should split two words with spaces"] = function()
|
||||
T["to_words()"]["should split two words with spaces"] = function()
|
||||
child.lua([[require('text-transform').setup()]])
|
||||
child.lua([[result = require('text-transform').into_words("hello world")]])
|
||||
child.lua([[result = require('text-transform').to_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()
|
||||
T["to_words()"]["should split two words with no spaces"] = function()
|
||||
child.lua([[require('text-transform').setup()]])
|
||||
child.lua([[result = require('text-transform').into_words("helloWorld")]])
|
||||
child.lua([[result = require('text-transform').to_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()
|
||||
T["to_words()"]["should split two words with dots"] = function()
|
||||
child.lua([[require('text-transform').setup()]])
|
||||
child.lua([[result = require('text-transform').into_words("hello.world")]])
|
||||
child.lua([[result = require('text-transform').to_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()
|
||||
T["to_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")]])
|
||||
child.lua([[result = require('text-transform').to_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
|
||||
|
||||
T["into_words()"]["should split two words and ignore trailing/leading spaces"] = function()
|
||||
T["to_words()"]["should split two words and ignore trailing/leading spaces"] = function()
|
||||
child.lua([[require('text-transform').setup()]])
|
||||
child.lua([[result = require('text-transform').into_words(" hello world ")]])
|
||||
child.lua([[result = require('text-transform').to_words(" hello world ")]])
|
||||
eq_type_global(child, "result", "table")
|
||||
eq_global(child, "result[1]", "hello")
|
||||
eq_global(child, "result[2]", "world")
|
||||
@@ -25,7 +25,7 @@ local T = MiniTest.new_set({
|
||||
local function make_transform_test(fn_name, input, expected)
|
||||
return function()
|
||||
child.lua([[require('text-transform').setup()]])
|
||||
child.lua([[result = require('text-transform').]] .. fn_name .. '("' .. input .. '")')
|
||||
child.lua([[result = require('text-transform').to_]] .. fn_name .. '("' .. input .. '")')
|
||||
eq_global(child, "result", expected)
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user