annotate src/testdir/test_prompt_buffer.vim @ 14029:d9fc15c833d5 v8.1.0032

patch 8.1.0032: BS in prompt buffer starts new line commit https://github.com/vim/vim/commit/6b810d92a9cd9378ab46ea0db07079cb789f9faa Author: Bram Moolenaar <Bram@vim.org> Date: Mon Jun 4 17:28:44 2018 +0200 patch 8.1.0032: BS in prompt buffer starts new line Problem: BS in prompt buffer starts new line. Solution: Do not allows BS over the prompt. Make term_sendkeys() handle special keys. Add a test.
author Christian Brabandt <cb@256bit.org>
date Mon, 04 Jun 2018 17:30:08 +0200
parents eb5ee7479d31
children fba38a3491f5
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
14019
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1 " Tests for setting 'buftype' to "prompt"
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3 if !has('channel')
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4 finish
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5 endif
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
7 source shared.vim
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
8 source screendump.vim
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
9
14029
d9fc15c833d5 patch 8.1.0032: BS in prompt buffer starts new line
Christian Brabandt <cb@256bit.org>
parents: 14025
diff changeset
10 func CanTestPromptBuffer()
14019
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
11 " We need to use a terminal window to be able to feed keys without leaving
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
12 " Insert mode.
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
13 if !has('terminal')
14029
d9fc15c833d5 patch 8.1.0032: BS in prompt buffer starts new line
Christian Brabandt <cb@256bit.org>
parents: 14025
diff changeset
14 return 0
14021
945d343d3024 patch 8.1.0028: prompt buffer test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 14019
diff changeset
15 endif
945d343d3024 patch 8.1.0028: prompt buffer test fails on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 14019
diff changeset
16 if has('win32')
14029
d9fc15c833d5 patch 8.1.0032: BS in prompt buffer starts new line
Christian Brabandt <cb@256bit.org>
parents: 14025
diff changeset
17 " TODO: make the tests work on MS-Windows
d9fc15c833d5 patch 8.1.0032: BS in prompt buffer starts new line
Christian Brabandt <cb@256bit.org>
parents: 14025
diff changeset
18 return 0
14019
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
19 endif
14029
d9fc15c833d5 patch 8.1.0032: BS in prompt buffer starts new line
Christian Brabandt <cb@256bit.org>
parents: 14025
diff changeset
20 return 1
d9fc15c833d5 patch 8.1.0032: BS in prompt buffer starts new line
Christian Brabandt <cb@256bit.org>
parents: 14025
diff changeset
21 endfunc
d9fc15c833d5 patch 8.1.0032: BS in prompt buffer starts new line
Christian Brabandt <cb@256bit.org>
parents: 14025
diff changeset
22
d9fc15c833d5 patch 8.1.0032: BS in prompt buffer starts new line
Christian Brabandt <cb@256bit.org>
parents: 14025
diff changeset
23 func WriteScript(name)
14019
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
24 call writefile([
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
25 \ 'func TextEntered(text)',
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
26 \ ' if a:text == "exit"',
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
27 \ ' stopinsert',
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
28 \ ' close',
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
29 \ ' else',
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
30 \ ' " Add the output above the current prompt.',
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
31 \ ' call append(line("$") - 1, "Command: \"" . a:text . "\"")',
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
32 \ ' " Reset &modified to allow the buffer to be closed.',
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
33 \ ' set nomodified',
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
34 \ ' call timer_start(20, {id -> TimerFunc(a:text)})',
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
35 \ ' endif',
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
36 \ 'endfunc',
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
37 \ '',
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
38 \ 'func TimerFunc(text)',
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
39 \ ' " Add the output above the current prompt.',
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
40 \ ' call append(line("$") - 1, "Result: \"" . a:text . "\"")',
14025
eb5ee7479d31 patch 8.1.0030: stoping Vim running in a terminal may not work
Christian Brabandt <cb@256bit.org>
parents: 14021
diff changeset
41 \ ' " Reset &modified to allow the buffer to be closed.',
eb5ee7479d31 patch 8.1.0030: stoping Vim running in a terminal may not work
Christian Brabandt <cb@256bit.org>
parents: 14021
diff changeset
42 \ ' set nomodified',
14019
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
43 \ 'endfunc',
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
44 \ '',
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
45 \ 'call setline(1, "other buffer")',
14025
eb5ee7479d31 patch 8.1.0030: stoping Vim running in a terminal may not work
Christian Brabandt <cb@256bit.org>
parents: 14021
diff changeset
46 \ 'set nomodified',
14019
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
47 \ 'new',
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
48 \ 'set buftype=prompt',
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
49 \ 'call prompt_setcallback(bufnr(""), function("TextEntered"))',
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
50 \ 'startinsert',
14029
d9fc15c833d5 patch 8.1.0032: BS in prompt buffer starts new line
Christian Brabandt <cb@256bit.org>
parents: 14025
diff changeset
51 \ ], a:name)
d9fc15c833d5 patch 8.1.0032: BS in prompt buffer starts new line
Christian Brabandt <cb@256bit.org>
parents: 14025
diff changeset
52 endfunc
d9fc15c833d5 patch 8.1.0032: BS in prompt buffer starts new line
Christian Brabandt <cb@256bit.org>
parents: 14025
diff changeset
53
d9fc15c833d5 patch 8.1.0032: BS in prompt buffer starts new line
Christian Brabandt <cb@256bit.org>
parents: 14025
diff changeset
54 func Test_prompt_basic()
d9fc15c833d5 patch 8.1.0032: BS in prompt buffer starts new line
Christian Brabandt <cb@256bit.org>
parents: 14025
diff changeset
55 if !CanTestPromptBuffer()
d9fc15c833d5 patch 8.1.0032: BS in prompt buffer starts new line
Christian Brabandt <cb@256bit.org>
parents: 14025
diff changeset
56 return
d9fc15c833d5 patch 8.1.0032: BS in prompt buffer starts new line
Christian Brabandt <cb@256bit.org>
parents: 14025
diff changeset
57 endif
d9fc15c833d5 patch 8.1.0032: BS in prompt buffer starts new line
Christian Brabandt <cb@256bit.org>
parents: 14025
diff changeset
58 let scriptName = 'XpromptscriptBasic'
d9fc15c833d5 patch 8.1.0032: BS in prompt buffer starts new line
Christian Brabandt <cb@256bit.org>
parents: 14025
diff changeset
59 call WriteScript(scriptName)
d9fc15c833d5 patch 8.1.0032: BS in prompt buffer starts new line
Christian Brabandt <cb@256bit.org>
parents: 14025
diff changeset
60
d9fc15c833d5 patch 8.1.0032: BS in prompt buffer starts new line
Christian Brabandt <cb@256bit.org>
parents: 14025
diff changeset
61 let buf = RunVimInTerminal('-S ' . scriptName, {})
14019
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
62 call WaitForAssert({-> assert_equal('%', term_getline(buf, 1))})
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
63
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
64 call term_sendkeys(buf, "hello\<CR>")
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
65 call WaitForAssert({-> assert_equal('% hello', term_getline(buf, 1))})
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
66 call WaitForAssert({-> assert_equal('Command: "hello"', term_getline(buf, 2))})
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
67 call WaitForAssert({-> assert_equal('Result: "hello"', term_getline(buf, 3))})
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
68
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
69 call term_sendkeys(buf, "exit\<CR>")
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
70 call WaitForAssert({-> assert_equal('other buffer', term_getline(buf, 1))})
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
71
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
72 call StopVimInTerminal(buf)
14029
d9fc15c833d5 patch 8.1.0032: BS in prompt buffer starts new line
Christian Brabandt <cb@256bit.org>
parents: 14025
diff changeset
73 call delete(scriptName)
14019
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
74 endfunc
14029
d9fc15c833d5 patch 8.1.0032: BS in prompt buffer starts new line
Christian Brabandt <cb@256bit.org>
parents: 14025
diff changeset
75
d9fc15c833d5 patch 8.1.0032: BS in prompt buffer starts new line
Christian Brabandt <cb@256bit.org>
parents: 14025
diff changeset
76 func Test_prompt_editing()
d9fc15c833d5 patch 8.1.0032: BS in prompt buffer starts new line
Christian Brabandt <cb@256bit.org>
parents: 14025
diff changeset
77 if !CanTestPromptBuffer()
d9fc15c833d5 patch 8.1.0032: BS in prompt buffer starts new line
Christian Brabandt <cb@256bit.org>
parents: 14025
diff changeset
78 return
d9fc15c833d5 patch 8.1.0032: BS in prompt buffer starts new line
Christian Brabandt <cb@256bit.org>
parents: 14025
diff changeset
79 endif
d9fc15c833d5 patch 8.1.0032: BS in prompt buffer starts new line
Christian Brabandt <cb@256bit.org>
parents: 14025
diff changeset
80 let scriptName = 'XpromptscriptEditing'
d9fc15c833d5 patch 8.1.0032: BS in prompt buffer starts new line
Christian Brabandt <cb@256bit.org>
parents: 14025
diff changeset
81 call WriteScript(scriptName)
d9fc15c833d5 patch 8.1.0032: BS in prompt buffer starts new line
Christian Brabandt <cb@256bit.org>
parents: 14025
diff changeset
82
d9fc15c833d5 patch 8.1.0032: BS in prompt buffer starts new line
Christian Brabandt <cb@256bit.org>
parents: 14025
diff changeset
83 let buf = RunVimInTerminal('-S ' . scriptName, {})
d9fc15c833d5 patch 8.1.0032: BS in prompt buffer starts new line
Christian Brabandt <cb@256bit.org>
parents: 14025
diff changeset
84 call WaitForAssert({-> assert_equal('%', term_getline(buf, 1))})
d9fc15c833d5 patch 8.1.0032: BS in prompt buffer starts new line
Christian Brabandt <cb@256bit.org>
parents: 14025
diff changeset
85
d9fc15c833d5 patch 8.1.0032: BS in prompt buffer starts new line
Christian Brabandt <cb@256bit.org>
parents: 14025
diff changeset
86 let bs = "\<BS>"
d9fc15c833d5 patch 8.1.0032: BS in prompt buffer starts new line
Christian Brabandt <cb@256bit.org>
parents: 14025
diff changeset
87 call term_sendkeys(buf, "hello" . bs . bs)
d9fc15c833d5 patch 8.1.0032: BS in prompt buffer starts new line
Christian Brabandt <cb@256bit.org>
parents: 14025
diff changeset
88 call WaitForAssert({-> assert_equal('% hel', term_getline(buf, 1))})
d9fc15c833d5 patch 8.1.0032: BS in prompt buffer starts new line
Christian Brabandt <cb@256bit.org>
parents: 14025
diff changeset
89
d9fc15c833d5 patch 8.1.0032: BS in prompt buffer starts new line
Christian Brabandt <cb@256bit.org>
parents: 14025
diff changeset
90 let left = "\<Left>"
d9fc15c833d5 patch 8.1.0032: BS in prompt buffer starts new line
Christian Brabandt <cb@256bit.org>
parents: 14025
diff changeset
91 call term_sendkeys(buf, left . left . left . bs . '-')
d9fc15c833d5 patch 8.1.0032: BS in prompt buffer starts new line
Christian Brabandt <cb@256bit.org>
parents: 14025
diff changeset
92 call WaitForAssert({-> assert_equal('% -hel', term_getline(buf, 1))})
d9fc15c833d5 patch 8.1.0032: BS in prompt buffer starts new line
Christian Brabandt <cb@256bit.org>
parents: 14025
diff changeset
93
d9fc15c833d5 patch 8.1.0032: BS in prompt buffer starts new line
Christian Brabandt <cb@256bit.org>
parents: 14025
diff changeset
94 let end = "\<End>"
d9fc15c833d5 patch 8.1.0032: BS in prompt buffer starts new line
Christian Brabandt <cb@256bit.org>
parents: 14025
diff changeset
95 call term_sendkeys(buf, end . "x")
d9fc15c833d5 patch 8.1.0032: BS in prompt buffer starts new line
Christian Brabandt <cb@256bit.org>
parents: 14025
diff changeset
96 call WaitForAssert({-> assert_equal('% -helx', term_getline(buf, 1))})
d9fc15c833d5 patch 8.1.0032: BS in prompt buffer starts new line
Christian Brabandt <cb@256bit.org>
parents: 14025
diff changeset
97
d9fc15c833d5 patch 8.1.0032: BS in prompt buffer starts new line
Christian Brabandt <cb@256bit.org>
parents: 14025
diff changeset
98 call term_sendkeys(buf, "\<C-U>exit\<CR>")
d9fc15c833d5 patch 8.1.0032: BS in prompt buffer starts new line
Christian Brabandt <cb@256bit.org>
parents: 14025
diff changeset
99 call WaitForAssert({-> assert_equal('other buffer', term_getline(buf, 1))})
d9fc15c833d5 patch 8.1.0032: BS in prompt buffer starts new line
Christian Brabandt <cb@256bit.org>
parents: 14025
diff changeset
100
d9fc15c833d5 patch 8.1.0032: BS in prompt buffer starts new line
Christian Brabandt <cb@256bit.org>
parents: 14025
diff changeset
101 call StopVimInTerminal(buf)
d9fc15c833d5 patch 8.1.0032: BS in prompt buffer starts new line
Christian Brabandt <cb@256bit.org>
parents: 14025
diff changeset
102 call delete(scriptName)
d9fc15c833d5 patch 8.1.0032: BS in prompt buffer starts new line
Christian Brabandt <cb@256bit.org>
parents: 14025
diff changeset
103 endfunc