comparison src/testdir/test_selectmode.vim @ 19738:0208534b8a84 v8.2.0425

patch 8.2.0425: code for modeless selection not sufficiently tested Commit: https://github.com/vim/vim/commit/515545e11f523d14343b1e588dc0b9bd3d362bc2 Author: Bram Moolenaar <Bram@vim.org> Date: Sun Mar 22 14:08:59 2020 +0100 patch 8.2.0425: code for modeless selection not sufficiently tested Problem: Code for modeless selection not sufficiently tested. Solution: Add tests. Move mouse code functionality to a common script file. (Yegappan Lakshmanan, closes #5821)
author Bram Moolenaar <Bram@vim.org>
date Sun, 22 Mar 2020 14:15:04 +0100
parents
children 505d97ea54da
comparison
equal deleted inserted replaced
19737:5591829276ff 19738:0208534b8a84
1 " Test for Select-mode
2
3 " This only works for Unix in a terminal
4 source check.vim
5 CheckNotGui
6 CheckUnix
7
8 source mouse.vim
9
10 " Test for select mode
11 func Test_selectmode_basic()
12 new
13 call setline(1, range(1,100))
14 50
15 norm! gHy
16 call assert_equal('y51', getline('.'))
17 call setline(1, range(1,100))
18 50
19 exe ":norm! V9jo\<c-g>y"
20 call assert_equal('y60', getline('.'))
21 call setline(1, range(1,100))
22 50
23 call feedkeys(":set im\n\<c-o>gHc\<c-o>:set noim\n", 'tx')
24 call assert_equal('c51', getline('.'))
25 " clean up
26 bw!
27 endfunc
28
29 " Test for starting selectmode
30 func Test_selectmode_start()
31 new
32 set selectmode=key keymodel=startsel
33 call setline(1, ['abc', 'def', 'ghi'])
34 call cursor(1, 4)
35 call feedkeys("A\<s-home>start\<esc>", 'txin')
36 call assert_equal(['startdef', 'ghi'], getline(1, '$'))
37 " start select mode again with gv
38 set selectmode=cmd
39 call feedkeys('gvabc', 'xt')
40 call assert_equal('abctdef', getline(1))
41 set selectmode= keymodel=
42 bw!
43 endfunc
44
45 " Test for characterwise select mode
46 func Test_characterwise_select_mode()
47 new
48
49 " Select mode maps
50 snoremap <lt>End> <End>
51 snoremap <lt>Down> <Down>
52 snoremap <lt>Del> <Del>
53
54 " characterwise select mode: delete middle line
55 call deletebufline('', 1, '$')
56 call append('$', ['a', 'b', 'c'])
57 exe "normal Gkkgh\<End>\<Del>"
58 call assert_equal(['', 'b', 'c'], getline(1, '$'))
59
60 " characterwise select mode: delete middle two lines
61 call deletebufline('', 1, '$')
62 call append('$', ['a', 'b', 'c'])
63 exe "normal Gkkgh\<Down>\<End>\<Del>"
64 call assert_equal(['', 'c'], getline(1, '$'))
65
66 " characterwise select mode: delete last line
67 call deletebufline('', 1, '$')
68 call append('$', ['a', 'b', 'c'])
69 exe "normal Ggh\<End>\<Del>"
70 call assert_equal(['', 'a', 'b', ''], getline(1, '$'))
71
72 " characterwise select mode: delete last two lines
73 call deletebufline('', 1, '$')
74 call append('$', ['a', 'b', 'c'])
75 exe "normal Gkgh\<Down>\<End>\<Del>"
76 call assert_equal(['', 'a', ''], getline(1, '$'))
77
78 " CTRL-H in select mode behaves like 'x'
79 call setline(1, 'abcdef')
80 exe "normal! gggh\<Right>\<Right>\<Right>\<C-H>"
81 call assert_equal('ef', getline(1))
82
83 " CTRL-O in select mode switches to visual mode for one command
84 call setline(1, 'abcdef')
85 exe "normal! gggh\<C-O>3lm"
86 call assert_equal('mef', getline(1))
87
88 sunmap <lt>End>
89 sunmap <lt>Down>
90 sunmap <lt>Del>
91 bwipe!
92 endfunc
93
94 " Test for linewise select mode
95 func Test_linewise_select_mode()
96 new
97
98 " linewise select mode: delete middle line
99 call append('$', ['a', 'b', 'c'])
100 exe "normal GkkgH\<Del>"
101 call assert_equal(['', 'b', 'c'], getline(1, '$'))
102
103 " linewise select mode: delete middle two lines
104 call deletebufline('', 1, '$')
105 call append('$', ['a', 'b', 'c'])
106 exe "normal GkkgH\<Down>\<Del>"
107 call assert_equal(['', 'c'], getline(1, '$'))
108
109 " linewise select mode: delete last line
110 call deletebufline('', 1, '$')
111 call append('$', ['a', 'b', 'c'])
112 exe "normal GgH\<Del>"
113 call assert_equal(['', 'a', 'b'], getline(1, '$'))
114
115 " linewise select mode: delete last two lines
116 call deletebufline('', 1, '$')
117 call append('$', ['a', 'b', 'c'])
118 exe "normal GkgH\<Down>\<Del>"
119 call assert_equal(['', 'a'], getline(1, '$'))
120
121 bwipe!
122 endfunc
123
124 " Test for blockwise select mode (g CTRL-H)
125 func Test_blockwise_select_mode()
126 new
127 call setline(1, ['foo', 'bar'])
128 call feedkeys("g\<BS>\<Right>\<Down>mm", 'xt')
129 call assert_equal(['mmo', 'mmr'], getline(1, '$'))
130 close!
131 endfunc
132
133 " Test for using visual mode maps in select mode
134 func Test_select_mode_map()
135 new
136 vmap <buffer> <F2> 3l
137 call setline(1, 'Test line')
138 call feedkeys("gh\<F2>map", 'xt')
139 call assert_equal('map line', getline(1))
140
141 vmap <buffer> <F2> ygV
142 call feedkeys("0gh\<Right>\<Right>\<F2>cwabc", 'xt')
143 call assert_equal('abc line', getline(1))
144
145 vmap <buffer> <F2> :<C-U>let v=100<CR>
146 call feedkeys("gggh\<Right>\<Right>\<F2>foo", 'xt')
147 call assert_equal('foo line', getline(1))
148
149 " reselect the select mode using gv from a visual mode map
150 vmap <buffer> <F2> gv
151 set selectmode=cmd
152 call feedkeys("0gh\<F2>map", 'xt')
153 call assert_equal('map line', getline(1))
154 set selectmode&
155
156 close!
157 endfunc
158
159 " Test double/triple/quadruple click to start 'select' mode
160 func Test_term_mouse_multiple_clicks_to_select_mode()
161 let save_mouse = &mouse
162 let save_term = &term
163 let save_ttymouse = &ttymouse
164 call test_override('no_query_mouse', 1)
165 set mouse=a term=xterm mousetime=200
166 set selectmode=mouse
167 new
168
169 for ttymouse_val in g:Ttymouse_values + g:Ttymouse_dec
170 let msg = 'ttymouse=' .. ttymouse_val
171 exe 'set ttymouse=' .. ttymouse_val
172
173 " Single-click and drag should 'select' the characters
174 call setline(1, ['foo [foo bar] foo', 'foo'])
175 call MouseLeftClick(1, 3)
176 call assert_equal(0, getcharmod(), msg)
177 call MouseLeftDrag(1, 13)
178 call MouseLeftRelease(1, 13)
179 norm! o
180 call assert_equal(['foo foo', 'foo'], getline(1, '$'), msg)
181
182 " Double-click on word should visually 'select' the word.
183 call setline(1, ['foo [foo bar] foo', 'foo'])
184 call MouseLeftClick(1, 2)
185 call assert_equal(0, getcharmod(), msg)
186 call MouseLeftRelease(1, 2)
187 call MouseLeftClick(1, 2)
188 call assert_equal(32, getcharmod(), msg) " double-click
189 call MouseLeftRelease(1, 2)
190 call assert_equal('s', mode(), msg)
191 norm! bar
192 call assert_equal(['bar [foo bar] foo', 'foo'], getline(1, '$'), msg)
193
194 " Double-click on opening square bracket should visually
195 " 'select' the whole [foo bar].
196 call setline(1, ['foo [foo bar] foo', 'foo'])
197 call MouseLeftClick(1, 5)
198 call assert_equal(0, getcharmod(), msg)
199 call MouseLeftRelease(1, 5)
200 call MouseLeftClick(1, 5)
201 call assert_equal(32, getcharmod(), msg) " double-click
202 call MouseLeftRelease(1, 5)
203 call assert_equal('s', mode(), msg)
204 norm! bar
205 call assert_equal(['foo bar foo', 'foo'], getline(1, '$'), msg)
206
207 " To guarantee that the next click is not counted as a triple click
208 call MouseRightClick(1, 1)
209 call MouseRightRelease(1, 1)
210
211 " Triple-click should visually 'select' the whole line.
212 call setline(1, ['foo [foo bar] foo', 'foo'])
213 call MouseLeftClick(1, 3)
214 call assert_equal(0, getcharmod(), msg)
215 call MouseLeftRelease(1, 3)
216 call MouseLeftClick(1, 3)
217 call assert_equal(32, getcharmod(), msg) " double-click
218 call MouseLeftRelease(1, 3)
219 call MouseLeftClick(1, 3)
220 call assert_equal(64, getcharmod(), msg) " triple-click
221 call MouseLeftRelease(1, 3)
222 call assert_equal('S', mode(), msg)
223 norm! baz
224 call assert_equal(['bazfoo'], getline(1, '$'), msg)
225
226 " Quadruple-click should start visual block 'select'.
227 call setline(1, ['aaaaaa', 'bbbbbb'])
228 call MouseLeftClick(1, 2)
229 call assert_equal(0, getcharmod(), msg)
230 call MouseLeftRelease(1, 2)
231 call MouseLeftClick(1, 2)
232 call assert_equal(32, getcharmod(), msg) " double-click
233 call MouseLeftRelease(1, 2)
234 call MouseLeftClick(1, 2)
235 call assert_equal(64, getcharmod(), msg) " triple-click
236 call MouseLeftRelease(1, 2)
237 call MouseLeftClick(1, 2)
238 call assert_equal(96, getcharmod(), msg) " quadruple-click
239 call MouseLeftDrag(2, 4)
240 call MouseLeftRelease(2, 4)
241 call assert_equal("\<c-s>", mode(), msg)
242 norm! x
243 call assert_equal(['axaa', 'bxbb'], getline(1, '$'), msg)
244 endfor
245
246 let &mouse = save_mouse
247 let &term = save_term
248 let &ttymouse = save_ttymouse
249 set mousetime&
250 set selectmode&
251 call test_override('no_query_mouse', 0)
252 bwipe!
253 endfunc
254
255 " vim: shiftwidth=2 sts=2 expandtab