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    return
15  endif
16  if has('win32')
17    " TODO: make this work on MS-Windows
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	\ '  " Reset &modified to allow the buffer to be closed.',
38	\ '  set nomodified',
39	\ 'endfunc',
40	\ '',
41	\ 'call setline(1, "other buffer")',
42	\ 'set nomodified',
43	\ '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
62