Update generated neovim config
This commit is contained in:
@ -0,0 +1,14 @@
|
||||
local Buf = require("which-key.buf")
|
||||
|
||||
before_each(function()
|
||||
require("helpers").reset()
|
||||
end)
|
||||
|
||||
describe("triggers", function()
|
||||
it("does not create hooks for default mappings", function()
|
||||
vim.keymap.set("n", "aa", "<nop>")
|
||||
Buf.get({ mode = "n" })
|
||||
local m = vim.fn.maparg("a", "n", false, true)
|
||||
assert.same(vim.empty_dict(), m)
|
||||
end)
|
||||
end)
|
||||
@ -0,0 +1,12 @@
|
||||
local M = {}
|
||||
|
||||
---@param lines? string[]
|
||||
function M.reset(lines)
|
||||
vim.o.showmode = false
|
||||
vim.api.nvim_feedkeys(vim.keycode("<Ignore><C-\\><C-n><esc>"), "nx", false)
|
||||
vim.cmd("enew")
|
||||
vim.cmd("normal! <c-w>o")
|
||||
vim.api.nvim_buf_set_lines(0, 0, -1, false, lines or {})
|
||||
end
|
||||
|
||||
return M
|
||||
@ -0,0 +1,38 @@
|
||||
local layout = require("which-key.layout")
|
||||
|
||||
describe("dim", function()
|
||||
local tests = {
|
||||
{ 100, { 200 }, 100 },
|
||||
{ 0.2, { 100 }, 20 },
|
||||
{ -0.2, { 100 }, 80 },
|
||||
{ -20, { 100 }, 80 },
|
||||
{ 1, { 100 }, 1 },
|
||||
{ 100, { 200, { min = 50 } }, 100 },
|
||||
{ 100, { 200, { max = 150 } }, 100 },
|
||||
{ 100, { 200, { max = 150, min = 50 } }, 100 },
|
||||
{ 100, { 200, { max = 150, min = 150 } }, 150 },
|
||||
{ 0.2, { 100, { max = 150, min = 20 } }, 20 },
|
||||
{ 0.2, { 100, { max = 50, min = 20 } }, 20 },
|
||||
{ math.huge, { 200 }, 200 },
|
||||
{ -0.5, { 200 }, 100 },
|
||||
{ 0.5, { 200 }, 100 },
|
||||
{ 0.5, { 200, { min = 150 } }, 150 },
|
||||
{ -0.5, { 200, { max = 50 } }, 50 },
|
||||
{ 300, { 200, { max = 250 } }, 200 },
|
||||
{ 300, { 200, { min = 250 } }, 200 },
|
||||
{ -100, { 100, { max = 90, min = 20 } }, 20 },
|
||||
{ -200, { 100, { max = -50, min = -50 } }, 0 },
|
||||
{ 0.2, { 100, { min = 0.5 } }, 50 },
|
||||
{ -200, { 100 }, 0 },
|
||||
{ -1, { 100 }, 99 },
|
||||
{ -0.1, { 100 }, 90 },
|
||||
{ 0.1, { 100 }, 10 },
|
||||
{ 14, { 212, 0.9 }, 191 },
|
||||
}
|
||||
|
||||
for _, test in ipairs(tests) do
|
||||
it("size=" .. test[1] .. ", parent=" .. test[2][1] .. ", result = " .. test[3], function()
|
||||
assert.are.equal(test[3], layout.dim(test[1], unpack(test[2])))
|
||||
end)
|
||||
end
|
||||
end)
|
||||
@ -0,0 +1,101 @@
|
||||
local Mappings = require("which-key.mappings")
|
||||
|
||||
before_each(function()
|
||||
Mappings.notifs = {}
|
||||
end)
|
||||
|
||||
describe("specs v1", function()
|
||||
local tests = {
|
||||
{
|
||||
spec = {
|
||||
["<leader>"] = {
|
||||
name = "leader",
|
||||
["a"] = { "a" },
|
||||
["b"] = { "b" },
|
||||
["c"] = { "c" },
|
||||
},
|
||||
},
|
||||
mappings = {
|
||||
{ lhs = "<leader>", group = true, desc = "leader", mode = "n" },
|
||||
{ lhs = "<leader>a", desc = "a", mode = "n" },
|
||||
{ lhs = "<leader>b", desc = "b", mode = "n" },
|
||||
{ lhs = "<leader>c", desc = "c", mode = "n" },
|
||||
},
|
||||
},
|
||||
{
|
||||
spec = {
|
||||
mode = "v",
|
||||
["<leader>"] = {
|
||||
name = "leader",
|
||||
["a"] = { "a" },
|
||||
["b"] = { "b" },
|
||||
["c"] = { "c" },
|
||||
},
|
||||
},
|
||||
mappings = {
|
||||
{ lhs = "<leader>", group = true, desc = "leader", mode = "v" },
|
||||
{ lhs = "<leader>a", desc = "a", mode = "v" },
|
||||
{ lhs = "<leader>b", desc = "b", mode = "v" },
|
||||
{ lhs = "<leader>c", desc = "c", mode = "v" },
|
||||
},
|
||||
},
|
||||
{
|
||||
spec = { desc = "foo", noremap = true },
|
||||
mappings = {},
|
||||
},
|
||||
{
|
||||
spec = { a = { desc = "which_key_ignore" } },
|
||||
mappings = {
|
||||
{ lhs = "a", hidden = true, mode = "n" },
|
||||
},
|
||||
},
|
||||
{
|
||||
spec = { a = { "foo", cond = false } },
|
||||
mappings = {},
|
||||
},
|
||||
{
|
||||
spec = { a = { "foo", cond = true } },
|
||||
mappings = {
|
||||
{ desc = "foo", lhs = "a", mode = "n" },
|
||||
},
|
||||
},
|
||||
{
|
||||
spec = {
|
||||
a = { "a", cmd = "aa" },
|
||||
b = { "b", callback = "bb" },
|
||||
c = { "cc", "c" },
|
||||
d = { "dd", desc = "d" },
|
||||
},
|
||||
mappings = {
|
||||
{ lhs = "a", desc = "a", rhs = "aa", mode = "n", silent = true },
|
||||
{ lhs = "b", desc = "b", rhs = "bb", mode = "n", silent = true },
|
||||
{ lhs = "c", desc = "c", rhs = "cc", mode = "n", silent = true },
|
||||
{ lhs = "d", desc = "dd", mode = "n" },
|
||||
},
|
||||
},
|
||||
{
|
||||
spec = {
|
||||
a = { "a1" },
|
||||
b = { "b1", "b2" },
|
||||
c = { "c1", desc = "c2" },
|
||||
},
|
||||
mappings = {
|
||||
{ lhs = "a", desc = "a1", mode = "n" },
|
||||
{ lhs = "b", desc = "b2", rhs = "b1", mode = "n", silent = true },
|
||||
{ lhs = "c", desc = "c1", mode = "n" },
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
-- Function to run the tests
|
||||
for t, test in ipairs(tests) do
|
||||
it(tostring(t), function()
|
||||
local result = Mappings.parse(test.spec, { version = 1 })
|
||||
assert.same(test.mappings, result)
|
||||
local errors = vim.tbl_filter(function(n)
|
||||
return n.level >= vim.log.levels.ERROR
|
||||
end, Mappings.notifs)
|
||||
assert.same({}, errors)
|
||||
end)
|
||||
end
|
||||
end)
|
||||
@ -0,0 +1,17 @@
|
||||
#!/usr/bin/env -S nvim -l
|
||||
|
||||
vim.env.LAZY_STDPATH = ".tests"
|
||||
vim.env.LAZY_PATH = vim.fs.normalize("~/projects/lazy.nvim")
|
||||
load(vim.fn.system("curl -s https://raw.githubusercontent.com/folke/lazy.nvim/main/bootstrap.lua"))()
|
||||
|
||||
-- Setup lazy.nvim
|
||||
require("lazy.minit").setup({
|
||||
spec = {
|
||||
{
|
||||
dir = vim.uv.cwd(),
|
||||
opts = {
|
||||
notify = false,
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
@ -0,0 +1,125 @@
|
||||
---@module 'luassert'
|
||||
|
||||
local Util = require("which-key.util")
|
||||
|
||||
describe("parse keys", function()
|
||||
local tests = {
|
||||
[" <c-a><esc>Ä<lt>🔥foo"] = {
|
||||
"<Space>",
|
||||
"<C-A>",
|
||||
"<Esc>",
|
||||
"Ä",
|
||||
"<",
|
||||
"🔥",
|
||||
"f",
|
||||
"o",
|
||||
"o",
|
||||
},
|
||||
["\1<esc>Ä<lt>🔥foo"] = {
|
||||
"<C-A>",
|
||||
"<Esc>",
|
||||
"Ä",
|
||||
"<",
|
||||
"🔥",
|
||||
"f",
|
||||
"o",
|
||||
"o",
|
||||
},
|
||||
["<esc>"] = { "<Esc>" },
|
||||
["foo<baz>"] = { "f", "o", "o", "<", "b", "a", "z", ">" },
|
||||
["foo<bar>"] = { "f", "o", "o", "|" },
|
||||
["foo<a-2>"] = { "f", "o", "o", "<M-2>" },
|
||||
["foo<A-2>"] = { "f", "o", "o", "<M-2>" },
|
||||
["foo<m-2>"] = { "f", "o", "o", "<M-2>" },
|
||||
["foo<M-2>"] = { "f", "o", "o", "<M-2>" },
|
||||
["foo<"] = { "f", "o", "o", "<" },
|
||||
["foo<bar"] = { "f", "o", "o", "<", "b", "a", "r" },
|
||||
["foo>"] = { "f", "o", "o", ">" },
|
||||
-- test with japanese chars
|
||||
["fooあ"] = { "f", "o", "o", "あ" },
|
||||
["fooあ<lt>"] = { "f", "o", "o", "あ", "<" },
|
||||
["fooあ<lt>bar"] = { "f", "o", "o", "あ", "<", "b", "a", "r" },
|
||||
["fooあ<lt>bar<lt>"] = { "f", "o", "o", "あ", "<", "b", "a", "r", "<" },
|
||||
["fooあ<lt>bar<lt>baz"] = { "f", "o", "o", "あ", "<", "b", "a", "r", "<", "b", "a", "z" },
|
||||
["fooあ<lt>bar<lt>baz<lt>"] = { "f", "o", "o", "あ", "<", "b", "a", "r", "<", "b", "a", "z", "<" },
|
||||
["fooあ<lt>bar<lt>baz<lt>qux"] = {
|
||||
"f",
|
||||
"o",
|
||||
"o",
|
||||
"あ",
|
||||
"<",
|
||||
"b",
|
||||
"a",
|
||||
"r",
|
||||
"<",
|
||||
"b",
|
||||
"a",
|
||||
"z",
|
||||
"<",
|
||||
"q",
|
||||
"u",
|
||||
"x",
|
||||
},
|
||||
["fooあ<lt>bar<lt>baz<lt>qux<lt>"] = {
|
||||
"f",
|
||||
"o",
|
||||
"o",
|
||||
"あ",
|
||||
"<",
|
||||
"b",
|
||||
"a",
|
||||
"r",
|
||||
"<",
|
||||
"b",
|
||||
"a",
|
||||
"z",
|
||||
"<",
|
||||
"q",
|
||||
"u",
|
||||
"x",
|
||||
"<",
|
||||
},
|
||||
}
|
||||
|
||||
for input, output in pairs(tests) do
|
||||
it(("should parse %q"):format(input), function()
|
||||
local keys = Util.keys(input)
|
||||
assert.same(output, keys)
|
||||
end)
|
||||
end
|
||||
end)
|
||||
|
||||
describe("modes", function()
|
||||
before_each(function()
|
||||
require("helpers").reset()
|
||||
end)
|
||||
|
||||
local tests = {
|
||||
["gg"] = "n",
|
||||
["vl"] = "x",
|
||||
["<c-v>j"] = "x",
|
||||
["gh"] = "s",
|
||||
["aa"] = "i",
|
||||
["ciw"] = "o",
|
||||
["c"] = "n",
|
||||
["<cmd>terminal exit<cr>"] = "n",
|
||||
}
|
||||
|
||||
local inputs = vim.tbl_keys(tests)
|
||||
table.sort(inputs)
|
||||
for _, input in ipairs(inputs) do
|
||||
local output = tests[input]
|
||||
it(("should return %q for %q"):format(output, input), function()
|
||||
local mode = "n"
|
||||
assert.same(mode, Util.mapmode())
|
||||
vim.api.nvim_create_autocmd("ModeChanged", {
|
||||
once = true,
|
||||
callback = function()
|
||||
mode = Util.mapmode()
|
||||
end,
|
||||
})
|
||||
vim.api.nvim_feedkeys(vim.keycode(input), "nitx", false)
|
||||
assert.same(output, mode)
|
||||
end)
|
||||
end
|
||||
end)
|
||||
Reference in New Issue
Block a user