1" 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')
14    call assert_report('no terminal')
15    return
16  endif
17  call writefile([
18	\ 'func TextEntered(text)',
19	\ '  if a:text == "exit"',
20	\ '    stopinsert',
21	\ '    close',
22	\ '  else',
23	\ '    " Add the output above the current prompt.',
24	\ '    call append(line("$") - 1, "Command: \"" . a:text . "\"")',
25	\ '    " Reset &modified to allow the buffer to be closed.',
26	\ '    set nomodified',
27	\ '    call timer_start(20, {id -> TimerFunc(a:text)})',
28	\ '  endif',
29	\ 'endfunc',
30	\ '',
31	\ 'func TimerFunc(text)',
32	\ '  " Add the output above the current prompt.',
33	\ '  call append(line("$") - 1, "Result: \"" . a:text . "\"")',
34	\ 'endfunc',
35	\ '',
36	\ 'call setline(1, "other buffer")',
37	\ 'new',
38	\ 'set buftype=prompt',
39	\ 'call prompt_setcallback(bufnr(""), function("TextEntered"))',
40	\ 'startinsert',
41	\ ], 'Xpromptscript')
42  let buf = RunVimInTerminal('-S Xpromptscript', {})
43  call WaitForAssert({-> assert_equal('%', term_getline(buf, 1))})
44
45  call term_sendkeys(buf, "hello\<CR>")
46  call WaitForAssert({-> assert_equal('% hello', term_getline(buf, 1))})
47  call WaitForAssert({-> assert_equal('Command: "hello"', term_getline(buf, 2))})
48  call WaitForAssert({-> assert_equal('Result: "hello"', term_getline(buf, 3))})
49
50  call term_sendkeys(buf, "exit\<CR>")
51  call WaitForAssert({-> assert_equal('other buffer', term_getline(buf, 1))})
52
53  call StopVimInTerminal(buf)
54  call delete('Xpromptscript')
55endfunc
56