2018-06-03 14:47:35 +02:00
|
|
|
" Tests for setting 'buftype' to "prompt"
|
|
|
|
|
|
|
|
if !has('channel')
|
2019-06-13 22:19:53 +02:00
|
|
|
throw 'Skipped, channel feature missing'
|
2018-06-03 14:47:35 +02:00
|
|
|
endif
|
|
|
|
|
|
|
|
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"))',
|
|
|
|
\ '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, {})
|
2018-06-03 14:47:35 +02:00
|
|
|
call WaitForAssert({-> assert_equal('%', term_getline(buf, 1))})
|
|
|
|
|
|
|
|
call term_sendkeys(buf, "hello\<CR>")
|
|
|
|
call WaitForAssert({-> assert_equal('% hello', term_getline(buf, 1))})
|
|
|
|
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, {})
|
|
|
|
call WaitForAssert({-> assert_equal('%', term_getline(buf, 1))})
|
|
|
|
|
|
|
|
let bs = "\<BS>"
|
|
|
|
call term_sendkeys(buf, "hello" . bs . bs)
|
|
|
|
call WaitForAssert({-> assert_equal('% hel', term_getline(buf, 1))})
|
|
|
|
|
|
|
|
let left = "\<Left>"
|
|
|
|
call term_sendkeys(buf, left . left . left . bs . '-')
|
|
|
|
call WaitForAssert({-> assert_equal('% -hel', term_getline(buf, 1))})
|
|
|
|
|
|
|
|
let end = "\<End>"
|
|
|
|
call term_sendkeys(buf, end . "x")
|
|
|
|
call WaitForAssert({-> assert_equal('% -helx', term_getline(buf, 1))})
|
|
|
|
|
|
|
|
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
|