spacevim/bundle/nui.nvim/tests/nui/input/init_spec.lua
JIe 2bb7059579
Some checks failed
Detach Plugins / check (FlyGrep.vim) (push) Has been cancelled
Detach Plugins / check (GitHub.vim) (push) Has been cancelled
Detach Plugins / check (JavaUnit.vim) (push) Has been cancelled
Detach Plugins / check (SourceCounter.vim) (push) Has been cancelled
Detach Plugins / check (cpicker.nvim) (push) Has been cancelled
Detach Plugins / check (dein-ui.vim) (push) Has been cancelled
Detach Plugins / check (git.vim) (push) Has been cancelled
Detach Plugins / check (iedit.vim) (push) Has been cancelled
Detach Plugins / check (scrollbar.vim) (push) Has been cancelled
Detach Plugins / check (vim-chat) (push) Has been cancelled
Detach Plugins / check (vim-cheat) (push) Has been cancelled
Detach Plugins / check (vim-todo) (push) Has been cancelled
Detach Plugins / check (xmake.vim) (push) Has been cancelled
test / Linux (nvim, nightly) (push) Has been cancelled
test / Linux (nvim, v0.3.8) (push) Has been cancelled
test / Linux (nvim, v0.4.0) (push) Has been cancelled
test / Linux (nvim, v0.4.2) (push) Has been cancelled
test / Linux (nvim, v0.4.3) (push) Has been cancelled
test / Linux (nvim, v0.4.4) (push) Has been cancelled
test / Linux (nvim, v0.5.0) (push) Has been cancelled
test / Linux (nvim, v0.5.1) (push) Has been cancelled
test / Linux (nvim, v0.6.0) (push) Has been cancelled
test / Linux (nvim, v0.6.1) (push) Has been cancelled
test / Linux (nvim, v0.7.0) (push) Has been cancelled
test / Linux (nvim, v0.7.2) (push) Has been cancelled
test / Linux (nvim, v0.8.0) (push) Has been cancelled
test / Linux (nvim, v0.8.1) (push) Has been cancelled
test / Linux (nvim, v0.8.2) (push) Has been cancelled
test / Linux (nvim, v0.8.3) (push) Has been cancelled
test / Linux (nvim, v0.9.0) (push) Has been cancelled
test / Linux (nvim, v0.9.1) (push) Has been cancelled
test / Linux (true, vim, v7.4.052) (push) Has been cancelled
test / Linux (true, vim, v7.4.1689) (push) Has been cancelled
test / Linux (true, vim, v7.4.629) (push) Has been cancelled
test / Linux (true, vim, v8.0.0027) (push) Has been cancelled
test / Linux (true, vim, v8.0.0183) (push) Has been cancelled
test / Linux (vim, nightly) (push) Has been cancelled
test / Linux (vim, v8.0.0184) (push) Has been cancelled
test / Linux (vim, v8.0.1453) (push) Has been cancelled
test / Linux (vim, v8.1.2269) (push) Has been cancelled
test / Linux (vim, v8.2.2434) (push) Has been cancelled
test / Linux (vim, v8.2.3995) (push) Has been cancelled
test / Windows (nvim, nightly) (push) Has been cancelled
test / Windows (nvim, v0.3.8) (push) Has been cancelled
test / Windows (nvim, v0.4.2) (push) Has been cancelled
test / Windows (nvim, v0.4.3) (push) Has been cancelled
test / Windows (nvim, v0.4.4) (push) Has been cancelled
test / Windows (nvim, v0.5.0) (push) Has been cancelled
test / Windows (nvim, v0.5.1) (push) Has been cancelled
test / Windows (nvim, v0.6.0) (push) Has been cancelled
test / Windows (nvim, v0.6.1) (push) Has been cancelled
test / Windows (nvim, v0.7.0) (push) Has been cancelled
test / Windows (nvim, v0.7.2) (push) Has been cancelled
test / Windows (nvim, v0.8.0) (push) Has been cancelled
test / Windows (nvim, v0.8.1) (push) Has been cancelled
test / Windows (nvim, v0.8.2) (push) Has been cancelled
test / Windows (nvim, v0.8.3) (push) Has been cancelled
test / Windows (nvim, v0.9.0) (push) Has been cancelled
test / Windows (nvim, v0.9.1) (push) Has been cancelled
test / Windows (vim, nightly) (push) Has been cancelled
test / Windows (vim, v7.4.1185) (push) Has been cancelled
test / Windows (vim, v7.4.1689) (push) Has been cancelled
test / Windows (vim, v8.0.0027) (push) Has been cancelled
test / Windows (vim, v8.0.1453) (push) Has been cancelled
test / Windows (vim, v8.1.2269) (push) Has been cancelled
test / Windows (vim, v8.2.2434) (push) Has been cancelled
test / Windows (vim, v8.2.3995) (push) Has been cancelled
docker / docker (push) Has been cancelled
mirror / check (coding) (push) Has been cancelled
mirror / check (gitee) (push) Has been cancelled
mirror / check (gitlab) (push) Has been cancelled
init
2024-08-21 14:17:26 +08:00

