blob: f7363d9ad5ac3e5f10ae9dcea6e4a25ff2000345 [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 . "\"")',
Bram Moolenaar3339d3d2018-06-03 17:10:40 +020037 \ ' " Reset &modified to allow the buffer to be closed.',
38 \ ' set nomodified',
Bram Moolenaarf2732452018-06-03 14:47:35 +020039 \ 'endfunc',
40 \ '',
41 \ 'call setline(1, "other buffer")',
Bram Moolenaar3339d3d2018-06-03 17:10:40 +020042 \ 'set nomodified',
Bram Moolenaarf2732452018-06-03 14:47:35 +020043 \ 'new',
44 \ 'set buftype=prompt',
45 \ 'call prompt_setcallback(bufnr(""), function("TextEntered"))',
46 \ 'startinsert',
47 \ ], 'Xpromptscript')
48 let buf = RunVimInTerminal('-S Xpromptscript', {})
49 call WaitForAssert({-> assert_equal('%', term_getline(buf, 1))})
50
51 call term_sendkeys(buf, "hello\<CR>")
52 call WaitForAssert({-> assert_equal('% hello', term_getline(buf, 1))})
53 call WaitForAssert({-> assert_equal('Command: "hello"', term_getline(buf, 2))})
54 call WaitForAssert({-> assert_equal('Result: "hello"', term_getline(buf, 3))})
55
56 call term_sendkeys(buf, "exit\<CR>")
57 call WaitForAssert({-> assert_equal('other buffer', term_getline(buf, 1))})
58
59 call StopVimInTerminal(buf)
60 call delete('Xpromptscript')
61endfunc