2024-04-20 08:44:13 -07:00
|
|
|
local t = require('test.testutil')
|
|
|
|
local n = require('test.functional.testnvim')()
|
2019-05-19 19:57:45 -07:00
|
|
|
local Screen = require('test.functional.ui.screen')
|
2024-04-20 08:44:13 -07:00
|
|
|
|
|
|
|
local feed = n.feed
|
|
|
|
local source = n.source
|
|
|
|
local clear = n.clear
|
|
|
|
local command = n.command
|
|
|
|
local expect = n.expect
|
|
|
|
local poke_eventloop = n.poke_eventloop
|
|
|
|
local api = n.api
|
2024-04-08 02:03:20 -07:00
|
|
|
local eq = t.eq
|
|
|
|
local neq = t.neq
|
2019-05-19 19:57:45 -07:00
|
|
|
|
|
|
|
describe('prompt buffer', function()
|
|
|
|
local screen
|
|
|
|
|
|
|
|
before_each(function()
|
|
|
|
clear()
|
|
|
|
screen = Screen.new(25, 10)
|
2023-04-02 17:36:14 -07:00
|
|
|
command('set laststatus=0 nohidden')
|
|
|
|
end)
|
2023-02-21 02:43:53 -07:00
|
|
|
|
2023-04-02 17:36:14 -07:00
|
|
|
local function source_script()
|
|
|
|
source([[
|
2019-05-19 19:57:45 -07:00
|
|
|
func TextEntered(text)
|
|
|
|
if a:text == "exit"
|
2023-02-21 02:43:53 -07:00
|
|
|
" Reset &modified to allow the buffer to be closed.
|
2019-05-24 21:15:01 -07:00
|
|
|
set nomodified
|
2019-05-19 19:57:45 -07:00
|
|
|
stopinsert
|
|
|
|
close
|
|
|
|
else
|
2023-02-21 02:43:53 -07:00
|
|
|
" Add the output above the current prompt.
|
2019-05-19 19:57:45 -07:00
|
|
|
call append(line("$") - 1, 'Command: "' . a:text . '"')
|
2023-02-21 02:43:53 -07:00
|
|
|
" Reset &modified to allow the buffer to be closed.
|
2022-05-21 14:07:34 -07:00
|
|
|
set nomodified
|
2019-05-19 19:57:45 -07:00
|
|
|
call timer_start(20, {id -> TimerFunc(a:text)})
|
|
|
|
endif
|
|
|
|
endfunc
|
|
|
|
|
|
|
|
func TimerFunc(text)
|
2023-02-21 02:43:53 -07:00
|
|
|
" Add the output above the current prompt.
|
2019-05-19 19:57:45 -07:00
|
|
|
call append(line("$") - 1, 'Result: "' . a:text .'"')
|
2023-02-21 02:43:53 -07:00
|
|
|
" Reset &modified to allow the buffer to be closed.
|
|
|
|
set nomodified
|
2019-05-19 19:57:45 -07:00
|
|
|
endfunc
|
2021-11-25 15:53:14 -07:00
|
|
|
|
|
|
|
func SwitchWindows()
|
2022-05-21 14:07:34 -07:00
|
|
|
call timer_start(0, {-> execute("wincmd p", "")})
|
2021-11-25 15:53:14 -07:00
|
|
|
endfunc
|
2019-05-19 19:57:45 -07:00
|
|
|
|
2023-02-21 02:43:53 -07:00
|
|
|
call setline(1, "other buffer")
|
|
|
|
set nomodified
|
|
|
|
new
|
|
|
|
set buftype=prompt
|
|
|
|
call prompt_setcallback(bufnr(''), function("TextEntered"))
|
|
|
|
eval bufnr("")->prompt_setprompt("cmd: ")
|
|
|
|
startinsert
|
|
|
|
]])
|
2019-05-19 19:57:45 -07:00
|
|
|
screen:expect([[
|
2023-02-21 02:43:53 -07:00
|
|
|
cmd: ^ |
|
2024-03-22 03:02:52 -07:00
|
|
|
{1:~ }|*3
|
|
|
|
{3:[Prompt] [+] }|
|
2019-05-19 19:57:45 -07:00
|
|
|
other buffer |
|
2024-03-22 03:02:52 -07:00
|
|
|
{1:~ }|*3
|
|
|
|
{5:-- INSERT --} |
|
2019-05-19 19:57:45 -07:00
|
|
|
]])
|
2023-04-02 17:36:14 -07:00
|
|
|
end
|
2023-02-21 02:43:53 -07:00
|
|
|
|
|
|
|
-- oldtest: Test_prompt_basic()
|
|
|
|
it('works', function()
|
2023-04-02 17:36:14 -07:00
|
|
|
source_script()
|
2019-05-19 19:57:45 -07:00
|
|
|
feed('hello\n')
|
|
|
|
screen:expect([[
|
2021-11-25 20:34:41 -07:00
|
|
|
cmd: hello |
|
2019-05-19 19:57:45 -07:00
|
|
|
Command: "hello" |
|
|
|
|
Result: "hello" |
|
2021-11-25 20:34:41 -07:00
|
|
|
cmd: ^ |
|
2024-03-22 03:02:52 -07:00
|
|
|
{3:[Prompt] }|
|
2019-05-19 19:57:45 -07:00
|
|
|
other buffer |
|
2024-03-22 03:02:52 -07:00
|
|
|
{1:~ }|*3
|
|
|
|
{5:-- INSERT --} |
|
2019-05-19 19:57:45 -07:00
|
|
|
]])
|
|
|
|
feed('exit\n')
|
|
|
|
screen:expect([[
|
|
|
|
^other buffer |
|
2024-03-22 03:02:52 -07:00
|
|
|
{1:~ }|*8
|
2019-05-19 19:57:45 -07:00
|
|
|
|
|
|
|
|
]])
|
|
|
|
end)
|
|
|
|
|
2023-02-21 02:43:53 -07:00
|
|
|
-- oldtest: Test_prompt_editing()
|
2019-05-22 09:47:56 -07:00
|
|
|
it('editing', function()
|
2023-04-02 17:36:14 -07:00
|
|
|
source_script()
|
2019-05-22 09:47:56 -07:00
|
|
|
feed('hello<BS><BS>')
|
|
|
|
screen:expect([[
|
2021-11-25 20:34:41 -07:00
|
|
|
cmd: hel^ |
|
2024-03-22 03:02:52 -07:00
|
|
|
{1:~ }|*3
|
|
|
|
{3:[Prompt] [+] }|
|
2019-05-22 09:47:56 -07:00
|
|
|
other buffer |
|
2024-03-22 03:02:52 -07:00
|
|
|
{1:~ }|*3
|
|
|
|
{5:-- INSERT --} |
|
2019-05-22 09:47:56 -07:00
|
|
|
]])
|
|
|
|
feed('<Left><Left><Left><BS>-')
|
|
|
|
screen:expect([[
|
2021-11-25 20:34:41 -07:00
|
|
|
cmd: -^hel |
|
2024-03-22 03:02:52 -07:00
|
|
|
{1:~ }|*3
|
|
|
|
{3:[Prompt] [+] }|
|
2019-05-22 09:47:56 -07:00
|
|
|
other buffer |
|
2024-03-22 03:02:52 -07:00
|
|
|
{1:~ }|*3
|
|
|
|
{5:-- INSERT --} |
|
2019-05-22 09:47:56 -07:00
|
|
|
]])
|
2021-11-07 06:12:17 -07:00
|
|
|
feed('<C-O>lz')
|
|
|
|
screen:expect([[
|
2021-11-25 20:34:41 -07:00
|
|
|
cmd: -hz^el |
|
2024-03-22 03:02:52 -07:00
|
|
|
{1:~ }|*3
|
|
|
|
{3:[Prompt] [+] }|
|
2021-11-07 06:12:17 -07:00
|
|
|
other buffer |
|
2024-03-22 03:02:52 -07:00
|
|
|
{1:~ }|*3
|
|
|
|
{5:-- INSERT --} |
|
2021-11-07 06:12:17 -07:00
|
|
|
]])
|
2019-05-22 09:47:56 -07:00
|
|
|
feed('<End>x')
|
|
|
|
screen:expect([[
|
2021-11-25 20:34:41 -07:00
|
|
|
cmd: -hzelx^ |
|
2024-03-22 03:02:52 -07:00
|
|
|
{1:~ }|*3
|
|
|
|
{3:[Prompt] [+] }|
|
2019-05-22 09:47:56 -07:00
|
|
|
other buffer |
|
2024-03-22 03:02:52 -07:00
|
|
|
{1:~ }|*3
|
|
|
|
{5:-- INSERT --} |
|
2019-05-22 09:47:56 -07:00
|
|
|
]])
|
|
|
|
feed('<C-U>exit\n')
|
|
|
|
screen:expect([[
|
|
|
|
^other buffer |
|
2024-03-22 03:02:52 -07:00
|
|
|
{1:~ }|*8
|
2019-05-22 09:47:56 -07:00
|
|
|
|
|
|
|
|
]])
|
|
|
|
end)
|
|
|
|
|
2023-02-21 02:43:53 -07:00
|
|
|
-- oldtest: Test_prompt_switch_windows()
|
2021-11-25 15:53:14 -07:00
|
|
|
it('switch windows', function()
|
2023-04-02 17:36:14 -07:00
|
|
|
source_script()
|
2021-11-25 15:53:14 -07:00
|
|
|
feed('<C-O>:call SwitchWindows()<CR>')
|
2024-03-22 03:02:52 -07:00
|
|
|
screen:expect([[
|
2022-05-21 14:07:34 -07:00
|
|
|
cmd: |
|
2024-03-22 03:02:52 -07:00
|
|
|
{1:~ }|*3
|
|
|
|
{2:[Prompt] [+] }|
|
2022-05-21 14:07:34 -07:00
|
|
|
^other buffer |
|
2024-03-22 03:02:52 -07:00
|
|
|
{1:~ }|*3
|
2022-05-21 14:07:34 -07:00
|
|
|
|
|
2024-03-22 03:02:52 -07:00
|
|
|
]])
|
2022-05-21 14:07:34 -07:00
|
|
|
feed('<C-O>:call SwitchWindows()<CR>')
|
2021-11-25 15:53:14 -07:00
|
|
|
screen:expect([[
|
|
|
|
cmd: ^ |
|
2024-03-22 03:02:52 -07:00
|
|
|
{1:~ }|*3
|
|
|
|
{3:[Prompt] [+] }|
|
2021-11-25 15:53:14 -07:00
|
|
|
other buffer |
|
2024-03-22 03:02:52 -07:00
|
|
|
{1:~ }|*3
|
|
|
|
{5:-- INSERT --} |
|
2021-11-25 15:53:14 -07:00
|
|
|
]])
|
|
|
|
feed('<Esc>')
|
|
|
|
screen:expect([[
|
|
|
|
cmd:^ |
|
2024-03-22 03:02:52 -07:00
|
|
|
{1:~ }|*3
|
|
|
|
{3:[Prompt] [+] }|
|
2021-11-25 15:53:14 -07:00
|
|
|
other buffer |
|
2024-03-22 03:02:52 -07:00
|
|
|
{1:~ }|*3
|
2021-11-25 15:53:14 -07:00
|
|
|
|
|
|
|
|
]])
|
|
|
|
end)
|
|
|
|
|
2023-02-21 02:43:53 -07:00
|
|
|
-- oldtest: Test_prompt_while_writing_to_hidden_buffer()
|
2021-11-07 14:28:11 -07:00
|
|
|
it('keeps insert mode after aucmd_restbuf in callback', function()
|
2023-04-02 17:36:14 -07:00
|
|
|
source_script()
|
2021-11-07 14:28:11 -07:00
|
|
|
source [[
|
|
|
|
let s:buf = nvim_create_buf(1, 1)
|
|
|
|
call timer_start(0, {-> nvim_buf_set_lines(s:buf, -1, -1, 0, ['walrus'])})
|
|
|
|
]]
|
|
|
|
poke_eventloop()
|
2024-01-12 10:59:57 -07:00
|
|
|
eq({ mode = 'i', blocking = false }, api.nvim_get_mode())
|
2023-04-02 17:36:14 -07:00
|
|
|
end)
|
|
|
|
|
|
|
|
-- oldtest: Test_prompt_appending_while_hidden()
|
|
|
|
it('accessing hidden prompt buffer does not start insert mode', function()
|
2024-01-12 10:59:57 -07:00
|
|
|
local prev_win = api.nvim_get_current_win()
|
2023-04-02 17:36:14 -07:00
|
|
|
source([[
|
|
|
|
new prompt
|
|
|
|
set buftype=prompt
|
|
|
|
set bufhidden=hide
|
|
|
|
|
|
|
|
func s:TextEntered(text)
|
|
|
|
if a:text == 'exit'
|
|
|
|
close
|
|
|
|
endif
|
|
|
|
let g:entered = a:text
|
|
|
|
endfunc
|
|
|
|
call prompt_setcallback(bufnr(), function('s:TextEntered'))
|
|
|
|
|
|
|
|
func DoAppend()
|
|
|
|
call appendbufline('prompt', '$', 'Test')
|
2023-04-09 16:33:26 -07:00
|
|
|
return ''
|
2023-04-02 17:36:14 -07:00
|
|
|
endfunc
|
|
|
|
]])
|
|
|
|
feed('asomething<CR>')
|
2024-01-12 10:59:57 -07:00
|
|
|
eq('something', api.nvim_get_var('entered'))
|
|
|
|
neq(prev_win, api.nvim_get_current_win())
|
2023-04-02 17:36:14 -07:00
|
|
|
feed('exit<CR>')
|
2024-01-12 10:59:57 -07:00
|
|
|
eq(prev_win, api.nvim_get_current_win())
|
|
|
|
eq({ mode = 'n', blocking = false }, api.nvim_get_mode())
|
2023-04-02 17:36:14 -07:00
|
|
|
command('call DoAppend()')
|
2024-01-12 10:59:57 -07:00
|
|
|
eq({ mode = 'n', blocking = false }, api.nvim_get_mode())
|
2023-04-09 16:33:26 -07:00
|
|
|
feed('i')
|
2024-01-12 10:59:57 -07:00
|
|
|
eq({ mode = 'i', blocking = false }, api.nvim_get_mode())
|
2023-04-09 16:33:26 -07:00
|
|
|
command('call DoAppend()')
|
2024-01-12 10:59:57 -07:00
|
|
|
eq({ mode = 'i', blocking = false }, api.nvim_get_mode())
|
2021-11-07 14:28:11 -07:00
|
|
|
end)
|
2024-01-16 17:18:52 -07:00
|
|
|
|
2024-01-17 16:23:48 -07:00
|
|
|
-- oldtest: Test_prompt_leave_modify_hidden()
|
2024-01-16 17:18:52 -07:00
|
|
|
it('modifying hidden buffer does not prevent prompt buffer mode change', function()
|
|
|
|
source([[
|
|
|
|
file hidden
|
|
|
|
set bufhidden=hide
|
|
|
|
enew
|
|
|
|
new prompt
|
|
|
|
set buftype=prompt
|
|
|
|
|
2024-01-17 16:23:48 -07:00
|
|
|
inoremap <buffer> w <Cmd>wincmd w<CR>
|
2024-01-16 17:18:52 -07:00
|
|
|
inoremap <buffer> q <Cmd>bwipe!<CR>
|
2024-01-17 16:23:48 -07:00
|
|
|
autocmd BufLeave prompt call appendbufline('hidden', '$', 'Leave')
|
|
|
|
autocmd BufEnter prompt call appendbufline('hidden', '$', 'Enter')
|
|
|
|
autocmd BufWinLeave prompt call appendbufline('hidden', '$', 'Close')
|
2024-01-16 17:18:52 -07:00
|
|
|
]])
|
|
|
|
feed('a')
|
|
|
|
eq({ mode = 'i', blocking = false }, api.nvim_get_mode())
|
2024-01-17 16:23:48 -07:00
|
|
|
feed('w')
|
|
|
|
eq({ mode = 'n', blocking = false }, api.nvim_get_mode())
|
|
|
|
feed('<C-W>w')
|
|
|
|
eq({ mode = 'i', blocking = false }, api.nvim_get_mode())
|
2024-01-16 17:18:52 -07:00
|
|
|
feed('q')
|
|
|
|
eq({ mode = 'n', blocking = false }, api.nvim_get_mode())
|
|
|
|
command('bwipe!')
|
2024-01-17 16:23:48 -07:00
|
|
|
expect([[
|
|
|
|
|
|
|
|
Leave
|
|
|
|
Enter
|
|
|
|
Leave
|
|
|
|
Close]])
|
2024-01-16 17:18:52 -07:00
|
|
|
end)
|
2019-05-19 19:57:45 -07:00
|
|
|
end)
|