Bram Moolenaar | f273245 | 2018-06-03 14:47:35 +0200 | [diff] [blame] | 1 | " Tests for setting 'buftype' to "prompt" |
| 2 | |
| 3 | if !has('channel') |
| 4 | finish |
| 5 | endif |
| 6 | |
| 7 | source shared.vim |
| 8 | source screendump.vim |
| 9 | |
| 10 | func Test_prompt_basic() |
| 11 | " We need to use a terminal window to be able to feed keys without leaving |
| 12 | " Insert mode. |
| 13 | if !has('terminal') |
Bram Moolenaar | 1149382 | 2018-06-03 15:08:09 +0200 | [diff] [blame^] | 14 | return |
| 15 | endif |
| 16 | if has('win32') |
| 17 | " TODO: make this work on MS-Windows |
Bram Moolenaar | f273245 | 2018-06-03 14:47:35 +0200 | [diff] [blame] | 18 | return |
| 19 | endif |
| 20 | call writefile([ |
| 21 | \ 'func TextEntered(text)', |
| 22 | \ ' if a:text == "exit"', |
| 23 | \ ' stopinsert', |
| 24 | \ ' close', |
| 25 | \ ' else', |
| 26 | \ ' " Add the output above the current prompt.', |
| 27 | \ ' call append(line("$") - 1, "Command: \"" . a:text . "\"")', |
| 28 | \ ' " Reset &modified to allow the buffer to be closed.', |
| 29 | \ ' set nomodified', |
| 30 | \ ' call timer_start(20, {id -> TimerFunc(a:text)})', |
| 31 | \ ' endif', |
| 32 | \ 'endfunc', |
| 33 | \ '', |
| 34 | \ 'func TimerFunc(text)', |
| 35 | \ ' " Add the output above the current prompt.', |
| 36 | \ ' call append(line("$") - 1, "Result: \"" . a:text . "\"")', |
| 37 | \ 'endfunc', |
| 38 | \ '', |
| 39 | \ 'call setline(1, "other buffer")', |
| 40 | \ 'new', |
| 41 | \ 'set buftype=prompt', |
| 42 | \ 'call prompt_setcallback(bufnr(""), function("TextEntered"))', |
| 43 | \ 'startinsert', |
| 44 | \ ], 'Xpromptscript') |
| 45 | let buf = RunVimInTerminal('-S Xpromptscript', {}) |
| 46 | call WaitForAssert({-> assert_equal('%', term_getline(buf, 1))}) |
| 47 | |
| 48 | call term_sendkeys(buf, "hello\<CR>") |
| 49 | call WaitForAssert({-> assert_equal('% hello', term_getline(buf, 1))}) |
| 50 | call WaitForAssert({-> assert_equal('Command: "hello"', term_getline(buf, 2))}) |
| 51 | call WaitForAssert({-> assert_equal('Result: "hello"', term_getline(buf, 3))}) |
| 52 | |
| 53 | call term_sendkeys(buf, "exit\<CR>") |
| 54 | call WaitForAssert({-> assert_equal('other buffer', term_getline(buf, 1))}) |
| 55 | |
| 56 | call StopVimInTerminal(buf) |
| 57 | call delete('Xpromptscript') |
| 58 | endfunc |