blob: e0df0ae1ebe07f91b597f9110caea5a04583efb2 [file] [log] [blame]
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001" Test for various Normal mode commands
2
Bram Moolenaarc3c766e2017-03-08 22:55:19 +01003set belloff=all
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02004func! Setup_NewWindow()
5 10new
6 call setline(1, range(1,100))
7endfunc
8
9func! MyFormatExpr()
10 " Adds '->$' at lines having numbers followed by trailing whitespace
11 for ln in range(v:lnum, v:lnum+v:count-1)
12 let line = getline(ln)
13 if getline(ln) =~# '\d\s\+$'
14 call setline(ln, substitute(line, '\s\+$', '', '') . '->$')
15 endif
16 endfor
Bram Moolenaar2931f2a2016-09-09 16:59:08 +020017endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +020018
Bram Moolenaar2931f2a2016-09-09 16:59:08 +020019func! CountSpaces(type, ...)
Bram Moolenaar87bc3f72016-09-03 17:33:54 +020020 " for testing operatorfunc
21 " will count the number of spaces
22 " and return the result in g:a
23 let sel_save = &selection
24 let &selection = "inclusive"
25 let reg_save = @@
26
27 if a:0 " Invoked from Visual mode, use gv command.
28 silent exe "normal! gvy"
29 elseif a:type == 'line'
30 silent exe "normal! '[V']y"
31 else
32 silent exe "normal! `[v`]y"
33 endif
34 let g:a=strlen(substitute(@@, '[^ ]', '', 'g'))
35 let &selection = sel_save
36 let @@ = reg_save
Bram Moolenaar2931f2a2016-09-09 16:59:08 +020037endfunc
38
Bram Moolenaar4a08b0d2016-11-05 21:55:13 +010039func! OpfuncDummy(type, ...)
40 " for testing operatorfunc
41 let g:opt=&linebreak
42
43 if a:0 " Invoked from Visual mode, use gv command.
44 silent exe "normal! gvy"
45 elseif a:type == 'line'
46 silent exe "normal! '[V']y"
47 else
48 silent exe "normal! `[v`]y"
49 endif
50 " Create a new dummy window
51 new
52 let g:bufnr=bufnr('%')
Bram Moolenaar2931f2a2016-09-09 16:59:08 +020053endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +020054
55fun! Test_normal00_optrans()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +020056 new
57 call append(0, ['1 This is a simple test: abcd', '2 This is the second line', '3 this is the third line'])
58 1
59 exe "norm! Sfoobar\<esc>"
60 call assert_equal(['foobar', '2 This is the second line', '3 this is the third line', ''], getline(1,'$'))
61 2
Bram Moolenaar87bc3f72016-09-03 17:33:54 +020062 exe "norm! $vbsone"
63 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 +020064 norm! VS Second line here
65 call assert_equal(['foobar', ' Second line here', '3 this is the third line', ''], getline(1, '$'))
66 %d
67 call append(0, ['4 This is a simple test: abcd', '5 This is the second line', '6 this is the third line'])
68 call append(0, ['1 This is a simple test: abcd', '2 This is the second line', '3 this is the third line'])
69
70 1
71 norm! 2D
72 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,'$'))
73 set cpo+=#
74 norm! 4D
75 call assert_equal(['', '4 This is a simple test: abcd', '5 This is the second line', '6 this is the third line', ''], getline(1,'$'))
76
77 " clean up
78 set cpo-=#
79 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +020080endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +020081
82func! Test_normal01_keymodel()
83 call Setup_NewWindow()
84 " Test 1: depending on 'keymodel' <s-down> does something different
Bram Moolenaar2931f2a2016-09-09 16:59:08 +020085 50
Bram Moolenaar87bc3f72016-09-03 17:33:54 +020086 call feedkeys("V\<S-Up>y", 'tx')
87 call assert_equal(['47', '48', '49', '50'], getline("'<", "'>"))
Bram Moolenaar2931f2a2016-09-09 16:59:08 +020088 set keymodel=startsel
89 50
Bram Moolenaar87bc3f72016-09-03 17:33:54 +020090 call feedkeys("V\<S-Up>y", 'tx')
91 call assert_equal(['49', '50'], getline("'<", "'>"))
92 " Start visual mode when keymodel = startsel
Bram Moolenaar2931f2a2016-09-09 16:59:08 +020093 50
Bram Moolenaar87bc3f72016-09-03 17:33:54 +020094 call feedkeys("\<S-Up>y", 'tx')
95 call assert_equal(['49', '5'], getreg(0, 0, 1))
96 " Do not start visual mode when keymodel=
Bram Moolenaar2931f2a2016-09-09 16:59:08 +020097 set keymodel=
98 50
Bram Moolenaar87bc3f72016-09-03 17:33:54 +020099 call feedkeys("\<S-Up>y$", 'tx')
100 call assert_equal(['42'], getreg(0, 0, 1))
Bram Moolenaar2931f2a2016-09-09 16:59:08 +0200101 " Stop visual mode when keymodel=stopsel
102 set keymodel=stopsel
103 50
104 call feedkeys("Vkk\<Up>yy", 'tx')
105 call assert_equal(['47'], getreg(0, 0, 1))
106
107 set keymodel=
108 50
109 call feedkeys("Vkk\<Up>yy", 'tx')
110 call assert_equal(['47', '48', '49', '50'], getreg(0, 0, 1))
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200111
112 " clean up
113 bw!
114endfunc
115
116func! Test_normal02_selectmode()
117 " some basic select mode tests
118 call Setup_NewWindow()
119 50
120 norm! gHy
121 call assert_equal('y51', getline('.'))
122 call setline(1, range(1,100))
123 50
124 exe ":norm! V9jo\<c-g>y"
125 call assert_equal('y60', getline('.'))
126 " clean up
127 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +0200128endfunc
129
130func! Test_normal02_selectmode2()
131 " some basic select mode tests
132 call Setup_NewWindow()
133 50
134 call feedkeys(":set im\n\<c-o>gHc\<c-o>:set noim\n", 'tx')
135 call assert_equal('c51', getline('.'))
136 " clean up
137 bw!
138endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200139
140func! Test_normal03_join()
141 " basic join test
142 call Setup_NewWindow()
143 50
144 norm! VJ
145 call assert_equal('50 51', getline('.'))
146 $
147 norm! J
148 call assert_equal('100', getline('.'))
149 $
150 norm! V9-gJ
151 call assert_equal('919293949596979899100', getline('.'))
152 call setline(1, range(1,100))
153 $
154 :j 10
155 call assert_equal('100', getline('.'))
156 " clean up
157 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +0200158endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200159
160func! Test_normal04_filter()
161 " basic filter test
162 " only test on non windows platform
Bram Moolenaar4a08b0d2016-11-05 21:55:13 +0100163 if has('win32')
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200164 return
165 endif
166 call Setup_NewWindow()
167 1
168 call feedkeys("!!sed -e 's/^/| /'\n", 'tx')
169 call assert_equal('| 1', getline('.'))
170 90
171 :sil :!echo one
172 call feedkeys('.', 'tx')
173 call assert_equal('| 90', getline('.'))
174 95
175 set cpo+=!
176 " 2 <CR>, 1: for executing the command,
177 " 2: clear hit-enter-prompt
178 call feedkeys("!!\n", 'tx')
179 call feedkeys(":!echo one\n\n", 'tx')
180 call feedkeys(".", 'tx')
181 call assert_equal('one', getline('.'))
182 set cpo-=!
183 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +0200184endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200185
186func! Test_normal05_formatexpr()
187 " basic formatexpr test
188 call Setup_NewWindow()
189 %d_
190 call setline(1, ['here: 1 ', '2', 'here: 3 ', '4', 'not here: '])
191 1
192 set formatexpr=MyFormatExpr()
193 norm! gqG
194 call assert_equal(['here: 1->$', '2', 'here: 3->$', '4', 'not here: '], getline(1,'$'))
195 set formatexpr=
196 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +0200197endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200198
Bram Moolenaard77f9d52016-09-04 15:13:39 +0200199func Test_normal05_formatexpr_newbuf()
200 " Edit another buffer in the 'formatexpr' function
201 new
202 func! Format()
203 edit another
204 endfunc
205 set formatexpr=Format()
206 norm gqG
207 bw!
208 set formatexpr=
209endfunc
210
211func Test_normal05_formatexpr_setopt()
212 " Change the 'formatexpr' value in the function
213 new
214 func! Format()
215 set formatexpr=
216 endfunc
217 set formatexpr=Format()
218 norm gqG
219 bw!
220 set formatexpr=
221endfunc
222
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200223func! Test_normal06_formatprg()
224 " basic test for formatprg
225 " only test on non windows platform
Bram Moolenaar4a08b0d2016-11-05 21:55:13 +0100226 if has('win32')
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200227 return
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200228 endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +0100229
230 " uses sed to number non-empty lines
231 call writefile(['#!/bin/sh', 'sed ''/./=''|sed ''/./{', 'N', 's/\n/ /', '}'''], 'Xsed_format.sh')
232 call system('chmod +x ./Xsed_format.sh')
233 let text = ['a', '', 'c', '', ' ', 'd', 'e']
234 let expected = ['1 a', '', '3 c', '', '5 ', '6 d', '7 e']
235
236 10new
237 call setline(1, text)
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200238 set formatprg=./Xsed_format.sh
239 norm! gggqG
Bram Moolenaar9be7c042017-01-14 14:28:30 +0100240 call assert_equal(expected, getline(1, '$'))
241 bw!
242
243 10new
244 call setline(1, text)
245 set formatprg=donothing
246 setlocal formatprg=./Xsed_format.sh
247 norm! gggqG
248 call assert_equal(expected, getline(1, '$'))
249 bw!
250
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200251 " clean up
252 set formatprg=
Bram Moolenaar9be7c042017-01-14 14:28:30 +0100253 setlocal formatprg=
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200254 call delete('Xsed_format.sh')
Bram Moolenaar2931f2a2016-09-09 16:59:08 +0200255endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200256
257func! Test_normal07_internalfmt()
258 " basic test for internal formmatter to textwidth of 12
259 let list=range(1,11)
260 call map(list, 'v:val." "')
261 10new
262 call setline(1, list)
263 set tw=12
264 norm! gggqG
265 call assert_equal(['1 2 3', '4 5 6', '7 8 9', '10 11 '], getline(1, '$'))
266 " clean up
Bram Moolenaar9be7c042017-01-14 14:28:30 +0100267 set tw=0
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200268 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +0200269endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200270
271func! Test_normal08_fold()
272 " basic tests for foldopen/folddelete
273 if !has("folding")
274 return
275 endif
276 call Setup_NewWindow()
277 50
278 setl foldenable fdm=marker
279 " First fold
280 norm! V4jzf
281 " check that folds have been created
282 call assert_equal(['50/*{{{*/', '51', '52', '53', '54/*}}}*/'], getline(50,54))
283 " Second fold
284 46
285 norm! V10jzf
286 " check that folds have been created
287 call assert_equal('46/*{{{*/', getline(46))
288 call assert_equal('60/*}}}*/', getline(60))
289 norm! k
290 call assert_equal('45', getline('.'))
291 norm! j
292 call assert_equal('46/*{{{*/', getline('.'))
293 norm! j
294 call assert_equal('61', getline('.'))
295 norm! k
296 " open a fold
297 norm! Vzo
298 norm! k
299 call assert_equal('45', getline('.'))
300 norm! j
301 call assert_equal('46/*{{{*/', getline('.'))
302 norm! j
303 call assert_equal('47', getline('.'))
304 norm! k
305 norm! zcVzO
306 call assert_equal('46/*{{{*/', getline('.'))
307 norm! j
308 call assert_equal('47', getline('.'))
309 norm! j
310 call assert_equal('48', getline('.'))
311 norm! j
312 call assert_equal('49', getline('.'))
313 norm! j
314 call assert_equal('50/*{{{*/', getline('.'))
315 norm! j
316 call assert_equal('51', getline('.'))
317 " delete folds
318 :46
319 " collapse fold
320 norm! V14jzC
321 " delete all folds recursively
322 norm! VzD
323 call assert_equal(['46', '47', '48', '49', '50', '51', '52', '53', '54', '55', '56', '57', '58', '59', '60'], getline(46,60))
324
325 " clean up
326 setl nofoldenable fdm=marker
327 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +0200328endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200329
330func! Test_normal09_operatorfunc()
331 " Test operatorfunc
332 call Setup_NewWindow()
333 " Add some spaces for counting
334 50,60s/$/ /
335 unlet! g:a
336 let g:a=0
337 nmap <buffer><silent> ,, :set opfunc=CountSpaces<CR>g@
338 vmap <buffer><silent> ,, :<C-U>call CountSpaces(visualmode(), 1)<CR>
339 50
340 norm V2j,,
341 call assert_equal(6, g:a)
342 norm V,,
343 call assert_equal(2, g:a)
344 norm ,,l
345 call assert_equal(0, g:a)
346 50
347 exe "norm 0\<c-v>10j2l,,"
348 call assert_equal(11, g:a)
349 50
350 norm V10j,,
351 call assert_equal(22, g:a)
352
353 " clean up
354 unmap <buffer> ,,
355 set opfunc=
Bram Moolenaar4a08b0d2016-11-05 21:55:13 +0100356 unlet! g:a
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200357 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +0200358endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200359
Bram Moolenaar4a08b0d2016-11-05 21:55:13 +0100360func! Test_normal09a_operatorfunc()
361 " Test operatorfunc
362 call Setup_NewWindow()
363 " Add some spaces for counting
364 50,60s/$/ /
365 unlet! g:opt
366 set linebreak
367 nmap <buffer><silent> ,, :set opfunc=OpfuncDummy<CR>g@
368 50
369 norm ,,j
370 exe "bd!" g:bufnr
371 call assert_true(&linebreak)
372 call assert_equal(g:opt, &linebreak)
373 set nolinebreak
374 norm ,,j
375 exe "bd!" g:bufnr
376 call assert_false(&linebreak)
377 call assert_equal(g:opt, &linebreak)
378
379 " clean up
380 unmap <buffer> ,,
381 set opfunc=
382 bw!
383 unlet! g:opt
384endfunc
385
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200386func! Test_normal10_expand()
387 " Test for expand()
388 10new
389 call setline(1, ['1', 'ifooar,,cbar'])
390 2
391 norm! $
392 let a=expand('<cword>')
393 let b=expand('<cWORD>')
394 call assert_equal('cbar', a)
395 call assert_equal('ifooar,,cbar', b)
396 " clean up
397 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +0200398endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200399
400func! Test_normal11_showcmd()
401 " test for 'showcmd'
402 10new
403 exe "norm! ofoobar\<esc>"
404 call assert_equal(2, line('$'))
405 set showcmd
406 exe "norm! ofoobar2\<esc>"
407 call assert_equal(3, line('$'))
408 exe "norm! VAfoobar3\<esc>"
409 call assert_equal(3, line('$'))
410 exe "norm! 0d3\<del>2l"
411 call assert_equal('obar2foobar3', getline('.'))
412 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +0200413endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200414
415func! Test_normal12_nv_error()
416 " Test for nv_error
417 10new
418 call setline(1, range(1,5))
419 " should not do anything, just beep
420 exe "norm! <c-k>"
421 call assert_equal(map(range(1,5), 'string(v:val)'), getline(1,'$'))
422 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +0200423endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200424
425func! Test_normal13_help()
426 " Test for F1
427 call assert_equal(1, winnr())
428 call feedkeys("\<f1>", 'txi')
429 call assert_match('help\.txt', bufname('%'))
430 call assert_equal(2, winnr('$'))
431 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +0200432endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200433
434func! Test_normal14_page()
435 " basic test for Ctrl-F and Ctrl-B
436 call Setup_NewWindow()
437 exe "norm! \<c-f>"
438 call assert_equal('9', getline('.'))
439 exe "norm! 2\<c-f>"
440 call assert_equal('25', getline('.'))
441 exe "norm! 2\<c-b>"
442 call assert_equal('18', getline('.'))
443 1
444 set scrolloff=5
445 exe "norm! 2\<c-f>"
446 call assert_equal('21', getline('.'))
447 exe "norm! \<c-b>"
448 call assert_equal('13', getline('.'))
449 1
450 set scrolloff=99
451 exe "norm! \<c-f>"
452 call assert_equal('13', getline('.'))
453 set scrolloff=0
454 100
455 exe "norm! $\<c-b>"
456 call assert_equal('92', getline('.'))
457 call assert_equal([0, 92, 1, 0, 1], getcurpos())
458 100
459 set nostartofline
460 exe "norm! $\<c-b>"
461 call assert_equal('92', getline('.'))
462 call assert_equal([0, 92, 2, 0, 2147483647], getcurpos())
463 " cleanup
464 set startofline
465 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +0200466endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200467
Bram Moolenaarbc54f3f2016-09-04 14:34:28 +0200468func! Test_normal14_page_eol()
469 10new
470 norm oxxxxxxx
471 exe "norm 2\<c-f>"
472 " check with valgrind that cursor is put back in column 1
473 exe "norm 2\<c-b>"
474 bw!
475endfunc
476
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200477func! Test_normal15_z_scroll_vert()
478 " basic test for z commands that scroll the window
479 call Setup_NewWindow()
480 100
481 norm! >>
482 " Test for z<cr>
483 exe "norm! z\<cr>"
484 call assert_equal(' 100', getline('.'))
485 call assert_equal(100, winsaveview()['topline'])
486 call assert_equal([0, 100, 2, 0, 9], getcurpos())
487
488 " Test for zt
489 21
490 norm! >>0zt
491 call assert_equal(' 21', getline('.'))
492 call assert_equal(21, winsaveview()['topline'])
493 call assert_equal([0, 21, 1, 0, 8], getcurpos())
494
495 " Test for zb
496 30
497 norm! >>$ztzb
498 call assert_equal(' 30', getline('.'))
499 call assert_equal(30, winsaveview()['topline']+winheight(0)-1)
500 call assert_equal([0, 30, 3, 0, 2147483647], getcurpos())
501
502 " Test for z-
503 1
504 30
505 norm! 0z-
506 call assert_equal(' 30', getline('.'))
507 call assert_equal(30, winsaveview()['topline']+winheight(0)-1)
508 call assert_equal([0, 30, 2, 0, 9], getcurpos())
509
510 " Test for z{height}<cr>
511 call assert_equal(10, winheight(0))
512 exe "norm! z12\<cr>"
513 call assert_equal(12, winheight(0))
514 exe "norm! z10\<cr>"
515 call assert_equal(10, winheight(0))
516
517 " Test for z.
518 1
519 21
520 norm! 0z.
521 call assert_equal(' 21', getline('.'))
522 call assert_equal(17, winsaveview()['topline'])
523 call assert_equal([0, 21, 2, 0, 9], getcurpos())
524
525 " Test for zz
526 1
527 21
528 norm! 0zz
529 call assert_equal(' 21', getline('.'))
530 call assert_equal(17, winsaveview()['topline'])
531 call assert_equal([0, 21, 1, 0, 8], getcurpos())
532
533 " Test for z+
534 11
535 norm! zt
536 norm! z+
537 call assert_equal(' 21', getline('.'))
538 call assert_equal(21, winsaveview()['topline'])
539 call assert_equal([0, 21, 2, 0, 9], getcurpos())
540
541 " Test for [count]z+
542 1
543 norm! 21z+
544 call assert_equal(' 21', getline('.'))
545 call assert_equal(21, winsaveview()['topline'])
546 call assert_equal([0, 21, 2, 0, 9], getcurpos())
547
548 " Test for z^
549 norm! 22z+0
550 norm! z^
551 call assert_equal(' 21', getline('.'))
552 call assert_equal(12, winsaveview()['topline'])
553 call assert_equal([0, 21, 2, 0, 9], getcurpos())
554
555 " Test for [count]z^
556 1
557 norm! 30z^
558 call assert_equal(' 21', getline('.'))
559 call assert_equal(12, winsaveview()['topline'])
560 call assert_equal([0, 21, 2, 0, 9], getcurpos())
561
562 " cleanup
563 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +0200564endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200565
566func! Test_normal16_z_scroll_hor()
567 " basic test for z commands that scroll the window
568 10new
569 15vsp
570 set nowrap listchars=
571 let lineA='abcdefghijklmnopqrstuvwxyz'
572 let lineB='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'
573 $put =lineA
574 $put =lineB
575 1d
576
577 " Test for zl
578 1
579 norm! 5zl
580 call assert_equal(lineA, getline('.'))
581 call assert_equal(6, col('.'))
582 call assert_equal(5, winsaveview()['leftcol'])
583 norm! yl
584 call assert_equal('f', @0)
585
586 " Test for zh
587 norm! 2zh
588 call assert_equal(lineA, getline('.'))
589 call assert_equal(6, col('.'))
590 norm! yl
591 call assert_equal('f', @0)
592 call assert_equal(3, winsaveview()['leftcol'])
593
594 " Test for zL
595 norm! zL
596 call assert_equal(11, col('.'))
597 norm! yl
598 call assert_equal('k', @0)
599 call assert_equal(10, winsaveview()['leftcol'])
600 norm! 2zL
601 call assert_equal(25, col('.'))
602 norm! yl
603 call assert_equal('y', @0)
604 call assert_equal(24, winsaveview()['leftcol'])
605
606 " Test for zH
607 norm! 2zH
608 call assert_equal(25, col('.'))
609 call assert_equal(10, winsaveview()['leftcol'])
610 norm! yl
611 call assert_equal('y', @0)
612
613 " Test for zs
614 norm! $zs
615 call assert_equal(26, col('.'))
616 call assert_equal(25, winsaveview()['leftcol'])
617 norm! yl
618 call assert_equal('z', @0)
619
620 " Test for ze
621 norm! ze
622 call assert_equal(26, col('.'))
623 call assert_equal(11, winsaveview()['leftcol'])
624 norm! yl
625 call assert_equal('z', @0)
626
627 " cleanup
628 set wrap listchars=eol:$
629 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +0200630endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200631
632func! Test_normal17_z_scroll_hor2()
633 " basic test for z commands that scroll the window
634 " using 'sidescrolloff' setting
635 10new
636 20vsp
637 set nowrap listchars= sidescrolloff=5
638 let lineA='abcdefghijklmnopqrstuvwxyz'
639 let lineB='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'
640 $put =lineA
641 $put =lineB
642 1d
643
644 " Test for zl
645 1
646 norm! 5zl
647 call assert_equal(lineA, getline('.'))
648 call assert_equal(11, col('.'))
649 call assert_equal(5, winsaveview()['leftcol'])
650 norm! yl
651 call assert_equal('k', @0)
652
653 " Test for zh
654 norm! 2zh
655 call assert_equal(lineA, getline('.'))
656 call assert_equal(11, col('.'))
657 norm! yl
658 call assert_equal('k', @0)
659 call assert_equal(3, winsaveview()['leftcol'])
660
661 " Test for zL
662 norm! 0zL
663 call assert_equal(16, col('.'))
664 norm! yl
665 call assert_equal('p', @0)
666 call assert_equal(10, winsaveview()['leftcol'])
667 norm! 2zL
668 call assert_equal(26, col('.'))
669 norm! yl
670 call assert_equal('z', @0)
671 call assert_equal(15, winsaveview()['leftcol'])
672
673 " Test for zH
674 norm! 2zH
675 call assert_equal(15, col('.'))
676 call assert_equal(0, winsaveview()['leftcol'])
677 norm! yl
678 call assert_equal('o', @0)
679
680 " Test for zs
681 norm! $zs
682 call assert_equal(26, col('.'))
683 call assert_equal(20, winsaveview()['leftcol'])
684 norm! yl
685 call assert_equal('z', @0)
686
687 " Test for ze
688 norm! ze
689 call assert_equal(26, col('.'))
690 call assert_equal(11, winsaveview()['leftcol'])
691 norm! yl
692 call assert_equal('z', @0)
693
694 " cleanup
695 set wrap listchars=eol:$ sidescrolloff=0
696 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +0200697endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200698
699func! Test_normal18_z_fold()
700 " basic tests for foldopen/folddelete
701 if !has("folding")
702 return
703 endif
704 call Setup_NewWindow()
705 50
706 setl foldenable fdm=marker foldlevel=5
707
708 " Test for zF
709 " First fold
710 norm! 4zF
711 " check that folds have been created
712 call assert_equal(['50/*{{{*/', '51', '52', '53/*}}}*/'], getline(50,53))
713
714 " Test for zd
715 51
716 norm! 2zF
717 call assert_equal(2, foldlevel('.'))
718 norm! kzd
719 call assert_equal(['50', '51/*{{{*/', '52/*}}}*/', '53'], getline(50,53))
720 norm! j
721 call assert_equal(1, foldlevel('.'))
722
723 " Test for zD
724 " also deletes partially selected folds recursively
725 51
726 norm! zF
727 call assert_equal(2, foldlevel('.'))
728 norm! kV2jzD
729 call assert_equal(['50', '51', '52', '53'], getline(50,53))
730
731 " Test for zE
732 85
733 norm! 4zF
734 86
735 norm! 2zF
736 90
737 norm! 4zF
738 call assert_equal(['85/*{{{*/', '86/*{{{*/', '87/*}}}*/', '88/*}}}*/', '89', '90/*{{{*/', '91', '92', '93/*}}}*/'], getline(85,93))
739 norm! zE
740 call assert_equal(['85', '86', '87', '88', '89', '90', '91', '92', '93'], getline(85,93))
741
742 " Test for zn
743 50
744 set foldlevel=0
745 norm! 2zF
746 norm! zn
747 norm! k
748 call assert_equal('49', getline('.'))
749 norm! j
750 call assert_equal('50/*{{{*/', getline('.'))
751 norm! j
752 call assert_equal('51/*}}}*/', getline('.'))
753 norm! j
754 call assert_equal('52', getline('.'))
755 call assert_equal(0, &foldenable)
756
757 " Test for zN
758 49
759 norm! zN
760 call assert_equal('49', getline('.'))
761 norm! j
762 call assert_equal('50/*{{{*/', getline('.'))
763 norm! j
764 call assert_equal('52', getline('.'))
765 call assert_equal(1, &foldenable)
766
767 " Test for zi
768 norm! zi
769 call assert_equal(0, &foldenable)
770 norm! zi
771 call assert_equal(1, &foldenable)
772 norm! zi
773 call assert_equal(0, &foldenable)
774 norm! zi
775 call assert_equal(1, &foldenable)
776
777 " Test for za
778 50
779 norm! za
780 norm! k
781 call assert_equal('49', getline('.'))
782 norm! j
783 call assert_equal('50/*{{{*/', getline('.'))
784 norm! j
785 call assert_equal('51/*}}}*/', getline('.'))
786 norm! j
787 call assert_equal('52', getline('.'))
788 50
789 norm! za
790 norm! k
791 call assert_equal('49', getline('.'))
792 norm! j
793 call assert_equal('50/*{{{*/', getline('.'))
794 norm! j
795 call assert_equal('52', getline('.'))
796
797 49
798 norm! 5zF
799 norm! k
800 call assert_equal('48', getline('.'))
801 norm! j
802 call assert_equal('49/*{{{*/', getline('.'))
803 norm! j
804 call assert_equal('55', getline('.'))
805 49
806 norm! za
807 call assert_equal('49/*{{{*/', getline('.'))
808 norm! j
809 call assert_equal('50/*{{{*/', getline('.'))
810 norm! j
811 call assert_equal('52', getline('.'))
812 set nofoldenable
813 " close fold and set foldenable
814 norm! za
815 call assert_equal(1, &foldenable)
816
817 50
818 " have to use {count}za to open all folds and make the cursor visible
819 norm! 2za
820 norm! 2k
821 call assert_equal('48', getline('.'))
822 norm! j
823 call assert_equal('49/*{{{*/', getline('.'))
824 norm! j
825 call assert_equal('50/*{{{*/', getline('.'))
826 norm! j
827 call assert_equal('51/*}}}*/', getline('.'))
828 norm! j
829 call assert_equal('52', getline('.'))
830
831 " Test for zA
832 49
833 set foldlevel=0
834 50
835 norm! zA
836 norm! 2k
837 call assert_equal('48', getline('.'))
838 norm! j
839 call assert_equal('49/*{{{*/', getline('.'))
840 norm! j
841 call assert_equal('50/*{{{*/', getline('.'))
842 norm! j
843 call assert_equal('51/*}}}*/', getline('.'))
844 norm! j
845 call assert_equal('52', getline('.'))
846
847 " zA on a opened fold when foldenale is not set
848 50
849 set nofoldenable
850 norm! zA
851 call assert_equal(1, &foldenable)
852 norm! k
853 call assert_equal('48', getline('.'))
854 norm! j
855 call assert_equal('49/*{{{*/', getline('.'))
856 norm! j
857 call assert_equal('55', getline('.'))
858
859 " Test for zc
860 norm! zE
861 50
862 norm! 2zF
863 49
864 norm! 5zF
865 set nofoldenable
866 50
867 " There most likely is a bug somewhere:
868 " https://groups.google.com/d/msg/vim_dev/v2EkfJ_KQjI/u-Cvv94uCAAJ
869 " TODO: Should this only close the inner most fold or both folds?
870 norm! zc
871 call assert_equal(1, &foldenable)
872 norm! k
873 call assert_equal('48', getline('.'))
874 norm! j
875 call assert_equal('49/*{{{*/', getline('.'))
876 norm! j
877 call assert_equal('55', getline('.'))
878 set nofoldenable
879 50
880 norm! Vjzc
881 norm! k
882 call assert_equal('48', getline('.'))
883 norm! j
884 call assert_equal('49/*{{{*/', getline('.'))
885 norm! j
886 call assert_equal('55', getline('.'))
887
888 " Test for zC
889 set nofoldenable
890 50
891 norm! zCk
892 call assert_equal('48', getline('.'))
893 norm! j
894 call assert_equal('49/*{{{*/', getline('.'))
895 norm! j
896 call assert_equal('55', getline('.'))
897
898 " Test for zx
899 " 1) close folds at line 49-54
900 set nofoldenable
901 48
902 norm! zx
903 call assert_equal(1, &foldenable)
904 norm! j
905 call assert_equal('49/*{{{*/', getline('.'))
906 norm! j
907 call assert_equal('55', getline('.'))
908
909 " 2) do not close fold under curser
910 51
911 set nofoldenable
912 norm! zx
913 call assert_equal(1, &foldenable)
914 norm! 3k
915 call assert_equal('48', getline('.'))
916 norm! j
917 call assert_equal('49/*{{{*/', getline('.'))
918 norm! j
919 call assert_equal('50/*{{{*/', getline('.'))
920 norm! j
921 call assert_equal('51/*}}}*/', getline('.'))
922 norm! j
923 call assert_equal('52', getline('.'))
924 norm! j
925 call assert_equal('53', getline('.'))
926 norm! j
927 call assert_equal('54/*}}}*/', getline('.'))
928 norm! j
929 call assert_equal('55', getline('.'))
930
931 " 3) close one level of folds
932 48
933 set nofoldenable
934 set foldlevel=1
935 norm! zx
936 call assert_equal(1, &foldenable)
937 call assert_equal('48', getline('.'))
938 norm! j
939 call assert_equal('49/*{{{*/', getline('.'))
940 norm! j
941 call assert_equal('50/*{{{*/', getline('.'))
942 norm! j
943 call assert_equal('52', getline('.'))
944 norm! j
945 call assert_equal('53', getline('.'))
946 norm! j
947 call assert_equal('54/*}}}*/', getline('.'))
948 norm! j
949 call assert_equal('55', getline('.'))
950
951 " Test for zX
952 " Close all folds
953 set foldlevel=0 nofoldenable
954 50
955 norm! zX
956 call assert_equal(1, &foldenable)
957 norm! k
958 call assert_equal('48', getline('.'))
959 norm! j
960 call assert_equal('49/*{{{*/', getline('.'))
961 norm! j
962 call assert_equal('55', getline('.'))
963
964 " Test for zm
965 50
966 set nofoldenable foldlevel=2
967 norm! zm
968 call assert_equal(1, &foldenable)
969 call assert_equal(1, &foldlevel)
970 norm! zm
971 call assert_equal(0, &foldlevel)
972 norm! zm
973 call assert_equal(0, &foldlevel)
974 norm! k
975 call assert_equal('48', getline('.'))
976 norm! j
977 call assert_equal('49/*{{{*/', getline('.'))
978 norm! j
979 call assert_equal('55', getline('.'))
980
981 " Test for zM
982 48
983 set nofoldenable foldlevel=99
984 norm! zM
985 call assert_equal(1, &foldenable)
986 call assert_equal(0, &foldlevel)
987 call assert_equal('48', getline('.'))
988 norm! j
989 call assert_equal('49/*{{{*/', getline('.'))
990 norm! j
991 call assert_equal('55', getline('.'))
992
993 " Test for zr
994 48
995 set nofoldenable foldlevel=0
996 norm! zr
997 call assert_equal(0, &foldenable)
998 call assert_equal(1, &foldlevel)
999 set foldlevel=0 foldenable
1000 norm! zr
1001 call assert_equal(1, &foldenable)
1002 call assert_equal(1, &foldlevel)
1003 norm! zr
1004 call assert_equal(2, &foldlevel)
1005 call assert_equal('48', getline('.'))
1006 norm! j
1007 call assert_equal('49/*{{{*/', getline('.'))
1008 norm! j
1009 call assert_equal('50/*{{{*/', getline('.'))
1010 norm! j
1011 call assert_equal('51/*}}}*/', getline('.'))
1012 norm! j
1013 call assert_equal('52', getline('.'))
1014
1015 " Test for zR
1016 48
1017 set nofoldenable foldlevel=0
1018 norm! zR
1019 call assert_equal(0, &foldenable)
1020 call assert_equal(2, &foldlevel)
1021 set foldenable foldlevel=0
1022 norm! zR
1023 call assert_equal(1, &foldenable)
1024 call assert_equal(2, &foldlevel)
1025 call assert_equal('48', getline('.'))
1026 norm! j
1027 call assert_equal('49/*{{{*/', getline('.'))
1028 norm! j
1029 call assert_equal('50/*{{{*/', getline('.'))
1030 norm! j
1031 call assert_equal('51/*}}}*/', getline('.'))
1032 norm! j
1033 call assert_equal('52', getline('.'))
1034 call append(50, ['a /*{{{*/', 'b /*}}}*/'])
1035 48
1036 call assert_equal('48', getline('.'))
1037 norm! j
1038 call assert_equal('49/*{{{*/', getline('.'))
1039 norm! j
1040 call assert_equal('50/*{{{*/', getline('.'))
1041 norm! j
1042 call assert_equal('a /*{{{*/', getline('.'))
1043 norm! j
1044 call assert_equal('51/*}}}*/', getline('.'))
1045 norm! j
1046 call assert_equal('52', getline('.'))
1047 48
1048 norm! zR
1049 call assert_equal(1, &foldenable)
1050 call assert_equal(3, &foldlevel)
1051 call assert_equal('48', getline('.'))
1052 norm! j
1053 call assert_equal('49/*{{{*/', getline('.'))
1054 norm! j
1055 call assert_equal('50/*{{{*/', getline('.'))
1056 norm! j
1057 call assert_equal('a /*{{{*/', getline('.'))
1058 norm! j
1059 call assert_equal('b /*}}}*/', getline('.'))
1060 norm! j
1061 call assert_equal('51/*}}}*/', getline('.'))
1062 norm! j
1063 call assert_equal('52', getline('.'))
1064
1065 " clean up
1066 setl nofoldenable fdm=marker foldlevel=0
1067 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02001068endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001069
1070func! Test_normal19_z_spell()
1071 if !has("spell") || !has('syntax')
1072 return
1073 endif
1074 new
1075 call append(0, ['1 good', '2 goood', '3 goood'])
1076 set spell spellfile=./Xspellfile.add spelllang=en
1077 let oldlang=v:lang
1078 lang C
1079
1080 " Test for zg
1081 1
1082 norm! ]s
1083 call assert_equal('2 goood', getline('.'))
1084 norm! zg
1085 1
1086 let a=execute('unsilent :norm! ]s')
1087 call assert_equal('1 good', getline('.'))
1088 call assert_equal('search hit BOTTOM, continuing at TOP', a[1:])
1089 let cnt=readfile('./Xspellfile.add')
1090 call assert_equal('goood', cnt[0])
1091
1092 " Test for zw
1093 2
1094 norm! $zw
1095 1
1096 norm! ]s
1097 call assert_equal('2 goood', getline('.'))
1098 let cnt=readfile('./Xspellfile.add')
1099 call assert_equal('#oood', cnt[0])
1100 call assert_equal('goood/!', cnt[1])
1101
1102 " Test for zg in visual mode
1103 let a=execute('unsilent :norm! V$zg')
1104 call assert_equal("Word '2 goood' added to ./Xspellfile.add", a[1:])
1105 1
1106 norm! ]s
1107 call assert_equal('3 goood', getline('.'))
1108 let cnt=readfile('./Xspellfile.add')
1109 call assert_equal('2 goood', cnt[2])
1110 " Remove "2 good" from spellfile
1111 2
1112 let a=execute('unsilent norm! V$zw')
1113 call assert_equal("Word '2 goood' added to ./Xspellfile.add", a[1:])
1114 let cnt=readfile('./Xspellfile.add')
1115 call assert_equal('2 goood/!', cnt[3])
1116
1117 " Test for zG
1118 let a=execute('unsilent norm! V$zG')
1119 call assert_match("Word '2 goood' added to .*", a)
1120 let fname=matchstr(a, 'to\s\+\zs\f\+$')
1121 let cnt=readfile(fname)
1122 call assert_equal('2 goood', cnt[0])
1123
1124 " Test for zW
1125 let a=execute('unsilent norm! V$zW')
1126 call assert_match("Word '2 goood' added to .*", a)
1127 let cnt=readfile(fname)
1128 call assert_equal('# goood', cnt[0])
1129 call assert_equal('2 goood/!', cnt[1])
1130
1131 " Test for zuW
1132 let a=execute('unsilent norm! V$zuW')
1133 call assert_match("Word '2 goood' removed from .*", a)
1134 let cnt=readfile(fname)
1135 call assert_equal('# goood', cnt[0])
1136 call assert_equal('# goood/!', cnt[1])
1137
1138 " Test for zuG
1139 let a=execute('unsilent norm! $zG')
1140 call assert_match("Word 'goood' added to .*", a)
1141 let cnt=readfile(fname)
1142 call assert_equal('# goood', cnt[0])
1143 call assert_equal('# goood/!', cnt[1])
1144 call assert_equal('goood', cnt[2])
1145 let a=execute('unsilent norm! $zuG')
1146 let cnt=readfile(fname)
1147 call assert_match("Word 'goood' removed from .*", a)
1148 call assert_equal('# goood', cnt[0])
1149 call assert_equal('# goood/!', cnt[1])
1150 call assert_equal('#oood', cnt[2])
1151 " word not found in wordlist
1152 let a=execute('unsilent norm! V$zuG')
1153 let cnt=readfile(fname)
1154 call assert_match("", a)
1155 call assert_equal('# goood', cnt[0])
1156 call assert_equal('# goood/!', cnt[1])
1157 call assert_equal('#oood', cnt[2])
1158
1159 " Test for zug
1160 call delete('./Xspellfile.add')
1161 2
1162 let a=execute('unsilent norm! $zg')
1163 let cnt=readfile('./Xspellfile.add')
1164 call assert_equal('goood', cnt[0])
1165 let a=execute('unsilent norm! $zug')
1166 call assert_match("Word 'goood' removed from \./Xspellfile.add", a)
1167 let cnt=readfile('./Xspellfile.add')
1168 call assert_equal('#oood', cnt[0])
1169 " word not in wordlist
1170 let a=execute('unsilent norm! V$zug')
1171 call assert_match('', a)
1172 let cnt=readfile('./Xspellfile.add')
1173 call assert_equal('#oood', cnt[0])
1174
1175 " Test for zuw
1176 call delete('./Xspellfile.add')
1177 2
1178 let a=execute('unsilent norm! Vzw')
1179 let cnt=readfile('./Xspellfile.add')
1180 call assert_equal('2 goood/!', cnt[0])
1181 let a=execute('unsilent norm! Vzuw')
1182 call assert_match("Word '2 goood' removed from \./Xspellfile.add", a)
1183 let cnt=readfile('./Xspellfile.add')
1184 call assert_equal('# goood/!', cnt[0])
1185 " word not in wordlist
1186 let a=execute('unsilent norm! $zug')
1187 call assert_match('', a)
1188 let cnt=readfile('./Xspellfile.add')
1189 call assert_equal('# goood/!', cnt[0])
1190
1191 " add second entry to spellfile setting
1192 set spellfile=./Xspellfile.add,./Xspellfile2.add
1193 call delete('./Xspellfile.add')
1194 2
1195 let a=execute('unsilent norm! $2zg')
1196 let cnt=readfile('./Xspellfile2.add')
1197 call assert_match("Word 'goood' added to ./Xspellfile2.add", a)
1198 call assert_equal('goood', cnt[0])
1199
1200 " clean up
1201 exe "lang" oldlang
1202 call delete("./Xspellfile.add")
1203 call delete("./Xspellfile2.add")
Bram Moolenaardf0db162016-09-06 20:37:41 +02001204 call delete("./Xspellfile.add.spl")
1205 call delete("./Xspellfile2.add.spl")
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001206
1207 " zux -> no-op
1208 2
1209 norm! $zux
1210 call assert_equal([], glob('Xspellfile.add',0,1))
1211 call assert_equal([], glob('Xspellfile2.add',0,1))
1212
1213 set spellfile=
1214 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02001215endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001216
1217func! Test_normal20_exmode()
Bram Moolenaar0913a102016-09-03 19:11:59 +02001218 if !has("unix")
1219 " Reading from redirected file doesn't work on MS-Windows
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001220 return
1221 endif
1222 call writefile(['1a', 'foo', 'bar', '.', 'w! Xfile2', 'q!'], 'Xscript')
1223 call writefile(['1', '2'], 'Xfile')
1224 call system(v:progpath .' -e -s < Xscript Xfile')
1225 let a=readfile('Xfile2')
1226 call assert_equal(['1', 'foo', 'bar', '2'], a)
1227
1228 " clean up
1229 for file in ['Xfile', 'Xfile2', 'Xscript']
1230 call delete(file)
1231 endfor
1232 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02001233endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001234
1235func! Test_normal21_nv_hat()
1236 set hidden
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02001237 new
1238 " to many buffers opened already, will not work
1239 "call assert_fails(":b#", 'E23')
1240 "call assert_equal('', @#)
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001241 e Xfoobar
1242 e Xfile2
1243 call feedkeys("\<c-^>", 't')
1244 call assert_equal("Xfile2", fnamemodify(bufname('%'), ':t'))
1245 call feedkeys("f\<c-^>", 't')
1246 call assert_equal("Xfile2", fnamemodify(bufname('%'), ':t'))
1247 " clean up
1248 set nohidden
1249 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02001250endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001251
1252func! Test_normal22_zet()
1253 " Test for ZZ
Bram Moolenaar0913a102016-09-03 19:11:59 +02001254 " let shell = &shell
1255 " let &shell = 'sh'
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001256 call writefile(['1', '2'], 'Xfile')
1257 let args = ' -u NONE -N -U NONE -i NONE --noplugins -X --not-a-term'
1258 call system(v:progpath . args . ' -c "%d" -c ":norm! ZZ" Xfile')
1259 let a = readfile('Xfile')
1260 call assert_equal([], a)
1261 " Test for ZQ
1262 call writefile(['1', '2'], 'Xfile')
1263 call system(v:progpath . args . ' -c "%d" -c ":norm! ZQ" Xfile')
1264 let a = readfile('Xfile')
1265 call assert_equal(['1', '2'], a)
1266
1267 " clean up
1268 for file in ['Xfile']
1269 call delete(file)
1270 endfor
Bram Moolenaar0913a102016-09-03 19:11:59 +02001271 " let &shell = shell
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02001272endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001273
1274func! Test_normal23_K()
1275 " Test for K command
1276 new
Bram Moolenaar426f3752016-11-04 21:22:37 +01001277 call append(0, ['version8.txt', 'man', 'aa%bb', 'cc|dd'])
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001278 let k = &keywordprg
1279 set keywordprg=:help
1280 1
1281 norm! VK
1282 call assert_equal('version8.txt', fnamemodify(bufname('%'), ':t'))
1283 call assert_equal('help', &ft)
1284 call assert_match('\*version8.txt\*', getline('.'))
1285 helpclose
1286 norm! 0K
1287 call assert_equal('version8.txt', fnamemodify(bufname('%'), ':t'))
1288 call assert_equal('help', &ft)
1289 call assert_match('\*version8\.0\*', getline('.'))
1290 helpclose
1291
Bram Moolenaar426f3752016-11-04 21:22:37 +01001292 set keywordprg=:new
1293 set iskeyword+=%
1294 set iskeyword+=\|
1295 2
1296 norm! K
1297 call assert_equal('man', fnamemodify(bufname('%'), ':t'))
1298 bwipe!
1299 3
1300 norm! K
1301 call assert_equal('aa%bb', fnamemodify(bufname('%'), ':t'))
1302 bwipe!
Bram Moolenaareb828d02016-11-05 19:54:01 +01001303 if !has('win32')
1304 4
1305 norm! K
1306 call assert_equal('cc|dd', fnamemodify(bufname('%'), ':t'))
1307 bwipe!
1308 endif
Bram Moolenaar426f3752016-11-04 21:22:37 +01001309 set iskeyword-=%
1310 set iskeyword-=\|
1311
Bram Moolenaar0913a102016-09-03 19:11:59 +02001312 " Only expect "man" to work on Unix
1313 if !has("unix")
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001314 let &keywordprg = k
1315 bw!
1316 return
1317 endif
1318 set keywordprg=man\ --pager=cat
1319 " Test for using man
1320 2
1321 let a = execute('unsilent norm! K')
1322 call assert_match("man --pager=cat 'man'", a)
1323
1324 " clean up
1325 let &keywordprg = k
1326 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02001327endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001328
1329func! Test_normal24_rot13()
1330 " This test uses multi byte characters
1331 if !has("multi_byte")
1332 return
1333 endif
1334 " Testing for g?? g?g?
1335 new
1336 call append(0, 'abcdefghijklmnopqrstuvwxyzäüö')
1337 1
1338 norm! g??
1339 call assert_equal('nopqrstuvwxyzabcdefghijklmäüö', getline('.'))
1340 norm! g?g?
1341 call assert_equal('abcdefghijklmnopqrstuvwxyzäüö', getline('.'))
1342
1343 " clean up
1344 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02001345endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001346
1347func! Test_normal25_tag()
1348 " Testing for CTRL-] g CTRL-] g]
1349 " CTRL-W g] CTRL-W CTRL-] CTRL-W g CTRL-]
1350 h
1351 " Test for CTRL-]
1352 call search('\<x\>$')
1353 exe "norm! \<c-]>"
1354 call assert_equal("change.txt", fnamemodify(bufname('%'), ':t'))
1355 norm! yiW
1356 call assert_equal("*x*", @0)
1357 exe ":norm \<c-o>"
1358
1359 " Test for g_CTRL-]
1360 call search('\<v_u\>$')
1361 exe "norm! g\<c-]>"
1362 call assert_equal("change.txt", fnamemodify(bufname('%'), ':t'))
1363 norm! yiW
1364 call assert_equal("*v_u*", @0)
1365 exe ":norm \<c-o>"
1366
1367 " Test for g]
1368 call search('\<i_<Esc>$')
1369 let a = execute(":norm! g]")
1370 call assert_match('i_<Esc>.*insert.txt', a)
1371
1372 if !empty(exepath('cscope')) && has('cscope')
1373 " setting cscopetag changes how g] works
1374 set cst
1375 exe "norm! g]"
1376 call assert_equal("insert.txt", fnamemodify(bufname('%'), ':t'))
1377 norm! yiW
1378 call assert_equal("*i_<Esc>*", @0)
1379 exe ":norm \<c-o>"
1380 " Test for CTRL-W g]
1381 exe "norm! \<C-W>g]"
1382 call assert_equal("insert.txt", fnamemodify(bufname('%'), ':t'))
1383 norm! yiW
1384 call assert_equal("*i_<Esc>*", @0)
1385 call assert_equal(3, winnr('$'))
1386 helpclose
1387 set nocst
1388 endif
1389
1390 " Test for CTRL-W g]
1391 let a = execute("norm! \<C-W>g]")
1392 call assert_match('i_<Esc>.*insert.txt', a)
1393
1394 " Test for CTRL-W CTRL-]
1395 exe "norm! \<C-W>\<C-]>"
1396 call assert_equal("insert.txt", fnamemodify(bufname('%'), ':t'))
1397 norm! yiW
1398 call assert_equal("*i_<Esc>*", @0)
1399 call assert_equal(3, winnr('$'))
1400 helpclose
1401
1402 " Test for CTRL-W g CTRL-]
1403 exe "norm! \<C-W>g\<C-]>"
1404 call assert_equal("insert.txt", fnamemodify(bufname('%'), ':t'))
1405 norm! yiW
1406 call assert_equal("*i_<Esc>*", @0)
1407 call assert_equal(3, winnr('$'))
1408 helpclose
1409
1410 " clean up
1411 helpclose
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02001412endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001413
1414func! Test_normal26_put()
1415 " Test for ]p ]P [p and [P
1416 new
1417 call append(0, ['while read LINE', 'do', ' ((count++))', ' if [ $? -ne 0 ]; then', " echo 'Error writing file'", ' fi', 'done'])
1418 1
1419 /Error/y a
1420 2
1421 norm! "a]pj"a[p
1422 call assert_equal(['do', "echo 'Error writing file'", " echo 'Error writing file'", ' ((count++))'], getline(2,5))
1423 1
1424 /^\s\{4}/
1425 exe "norm! \"a]P3Eldt'"
1426 exe "norm! j\"a[P2Eldt'"
1427 call assert_equal([' if [ $? -ne 0 ]; then', " echo 'Error writing'", " echo 'Error'", " echo 'Error writing file'", ' fi'], getline(6,10))
1428
1429 " clean up
1430 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02001431endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001432
1433func! Test_normal27_bracket()
1434 " Test for [' [` ]' ]`
1435 call Setup_NewWindow()
1436 1,21s/.\+/ & b/
1437 1
1438 norm! $ma
1439 5
1440 norm! $mb
1441 10
1442 norm! $mc
1443 15
1444 norm! $md
1445 20
1446 norm! $me
1447
1448 " Test for ['
1449 9
1450 norm! 2['
1451 call assert_equal(' 1 b', getline('.'))
1452 call assert_equal(1, line('.'))
1453 call assert_equal(3, col('.'))
1454
1455 " Test for ]'
1456 norm! ]'
1457 call assert_equal(' 5 b', getline('.'))
1458 call assert_equal(5, line('.'))
1459 call assert_equal(3, col('.'))
1460
1461 " No mark after line 21, cursor moves to first non blank on current line
1462 21
1463 norm! $]'
1464 call assert_equal(' 21 b', getline('.'))
1465 call assert_equal(21, line('.'))
1466 call assert_equal(3, col('.'))
1467
1468 " Test for [`
1469 norm! 2[`
1470 call assert_equal(' 15 b', getline('.'))
1471 call assert_equal(15, line('.'))
1472 call assert_equal(8, col('.'))
1473
1474 " Test for ]`
1475 norm! ]`
1476 call assert_equal(' 20 b', getline('.'))
1477 call assert_equal(20, line('.'))
1478 call assert_equal(8, col('.'))
1479
1480 " clean up
1481 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02001482endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001483
1484func! Test_normal28_parenthesis()
1485 " basic testing for ( and )
1486 new
1487 call append(0, ['This is a test. With some sentences!', '', 'Even with a question? And one more. And no sentence here'])
1488
1489 $
1490 norm! d(
1491 call assert_equal(['This is a test. With some sentences!', '', 'Even with a question? And one more. ', ''], getline(1, '$'))
1492 norm! 2d(
1493 call assert_equal(['This is a test. With some sentences!', '', ' ', ''], getline(1, '$'))
1494 1
1495 norm! 0d)
1496 call assert_equal(['With some sentences!', '', ' ', ''], getline(1, '$'))
1497
1498 call append('$', ['This is a long sentence', '', 'spanning', 'over several lines. '])
1499 $
1500 norm! $d(
1501 call assert_equal(['With some sentences!', '', ' ', '', 'This is a long sentence', ''], getline(1, '$'))
1502
1503 " clean up
1504 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02001505endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001506
1507fun! Test_normal29_brace()
1508 " basic test for { and } movements
1509 let text= ['A paragraph begins after each empty line, and also at each of a set of',
1510 \ 'paragraph macros, specified by the pairs of characters in the ''paragraphs''',
1511 \ 'option. The default is "IPLPPPQPP TPHPLIPpLpItpplpipbp", which corresponds to',
1512 \ 'the macros ".IP", ".LP", etc. (These are nroff macros, so the dot must be in',
1513 \ 'the first column). A section boundary is also a paragraph boundary.',
1514 \ 'Note that a blank line (only containing white space) is NOT a paragraph',
1515 \ 'boundary.',
1516 \ '',
1517 \ '',
1518 \ 'Also note that this does not include a ''{'' or ''}'' in the first column. When',
1519 \ 'the ''{'' flag is in ''cpoptions'' then ''{'' in the first column is used as a',
1520 \ 'paragraph boundary |posix|.',
1521 \ '{',
1522 \ 'This is no paragaraph',
1523 \ 'unless the ''{'' is set',
1524 \ 'in ''cpoptions''',
1525 \ '}',
1526 \ '.IP',
1527 \ 'The nroff macros IP seperates a paragraph',
1528 \ 'That means, it must be a ''.''',
1529 \ 'followed by IP',
1530 \ '.LPIt does not matter, if afterwards some',
1531 \ 'more characters follow.',
1532 \ '.SHAlso section boundaries from the nroff',
1533 \ 'macros terminate a paragraph. That means',
1534 \ 'a character like this:',
1535 \ '.NH',
1536 \ 'End of text here']
1537 new
1538 call append(0, text)
1539 1
1540 norm! 0d2}
1541 call assert_equal(['.IP',
1542 \ 'The nroff macros IP seperates a paragraph', 'That means, it must be a ''.''', 'followed by IP',
1543 \ '.LPIt does not matter, if afterwards some', 'more characters follow.', '.SHAlso section boundaries from the nroff',
1544 \ 'macros terminate a paragraph. That means', 'a character like this:', '.NH', 'End of text here', ''], getline(1,'$'))
1545 norm! 0d}
1546 call assert_equal(['.LPIt does not matter, if afterwards some', 'more characters follow.',
1547 \ '.SHAlso section boundaries from the nroff', 'macros terminate a paragraph. That means',
1548 \ 'a character like this:', '.NH', 'End of text here', ''], getline(1, '$'))
1549 $
1550 norm! d{
1551 call assert_equal(['.LPIt does not matter, if afterwards some', 'more characters follow.',
1552 \ '.SHAlso section boundaries from the nroff', 'macros terminate a paragraph. That means', 'a character like this:', ''], getline(1, '$'))
1553 norm! d{
1554 call assert_equal(['.LPIt does not matter, if afterwards some', 'more characters follow.', ''], getline(1,'$'))
1555 " Test with { in cpooptions
1556 %d
1557 call append(0, text)
1558 set cpo+={
1559 1
1560 norm! 0d2}
1561 call assert_equal(['{', 'This is no paragaraph', 'unless the ''{'' is set', 'in ''cpoptions''', '}',
1562 \ '.IP', 'The nroff macros IP seperates a paragraph', 'That means, it must be a ''.''',
1563 \ 'followed by IP', '.LPIt does not matter, if afterwards some', 'more characters follow.',
1564 \ '.SHAlso section boundaries from the nroff', 'macros terminate a paragraph. That means',
1565 \ 'a character like this:', '.NH', 'End of text here', ''], getline(1,'$'))
1566 $
1567 norm! d}
1568 call assert_equal(['{', 'This is no paragaraph', 'unless the ''{'' is set', 'in ''cpoptions''', '}',
1569 \ '.IP', 'The nroff macros IP seperates a paragraph', 'That means, it must be a ''.''',
1570 \ 'followed by IP', '.LPIt does not matter, if afterwards some', 'more characters follow.',
1571 \ '.SHAlso section boundaries from the nroff', 'macros terminate a paragraph. That means',
1572 \ 'a character like this:', '.NH', 'End of text here', ''], getline(1,'$'))
1573 norm! gg}
1574 norm! d5}
1575 call assert_equal(['{', 'This is no paragaraph', 'unless the ''{'' is set', 'in ''cpoptions''', '}', ''], getline(1,'$'))
1576
1577 " clean up
1578 set cpo-={
1579 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02001580endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001581
1582fun! Test_normal30_changecase()
1583 " This test uses multi byte characters
1584 if !has("multi_byte")
1585 return
1586 endif
1587 new
1588 call append(0, 'This is a simple test: äüöß')
1589 norm! 1ggVu
1590 call assert_equal('this is a simple test: äüöß', getline('.'))
1591 norm! VU
1592 call assert_equal('THIS IS A SIMPLE TEST: ÄÜÖSS', getline('.'))
1593 norm! guu
1594 call assert_equal('this is a simple test: äüöss', getline('.'))
1595 norm! gUgU
1596 call assert_equal('THIS IS A SIMPLE TEST: ÄÜÖSS', getline('.'))
1597 norm! gugu
1598 call assert_equal('this is a simple test: äüöss', getline('.'))
1599 norm! gUU
1600 call assert_equal('THIS IS A SIMPLE TEST: ÄÜÖSS', getline('.'))
1601 norm! 010~
1602 call assert_equal('this is a SIMPLE TEST: ÄÜÖSS', getline('.'))
1603 norm! V~
1604 call assert_equal('THIS IS A simple test: äüöss', getline('.'))
1605
1606 " clean up
1607 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02001608endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001609
1610fun! Test_normal31_r_cmd()
1611 " Test for r command
1612 new
1613 call append(0, 'This is a simple test: abcd')
1614 exe "norm! 1gg$r\<cr>"
1615 call assert_equal(['This is a simple test: abc', '', ''], getline(1,'$'))
1616 exe "norm! 1gg2wlr\<cr>"
1617 call assert_equal(['This is a', 'simple test: abc', '', ''], getline(1,'$'))
1618 exe "norm! 2gg0W5r\<cr>"
1619 call assert_equal(['This is a', 'simple ', ' abc', '', ''], getline('1', '$'))
1620 set autoindent
1621 call setline(2, ['simple test: abc', ''])
1622 exe "norm! 2gg0W5r\<cr>"
1623 call assert_equal(['This is a', 'simple ', 'abc', '', '', ''], getline('1', '$'))
1624 exe "norm! 1ggVr\<cr>"
1625 call assert_equal('^M^M^M^M^M^M^M^M^M', strtrans(getline(1)))
1626 call setline(1, 'This is a')
1627 exe "norm! 1gg05rf"
1628 call assert_equal('fffffis a', getline(1))
1629
1630 " clean up
1631 set noautoindent
1632 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02001633endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001634
1635func! Test_normal32_g_cmd1()
1636 " Test for g*, g#
1637 new
1638 call append(0, ['abc.x_foo', 'x_foobar.abc'])
1639 1
1640 norm! $g*
1641 call assert_equal('x_foo', @/)
1642 call assert_equal('x_foobar.abc', getline('.'))
1643 norm! $g#
1644 call assert_equal('abc', @/)
1645 call assert_equal('abc.x_foo', getline('.'))
1646
1647 " clean up
1648 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02001649endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001650
1651fun! Test_normal33_g_cmd2()
1652 if !has("jumplist")
1653 return
1654 endif
1655 " Tests for g cmds
1656 call Setup_NewWindow()
1657 " Test for g`
1658 clearjumps
1659 norm! ma10j
1660 let a=execute(':jumps')
1661 " empty jumplist
1662 call assert_equal('>', a[-1:])
1663 norm! g`a
1664 call assert_equal('>', a[-1:])
1665 call assert_equal(1, line('.'))
1666 call assert_equal('1', getline('.'))
1667
1668 " Test for g; and g,
1669 norm! g;
1670 " there is only one change in the changelist
1671 " currently, when we setup the window
1672 call assert_equal(2, line('.'))
1673 call assert_fails(':norm! g;', 'E662')
1674 call assert_fails(':norm! g,', 'E663')
1675 let &ul=&ul
1676 call append('$', ['a', 'b', 'c', 'd'])
1677 let &ul=&ul
1678 call append('$', ['Z', 'Y', 'X', 'W'])
1679 let a = execute(':changes')
1680 call assert_match('2\s\+0\s\+2', a)
1681 call assert_match('101\s\+0\s\+a', a)
1682 call assert_match('105\s\+0\s\+Z', a)
1683 norm! 3g;
1684 call assert_equal(2, line('.'))
1685 norm! 2g,
1686 call assert_equal(105, line('.'))
1687
1688 " Test for g& - global substitute
1689 %d
1690 call setline(1, range(1,10))
1691 call append('$', ['a', 'b', 'c', 'd'])
1692 $s/\w/&&/g
1693 exe "norm! /[1-8]\<cr>"
1694 norm! g&
1695 call assert_equal(['11', '22', '33', '44', '55', '66', '77', '88', '9', '110', 'a', 'b', 'c', 'dd'], getline(1, '$'))
1696
1697 " Test for gv
1698 %d
1699 call append('$', repeat(['abcdefgh'], 8))
1700 exe "norm! 2gg02l\<c-v>2j2ly"
1701 call assert_equal(['cde', 'cde', 'cde'], getreg(0, 1, 1))
1702 " in visual mode, gv swaps current and last selected region
1703 exe "norm! G0\<c-v>4k4lgvd"
1704 call assert_equal(['', 'abfgh', 'abfgh', 'abfgh', 'abcdefgh', 'abcdefgh', 'abcdefgh', 'abcdefgh', 'abcdefgh'], getline(1,'$'))
1705 exe "norm! G0\<c-v>4k4ly"
1706 exe "norm! gvood"
1707 call assert_equal(['', 'abfgh', 'abfgh', 'abfgh', 'fgh', 'fgh', 'fgh', 'fgh', 'fgh'], getline(1,'$'))
1708
1709 " Test for gk/gj
1710 %d
1711 15vsp
1712 set wrap listchars= sbr=
1713 let lineA='abcdefghijklmnopqrstuvwxyz'
1714 let lineB='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'
1715 $put =lineA
1716 $put =lineB
1717
1718 norm! 3gg0dgk
1719 call assert_equal(['', 'abcdefghijklmno', '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'], getline(1, '$'))
1720 set nu
1721 norm! 3gg0gjdgj
1722 call assert_equal(['', 'abcdefghijklmno', '0123456789AMNOPQRSTUVWXYZ'], getline(1,'$'))
1723
1724 " Test for gJ
1725 norm! 2gggJ
1726 call assert_equal(['', 'abcdefghijklmno0123456789AMNOPQRSTUVWXYZ'], getline(1,'$'))
1727 call assert_equal(16, col('.'))
1728 " shouldn't do anything
1729 norm! 10gJ
1730 call assert_equal(1, col('.'))
1731
1732 " Test for g0 g^ gm g$
1733 exe "norm! 2gg0gji "
1734 call assert_equal(['', 'abcdefghijk lmno0123456789AMNOPQRSTUVWXYZ'], getline(1,'$'))
1735 norm! g0yl
1736 call assert_equal(12, col('.'))
1737 call assert_equal(' ', getreg(0))
1738 norm! g$yl
1739 call assert_equal(22, col('.'))
1740 call assert_equal('3', getreg(0))
1741 norm! gmyl
1742 call assert_equal(17, col('.'))
1743 call assert_equal('n', getreg(0))
1744 norm! g^yl
1745 call assert_equal(15, col('.'))
1746 call assert_equal('l', getreg(0))
1747
1748 " Test for g Ctrl-G
Bram Moolenaar0913a102016-09-03 19:11:59 +02001749 set ff=unix
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001750 let a=execute(":norm! g\<c-g>")
1751 call assert_match('Col 15 of 43; Line 2 of 2; Word 2 of 2; Byte 16 of 45', a)
1752
1753 " Test for gI
1754 norm! gIfoo
1755 call assert_equal(['', 'fooabcdefghijk lmno0123456789AMNOPQRSTUVWXYZ'], getline(1,'$'))
1756
1757 " Test for gi
1758 wincmd c
1759 %d
1760 set tw=0
1761 call setline(1, ['foobar', 'new line'])
1762 norm! A next word
1763 $put ='third line'
1764 norm! gi another word
1765 call assert_equal(['foobar next word another word', 'new line', 'third line'], getline(1,'$'))
1766
1767 " clean up
1768 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02001769endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001770
1771fun! Test_normal34_g_cmd3()
1772 if !has("multi_byte")
1773 return
1774 endif
1775 " Test for g8
1776 new
1777 call append(0, 'abcdefghijklmnopqrstuvwxyzäüö')
1778 let a=execute(':norm! 1gg$g8')
1779 call assert_equal('c3 b6 ', a[1:])
1780
1781 " Test for gp gP
1782 call append(1, range(1,10))
1783 " clean up
1784 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02001785endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001786
1787fun! Test_normal35_g_cmd4()
1788 " Test for g<
1789 " Cannot capture its output,
1790 " probably a bug, therefore, test disabled:
Bram Moolenaar31845092016-09-05 22:58:31 +02001791 throw "Skipped: output of g< can't be tested currently"
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001792 echo "a\nb\nc\nd"
1793 let b=execute(':norm! g<')
1794 call assert_true(!empty(b), 'failed `execute(g<)`')
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02001795endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001796
1797fun! Test_normal36_g_cmd5()
1798 new
1799 call append(0, 'abcdefghijklmnopqrstuvwxyz')
Bram Moolenaar0913a102016-09-03 19:11:59 +02001800 set ff=unix
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001801 " Test for gp gP
1802 call append(1, range(1,10))
1803 1
1804 norm! 1yy
1805 3
1806 norm! gp
1807 call assert_equal([0, 5, 1, 0, 1], getcurpos())
1808 $
1809 norm! gP
1810 call assert_equal([0, 14, 1, 0, 1], getcurpos())
1811
1812 " Test for go
1813 norm! 26go
1814 call assert_equal([0, 1, 26, 0, 26], getcurpos())
1815 norm! 27go
1816 call assert_equal([0, 1, 26, 0, 26], getcurpos())
1817 norm! 28go
1818 call assert_equal([0, 2, 1, 0, 1], getcurpos())
1819 set ff=dos
1820 norm! 29go
1821 call assert_equal([0, 2, 1, 0, 1], getcurpos())
1822 set ff=unix
1823 norm! gg0
1824 norm! 101go
1825 call assert_equal([0, 13, 26, 0, 26], getcurpos())
1826 norm! 103go
1827 call assert_equal([0, 14, 1, 0, 1], getcurpos())
1828 " count > buffer content
1829 norm! 120go
1830 call assert_equal([0, 14, 1, 0, 2147483647], getcurpos())
1831 " clean up
1832 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02001833endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001834
1835fun! Test_normal37_g_cmd6()
1836 " basic test for gt and gT
1837 tabnew 1.txt
1838 tabnew 2.txt
1839 tabnew 3.txt
1840 norm! 1gt
1841 call assert_equal(1, tabpagenr())
1842 norm! 3gt
1843 call assert_equal(3, tabpagenr())
1844 norm! 1gT
1845 " count gT goes not to the absolute tabpagenumber
1846 " but, but goes to the count previous tabpagenumber
1847 call assert_equal(2, tabpagenr())
1848 " wrap around
1849 norm! 3gT
1850 call assert_equal(3, tabpagenr())
1851 " gt does not wrap around
1852 norm! 5gt
1853 call assert_equal(3, tabpagenr())
1854
1855 for i in range(3)
1856 tabclose
1857 endfor
1858 " clean up
1859 call assert_fails(':tabclose', 'E784')
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02001860endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001861
1862fun! Test_normal38_nvhome()
1863 " Test for <Home> and <C-Home> key
1864 new
1865 call setline(1, range(10))
1866 $
1867 setl et sw=2
1868 norm! V10>$
1869 " count is ignored
1870 exe "norm! 10\<home>"
1871 call assert_equal(1, col('.'))
1872 exe "norm! \<home>"
1873 call assert_equal([0, 10, 1, 0, 1], getcurpos())
1874 exe "norm! 5\<c-home>"
1875 call assert_equal([0, 5, 1, 0, 1], getcurpos())
1876 exe "norm! \<c-home>"
1877 call assert_equal([0, 1, 1, 0, 1], getcurpos())
1878
1879 " clean up
1880 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02001881endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001882
1883fun! Test_normal39_cw()
1884 " Test for cw and cW on whitespace
1885 " and cpo+=w setting
1886 new
1887 set tw=0
1888 call append(0, 'here are some words')
1889 norm! 1gg0elcwZZZ
1890 call assert_equal('hereZZZare some words', getline('.'))
1891 norm! 1gg0elcWYYY
1892 call assert_equal('hereZZZareYYYsome words', getline('.'))
1893 set cpo+=w
1894 call setline(1, 'here are some words')
1895 norm! 1gg0elcwZZZ
1896 call assert_equal('hereZZZ are some words', getline('.'))
1897 norm! 1gg2elcWYYY
1898 call assert_equal('hereZZZ areYYY some words', getline('.'))
1899 set cpo-=w
1900 norm! 2gg0cwfoo
1901 call assert_equal('foo', getline('.'))
1902
1903 " clean up
1904 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02001905endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001906
1907fun! Test_normal40_ctrl_bsl()
1908 " Basic test for CTRL-\ commands
1909 new
1910 call append(0, 'here are some words')
1911 exe "norm! 1gg0a\<C-\>\<C-N>"
1912 call assert_equal('n', mode())
1913 call assert_equal(1, col('.'))
1914 call assert_equal('', visualmode())
1915 exe "norm! 1gg0viw\<C-\>\<C-N>"
1916 call assert_equal('n', mode())
1917 call assert_equal(4, col('.'))
1918 exe "norm! 1gg0a\<C-\>\<C-G>"
1919 call assert_equal('n', mode())
1920 call assert_equal(1, col('.'))
1921 "imap <buffer> , <c-\><c-n>
1922 set im
1923 exe ":norm! \<c-\>\<c-n>dw"
1924 set noim
1925 call assert_equal('are some words', getline(1))
1926 call assert_false(&insertmode)
1927
1928 " clean up
1929 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02001930endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001931
1932fun! Test_normal41_insert_reg()
1933 " Test for <c-r>=, <c-r><c-r>= and <c-r><c-o>=
1934 " in insert mode
1935 new
1936 set sts=2 sw=2 ts=8 tw=0
1937 call append(0, ["aaa\tbbb\tccc", '', '', ''])
1938 let a=getline(1)
1939 norm! 2gg0
1940 exe "norm! a\<c-r>=a\<cr>"
1941 norm! 3gg0
1942 exe "norm! a\<c-r>\<c-r>=a\<cr>"
1943 norm! 4gg0
1944 exe "norm! a\<c-r>\<c-o>=a\<cr>"
1945 call assert_equal(['aaa bbb ccc', 'aaa bbb ccc', 'aaa bbb ccc', 'aaa bbb ccc', ''], getline(1, '$'))
1946
1947 " clean up
1948 set sts=0 sw=8 ts=8
Bram Moolenaar31845092016-09-05 22:58:31 +02001949 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02001950endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001951
1952func! Test_normal42_halfpage()
1953 " basic test for Ctrl-D and Ctrl-U
1954 call Setup_NewWindow()
1955 call assert_equal(5, &scroll)
1956 exe "norm! \<c-d>"
1957 call assert_equal('6', getline('.'))
1958 exe "norm! 2\<c-d>"
1959 call assert_equal('8', getline('.'))
1960 call assert_equal(2, &scroll)
1961 set scroll=5
1962 exe "norm! \<c-u>"
1963 call assert_equal('3', getline('.'))
1964 1
1965 set scrolloff=5
1966 exe "norm! \<c-d>"
1967 call assert_equal('10', getline('.'))
1968 exe "norm! \<c-u>"
1969 call assert_equal('5', getline('.'))
1970 1
1971 set scrolloff=99
1972 exe "norm! \<c-d>"
1973 call assert_equal('10', getline('.'))
1974 set scrolloff=0
1975 100
1976 exe "norm! $\<c-u>"
1977 call assert_equal('95', getline('.'))
1978 call assert_equal([0, 95, 1, 0, 1], getcurpos())
1979 100
1980 set nostartofline
1981 exe "norm! $\<c-u>"
1982 call assert_equal('95', getline('.'))
1983 call assert_equal([0, 95, 2, 0, 2147483647], getcurpos())
1984 " cleanup
1985 set startofline
1986 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02001987endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001988
1989fun! Test_normal43_textobject1()
1990 " basic tests for text object aw
1991 new
1992 call append(0, ['foobar,eins,foobar', 'foo,zwei,foo '])
1993 " diw
1994 norm! 1gg0diw
1995 call assert_equal([',eins,foobar', 'foo,zwei,foo ', ''], getline(1,'$'))
1996 " daw
1997 norm! 2ggEdaw
1998 call assert_equal([',eins,foobar', 'foo,zwei,', ''], getline(1, '$'))
1999 %d
2000 call append(0, ["foo\teins\tfoobar", "foo\tzwei\tfoo "])
2001 " diW
2002 norm! 2ggwd2iW
2003 call assert_equal(['foo eins foobar', 'foo foo ', ''], getline(1,'$'))
2004 " daW
2005 norm! 1ggd2aW
2006 call assert_equal(['foobar', 'foo foo ', ''], getline(1,'$'))
2007
2008 %d
2009 call append(0, ["foo\teins\tfoobar", "foo\tzwei\tfoo "])
2010 " aw in visual line mode switches to characterwise mode
2011 norm! 2gg$Vawd
2012 call assert_equal(['foo eins foobar', 'foo zwei foo'], getline(1,'$'))
2013 norm! 1gg$Viwd
2014 call assert_equal(['foo eins ', 'foo zwei foo'], getline(1,'$'))
2015
2016 " clean up
2017 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002018endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002019
2020func! Test_normal44_textobjects2()
2021 " basic testing for is and as text objects
2022 new
2023 call append(0, ['This is a test. With some sentences!', '', 'Even with a question? And one more. And no sentence here'])
2024 " Test for dis - does not remove trailing whitespace
2025 norm! 1gg0dis
2026 call assert_equal([' With some sentences!', '', 'Even with a question? And one more. And no sentence here', ''], getline(1,'$'))
2027 " Test for das - removes leading whitespace
2028 norm! 3ggf?ldas
2029 call assert_equal([' With some sentences!', '', 'Even with a question? And no sentence here', ''], getline(1,'$'))
2030 " when used in visual mode, is made characterwise
2031 norm! 3gg$Visy
2032 call assert_equal('v', visualmode())
2033 " reset visualmode()
2034 norm! 3ggVy
2035 norm! 3gg$Vasy
2036 call assert_equal('v', visualmode())
2037 " basic testing for textobjects a< and at
2038 %d
2039 call setline(1, ['<div> ','<a href="foobar" class="foo">xyz</a>',' </div>', ' '])
2040 " a<
2041 norm! 1gg0da<
2042 call assert_equal([' ', '<a href="foobar" class="foo">xyz</a>', ' </div>', ' '], getline(1,'$'))
2043 norm! 1pj
2044 call assert_equal([' <div>', '<a href="foobar" class="foo">xyz</a>', ' </div>', ' '], getline(1,'$'))
2045 " at
2046 norm! d2at
2047 call assert_equal([' '], getline(1,'$'))
2048 %d
2049 call setline(1, ['<div> ','<a href="foobar" class="foo">xyz</a>',' </div>', ' '])
2050 " i<
2051 norm! 1gg0di<
2052 call assert_equal(['<> ', '<a href="foobar" class="foo">xyz</a>', ' </div>', ' '], getline(1,'$'))
2053 norm! 1Pj
2054 call assert_equal(['<div> ', '<a href="foobar" class="foo">xyz</a>', ' </div>', ' '], getline(1,'$'))
2055 norm! d2it
2056 call assert_equal(['<div></div>',' '], getline(1,'$'))
2057 " basic testing for a[ and i[ text object
2058 %d
2059 call setline(1, [' ', '[', 'one [two]', 'thre', ']'])
2060 norm! 3gg0di[
2061 call assert_equal([' ', '[', ']'], getline(1,'$'))
2062 call setline(1, [' ', '[', 'one [two]', 'thre', ']'])
2063 norm! 3gg0ftd2a[
2064 call assert_equal([' '], getline(1,'$'))
2065 %d
2066 " Test for i" when cursor is in front of a quoted object
2067 call append(0, 'foo "bar"')
2068 norm! 1gg0di"
2069 call assert_equal(['foo ""', ''], getline(1,'$'))
2070
2071 " clean up
2072 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002073endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002074
2075func! Test_normal45_drop()
2076 if !has("dnd")
2077 return
2078 endif
2079 " basic test for :drop command
2080 " unfortunately, without a gui, we can't really test much here,
2081 " so simply test that ~p fails (which uses the drop register)
2082 new
2083 call assert_fails(':norm! "~p', 'E353')
2084 call assert_equal([], getreg('~', 1, 1))
2085 " the ~ register is read only
2086 call assert_fails(':let @~="1"', 'E354')
2087 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002088endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002089
2090func! Test_normal46_ignore()
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002091 " This test uses multi byte characters
2092 if !has("multi_byte")
2093 return
2094 endif
2095
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002096 new
2097 " How to test this?
2098 " let's just for now test, that the buffer
2099 " does not change
2100 call feedkeys("\<c-s>", 't')
2101 call assert_equal([''], getline(1,'$'))
2102
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002103 " no valid commands
2104 exe "norm! \<char-0x100>"
2105 call assert_equal([''], getline(1,'$'))
2106
2107 exe "norm! ä"
2108 call assert_equal([''], getline(1,'$'))
2109
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002110 " clean up
2111 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002112endfunc
Bram Moolenaarc4a908e2016-09-08 23:35:30 +02002113
2114func! Test_normal47_visual_buf_wipe()
2115 " This was causing a crash or ml_get error.
2116 enew!
2117 call setline(1,'xxx')
2118 normal $
2119 new
2120 call setline(1, range(1,2))
2121 2
2122 exe "norm \<C-V>$"
2123 bw!
2124 norm yp
2125 set nomodified
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002126endfunc
2127
2128func! Test_normal47_autocmd()
2129 " disabled, does not seem to be possible currently
2130 throw "Skipped: not possible to test cursorhold autocmd while waiting for input in normal_cmd"
2131 new
2132 call append(0, repeat('-',20))
2133 au CursorHold * call feedkeys('2l', '')
2134 1
2135 set updatetime=20
2136 " should delete 12 chars (d12l)
2137 call feedkeys('d1', '!')
2138 call assert_equal('--------', getline(1))
2139
2140 " clean up
2141 au! CursorHold
2142 set updatetime=4000
2143 bw!
2144endfunc
2145
2146func! Test_normal48_wincmd()
2147 new
2148 exe "norm! \<c-w>c"
2149 call assert_equal(1, winnr('$'))
2150 call assert_fails(":norm! \<c-w>c", "E444")
2151endfunc
2152
2153func! Test_normal49_counts()
2154 new
2155 call setline(1, 'one two three four five six seven eight nine ten')
2156 1
2157 norm! 3d2w
2158 call assert_equal('seven eight nine ten', getline(1))
2159 bw!
2160endfunc
2161
2162func! Test_normal50_commandline()
2163 if !has("timers") || !has("cmdline_hist") || !has("vertsplit")
2164 return
2165 endif
2166 func! DoTimerWork(id)
2167 call assert_equal('[Command Line]', bufname(''))
2168 " should fail, with E11, but does fail with E23?
2169 "call feedkeys("\<c-^>", 'tm')
2170
2171 " should also fail with E11
2172 call assert_fails(":wincmd p", 'E11')
2173 " return from commandline window
2174 call feedkeys("\<cr>")
2175 endfunc
2176
2177 let oldlang=v:lang
2178 lang C
2179 set updatetime=20
2180 call timer_start(100, 'DoTimerWork')
2181 try
2182 " throws E23, for whatever reason...
2183 call feedkeys('q:', 'x!')
2184 catch /E23/
2185 " no-op
2186 endtry
2187 " clean up
2188 set updatetime=4000
2189 exe "lang" oldlang
2190 bw!
2191endfunc
2192
2193func! Test_normal51_FileChangedRO()
2194 if !has("autocmd")
2195 return
2196 endif
Bram Moolenaare5f2a072017-02-01 22:31:49 +01002197 " Don't sleep after the warning message.
2198 call test_settime(1)
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002199 call writefile(['foo'], 'Xreadonly.log')
2200 new Xreadonly.log
2201 setl ro
2202 au FileChangedRO <buffer> :call feedkeys("\<c-^>", 'tix')
2203 call assert_fails(":norm! Af", 'E788')
2204 call assert_equal(['foo'], getline(1,'$'))
2205 call assert_equal('Xreadonly.log', bufname(''))
2206
2207 " cleanup
Bram Moolenaare5f2a072017-02-01 22:31:49 +01002208 call test_settime(0)
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002209 bw!
2210 call delete("Xreadonly.log")
2211endfunc
2212
2213func! Test_normal52_rl()
2214 if !has("rightleft")
2215 return
2216 endif
2217 new
2218 call setline(1, 'abcde fghij klmnopq')
2219 norm! 1gg$
2220 set rl
2221 call assert_equal(19, col('.'))
2222 call feedkeys('l', 'tx')
2223 call assert_equal(18, col('.'))
2224 call feedkeys('h', 'tx')
2225 call assert_equal(19, col('.'))
2226 call feedkeys("\<right>", 'tx')
2227 call assert_equal(18, col('.'))
2228 call feedkeys("\<s-right>", 'tx')
2229 call assert_equal(13, col('.'))
2230 call feedkeys("\<c-right>", 'tx')
2231 call assert_equal(7, col('.'))
2232 call feedkeys("\<c-left>", 'tx')
2233 call assert_equal(13, col('.'))
2234 call feedkeys("\<s-left>", 'tx')
2235 call assert_equal(19, col('.'))
2236 call feedkeys("<<", 'tx')
2237 call assert_equal(' abcde fghij klmnopq',getline(1))
2238 call feedkeys(">>", 'tx')
2239 call assert_equal('abcde fghij klmnopq',getline(1))
2240
2241 " cleanup
2242 set norl
2243 bw!
2244endfunc
2245
2246func! Test_normal53_digraph()
2247 if !has('digraphs')
2248 return
2249 endif
2250 new
2251 call setline(1, 'abcdefgh|')
2252 exe "norm! 1gg0f\<c-k>!!"
2253 call assert_equal(9, col('.'))
2254 set cpo+=D
2255 exe "norm! 1gg0f\<c-k>!!"
2256 call assert_equal(1, col('.'))
2257
2258 set cpo-=D
2259 bw!
2260endfunc
2261
2262func! Test_normal54_Ctrl_bsl()
2263 new
2264 call setline(1, 'abcdefghijklmn')
2265 exe "norm! df\<c-\>\<c-n>"
2266 call assert_equal(['abcdefghijklmn'], getline(1,'$'))
2267 exe "norm! df\<c-\>\<c-g>"
2268 call assert_equal(['abcdefghijklmn'], getline(1,'$'))
2269 exe "norm! df\<c-\>m"
2270 call assert_equal(['abcdefghijklmn'], getline(1,'$'))
2271 if !has("multi_byte")
2272 return
2273 endif
2274 call setline(2, 'abcdefghijklmnāf')
2275 norm! 2gg0
2276 exe "norm! df\<Char-0x101>"
2277 call assert_equal(['abcdefghijklmn', 'f'], getline(1,'$'))
2278 norm! 1gg0
2279 exe "norm! df\<esc>"
2280 call assert_equal(['abcdefghijklmn', 'f'], getline(1,'$'))
2281
2282 " clean up
2283 bw!
2284endfunc