blob: bae5d8d0a2358758423f3d0c425c57a52285db12 [file] [log] [blame]
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001" Test for various Normal mode commands
2
Bram Moolenaara84a3dd2019-03-25 22:21:24 +01003source shared.vim
Bram Moolenaar5a4c3082019-12-01 15:23:11 +01004source check.vim
Bram Moolenaarca68ae12020-03-30 19:32:53 +02005source view_util.vim
Bram Moolenaara84a3dd2019-03-25 22:21:24 +01006
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01007func Setup_NewWindow()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02008 10new
9 call setline(1, range(1,100))
10endfunc
11
Bram Moolenaar1bbb6192018-11-10 16:02:01 +010012func MyFormatExpr()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +020013 " Adds '->$' at lines having numbers followed by trailing whitespace
14 for ln in range(v:lnum, v:lnum+v:count-1)
15 let line = getline(ln)
16 if getline(ln) =~# '\d\s\+$'
17 call setline(ln, substitute(line, '\s\+$', '', '') . '->$')
18 endif
19 endfor
Bram Moolenaar2931f2a2016-09-09 16:59:08 +020020endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +020021
Bram Moolenaar1bbb6192018-11-10 16:02:01 +010022func CountSpaces(type, ...)
Bram Moolenaar87bc3f72016-09-03 17:33:54 +020023 " for testing operatorfunc
24 " will count the number of spaces
25 " and return the result in g:a
26 let sel_save = &selection
27 let &selection = "inclusive"
28 let reg_save = @@
29
30 if a:0 " Invoked from Visual mode, use gv command.
31 silent exe "normal! gvy"
32 elseif a:type == 'line'
33 silent exe "normal! '[V']y"
34 else
35 silent exe "normal! `[v`]y"
36 endif
37 let g:a=strlen(substitute(@@, '[^ ]', '', 'g'))
38 let &selection = sel_save
39 let @@ = reg_save
Bram Moolenaar2931f2a2016-09-09 16:59:08 +020040endfunc
41
Bram Moolenaar1bbb6192018-11-10 16:02:01 +010042func OpfuncDummy(type, ...)
Bram Moolenaar4a08b0d2016-11-05 21:55:13 +010043 " for testing operatorfunc
44 let g:opt=&linebreak
45
46 if a:0 " Invoked from Visual mode, use gv command.
47 silent exe "normal! gvy"
48 elseif a:type == 'line'
49 silent exe "normal! '[V']y"
50 else
51 silent exe "normal! `[v`]y"
52 endif
53 " Create a new dummy window
54 new
55 let g:bufnr=bufnr('%')
Bram Moolenaar2931f2a2016-09-09 16:59:08 +020056endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +020057
Bram Moolenaar1671f442020-03-10 07:48:13 +010058func Test_normal00_optrans()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +020059 new
60 call append(0, ['1 This is a simple test: abcd', '2 This is the second line', '3 this is the third line'])
61 1
62 exe "norm! Sfoobar\<esc>"
63 call assert_equal(['foobar', '2 This is the second line', '3 this is the third line', ''], getline(1,'$'))
64 2
Bram Moolenaar87bc3f72016-09-03 17:33:54 +020065 exe "norm! $vbsone"
66 call assert_equal(['foobar', '2 This is the second one', '3 this is the third line', ''], getline(1,'$'))
Bram Moolenaar87bc3f72016-09-03 17:33:54 +020067 norm! VS Second line here
68 call assert_equal(['foobar', ' Second line here', '3 this is the third line', ''], getline(1, '$'))
69 %d
70 call append(0, ['4 This is a simple test: abcd', '5 This is the second line', '6 this is the third line'])
71 call append(0, ['1 This is a simple test: abcd', '2 This is the second line', '3 this is the third line'])
72
73 1
74 norm! 2D
75 call assert_equal(['3 this is the third line', '4 This is a simple test: abcd', '5 This is the second line', '6 this is the third line', ''], getline(1,'$'))
76 set cpo+=#
77 norm! 4D
78 call assert_equal(['', '4 This is a simple test: abcd', '5 This is the second line', '6 this is the third line', ''], getline(1,'$'))
79
80 " clean up
81 set cpo-=#
82 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +020083endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +020084
Bram Moolenaar1bbb6192018-11-10 16:02:01 +010085func Test_normal01_keymodel()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +020086 call Setup_NewWindow()
87 " Test 1: depending on 'keymodel' <s-down> does something different
Bram Moolenaar2931f2a2016-09-09 16:59:08 +020088 50
Bram Moolenaar87bc3f72016-09-03 17:33:54 +020089 call feedkeys("V\<S-Up>y", 'tx')
90 call assert_equal(['47', '48', '49', '50'], getline("'<", "'>"))
Bram Moolenaar2931f2a2016-09-09 16:59:08 +020091 set keymodel=startsel
92 50
Bram Moolenaar87bc3f72016-09-03 17:33:54 +020093 call feedkeys("V\<S-Up>y", 'tx')
94 call assert_equal(['49', '50'], getline("'<", "'>"))
95 " Start visual mode when keymodel = startsel
Bram Moolenaar2931f2a2016-09-09 16:59:08 +020096 50
Bram Moolenaar87bc3f72016-09-03 17:33:54 +020097 call feedkeys("\<S-Up>y", 'tx')
98 call assert_equal(['49', '5'], getreg(0, 0, 1))
Bram Moolenaar1671f442020-03-10 07:48:13 +010099 " Use the different Shift special keys
100 50
101 call feedkeys("\<S-Right>\<S-Left>\<S-Up>\<S-Down>\<S-Home>\<S-End>y", 'tx')
102 call assert_equal(['50'], getline("'<", "'>"))
103 call assert_equal(['50', ''], getreg(0, 0, 1))
104
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200105 " Do not start visual mode when keymodel=
Bram Moolenaar2931f2a2016-09-09 16:59:08 +0200106 set keymodel=
107 50
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200108 call feedkeys("\<S-Up>y$", 'tx')
109 call assert_equal(['42'], getreg(0, 0, 1))
Bram Moolenaar2931f2a2016-09-09 16:59:08 +0200110 " Stop visual mode when keymodel=stopsel
111 set keymodel=stopsel
112 50
113 call feedkeys("Vkk\<Up>yy", 'tx')
114 call assert_equal(['47'], getreg(0, 0, 1))
115
116 set keymodel=
117 50
118 call feedkeys("Vkk\<Up>yy", 'tx')
119 call assert_equal(['47', '48', '49', '50'], getreg(0, 0, 1))
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200120
121 " clean up
122 bw!
123endfunc
124
Bram Moolenaar1bbb6192018-11-10 16:02:01 +0100125func Test_normal03_join()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200126 " basic join test
127 call Setup_NewWindow()
128 50
129 norm! VJ
130 call assert_equal('50 51', getline('.'))
131 $
132 norm! J
133 call assert_equal('100', getline('.'))
134 $
135 norm! V9-gJ
136 call assert_equal('919293949596979899100', getline('.'))
137 call setline(1, range(1,100))
138 $
139 :j 10
140 call assert_equal('100', getline('.'))
Bram Moolenaar004a6782020-04-11 17:09:31 +0200141 call assert_beeps('normal GVJ')
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200142 " clean up
143 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +0200144endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200145
Bram Moolenaar004a6782020-04-11 17:09:31 +0200146" basic filter test
Bram Moolenaar1bbb6192018-11-10 16:02:01 +0100147func Test_normal04_filter()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200148 " only test on non windows platform
Bram Moolenaar004a6782020-04-11 17:09:31 +0200149 CheckNotMSWindows
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200150 call Setup_NewWindow()
151 1
152 call feedkeys("!!sed -e 's/^/| /'\n", 'tx')
153 call assert_equal('| 1', getline('.'))
154 90
155 :sil :!echo one
156 call feedkeys('.', 'tx')
157 call assert_equal('| 90', getline('.'))
158 95
159 set cpo+=!
160 " 2 <CR>, 1: for executing the command,
161 " 2: clear hit-enter-prompt
162 call feedkeys("!!\n", 'tx')
163 call feedkeys(":!echo one\n\n", 'tx')
164 call feedkeys(".", 'tx')
165 call assert_equal('one', getline('.'))
166 set cpo-=!
167 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +0200168endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200169
Bram Moolenaar1bbb6192018-11-10 16:02:01 +0100170func Test_normal05_formatexpr()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200171 " basic formatexpr test
172 call Setup_NewWindow()
173 %d_
174 call setline(1, ['here: 1 ', '2', 'here: 3 ', '4', 'not here: '])
175 1
176 set formatexpr=MyFormatExpr()
177 norm! gqG
178 call assert_equal(['here: 1->$', '2', 'here: 3->$', '4', 'not here: '], getline(1,'$'))
179 set formatexpr=
180 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +0200181endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200182
Bram Moolenaard77f9d52016-09-04 15:13:39 +0200183func Test_normal05_formatexpr_newbuf()
184 " Edit another buffer in the 'formatexpr' function
185 new
186 func! Format()
187 edit another
188 endfunc
189 set formatexpr=Format()
190 norm gqG
191 bw!
192 set formatexpr=
193endfunc
194
195func Test_normal05_formatexpr_setopt()
196 " Change the 'formatexpr' value in the function
197 new
198 func! Format()
199 set formatexpr=
200 endfunc
201 set formatexpr=Format()
202 norm gqG
203 bw!
204 set formatexpr=
205endfunc
206
Bram Moolenaar2eaeaf32020-05-03 16:04:43 +0200207" When 'formatexpr' returns non-zero, internal formatting is used.
208func Test_normal_formatexpr_returns_nonzero()
209 new
210 call setline(1, ['one', 'two'])
211 func! Format()
212 return 1
213 endfunc
214 setlocal formatexpr=Format()
215 normal VGgq
216 call assert_equal(['one two'], getline(1, '$'))
217 setlocal formatexpr=
218 delfunc Format
219 close!
220endfunc
221
Bram Moolenaar004a6782020-04-11 17:09:31 +0200222" basic test for formatprg
Bram Moolenaar1bbb6192018-11-10 16:02:01 +0100223func Test_normal06_formatprg()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200224 " only test on non windows platform
Bram Moolenaar004a6782020-04-11 17:09:31 +0200225 CheckNotMSWindows
Bram Moolenaar9be7c042017-01-14 14:28:30 +0100226
227 " uses sed to number non-empty lines
228 call writefile(['#!/bin/sh', 'sed ''/./=''|sed ''/./{', 'N', 's/\n/ /', '}'''], 'Xsed_format.sh')
229 call system('chmod +x ./Xsed_format.sh')
230 let text = ['a', '', 'c', '', ' ', 'd', 'e']
231 let expected = ['1 a', '', '3 c', '', '5 ', '6 d', '7 e']
232
233 10new
234 call setline(1, text)
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200235 set formatprg=./Xsed_format.sh
236 norm! gggqG
Bram Moolenaar9be7c042017-01-14 14:28:30 +0100237 call assert_equal(expected, getline(1, '$'))
Bram Moolenaar004a6782020-04-11 17:09:31 +0200238 %d
Bram Moolenaar9be7c042017-01-14 14:28:30 +0100239
Bram Moolenaar9be7c042017-01-14 14:28:30 +0100240 call setline(1, text)
241 set formatprg=donothing
242 setlocal formatprg=./Xsed_format.sh
243 norm! gggqG
244 call assert_equal(expected, getline(1, '$'))
Bram Moolenaar004a6782020-04-11 17:09:31 +0200245 %d
Bram Moolenaar9be7c042017-01-14 14:28:30 +0100246
Bram Moolenaar004a6782020-04-11 17:09:31 +0200247 " Check for the command-line ranges added to 'formatprg'
248 set formatprg=cat
249 call setline(1, ['one', 'two', 'three', 'four', 'five'])
250 call feedkeys('gggqG', 'xt')
251 call assert_equal('.,$!cat', @:)
252 call feedkeys('2Ggq2j', 'xt')
253 call assert_equal('.,.+2!cat', @:)
254
255 bw!
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200256 " clean up
257 set formatprg=
Bram Moolenaar9be7c042017-01-14 14:28:30 +0100258 setlocal formatprg=
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200259 call delete('Xsed_format.sh')
Bram Moolenaar2931f2a2016-09-09 16:59:08 +0200260endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200261
Bram Moolenaar1bbb6192018-11-10 16:02:01 +0100262func Test_normal07_internalfmt()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200263 " basic test for internal formmatter to textwidth of 12
264 let list=range(1,11)
265 call map(list, 'v:val." "')
266 10new
267 call setline(1, list)
268 set tw=12
Bram Moolenaar004a6782020-04-11 17:09:31 +0200269 norm! ggVGgq
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200270 call assert_equal(['1 2 3', '4 5 6', '7 8 9', '10 11 '], getline(1, '$'))
271 " clean up
Bram Moolenaar9be7c042017-01-14 14:28:30 +0100272 set tw=0
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200273 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +0200274endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200275
Bram Moolenaar004a6782020-04-11 17:09:31 +0200276" basic tests for foldopen/folddelete
Bram Moolenaar1bbb6192018-11-10 16:02:01 +0100277func Test_normal08_fold()
Bram Moolenaar004a6782020-04-11 17:09:31 +0200278 CheckFeature folding
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200279 call Setup_NewWindow()
280 50
281 setl foldenable fdm=marker
282 " First fold
283 norm! V4jzf
284 " check that folds have been created
285 call assert_equal(['50/*{{{*/', '51', '52', '53', '54/*}}}*/'], getline(50,54))
286 " Second fold
287 46
288 norm! V10jzf
289 " check that folds have been created
290 call assert_equal('46/*{{{*/', getline(46))
291 call assert_equal('60/*}}}*/', getline(60))
292 norm! k
293 call assert_equal('45', getline('.'))
294 norm! j
295 call assert_equal('46/*{{{*/', getline('.'))
296 norm! j
297 call assert_equal('61', getline('.'))
298 norm! k
299 " open a fold
300 norm! Vzo
301 norm! k
302 call assert_equal('45', getline('.'))
303 norm! j
304 call assert_equal('46/*{{{*/', getline('.'))
305 norm! j
306 call assert_equal('47', getline('.'))
307 norm! k
308 norm! zcVzO
309 call assert_equal('46/*{{{*/', getline('.'))
310 norm! j
311 call assert_equal('47', getline('.'))
312 norm! j
313 call assert_equal('48', getline('.'))
314 norm! j
315 call assert_equal('49', getline('.'))
316 norm! j
317 call assert_equal('50/*{{{*/', getline('.'))
318 norm! j
319 call assert_equal('51', getline('.'))
320 " delete folds
321 :46
322 " collapse fold
323 norm! V14jzC
324 " delete all folds recursively
325 norm! VzD
326 call assert_equal(['46', '47', '48', '49', '50', '51', '52', '53', '54', '55', '56', '57', '58', '59', '60'], getline(46,60))
327
328 " clean up
329 setl nofoldenable fdm=marker
330 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +0200331endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200332
Bram Moolenaar1bbb6192018-11-10 16:02:01 +0100333func Test_normal09_operatorfunc()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200334 " Test operatorfunc
335 call Setup_NewWindow()
336 " Add some spaces for counting
337 50,60s/$/ /
338 unlet! g:a
339 let g:a=0
340 nmap <buffer><silent> ,, :set opfunc=CountSpaces<CR>g@
341 vmap <buffer><silent> ,, :<C-U>call CountSpaces(visualmode(), 1)<CR>
342 50
343 norm V2j,,
344 call assert_equal(6, g:a)
345 norm V,,
346 call assert_equal(2, g:a)
347 norm ,,l
348 call assert_equal(0, g:a)
349 50
350 exe "norm 0\<c-v>10j2l,,"
351 call assert_equal(11, g:a)
352 50
353 norm V10j,,
354 call assert_equal(22, g:a)
355
356 " clean up
357 unmap <buffer> ,,
358 set opfunc=
Bram Moolenaar4a08b0d2016-11-05 21:55:13 +0100359 unlet! g:a
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200360 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +0200361endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200362
Bram Moolenaar1bbb6192018-11-10 16:02:01 +0100363func Test_normal09a_operatorfunc()
Bram Moolenaar4a08b0d2016-11-05 21:55:13 +0100364 " Test operatorfunc
365 call Setup_NewWindow()
366 " Add some spaces for counting
367 50,60s/$/ /
368 unlet! g:opt
369 set linebreak
370 nmap <buffer><silent> ,, :set opfunc=OpfuncDummy<CR>g@
371 50
372 norm ,,j
373 exe "bd!" g:bufnr
374 call assert_true(&linebreak)
375 call assert_equal(g:opt, &linebreak)
376 set nolinebreak
377 norm ,,j
378 exe "bd!" g:bufnr
379 call assert_false(&linebreak)
380 call assert_equal(g:opt, &linebreak)
381
382 " clean up
383 unmap <buffer> ,,
384 set opfunc=
Bram Moolenaaree4e0c12020-04-06 21:35:05 +0200385 call assert_fails('normal Vg@', 'E774:')
Bram Moolenaar4a08b0d2016-11-05 21:55:13 +0100386 bw!
387 unlet! g:opt
388endfunc
389
Bram Moolenaar1bbb6192018-11-10 16:02:01 +0100390func Test_normal10_expand()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200391 " Test for expand()
392 10new
393 call setline(1, ['1', 'ifooar,,cbar'])
394 2
395 norm! $
Bram Moolenaar65f08472017-09-10 18:16:20 +0200396 call assert_equal('cbar', expand('<cword>'))
397 call assert_equal('ifooar,,cbar', expand('<cWORD>'))
398
399 call setline(1, ['prx = list[idx];'])
400 1
401 let expected = ['', 'prx', 'prx', 'prx',
402 \ 'list', 'list', 'list', 'list', 'list', 'list', 'list',
403 \ 'idx', 'idx', 'idx', 'idx',
404 \ 'list[idx]',
405 \ '];',
406 \ ]
407 for i in range(1, 16)
408 exe 'norm ' . i . '|'
409 call assert_equal(expected[i], expand('<cexpr>'), 'i == ' . i)
410 endfor
411
Bram Moolenaarae6f8652017-12-20 22:32:20 +0100412 if executable('echo')
413 " Test expand(`...`) i.e. backticks command expansion.
Bram Moolenaar077ff432019-10-28 00:42:21 +0100414 call assert_equal('abcde', expand('`echo abcde`'))
Bram Moolenaarae6f8652017-12-20 22:32:20 +0100415 endif
416
417 " Test expand(`=...`) i.e. backticks expression expansion
418 call assert_equal('5', expand('`=2+3`'))
Bram Moolenaar8b633132020-03-20 18:20:51 +0100419 call assert_equal('3.14', expand('`=3.14`'))
Bram Moolenaarae6f8652017-12-20 22:32:20 +0100420
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200421 " clean up
422 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +0200423endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200424
Bram Moolenaar1bbb6192018-11-10 16:02:01 +0100425func Test_normal11_showcmd()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200426 " test for 'showcmd'
427 10new
428 exe "norm! ofoobar\<esc>"
429 call assert_equal(2, line('$'))
430 set showcmd
431 exe "norm! ofoobar2\<esc>"
432 call assert_equal(3, line('$'))
433 exe "norm! VAfoobar3\<esc>"
434 call assert_equal(3, line('$'))
435 exe "norm! 0d3\<del>2l"
436 call assert_equal('obar2foobar3', getline('.'))
Bram Moolenaard1ad99b2020-10-04 16:16:54 +0200437 " test for the visual block size displayed in the status line
438 call setline(1, ['aaaaa', 'bbbbb', 'ccccc'])
439 call feedkeys("ggl\<C-V>lljj", 'xt')
440 redraw!
441 call assert_match('3x3$', Screenline(&lines))
442 call feedkeys("\<C-V>", 'xt')
443 " test for visually selecting a multi-byte character
444 call setline(1, ["\U2206"])
445 call feedkeys("ggv", 'xt')
446 redraw!
447 call assert_match('1-3$', Screenline(&lines))
448 call feedkeys("v", 'xt')
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200449 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +0200450endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200451
Bram Moolenaar1671f442020-03-10 07:48:13 +0100452" Test for nv_error and normal command errors
Bram Moolenaar1bbb6192018-11-10 16:02:01 +0100453func Test_normal12_nv_error()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200454 10new
455 call setline(1, range(1,5))
456 " should not do anything, just beep
Bram Moolenaarf5f1e102020-03-08 05:13:15 +0100457 call assert_beeps('exe "norm! <c-k>"')
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200458 call assert_equal(map(range(1,5), 'string(v:val)'), getline(1,'$'))
Bram Moolenaarf5f1e102020-03-08 05:13:15 +0100459 call assert_beeps('normal! G2dd')
460 call assert_beeps("normal! g\<C-A>")
461 call assert_beeps("normal! g\<C-X>")
462 call assert_beeps("normal! g\<C-B>")
Bram Moolenaar1671f442020-03-10 07:48:13 +0100463 call assert_beeps("normal! vQ\<Esc>")
464 call assert_beeps("normal! 2[[")
465 call assert_beeps("normal! 2]]")
466 call assert_beeps("normal! 2[]")
467 call assert_beeps("normal! 2][")
468 call assert_beeps("normal! 4[z")
469 call assert_beeps("normal! 4]z")
470 call assert_beeps("normal! 4[c")
471 call assert_beeps("normal! 4]c")
472 call assert_beeps("normal! 200%")
473 call assert_beeps("normal! %")
474 call assert_beeps("normal! 2{")
475 call assert_beeps("normal! 2}")
476 call assert_beeps("normal! r\<Right>")
477 call assert_beeps("normal! 8ry")
478 call assert_beeps('normal! "@')
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200479 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +0200480endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200481
Bram Moolenaar1bbb6192018-11-10 16:02:01 +0100482func Test_normal13_help()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200483 " Test for F1
484 call assert_equal(1, winnr())
485 call feedkeys("\<f1>", 'txi')
486 call assert_match('help\.txt', bufname('%'))
487 call assert_equal(2, winnr('$'))
488 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +0200489endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200490
Bram Moolenaar1bbb6192018-11-10 16:02:01 +0100491func Test_normal14_page()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200492 " basic test for Ctrl-F and Ctrl-B
493 call Setup_NewWindow()
494 exe "norm! \<c-f>"
495 call assert_equal('9', getline('.'))
496 exe "norm! 2\<c-f>"
497 call assert_equal('25', getline('.'))
498 exe "norm! 2\<c-b>"
499 call assert_equal('18', getline('.'))
500 1
501 set scrolloff=5
502 exe "norm! 2\<c-f>"
503 call assert_equal('21', getline('.'))
504 exe "norm! \<c-b>"
505 call assert_equal('13', getline('.'))
506 1
507 set scrolloff=99
508 exe "norm! \<c-f>"
509 call assert_equal('13', getline('.'))
510 set scrolloff=0
511 100
512 exe "norm! $\<c-b>"
513 call assert_equal('92', getline('.'))
514 call assert_equal([0, 92, 1, 0, 1], getcurpos())
515 100
516 set nostartofline
517 exe "norm! $\<c-b>"
518 call assert_equal('92', getline('.'))
519 call assert_equal([0, 92, 2, 0, 2147483647], getcurpos())
520 " cleanup
521 set startofline
522 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +0200523endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200524
Bram Moolenaar1bbb6192018-11-10 16:02:01 +0100525func Test_normal14_page_eol()
Bram Moolenaarbc54f3f2016-09-04 14:34:28 +0200526 10new
527 norm oxxxxxxx
528 exe "norm 2\<c-f>"
529 " check with valgrind that cursor is put back in column 1
530 exe "norm 2\<c-b>"
531 bw!
532endfunc
533
Bram Moolenaar1671f442020-03-10 07:48:13 +0100534" Test for errors with z command
535func Test_normal_z_error()
536 call assert_beeps('normal! z2p')
537 call assert_beeps('normal! zp')
538endfunc
539
Bram Moolenaar1bbb6192018-11-10 16:02:01 +0100540func Test_normal15_z_scroll_vert()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200541 " basic test for z commands that scroll the window
542 call Setup_NewWindow()
543 100
544 norm! >>
545 " Test for z<cr>
546 exe "norm! z\<cr>"
547 call assert_equal(' 100', getline('.'))
548 call assert_equal(100, winsaveview()['topline'])
549 call assert_equal([0, 100, 2, 0, 9], getcurpos())
550
551 " Test for zt
552 21
553 norm! >>0zt
554 call assert_equal(' 21', getline('.'))
555 call assert_equal(21, winsaveview()['topline'])
556 call assert_equal([0, 21, 1, 0, 8], getcurpos())
557
558 " Test for zb
559 30
560 norm! >>$ztzb
561 call assert_equal(' 30', getline('.'))
562 call assert_equal(30, winsaveview()['topline']+winheight(0)-1)
563 call assert_equal([0, 30, 3, 0, 2147483647], getcurpos())
564
565 " Test for z-
566 1
567 30
568 norm! 0z-
569 call assert_equal(' 30', getline('.'))
570 call assert_equal(30, winsaveview()['topline']+winheight(0)-1)
571 call assert_equal([0, 30, 2, 0, 9], getcurpos())
572
573 " Test for z{height}<cr>
574 call assert_equal(10, winheight(0))
575 exe "norm! z12\<cr>"
576 call assert_equal(12, winheight(0))
577 exe "norm! z10\<cr>"
578 call assert_equal(10, winheight(0))
579
580 " Test for z.
581 1
582 21
583 norm! 0z.
584 call assert_equal(' 21', getline('.'))
585 call assert_equal(17, winsaveview()['topline'])
586 call assert_equal([0, 21, 2, 0, 9], getcurpos())
587
588 " Test for zz
589 1
590 21
591 norm! 0zz
592 call assert_equal(' 21', getline('.'))
593 call assert_equal(17, winsaveview()['topline'])
594 call assert_equal([0, 21, 1, 0, 8], getcurpos())
595
596 " Test for z+
597 11
598 norm! zt
599 norm! z+
600 call assert_equal(' 21', getline('.'))
601 call assert_equal(21, winsaveview()['topline'])
602 call assert_equal([0, 21, 2, 0, 9], getcurpos())
603
604 " Test for [count]z+
605 1
606 norm! 21z+
607 call assert_equal(' 21', getline('.'))
608 call assert_equal(21, winsaveview()['topline'])
609 call assert_equal([0, 21, 2, 0, 9], getcurpos())
610
Bram Moolenaar8a9bc952020-10-02 18:48:07 +0200611 " Test for z+ with [count] greater than buffer size
612 1
613 norm! 1000z+
614 call assert_equal(' 100', getline('.'))
615 call assert_equal(100, winsaveview()['topline'])
616 call assert_equal([0, 100, 2, 0, 9], getcurpos())
617
618 " Test for z+ from the last buffer line
619 norm! Gz.z+
620 call assert_equal(' 100', getline('.'))
621 call assert_equal(100, winsaveview()['topline'])
622 call assert_equal([0, 100, 2, 0, 9], getcurpos())
623
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200624 " Test for z^
625 norm! 22z+0
626 norm! z^
627 call assert_equal(' 21', getline('.'))
628 call assert_equal(12, winsaveview()['topline'])
629 call assert_equal([0, 21, 2, 0, 9], getcurpos())
630
Bram Moolenaar8a9bc952020-10-02 18:48:07 +0200631 " Test for z^ from first buffer line
632 norm! ggz^
633 call assert_equal('1', getline('.'))
634 call assert_equal(1, winsaveview()['topline'])
635 call assert_equal([0, 1, 1, 0, 1], getcurpos())
636
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200637 " Test for [count]z^
638 1
639 norm! 30z^
640 call assert_equal(' 21', getline('.'))
641 call assert_equal(12, winsaveview()['topline'])
642 call assert_equal([0, 21, 2, 0, 9], getcurpos())
643
644 " cleanup
645 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +0200646endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200647
Bram Moolenaar1bbb6192018-11-10 16:02:01 +0100648func Test_normal16_z_scroll_hor()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200649 " basic test for z commands that scroll the window
650 10new
651 15vsp
652 set nowrap listchars=
653 let lineA='abcdefghijklmnopqrstuvwxyz'
654 let lineB='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'
655 $put =lineA
656 $put =lineB
657 1d
658
Bram Moolenaar1671f442020-03-10 07:48:13 +0100659 " Test for zl and zh with a count
660 norm! 0z10l
661 call assert_equal([11, 1], [col('.'), wincol()])
662 norm! z4h
663 call assert_equal([11, 5], [col('.'), wincol()])
664 normal! 2gg
665
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200666 " Test for zl
667 1
668 norm! 5zl
669 call assert_equal(lineA, getline('.'))
670 call assert_equal(6, col('.'))
671 call assert_equal(5, winsaveview()['leftcol'])
672 norm! yl
673 call assert_equal('f', @0)
674
675 " Test for zh
676 norm! 2zh
677 call assert_equal(lineA, getline('.'))
678 call assert_equal(6, col('.'))
679 norm! yl
680 call assert_equal('f', @0)
681 call assert_equal(3, winsaveview()['leftcol'])
682
683 " Test for zL
684 norm! zL
685 call assert_equal(11, col('.'))
686 norm! yl
687 call assert_equal('k', @0)
688 call assert_equal(10, winsaveview()['leftcol'])
689 norm! 2zL
690 call assert_equal(25, col('.'))
691 norm! yl
692 call assert_equal('y', @0)
693 call assert_equal(24, winsaveview()['leftcol'])
694
695 " Test for zH
696 norm! 2zH
697 call assert_equal(25, col('.'))
698 call assert_equal(10, winsaveview()['leftcol'])
699 norm! yl
700 call assert_equal('y', @0)
701
702 " Test for zs
703 norm! $zs
704 call assert_equal(26, col('.'))
705 call assert_equal(25, winsaveview()['leftcol'])
706 norm! yl
707 call assert_equal('z', @0)
708
709 " Test for ze
710 norm! ze
711 call assert_equal(26, col('.'))
712 call assert_equal(11, winsaveview()['leftcol'])
713 norm! yl
714 call assert_equal('z', @0)
715
Bram Moolenaar8a9bc952020-10-02 18:48:07 +0200716 " Test for zs and ze with folds
717 %fold
718 norm! $zs
719 call assert_equal(26, col('.'))
720 call assert_equal(0, winsaveview()['leftcol'])
721 norm! yl
722 call assert_equal('z', @0)
723 norm! ze
724 call assert_equal(26, col('.'))
725 call assert_equal(0, winsaveview()['leftcol'])
726 norm! yl
727 call assert_equal('z', @0)
728
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200729 " cleanup
730 set wrap listchars=eol:$
731 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +0200732endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200733
Bram Moolenaar1bbb6192018-11-10 16:02:01 +0100734func Test_normal17_z_scroll_hor2()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200735 " basic test for z commands that scroll the window
736 " using 'sidescrolloff' setting
737 10new
738 20vsp
739 set nowrap listchars= sidescrolloff=5
740 let lineA='abcdefghijklmnopqrstuvwxyz'
741 let lineB='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'
742 $put =lineA
743 $put =lineB
744 1d
745
746 " Test for zl
747 1
748 norm! 5zl
749 call assert_equal(lineA, getline('.'))
750 call assert_equal(11, col('.'))
751 call assert_equal(5, winsaveview()['leftcol'])
752 norm! yl
753 call assert_equal('k', @0)
754
755 " Test for zh
756 norm! 2zh
757 call assert_equal(lineA, getline('.'))
758 call assert_equal(11, col('.'))
759 norm! yl
760 call assert_equal('k', @0)
761 call assert_equal(3, winsaveview()['leftcol'])
762
763 " Test for zL
764 norm! 0zL
765 call assert_equal(16, col('.'))
766 norm! yl
767 call assert_equal('p', @0)
768 call assert_equal(10, winsaveview()['leftcol'])
769 norm! 2zL
770 call assert_equal(26, col('.'))
771 norm! yl
772 call assert_equal('z', @0)
773 call assert_equal(15, winsaveview()['leftcol'])
774
775 " Test for zH
776 norm! 2zH
777 call assert_equal(15, col('.'))
778 call assert_equal(0, winsaveview()['leftcol'])
779 norm! yl
780 call assert_equal('o', @0)
781
782 " Test for zs
783 norm! $zs
784 call assert_equal(26, col('.'))
785 call assert_equal(20, winsaveview()['leftcol'])
786 norm! yl
787 call assert_equal('z', @0)
788
789 " Test for ze
790 norm! ze
791 call assert_equal(26, col('.'))
792 call assert_equal(11, winsaveview()['leftcol'])
793 norm! yl
794 call assert_equal('z', @0)
795
796 " cleanup
797 set wrap listchars=eol:$ sidescrolloff=0
798 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +0200799endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200800
Bram Moolenaarbdd2c292020-06-22 21:34:30 +0200801" Test for commands that scroll the window horizontally. Test with folds.
802" H, M, L, CTRL-E, CTRL-Y, CTRL-U, CTRL-D, PageUp, PageDown commands
803func Test_vert_scroll_cmds()
Bram Moolenaar1671f442020-03-10 07:48:13 +0100804 15new
805 call setline(1, range(1, 100))
806 exe "normal! 30ggz\<CR>"
807 set foldenable
808 33,36fold
809 40,43fold
810 46,49fold
811 let h = winheight(0)
Bram Moolenaarbdd2c292020-06-22 21:34:30 +0200812
813 " Test for H, M and L commands
Bram Moolenaar1671f442020-03-10 07:48:13 +0100814 " Top of the screen = 30
815 " Folded lines = 9
816 " Bottom of the screen = 30 + h + 9 - 1
817 normal! 4L
818 call assert_equal(35 + h, line('.'))
819 normal! 4H
820 call assert_equal(33, line('.'))
Bram Moolenaarbdd2c292020-06-22 21:34:30 +0200821
Bram Moolenaar8a9bc952020-10-02 18:48:07 +0200822 " Test for using a large count value
823 %d
824 call setline(1, range(1, 4))
825 norm! 6H
826 call assert_equal(4, line('.'))
827
828 " Test for 'M' with folded lines
829 %d
830 call setline(1, range(1, 20))
831 1,5fold
832 norm! LM
833 call assert_equal(12, line('.'))
834
Bram Moolenaarbdd2c292020-06-22 21:34:30 +0200835 " Test for the CTRL-E and CTRL-Y commands with folds
836 %d
837 call setline(1, range(1, 10))
838 3,5fold
839 exe "normal 6G3\<C-E>"
840 call assert_equal(6, line('w0'))
841 exe "normal 2\<C-Y>"
842 call assert_equal(2, line('w0'))
843
844 " Test for CTRL-Y on a folded line
845 %d
846 call setline(1, range(1, 100))
847 exe (h + 2) .. "," .. (h + 4) .. "fold"
848 exe h + 5
849 normal z-
850 exe "normal \<C-Y>\<C-Y>"
851 call assert_equal(h + 1, line('w$'))
852
Bram Moolenaard1ad99b2020-10-04 16:16:54 +0200853 " Test for CTRL-Y from the first line and CTRL-E from the last line
854 %d
855 set scrolloff=2
856 call setline(1, range(1, 4))
857 exe "normal gg\<C-Y>"
858 call assert_equal(1, line('w0'))
859 call assert_equal(1, line('.'))
860 exe "normal G4\<C-E>\<C-E>"
861 call assert_equal(4, line('w$'))
862 call assert_equal(4, line('.'))
863 set scrolloff&
864
Bram Moolenaarbdd2c292020-06-22 21:34:30 +0200865 " Using <PageUp> and <PageDown> in an empty buffer should beep
866 %d
867 call assert_beeps('exe "normal \<PageUp>"')
868 call assert_beeps('exe "normal \<C-B>"')
869 call assert_beeps('exe "normal \<PageDown>"')
870 call assert_beeps('exe "normal \<C-F>"')
871
872 " Test for <C-U> and <C-D> with fold
873 %d
874 call setline(1, range(1, 100))
875 10,35fold
876 set scroll=10
877 exe "normal \<C-D>"
878 call assert_equal(36, line('.'))
879 exe "normal \<C-D>"
880 call assert_equal(46, line('.'))
881 exe "normal \<C-U>"
882 call assert_equal(36, line('.'))
883 exe "normal \<C-U>"
884 call assert_equal(10, line('.'))
885 exe "normal \<C-U>"
886 call assert_equal(1, line('.'))
887 set scroll&
888
889 " Test for scrolling to the top of the file with <C-U> and a fold
890 10
891 normal ztL
892 exe "normal \<C-U>\<C-U>"
893 call assert_equal(1, line('w0'))
894
895 " Test for CTRL-D on a folded line
896 %d
897 call setline(1, range(1, 100))
898 50,100fold
899 75
900 normal z-
901 exe "normal \<C-D>"
902 call assert_equal(50, line('.'))
903 call assert_equal(100, line('w$'))
904 normal z.
905 let lnum = winline()
906 exe "normal \<C-D>"
907 call assert_equal(lnum, winline())
908 call assert_equal(50, line('.'))
909 normal zt
910 exe "normal \<C-D>"
911 call assert_equal(50, line('w0'))
912
Bram Moolenaard1ad99b2020-10-04 16:16:54 +0200913 " Test for <S-CR>. Page down.
914 %d
915 call setline(1, range(1, 100))
916 call feedkeys("\<S-CR>", 'xt')
917 call assert_equal(14, line('w0'))
918 call assert_equal(28, line('w$'))
919
920 " Test for <S-->. Page up.
921 call feedkeys("\<S-->", 'xt')
922 call assert_equal(1, line('w0'))
923 call assert_equal(15, line('w$'))
924
Bram Moolenaar1671f442020-03-10 07:48:13 +0100925 set foldenable&
926 close!
927endfunc
928
Bram Moolenaarbdd2c292020-06-22 21:34:30 +0200929" Test for the 'sidescroll' option
930func Test_sidescroll_opt()
931 new
932 20vnew
933
934 " scroll by 2 characters horizontally
935 set sidescroll=2 nowrap
936 call setline(1, repeat('a', 40))
937 normal g$l
938 call assert_equal(19, screenpos(0, 1, 21).col)
939 normal l
940 call assert_equal(20, screenpos(0, 1, 22).col)
941 normal g0h
942 call assert_equal(2, screenpos(0, 1, 2).col)
943 call assert_equal(20, screenpos(0, 1, 20).col)
944
945 " when 'sidescroll' is 0, cursor positioned at the center
946 set sidescroll=0
947 normal g$l
948 call assert_equal(11, screenpos(0, 1, 21).col)
949 normal g0h
950 call assert_equal(10, screenpos(0, 1, 10).col)
951
952 %bw!
953 set wrap& sidescroll&
954endfunc
955
Bram Moolenaar004a6782020-04-11 17:09:31 +0200956" basic tests for foldopen/folddelete
Bram Moolenaar1bbb6192018-11-10 16:02:01 +0100957func Test_normal18_z_fold()
Bram Moolenaar004a6782020-04-11 17:09:31 +0200958 CheckFeature folding
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200959 call Setup_NewWindow()
960 50
961 setl foldenable fdm=marker foldlevel=5
962
Bram Moolenaar1671f442020-03-10 07:48:13 +0100963 call assert_beeps('normal! zj')
964 call assert_beeps('normal! zk')
965
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200966 " Test for zF
967 " First fold
968 norm! 4zF
969 " check that folds have been created
970 call assert_equal(['50/*{{{*/', '51', '52', '53/*}}}*/'], getline(50,53))
971
972 " Test for zd
973 51
974 norm! 2zF
975 call assert_equal(2, foldlevel('.'))
976 norm! kzd
977 call assert_equal(['50', '51/*{{{*/', '52/*}}}*/', '53'], getline(50,53))
978 norm! j
979 call assert_equal(1, foldlevel('.'))
980
981 " Test for zD
982 " also deletes partially selected folds recursively
983 51
984 norm! zF
985 call assert_equal(2, foldlevel('.'))
986 norm! kV2jzD
987 call assert_equal(['50', '51', '52', '53'], getline(50,53))
988
989 " Test for zE
990 85
991 norm! 4zF
992 86
993 norm! 2zF
994 90
995 norm! 4zF
996 call assert_equal(['85/*{{{*/', '86/*{{{*/', '87/*}}}*/', '88/*}}}*/', '89', '90/*{{{*/', '91', '92', '93/*}}}*/'], getline(85,93))
997 norm! zE
998 call assert_equal(['85', '86', '87', '88', '89', '90', '91', '92', '93'], getline(85,93))
999
1000 " Test for zn
1001 50
1002 set foldlevel=0
1003 norm! 2zF
1004 norm! zn
1005 norm! k
1006 call assert_equal('49', getline('.'))
1007 norm! j
1008 call assert_equal('50/*{{{*/', getline('.'))
1009 norm! j
1010 call assert_equal('51/*}}}*/', getline('.'))
1011 norm! j
1012 call assert_equal('52', getline('.'))
1013 call assert_equal(0, &foldenable)
1014
1015 " Test for zN
1016 49
1017 norm! zN
1018 call assert_equal('49', getline('.'))
1019 norm! j
1020 call assert_equal('50/*{{{*/', getline('.'))
1021 norm! j
1022 call assert_equal('52', getline('.'))
1023 call assert_equal(1, &foldenable)
1024
1025 " Test for zi
1026 norm! zi
1027 call assert_equal(0, &foldenable)
1028 norm! zi
1029 call assert_equal(1, &foldenable)
1030 norm! zi
1031 call assert_equal(0, &foldenable)
1032 norm! zi
1033 call assert_equal(1, &foldenable)
1034
1035 " Test for za
1036 50
1037 norm! za
1038 norm! k
1039 call assert_equal('49', getline('.'))
1040 norm! j
1041 call assert_equal('50/*{{{*/', getline('.'))
1042 norm! j
1043 call assert_equal('51/*}}}*/', getline('.'))
1044 norm! j
1045 call assert_equal('52', getline('.'))
1046 50
1047 norm! za
1048 norm! k
1049 call assert_equal('49', getline('.'))
1050 norm! j
1051 call assert_equal('50/*{{{*/', getline('.'))
1052 norm! j
1053 call assert_equal('52', getline('.'))
1054
1055 49
1056 norm! 5zF
1057 norm! k
1058 call assert_equal('48', getline('.'))
1059 norm! j
1060 call assert_equal('49/*{{{*/', getline('.'))
1061 norm! j
1062 call assert_equal('55', getline('.'))
1063 49
1064 norm! za
1065 call assert_equal('49/*{{{*/', getline('.'))
1066 norm! j
1067 call assert_equal('50/*{{{*/', getline('.'))
1068 norm! j
1069 call assert_equal('52', getline('.'))
1070 set nofoldenable
1071 " close fold and set foldenable
1072 norm! za
1073 call assert_equal(1, &foldenable)
1074
1075 50
1076 " have to use {count}za to open all folds and make the cursor visible
1077 norm! 2za
1078 norm! 2k
1079 call assert_equal('48', getline('.'))
1080 norm! j
1081 call assert_equal('49/*{{{*/', getline('.'))
1082 norm! j
1083 call assert_equal('50/*{{{*/', getline('.'))
1084 norm! j
1085 call assert_equal('51/*}}}*/', getline('.'))
1086 norm! j
1087 call assert_equal('52', getline('.'))
1088
1089 " Test for zA
1090 49
1091 set foldlevel=0
1092 50
1093 norm! zA
1094 norm! 2k
1095 call assert_equal('48', getline('.'))
1096 norm! j
1097 call assert_equal('49/*{{{*/', getline('.'))
1098 norm! j
1099 call assert_equal('50/*{{{*/', getline('.'))
1100 norm! j
1101 call assert_equal('51/*}}}*/', getline('.'))
1102 norm! j
1103 call assert_equal('52', getline('.'))
1104
Bram Moolenaar395b6ba2017-04-07 20:09:51 +02001105 " zA on a opened fold when foldenable is not set
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001106 50
1107 set nofoldenable
1108 norm! zA
1109 call assert_equal(1, &foldenable)
1110 norm! k
1111 call assert_equal('48', getline('.'))
1112 norm! j
1113 call assert_equal('49/*{{{*/', getline('.'))
1114 norm! j
1115 call assert_equal('55', getline('.'))
1116
1117 " Test for zc
1118 norm! zE
1119 50
1120 norm! 2zF
1121 49
1122 norm! 5zF
1123 set nofoldenable
1124 50
1125 " There most likely is a bug somewhere:
1126 " https://groups.google.com/d/msg/vim_dev/v2EkfJ_KQjI/u-Cvv94uCAAJ
1127 " TODO: Should this only close the inner most fold or both folds?
1128 norm! zc
1129 call assert_equal(1, &foldenable)
1130 norm! k
1131 call assert_equal('48', getline('.'))
1132 norm! j
1133 call assert_equal('49/*{{{*/', getline('.'))
1134 norm! j
1135 call assert_equal('55', getline('.'))
1136 set nofoldenable
1137 50
1138 norm! Vjzc
1139 norm! k
1140 call assert_equal('48', getline('.'))
1141 norm! j
1142 call assert_equal('49/*{{{*/', getline('.'))
1143 norm! j
1144 call assert_equal('55', getline('.'))
1145
1146 " Test for zC
1147 set nofoldenable
1148 50
1149 norm! zCk
1150 call assert_equal('48', getline('.'))
1151 norm! j
1152 call assert_equal('49/*{{{*/', getline('.'))
1153 norm! j
1154 call assert_equal('55', getline('.'))
1155
1156 " Test for zx
1157 " 1) close folds at line 49-54
1158 set nofoldenable
1159 48
1160 norm! zx
1161 call assert_equal(1, &foldenable)
1162 norm! j
1163 call assert_equal('49/*{{{*/', getline('.'))
1164 norm! j
1165 call assert_equal('55', getline('.'))
1166
Bram Moolenaar395b6ba2017-04-07 20:09:51 +02001167 " 2) do not close fold under cursor
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001168 51
1169 set nofoldenable
1170 norm! zx
1171 call assert_equal(1, &foldenable)
1172 norm! 3k
1173 call assert_equal('48', getline('.'))
1174 norm! j
1175 call assert_equal('49/*{{{*/', getline('.'))
1176 norm! j
1177 call assert_equal('50/*{{{*/', getline('.'))
1178 norm! j
1179 call assert_equal('51/*}}}*/', getline('.'))
1180 norm! j
1181 call assert_equal('52', getline('.'))
1182 norm! j
1183 call assert_equal('53', getline('.'))
1184 norm! j
1185 call assert_equal('54/*}}}*/', getline('.'))
1186 norm! j
1187 call assert_equal('55', getline('.'))
1188
1189 " 3) close one level of folds
1190 48
1191 set nofoldenable
1192 set foldlevel=1
1193 norm! zx
1194 call assert_equal(1, &foldenable)
1195 call assert_equal('48', getline('.'))
1196 norm! j
1197 call assert_equal('49/*{{{*/', getline('.'))
1198 norm! j
1199 call assert_equal('50/*{{{*/', getline('.'))
1200 norm! j
1201 call assert_equal('52', getline('.'))
1202 norm! j
1203 call assert_equal('53', getline('.'))
1204 norm! j
1205 call assert_equal('54/*}}}*/', getline('.'))
1206 norm! j
1207 call assert_equal('55', getline('.'))
1208
1209 " Test for zX
1210 " Close all folds
1211 set foldlevel=0 nofoldenable
1212 50
1213 norm! zX
1214 call assert_equal(1, &foldenable)
1215 norm! k
1216 call assert_equal('48', getline('.'))
1217 norm! j
1218 call assert_equal('49/*{{{*/', getline('.'))
1219 norm! j
1220 call assert_equal('55', getline('.'))
1221
1222 " Test for zm
1223 50
1224 set nofoldenable foldlevel=2
1225 norm! zm
1226 call assert_equal(1, &foldenable)
1227 call assert_equal(1, &foldlevel)
1228 norm! zm
1229 call assert_equal(0, &foldlevel)
1230 norm! zm
1231 call assert_equal(0, &foldlevel)
1232 norm! k
1233 call assert_equal('48', getline('.'))
1234 norm! j
1235 call assert_equal('49/*{{{*/', getline('.'))
1236 norm! j
1237 call assert_equal('55', getline('.'))
1238
Bram Moolenaar8a9bc952020-10-02 18:48:07 +02001239 " Test for zm with a count
1240 50
1241 set foldlevel=2
1242 norm! 3zm
1243 call assert_equal(0, &foldlevel)
1244 call assert_equal(49, foldclosed(line('.')))
1245
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001246 " Test for zM
1247 48
1248 set nofoldenable foldlevel=99
1249 norm! zM
1250 call assert_equal(1, &foldenable)
1251 call assert_equal(0, &foldlevel)
1252 call assert_equal('48', getline('.'))
1253 norm! j
1254 call assert_equal('49/*{{{*/', getline('.'))
1255 norm! j
1256 call assert_equal('55', getline('.'))
1257
1258 " Test for zr
1259 48
1260 set nofoldenable foldlevel=0
1261 norm! zr
1262 call assert_equal(0, &foldenable)
1263 call assert_equal(1, &foldlevel)
1264 set foldlevel=0 foldenable
1265 norm! zr
1266 call assert_equal(1, &foldenable)
1267 call assert_equal(1, &foldlevel)
1268 norm! zr
1269 call assert_equal(2, &foldlevel)
1270 call assert_equal('48', getline('.'))
1271 norm! j
1272 call assert_equal('49/*{{{*/', getline('.'))
1273 norm! j
1274 call assert_equal('50/*{{{*/', getline('.'))
1275 norm! j
1276 call assert_equal('51/*}}}*/', getline('.'))
1277 norm! j
1278 call assert_equal('52', getline('.'))
1279
1280 " Test for zR
1281 48
1282 set nofoldenable foldlevel=0
1283 norm! zR
1284 call assert_equal(0, &foldenable)
1285 call assert_equal(2, &foldlevel)
1286 set foldenable foldlevel=0
1287 norm! zR
1288 call assert_equal(1, &foldenable)
1289 call assert_equal(2, &foldlevel)
1290 call assert_equal('48', getline('.'))
1291 norm! j
1292 call assert_equal('49/*{{{*/', getline('.'))
1293 norm! j
1294 call assert_equal('50/*{{{*/', getline('.'))
1295 norm! j
1296 call assert_equal('51/*}}}*/', getline('.'))
1297 norm! j
1298 call assert_equal('52', getline('.'))
1299 call append(50, ['a /*{{{*/', 'b /*}}}*/'])
1300 48
1301 call assert_equal('48', getline('.'))
1302 norm! j
1303 call assert_equal('49/*{{{*/', getline('.'))
1304 norm! j
1305 call assert_equal('50/*{{{*/', getline('.'))
1306 norm! j
1307 call assert_equal('a /*{{{*/', getline('.'))
1308 norm! j
1309 call assert_equal('51/*}}}*/', getline('.'))
1310 norm! j
1311 call assert_equal('52', getline('.'))
1312 48
1313 norm! zR
1314 call assert_equal(1, &foldenable)
1315 call assert_equal(3, &foldlevel)
1316 call assert_equal('48', getline('.'))
1317 norm! j
1318 call assert_equal('49/*{{{*/', getline('.'))
1319 norm! j
1320 call assert_equal('50/*{{{*/', getline('.'))
1321 norm! j
1322 call assert_equal('a /*{{{*/', getline('.'))
1323 norm! j
1324 call assert_equal('b /*}}}*/', getline('.'))
1325 norm! j
1326 call assert_equal('51/*}}}*/', getline('.'))
1327 norm! j
1328 call assert_equal('52', getline('.'))
1329
1330 " clean up
1331 setl nofoldenable fdm=marker foldlevel=0
1332 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02001333endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001334
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01001335func Test_normal20_exmode()
Bram Moolenaar004a6782020-04-11 17:09:31 +02001336 " Reading from redirected file doesn't work on MS-Windows
1337 CheckNotMSWindows
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001338 call writefile(['1a', 'foo', 'bar', '.', 'w! Xfile2', 'q!'], 'Xscript')
1339 call writefile(['1', '2'], 'Xfile')
Bram Moolenaar93344c22019-08-14 21:12:05 +02001340 call system(GetVimCommand() .. ' -e -s < Xscript Xfile')
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001341 let a=readfile('Xfile2')
1342 call assert_equal(['1', 'foo', 'bar', '2'], a)
1343
1344 " clean up
1345 for file in ['Xfile', 'Xfile2', 'Xscript']
1346 call delete(file)
1347 endfor
1348 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02001349endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001350
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01001351func Test_normal21_nv_hat()
1352
1353 " Edit a fresh file and wipe the buffer list so that there is no alternate
1354 " file present. Next, check for the expected command failures.
1355 edit Xfoo | %bw
Bram Moolenaare2e40752020-09-04 21:18:46 +02001356 call assert_fails(':buffer #', 'E86:')
1357 call assert_fails(':execute "normal! \<C-^>"', 'E23:')
Bram Moolenaarb7e24832020-06-24 13:37:35 +02001358 call assert_fails("normal i\<C-R>#", 'E23:')
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01001359
1360 " Test for the expected behavior when switching between two named buffers.
1361 edit Xfoo | edit Xbar
1362 call feedkeys("\<C-^>", 'tx')
1363 call assert_equal('Xfoo', fnamemodify(bufname('%'), ':t'))
1364 call feedkeys("\<C-^>", 'tx')
1365 call assert_equal('Xbar', fnamemodify(bufname('%'), ':t'))
1366
1367 " Test for the expected behavior when only one buffer is named.
1368 enew | let l:nr = bufnr('%')
1369 call feedkeys("\<C-^>", 'tx')
1370 call assert_equal('Xbar', fnamemodify(bufname('%'), ':t'))
1371 call feedkeys("\<C-^>", 'tx')
1372 call assert_equal('', bufname('%'))
1373 call assert_equal(l:nr, bufnr('%'))
1374
1375 " Test that no action is taken by "<C-^>" when an operator is pending.
1376 edit Xfoo
1377 call feedkeys("ci\<C-^>", 'tx')
1378 call assert_equal('Xfoo', fnamemodify(bufname('%'), ':t'))
1379
1380 %bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02001381endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001382
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01001383func Test_normal22_zet()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001384 " Test for ZZ
Bram Moolenaar0913a102016-09-03 19:11:59 +02001385 " let shell = &shell
1386 " let &shell = 'sh'
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001387 call writefile(['1', '2'], 'Xfile')
Bram Moolenaar93344c22019-08-14 21:12:05 +02001388 let args = ' -N -i NONE --noplugins -X --not-a-term'
1389 call system(GetVimCommand() .. args .. ' -c "%d" -c ":norm! ZZ" Xfile')
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001390 let a = readfile('Xfile')
1391 call assert_equal([], a)
1392 " Test for ZQ
1393 call writefile(['1', '2'], 'Xfile')
Bram Moolenaar93344c22019-08-14 21:12:05 +02001394 call system(GetVimCommand() . args . ' -c "%d" -c ":norm! ZQ" Xfile')
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001395 let a = readfile('Xfile')
1396 call assert_equal(['1', '2'], a)
1397
Bram Moolenaar1671f442020-03-10 07:48:13 +01001398 " Unsupported Z command
1399 call assert_beeps('normal! ZW')
1400
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001401 " clean up
1402 for file in ['Xfile']
1403 call delete(file)
1404 endfor
Bram Moolenaar0913a102016-09-03 19:11:59 +02001405 " let &shell = shell
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02001406endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001407
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01001408func Test_normal23_K()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001409 " Test for K command
1410 new
Bram Moolenaar426f3752016-11-04 21:22:37 +01001411 call append(0, ['version8.txt', 'man', 'aa%bb', 'cc|dd'])
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001412 let k = &keywordprg
1413 set keywordprg=:help
1414 1
1415 norm! VK
1416 call assert_equal('version8.txt', fnamemodify(bufname('%'), ':t'))
1417 call assert_equal('help', &ft)
1418 call assert_match('\*version8.txt\*', getline('.'))
1419 helpclose
1420 norm! 0K
1421 call assert_equal('version8.txt', fnamemodify(bufname('%'), ':t'))
1422 call assert_equal('help', &ft)
Bram Moolenaarb1c91982018-05-17 17:04:55 +02001423 call assert_match('\*version8\.\d\*', getline('.'))
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001424 helpclose
1425
Bram Moolenaar426f3752016-11-04 21:22:37 +01001426 set keywordprg=:new
1427 set iskeyword+=%
1428 set iskeyword+=\|
1429 2
1430 norm! K
1431 call assert_equal('man', fnamemodify(bufname('%'), ':t'))
1432 bwipe!
1433 3
1434 norm! K
1435 call assert_equal('aa%bb', fnamemodify(bufname('%'), ':t'))
1436 bwipe!
Bram Moolenaareb828d02016-11-05 19:54:01 +01001437 if !has('win32')
1438 4
1439 norm! K
1440 call assert_equal('cc|dd', fnamemodify(bufname('%'), ':t'))
1441 bwipe!
1442 endif
Bram Moolenaar426f3752016-11-04 21:22:37 +01001443 set iskeyword-=%
1444 set iskeyword-=\|
1445
Bram Moolenaar8a9bc952020-10-02 18:48:07 +02001446 " Test for specifying a count to K
1447 1
1448 com! -nargs=* Kprog let g:Kprog_Args = <q-args>
1449 set keywordprg=:Kprog
1450 norm! 3K
1451 call assert_equal('3 version8', g:Kprog_Args)
1452 delcom Kprog
1453
Bram Moolenaar0913a102016-09-03 19:11:59 +02001454 " Only expect "man" to work on Unix
1455 if !has("unix")
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001456 let &keywordprg = k
1457 bw!
1458 return
1459 endif
Bram Moolenaarc6b37db2019-04-27 18:00:34 +02001460
Bram Moolenaar9134f1e2019-11-29 20:26:13 +01001461 let not_gnu_man = has('mac') || has('bsd')
1462 if not_gnu_man
Bram Moolenaarc7d2a572019-11-28 21:16:06 +01001463 " In MacOS and BSD, the option for specifying a pager is different
Bram Moolenaarc6b37db2019-04-27 18:00:34 +02001464 set keywordprg=man\ -P\ cat
1465 else
1466 set keywordprg=man\ --pager=cat
1467 endif
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001468 " Test for using man
1469 2
1470 let a = execute('unsilent norm! K')
Bram Moolenaar9134f1e2019-11-29 20:26:13 +01001471 if not_gnu_man
Bram Moolenaarc6b37db2019-04-27 18:00:34 +02001472 call assert_match("man -P cat 'man'", a)
1473 else
1474 call assert_match("man --pager=cat 'man'", a)
1475 endif
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001476
Bram Moolenaar1671f442020-03-10 07:48:13 +01001477 " Error cases
1478 call setline(1, '#$#')
1479 call assert_fails('normal! ggK', 'E349:')
1480 call setline(1, '---')
1481 call assert_fails('normal! ggv2lK', 'E349:')
1482 call setline(1, ['abc', 'xyz'])
Bram Moolenaar9b7bf9e2020-07-11 22:14:59 +02001483 call assert_fails("normal! gg2lv2h\<C-]>", 'E433:')
Bram Moolenaar1671f442020-03-10 07:48:13 +01001484 call assert_beeps("normal! ggVjK")
Bram Moolenaar8a9bc952020-10-02 18:48:07 +02001485 norm! V
1486 call assert_beeps("norm! cK")
Bram Moolenaar1671f442020-03-10 07:48:13 +01001487
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001488 " clean up
1489 let &keywordprg = k
1490 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02001491endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001492
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01001493func Test_normal24_rot13()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001494 " Testing for g?? g?g?
1495 new
1496 call append(0, 'abcdefghijklmnopqrstuvwxyzäüö')
1497 1
1498 norm! g??
1499 call assert_equal('nopqrstuvwxyzabcdefghijklmäüö', getline('.'))
1500 norm! g?g?
1501 call assert_equal('abcdefghijklmnopqrstuvwxyzäüö', getline('.'))
1502
1503 " clean up
1504 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02001505endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001506
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01001507func Test_normal25_tag()
Bram Moolenaar5a4c3082019-12-01 15:23:11 +01001508 CheckFeature quickfix
1509
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001510 " Testing for CTRL-] g CTRL-] g]
1511 " CTRL-W g] CTRL-W CTRL-] CTRL-W g CTRL-]
1512 h
1513 " Test for CTRL-]
1514 call search('\<x\>$')
1515 exe "norm! \<c-]>"
1516 call assert_equal("change.txt", fnamemodify(bufname('%'), ':t'))
1517 norm! yiW
1518 call assert_equal("*x*", @0)
1519 exe ":norm \<c-o>"
1520
1521 " Test for g_CTRL-]
1522 call search('\<v_u\>$')
1523 exe "norm! g\<c-]>"
1524 call assert_equal("change.txt", fnamemodify(bufname('%'), ':t'))
1525 norm! yiW
1526 call assert_equal("*v_u*", @0)
1527 exe ":norm \<c-o>"
1528
1529 " Test for g]
1530 call search('\<i_<Esc>$')
1531 let a = execute(":norm! g]")
1532 call assert_match('i_<Esc>.*insert.txt', a)
1533
1534 if !empty(exepath('cscope')) && has('cscope')
1535 " setting cscopetag changes how g] works
1536 set cst
1537 exe "norm! g]"
1538 call assert_equal("insert.txt", fnamemodify(bufname('%'), ':t'))
1539 norm! yiW
1540 call assert_equal("*i_<Esc>*", @0)
1541 exe ":norm \<c-o>"
1542 " Test for CTRL-W g]
1543 exe "norm! \<C-W>g]"
1544 call assert_equal("insert.txt", fnamemodify(bufname('%'), ':t'))
1545 norm! yiW
1546 call assert_equal("*i_<Esc>*", @0)
1547 call assert_equal(3, winnr('$'))
1548 helpclose
1549 set nocst
1550 endif
1551
1552 " Test for CTRL-W g]
1553 let a = execute("norm! \<C-W>g]")
1554 call assert_match('i_<Esc>.*insert.txt', a)
1555
1556 " Test for CTRL-W CTRL-]
1557 exe "norm! \<C-W>\<C-]>"
1558 call assert_equal("insert.txt", fnamemodify(bufname('%'), ':t'))
1559 norm! yiW
1560 call assert_equal("*i_<Esc>*", @0)
1561 call assert_equal(3, winnr('$'))
1562 helpclose
1563
1564 " Test for CTRL-W g CTRL-]
1565 exe "norm! \<C-W>g\<C-]>"
1566 call assert_equal("insert.txt", fnamemodify(bufname('%'), ':t'))
1567 norm! yiW
1568 call assert_equal("*i_<Esc>*", @0)
1569 call assert_equal(3, winnr('$'))
1570 helpclose
1571
1572 " clean up
1573 helpclose
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02001574endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001575
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01001576func Test_normal26_put()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001577 " Test for ]p ]P [p and [P
1578 new
1579 call append(0, ['while read LINE', 'do', ' ((count++))', ' if [ $? -ne 0 ]; then', " echo 'Error writing file'", ' fi', 'done'])
1580 1
1581 /Error/y a
1582 2
1583 norm! "a]pj"a[p
1584 call assert_equal(['do', "echo 'Error writing file'", " echo 'Error writing file'", ' ((count++))'], getline(2,5))
1585 1
1586 /^\s\{4}/
1587 exe "norm! \"a]P3Eldt'"
1588 exe "norm! j\"a[P2Eldt'"
1589 call assert_equal([' if [ $? -ne 0 ]; then', " echo 'Error writing'", " echo 'Error'", " echo 'Error writing file'", ' fi'], getline(6,10))
1590
1591 " clean up
1592 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02001593endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001594
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01001595func Test_normal27_bracket()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001596 " Test for [' [` ]' ]`
1597 call Setup_NewWindow()
1598 1,21s/.\+/ & b/
1599 1
1600 norm! $ma
1601 5
1602 norm! $mb
1603 10
1604 norm! $mc
1605 15
1606 norm! $md
1607 20
1608 norm! $me
1609
1610 " Test for ['
1611 9
1612 norm! 2['
1613 call assert_equal(' 1 b', getline('.'))
1614 call assert_equal(1, line('.'))
1615 call assert_equal(3, col('.'))
1616
1617 " Test for ]'
1618 norm! ]'
1619 call assert_equal(' 5 b', getline('.'))
1620 call assert_equal(5, line('.'))
1621 call assert_equal(3, col('.'))
1622
1623 " No mark after line 21, cursor moves to first non blank on current line
1624 21
1625 norm! $]'
1626 call assert_equal(' 21 b', getline('.'))
1627 call assert_equal(21, line('.'))
1628 call assert_equal(3, col('.'))
1629
1630 " Test for [`
1631 norm! 2[`
1632 call assert_equal(' 15 b', getline('.'))
1633 call assert_equal(15, line('.'))
1634 call assert_equal(8, col('.'))
1635
1636 " Test for ]`
1637 norm! ]`
1638 call assert_equal(' 20 b', getline('.'))
1639 call assert_equal(20, line('.'))
1640 call assert_equal(8, col('.'))
1641
1642 " clean up
1643 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02001644endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001645
Bram Moolenaar1671f442020-03-10 07:48:13 +01001646" Test for ( and ) sentence movements
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01001647func Test_normal28_parenthesis()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001648 new
1649 call append(0, ['This is a test. With some sentences!', '', 'Even with a question? And one more. And no sentence here'])
1650
1651 $
1652 norm! d(
1653 call assert_equal(['This is a test. With some sentences!', '', 'Even with a question? And one more. ', ''], getline(1, '$'))
1654 norm! 2d(
1655 call assert_equal(['This is a test. With some sentences!', '', ' ', ''], getline(1, '$'))
1656 1
1657 norm! 0d)
1658 call assert_equal(['With some sentences!', '', ' ', ''], getline(1, '$'))
1659
1660 call append('$', ['This is a long sentence', '', 'spanning', 'over several lines. '])
1661 $
1662 norm! $d(
1663 call assert_equal(['With some sentences!', '', ' ', '', 'This is a long sentence', ''], getline(1, '$'))
1664
Bram Moolenaar224a5f12020-04-28 20:29:07 +02001665 " Move to the next sentence from a paragraph macro
1666 %d
1667 call setline(1, ['.LP', 'blue sky!. blue sky.', 'blue sky. blue sky.'])
1668 call cursor(1, 1)
1669 normal )
1670 call assert_equal([2, 1], [line('.'), col('.')])
1671 normal )
1672 call assert_equal([2, 12], [line('.'), col('.')])
1673 normal ((
1674 call assert_equal([1, 1], [line('.'), col('.')])
1675
Bram Moolenaar1671f442020-03-10 07:48:13 +01001676 " It is an error if a next sentence is not found
1677 %d
1678 call setline(1, '.SH')
1679 call assert_beeps('normal )')
1680
Bram Moolenaar224a5f12020-04-28 20:29:07 +02001681 " If only dot is present, don't treat that as a sentence
1682 call setline(1, '. This is a sentence.')
1683 normal $((
1684 call assert_equal(3, col('.'))
1685
Bram Moolenaar1671f442020-03-10 07:48:13 +01001686 " Jumping to a fold should open the fold
1687 call setline(1, ['', '', 'one', 'two', 'three'])
1688 set foldenable
1689 2,$fold
1690 call feedkeys(')', 'xt')
1691 call assert_equal(3, line('.'))
1692 call assert_equal(1, foldlevel('.'))
1693 call assert_equal(-1, foldclosed('.'))
1694 set foldenable&
1695
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001696 " clean up
1697 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02001698endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001699
Bram Moolenaar1671f442020-03-10 07:48:13 +01001700" Test for { and } paragraph movements
1701func Test_normal29_brace()
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001702 let text =<< trim [DATA]
Bram Moolenaare7eb9272019-06-24 00:58:07 +02001703 A paragraph begins after each empty line, and also at each of a set of
1704 paragraph macros, specified by the pairs of characters in the 'paragraphs'
1705 option. The default is "IPLPPPQPP TPHPLIPpLpItpplpipbp", which corresponds to
1706 the macros ".IP", ".LP", etc. (These are nroff macros, so the dot must be in
1707 the first column). A section boundary is also a paragraph boundary.
1708 Note that a blank line (only containing white space) is NOT a paragraph
1709 boundary.
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001710
1711
Bram Moolenaare7eb9272019-06-24 00:58:07 +02001712 Also note that this does not include a '{' or '}' in the first column. When
1713 the '{' flag is in 'cpoptions' then '{' in the first column is used as a
1714 paragraph boundary |posix|.
1715 {
1716 This is no paragraph
1717 unless the '{' is set
1718 in 'cpoptions'
1719 }
1720 .IP
1721 The nroff macros IP separates a paragraph
1722 That means, it must be a '.'
1723 followed by IP
1724 .LPIt does not matter, if afterwards some
1725 more characters follow.
1726 .SHAlso section boundaries from the nroff
1727 macros terminate a paragraph. That means
1728 a character like this:
1729 .NH
1730 End of text here
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001731 [DATA]
1732
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001733 new
1734 call append(0, text)
1735 1
1736 norm! 0d2}
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001737
1738 let expected =<< trim [DATA]
Bram Moolenaare7eb9272019-06-24 00:58:07 +02001739 .IP
1740 The nroff macros IP separates a paragraph
1741 That means, it must be a '.'
1742 followed by IP
1743 .LPIt does not matter, if afterwards some
1744 more characters follow.
1745 .SHAlso section boundaries from the nroff
1746 macros terminate a paragraph. That means
1747 a character like this:
1748 .NH
1749 End of text here
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001750
1751 [DATA]
1752 call assert_equal(expected, getline(1, '$'))
1753
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001754 norm! 0d}
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001755
1756 let expected =<< trim [DATA]
Bram Moolenaare7eb9272019-06-24 00:58:07 +02001757 .LPIt does not matter, if afterwards some
1758 more characters follow.
1759 .SHAlso section boundaries from the nroff
1760 macros terminate a paragraph. That means
1761 a character like this:
1762 .NH
1763 End of text here
1764
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001765 [DATA]
1766 call assert_equal(expected, getline(1, '$'))
1767
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001768 $
1769 norm! d{
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001770
1771 let expected =<< trim [DATA]
Bram Moolenaare7eb9272019-06-24 00:58:07 +02001772 .LPIt does not matter, if afterwards some
1773 more characters follow.
1774 .SHAlso section boundaries from the nroff
1775 macros terminate a paragraph. That means
1776 a character like this:
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001777
1778 [DATA]
1779 call assert_equal(expected, getline(1, '$'))
1780
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001781 norm! d{
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001782
1783 let expected =<< trim [DATA]
Bram Moolenaare7eb9272019-06-24 00:58:07 +02001784 .LPIt does not matter, if afterwards some
1785 more characters follow.
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001786
1787 [DATA]
1788 call assert_equal(expected, getline(1, '$'))
1789
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001790 " Test with { in cpooptions
1791 %d
1792 call append(0, text)
1793 set cpo+={
1794 1
1795 norm! 0d2}
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001796
1797 let expected =<< trim [DATA]
Bram Moolenaare7eb9272019-06-24 00:58:07 +02001798 {
1799 This is no paragraph
1800 unless the '{' is set
1801 in 'cpoptions'
1802 }
1803 .IP
1804 The nroff macros IP separates a paragraph
1805 That means, it must be a '.'
1806 followed by IP
1807 .LPIt does not matter, if afterwards some
1808 more characters follow.
1809 .SHAlso section boundaries from the nroff
1810 macros terminate a paragraph. That means
1811 a character like this:
1812 .NH
1813 End of text here
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001814
1815 [DATA]
1816 call assert_equal(expected, getline(1, '$'))
1817
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001818 $
1819 norm! d}
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001820
1821 let expected =<< trim [DATA]
Bram Moolenaare7eb9272019-06-24 00:58:07 +02001822 {
1823 This is no paragraph
1824 unless the '{' is set
1825 in 'cpoptions'
1826 }
1827 .IP
1828 The nroff macros IP separates a paragraph
1829 That means, it must be a '.'
1830 followed by IP
1831 .LPIt does not matter, if afterwards some
1832 more characters follow.
1833 .SHAlso section boundaries from the nroff
1834 macros terminate a paragraph. That means
1835 a character like this:
1836 .NH
1837 End of text here
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001838
1839 [DATA]
1840 call assert_equal(expected, getline(1, '$'))
1841
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001842 norm! gg}
1843 norm! d5}
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001844
1845 let expected =<< trim [DATA]
Bram Moolenaare7eb9272019-06-24 00:58:07 +02001846 {
1847 This is no paragraph
1848 unless the '{' is set
1849 in 'cpoptions'
1850 }
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001851
1852 [DATA]
1853 call assert_equal(expected, getline(1, '$'))
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001854
Bram Moolenaar1671f442020-03-10 07:48:13 +01001855 " Jumping to a fold should open the fold
1856 %d
1857 call setline(1, ['', 'one', 'two', ''])
1858 set foldenable
1859 2,$fold
1860 call feedkeys('}', 'xt')
1861 call assert_equal(4, line('.'))
1862 call assert_equal(1, foldlevel('.'))
1863 call assert_equal(-1, foldclosed('.'))
1864 set foldenable&
1865
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001866 " clean up
1867 set cpo-={
1868 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02001869endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001870
Bram Moolenaar8a9bc952020-10-02 18:48:07 +02001871" Test for section movements
1872func Test_normal_section()
1873 new
1874 let lines =<< trim [END]
1875 int foo()
1876 {
1877 if (1)
1878 {
1879 a = 1;
1880 }
1881 }
1882 [END]
1883 call setline(1, lines)
1884
1885 " jumping to a folded line using [[ should open the fold
1886 2,3fold
1887 call cursor(5, 1)
1888 call feedkeys("[[", 'xt')
1889 call assert_equal(2, line('.'))
1890 call assert_equal(-1, foldclosedend(line('.')))
1891
1892 close!
1893endfunc
1894
Bram Moolenaard1ad99b2020-10-04 16:16:54 +02001895" Test for changing case using u, U, gu, gU and ~ (tilde) commands
Bram Moolenaar1671f442020-03-10 07:48:13 +01001896func Test_normal30_changecase()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001897 new
1898 call append(0, 'This is a simple test: äüöß')
1899 norm! 1ggVu
1900 call assert_equal('this is a simple test: äüöß', getline('.'))
1901 norm! VU
1902 call assert_equal('THIS IS A SIMPLE TEST: ÄÜÖSS', getline('.'))
1903 norm! guu
1904 call assert_equal('this is a simple test: äüöss', getline('.'))
1905 norm! gUgU
1906 call assert_equal('THIS IS A SIMPLE TEST: ÄÜÖSS', getline('.'))
1907 norm! gugu
1908 call assert_equal('this is a simple test: äüöss', getline('.'))
1909 norm! gUU
1910 call assert_equal('THIS IS A SIMPLE TEST: ÄÜÖSS', getline('.'))
1911 norm! 010~
1912 call assert_equal('this is a SIMPLE TEST: ÄÜÖSS', getline('.'))
1913 norm! V~
1914 call assert_equal('THIS IS A simple test: äüöss', getline('.'))
Bram Moolenaard1ad99b2020-10-04 16:16:54 +02001915 call assert_beeps('norm! c~')
1916 %d
1917 call assert_beeps('norm! ~')
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001918
Bram Moolenaar1671f442020-03-10 07:48:13 +01001919 " Test for changing case across lines using 'whichwrap'
1920 call setline(1, ['aaaaaa', 'aaaaaa'])
1921 normal! gg10~
1922 call assert_equal(['AAAAAA', 'aaaaaa'], getline(1, 2))
1923 set whichwrap+=~
1924 normal! gg10~
1925 call assert_equal(['aaaaaa', 'AAAAaa'], getline(1, 2))
1926 set whichwrap&
1927
1928 " clean up
1929 bw!
1930endfunc
1931
1932" Turkish ASCII turns to multi-byte. On some systems Turkish locale
1933" is available but toupper()/tolower() don't do the right thing.
1934func Test_normal_changecase_turkish()
1935 new
Bram Moolenaarf1c118b2018-09-03 22:08:10 +02001936 try
1937 lang tr_TR.UTF-8
1938 set casemap=
1939 let iupper = toupper('i')
1940 if iupper == "\u0130"
Bram Moolenaar9f4de1f2017-04-08 19:39:43 +02001941 call setline(1, 'iI')
1942 1normal gUU
1943 call assert_equal("\u0130I", getline(1))
1944 call assert_equal("\u0130I", toupper("iI"))
Bram Moolenaar3317d5e2017-04-08 19:12:06 +02001945
Bram Moolenaar9f4de1f2017-04-08 19:39:43 +02001946 call setline(1, 'iI')
1947 1normal guu
1948 call assert_equal("i\u0131", getline(1))
1949 call assert_equal("i\u0131", tolower("iI"))
Bram Moolenaarf1c118b2018-09-03 22:08:10 +02001950 elseif iupper == "I"
Bram Moolenaar1cc48202017-04-09 13:41:59 +02001951 call setline(1, 'iI')
1952 1normal gUU
1953 call assert_equal("II", getline(1))
1954 call assert_equal("II", toupper("iI"))
1955
1956 call setline(1, 'iI')
1957 1normal guu
1958 call assert_equal("ii", getline(1))
1959 call assert_equal("ii", tolower("iI"))
Bram Moolenaarf1c118b2018-09-03 22:08:10 +02001960 else
1961 call assert_true(false, "expected toupper('i') to be either 'I' or '\u0130'")
1962 endif
1963 set casemap&
1964 call setline(1, 'iI')
1965 1normal gUU
1966 call assert_equal("II", getline(1))
1967 call assert_equal("II", toupper("iI"))
Bram Moolenaar1cc48202017-04-09 13:41:59 +02001968
Bram Moolenaarf1c118b2018-09-03 22:08:10 +02001969 call setline(1, 'iI')
1970 1normal guu
1971 call assert_equal("ii", getline(1))
1972 call assert_equal("ii", tolower("iI"))
1973
1974 lang en_US.UTF-8
1975 catch /E197:/
1976 " can't use Turkish locale
1977 throw 'Skipped: Turkish locale not available'
1978 endtry
Bram Moolenaar1671f442020-03-10 07:48:13 +01001979 close!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02001980endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001981
Bram Moolenaar1671f442020-03-10 07:48:13 +01001982" Test for r (replace) command
1983func Test_normal31_r_cmd()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001984 new
1985 call append(0, 'This is a simple test: abcd')
1986 exe "norm! 1gg$r\<cr>"
1987 call assert_equal(['This is a simple test: abc', '', ''], getline(1,'$'))
1988 exe "norm! 1gg2wlr\<cr>"
1989 call assert_equal(['This is a', 'simple test: abc', '', ''], getline(1,'$'))
1990 exe "norm! 2gg0W5r\<cr>"
1991 call assert_equal(['This is a', 'simple ', ' abc', '', ''], getline('1', '$'))
1992 set autoindent
1993 call setline(2, ['simple test: abc', ''])
1994 exe "norm! 2gg0W5r\<cr>"
1995 call assert_equal(['This is a', 'simple ', 'abc', '', '', ''], getline('1', '$'))
1996 exe "norm! 1ggVr\<cr>"
1997 call assert_equal('^M^M^M^M^M^M^M^M^M', strtrans(getline(1)))
1998 call setline(1, 'This is a')
1999 exe "norm! 1gg05rf"
2000 call assert_equal('fffffis a', getline(1))
2001
Bram Moolenaar1671f442020-03-10 07:48:13 +01002002 " When replacing characters, copy characters from above and below lines
2003 " using CTRL-Y and CTRL-E.
2004 " Different code paths are used for utf-8 and latin1 encodings
2005 set showmatch
2006 for enc in ['latin1', 'utf-8']
2007 enew!
2008 let &encoding = enc
2009 call setline(1, [' {a}', 'xxxxxxxxxx', ' [b]'])
2010 exe "norm! 2gg5r\<C-Y>l5r\<C-E>"
2011 call assert_equal(' {a}x [b]x', getline(2))
2012 endfor
2013 set showmatch&
2014
2015 " r command should fail in operator pending mode
2016 call assert_beeps('normal! cr')
2017
Bram Moolenaar004a6782020-04-11 17:09:31 +02002018 " replace a tab character in visual mode
2019 %d
2020 call setline(1, ["a\tb", "c\td", "e\tf"])
2021 normal gglvjjrx
2022 call assert_equal(['axx', 'xxx', 'xxf'], getline(1, '$'))
2023
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002024 " clean up
2025 set noautoindent
2026 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002027endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002028
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01002029" Test for g*, g#
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01002030func Test_normal32_g_cmd1()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002031 new
2032 call append(0, ['abc.x_foo', 'x_foobar.abc'])
2033 1
2034 norm! $g*
2035 call assert_equal('x_foo', @/)
2036 call assert_equal('x_foobar.abc', getline('.'))
2037 norm! $g#
2038 call assert_equal('abc', @/)
2039 call assert_equal('abc.x_foo', getline('.'))
2040
2041 " clean up
2042 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002043endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002044
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01002045" Test for g`, g;, g,, g&, gv, gk, gj, gJ, g0, g^, g_, gm, g$, gM, g CTRL-G,
2046" gi and gI commands
Bram Moolenaar1671f442020-03-10 07:48:13 +01002047func Test_normal33_g_cmd2()
Bram Moolenaar004a6782020-04-11 17:09:31 +02002048 CheckFeature jumplist
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002049 call Setup_NewWindow()
2050 " Test for g`
2051 clearjumps
2052 norm! ma10j
2053 let a=execute(':jumps')
2054 " empty jumplist
2055 call assert_equal('>', a[-1:])
2056 norm! g`a
2057 call assert_equal('>', a[-1:])
2058 call assert_equal(1, line('.'))
2059 call assert_equal('1', getline('.'))
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01002060 call cursor(10, 1)
2061 norm! g'a
2062 call assert_equal('>', a[-1:])
2063 call assert_equal(1, line('.'))
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002064
2065 " Test for g; and g,
2066 norm! g;
2067 " there is only one change in the changelist
2068 " currently, when we setup the window
2069 call assert_equal(2, line('.'))
Bram Moolenaare2e40752020-09-04 21:18:46 +02002070 call assert_fails(':norm! g;', 'E662:')
2071 call assert_fails(':norm! g,', 'E663:')
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002072 let &ul=&ul
2073 call append('$', ['a', 'b', 'c', 'd'])
2074 let &ul=&ul
2075 call append('$', ['Z', 'Y', 'X', 'W'])
2076 let a = execute(':changes')
2077 call assert_match('2\s\+0\s\+2', a)
2078 call assert_match('101\s\+0\s\+a', a)
2079 call assert_match('105\s\+0\s\+Z', a)
2080 norm! 3g;
2081 call assert_equal(2, line('.'))
2082 norm! 2g,
2083 call assert_equal(105, line('.'))
2084
2085 " Test for g& - global substitute
2086 %d
2087 call setline(1, range(1,10))
2088 call append('$', ['a', 'b', 'c', 'd'])
2089 $s/\w/&&/g
2090 exe "norm! /[1-8]\<cr>"
2091 norm! g&
2092 call assert_equal(['11', '22', '33', '44', '55', '66', '77', '88', '9', '110', 'a', 'b', 'c', 'dd'], getline(1, '$'))
2093
Bram Moolenaar1671f442020-03-10 07:48:13 +01002094 " Jumping to a fold using gg should open the fold
2095 set foldenable
2096 set foldopen+=jump
2097 5,8fold
2098 call feedkeys('6gg', 'xt')
2099 call assert_equal(1, foldlevel('.'))
2100 call assert_equal(-1, foldclosed('.'))
2101 set foldopen-=jump
2102 set foldenable&
2103
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002104 " Test for gv
2105 %d
2106 call append('$', repeat(['abcdefgh'], 8))
2107 exe "norm! 2gg02l\<c-v>2j2ly"
2108 call assert_equal(['cde', 'cde', 'cde'], getreg(0, 1, 1))
2109 " in visual mode, gv swaps current and last selected region
2110 exe "norm! G0\<c-v>4k4lgvd"
2111 call assert_equal(['', 'abfgh', 'abfgh', 'abfgh', 'abcdefgh', 'abcdefgh', 'abcdefgh', 'abcdefgh', 'abcdefgh'], getline(1,'$'))
2112 exe "norm! G0\<c-v>4k4ly"
2113 exe "norm! gvood"
2114 call assert_equal(['', 'abfgh', 'abfgh', 'abfgh', 'fgh', 'fgh', 'fgh', 'fgh', 'fgh'], getline(1,'$'))
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01002115 " gv cannot be used in operator pending mode
2116 call assert_beeps('normal! cgv')
2117 " gv should beep without a previously selected visual area
2118 new
2119 call assert_beeps('normal! gv')
2120 close
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002121
2122 " Test for gk/gj
2123 %d
2124 15vsp
2125 set wrap listchars= sbr=
2126 let lineA='abcdefghijklmnopqrstuvwxyz'
2127 let lineB='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'
Bram Moolenaar8b530c12019-10-28 02:13:05 +01002128 let lineC='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz01234567890123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002129 $put =lineA
2130 $put =lineB
2131
2132 norm! 3gg0dgk
2133 call assert_equal(['', 'abcdefghijklmno', '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'], getline(1, '$'))
2134 set nu
2135 norm! 3gg0gjdgj
2136 call assert_equal(['', 'abcdefghijklmno', '0123456789AMNOPQRSTUVWXYZ'], getline(1,'$'))
2137
2138 " Test for gJ
2139 norm! 2gggJ
2140 call assert_equal(['', 'abcdefghijklmno0123456789AMNOPQRSTUVWXYZ'], getline(1,'$'))
2141 call assert_equal(16, col('.'))
2142 " shouldn't do anything
2143 norm! 10gJ
2144 call assert_equal(1, col('.'))
2145
2146 " Test for g0 g^ gm g$
2147 exe "norm! 2gg0gji "
2148 call assert_equal(['', 'abcdefghijk lmno0123456789AMNOPQRSTUVWXYZ'], getline(1,'$'))
2149 norm! g0yl
2150 call assert_equal(12, col('.'))
2151 call assert_equal(' ', getreg(0))
2152 norm! g$yl
2153 call assert_equal(22, col('.'))
2154 call assert_equal('3', getreg(0))
2155 norm! gmyl
2156 call assert_equal(17, col('.'))
2157 call assert_equal('n', getreg(0))
2158 norm! g^yl
2159 call assert_equal(15, col('.'))
2160 call assert_equal('l', getreg(0))
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01002161 call assert_beeps('normal 5g$')
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002162
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01002163 " Test for g_
2164 call assert_beeps('normal! 100g_')
2165 call setline(2, [' foo ', ' foobar '])
2166 normal! 2ggg_
2167 call assert_equal(5, col('.'))
2168 normal! 2g_
2169 call assert_equal(8, col('.'))
2170
2171 norm! 2ggdG
Bram Moolenaar8b530c12019-10-28 02:13:05 +01002172 $put =lineC
2173
2174 " Test for gM
2175 norm! gMyl
2176 call assert_equal(73, col('.'))
2177 call assert_equal('0', getreg(0))
2178 " Test for 20gM
2179 norm! 20gMyl
2180 call assert_equal(29, col('.'))
2181 call assert_equal('S', getreg(0))
2182 " Test for 60gM
2183 norm! 60gMyl
2184 call assert_equal(87, col('.'))
2185 call assert_equal('E', getreg(0))
2186
2187 " Test for g Ctrl-G
2188 set ff=unix
2189 let a=execute(":norm! g\<c-g>")
2190 call assert_match('Col 87 of 144; Line 2 of 2; Word 1 of 1; Byte 88 of 146', a)
2191
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002192 " Test for gI
2193 norm! gIfoo
Bram Moolenaar8b530c12019-10-28 02:13:05 +01002194 call assert_equal(['', 'foo0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz01234567890123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'], getline(1,'$'))
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002195
2196 " Test for gi
2197 wincmd c
2198 %d
2199 set tw=0
2200 call setline(1, ['foobar', 'new line'])
2201 norm! A next word
2202 $put ='third line'
2203 norm! gi another word
2204 call assert_equal(['foobar next word another word', 'new line', 'third line'], getline(1,'$'))
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01002205 call setline(1, 'foobar')
2206 normal! Ggifirst line
2207 call assert_equal('foobarfirst line', getline(1))
2208 " Test gi in 'virtualedit' mode with cursor after the end of the line
2209 set virtualedit=all
2210 call setline(1, 'foo')
2211 exe "normal! Abar\<Right>\<Right>\<Right>\<Right>"
2212 call setline(1, 'foo')
2213 normal! Ggifirst line
2214 call assert_equal('foo first line', getline(1))
2215 set virtualedit&
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002216
Bram Moolenaar1671f442020-03-10 07:48:13 +01002217 " Test for aboring a g command using CTRL-\ CTRL-G
2218 exe "normal! g\<C-\>\<C-G>"
2219 call assert_equal('foo first line', getline('.'))
2220
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002221 " clean up
2222 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002223endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002224
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01002225" Test for g CTRL-G
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01002226func Test_g_ctrl_g()
Bram Moolenaar05295832018-08-24 22:07:58 +02002227 new
2228
2229 let a = execute(":norm! g\<c-g>")
2230 call assert_equal("\n--No lines in buffer--", a)
2231
Bram Moolenaar1671f442020-03-10 07:48:13 +01002232 " Test for CTRL-G (same as :file)
2233 let a = execute(":norm! \<c-g>")
2234 call assert_equal("\n\n\"[No Name]\" --No lines in buffer--", a)
2235
Bram Moolenaar05295832018-08-24 22:07:58 +02002236 call setline(1, ['first line', 'second line'])
2237
2238 " Test g CTRL-g with dos, mac and unix file type.
2239 norm! gojll
2240 set ff=dos
2241 let a = execute(":norm! g\<c-g>")
2242 call assert_equal("\nCol 3 of 11; Line 2 of 2; Word 3 of 4; Byte 15 of 25", a)
2243
2244 set ff=mac
2245 let a = execute(":norm! g\<c-g>")
2246 call assert_equal("\nCol 3 of 11; Line 2 of 2; Word 3 of 4; Byte 14 of 23", a)
2247
2248 set ff=unix
2249 let a = execute(":norm! g\<c-g>")
2250 call assert_equal("\nCol 3 of 11; Line 2 of 2; Word 3 of 4; Byte 14 of 23", a)
2251
2252 " Test g CTRL-g in visual mode (v)
2253 let a = execute(":norm! gojllvlg\<c-g>")
2254 call assert_equal("\nSelected 1 of 2 Lines; 1 of 4 Words; 2 of 23 Bytes", a)
2255
2256 " Test g CTRL-g in visual mode (CTRL-V) with end col > start col
2257 let a = execute(":norm! \<Esc>gojll\<C-V>kllg\<c-g>")
2258 call assert_equal("\nSelected 3 Cols; 2 of 2 Lines; 2 of 4 Words; 6 of 23 Bytes", a)
2259
2260 " Test g_CTRL-g in visual mode (CTRL-V) with end col < start col
2261 let a = execute(":norm! \<Esc>goll\<C-V>jhhg\<c-g>")
2262 call assert_equal("\nSelected 3 Cols; 2 of 2 Lines; 2 of 4 Words; 6 of 23 Bytes", a)
2263
2264 " Test g CTRL-g in visual mode (CTRL-V) with end_vcol being MAXCOL
2265 let a = execute(":norm! \<Esc>gojll\<C-V>k$g\<c-g>")
2266 call assert_equal("\nSelected 2 of 2 Lines; 4 of 4 Words; 17 of 23 Bytes", a)
2267
2268 " There should be one byte less with noeol
2269 set bin noeol
2270 let a = execute(":norm! \<Esc>gog\<c-g>")
2271 call assert_equal("\nCol 1 of 10; Line 1 of 2; Word 1 of 4; Char 1 of 23; Byte 1 of 22", a)
2272 set bin & eol&
2273
Bram Moolenaar30276f22019-01-24 17:59:39 +01002274 call setline(1, ['Français', '日本語'])
Bram Moolenaar05295832018-08-24 22:07:58 +02002275
Bram Moolenaar30276f22019-01-24 17:59:39 +01002276 let a = execute(":norm! \<Esc>gojlg\<c-g>")
2277 call assert_equal("\nCol 4-3 of 9-6; Line 2 of 2; Word 2 of 2; Char 11 of 13; Byte 16 of 20", a)
Bram Moolenaar05295832018-08-24 22:07:58 +02002278
Bram Moolenaar30276f22019-01-24 17:59:39 +01002279 let a = execute(":norm! \<Esc>gojvlg\<c-g>")
2280 call assert_equal("\nSelected 1 of 2 Lines; 1 of 2 Words; 2 of 13 Chars; 6 of 20 Bytes", a)
Bram Moolenaar05295832018-08-24 22:07:58 +02002281
Bram Moolenaar30276f22019-01-24 17:59:39 +01002282 let a = execute(":norm! \<Esc>goll\<c-v>jlg\<c-g>")
2283 call assert_equal("\nSelected 4 Cols; 2 of 2 Lines; 2 of 2 Words; 6 of 13 Chars; 11 of 20 Bytes", a)
Bram Moolenaar05295832018-08-24 22:07:58 +02002284
Bram Moolenaar30276f22019-01-24 17:59:39 +01002285 set fenc=utf8 bomb
2286 let a = execute(":norm! \<Esc>gojlg\<c-g>")
2287 call assert_equal("\nCol 4-3 of 9-6; Line 2 of 2; Word 2 of 2; Char 11 of 13; Byte 16 of 20(+3 for BOM)", a)
Bram Moolenaar05295832018-08-24 22:07:58 +02002288
Bram Moolenaar30276f22019-01-24 17:59:39 +01002289 set fenc=utf16 bomb
2290 let a = execute(":norm! g\<c-g>")
2291 call assert_equal("\nCol 4-3 of 9-6; Line 2 of 2; Word 2 of 2; Char 11 of 13; Byte 16 of 20(+2 for BOM)", a)
Bram Moolenaar05295832018-08-24 22:07:58 +02002292
Bram Moolenaar30276f22019-01-24 17:59:39 +01002293 set fenc=utf32 bomb
2294 let a = execute(":norm! g\<c-g>")
2295 call assert_equal("\nCol 4-3 of 9-6; Line 2 of 2; Word 2 of 2; Char 11 of 13; Byte 16 of 20(+4 for BOM)", a)
Bram Moolenaar05295832018-08-24 22:07:58 +02002296
Bram Moolenaar30276f22019-01-24 17:59:39 +01002297 set fenc& bomb&
Bram Moolenaar05295832018-08-24 22:07:58 +02002298
2299 set ff&
2300 bwipe!
2301endfunc
2302
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01002303" Test for g8
Bram Moolenaar1671f442020-03-10 07:48:13 +01002304func Test_normal34_g_cmd3()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002305 new
Bram Moolenaar395b6ba2017-04-07 20:09:51 +02002306 let a=execute(':norm! 1G0g8')
2307 call assert_equal("\nNUL", a)
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002308
Bram Moolenaar395b6ba2017-04-07 20:09:51 +02002309 call setline(1, 'abcdefghijklmnopqrstuvwxyzäüö')
2310 let a=execute(':norm! 1G$g8')
2311 call assert_equal("\nc3 b6 ", a)
2312
2313 call setline(1, "a\u0302")
2314 let a=execute(':norm! 1G0g8')
2315 call assert_equal("\n61 + cc 82 ", a)
2316
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002317 " clean up
2318 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002319endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002320
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01002321" Test 8g8 which finds invalid utf8 at or after the cursor.
Bram Moolenaar395b6ba2017-04-07 20:09:51 +02002322func Test_normal_8g8()
Bram Moolenaar395b6ba2017-04-07 20:09:51 +02002323 new
2324
Bram Moolenaar395b6ba2017-04-07 20:09:51 +02002325 " With invalid byte.
2326 call setline(1, "___\xff___")
2327 norm! 1G08g8g
2328 call assert_equal([0, 1, 4, 0, 1], getcurpos())
2329
2330 " With invalid byte before the cursor.
2331 call setline(1, "___\xff___")
2332 norm! 1G$h8g8g
2333 call assert_equal([0, 1, 6, 0, 9], getcurpos())
2334
2335 " With truncated sequence.
2336 call setline(1, "___\xE2\x82___")
2337 norm! 1G08g8g
2338 call assert_equal([0, 1, 4, 0, 1], getcurpos())
2339
2340 " With overlong sequence.
2341 call setline(1, "___\xF0\x82\x82\xAC___")
2342 norm! 1G08g8g
2343 call assert_equal([0, 1, 4, 0, 1], getcurpos())
2344
2345 " With valid utf8.
2346 call setline(1, "café")
2347 norm! 1G08g8
2348 call assert_equal([0, 1, 1, 0, 1], getcurpos())
2349
2350 bw!
2351endfunc
2352
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01002353" Test for g<
Bram Moolenaar1671f442020-03-10 07:48:13 +01002354func Test_normal35_g_cmd4()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002355 " Cannot capture its output,
2356 " probably a bug, therefore, test disabled:
Bram Moolenaar31845092016-09-05 22:58:31 +02002357 throw "Skipped: output of g< can't be tested currently"
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002358 echo "a\nb\nc\nd"
2359 let b=execute(':norm! g<')
2360 call assert_true(!empty(b), 'failed `execute(g<)`')
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002361endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002362
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01002363" Test for gp gP go
Bram Moolenaar1671f442020-03-10 07:48:13 +01002364func Test_normal36_g_cmd5()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002365 new
2366 call append(0, 'abcdefghijklmnopqrstuvwxyz')
Bram Moolenaar0913a102016-09-03 19:11:59 +02002367 set ff=unix
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002368 " Test for gp gP
2369 call append(1, range(1,10))
2370 1
2371 norm! 1yy
2372 3
2373 norm! gp
2374 call assert_equal([0, 5, 1, 0, 1], getcurpos())
2375 $
2376 norm! gP
2377 call assert_equal([0, 14, 1, 0, 1], getcurpos())
2378
2379 " Test for go
2380 norm! 26go
2381 call assert_equal([0, 1, 26, 0, 26], getcurpos())
2382 norm! 27go
2383 call assert_equal([0, 1, 26, 0, 26], getcurpos())
2384 norm! 28go
2385 call assert_equal([0, 2, 1, 0, 1], getcurpos())
2386 set ff=dos
2387 norm! 29go
2388 call assert_equal([0, 2, 1, 0, 1], getcurpos())
2389 set ff=unix
2390 norm! gg0
2391 norm! 101go
2392 call assert_equal([0, 13, 26, 0, 26], getcurpos())
2393 norm! 103go
2394 call assert_equal([0, 14, 1, 0, 1], getcurpos())
2395 " count > buffer content
2396 norm! 120go
2397 call assert_equal([0, 14, 1, 0, 2147483647], getcurpos())
2398 " clean up
2399 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002400endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002401
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01002402" Test for gt and gT
Bram Moolenaar1671f442020-03-10 07:48:13 +01002403func Test_normal37_g_cmd6()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002404 tabnew 1.txt
2405 tabnew 2.txt
2406 tabnew 3.txt
2407 norm! 1gt
2408 call assert_equal(1, tabpagenr())
2409 norm! 3gt
2410 call assert_equal(3, tabpagenr())
2411 norm! 1gT
2412 " count gT goes not to the absolute tabpagenumber
2413 " but, but goes to the count previous tabpagenumber
2414 call assert_equal(2, tabpagenr())
2415 " wrap around
2416 norm! 3gT
2417 call assert_equal(3, tabpagenr())
2418 " gt does not wrap around
2419 norm! 5gt
2420 call assert_equal(3, tabpagenr())
2421
2422 for i in range(3)
2423 tabclose
2424 endfor
2425 " clean up
Bram Moolenaarbc2b71d2020-02-17 21:33:30 +01002426 call assert_fails(':tabclose', 'E784:')
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002427endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002428
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01002429" Test for <Home> and <C-Home> key
Bram Moolenaar1671f442020-03-10 07:48:13 +01002430func Test_normal38_nvhome()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002431 new
2432 call setline(1, range(10))
2433 $
2434 setl et sw=2
2435 norm! V10>$
2436 " count is ignored
2437 exe "norm! 10\<home>"
2438 call assert_equal(1, col('.'))
2439 exe "norm! \<home>"
2440 call assert_equal([0, 10, 1, 0, 1], getcurpos())
2441 exe "norm! 5\<c-home>"
2442 call assert_equal([0, 5, 1, 0, 1], getcurpos())
2443 exe "norm! \<c-home>"
2444 call assert_equal([0, 1, 1, 0, 1], getcurpos())
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01002445 exe "norm! G\<c-kHome>"
2446 call assert_equal([0, 1, 1, 0, 1], getcurpos())
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002447
2448 " clean up
2449 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002450endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002451
Bram Moolenaar1671f442020-03-10 07:48:13 +01002452" Test for <End> and <C-End> keys
2453func Test_normal_nvend()
2454 new
2455 call setline(1, map(range(1, 10), '"line" .. v:val'))
2456 exe "normal! \<End>"
2457 call assert_equal(5, col('.'))
2458 exe "normal! 4\<End>"
2459 call assert_equal([4, 5], [line('.'), col('.')])
2460 exe "normal! \<C-End>"
2461 call assert_equal([10, 6], [line('.'), col('.')])
2462 close!
2463endfunc
2464
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01002465" Test for cw cW ce
Bram Moolenaar1671f442020-03-10 07:48:13 +01002466func Test_normal39_cw()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002467 " Test for cw and cW on whitespace
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002468 new
2469 set tw=0
2470 call append(0, 'here are some words')
2471 norm! 1gg0elcwZZZ
2472 call assert_equal('hereZZZare some words', getline('.'))
2473 norm! 1gg0elcWYYY
2474 call assert_equal('hereZZZareYYYsome words', getline('.'))
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002475 norm! 2gg0cwfoo
2476 call assert_equal('foo', getline('.'))
2477
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01002478 call setline(1, 'one; two')
2479 call cursor(1, 1)
2480 call feedkeys('cwvim', 'xt')
2481 call assert_equal('vim; two', getline(1))
2482 call feedkeys('0cWone', 'xt')
2483 call assert_equal('one two', getline(1))
2484 "When cursor is at the end of a word 'ce' will change until the end of the
2485 "next word, but 'cw' will change only one character
2486 call setline(1, 'one two')
2487 call feedkeys('0ecwce', 'xt')
2488 call assert_equal('once two', getline(1))
2489 call setline(1, 'one two')
2490 call feedkeys('0ecely', 'xt')
2491 call assert_equal('only', getline(1))
2492
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002493 " clean up
2494 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002495endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002496
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01002497" Test for CTRL-\ commands
Bram Moolenaar1671f442020-03-10 07:48:13 +01002498func Test_normal40_ctrl_bsl()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002499 new
2500 call append(0, 'here are some words')
2501 exe "norm! 1gg0a\<C-\>\<C-N>"
2502 call assert_equal('n', mode())
2503 call assert_equal(1, col('.'))
2504 call assert_equal('', visualmode())
2505 exe "norm! 1gg0viw\<C-\>\<C-N>"
2506 call assert_equal('n', mode())
2507 call assert_equal(4, col('.'))
2508 exe "norm! 1gg0a\<C-\>\<C-G>"
2509 call assert_equal('n', mode())
2510 call assert_equal(1, col('.'))
2511 "imap <buffer> , <c-\><c-n>
2512 set im
2513 exe ":norm! \<c-\>\<c-n>dw"
2514 set noim
2515 call assert_equal('are some words', getline(1))
2516 call assert_false(&insertmode)
Bram Moolenaar1671f442020-03-10 07:48:13 +01002517 call assert_beeps("normal! \<C-\>\<C-A>", 'xt')
2518
2519 " Using CTRL-\ CTRL-N in cmd window should close the window
2520 call feedkeys("q:\<C-\>\<C-N>", 'xt')
2521 call assert_equal('', getcmdwintype())
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002522
2523 " clean up
2524 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002525endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002526
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01002527" Test for <c-r>=, <c-r><c-r>= and <c-r><c-o>= in insert mode
Bram Moolenaar1671f442020-03-10 07:48:13 +01002528func Test_normal41_insert_reg()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002529 new
2530 set sts=2 sw=2 ts=8 tw=0
2531 call append(0, ["aaa\tbbb\tccc", '', '', ''])
2532 let a=getline(1)
2533 norm! 2gg0
2534 exe "norm! a\<c-r>=a\<cr>"
2535 norm! 3gg0
2536 exe "norm! a\<c-r>\<c-r>=a\<cr>"
2537 norm! 4gg0
2538 exe "norm! a\<c-r>\<c-o>=a\<cr>"
2539 call assert_equal(['aaa bbb ccc', 'aaa bbb ccc', 'aaa bbb ccc', 'aaa bbb ccc', ''], getline(1, '$'))
2540
2541 " clean up
2542 set sts=0 sw=8 ts=8
Bram Moolenaar31845092016-09-05 22:58:31 +02002543 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002544endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002545
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01002546" Test for Ctrl-D and Ctrl-U
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01002547func Test_normal42_halfpage()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002548 call Setup_NewWindow()
2549 call assert_equal(5, &scroll)
2550 exe "norm! \<c-d>"
2551 call assert_equal('6', getline('.'))
2552 exe "norm! 2\<c-d>"
2553 call assert_equal('8', getline('.'))
2554 call assert_equal(2, &scroll)
2555 set scroll=5
2556 exe "norm! \<c-u>"
2557 call assert_equal('3', getline('.'))
2558 1
2559 set scrolloff=5
2560 exe "norm! \<c-d>"
2561 call assert_equal('10', getline('.'))
2562 exe "norm! \<c-u>"
2563 call assert_equal('5', getline('.'))
2564 1
2565 set scrolloff=99
2566 exe "norm! \<c-d>"
2567 call assert_equal('10', getline('.'))
2568 set scrolloff=0
2569 100
2570 exe "norm! $\<c-u>"
2571 call assert_equal('95', getline('.'))
2572 call assert_equal([0, 95, 1, 0, 1], getcurpos())
2573 100
2574 set nostartofline
2575 exe "norm! $\<c-u>"
2576 call assert_equal('95', getline('.'))
2577 call assert_equal([0, 95, 2, 0, 2147483647], getcurpos())
2578 " cleanup
2579 set startofline
2580 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002581endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002582
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01002583func Test_normal45_drop()
Bram Moolenaar29495952018-02-12 22:49:00 +01002584 if !has('dnd')
Bram Moolenaarb48e96f2018-02-13 12:26:14 +01002585 " The ~ register does not exist
2586 call assert_beeps('norm! "~')
Bram Moolenaar29495952018-02-12 22:49:00 +01002587 return
2588 endif
2589
2590 " basic test for drag-n-drop
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002591 " unfortunately, without a gui, we can't really test much here,
2592 " so simply test that ~p fails (which uses the drop register)
2593 new
Bram Moolenaare2e40752020-09-04 21:18:46 +02002594 call assert_fails(':norm! "~p', 'E353:')
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002595 call assert_equal([], getreg('~', 1, 1))
2596 " the ~ register is read only
Bram Moolenaare2e40752020-09-04 21:18:46 +02002597 call assert_fails(':let @~="1"', 'E354:')
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002598 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002599endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002600
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01002601func Test_normal46_ignore()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002602 new
2603 " How to test this?
2604 " let's just for now test, that the buffer
2605 " does not change
2606 call feedkeys("\<c-s>", 't')
2607 call assert_equal([''], getline(1,'$'))
2608
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002609 " no valid commands
2610 exe "norm! \<char-0x100>"
2611 call assert_equal([''], getline(1,'$'))
2612
2613 exe "norm! ä"
2614 call assert_equal([''], getline(1,'$'))
2615
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002616 " clean up
2617 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002618endfunc
Bram Moolenaarc4a908e2016-09-08 23:35:30 +02002619
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01002620func Test_normal47_visual_buf_wipe()
Bram Moolenaarc4a908e2016-09-08 23:35:30 +02002621 " This was causing a crash or ml_get error.
2622 enew!
2623 call setline(1,'xxx')
2624 normal $
2625 new
2626 call setline(1, range(1,2))
2627 2
2628 exe "norm \<C-V>$"
2629 bw!
2630 norm yp
2631 set nomodified
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002632endfunc
2633
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01002634func Test_normal48_wincmd()
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002635 new
2636 exe "norm! \<c-w>c"
2637 call assert_equal(1, winnr('$'))
Bram Moolenaare2e40752020-09-04 21:18:46 +02002638 call assert_fails(":norm! \<c-w>c", 'E444:')
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002639endfunc
2640
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01002641func Test_normal49_counts()
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002642 new
2643 call setline(1, 'one two three four five six seven eight nine ten')
2644 1
2645 norm! 3d2w
2646 call assert_equal('seven eight nine ten', getline(1))
2647 bw!
2648endfunc
2649
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01002650func Test_normal50_commandline()
Bram Moolenaar004a6782020-04-11 17:09:31 +02002651 CheckFeature timers
2652 CheckFeature cmdline_hist
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002653 func! DoTimerWork(id)
2654 call assert_equal('[Command Line]', bufname(''))
2655 " should fail, with E11, but does fail with E23?
2656 "call feedkeys("\<c-^>", 'tm')
2657
2658 " should also fail with E11
Bram Moolenaare2e40752020-09-04 21:18:46 +02002659 call assert_fails(":wincmd p", 'E11:')
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002660 " return from commandline window
2661 call feedkeys("\<cr>")
2662 endfunc
2663
2664 let oldlang=v:lang
2665 lang C
2666 set updatetime=20
2667 call timer_start(100, 'DoTimerWork')
2668 try
2669 " throws E23, for whatever reason...
2670 call feedkeys('q:', 'x!')
2671 catch /E23/
2672 " no-op
2673 endtry
2674 " clean up
2675 set updatetime=4000
2676 exe "lang" oldlang
2677 bw!
2678endfunc
2679
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01002680func Test_normal51_FileChangedRO()
Bram Moolenaar004a6782020-04-11 17:09:31 +02002681 CheckFeature autocmd
Bram Moolenaare5f2a072017-02-01 22:31:49 +01002682 " Don't sleep after the warning message.
2683 call test_settime(1)
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002684 call writefile(['foo'], 'Xreadonly.log')
2685 new Xreadonly.log
2686 setl ro
2687 au FileChangedRO <buffer> :call feedkeys("\<c-^>", 'tix')
Bram Moolenaare2e40752020-09-04 21:18:46 +02002688 call assert_fails(":norm! Af", 'E788:')
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002689 call assert_equal(['foo'], getline(1,'$'))
2690 call assert_equal('Xreadonly.log', bufname(''))
2691
2692 " cleanup
Bram Moolenaare5f2a072017-02-01 22:31:49 +01002693 call test_settime(0)
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002694 bw!
2695 call delete("Xreadonly.log")
2696endfunc
2697
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01002698func Test_normal52_rl()
Bram Moolenaar004a6782020-04-11 17:09:31 +02002699 CheckFeature rightleft
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002700 new
2701 call setline(1, 'abcde fghij klmnopq')
2702 norm! 1gg$
2703 set rl
2704 call assert_equal(19, col('.'))
2705 call feedkeys('l', 'tx')
2706 call assert_equal(18, col('.'))
2707 call feedkeys('h', 'tx')
2708 call assert_equal(19, col('.'))
2709 call feedkeys("\<right>", 'tx')
2710 call assert_equal(18, col('.'))
Bram Moolenaar1671f442020-03-10 07:48:13 +01002711 call feedkeys("\<left>", 'tx')
2712 call assert_equal(19, col('.'))
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002713 call feedkeys("\<s-right>", 'tx')
2714 call assert_equal(13, col('.'))
2715 call feedkeys("\<c-right>", 'tx')
2716 call assert_equal(7, col('.'))
2717 call feedkeys("\<c-left>", 'tx')
2718 call assert_equal(13, col('.'))
2719 call feedkeys("\<s-left>", 'tx')
2720 call assert_equal(19, col('.'))
2721 call feedkeys("<<", 'tx')
2722 call assert_equal(' abcde fghij klmnopq',getline(1))
2723 call feedkeys(">>", 'tx')
2724 call assert_equal('abcde fghij klmnopq',getline(1))
2725
2726 " cleanup
2727 set norl
2728 bw!
2729endfunc
2730
Bram Moolenaarb1e04fc2017-03-29 13:08:35 +02002731func Test_normal54_Ctrl_bsl()
2732 new
2733 call setline(1, 'abcdefghijklmn')
2734 exe "norm! df\<c-\>\<c-n>"
2735 call assert_equal(['abcdefghijklmn'], getline(1,'$'))
2736 exe "norm! df\<c-\>\<c-g>"
2737 call assert_equal(['abcdefghijklmn'], getline(1,'$'))
2738 exe "norm! df\<c-\>m"
2739 call assert_equal(['abcdefghijklmn'], getline(1,'$'))
Bram Moolenaar30276f22019-01-24 17:59:39 +01002740
Bram Moolenaarb1e04fc2017-03-29 13:08:35 +02002741 call setline(2, 'abcdefghijklmnāf')
2742 norm! 2gg0
2743 exe "norm! df\<Char-0x101>"
2744 call assert_equal(['abcdefghijklmn', 'f'], getline(1,'$'))
2745 norm! 1gg0
2746 exe "norm! df\<esc>"
2747 call assert_equal(['abcdefghijklmn', 'f'], getline(1,'$'))
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002748
Bram Moolenaarb1e04fc2017-03-29 13:08:35 +02002749 " clean up
2750 bw!
2751endfunc
2752
2753func Test_normal_large_count()
2754 " This may fail with 32bit long, how do we detect that?
2755 new
2756 normal o
2757 normal 6666666666dL
2758 bwipe!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002759endfunc
Bram Moolenaarbf3d5802017-03-29 19:48:11 +02002760
2761func Test_delete_until_paragraph()
Bram Moolenaarbf3d5802017-03-29 19:48:11 +02002762 new
2763 normal grádv}
2764 call assert_equal('á', getline(1))
2765 normal grád}
2766 call assert_equal('', getline(1))
2767 bwipe!
2768endfunc
Bram Moolenaarfb094e12017-11-05 20:59:28 +01002769
2770" Test for the gr (virtual replace) command
2771" Test for the bug fixed by 7.4.387
2772func Test_gr_command()
2773 enew!
2774 let save_cpo = &cpo
2775 call append(0, ['First line', 'Second line', 'Third line'])
2776 exe "normal i\<C-G>u"
2777 call cursor(2, 1)
2778 set cpo-=X
2779 normal 4gro
2780 call assert_equal('oooond line', getline(2))
2781 undo
2782 set cpo+=X
2783 normal 4gro
2784 call assert_equal('ooooecond line', getline(2))
2785 let &cpo = save_cpo
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01002786 normal! ggvegrx
2787 call assert_equal('xxxxx line', getline(1))
2788 exe "normal! gggr\<C-V>122"
2789 call assert_equal('zxxxx line', getline(1))
2790 set virtualedit=all
2791 normal! 15|grl
2792 call assert_equal('zxxxx line l', getline(1))
2793 set virtualedit&
2794 set nomodifiable
2795 call assert_fails('normal! grx', 'E21:')
2796 call assert_fails('normal! gRx', 'E21:')
2797 set modifiable&
Bram Moolenaarfb094e12017-11-05 20:59:28 +01002798 enew!
2799endfunc
2800
2801" When splitting a window the changelist position is wrong.
2802" Test the changelist position after splitting a window.
2803" Test for the bug fixed by 7.4.386
2804func Test_changelist()
2805 let save_ul = &ul
2806 enew!
2807 call append('$', ['1', '2'])
2808 exe "normal i\<C-G>u"
2809 exe "normal Gkylpa\<C-G>u"
2810 set ul=100
2811 exe "normal Gylpa\<C-G>u"
2812 set ul=100
2813 normal gg
2814 vsplit
2815 normal g;
2816 call assert_equal([3, 2], [line('.'), col('.')])
2817 normal g;
2818 call assert_equal([2, 2], [line('.'), col('.')])
2819 call assert_fails('normal g;', 'E662:')
Bram Moolenaar1671f442020-03-10 07:48:13 +01002820 new
2821 call assert_fails('normal g;', 'E664:')
Bram Moolenaarfb094e12017-11-05 20:59:28 +01002822 %bwipe!
2823 let &ul = save_ul
2824endfunc
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01002825
2826func Test_nv_hat_count()
2827 %bwipeout!
2828 let l:nr = bufnr('%') + 1
Bram Moolenaare2e40752020-09-04 21:18:46 +02002829 call assert_fails(':execute "normal! ' . l:nr . '\<C-^>"', 'E92:')
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01002830
2831 edit Xfoo
2832 let l:foo_nr = bufnr('Xfoo')
2833
2834 edit Xbar
2835 let l:bar_nr = bufnr('Xbar')
2836
2837 " Make sure we are not just using the alternate file.
2838 edit Xbaz
2839
2840 call feedkeys(l:foo_nr . "\<C-^>", 'tx')
2841 call assert_equal('Xfoo', fnamemodify(bufname('%'), ':t'))
2842
2843 call feedkeys(l:bar_nr . "\<C-^>", 'tx')
2844 call assert_equal('Xbar', fnamemodify(bufname('%'), ':t'))
2845
2846 %bwipeout!
2847endfunc
Bram Moolenaara84a3dd2019-03-25 22:21:24 +01002848
2849func Test_message_when_using_ctrl_c()
Bram Moolenaar553e5a52019-03-25 23:16:34 +01002850 " Make sure no buffers are changed.
2851 %bwipe!
2852
Bram Moolenaara84a3dd2019-03-25 22:21:24 +01002853 exe "normal \<C-C>"
2854 call assert_match("Type :qa and press <Enter> to exit Vim", Screenline(&lines))
Bram Moolenaar553e5a52019-03-25 23:16:34 +01002855
Bram Moolenaara84a3dd2019-03-25 22:21:24 +01002856 new
2857 cal setline(1, 'hi!')
2858 exe "normal \<C-C>"
2859 call assert_match("Type :qa! and press <Enter> to abandon all changes and exit Vim", Screenline(&lines))
Bram Moolenaar553e5a52019-03-25 23:16:34 +01002860
Bram Moolenaara84a3dd2019-03-25 22:21:24 +01002861 bwipe!
2862endfunc
Bram Moolenaarc6b37db2019-04-27 18:00:34 +02002863
2864" Test for '[m', ']m', '[M' and ']M'
2865" Jumping to beginning and end of methods in Java-like languages
2866func Test_java_motion()
2867 new
Bram Moolenaar1671f442020-03-10 07:48:13 +01002868 call assert_beeps('normal! [m')
2869 call assert_beeps('normal! ]m')
2870 call assert_beeps('normal! [M')
2871 call assert_beeps('normal! ]M')
Bram Moolenaar8a9bc952020-10-02 18:48:07 +02002872 let lines =<< trim [CODE]
2873 Piece of Java
2874 {
2875 tt m1 {
2876 t1;
2877 } e1
Bram Moolenaarc6b37db2019-04-27 18:00:34 +02002878
Bram Moolenaar8a9bc952020-10-02 18:48:07 +02002879 tt m2 {
2880 t2;
2881 } e2
Bram Moolenaarc6b37db2019-04-27 18:00:34 +02002882
Bram Moolenaar8a9bc952020-10-02 18:48:07 +02002883 tt m3 {
2884 if (x)
2885 {
2886 t3;
2887 }
2888 } e3
2889 }
2890 [CODE]
2891 call setline(1, lines)
Bram Moolenaarc6b37db2019-04-27 18:00:34 +02002892
2893 normal gg
2894
2895 normal 2]maA
2896 call assert_equal("\ttt m1 {A", getline('.'))
2897 call assert_equal([3, 9, 16], [line('.'), col('.'), virtcol('.')])
2898
2899 normal j]maB
2900 call assert_equal("\ttt m2 {B", getline('.'))
2901 call assert_equal([7, 9, 16], [line('.'), col('.'), virtcol('.')])
2902
2903 normal ]maC
2904 call assert_equal("\ttt m3 {C", getline('.'))
2905 call assert_equal([11, 9, 16], [line('.'), col('.'), virtcol('.')])
2906
2907 normal [maD
2908 call assert_equal("\ttt m3 {DC", getline('.'))
2909 call assert_equal([11, 9, 16], [line('.'), col('.'), virtcol('.')])
2910
2911 normal k2[maE
2912 call assert_equal("\ttt m1 {EA", getline('.'))
2913 call assert_equal([3, 9, 16], [line('.'), col('.'), virtcol('.')])
2914
2915 normal 3[maF
2916 call assert_equal("{F", getline('.'))
2917 call assert_equal([2, 2, 2], [line('.'), col('.'), virtcol('.')])
2918
2919 normal ]MaG
2920 call assert_equal("\t}G e1", getline('.'))
2921 call assert_equal([5, 3, 10], [line('.'), col('.'), virtcol('.')])
2922
2923 normal j2]MaH
2924 call assert_equal("\t}H e3", getline('.'))
2925 call assert_equal([16, 3, 10], [line('.'), col('.'), virtcol('.')])
2926
2927 normal ]M]M
2928 normal aI
2929 call assert_equal("}I", getline('.'))
2930 call assert_equal([17, 2, 2], [line('.'), col('.'), virtcol('.')])
2931
2932 normal 2[MaJ
2933 call assert_equal("\t}JH e3", getline('.'))
2934 call assert_equal([16, 3, 10], [line('.'), col('.'), virtcol('.')])
2935
2936 normal k[MaK
2937 call assert_equal("\t}K e2", getline('.'))
2938 call assert_equal([9, 3, 10], [line('.'), col('.'), virtcol('.')])
2939
2940 normal 3[MaL
2941 call assert_equal("{LF", getline('.'))
2942 call assert_equal([2, 2, 2], [line('.'), col('.'), virtcol('.')])
2943
Bram Moolenaar8a9bc952020-10-02 18:48:07 +02002944 call cursor(2, 1)
2945 call assert_beeps('norm! 5]m')
2946
2947 " jumping to a method in a fold should open the fold
2948 6,10fold
2949 call feedkeys("gg3]m", 'xt')
2950 call assert_equal([7, 8, 15], [line('.'), col('.'), virtcol('.')])
2951 call assert_equal(-1, foldclosedend(7))
2952
Bram Moolenaarc6b37db2019-04-27 18:00:34 +02002953 close!
2954endfunc
Bram Moolenaard5c82342019-07-27 18:44:57 +02002955
Bram Moolenaar004a6782020-04-11 17:09:31 +02002956" Tests for g cmds
Bram Moolenaar1671f442020-03-10 07:48:13 +01002957func Test_normal_gdollar_cmd()
Bram Moolenaar004a6782020-04-11 17:09:31 +02002958 CheckFeature jumplist
Bram Moolenaard5c82342019-07-27 18:44:57 +02002959 call Setup_NewWindow()
2960 " Make long lines that will wrap
2961 %s/$/\=repeat(' foobar', 10)/
2962 20vsp
2963 set wrap
2964 " Test for g$ with count
2965 norm! gg
2966 norm! 0vg$y
2967 call assert_equal(20, col("'>"))
2968 call assert_equal('1 foobar foobar foob', getreg(0))
2969 norm! gg
2970 norm! 0v4g$y
2971 call assert_equal(72, col("'>"))
2972 call assert_equal('1 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar'.."\n", getreg(0))
2973 norm! gg
2974 norm! 0v6g$y
2975 call assert_equal(40, col("'>"))
2976 call assert_equal('1 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar'.. "\n"..
2977 \ '2 foobar foobar foobar foobar foobar foo', getreg(0))
2978 set nowrap
2979 " clean up
2980 norm! gg
2981 norm! 0vg$y
2982 call assert_equal(20, col("'>"))
2983 call assert_equal('1 foobar foobar foob', getreg(0))
2984 norm! gg
2985 norm! 0v4g$y
2986 call assert_equal(20, col("'>"))
2987 call assert_equal('1 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar'.. "\n"..
2988 \ '2 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar'.. "\n"..
2989 \ '3 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar'.. "\n"..
2990 \ '4 foobar foobar foob', getreg(0))
2991 norm! gg
2992 norm! 0v6g$y
2993 call assert_equal(20, col("'>"))
2994 call assert_equal('1 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar'.. "\n"..
2995 \ '2 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar'.. "\n"..
2996 \ '3 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar'.. "\n"..
2997 \ '4 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar'.. "\n"..
2998 \ '5 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar'.. "\n"..
2999 \ '6 foobar foobar foob', getreg(0))
3000 " Move to last line, also down movement is not possible, should still move
3001 " the cursor to the last visible char
3002 norm! G
3003 norm! 0v6g$y
3004 call assert_equal(20, col("'>"))
3005 call assert_equal('100 foobar foobar fo', getreg(0))
3006 bw!
3007endfunc
Bram Moolenaar03ac52f2019-09-24 22:47:46 +02003008
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01003009func Test_normal_gk_gj()
Bram Moolenaar03ac52f2019-09-24 22:47:46 +02003010 " needs 80 column new window
3011 new
3012 vert 80new
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01003013 call assert_beeps('normal gk')
Bram Moolenaar03ac52f2019-09-24 22:47:46 +02003014 put =[repeat('x',90)..' {{{1', 'x {{{1']
3015 norm! gk
3016 " In a 80 column wide terminal the window will be only 78 char
3017 " (because Vim will leave space for the other window),
3018 " but if the terminal is larger, it will be 80 chars, so verify the
3019 " cursor column correctly.
3020 call assert_equal(winwidth(0)+1, col('.'))
3021 call assert_equal(winwidth(0)+1, virtcol('.'))
3022 norm! j
3023 call assert_equal(6, col('.'))
3024 call assert_equal(6, virtcol('.'))
3025 norm! gk
3026 call assert_equal(95, col('.'))
3027 call assert_equal(95, virtcol('.'))
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01003028 %bw!
Bram Moolenaarceba3dd2019-10-12 16:12:54 +02003029
3030 " needs 80 column new window
3031 new
3032 vert 80new
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01003033 call assert_beeps('normal gj')
Bram Moolenaarceba3dd2019-10-12 16:12:54 +02003034 set number
3035 set numberwidth=10
3036 set cpoptions+=n
3037 put =[repeat('0',90), repeat('1',90)]
3038 norm! 075l
3039 call assert_equal(76, col('.'))
3040 norm! gk
3041 call assert_equal(1, col('.'))
3042 norm! gk
3043 call assert_equal(76, col('.'))
3044 norm! gk
3045 call assert_equal(1, col('.'))
3046 norm! gj
3047 call assert_equal(76, col('.'))
3048 norm! gj
3049 call assert_equal(1, col('.'))
3050 norm! gj
3051 call assert_equal(76, col('.'))
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01003052 " When 'nowrap' is set, gk and gj behave like k and j
3053 set nowrap
3054 normal! gk
3055 call assert_equal([2, 76], [line('.'), col('.')])
3056 normal! gj
3057 call assert_equal([3, 76], [line('.'), col('.')])
3058 %bw!
3059 set cpoptions& number& numberwidth& wrap&
Bram Moolenaar03ac52f2019-09-24 22:47:46 +02003060endfunc
Bram Moolenaarf0cee192020-02-16 13:33:56 +01003061
Bram Moolenaar818fc9a2020-02-21 17:54:45 +01003062" Test for using : to run a multi-line Ex command in operator pending mode
3063func Test_normal_yank_with_excmd()
3064 new
3065 call setline(1, ['foo', 'bar', 'baz'])
3066 let @a = ''
3067 call feedkeys("\"ay:if v:true\<CR>normal l\<CR>endif\<CR>", 'xt')
3068 call assert_equal('f', @a)
3069 close!
3070endfunc
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01003071
3072" Test for supplying a count to a normal-mode command across a cursorhold call
3073func Test_normal_cursorhold_with_count()
3074 func s:cHold()
3075 let g:cHold_Called += 1
3076 endfunc
3077 new
3078 augroup normalcHoldTest
3079 au!
3080 au CursorHold <buffer> call s:cHold()
3081 augroup END
3082 let g:cHold_Called = 0
3083 call feedkeys("3\<CursorHold>2ix", 'xt')
3084 call assert_equal(1, g:cHold_Called)
3085 call assert_equal(repeat('x', 32), getline(1))
3086 augroup normalcHoldTest
3087 au!
3088 augroup END
3089 au! normalcHoldTest
3090 close!
3091 delfunc s:cHold
3092endfunc
3093
3094" Test for using a count and a command with CTRL-W
3095func Test_wincmd_with_count()
3096 call feedkeys("\<C-W>12n", 'xt')
3097 call assert_equal(12, winheight(0))
3098endfunc
3099
3100" Test for 'b', 'B' 'ge' and 'gE' commands
Bram Moolenaar1671f442020-03-10 07:48:13 +01003101func Test_horiz_motion()
3102 new
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01003103 normal! gg
3104 call assert_beeps('normal! b')
3105 call assert_beeps('normal! B')
3106 call assert_beeps('normal! gE')
3107 call assert_beeps('normal! ge')
Bram Moolenaar1671f442020-03-10 07:48:13 +01003108 " <S-Backspace> moves one word left and <C-Backspace> moves one WORD left
3109 call setline(1, 'one ,two ,three')
3110 exe "normal! $\<S-BS>"
3111 call assert_equal(11, col('.'))
3112 exe "normal! $\<C-BS>"
3113 call assert_equal(10, col('.'))
3114 close!
3115endfunc
3116
3117" Test for using a : command in operator pending mode
3118func Test_normal_colon_op()
3119 new
3120 call setline(1, ['one', 'two'])
3121 call assert_beeps("normal! Gc:d\<CR>")
3122 close!
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01003123endfunc
3124
Bram Moolenaar004a6782020-04-11 17:09:31 +02003125" Test for d and D commands
3126func Test_normal_delete_cmd()
3127 new
3128 " D in an empty line
3129 call setline(1, '')
3130 normal D
3131 call assert_equal('', getline(1))
3132 " D in an empty line in virtualedit mode
3133 set virtualedit=all
3134 normal D
3135 call assert_equal('', getline(1))
3136 set virtualedit&
3137 " delete to a readonly register
3138 call setline(1, ['abcd'])
3139 call assert_beeps('normal ":d2l')
3140 close!
3141endfunc
3142
Bram Moolenaar8a9bc952020-10-02 18:48:07 +02003143" Test for deleting or changing characters across lines with 'whichwrap'
3144" containing 's'. Should count <EOL> as one character.
3145func Test_normal_op_across_lines()
3146 new
3147 set whichwrap&
3148 call setline(1, ['one two', 'three four'])
3149 exe "norm! $3d\<Space>"
3150 call assert_equal(['one twhree four'], getline(1, '$'))
3151
3152 call setline(1, ['one two', 'three four'])
3153 exe "norm! $3c\<Space>x"
3154 call assert_equal(['one twxhree four'], getline(1, '$'))
3155
3156 set whichwrap+=l
3157 call setline(1, ['one two', 'three four'])
3158 exe "norm! $3x"
3159 call assert_equal(['one twhree four'], getline(1, '$'))
3160 close!
3161 set whichwrap&
3162endfunc
3163
Bram Moolenaar224a5f12020-04-28 20:29:07 +02003164" Test for 'w' and 'b' commands
3165func Test_normal_word_move()
3166 new
3167 call setline(1, ['foo bar a', '', 'foo bar b'])
3168 " copy a single character word at the end of a line
3169 normal 1G$yw
3170 call assert_equal('a', @")
3171 " copy a single character word at the end of a file
3172 normal G$yw
3173 call assert_equal('b', @")
3174 " check for a word movement handling an empty line properly
3175 normal 1G$vwy
3176 call assert_equal("a\n\n", @")
3177
3178 " copy using 'b' command
3179 %d
3180 " non-empty blank line at the start of file
3181 call setline(1, [' ', 'foo bar'])
3182 normal 2Gyb
3183 call assert_equal(" \n", @")
3184 " try to copy backwards from the start of the file
3185 call setline(1, ['one two', 'foo bar'])
3186 call assert_beeps('normal ggyb')
3187 " 'b' command should stop at an empty line
3188 call setline(1, ['one two', '', 'foo bar'])
3189 normal 3Gyb
3190 call assert_equal("\n", @")
3191 normal 3Gy2b
3192 call assert_equal("two\n", @")
3193 " 'b' command should not stop at a non-empty blank line
3194 call setline(1, ['one two', ' ', 'foo bar'])
3195 normal 3Gyb
3196 call assert_equal("two\n ", @")
3197
3198 close!
3199endfunc
3200
Bram Moolenaarbdd2c292020-06-22 21:34:30 +02003201" Test for 'scrolloff' with a long line that doesn't fit in the screen
3202func Test_normal_scroloff()
3203 10new
3204 80vnew
3205 call setline(1, repeat('a', 1000))
3206 set scrolloff=10
3207 normal gg10gj
3208 call assert_equal(8, winline())
3209 normal 10gj
3210 call assert_equal(10, winline())
3211 normal 10gk
3212 call assert_equal(3, winline())
3213 set scrolloff&
3214 close!
3215endfunc
3216
3217" Test for vertical scrolling with CTRL-F and CTRL-B with a long line
3218func Test_normal_vert_scroll_longline()
3219 10new
3220 80vnew
3221 call setline(1, range(1, 10))
3222 call append(5, repeat('a', 1000))
3223 exe "normal gg\<C-F>"
3224 call assert_equal(6, line('.'))
3225 exe "normal \<C-F>\<C-F>"
3226 call assert_equal(11, line('.'))
3227 call assert_equal(1, winline())
3228 exe "normal \<C-B>"
3229 call assert_equal(10, line('.'))
3230 call assert_equal(3, winline())
3231 exe "normal \<C-B>\<C-B>"
3232 call assert_equal(5, line('.'))
3233 call assert_equal(5, winline())
3234 close!
3235endfunc
3236
Bram Moolenaar8a9bc952020-10-02 18:48:07 +02003237" Test for jumping in a file using %
3238func Test_normal_percent_jump()
3239 new
3240 call setline(1, range(1, 100))
3241
3242 " jumping to a folded line should open the fold
3243 25,75fold
3244 call feedkeys('50%', 'xt')
3245 call assert_equal(50, line('.'))
3246 call assert_equal(-1, foldclosedend(50))
3247 close!
3248endfunc
3249
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01003250" vim: shiftwidth=2 sts=2 expandtab