2018-06-03 14:47:35 +02:00
|
|
|
" Tests for setting 'buftype' to "prompt"
|
|
|
|
|
2019-06-15 17:58:09 +02:00
|
|
|
source check.vim
|
|
|
|
CheckFeature channel
|
2018-06-03 14:47:35 +02:00
|
|
|
|
|
|
|
source shared.vim
|
|
|
|
source screendump.vim
|
|
|
|
|
2018-06-04 17:28:44 +02:00
|
|
|
func CanTestPromptBuffer()
|
2018-06-03 14:47:35 +02:00
|
|
|
" We need to use a terminal window to be able to feed keys without leaving
|
|
|
|
" Insert mode.
|
|
|
|
if !has('terminal')
|
2018-06-04 17:28:44 +02:00
|
|
|
return 0
|
2018-06-03 15:08:09 +02:00
|
|
|
endif
|
|
|
|
if has('win32')
|
2018-06-04 17:28:44 +02:00
|
|
|
" TODO: make the tests work on MS-Windows
|
|
|
|
return 0
|
2018-06-03 14:47:35 +02:00
|
|
|
endif
|
2018-06-04 17:28:44 +02:00
|
|
|
return 1
|
|
|
|
endfunc
|
|
|
|
|
|
|
|
func WriteScript(name)
|
2018-06-03 14:47:35 +02:00
|
|
|
call writefile([
|
|
|
|
\ 'func TextEntered(text)',
|
|
|
|
\ ' if a:text == "exit"',
|
2018-06-21 12:07:04 +02:00
|
|
|
\ ' " Reset &modified to allow the buffer to be closed.',
|
|
|
|
\ ' set nomodified',
|
2018-06-03 14:47:35 +02:00
|
|
|
\ ' stopinsert',
|
|
|
|
\ ' close',
|
|
|
|
\ ' else',
|
|
|
|
\ ' " Add the output above the current prompt.',
|
|
|
|
\ ' call append(line("$") - 1, "Command: \"" . a:text . "\"")',
|
|
|
|
\ ' " Reset &modified to allow the buffer to be closed.',
|
|
|
|
\ ' set nomodified',
|
|
|
|
\ ' call timer_start(20, {id -> TimerFunc(a:text)})',
|
|
|
|
\ ' endif',
|
|
|
|
\ 'endfunc',
|
|
|
|
\ '',
|
|
|
|
\ 'func TimerFunc(text)',
|
|
|
|
\ ' " Add the output above the current prompt.',
|
|
|
|
\ ' call append(line("$") - 1, "Result: \"" . a:text . "\"")',
|
2018-06-03 17:10:40 +02:00
|
|
|
\ ' " Reset &modified to allow the buffer to be closed.',
|
|
|
|
\ ' set nomodified',
|
2018-06-03 14:47:35 +02:00
|
|
|
\ 'endfunc',
|
|
|
|
\ '',
|
|
|
|
\ 'call setline(1, "other buffer")',
|
2018-06-03 17:10:40 +02:00
|
|
|
\ 'set nomodified',
|
2018-06-03 14:47:35 +02:00
|
|
|
\ 'new',
|
|
|
|
\ 'set buftype=prompt',
|
|
|
|
\ 'call prompt_setcallback(bufnr(""), function("TextEntered"))',
|
2019-09-04 20:05:59 +02:00
|
|
|
\ 'eval bufnr("")->prompt_setprompt("cmd: ")',
|
2018-06-03 14:47:35 +02:00
|
|
|
\ 'startinsert',
|
2018-06-04 17:28:44 +02:00
|
|
|
\ ], a:name)
|
|
|
|
endfunc
|
|
|
|
|
|
|
|
func Test_prompt_basic()
|
|
|
|
if !CanTestPromptBuffer()
|
|
|
|
return
|
|
|
|
endif
|
|
|
|
let scriptName = 'XpromptscriptBasic'
|
|
|
|
call WriteScript(scriptName)
|
|
|
|
|
|
|
|
let buf = RunVimInTerminal('-S ' . scriptName, {})
|
2019-09-04 20:05:59 +02:00
|
|
|
call WaitForAssert({-> assert_equal('cmd:', term_getline(buf, 1))})
|
2018-06-03 14:47:35 +02:00
|
|
|
|
|
|
|
call term_sendkeys(buf, "hello\<CR>")
|
2019-09-04 20:05:59 +02:00
|
|
|
call WaitForAssert({-> assert_equal('cmd: hello', term_getline(buf, 1))})
|
2018-06-03 14:47:35 +02:00
|
|
|
call WaitForAssert({-> assert_equal('Command: "hello"', term_getline(buf, 2))})
|
|
|
|
call WaitForAssert({-> assert_equal('Result: "hello"', term_getline(buf, 3))})
|
|
|
|
|
|
|
|
call term_sendkeys(buf, "exit\<CR>")
|
|
|
|
call WaitForAssert({-> assert_equal('other buffer', term_getline(buf, 1))})
|
|
|
|
|
|
|
|
call StopVimInTerminal(buf)
|
2018-06-04 17:28:44 +02:00
|
|
|
call delete(scriptName)
|
|
|
|
endfunc
|
|
|
|
|
|
|
|
func Test_prompt_editing()
|
|
|
|
if !CanTestPromptBuffer()
|
|
|
|
return
|
|
|
|
endif
|
|
|
|
let scriptName = 'XpromptscriptEditing'
|
|
|
|
call WriteScript(scriptName)
|
|
|
|
|
|
|
|
let buf = RunVimInTerminal('-S ' . scriptName, {})
|
2019-09-04 20:05:59 +02:00
|
|
|
call WaitForAssert({-> assert_equal('cmd:', term_getline(buf, 1))})
|
2018-06-04 17:28:44 +02:00
|
|
|
|
|
|
|
let bs = "\<BS>"
|
|
|
|
call term_sendkeys(buf, "hello" . bs . bs)
|
2019-09-04 20:05:59 +02:00
|
|
|
call WaitForAssert({-> assert_equal('cmd: hel', term_getline(buf, 1))})
|
2018-06-04 17:28:44 +02:00
|
|
|
|
|
|
|
let left = "\<Left>"
|
|
|
|
call term_sendkeys(buf, left . left . left . bs . '-')
|
2019-09-04 20:05:59 +02:00
|
|
|
call WaitForAssert({-> assert_equal('cmd: -hel', term_getline(buf, 1))})
|
2018-06-04 17:28:44 +02:00
|
|
|
|
|
|
|
let end = "\<End>"
|
|
|
|
call term_sendkeys(buf, end . "x")
|
2019-09-04 20:05:59 +02:00
|
|
|
call WaitForAssert({-> assert_equal('cmd: -helx', term_getline(buf, 1))})
|
2018-06-04 17:28:44 +02:00
|
|
|
|
|
|
|
call term_sendkeys(buf, "\<C-U>exit\<CR>")
|
|
|
|
call WaitForAssert({-> assert_equal('other buffer', term_getline(buf, 1))})
|
|
|
|
|
|
|
|
call StopVimInTerminal(buf)
|
|
|
|
call delete(scriptName)
|
2018-06-03 14:47:35 +02:00
|
|
|
endfunc
|
2019-06-20 03:45:36 +02:00
|
|
|
|
|
|
|
func Test_prompt_garbage_collect()
|
|
|
|
func MyPromptCallback(x, text)
|
|
|
|
" NOP
|
|
|
|
endfunc
|
|
|
|
func MyPromptInterrupt(x)
|
|
|
|
" NOP
|
|
|
|
endfunc
|
|
|
|
|
|
|
|
new
|
|
|
|
set buftype=prompt
|
2019-09-04 20:05:59 +02:00
|
|
|
eval bufnr('')->prompt_setcallback(function('MyPromptCallback', [{}]))
|
|
|
|
eval bufnr('')->prompt_setinterrupt(function('MyPromptInterrupt', [{}]))
|
2019-06-20 03:45:36 +02:00
|
|
|
call test_garbagecollect_now()
|
|
|
|
" Must not crash
|
|
|
|
call feedkeys("\<CR>\<C-C>", 'xt')
|
|
|
|
call assert_true(v:true)
|
|
|
|
|
2020-03-30 19:32:53 +02:00
|
|
|
call assert_fails("call prompt_setcallback(bufnr(), [])", 'E921:')
|
|
|
|
call assert_equal(0, prompt_setcallback({}, ''))
|
|
|
|
call assert_fails("call prompt_setinterrupt(bufnr(), [])", 'E921:')
|
|
|
|
call assert_equal(0, prompt_setinterrupt({}, ''))
|
|
|
|
|
2019-06-20 03:45:36 +02:00
|
|
|
delfunc MyPromptCallback
|
|
|
|
bwipe!
|
|
|
|
endfunc
|
2020-03-08 05:13:15 +01:00
|
|
|
|
|
|
|
" Test for editing the prompt buffer
|
|
|
|
func Test_prompt_buffer_edit()
|
|
|
|
new
|
|
|
|
set buftype=prompt
|
|
|
|
normal! i
|
|
|
|
call assert_beeps('normal! dd')
|
|
|
|
call assert_beeps('normal! ~')
|
2020-03-10 07:48:13 +01:00
|
|
|
call assert_beeps('normal! o')
|
|
|
|
call assert_beeps('normal! O')
|
|
|
|
call assert_beeps('normal! p')
|
|
|
|
call assert_beeps('normal! P')
|
|
|
|
call assert_beeps('normal! u')
|
|
|
|
call assert_beeps('normal! ra')
|
|
|
|
call assert_beeps('normal! s')
|
|
|
|
call assert_beeps('normal! S')
|
|
|
|
call assert_beeps("normal! \<C-A>")
|
|
|
|
call assert_beeps("normal! \<C-X>")
|
2020-03-08 05:13:15 +01:00
|
|
|
close!
|
2020-04-21 22:19:45 +02:00
|
|
|
call assert_equal(0, prompt_setprompt([], ''))
|
2020-03-08 05:13:15 +01:00
|
|
|
endfunc
|
|
|
|
|
|
|
|
" vim: shiftwidth=2 sts=2 expandtab
|