diff options
author | Bram Moolenaar <Bram@vim.org> | 2018-06-03 14:47:35 +0200 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2018-06-03 14:47:35 +0200 |
commit | f273245f6433d5d43a5671306b520a3230c35787 (patch) | |
tree | 958293fed4c59ee0cb91a491c8c0e32aa0e618c2 /src/testdir/test_prompt_buffer.vim | |
parent | 33c5e9fa7af935c61a8aac461b9664c501003440 (diff) | |
download | vim-git-f273245f6433d5d43a5671306b520a3230c35787.tar.gz |
patch 8.1.0027: difficult to make a plugin that feeds a line to a jobv8.1.0027
Problem: Difficult to make a plugin that feeds a line to a job.
Solution: Add the nitial code for the "prompt" buftype.
Diffstat (limited to 'src/testdir/test_prompt_buffer.vim')
-rw-r--r-- | src/testdir/test_prompt_buffer.vim | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/src/testdir/test_prompt_buffer.vim b/src/testdir/test_prompt_buffer.vim new file mode 100644 index 000000000..a21acc751 --- /dev/null +++ b/src/testdir/test_prompt_buffer.vim @@ -0,0 +1,55 @@ +" Tests for setting 'buftype' to "prompt" + +if !has('channel') + finish +endif + +source shared.vim +source screendump.vim + +func Test_prompt_basic() + " We need to use a terminal window to be able to feed keys without leaving + " Insert mode. + if !has('terminal') + call assert_report('no terminal') + return + endif + call writefile([ + \ 'func TextEntered(text)', + \ ' if a:text == "exit"', + \ ' 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 . "\"")', + \ 'endfunc', + \ '', + \ 'call setline(1, "other buffer")', + \ 'new', + \ 'set buftype=prompt', + \ 'call prompt_setcallback(bufnr(""), function("TextEntered"))', + \ 'startinsert', + \ ], 'Xpromptscript') + let buf = RunVimInTerminal('-S Xpromptscript', {}) + 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) + call delete('Xpromptscript') +endfunc |