Regenerate nvim config
This commit is contained in:
@ -0,0 +1,90 @@
|
||||
local Char = require("flash.plugins.char")
|
||||
local assert = require("luassert")
|
||||
require("flash").setup()
|
||||
|
||||
describe("char", function()
|
||||
local function set(text, pos)
|
||||
local lines = vim.split(vim.trim(text), "\n")
|
||||
lines = vim.tbl_map(function(line)
|
||||
return vim.trim(line)
|
||||
end, lines)
|
||||
vim.api.nvim_buf_set_lines(1, 0, -1, false, lines)
|
||||
vim.api.nvim_win_set_cursor(0, pos or { 1, 0 })
|
||||
end
|
||||
|
||||
before_each(function()
|
||||
set("abc_xyz", { 1, 3 })
|
||||
local state = require("flash.plugins.char").state
|
||||
if state then
|
||||
state:hide()
|
||||
end
|
||||
end)
|
||||
|
||||
local function get()
|
||||
return table.concat(vim.api.nvim_buf_get_lines(1, 0, -1, false), "\n")
|
||||
end
|
||||
|
||||
--- tests for deletes with ftFT motions
|
||||
--- test always runs on input "abc_xyz"
|
||||
--- with cursor at position { 1, 3 }
|
||||
local tests = {
|
||||
-- f
|
||||
{ motion = "dfx", result = "abcyz" },
|
||||
{ motion = "dfz", result = "abc" },
|
||||
{ motion = "df_", result = "abc_xyz" },
|
||||
{ motion = "dfa", result = "abc_xyz" },
|
||||
-- t
|
||||
{ motion = "dtx", result = "abcxyz" },
|
||||
{ motion = "dtz", result = "abcz" },
|
||||
{ motion = "dt_", result = "abc_xyz" },
|
||||
{ motion = "dta", result = "abc_xyz" },
|
||||
-- F
|
||||
{ motion = "dFa", result = "_xyz" },
|
||||
{ motion = "dFc", result = "ab_xyz" },
|
||||
{ motion = "dF_", result = "abc_xyz" },
|
||||
{ motion = "dFx", result = "abc_xyz" },
|
||||
-- T
|
||||
{ motion = "dTa", result = "a_xyz" },
|
||||
{ motion = "dTc", result = "abc_xyz" },
|
||||
{ motion = "dT_", result = "abc_xyz" },
|
||||
{ motion = "dTx", result = "abc_xyz" },
|
||||
}
|
||||
|
||||
for _, test in ipairs(tests) do
|
||||
it("works with " .. test.motion, function()
|
||||
vim.cmd("norm! " .. test.motion)
|
||||
assert.same(test.result, get())
|
||||
end)
|
||||
end
|
||||
for _, test in ipairs(tests) do
|
||||
it("works with " .. test.motion .. " (flash)", function()
|
||||
-- vim.api.nvim_feedkeys(test.motion, "mtx", false)
|
||||
vim.cmd("norm " .. test.motion)
|
||||
assert.same(test.result, get())
|
||||
end)
|
||||
end
|
||||
|
||||
local input = "abcd1abcd2abcd"
|
||||
for _, motion in ipairs({ "f", "t", "F", "T" }) do
|
||||
for col = 0, #input - 1 do
|
||||
for count = -1, 3 do
|
||||
count = count == -1 and "" or count
|
||||
for _, char in ipairs({ "a", "b", "c", "d" }) do
|
||||
local cmd = count .. "d" .. motion .. char
|
||||
local pos = { 1, col }
|
||||
it("works with " .. cmd .. " at " .. col, function()
|
||||
set(input, pos)
|
||||
vim.cmd("norm! " .. cmd)
|
||||
local ret = get()
|
||||
set(input, pos)
|
||||
if Char.state then
|
||||
Char.state:hide()
|
||||
end
|
||||
vim.cmd("norm " .. cmd)
|
||||
assert.same(ret, get())
|
||||
end)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end)
|
||||
@ -0,0 +1,38 @@
|
||||
local Config = require("flash.config")
|
||||
local assert = require("luassert")
|
||||
|
||||
describe("config", function()
|
||||
before_each(function()
|
||||
Config.setup()
|
||||
end)
|
||||
|
||||
it("processes modes", function()
|
||||
Config.setup({ modes = { foo = { bar = true } } })
|
||||
assert.is_true(Config.modes.foo.bar)
|
||||
assert.is_true(Config.get({ mode = "foo" }).bar)
|
||||
end)
|
||||
|
||||
it("processes modes recursively", function()
|
||||
Config.setup({
|
||||
modes = {
|
||||
foo = { mode = "bar" },
|
||||
bar = { field = true, mode = "foo" },
|
||||
},
|
||||
})
|
||||
assert.is_true(Config.get({ mode = "foo" }).field)
|
||||
assert.is_true(Config.get({ mode = "bar" }).field)
|
||||
end)
|
||||
|
||||
it("processes modes recursively in correct order", function()
|
||||
Config.setup({
|
||||
modes = {
|
||||
a = { mode = "b", v = "a" },
|
||||
b = { mode = "c", v = "b" },
|
||||
c = { v = "c" },
|
||||
},
|
||||
})
|
||||
assert.same("d", Config.get({ mode = "a", v = "d" }).v)
|
||||
assert.same("a", Config.get({ mode = "a" }).v)
|
||||
assert.same("b", Config.get({ mode = "b" }).v)
|
||||
end)
|
||||
end)
|
||||
36
config/neovim/store/lazy-plugins/flash.nvim/tests/init.lua
Normal file
36
config/neovim/store/lazy-plugins/flash.nvim/tests/init.lua
Normal file
@ -0,0 +1,36 @@
|
||||
local M = {}
|
||||
|
||||
function M.root(root)
|
||||
local f = debug.getinfo(1, "S").source:sub(2)
|
||||
return vim.fn.fnamemodify(f, ":p:h:h") .. "/" .. (root or "")
|
||||
end
|
||||
|
||||
---@param plugin string
|
||||
function M.load(plugin)
|
||||
local name = plugin:match(".*/(.*)")
|
||||
local package_root = M.root(".tests/site/pack/deps/start/")
|
||||
if not vim.loop.fs_stat(package_root .. name) then
|
||||
print("Installing " .. plugin)
|
||||
vim.fn.mkdir(package_root, "p")
|
||||
vim.fn.system({
|
||||
"git",
|
||||
"clone",
|
||||
"--depth=1",
|
||||
"https://github.com/" .. plugin .. ".git",
|
||||
package_root .. "/" .. name,
|
||||
})
|
||||
end
|
||||
end
|
||||
|
||||
function M.setup()
|
||||
vim.cmd([[set runtimepath=$VIMRUNTIME]])
|
||||
vim.opt.runtimepath:append(M.root())
|
||||
vim.opt.packpath = { M.root(".tests/site") }
|
||||
M.load("nvim-lua/plenary.nvim")
|
||||
vim.env.XDG_CONFIG_HOME = M.root(".tests/config")
|
||||
vim.env.XDG_DATA_HOME = M.root(".tests/data")
|
||||
vim.env.XDG_STATE_HOME = M.root(".tests/state")
|
||||
vim.env.XDG_CACHE_HOME = M.root(".tests/cache")
|
||||
end
|
||||
|
||||
M.setup()
|
||||
3
config/neovim/store/lazy-plugins/flash.nvim/tests/run
Executable file
3
config/neovim/store/lazy-plugins/flash.nvim/tests/run
Executable file
@ -0,0 +1,3 @@
|
||||
#!/nix/store/306znyj77fv49kwnkpxmb0j2znqpa8bj-bash-5.2p26/bin/sh
|
||||
|
||||
nvim --headless -u tests/init.lua -c "PlenaryBustedDirectory tests {minimal_init = 'tests//init.lua', sequential = true}"
|
||||
@ -0,0 +1,51 @@
|
||||
local Search = require("flash.search")
|
||||
local State = require("flash.state")
|
||||
|
||||
describe("search", function()
|
||||
before_each(function()
|
||||
vim.opt.ignorecase = true
|
||||
vim.opt.smartcase = true
|
||||
vim.api.nvim_buf_set_lines(1, 0, -1, false, {})
|
||||
end)
|
||||
|
||||
---@param opts? Flash.State.Config | string
|
||||
local function get_search(opts)
|
||||
if type(opts) == "string" then
|
||||
opts = { pattern = opts }
|
||||
end
|
||||
local state = State.new(opts)
|
||||
local win = vim.api.nvim_get_current_win()
|
||||
return Search.new(win, state)
|
||||
end
|
||||
|
||||
local function set(text, pos)
|
||||
local lines = vim.split(vim.trim(text), "\n")
|
||||
lines = vim.tbl_map(function(line)
|
||||
return vim.trim(line)
|
||||
end, lines)
|
||||
vim.api.nvim_buf_set_lines(1, 0, -1, false, lines)
|
||||
vim.api.nvim_win_set_cursor(0, pos or { 1, 0 })
|
||||
end
|
||||
|
||||
it("finds matches", function()
|
||||
set([[
|
||||
foobar
|
||||
line1
|
||||
line2
|
||||
]])
|
||||
|
||||
local search = get_search("line")
|
||||
local matches = search:get()
|
||||
assert.same("\\Vline", search.state.pattern.search)
|
||||
assert.same({
|
||||
{ win = 1000, pos = { 2, 0 }, end_pos = { 2, 3 } },
|
||||
{ win = 1000, pos = { 3, 0 }, end_pos = { 3, 3 } },
|
||||
}, matches)
|
||||
assert.same({ win = 1000, pos = { 2, 0 }, end_pos = { 2, 3 } }, search:find())
|
||||
assert.same({ win = 1000, pos = { 3, 0 }, end_pos = { 3, 3 } }, search:find({ count = 2 }))
|
||||
assert.same(
|
||||
{ win = 1000, pos = { 3, 0 }, end_pos = { 3, 3 } },
|
||||
search:find({ forward = false })
|
||||
)
|
||||
end)
|
||||
end)
|
||||
@ -0,0 +1,85 @@
|
||||
local Jump = require("flash.jump")
|
||||
local Pos = require("flash.search.pos")
|
||||
local State = require("flash.state")
|
||||
local assert = require("luassert")
|
||||
|
||||
describe("jump", function()
|
||||
local function set(text, pos)
|
||||
local lines = vim.split(vim.trim(text), "\n")
|
||||
lines = vim.tbl_map(function(line)
|
||||
return vim.trim(line)
|
||||
end, lines)
|
||||
if vim.fn.mode() == "v" then
|
||||
vim.cmd("normal! v")
|
||||
end
|
||||
vim.api.nvim_buf_set_lines(1, 0, -1, false, lines)
|
||||
vim.api.nvim_win_set_cursor(0, pos or { 1, 0 })
|
||||
end
|
||||
|
||||
---@param match Flash.Match
|
||||
---@param opts? Flash.State.Config
|
||||
local function jump(match, opts)
|
||||
match.win = vim.api.nvim_get_current_win()
|
||||
local state = State.new(opts)
|
||||
Jump.jump(match, state)
|
||||
end
|
||||
|
||||
before_each(function()
|
||||
vim.opt.ignorecase = true
|
||||
vim.opt.smartcase = true
|
||||
vim.api.nvim_buf_set_lines(0, 0, -1, false, {})
|
||||
set([[
|
||||
line1 foo
|
||||
line2 foo
|
||||
line3 foo
|
||||
]])
|
||||
end)
|
||||
|
||||
it("jumps to start", function()
|
||||
local match = {
|
||||
pos = Pos({ 1, 6 }),
|
||||
end_pos = Pos({ 1, 8 }),
|
||||
}
|
||||
jump(match)
|
||||
assert.same({ 1, 6 }, vim.api.nvim_win_get_cursor(0))
|
||||
end)
|
||||
|
||||
it("selects to start", function()
|
||||
assert.same({ 1, 0 }, vim.api.nvim_win_get_cursor(0))
|
||||
local match = {
|
||||
pos = Pos({ 1, 6 }),
|
||||
end_pos = Pos({ 1, 8 }),
|
||||
}
|
||||
|
||||
assert.same("n", vim.fn.mode())
|
||||
vim.cmd("normal! v")
|
||||
jump(match, { jump = { pos = "start", inclusive = false } })
|
||||
assert.same("v", vim.fn.mode())
|
||||
vim.cmd("normal! v")
|
||||
|
||||
assert.same({ 1, 6 }, vim.api.nvim_win_get_cursor(0))
|
||||
assert.same({ 1, 0 }, vim.api.nvim_buf_get_mark(0, "<"))
|
||||
assert.same({ 1, 6 }, vim.api.nvim_buf_get_mark(0, ">"))
|
||||
end)
|
||||
|
||||
-- it("yanks to start", function()
|
||||
-- assert.same({ 1, 0 }, vim.api.nvim_win_get_cursor(0))
|
||||
-- local match = {
|
||||
-- pos = Pos({ 1, 6 }),
|
||||
-- end_pos = Pos({ 1, 8 }),
|
||||
-- }
|
||||
--
|
||||
-- assert.same("n", vim.fn.mode())
|
||||
-- -- vim.cmd("normal! y")
|
||||
-- vim.api.nvim_feedkeys("y", "n", false)
|
||||
-- assert.same("no", vim.fn.mode(true))
|
||||
-- jump(match, { jump = { pos = "start", inclusive = false } })
|
||||
-- assert.same("n", vim.fn.mode())
|
||||
--
|
||||
-- vim.print(vim.fn.getmarklist(vim.api.nvim_get_current_buf()))
|
||||
--
|
||||
-- assert.same({ 1, 6 }, vim.api.nvim_win_get_cursor(0))
|
||||
-- assert.same({ 1, 0 }, vim.api.nvim_buf_get_mark(0, "["))
|
||||
-- assert.same({ 1, 6 }, vim.api.nvim_buf_get_mark(0, "]"))
|
||||
-- end)
|
||||
end)
|
||||
@ -0,0 +1,103 @@
|
||||
local Labeler = require("flash.labeler")
|
||||
local Search = require("flash.search")
|
||||
local State = require("flash.state")
|
||||
local assert = require("luassert")
|
||||
|
||||
describe("labeler", function()
|
||||
local function set(text, pos)
|
||||
local lines = vim.split(vim.trim(text), "\n")
|
||||
lines = vim.tbl_map(function(line)
|
||||
return vim.trim(line)
|
||||
end, lines)
|
||||
vim.api.nvim_buf_set_lines(1, 0, -1, false, lines)
|
||||
vim.api.nvim_win_set_cursor(0, pos or { 1, 0 })
|
||||
end
|
||||
|
||||
local function search(pattern)
|
||||
local state = State.new({ pattern = pattern, search = {
|
||||
mode = "search",
|
||||
} })
|
||||
return Labeler.new(state)
|
||||
end
|
||||
|
||||
before_each(function()
|
||||
vim.opt.ignorecase = true
|
||||
vim.opt.smartcase = true
|
||||
end)
|
||||
|
||||
it("skips labels", function()
|
||||
set([[
|
||||
foo foo
|
||||
bar
|
||||
barfoo
|
||||
]])
|
||||
local labels = search("bar"):skip(1000, { "a", "b", "c", "f" })
|
||||
assert.same({ "a", "b", "c" }, labels)
|
||||
end)
|
||||
it("skips all labels for an empty pattern", function()
|
||||
set([[
|
||||
test pattern
|
||||
]])
|
||||
local labels = search(""):skip(1000, { "a", "b", "c", "t" })
|
||||
assert.same({}, labels)
|
||||
end)
|
||||
|
||||
it("skips all labels for an invalid pattern", function()
|
||||
set([[
|
||||
invalid pattern
|
||||
]])
|
||||
local labels = search("[i"):skip(1000, { "a", "b", "i", "v" })
|
||||
assert.same({}, labels)
|
||||
end)
|
||||
|
||||
it("skips all labels when pattern ends with unescaped backslash", function()
|
||||
set([[
|
||||
pattern with backslash\
|
||||
]])
|
||||
local labels = search("backslash\\"):skip(1000, { "a", "b", "s", "\\" })
|
||||
assert.same({}, labels)
|
||||
end)
|
||||
|
||||
it("skips label that matches pattern", function()
|
||||
set([[
|
||||
pattern withc
|
||||
]])
|
||||
local labels = search("with"):skip(1000, { "a", "b", "c", "p", "w" })
|
||||
assert.same({ "a", "b", "p", "w" }, labels)
|
||||
end)
|
||||
|
||||
it("considers ignorecase when skipping labels", function()
|
||||
set([[
|
||||
pattern withC
|
||||
]])
|
||||
vim.opt.ignorecase = true
|
||||
local labels = search("with"):skip(1000, { "a", "b", "C", "p", "w" })
|
||||
assert.same({ "a", "b", "p", "w" }, labels)
|
||||
end)
|
||||
|
||||
it("considers ignorecase3 when skipping labels", function()
|
||||
set([[
|
||||
pattern withC
|
||||
]])
|
||||
vim.opt.ignorecase = true
|
||||
local labels = search("with"):skip(1000, { "a", "b", "c", "p", "w" })
|
||||
assert.same({ "a", "b", "p", "w" }, labels)
|
||||
end)
|
||||
|
||||
it("considers ignorecase2 when skipping labels", function()
|
||||
set([[
|
||||
pattern withc
|
||||
]])
|
||||
vim.opt.ignorecase = true
|
||||
local labels = search("with"):skip(1000, { "a", "b", "C", "p", "w" })
|
||||
assert.same({ "a", "b", "p", "w" }, labels)
|
||||
end)
|
||||
|
||||
it("skips all labels when pattern is an incomplete regex", function()
|
||||
set([[
|
||||
pattern with incomplete regex (
|
||||
]])
|
||||
local labels = search("regex \\("):skip(1000, { "a", "b", "i", "r", "(" })
|
||||
assert.same({}, labels)
|
||||
end)
|
||||
end)
|
||||
@ -0,0 +1,184 @@
|
||||
local Matcher = require("flash.search.matcher")
|
||||
local assert = require("luassert")
|
||||
|
||||
describe("search", function()
|
||||
local matcher = Matcher.new(1000)
|
||||
local matches = {
|
||||
{ win = 1000, pos = { 1, 0 }, end_pos = { 1, 2 } },
|
||||
{ win = 1000, pos = { 1, 7 }, end_pos = { 1, 9 } },
|
||||
{ win = 1000, pos = { 3, 4 }, end_pos = { 3, 6 } },
|
||||
}
|
||||
matcher:set(matches)
|
||||
|
||||
it("sets matches", function()
|
||||
assert.same(matches, matcher:get())
|
||||
end)
|
||||
|
||||
it("finds backward from after end", function()
|
||||
assert.same(
|
||||
matches[3],
|
||||
matcher:find({
|
||||
forward = false,
|
||||
pos = { 4, 6 },
|
||||
wrap = false,
|
||||
})
|
||||
)
|
||||
end)
|
||||
|
||||
it("handles count = 0", function()
|
||||
assert.same(
|
||||
matches[2],
|
||||
matcher:find({
|
||||
pos = { 1, 7 },
|
||||
count = 0,
|
||||
})
|
||||
)
|
||||
assert.is_nil(matcher:find({
|
||||
pos = { 2, 7 },
|
||||
count = 0,
|
||||
}))
|
||||
end)
|
||||
|
||||
it("returns forward matches", function()
|
||||
assert.same(
|
||||
{ matches[3] },
|
||||
matcher:get({
|
||||
from = { 2, 6 },
|
||||
})
|
||||
)
|
||||
end)
|
||||
|
||||
it("returns forward matches", function()
|
||||
assert.same(
|
||||
{ matches[3] },
|
||||
matcher:get({
|
||||
from = { 3, 4 },
|
||||
})
|
||||
)
|
||||
end)
|
||||
|
||||
it("returns backward matches", function()
|
||||
assert.same(
|
||||
{ matches[1] },
|
||||
matcher:get({
|
||||
to = { 1, 6 },
|
||||
})
|
||||
)
|
||||
end)
|
||||
|
||||
it("returns backward matches", function()
|
||||
assert.same(
|
||||
{ matches[1] },
|
||||
matcher:get({
|
||||
to = { 1, 0 },
|
||||
})
|
||||
)
|
||||
end)
|
||||
|
||||
it("finds matcher", function()
|
||||
assert.same({ win = 1000, pos = { 1, 7 }, end_pos = { 1, 9 } }, matcher:find())
|
||||
assert.same({ win = 1000, pos = { 3, 4 }, end_pos = { 3, 6 } }, matcher:find({ count = 2 }))
|
||||
assert.same(
|
||||
{ win = 1000, pos = { 3, 4 }, end_pos = { 3, 6 } },
|
||||
matcher:find({ forward = false })
|
||||
)
|
||||
assert.same(
|
||||
{ win = 1000, pos = { 1, 7 }, end_pos = { 1, 9 } },
|
||||
matcher:find({
|
||||
forward = false,
|
||||
pos = { 2, 7 },
|
||||
})
|
||||
)
|
||||
assert.same(
|
||||
{ win = 1000, pos = { 1, 7 }, end_pos = { 1, 9 } },
|
||||
matcher:find({
|
||||
forward = false,
|
||||
pos = { 3, 4 },
|
||||
})
|
||||
)
|
||||
end)
|
||||
|
||||
it("sorts matches", function()
|
||||
local m = Matcher.new(1000)
|
||||
local mm = {
|
||||
{ pos = { 3, 4 }, end_pos = { 3, 6 } },
|
||||
{ pos = { 1, 0 }, end_pos = { 1, 2 } },
|
||||
{ pos = { 1, 7 }, end_pos = { 1, 9 } },
|
||||
}
|
||||
m:set(mm)
|
||||
assert.same({
|
||||
{ win = 1000, pos = { 1, 0 }, end_pos = { 1, 2 } },
|
||||
{ win = 1000, pos = { 1, 7 }, end_pos = { 1, 9 } },
|
||||
{ win = 1000, pos = { 3, 4 }, end_pos = { 3, 6 } },
|
||||
}, m:get())
|
||||
end)
|
||||
it("finds forward skipping match at current position", function()
|
||||
assert.same(
|
||||
matches[2],
|
||||
matcher:find({
|
||||
forward = true,
|
||||
pos = { 1, 0 },
|
||||
wrap = false,
|
||||
})
|
||||
)
|
||||
end)
|
||||
|
||||
it("finds backward skipping match at current position", function()
|
||||
assert.same(
|
||||
matches[2],
|
||||
matcher:find({
|
||||
forward = false,
|
||||
pos = { 3, 4 },
|
||||
wrap = true,
|
||||
})
|
||||
)
|
||||
end)
|
||||
|
||||
it("finds forward from a non-match position", function()
|
||||
assert.same(
|
||||
matches[2],
|
||||
matcher:find({
|
||||
forward = true,
|
||||
pos = { 1, 3 },
|
||||
wrap = false,
|
||||
})
|
||||
)
|
||||
end)
|
||||
|
||||
it("finds backward from a non-match position", function()
|
||||
assert.same(
|
||||
matches[2],
|
||||
matcher:find({
|
||||
forward = false,
|
||||
pos = { 3, 2 },
|
||||
wrap = true,
|
||||
})
|
||||
)
|
||||
end)
|
||||
|
||||
it("returns nil when wrapping is disabled and no match is found forward", function()
|
||||
assert.is_nil(matcher:find({
|
||||
forward = true,
|
||||
pos = { 4, 0 },
|
||||
wrap = false,
|
||||
}))
|
||||
end)
|
||||
|
||||
it("returns nil when wrapping is disabled and no match is found backward", function()
|
||||
assert.is_nil(matcher:find({
|
||||
forward = false,
|
||||
pos = { 0, 0 },
|
||||
wrap = false,
|
||||
}))
|
||||
end)
|
||||
|
||||
it("can handle multiple matches on the same pos", function()
|
||||
local mm = Matcher.new(1000)
|
||||
mm:set({
|
||||
{ win = 1000, pos = { 1, 0 }, end_pos = { 1, 1 } },
|
||||
{ win = 1000, pos = { 1, 0 }, end_pos = { 1, 2 } },
|
||||
{ win = 1000, pos = { 1, 0 }, end_pos = { 1, 3 } },
|
||||
})
|
||||
-- assert.same()
|
||||
end)
|
||||
end)
|
||||
@ -0,0 +1,43 @@
|
||||
--# selene: allow(incorrect_standard_library_use)
|
||||
local Pos = require("flash.search.pos")
|
||||
|
||||
describe("pos", function()
|
||||
it("handles new", function()
|
||||
assert.same(Pos({ row = 1, col = 2 }), { 1, 2 })
|
||||
assert.same(Pos({ 1, 2 }), { 1, 2 })
|
||||
end)
|
||||
|
||||
it("handles cmp", function()
|
||||
assert(Pos({ 1, 2 }) < Pos({ 2, 2 }))
|
||||
assert(Pos({ 1, 2 }) < Pos({ 1, 3 }))
|
||||
assert(Pos({ 1, 2 }) <= Pos({ 1, 2 }))
|
||||
assert(Pos({ 1, 2 }) <= Pos({ 2, 2 }))
|
||||
assert(Pos({ 1, 2 }) <= Pos({ 1, 3 }))
|
||||
assert(Pos({ 1, 2 }) == Pos({ 1, 2 }))
|
||||
assert(Pos({ 1, 2 }) == Pos({ 1, 2 }))
|
||||
assert(Pos({ 1, 2 }) ~= Pos({ 2, 2 }))
|
||||
assert(Pos({ 1, 2 }) <= Pos({ 2, 2 }))
|
||||
assert(Pos({ 1, 2 }) >= Pos({ 1, 2 }))
|
||||
assert(Pos({ 1, 2 }) >= Pos({ 1, 1 }))
|
||||
end)
|
||||
|
||||
it("handles add", function()
|
||||
assert.same(Pos({ 1, 2 }) + Pos({ 1, 2 }), { 2, 4 })
|
||||
assert.same(Pos({ 1, 2 }) + { 1, 2 }, { 2, 4 })
|
||||
assert.same(Pos({ 1, 2 }) + { row = 1, col = 2 }, { 2, 4 })
|
||||
end)
|
||||
|
||||
it("handles sub", function()
|
||||
assert.same(Pos({ 1, 2 }) - Pos({ 1, 2 }), { 0, 0 })
|
||||
assert.same(Pos({ 1, 2 }) - { 1, 2 }, { 0, 0 })
|
||||
assert.same(Pos({ 1, 2 }) - { row = 1, col = 2 }, { 0, 0 })
|
||||
end)
|
||||
|
||||
it("handles tostring", function()
|
||||
assert.same(tostring(Pos({ 1, 2 })), "[1, 2]")
|
||||
end)
|
||||
|
||||
it("handles id", function()
|
||||
assert.same(Pos({ 1, 2 }):id(123), "123:1:2")
|
||||
end)
|
||||
end)
|
||||
@ -0,0 +1,182 @@
|
||||
local Search = require("flash.search")
|
||||
local State = require("flash.state")
|
||||
local assert = require("luassert")
|
||||
|
||||
describe("search", function()
|
||||
local function set(text, pos)
|
||||
local lines = vim.split(vim.trim(text), "\n")
|
||||
lines = vim.tbl_map(function(line)
|
||||
return vim.trim(line)
|
||||
end, lines)
|
||||
vim.api.nvim_buf_set_lines(1, 0, -1, false, lines)
|
||||
vim.api.nvim_win_set_cursor(0, pos or { 1, 0 })
|
||||
end
|
||||
|
||||
before_each(function()
|
||||
vim.opt.ignorecase = true
|
||||
vim.opt.smartcase = true
|
||||
vim.api.nvim_buf_set_lines(1, 0, -1, false, {})
|
||||
set([[
|
||||
foo foo
|
||||
bar
|
||||
barfoo
|
||||
]])
|
||||
end)
|
||||
|
||||
local state = State.new({ pattern = "foo" })
|
||||
local search = Search.new(1000, state)
|
||||
|
||||
local matches = {
|
||||
{ win = 1000, pos = { 1, 0 }, end_pos = { 1, 2 } },
|
||||
{ win = 1000, pos = { 1, 4 }, end_pos = { 1, 6 } },
|
||||
{ win = 1000, pos = { 3, 3 }, end_pos = { 3, 5 } },
|
||||
}
|
||||
|
||||
it("sets matches", function()
|
||||
assert.same(matches, search:get())
|
||||
end)
|
||||
|
||||
it("finds backward from after end", function()
|
||||
assert.same(
|
||||
matches[3],
|
||||
search:find({
|
||||
forward = false,
|
||||
pos = { 4, 6 },
|
||||
wrap = false,
|
||||
})
|
||||
)
|
||||
end)
|
||||
|
||||
it("handles count = 0", function()
|
||||
assert.same(
|
||||
matches[2],
|
||||
search:find({
|
||||
pos = { 1, 4 },
|
||||
count = 0,
|
||||
})
|
||||
)
|
||||
assert.is_nil(search:find({
|
||||
pos = { 2, 7 },
|
||||
count = 0,
|
||||
}))
|
||||
end)
|
||||
|
||||
it("returns forward matches", function()
|
||||
assert.same(
|
||||
{ matches[3] },
|
||||
search:get({
|
||||
from = { 2, 6 },
|
||||
})
|
||||
)
|
||||
end)
|
||||
|
||||
it("returns forward matches", function()
|
||||
assert.same(
|
||||
{ matches[3] },
|
||||
search:get({
|
||||
from = { 3, 3 },
|
||||
})
|
||||
)
|
||||
end)
|
||||
|
||||
it("returns backward matches", function()
|
||||
assert.same(
|
||||
{ matches[1] },
|
||||
search:get({
|
||||
to = { 1, 3 },
|
||||
})
|
||||
)
|
||||
end)
|
||||
|
||||
it("returns backward matches at pos", function()
|
||||
assert.same(
|
||||
{ matches[1] },
|
||||
search:get({
|
||||
to = { 1, 0 },
|
||||
})
|
||||
)
|
||||
end)
|
||||
|
||||
it("finds matcher", function()
|
||||
assert.same({ win = 1000, pos = { 1, 4 }, end_pos = { 1, 6 } }, search:find())
|
||||
assert.same({ win = 1000, pos = { 3, 3 }, end_pos = { 3, 5 } }, search:find({ count = 2 }))
|
||||
assert.same(
|
||||
{ win = 1000, pos = { 3, 3 }, end_pos = { 3, 5 } },
|
||||
search:find({ forward = false })
|
||||
)
|
||||
assert.same(
|
||||
{ win = 1000, pos = { 1, 4 }, end_pos = { 1, 6 } },
|
||||
search:find({
|
||||
forward = false,
|
||||
pos = { 2, 7 },
|
||||
})
|
||||
)
|
||||
assert.same(
|
||||
{ win = 1000, pos = { 1, 4 }, end_pos = { 1, 6 } },
|
||||
search:find({
|
||||
forward = false,
|
||||
pos = { 3, 2 },
|
||||
})
|
||||
)
|
||||
end)
|
||||
|
||||
it("finds forward skipping match at current position", function()
|
||||
assert.same(
|
||||
matches[2],
|
||||
search:find({
|
||||
forward = true,
|
||||
pos = { 1, 0 },
|
||||
wrap = false,
|
||||
})
|
||||
)
|
||||
end)
|
||||
|
||||
it("finds backward skipping match at current position", function()
|
||||
assert.same(
|
||||
matches[2],
|
||||
search:find({
|
||||
forward = false,
|
||||
pos = { 3, 3 },
|
||||
wrap = true,
|
||||
})
|
||||
)
|
||||
end)
|
||||
|
||||
it("finds forward from a non-match position", function()
|
||||
assert.same(
|
||||
matches[2],
|
||||
search:find({
|
||||
forward = true,
|
||||
pos = { 1, 3 },
|
||||
wrap = false,
|
||||
})
|
||||
)
|
||||
end)
|
||||
|
||||
it("finds backward from a non-match position", function()
|
||||
assert.same(
|
||||
matches[2],
|
||||
search:find({
|
||||
forward = false,
|
||||
pos = { 3, 2 },
|
||||
wrap = true,
|
||||
})
|
||||
)
|
||||
end)
|
||||
|
||||
it("returns nil when wrapping is disabled and no match is found forward", function()
|
||||
assert.is_nil(search:find({
|
||||
forward = true,
|
||||
pos = { 4, 0 },
|
||||
wrap = false,
|
||||
}))
|
||||
end)
|
||||
|
||||
it("returns nil when wrapping is disabled and no match is found backward", function()
|
||||
assert.is_nil(search:find({
|
||||
forward = false,
|
||||
pos = { 1, 0 },
|
||||
wrap = false,
|
||||
}))
|
||||
end)
|
||||
end)
|
||||
@ -0,0 +1,190 @@
|
||||
local Search = require("flash.search")
|
||||
local State = require("flash.state")
|
||||
|
||||
describe("search.view", function()
|
||||
before_each(function()
|
||||
vim.opt.ignorecase = true
|
||||
vim.opt.smartcase = true
|
||||
vim.api.nvim_buf_set_lines(1, 0, -1, false, {})
|
||||
end)
|
||||
|
||||
local function get_matches(pattern)
|
||||
local state = State.new({ pattern = pattern, search = {
|
||||
mode = "search",
|
||||
} })
|
||||
local win = vim.api.nvim_get_current_win()
|
||||
local search = Search.new(win, state)
|
||||
return search:get()
|
||||
end
|
||||
|
||||
local function set(text, pos)
|
||||
local lines = vim.split(vim.trim(text), "\n")
|
||||
lines = vim.tbl_map(function(line)
|
||||
return vim.trim(line)
|
||||
end, lines)
|
||||
vim.api.nvim_buf_set_lines(1, 0, -1, false, lines)
|
||||
vim.api.nvim_win_set_cursor(0, pos or { 1, 0 })
|
||||
end
|
||||
|
||||
it("finds matches", function()
|
||||
set([[
|
||||
foobar
|
||||
line1
|
||||
line2
|
||||
]])
|
||||
|
||||
local matches = get_matches("line")
|
||||
assert.same({
|
||||
{ win = 1000, pos = { 2, 0 }, end_pos = { 2, 3 } },
|
||||
{ win = 1000, pos = { 3, 0 }, end_pos = { 3, 3 } },
|
||||
}, matches)
|
||||
end)
|
||||
|
||||
it("finds multi matches on same line", function()
|
||||
set([[
|
||||
foobar foobar
|
||||
line1
|
||||
lineFoo
|
||||
]])
|
||||
|
||||
local matches = get_matches("foo")
|
||||
assert.same({
|
||||
{ win = 1000, pos = { 1, 0 }, end_pos = { 1, 2 } },
|
||||
{ win = 1000, pos = { 1, 7 }, end_pos = { 1, 9 } },
|
||||
{ win = 1000, pos = { 3, 4 }, end_pos = { 3, 6 } },
|
||||
}, matches)
|
||||
end)
|
||||
|
||||
it("deals with case", function()
|
||||
set([[
|
||||
foobar
|
||||
Line1
|
||||
line2
|
||||
]])
|
||||
|
||||
local matches = get_matches("line")
|
||||
assert.same({
|
||||
{ win = 1000, pos = { 2, 0 }, end_pos = { 2, 3 } },
|
||||
{ win = 1000, pos = { 3, 0 }, end_pos = { 3, 3 } },
|
||||
}, matches)
|
||||
end)
|
||||
|
||||
it("deals with smartcase", function()
|
||||
set([[
|
||||
foobar
|
||||
Line1
|
||||
line2
|
||||
]])
|
||||
|
||||
local matches = get_matches("Line")
|
||||
assert.same({
|
||||
{ win = 1000, pos = { 2, 0 }, end_pos = { 2, 3 } },
|
||||
}, matches)
|
||||
end)
|
||||
|
||||
it("finds matches on each line", function()
|
||||
set([[
|
||||
line1
|
||||
line2
|
||||
line3
|
||||
]])
|
||||
|
||||
local matches = get_matches("line")
|
||||
assert.same({
|
||||
{ win = 1000, pos = { 1, 0 }, end_pos = { 1, 3 } },
|
||||
{ win = 1000, pos = { 2, 0 }, end_pos = { 2, 3 } },
|
||||
{ win = 1000, pos = { 3, 0 }, end_pos = { 3, 3 } },
|
||||
}, matches)
|
||||
end)
|
||||
|
||||
it("handles '\\Vi\\zs\\.'", function()
|
||||
set([[
|
||||
line1
|
||||
line2
|
||||
line3
|
||||
]])
|
||||
|
||||
local matches = get_matches([[\Vi\zs\m.]])
|
||||
assert.same({
|
||||
{ win = 1000, pos = { 1, 2 }, end_pos = { 1, 2 } },
|
||||
{ win = 1000, pos = { 2, 2 }, end_pos = { 2, 2 } },
|
||||
{ win = 1000, pos = { 3, 2 }, end_pos = { 3, 2 } },
|
||||
}, matches)
|
||||
end)
|
||||
|
||||
it("handles ^", function()
|
||||
set([[
|
||||
foobar
|
||||
line1
|
||||
line2
|
||||
]])
|
||||
|
||||
local matches = get_matches("^")
|
||||
assert.same({
|
||||
{ win = 1000, pos = { 1, 0 }, end_pos = { 1, 0 } },
|
||||
{ win = 1000, pos = { 2, 0 }, end_pos = { 2, 0 } },
|
||||
{ win = 1000, pos = { 3, 0 }, end_pos = { 3, 0 } },
|
||||
}, matches)
|
||||
end)
|
||||
|
||||
it("handles ^", function()
|
||||
set([[
|
||||
foobar
|
||||
line1
|
||||
line2
|
||||
]])
|
||||
|
||||
local matches = get_matches("^")
|
||||
assert.same({
|
||||
{ win = 1000, pos = { 1, 0 }, end_pos = { 1, 0 } },
|
||||
{ win = 1000, pos = { 2, 0 }, end_pos = { 2, 0 } },
|
||||
{ win = 1000, pos = { 3, 0 }, end_pos = { 3, 0 } },
|
||||
}, matches)
|
||||
end)
|
||||
|
||||
it("handles ^.\\?", function()
|
||||
set([[
|
||||
foobar
|
||||
line1
|
||||
line2
|
||||
]])
|
||||
|
||||
local matches = get_matches("^.\\?")
|
||||
assert.same({
|
||||
{ win = 1000, pos = { 1, 0 }, end_pos = { 1, 0 } },
|
||||
{ win = 1000, pos = { 2, 0 }, end_pos = { 2, 0 } },
|
||||
{ win = 1000, pos = { 3, 0 }, end_pos = { 3, 0 } },
|
||||
}, matches)
|
||||
end)
|
||||
|
||||
it("handles ^l", function()
|
||||
set([[
|
||||
foobar
|
||||
line1
|
||||
line2
|
||||
]])
|
||||
|
||||
local matches = get_matches("^l")
|
||||
assert.same({
|
||||
{ win = 1000, pos = { 2, 0 }, end_pos = { 2, 0 } },
|
||||
{ win = 1000, pos = { 3, 0 }, end_pos = { 3, 0 } },
|
||||
}, matches)
|
||||
end)
|
||||
|
||||
it("handles wrapping", function()
|
||||
set(
|
||||
[[
|
||||
foo
|
||||
line1
|
||||
foo
|
||||
]],
|
||||
{ 3, 0 }
|
||||
)
|
||||
|
||||
local matches = get_matches("foo")
|
||||
assert.same({
|
||||
{ win = 1000, pos = { 1, 0 }, end_pos = { 1, 2 } },
|
||||
{ win = 1000, pos = { 3, 0 }, end_pos = { 3, 2 } },
|
||||
}, matches)
|
||||
end)
|
||||
end)
|
||||
@ -0,0 +1,11 @@
|
||||
local State = require("flash.state")
|
||||
local assert = require("luassert")
|
||||
|
||||
describe("unicode", function()
|
||||
local labels = "😅😀🏇🐎🐴🐵🐒"
|
||||
|
||||
it("splits labels", function()
|
||||
local state = State.new({ labels = labels })
|
||||
assert.same({ "😅", "😀", "🏇", "🐎", "🐴", "🐵", "🐒" }, state:labels())
|
||||
end)
|
||||
end)
|
||||
Reference in New Issue
Block a user