77source shared.vim
88source screendump.vim
99
10- func Test_prompt_basic ()
10+ func CanTestPromptBuffer ()
1111 " We need to use a terminal window to be able to feed keys without leaving
1212 " Insert mode.
1313 if ! has (' terminal' )
14- return
14+ return 0
1515 endif
1616 if has (' win32' )
17- " TODO: make this work on MS-Windows
18- return
17+ " TODO: make the tests work on MS-Windows
18+ return 0
1919 endif
20+ return 1
21+ endfunc
22+
23+ func WriteScript (name)
2024 call writefile ([
2125 \ ' func TextEntered(text)' ,
2226 \ ' if a:text == "exit"' ,
@@ -44,8 +48,17 @@ func Test_prompt_basic()
4448 \ ' set buftype=prompt' ,
4549 \ ' call prompt_setcallback(bufnr(""), function("TextEntered"))' ,
4650 \ ' startinsert' ,
47- \ ], ' Xpromptscript' )
48- let buf = RunVimInTerminal (' -S Xpromptscript' , {})
51+ \ ], a: name )
52+ endfunc
53+
54+ func Test_prompt_basic ()
55+ if ! CanTestPromptBuffer ()
56+ return
57+ endif
58+ let scriptName = ' XpromptscriptBasic'
59+ call WriteScript (scriptName)
60+
61+ let buf = RunVimInTerminal (' -S ' . scriptName, {})
4962 call WaitForAssert ({- > assert_equal (' %' , term_getline (buf , 1 ))})
5063
5164 call term_sendkeys (buf , " hello\<CR> " )
@@ -57,5 +70,34 @@ func Test_prompt_basic()
5770 call WaitForAssert ({- > assert_equal (' other buffer' , term_getline (buf , 1 ))})
5871
5972 call StopVimInTerminal (buf )
60- call delete (' Xpromptscript' )
73+ call delete (scriptName)
74+ endfunc
75+
76+ func Test_prompt_editing ()
77+ if ! CanTestPromptBuffer ()
78+ return
79+ endif
80+ let scriptName = ' XpromptscriptEditing'
81+ call WriteScript (scriptName)
82+
83+ let buf = RunVimInTerminal (' -S ' . scriptName, {})
84+ call WaitForAssert ({- > assert_equal (' %' , term_getline (buf , 1 ))})
85+
86+ let bs = " \<BS> "
87+ call term_sendkeys (buf , " hello" . bs . bs )
88+ call WaitForAssert ({- > assert_equal (' % hel' , term_getline (buf , 1 ))})
89+
90+ let left = " \<Left> "
91+ call term_sendkeys (buf , left . left . left . bs . ' -' )
92+ call WaitForAssert ({- > assert_equal (' % -hel' , term_getline (buf , 1 ))})
93+
94+ let end = " \<End> "
95+ call term_sendkeys (buf , end . " x" )
96+ call WaitForAssert ({- > assert_equal (' % -helx' , term_getline (buf , 1 ))})
97+
98+ call term_sendkeys (buf , " \<C-U> exit\<CR> " )
99+ call WaitForAssert ({- > assert_equal (' other buffer' , term_getline (buf , 1 ))})
100+
101+ call StopVimInTerminal (buf )
102+ call delete (scriptName)
61103endfunc
0 commit comments