blob: 3a0469da6389a87011e1ce25f8e0be3bec4215e7 [file] [log] [blame]
Bram Moolenaarf2732452018-06-03 14:47:35 +02001" Tests for setting 'buftype' to "prompt"
2
3if !has('channel')
4 finish
5endif
6
7source shared.vim
8source screendump.vim
9
10func 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 Moolenaar11493822018-06-03 15:08:09 +020014 return
15 endif
16 if has('win32')
17 " TODO: make this work on MS-Windows
Bram Moolenaarf2732452018-06-03 14:47:35 +020018 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')
58endfunc