160 lines
3.3 KiB
Lua

pcall(require, "luacov")
local Input = require("nui.input")
local Text = require("nui.text")
local h = require("tests.helpers")
local eq, feedkeys = h.eq, h.feedkeys
-- Input's functionalities are not testable using headless nvim.
-- Not sure what to do about it.
describe("nui.input", function()
local parent_winid, parent_bufnr
local popup_options
local input
before_each(function()
parent_winid = vim.api.nvim_get_current_win()
parent_bufnr = vim.api.nvim_get_current_buf()
popup_options = {
relative = "win",
position = "50%",
size = 20,
}
end)
after_each(function()
if input then
input:unmount()
input = nil
end
end)
pending("o.prompt", function()
it("supports NuiText", function()
local prompt_text = "> "
local hl_group = "NuiInputTest"
input = Input(popup_options, {
prompt = Text(prompt_text, hl_group),
})
input:mount()
h.assert_buf_lines(input.bufnr, {
prompt_text,
})
h.assert_highlight(input.bufnr, input.ns_id, 1, prompt_text, hl_group)
end)
end)
describe("cursor_position_patch", function()
local initial_cursor
local function setup()
vim.api.nvim_buf_set_lines(parent_bufnr, 0, -1, false, {
"1 nui.nvim",
"2 nui.nvim",
"3 nui.nvim",
})
initial_cursor = { 2, 4 }
vim.api.nvim_win_set_cursor(parent_winid, initial_cursor)
end
it("works after submitting from insert mode", function()
setup()
local done = false
input = Input(popup_options, {
on_submit = function()
done = true
end,
})
input:mount()
feedkeys("<cr>", "x")
vim.fn.wait(1000, function()
return done
end)
eq(done, true)
eq(vim.api.nvim_win_get_cursor(parent_winid), initial_cursor)
end)
it("works after submitting from normal mode", function()
setup()
local done = false
input = Input(popup_options, {
on_submit = function()
done = true
end,
})
input:mount()
feedkeys("<esc><cr>", "x")
vim.fn.wait(1000, function()
return done
end)
eq(done, true)
eq(vim.api.nvim_win_get_cursor(parent_winid), initial_cursor)
end)
it("works after closing from insert mode", function()
setup()
local done = false
input = Input(popup_options, {
on_close = function()
done = true
end,
})
input:mount()
input:map("i", "<esc>", input.input_props.on_close, { nowait = true, noremap = true })
feedkeys("i<esc>", "x")
vim.fn.wait(1000, function()
return done
end)
eq(done, true)
eq(vim.api.nvim_win_get_cursor(parent_winid), initial_cursor)
end)
it("works after closing from normal mode", function()
setup()
local done = false
input = Input(popup_options, {
on_close = function()
done = true
end,
})
input:mount()
input:map("n", "<esc>", input.input_props.on_close, { nowait = true, noremap = true })
feedkeys("<esc>", "x")
vim.fn.wait(1000, function()
return done
end)
eq(done, true)
eq(vim.api.nvim_win_get_cursor(parent_winid), initial_cursor)
end)
end)
end)