blob: 9a8f8f83be3c0b9f386db960619d23f5c6460aa3 [file] [log] [blame]
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001" Test for various Normal mode commands
2
3func! Setup_NewWindow()
4 10new
5 call setline(1, range(1,100))
6endfunc
7
8func! MyFormatExpr()
9 " Adds '->$' at lines having numbers followed by trailing whitespace
10 for ln in range(v:lnum, v:lnum+v:count-1)
11 let line = getline(ln)
12 if getline(ln) =~# '\d\s\+$'
13 call setline(ln, substitute(line, '\s\+$', '', '') . '->$')
14 endif
15 endfor
16endfu
17
18function! CountSpaces(type, ...)
19 " for testing operatorfunc
20 " will count the number of spaces
21 " and return the result in g:a
22 let sel_save = &selection
23 let &selection = "inclusive"
24 let reg_save = @@
25
26 if a:0 " Invoked from Visual mode, use gv command.
27 silent exe "normal! gvy"
28 elseif a:type == 'line'
29 silent exe "normal! '[V']y"
30 else
31 silent exe "normal! `[v`]y"
32 endif
33 let g:a=strlen(substitute(@@, '[^ ]', '', 'g'))
34 let &selection = sel_save
35 let @@ = reg_save
36endfunction
37
38fun! Test_normal00_optrans()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +020039 new
40 call append(0, ['1 This is a simple test: abcd', '2 This is the second line', '3 this is the third line'])
41 1
42 exe "norm! Sfoobar\<esc>"
43 call assert_equal(['foobar', '2 This is the second line', '3 this is the third line', ''], getline(1,'$'))
44 2
Bram Moolenaar87bc3f72016-09-03 17:33:54 +020045 exe "norm! $vbsone"
46 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 +020047 norm! VS Second line here
48 call assert_equal(['foobar', ' Second line here', '3 this is the third line', ''], getline(1, '$'))
49 %d
50 call append(0, ['4 This is a simple test: abcd', '5 This is the second line', '6 this is the third line'])
51 call append(0, ['1 This is a simple test: abcd', '2 This is the second line', '3 this is the third line'])
52
53 1
54 norm! 2D
55 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,'$'))
56 set cpo+=#
57 norm! 4D
58 call assert_equal(['', '4 This is a simple test: abcd', '5 This is the second line', '6 this is the third line', ''], getline(1,'$'))
59
60 " clean up
61 set cpo-=#
62 bw!
63endfu
64
65func! Test_normal01_keymodel()
66 call Setup_NewWindow()
67 " Test 1: depending on 'keymodel' <s-down> does something different
68 :50
69 call feedkeys("V\<S-Up>y", 'tx')
70 call assert_equal(['47', '48', '49', '50'], getline("'<", "'>"))
71 :set keymodel=startsel
72 :50
73 call feedkeys("V\<S-Up>y", 'tx')
74 call assert_equal(['49', '50'], getline("'<", "'>"))
75 " Start visual mode when keymodel = startsel
76 :50
77 call feedkeys("\<S-Up>y", 'tx')
78 call assert_equal(['49', '5'], getreg(0, 0, 1))
79 " Do not start visual mode when keymodel=
80 :set keymodel=
81 :50
82 call feedkeys("\<S-Up>y$", 'tx')
83 call assert_equal(['42'], getreg(0, 0, 1))
84
85 " clean up
86 bw!
87endfunc
88
89func! Test_normal02_selectmode()
90 " some basic select mode tests
91 call Setup_NewWindow()
92 50
93 norm! gHy
94 call assert_equal('y51', getline('.'))
95 call setline(1, range(1,100))
96 50
97 exe ":norm! V9jo\<c-g>y"
98 call assert_equal('y60', getline('.'))
99 " clean up
100 bw!
101endfu
102
103func! Test_normal03_join()
104 " basic join test
105 call Setup_NewWindow()
106 50
107 norm! VJ
108 call assert_equal('50 51', getline('.'))
109 $
110 norm! J
111 call assert_equal('100', getline('.'))
112 $
113 norm! V9-gJ
114 call assert_equal('919293949596979899100', getline('.'))
115 call setline(1, range(1,100))
116 $
117 :j 10
118 call assert_equal('100', getline('.'))
119 " clean up
120 bw!
121endfu
122
123func! Test_normal04_filter()
124 " basic filter test
125 " only test on non windows platform
126 if has("win32") || has("win64") || has("win95")
127 return
128 endif
129 call Setup_NewWindow()
130 1
131 call feedkeys("!!sed -e 's/^/| /'\n", 'tx')
132 call assert_equal('| 1', getline('.'))
133 90
134 :sil :!echo one
135 call feedkeys('.', 'tx')
136 call assert_equal('| 90', getline('.'))
137 95
138 set cpo+=!
139 " 2 <CR>, 1: for executing the command,
140 " 2: clear hit-enter-prompt
141 call feedkeys("!!\n", 'tx')
142 call feedkeys(":!echo one\n\n", 'tx')
143 call feedkeys(".", 'tx')
144 call assert_equal('one', getline('.'))
145 set cpo-=!
146 bw!
147endfu
148
149func! Test_normal05_formatexpr()
150 " basic formatexpr test
151 call Setup_NewWindow()
152 %d_
153 call setline(1, ['here: 1 ', '2', 'here: 3 ', '4', 'not here: '])
154 1
155 set formatexpr=MyFormatExpr()
156 norm! gqG
157 call assert_equal(['here: 1->$', '2', 'here: 3->$', '4', 'not here: '], getline(1,'$'))
158 set formatexpr=
159 bw!
160endfu
161
Bram Moolenaard77f9d52016-09-04 15:13:39 +0200162func Test_normal05_formatexpr_newbuf()
163 " Edit another buffer in the 'formatexpr' function
164 new
165 func! Format()
166 edit another
167 endfunc
168 set formatexpr=Format()
169 norm gqG
170 bw!
171 set formatexpr=
172endfunc
173
174func Test_normal05_formatexpr_setopt()
175 " Change the 'formatexpr' value in the function
176 new
177 func! Format()
178 set formatexpr=
179 endfunc
180 set formatexpr=Format()
181 norm gqG
182 bw!
183 set formatexpr=
184endfunc
185
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200186func! Test_normal06_formatprg()
187 " basic test for formatprg
188 " only test on non windows platform
189 if has("win32") || has("win64") || has("win95")
190 return
191 else
192 " uses sed to number non-empty lines
193 call writefile(['#!/bin/sh', 'sed ''/./=''|sed ''/./{', 'N', 's/\n/ /', '}'''], 'Xsed_format.sh')
194 call system('chmod +x ./Xsed_format.sh')
195 endif
196 call Setup_NewWindow()
197 %d
198 call setline(1, ['a', '', 'c', '', ' ', 'd', 'e'])
199 set formatprg=./Xsed_format.sh
200 norm! gggqG
201 call assert_equal(['1 a', '', '3 c', '', '5 ', '6 d', '7 e'], getline(1, '$'))
202 " clean up
203 set formatprg=
204 call delete('Xsed_format.sh')
205 bw!
206endfu
207
208func! Test_normal07_internalfmt()
209 " basic test for internal formmatter to textwidth of 12
210 let list=range(1,11)
211 call map(list, 'v:val." "')
212 10new
213 call setline(1, list)
214 set tw=12
215 norm! gggqG
216 call assert_equal(['1 2 3', '4 5 6', '7 8 9', '10 11 '], getline(1, '$'))
217 " clean up
Bram Moolenaar31845092016-09-05 22:58:31 +0200218 set formatprg= tw=0
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200219 bw!
220endfu
221
222func! Test_normal08_fold()
223 " basic tests for foldopen/folddelete
224 if !has("folding")
225 return
226 endif
227 call Setup_NewWindow()
228 50
229 setl foldenable fdm=marker
230 " First fold
231 norm! V4jzf
232 " check that folds have been created
233 call assert_equal(['50/*{{{*/', '51', '52', '53', '54/*}}}*/'], getline(50,54))
234 " Second fold
235 46
236 norm! V10jzf
237 " check that folds have been created
238 call assert_equal('46/*{{{*/', getline(46))
239 call assert_equal('60/*}}}*/', getline(60))
240 norm! k
241 call assert_equal('45', getline('.'))
242 norm! j
243 call assert_equal('46/*{{{*/', getline('.'))
244 norm! j
245 call assert_equal('61', getline('.'))
246 norm! k
247 " open a fold
248 norm! Vzo
249 norm! k
250 call assert_equal('45', getline('.'))
251 norm! j
252 call assert_equal('46/*{{{*/', getline('.'))
253 norm! j
254 call assert_equal('47', getline('.'))
255 norm! k
256 norm! zcVzO
257 call assert_equal('46/*{{{*/', getline('.'))
258 norm! j
259 call assert_equal('47', getline('.'))
260 norm! j
261 call assert_equal('48', getline('.'))
262 norm! j
263 call assert_equal('49', getline('.'))
264 norm! j
265 call assert_equal('50/*{{{*/', getline('.'))
266 norm! j
267 call assert_equal('51', getline('.'))
268 " delete folds
269 :46
270 " collapse fold
271 norm! V14jzC
272 " delete all folds recursively
273 norm! VzD
274 call assert_equal(['46', '47', '48', '49', '50', '51', '52', '53', '54', '55', '56', '57', '58', '59', '60'], getline(46,60))
275
276 " clean up
277 setl nofoldenable fdm=marker
278 bw!
279endfu
280
281func! Test_normal09_operatorfunc()
282 " Test operatorfunc
283 call Setup_NewWindow()
284 " Add some spaces for counting
285 50,60s/$/ /
286 unlet! g:a
287 let g:a=0
288 nmap <buffer><silent> ,, :set opfunc=CountSpaces<CR>g@
289 vmap <buffer><silent> ,, :<C-U>call CountSpaces(visualmode(), 1)<CR>
290 50
291 norm V2j,,
292 call assert_equal(6, g:a)
293 norm V,,
294 call assert_equal(2, g:a)
295 norm ,,l
296 call assert_equal(0, g:a)
297 50
298 exe "norm 0\<c-v>10j2l,,"
299 call assert_equal(11, g:a)
300 50
301 norm V10j,,
302 call assert_equal(22, g:a)
303
304 " clean up
305 unmap <buffer> ,,
306 set opfunc=
307 bw!
308endfu
309
310func! Test_normal10_expand()
311 " Test for expand()
312 10new
313 call setline(1, ['1', 'ifooar,,cbar'])
314 2
315 norm! $
316 let a=expand('<cword>')
317 let b=expand('<cWORD>')
318 call assert_equal('cbar', a)
319 call assert_equal('ifooar,,cbar', b)
320 " clean up
321 bw!
322endfu
323
324func! Test_normal11_showcmd()
325 " test for 'showcmd'
326 10new
327 exe "norm! ofoobar\<esc>"
328 call assert_equal(2, line('$'))
329 set showcmd
330 exe "norm! ofoobar2\<esc>"
331 call assert_equal(3, line('$'))
332 exe "norm! VAfoobar3\<esc>"
333 call assert_equal(3, line('$'))
334 exe "norm! 0d3\<del>2l"
335 call assert_equal('obar2foobar3', getline('.'))
336 bw!
337endfu
338
339func! Test_normal12_nv_error()
340 " Test for nv_error
341 10new
342 call setline(1, range(1,5))
343 " should not do anything, just beep
344 exe "norm! <c-k>"
345 call assert_equal(map(range(1,5), 'string(v:val)'), getline(1,'$'))
346 bw!
347endfu
348
349func! Test_normal13_help()
350 " Test for F1
351 call assert_equal(1, winnr())
352 call feedkeys("\<f1>", 'txi')
353 call assert_match('help\.txt', bufname('%'))
354 call assert_equal(2, winnr('$'))
355 bw!
356endfu
357
358func! Test_normal14_page()
359 " basic test for Ctrl-F and Ctrl-B
360 call Setup_NewWindow()
361 exe "norm! \<c-f>"
362 call assert_equal('9', getline('.'))
363 exe "norm! 2\<c-f>"
364 call assert_equal('25', getline('.'))
365 exe "norm! 2\<c-b>"
366 call assert_equal('18', getline('.'))
367 1
368 set scrolloff=5
369 exe "norm! 2\<c-f>"
370 call assert_equal('21', getline('.'))
371 exe "norm! \<c-b>"
372 call assert_equal('13', getline('.'))
373 1
374 set scrolloff=99
375 exe "norm! \<c-f>"
376 call assert_equal('13', getline('.'))
377 set scrolloff=0
378 100
379 exe "norm! $\<c-b>"
380 call assert_equal('92', getline('.'))
381 call assert_equal([0, 92, 1, 0, 1], getcurpos())
382 100
383 set nostartofline
384 exe "norm! $\<c-b>"
385 call assert_equal('92', getline('.'))
386 call assert_equal([0, 92, 2, 0, 2147483647], getcurpos())
387 " cleanup
388 set startofline
389 bw!
390endfu
391
Bram Moolenaarbc54f3f2016-09-04 14:34:28 +0200392func! Test_normal14_page_eol()
393 10new
394 norm oxxxxxxx
395 exe "norm 2\<c-f>"
396 " check with valgrind that cursor is put back in column 1
397 exe "norm 2\<c-b>"
398 bw!
399endfunc
400
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200401func! Test_normal15_z_scroll_vert()
402 " basic test for z commands that scroll the window
403 call Setup_NewWindow()
404 100
405 norm! >>
406 " Test for z<cr>
407 exe "norm! z\<cr>"
408 call assert_equal(' 100', getline('.'))
409 call assert_equal(100, winsaveview()['topline'])
410 call assert_equal([0, 100, 2, 0, 9], getcurpos())
411
412 " Test for zt
413 21
414 norm! >>0zt
415 call assert_equal(' 21', getline('.'))
416 call assert_equal(21, winsaveview()['topline'])
417 call assert_equal([0, 21, 1, 0, 8], getcurpos())
418
419 " Test for zb
420 30
421 norm! >>$ztzb
422 call assert_equal(' 30', getline('.'))
423 call assert_equal(30, winsaveview()['topline']+winheight(0)-1)
424 call assert_equal([0, 30, 3, 0, 2147483647], getcurpos())
425
426 " Test for z-
427 1
428 30
429 norm! 0z-
430 call assert_equal(' 30', getline('.'))
431 call assert_equal(30, winsaveview()['topline']+winheight(0)-1)
432 call assert_equal([0, 30, 2, 0, 9], getcurpos())
433
434 " Test for z{height}<cr>
435 call assert_equal(10, winheight(0))
436 exe "norm! z12\<cr>"
437 call assert_equal(12, winheight(0))
438 exe "norm! z10\<cr>"
439 call assert_equal(10, winheight(0))
440
441 " Test for z.
442 1
443 21
444 norm! 0z.
445 call assert_equal(' 21', getline('.'))
446 call assert_equal(17, winsaveview()['topline'])
447 call assert_equal([0, 21, 2, 0, 9], getcurpos())
448
449 " Test for zz
450 1
451 21
452 norm! 0zz
453 call assert_equal(' 21', getline('.'))
454 call assert_equal(17, winsaveview()['topline'])
455 call assert_equal([0, 21, 1, 0, 8], getcurpos())
456
457 " Test for z+
458 11
459 norm! zt
460 norm! z+
461 call assert_equal(' 21', getline('.'))
462 call assert_equal(21, winsaveview()['topline'])
463 call assert_equal([0, 21, 2, 0, 9], getcurpos())
464
465 " Test for [count]z+
466 1
467 norm! 21z+
468 call assert_equal(' 21', getline('.'))
469 call assert_equal(21, winsaveview()['topline'])
470 call assert_equal([0, 21, 2, 0, 9], getcurpos())
471
472 " Test for z^
473 norm! 22z+0
474 norm! z^
475 call assert_equal(' 21', getline('.'))
476 call assert_equal(12, winsaveview()['topline'])
477 call assert_equal([0, 21, 2, 0, 9], getcurpos())
478
479 " Test for [count]z^
480 1
481 norm! 30z^
482 call assert_equal(' 21', getline('.'))
483 call assert_equal(12, winsaveview()['topline'])
484 call assert_equal([0, 21, 2, 0, 9], getcurpos())
485
486 " cleanup
487 bw!
488endfu
489
490func! Test_normal16_z_scroll_hor()
491 " basic test for z commands that scroll the window
492 10new
493 15vsp
494 set nowrap listchars=
495 let lineA='abcdefghijklmnopqrstuvwxyz'
496 let lineB='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'
497 $put =lineA
498 $put =lineB
499 1d
500
501 " Test for zl
502 1
503 norm! 5zl
504 call assert_equal(lineA, getline('.'))
505 call assert_equal(6, col('.'))
506 call assert_equal(5, winsaveview()['leftcol'])
507 norm! yl
508 call assert_equal('f', @0)
509
510 " Test for zh
511 norm! 2zh
512 call assert_equal(lineA, getline('.'))
513 call assert_equal(6, col('.'))
514 norm! yl
515 call assert_equal('f', @0)
516 call assert_equal(3, winsaveview()['leftcol'])
517
518 " Test for zL
519 norm! zL
520 call assert_equal(11, col('.'))
521 norm! yl
522 call assert_equal('k', @0)
523 call assert_equal(10, winsaveview()['leftcol'])
524 norm! 2zL
525 call assert_equal(25, col('.'))
526 norm! yl
527 call assert_equal('y', @0)
528 call assert_equal(24, winsaveview()['leftcol'])
529
530 " Test for zH
531 norm! 2zH
532 call assert_equal(25, col('.'))
533 call assert_equal(10, winsaveview()['leftcol'])
534 norm! yl
535 call assert_equal('y', @0)
536
537 " Test for zs
538 norm! $zs
539 call assert_equal(26, col('.'))
540 call assert_equal(25, winsaveview()['leftcol'])
541 norm! yl
542 call assert_equal('z', @0)
543
544 " Test for ze
545 norm! ze
546 call assert_equal(26, col('.'))
547 call assert_equal(11, winsaveview()['leftcol'])
548 norm! yl
549 call assert_equal('z', @0)
550
551 " cleanup
552 set wrap listchars=eol:$
553 bw!
554endfu
555
556func! Test_normal17_z_scroll_hor2()
557 " basic test for z commands that scroll the window
558 " using 'sidescrolloff' setting
559 10new
560 20vsp
561 set nowrap listchars= sidescrolloff=5
562 let lineA='abcdefghijklmnopqrstuvwxyz'
563 let lineB='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'
564 $put =lineA
565 $put =lineB
566 1d
567
568 " Test for zl
569 1
570 norm! 5zl
571 call assert_equal(lineA, getline('.'))
572 call assert_equal(11, col('.'))
573 call assert_equal(5, winsaveview()['leftcol'])
574 norm! yl
575 call assert_equal('k', @0)
576
577 " Test for zh
578 norm! 2zh
579 call assert_equal(lineA, getline('.'))
580 call assert_equal(11, col('.'))
581 norm! yl
582 call assert_equal('k', @0)
583 call assert_equal(3, winsaveview()['leftcol'])
584
585 " Test for zL
586 norm! 0zL
587 call assert_equal(16, col('.'))
588 norm! yl
589 call assert_equal('p', @0)
590 call assert_equal(10, winsaveview()['leftcol'])
591 norm! 2zL
592 call assert_equal(26, col('.'))
593 norm! yl
594 call assert_equal('z', @0)
595 call assert_equal(15, winsaveview()['leftcol'])
596
597 " Test for zH
598 norm! 2zH
599 call assert_equal(15, col('.'))
600 call assert_equal(0, winsaveview()['leftcol'])
601 norm! yl
602 call assert_equal('o', @0)
603
604 " Test for zs
605 norm! $zs
606 call assert_equal(26, col('.'))
607 call assert_equal(20, winsaveview()['leftcol'])
608 norm! yl
609 call assert_equal('z', @0)
610
611 " Test for ze
612 norm! ze
613 call assert_equal(26, col('.'))
614 call assert_equal(11, winsaveview()['leftcol'])
615 norm! yl
616 call assert_equal('z', @0)
617
618 " cleanup
619 set wrap listchars=eol:$ sidescrolloff=0
620 bw!
621endfu
622
623func! Test_normal18_z_fold()
624 " basic tests for foldopen/folddelete
625 if !has("folding")
626 return
627 endif
628 call Setup_NewWindow()
629 50
630 setl foldenable fdm=marker foldlevel=5
631
632 " Test for zF
633 " First fold
634 norm! 4zF
635 " check that folds have been created
636 call assert_equal(['50/*{{{*/', '51', '52', '53/*}}}*/'], getline(50,53))
637
638 " Test for zd
639 51
640 norm! 2zF
641 call assert_equal(2, foldlevel('.'))
642 norm! kzd
643 call assert_equal(['50', '51/*{{{*/', '52/*}}}*/', '53'], getline(50,53))
644 norm! j
645 call assert_equal(1, foldlevel('.'))
646
647 " Test for zD
648 " also deletes partially selected folds recursively
649 51
650 norm! zF
651 call assert_equal(2, foldlevel('.'))
652 norm! kV2jzD
653 call assert_equal(['50', '51', '52', '53'], getline(50,53))
654
655 " Test for zE
656 85
657 norm! 4zF
658 86
659 norm! 2zF
660 90
661 norm! 4zF
662 call assert_equal(['85/*{{{*/', '86/*{{{*/', '87/*}}}*/', '88/*}}}*/', '89', '90/*{{{*/', '91', '92', '93/*}}}*/'], getline(85,93))
663 norm! zE
664 call assert_equal(['85', '86', '87', '88', '89', '90', '91', '92', '93'], getline(85,93))
665
666 " Test for zn
667 50
668 set foldlevel=0
669 norm! 2zF
670 norm! zn
671 norm! k
672 call assert_equal('49', getline('.'))
673 norm! j
674 call assert_equal('50/*{{{*/', getline('.'))
675 norm! j
676 call assert_equal('51/*}}}*/', getline('.'))
677 norm! j
678 call assert_equal('52', getline('.'))
679 call assert_equal(0, &foldenable)
680
681 " Test for zN
682 49
683 norm! zN
684 call assert_equal('49', getline('.'))
685 norm! j
686 call assert_equal('50/*{{{*/', getline('.'))
687 norm! j
688 call assert_equal('52', getline('.'))
689 call assert_equal(1, &foldenable)
690
691 " Test for zi
692 norm! zi
693 call assert_equal(0, &foldenable)
694 norm! zi
695 call assert_equal(1, &foldenable)
696 norm! zi
697 call assert_equal(0, &foldenable)
698 norm! zi
699 call assert_equal(1, &foldenable)
700
701 " Test for za
702 50
703 norm! za
704 norm! k
705 call assert_equal('49', getline('.'))
706 norm! j
707 call assert_equal('50/*{{{*/', getline('.'))
708 norm! j
709 call assert_equal('51/*}}}*/', getline('.'))
710 norm! j
711 call assert_equal('52', getline('.'))
712 50
713 norm! za
714 norm! k
715 call assert_equal('49', getline('.'))
716 norm! j
717 call assert_equal('50/*{{{*/', getline('.'))
718 norm! j
719 call assert_equal('52', getline('.'))
720
721 49
722 norm! 5zF
723 norm! k
724 call assert_equal('48', getline('.'))
725 norm! j
726 call assert_equal('49/*{{{*/', getline('.'))
727 norm! j
728 call assert_equal('55', getline('.'))
729 49
730 norm! za
731 call assert_equal('49/*{{{*/', getline('.'))
732 norm! j
733 call assert_equal('50/*{{{*/', getline('.'))
734 norm! j
735 call assert_equal('52', getline('.'))
736 set nofoldenable
737 " close fold and set foldenable
738 norm! za
739 call assert_equal(1, &foldenable)
740
741 50
742 " have to use {count}za to open all folds and make the cursor visible
743 norm! 2za
744 norm! 2k
745 call assert_equal('48', getline('.'))
746 norm! j
747 call assert_equal('49/*{{{*/', getline('.'))
748 norm! j
749 call assert_equal('50/*{{{*/', getline('.'))
750 norm! j
751 call assert_equal('51/*}}}*/', getline('.'))
752 norm! j
753 call assert_equal('52', getline('.'))
754
755 " Test for zA
756 49
757 set foldlevel=0
758 50
759 norm! zA
760 norm! 2k
761 call assert_equal('48', getline('.'))
762 norm! j
763 call assert_equal('49/*{{{*/', getline('.'))
764 norm! j
765 call assert_equal('50/*{{{*/', getline('.'))
766 norm! j
767 call assert_equal('51/*}}}*/', getline('.'))
768 norm! j
769 call assert_equal('52', getline('.'))
770
771 " zA on a opened fold when foldenale is not set
772 50
773 set nofoldenable
774 norm! zA
775 call assert_equal(1, &foldenable)
776 norm! k
777 call assert_equal('48', getline('.'))
778 norm! j
779 call assert_equal('49/*{{{*/', getline('.'))
780 norm! j
781 call assert_equal('55', getline('.'))
782
783 " Test for zc
784 norm! zE
785 50
786 norm! 2zF
787 49
788 norm! 5zF
789 set nofoldenable
790 50
791 " There most likely is a bug somewhere:
792 " https://groups.google.com/d/msg/vim_dev/v2EkfJ_KQjI/u-Cvv94uCAAJ
793 " TODO: Should this only close the inner most fold or both folds?
794 norm! zc
795 call assert_equal(1, &foldenable)
796 norm! k
797 call assert_equal('48', getline('.'))
798 norm! j
799 call assert_equal('49/*{{{*/', getline('.'))
800 norm! j
801 call assert_equal('55', getline('.'))
802 set nofoldenable
803 50
804 norm! Vjzc
805 norm! k
806 call assert_equal('48', getline('.'))
807 norm! j
808 call assert_equal('49/*{{{*/', getline('.'))
809 norm! j
810 call assert_equal('55', getline('.'))
811
812 " Test for zC
813 set nofoldenable
814 50
815 norm! zCk
816 call assert_equal('48', getline('.'))
817 norm! j
818 call assert_equal('49/*{{{*/', getline('.'))
819 norm! j
820 call assert_equal('55', getline('.'))
821
822 " Test for zx
823 " 1) close folds at line 49-54
824 set nofoldenable
825 48
826 norm! zx
827 call assert_equal(1, &foldenable)
828 norm! j
829 call assert_equal('49/*{{{*/', getline('.'))
830 norm! j
831 call assert_equal('55', getline('.'))
832
833 " 2) do not close fold under curser
834 51
835 set nofoldenable
836 norm! zx
837 call assert_equal(1, &foldenable)
838 norm! 3k
839 call assert_equal('48', getline('.'))
840 norm! j
841 call assert_equal('49/*{{{*/', getline('.'))
842 norm! j
843 call assert_equal('50/*{{{*/', getline('.'))
844 norm! j
845 call assert_equal('51/*}}}*/', getline('.'))
846 norm! j
847 call assert_equal('52', getline('.'))
848 norm! j
849 call assert_equal('53', getline('.'))
850 norm! j
851 call assert_equal('54/*}}}*/', getline('.'))
852 norm! j
853 call assert_equal('55', getline('.'))
854
855 " 3) close one level of folds
856 48
857 set nofoldenable
858 set foldlevel=1
859 norm! zx
860 call assert_equal(1, &foldenable)
861 call assert_equal('48', getline('.'))
862 norm! j
863 call assert_equal('49/*{{{*/', getline('.'))
864 norm! j
865 call assert_equal('50/*{{{*/', getline('.'))
866 norm! j
867 call assert_equal('52', getline('.'))
868 norm! j
869 call assert_equal('53', getline('.'))
870 norm! j
871 call assert_equal('54/*}}}*/', getline('.'))
872 norm! j
873 call assert_equal('55', getline('.'))
874
875 " Test for zX
876 " Close all folds
877 set foldlevel=0 nofoldenable
878 50
879 norm! zX
880 call assert_equal(1, &foldenable)
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 zm
889 50
890 set nofoldenable foldlevel=2
891 norm! zm
892 call assert_equal(1, &foldenable)
893 call assert_equal(1, &foldlevel)
894 norm! zm
895 call assert_equal(0, &foldlevel)
896 norm! zm
897 call assert_equal(0, &foldlevel)
898 norm! k
899 call assert_equal('48', getline('.'))
900 norm! j
901 call assert_equal('49/*{{{*/', getline('.'))
902 norm! j
903 call assert_equal('55', getline('.'))
904
905 " Test for zM
906 48
907 set nofoldenable foldlevel=99
908 norm! zM
909 call assert_equal(1, &foldenable)
910 call assert_equal(0, &foldlevel)
911 call assert_equal('48', getline('.'))
912 norm! j
913 call assert_equal('49/*{{{*/', getline('.'))
914 norm! j
915 call assert_equal('55', getline('.'))
916
917 " Test for zr
918 48
919 set nofoldenable foldlevel=0
920 norm! zr
921 call assert_equal(0, &foldenable)
922 call assert_equal(1, &foldlevel)
923 set foldlevel=0 foldenable
924 norm! zr
925 call assert_equal(1, &foldenable)
926 call assert_equal(1, &foldlevel)
927 norm! zr
928 call assert_equal(2, &foldlevel)
929 call assert_equal('48', getline('.'))
930 norm! j
931 call assert_equal('49/*{{{*/', getline('.'))
932 norm! j
933 call assert_equal('50/*{{{*/', getline('.'))
934 norm! j
935 call assert_equal('51/*}}}*/', getline('.'))
936 norm! j
937 call assert_equal('52', getline('.'))
938
939 " Test for zR
940 48
941 set nofoldenable foldlevel=0
942 norm! zR
943 call assert_equal(0, &foldenable)
944 call assert_equal(2, &foldlevel)
945 set foldenable foldlevel=0
946 norm! zR
947 call assert_equal(1, &foldenable)
948 call assert_equal(2, &foldlevel)
949 call assert_equal('48', getline('.'))
950 norm! j
951 call assert_equal('49/*{{{*/', getline('.'))
952 norm! j
953 call assert_equal('50/*{{{*/', getline('.'))
954 norm! j
955 call assert_equal('51/*}}}*/', getline('.'))
956 norm! j
957 call assert_equal('52', getline('.'))
958 call append(50, ['a /*{{{*/', 'b /*}}}*/'])
959 48
960 call assert_equal('48', getline('.'))
961 norm! j
962 call assert_equal('49/*{{{*/', getline('.'))
963 norm! j
964 call assert_equal('50/*{{{*/', getline('.'))
965 norm! j
966 call assert_equal('a /*{{{*/', getline('.'))
967 norm! j
968 call assert_equal('51/*}}}*/', getline('.'))
969 norm! j
970 call assert_equal('52', getline('.'))
971 48
972 norm! zR
973 call assert_equal(1, &foldenable)
974 call assert_equal(3, &foldlevel)
975 call assert_equal('48', getline('.'))
976 norm! j
977 call assert_equal('49/*{{{*/', getline('.'))
978 norm! j
979 call assert_equal('50/*{{{*/', getline('.'))
980 norm! j
981 call assert_equal('a /*{{{*/', getline('.'))
982 norm! j
983 call assert_equal('b /*}}}*/', getline('.'))
984 norm! j
985 call assert_equal('51/*}}}*/', getline('.'))
986 norm! j
987 call assert_equal('52', getline('.'))
988
989 " clean up
990 setl nofoldenable fdm=marker foldlevel=0
991 bw!
992endfu
993
994func! Test_normal19_z_spell()
995 if !has("spell") || !has('syntax')
996 return
997 endif
998 new
999 call append(0, ['1 good', '2 goood', '3 goood'])
1000 set spell spellfile=./Xspellfile.add spelllang=en
1001 let oldlang=v:lang
1002 lang C
1003
1004 " Test for zg
1005 1
1006 norm! ]s
1007 call assert_equal('2 goood', getline('.'))
1008 norm! zg
1009 1
1010 let a=execute('unsilent :norm! ]s')
1011 call assert_equal('1 good', getline('.'))
1012 call assert_equal('search hit BOTTOM, continuing at TOP', a[1:])
1013 let cnt=readfile('./Xspellfile.add')
1014 call assert_equal('goood', cnt[0])
1015
1016 " Test for zw
1017 2
1018 norm! $zw
1019 1
1020 norm! ]s
1021 call assert_equal('2 goood', getline('.'))
1022 let cnt=readfile('./Xspellfile.add')
1023 call assert_equal('#oood', cnt[0])
1024 call assert_equal('goood/!', cnt[1])
1025
1026 " Test for zg in visual mode
1027 let a=execute('unsilent :norm! V$zg')
1028 call assert_equal("Word '2 goood' added to ./Xspellfile.add", a[1:])
1029 1
1030 norm! ]s
1031 call assert_equal('3 goood', getline('.'))
1032 let cnt=readfile('./Xspellfile.add')
1033 call assert_equal('2 goood', cnt[2])
1034 " Remove "2 good" from spellfile
1035 2
1036 let a=execute('unsilent norm! V$zw')
1037 call assert_equal("Word '2 goood' added to ./Xspellfile.add", a[1:])
1038 let cnt=readfile('./Xspellfile.add')
1039 call assert_equal('2 goood/!', cnt[3])
1040
1041 " Test for zG
1042 let a=execute('unsilent norm! V$zG')
1043 call assert_match("Word '2 goood' added to .*", a)
1044 let fname=matchstr(a, 'to\s\+\zs\f\+$')
1045 let cnt=readfile(fname)
1046 call assert_equal('2 goood', cnt[0])
1047
1048 " Test for zW
1049 let a=execute('unsilent norm! V$zW')
1050 call assert_match("Word '2 goood' added to .*", a)
1051 let cnt=readfile(fname)
1052 call assert_equal('# goood', cnt[0])
1053 call assert_equal('2 goood/!', cnt[1])
1054
1055 " Test for zuW
1056 let a=execute('unsilent norm! V$zuW')
1057 call assert_match("Word '2 goood' removed from .*", a)
1058 let cnt=readfile(fname)
1059 call assert_equal('# goood', cnt[0])
1060 call assert_equal('# goood/!', cnt[1])
1061
1062 " Test for zuG
1063 let a=execute('unsilent norm! $zG')
1064 call assert_match("Word 'goood' added to .*", a)
1065 let cnt=readfile(fname)
1066 call assert_equal('# goood', cnt[0])
1067 call assert_equal('# goood/!', cnt[1])
1068 call assert_equal('goood', cnt[2])
1069 let a=execute('unsilent norm! $zuG')
1070 let cnt=readfile(fname)
1071 call assert_match("Word 'goood' removed from .*", a)
1072 call assert_equal('# goood', cnt[0])
1073 call assert_equal('# goood/!', cnt[1])
1074 call assert_equal('#oood', cnt[2])
1075 " word not found in wordlist
1076 let a=execute('unsilent norm! V$zuG')
1077 let cnt=readfile(fname)
1078 call assert_match("", a)
1079 call assert_equal('# goood', cnt[0])
1080 call assert_equal('# goood/!', cnt[1])
1081 call assert_equal('#oood', cnt[2])
1082
1083 " Test for zug
1084 call delete('./Xspellfile.add')
1085 2
1086 let a=execute('unsilent norm! $zg')
1087 let cnt=readfile('./Xspellfile.add')
1088 call assert_equal('goood', cnt[0])
1089 let a=execute('unsilent norm! $zug')
1090 call assert_match("Word 'goood' removed from \./Xspellfile.add", a)
1091 let cnt=readfile('./Xspellfile.add')
1092 call assert_equal('#oood', cnt[0])
1093 " word not in wordlist
1094 let a=execute('unsilent norm! V$zug')
1095 call assert_match('', a)
1096 let cnt=readfile('./Xspellfile.add')
1097 call assert_equal('#oood', cnt[0])
1098
1099 " Test for zuw
1100 call delete('./Xspellfile.add')
1101 2
1102 let a=execute('unsilent norm! Vzw')
1103 let cnt=readfile('./Xspellfile.add')
1104 call assert_equal('2 goood/!', cnt[0])
1105 let a=execute('unsilent norm! Vzuw')
1106 call assert_match("Word '2 goood' removed from \./Xspellfile.add", a)
1107 let cnt=readfile('./Xspellfile.add')
1108 call assert_equal('# goood/!', cnt[0])
1109 " word not in wordlist
1110 let a=execute('unsilent norm! $zug')
1111 call assert_match('', a)
1112 let cnt=readfile('./Xspellfile.add')
1113 call assert_equal('# goood/!', cnt[0])
1114
1115 " add second entry to spellfile setting
1116 set spellfile=./Xspellfile.add,./Xspellfile2.add
1117 call delete('./Xspellfile.add')
1118 2
1119 let a=execute('unsilent norm! $2zg')
1120 let cnt=readfile('./Xspellfile2.add')
1121 call assert_match("Word 'goood' added to ./Xspellfile2.add", a)
1122 call assert_equal('goood', cnt[0])
1123
1124 " clean up
1125 exe "lang" oldlang
1126 call delete("./Xspellfile.add")
1127 call delete("./Xspellfile2.add")
1128
1129 " zux -> no-op
1130 2
1131 norm! $zux
1132 call assert_equal([], glob('Xspellfile.add',0,1))
1133 call assert_equal([], glob('Xspellfile2.add',0,1))
1134
1135 set spellfile=
1136 bw!
1137endfu
1138
1139func! Test_normal20_exmode()
Bram Moolenaar0913a102016-09-03 19:11:59 +02001140 if !has("unix")
1141 " Reading from redirected file doesn't work on MS-Windows
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001142 return
1143 endif
1144 call writefile(['1a', 'foo', 'bar', '.', 'w! Xfile2', 'q!'], 'Xscript')
1145 call writefile(['1', '2'], 'Xfile')
1146 call system(v:progpath .' -e -s < Xscript Xfile')
1147 let a=readfile('Xfile2')
1148 call assert_equal(['1', 'foo', 'bar', '2'], a)
1149
1150 " clean up
1151 for file in ['Xfile', 'Xfile2', 'Xscript']
1152 call delete(file)
1153 endfor
1154 bw!
1155endfu
1156
1157func! Test_normal21_nv_hat()
1158 set hidden
1159 e Xfoobar
1160 e Xfile2
1161 call feedkeys("\<c-^>", 't')
1162 call assert_equal("Xfile2", fnamemodify(bufname('%'), ':t'))
1163 call feedkeys("f\<c-^>", 't')
1164 call assert_equal("Xfile2", fnamemodify(bufname('%'), ':t'))
1165 " clean up
1166 set nohidden
1167 bw!
1168endfu
1169
1170func! Test_normal22_zet()
1171 " Test for ZZ
Bram Moolenaar0913a102016-09-03 19:11:59 +02001172 " let shell = &shell
1173 " let &shell = 'sh'
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001174 call writefile(['1', '2'], 'Xfile')
1175 let args = ' -u NONE -N -U NONE -i NONE --noplugins -X --not-a-term'
1176 call system(v:progpath . args . ' -c "%d" -c ":norm! ZZ" Xfile')
1177 let a = readfile('Xfile')
1178 call assert_equal([], a)
1179 " Test for ZQ
1180 call writefile(['1', '2'], 'Xfile')
1181 call system(v:progpath . args . ' -c "%d" -c ":norm! ZQ" Xfile')
1182 let a = readfile('Xfile')
1183 call assert_equal(['1', '2'], a)
1184
1185 " clean up
1186 for file in ['Xfile']
1187 call delete(file)
1188 endfor
Bram Moolenaar0913a102016-09-03 19:11:59 +02001189 " let &shell = shell
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001190endfu
1191
1192func! Test_normal23_K()
1193 " Test for K command
1194 new
1195 call append(0, ['version8.txt', 'man'])
1196 let k = &keywordprg
1197 set keywordprg=:help
1198 1
1199 norm! VK
1200 call assert_equal('version8.txt', fnamemodify(bufname('%'), ':t'))
1201 call assert_equal('help', &ft)
1202 call assert_match('\*version8.txt\*', getline('.'))
1203 helpclose
1204 norm! 0K
1205 call assert_equal('version8.txt', fnamemodify(bufname('%'), ':t'))
1206 call assert_equal('help', &ft)
1207 call assert_match('\*version8\.0\*', getline('.'))
1208 helpclose
1209
Bram Moolenaar0913a102016-09-03 19:11:59 +02001210 " Only expect "man" to work on Unix
1211 if !has("unix")
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001212 let &keywordprg = k
1213 bw!
1214 return
1215 endif
1216 set keywordprg=man\ --pager=cat
1217 " Test for using man
1218 2
1219 let a = execute('unsilent norm! K')
1220 call assert_match("man --pager=cat 'man'", a)
1221
1222 " clean up
1223 let &keywordprg = k
1224 bw!
1225endfu
1226
1227func! Test_normal24_rot13()
1228 " This test uses multi byte characters
1229 if !has("multi_byte")
1230 return
1231 endif
1232 " Testing for g?? g?g?
1233 new
1234 call append(0, 'abcdefghijklmnopqrstuvwxyzäüö')
1235 1
1236 norm! g??
1237 call assert_equal('nopqrstuvwxyzabcdefghijklmäüö', getline('.'))
1238 norm! g?g?
1239 call assert_equal('abcdefghijklmnopqrstuvwxyzäüö', getline('.'))
1240
1241 " clean up
1242 bw!
1243endfu
1244
1245func! Test_normal25_tag()
1246 " Testing for CTRL-] g CTRL-] g]
1247 " CTRL-W g] CTRL-W CTRL-] CTRL-W g CTRL-]
1248 h
1249 " Test for CTRL-]
1250 call search('\<x\>$')
1251 exe "norm! \<c-]>"
1252 call assert_equal("change.txt", fnamemodify(bufname('%'), ':t'))
1253 norm! yiW
1254 call assert_equal("*x*", @0)
1255 exe ":norm \<c-o>"
1256
1257 " Test for g_CTRL-]
1258 call search('\<v_u\>$')
1259 exe "norm! g\<c-]>"
1260 call assert_equal("change.txt", fnamemodify(bufname('%'), ':t'))
1261 norm! yiW
1262 call assert_equal("*v_u*", @0)
1263 exe ":norm \<c-o>"
1264
1265 " Test for g]
1266 call search('\<i_<Esc>$')
1267 let a = execute(":norm! g]")
1268 call assert_match('i_<Esc>.*insert.txt', a)
1269
1270 if !empty(exepath('cscope')) && has('cscope')
1271 " setting cscopetag changes how g] works
1272 set cst
1273 exe "norm! g]"
1274 call assert_equal("insert.txt", fnamemodify(bufname('%'), ':t'))
1275 norm! yiW
1276 call assert_equal("*i_<Esc>*", @0)
1277 exe ":norm \<c-o>"
1278 " Test for CTRL-W g]
1279 exe "norm! \<C-W>g]"
1280 call assert_equal("insert.txt", fnamemodify(bufname('%'), ':t'))
1281 norm! yiW
1282 call assert_equal("*i_<Esc>*", @0)
1283 call assert_equal(3, winnr('$'))
1284 helpclose
1285 set nocst
1286 endif
1287
1288 " Test for CTRL-W g]
1289 let a = execute("norm! \<C-W>g]")
1290 call assert_match('i_<Esc>.*insert.txt', a)
1291
1292 " Test for CTRL-W CTRL-]
1293 exe "norm! \<C-W>\<C-]>"
1294 call assert_equal("insert.txt", fnamemodify(bufname('%'), ':t'))
1295 norm! yiW
1296 call assert_equal("*i_<Esc>*", @0)
1297 call assert_equal(3, winnr('$'))
1298 helpclose
1299
1300 " Test for CTRL-W g CTRL-]
1301 exe "norm! \<C-W>g\<C-]>"
1302 call assert_equal("insert.txt", fnamemodify(bufname('%'), ':t'))
1303 norm! yiW
1304 call assert_equal("*i_<Esc>*", @0)
1305 call assert_equal(3, winnr('$'))
1306 helpclose
1307
1308 " clean up
1309 helpclose
1310endfu
1311
1312func! Test_normal26_put()
1313 " Test for ]p ]P [p and [P
1314 new
1315 call append(0, ['while read LINE', 'do', ' ((count++))', ' if [ $? -ne 0 ]; then', " echo 'Error writing file'", ' fi', 'done'])
1316 1
1317 /Error/y a
1318 2
1319 norm! "a]pj"a[p
1320 call assert_equal(['do', "echo 'Error writing file'", " echo 'Error writing file'", ' ((count++))'], getline(2,5))
1321 1
1322 /^\s\{4}/
1323 exe "norm! \"a]P3Eldt'"
1324 exe "norm! j\"a[P2Eldt'"
1325 call assert_equal([' if [ $? -ne 0 ]; then', " echo 'Error writing'", " echo 'Error'", " echo 'Error writing file'", ' fi'], getline(6,10))
1326
1327 " clean up
1328 bw!
1329endfu
1330
1331func! Test_normal27_bracket()
1332 " Test for [' [` ]' ]`
1333 call Setup_NewWindow()
1334 1,21s/.\+/ & b/
1335 1
1336 norm! $ma
1337 5
1338 norm! $mb
1339 10
1340 norm! $mc
1341 15
1342 norm! $md
1343 20
1344 norm! $me
1345
1346 " Test for ['
1347 9
1348 norm! 2['
1349 call assert_equal(' 1 b', getline('.'))
1350 call assert_equal(1, line('.'))
1351 call assert_equal(3, col('.'))
1352
1353 " Test for ]'
1354 norm! ]'
1355 call assert_equal(' 5 b', getline('.'))
1356 call assert_equal(5, line('.'))
1357 call assert_equal(3, col('.'))
1358
1359 " No mark after line 21, cursor moves to first non blank on current line
1360 21
1361 norm! $]'
1362 call assert_equal(' 21 b', getline('.'))
1363 call assert_equal(21, line('.'))
1364 call assert_equal(3, col('.'))
1365
1366 " Test for [`
1367 norm! 2[`
1368 call assert_equal(' 15 b', getline('.'))
1369 call assert_equal(15, line('.'))
1370 call assert_equal(8, col('.'))
1371
1372 " Test for ]`
1373 norm! ]`
1374 call assert_equal(' 20 b', getline('.'))
1375 call assert_equal(20, line('.'))
1376 call assert_equal(8, col('.'))
1377
1378 " clean up
1379 bw!
1380endfu
1381
1382func! Test_normal28_parenthesis()
1383 " basic testing for ( and )
1384 new
1385 call append(0, ['This is a test. With some sentences!', '', 'Even with a question? And one more. And no sentence here'])
1386
1387 $
1388 norm! d(
1389 call assert_equal(['This is a test. With some sentences!', '', 'Even with a question? And one more. ', ''], getline(1, '$'))
1390 norm! 2d(
1391 call assert_equal(['This is a test. With some sentences!', '', ' ', ''], getline(1, '$'))
1392 1
1393 norm! 0d)
1394 call assert_equal(['With some sentences!', '', ' ', ''], getline(1, '$'))
1395
1396 call append('$', ['This is a long sentence', '', 'spanning', 'over several lines. '])
1397 $
1398 norm! $d(
1399 call assert_equal(['With some sentences!', '', ' ', '', 'This is a long sentence', ''], getline(1, '$'))
1400
1401 " clean up
1402 bw!
1403endfu
1404
1405fun! Test_normal29_brace()
1406 " basic test for { and } movements
1407 let text= ['A paragraph begins after each empty line, and also at each of a set of',
1408 \ 'paragraph macros, specified by the pairs of characters in the ''paragraphs''',
1409 \ 'option. The default is "IPLPPPQPP TPHPLIPpLpItpplpipbp", which corresponds to',
1410 \ 'the macros ".IP", ".LP", etc. (These are nroff macros, so the dot must be in',
1411 \ 'the first column). A section boundary is also a paragraph boundary.',
1412 \ 'Note that a blank line (only containing white space) is NOT a paragraph',
1413 \ 'boundary.',
1414 \ '',
1415 \ '',
1416 \ 'Also note that this does not include a ''{'' or ''}'' in the first column. When',
1417 \ 'the ''{'' flag is in ''cpoptions'' then ''{'' in the first column is used as a',
1418 \ 'paragraph boundary |posix|.',
1419 \ '{',
1420 \ 'This is no paragaraph',
1421 \ 'unless the ''{'' is set',
1422 \ 'in ''cpoptions''',
1423 \ '}',
1424 \ '.IP',
1425 \ 'The nroff macros IP seperates a paragraph',
1426 \ 'That means, it must be a ''.''',
1427 \ 'followed by IP',
1428 \ '.LPIt does not matter, if afterwards some',
1429 \ 'more characters follow.',
1430 \ '.SHAlso section boundaries from the nroff',
1431 \ 'macros terminate a paragraph. That means',
1432 \ 'a character like this:',
1433 \ '.NH',
1434 \ 'End of text here']
1435 new
1436 call append(0, text)
1437 1
1438 norm! 0d2}
1439 call assert_equal(['.IP',
1440 \ 'The nroff macros IP seperates a paragraph', 'That means, it must be a ''.''', 'followed by IP',
1441 \ '.LPIt does not matter, if afterwards some', 'more characters follow.', '.SHAlso section boundaries from the nroff',
1442 \ 'macros terminate a paragraph. That means', 'a character like this:', '.NH', 'End of text here', ''], getline(1,'$'))
1443 norm! 0d}
1444 call assert_equal(['.LPIt does not matter, if afterwards some', 'more characters follow.',
1445 \ '.SHAlso section boundaries from the nroff', 'macros terminate a paragraph. That means',
1446 \ 'a character like this:', '.NH', 'End of text here', ''], getline(1, '$'))
1447 $
1448 norm! d{
1449 call assert_equal(['.LPIt does not matter, if afterwards some', 'more characters follow.',
1450 \ '.SHAlso section boundaries from the nroff', 'macros terminate a paragraph. That means', 'a character like this:', ''], getline(1, '$'))
1451 norm! d{
1452 call assert_equal(['.LPIt does not matter, if afterwards some', 'more characters follow.', ''], getline(1,'$'))
1453 " Test with { in cpooptions
1454 %d
1455 call append(0, text)
1456 set cpo+={
1457 1
1458 norm! 0d2}
1459 call assert_equal(['{', 'This is no paragaraph', 'unless the ''{'' is set', 'in ''cpoptions''', '}',
1460 \ '.IP', 'The nroff macros IP seperates a paragraph', 'That means, it must be a ''.''',
1461 \ 'followed by IP', '.LPIt does not matter, if afterwards some', 'more characters follow.',
1462 \ '.SHAlso section boundaries from the nroff', 'macros terminate a paragraph. That means',
1463 \ 'a character like this:', '.NH', 'End of text here', ''], getline(1,'$'))
1464 $
1465 norm! d}
1466 call assert_equal(['{', 'This is no paragaraph', 'unless the ''{'' is set', 'in ''cpoptions''', '}',
1467 \ '.IP', 'The nroff macros IP seperates a paragraph', 'That means, it must be a ''.''',
1468 \ 'followed by IP', '.LPIt does not matter, if afterwards some', 'more characters follow.',
1469 \ '.SHAlso section boundaries from the nroff', 'macros terminate a paragraph. That means',
1470 \ 'a character like this:', '.NH', 'End of text here', ''], getline(1,'$'))
1471 norm! gg}
1472 norm! d5}
1473 call assert_equal(['{', 'This is no paragaraph', 'unless the ''{'' is set', 'in ''cpoptions''', '}', ''], getline(1,'$'))
1474
1475 " clean up
1476 set cpo-={
1477 bw!
1478endfu
1479
1480fun! Test_normal30_changecase()
1481 " This test uses multi byte characters
1482 if !has("multi_byte")
1483 return
1484 endif
1485 new
1486 call append(0, 'This is a simple test: äüöß')
1487 norm! 1ggVu
1488 call assert_equal('this is a simple test: äüöß', getline('.'))
1489 norm! VU
1490 call assert_equal('THIS IS A SIMPLE TEST: ÄÜÖSS', getline('.'))
1491 norm! guu
1492 call assert_equal('this is a simple test: äüöss', getline('.'))
1493 norm! gUgU
1494 call assert_equal('THIS IS A SIMPLE TEST: ÄÜÖSS', getline('.'))
1495 norm! gugu
1496 call assert_equal('this is a simple test: äüöss', getline('.'))
1497 norm! gUU
1498 call assert_equal('THIS IS A SIMPLE TEST: ÄÜÖSS', getline('.'))
1499 norm! 010~
1500 call assert_equal('this is a SIMPLE TEST: ÄÜÖSS', getline('.'))
1501 norm! V~
1502 call assert_equal('THIS IS A simple test: äüöss', getline('.'))
1503
1504 " clean up
1505 bw!
1506endfu
1507
1508fun! Test_normal31_r_cmd()
1509 " Test for r command
1510 new
1511 call append(0, 'This is a simple test: abcd')
1512 exe "norm! 1gg$r\<cr>"
1513 call assert_equal(['This is a simple test: abc', '', ''], getline(1,'$'))
1514 exe "norm! 1gg2wlr\<cr>"
1515 call assert_equal(['This is a', 'simple test: abc', '', ''], getline(1,'$'))
1516 exe "norm! 2gg0W5r\<cr>"
1517 call assert_equal(['This is a', 'simple ', ' abc', '', ''], getline('1', '$'))
1518 set autoindent
1519 call setline(2, ['simple test: abc', ''])
1520 exe "norm! 2gg0W5r\<cr>"
1521 call assert_equal(['This is a', 'simple ', 'abc', '', '', ''], getline('1', '$'))
1522 exe "norm! 1ggVr\<cr>"
1523 call assert_equal('^M^M^M^M^M^M^M^M^M', strtrans(getline(1)))
1524 call setline(1, 'This is a')
1525 exe "norm! 1gg05rf"
1526 call assert_equal('fffffis a', getline(1))
1527
1528 " clean up
1529 set noautoindent
1530 bw!
1531endfu
1532
1533func! Test_normal32_g_cmd1()
1534 " Test for g*, g#
1535 new
1536 call append(0, ['abc.x_foo', 'x_foobar.abc'])
1537 1
1538 norm! $g*
1539 call assert_equal('x_foo', @/)
1540 call assert_equal('x_foobar.abc', getline('.'))
1541 norm! $g#
1542 call assert_equal('abc', @/)
1543 call assert_equal('abc.x_foo', getline('.'))
1544
1545 " clean up
1546 bw!
1547endfu
1548
1549fun! Test_normal33_g_cmd2()
1550 if !has("jumplist")
1551 return
1552 endif
1553 " Tests for g cmds
1554 call Setup_NewWindow()
1555 " Test for g`
1556 clearjumps
1557 norm! ma10j
1558 let a=execute(':jumps')
1559 " empty jumplist
1560 call assert_equal('>', a[-1:])
1561 norm! g`a
1562 call assert_equal('>', a[-1:])
1563 call assert_equal(1, line('.'))
1564 call assert_equal('1', getline('.'))
1565
1566 " Test for g; and g,
1567 norm! g;
1568 " there is only one change in the changelist
1569 " currently, when we setup the window
1570 call assert_equal(2, line('.'))
1571 call assert_fails(':norm! g;', 'E662')
1572 call assert_fails(':norm! g,', 'E663')
1573 let &ul=&ul
1574 call append('$', ['a', 'b', 'c', 'd'])
1575 let &ul=&ul
1576 call append('$', ['Z', 'Y', 'X', 'W'])
1577 let a = execute(':changes')
1578 call assert_match('2\s\+0\s\+2', a)
1579 call assert_match('101\s\+0\s\+a', a)
1580 call assert_match('105\s\+0\s\+Z', a)
1581 norm! 3g;
1582 call assert_equal(2, line('.'))
1583 norm! 2g,
1584 call assert_equal(105, line('.'))
1585
1586 " Test for g& - global substitute
1587 %d
1588 call setline(1, range(1,10))
1589 call append('$', ['a', 'b', 'c', 'd'])
1590 $s/\w/&&/g
1591 exe "norm! /[1-8]\<cr>"
1592 norm! g&
1593 call assert_equal(['11', '22', '33', '44', '55', '66', '77', '88', '9', '110', 'a', 'b', 'c', 'dd'], getline(1, '$'))
1594
1595 " Test for gv
1596 %d
1597 call append('$', repeat(['abcdefgh'], 8))
1598 exe "norm! 2gg02l\<c-v>2j2ly"
1599 call assert_equal(['cde', 'cde', 'cde'], getreg(0, 1, 1))
1600 " in visual mode, gv swaps current and last selected region
1601 exe "norm! G0\<c-v>4k4lgvd"
1602 call assert_equal(['', 'abfgh', 'abfgh', 'abfgh', 'abcdefgh', 'abcdefgh', 'abcdefgh', 'abcdefgh', 'abcdefgh'], getline(1,'$'))
1603 exe "norm! G0\<c-v>4k4ly"
1604 exe "norm! gvood"
1605 call assert_equal(['', 'abfgh', 'abfgh', 'abfgh', 'fgh', 'fgh', 'fgh', 'fgh', 'fgh'], getline(1,'$'))
1606
1607 " Test for gk/gj
1608 %d
1609 15vsp
1610 set wrap listchars= sbr=
1611 let lineA='abcdefghijklmnopqrstuvwxyz'
1612 let lineB='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'
1613 $put =lineA
1614 $put =lineB
1615
1616 norm! 3gg0dgk
1617 call assert_equal(['', 'abcdefghijklmno', '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'], getline(1, '$'))
1618 set nu
1619 norm! 3gg0gjdgj
1620 call assert_equal(['', 'abcdefghijklmno', '0123456789AMNOPQRSTUVWXYZ'], getline(1,'$'))
1621
1622 " Test for gJ
1623 norm! 2gggJ
1624 call assert_equal(['', 'abcdefghijklmno0123456789AMNOPQRSTUVWXYZ'], getline(1,'$'))
1625 call assert_equal(16, col('.'))
1626 " shouldn't do anything
1627 norm! 10gJ
1628 call assert_equal(1, col('.'))
1629
1630 " Test for g0 g^ gm g$
1631 exe "norm! 2gg0gji "
1632 call assert_equal(['', 'abcdefghijk lmno0123456789AMNOPQRSTUVWXYZ'], getline(1,'$'))
1633 norm! g0yl
1634 call assert_equal(12, col('.'))
1635 call assert_equal(' ', getreg(0))
1636 norm! g$yl
1637 call assert_equal(22, col('.'))
1638 call assert_equal('3', getreg(0))
1639 norm! gmyl
1640 call assert_equal(17, col('.'))
1641 call assert_equal('n', getreg(0))
1642 norm! g^yl
1643 call assert_equal(15, col('.'))
1644 call assert_equal('l', getreg(0))
1645
1646 " Test for g Ctrl-G
Bram Moolenaar0913a102016-09-03 19:11:59 +02001647 set ff=unix
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001648 let a=execute(":norm! g\<c-g>")
1649 call assert_match('Col 15 of 43; Line 2 of 2; Word 2 of 2; Byte 16 of 45', a)
1650
1651 " Test for gI
1652 norm! gIfoo
1653 call assert_equal(['', 'fooabcdefghijk lmno0123456789AMNOPQRSTUVWXYZ'], getline(1,'$'))
1654
1655 " Test for gi
1656 wincmd c
1657 %d
1658 set tw=0
1659 call setline(1, ['foobar', 'new line'])
1660 norm! A next word
1661 $put ='third line'
1662 norm! gi another word
1663 call assert_equal(['foobar next word another word', 'new line', 'third line'], getline(1,'$'))
1664
1665 " clean up
1666 bw!
1667endfu
1668
1669fun! Test_normal34_g_cmd3()
1670 if !has("multi_byte")
1671 return
1672 endif
1673 " Test for g8
1674 new
1675 call append(0, 'abcdefghijklmnopqrstuvwxyzäüö')
1676 let a=execute(':norm! 1gg$g8')
1677 call assert_equal('c3 b6 ', a[1:])
1678
1679 " Test for gp gP
1680 call append(1, range(1,10))
1681 " clean up
1682 bw!
1683endfu
1684
1685fun! Test_normal35_g_cmd4()
1686 " Test for g<
1687 " Cannot capture its output,
1688 " probably a bug, therefore, test disabled:
Bram Moolenaar31845092016-09-05 22:58:31 +02001689 throw "Skipped: output of g< can't be tested currently"
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001690 echo "a\nb\nc\nd"
1691 let b=execute(':norm! g<')
1692 call assert_true(!empty(b), 'failed `execute(g<)`')
1693endfu
1694
1695fun! Test_normal36_g_cmd5()
1696 new
1697 call append(0, 'abcdefghijklmnopqrstuvwxyz')
Bram Moolenaar0913a102016-09-03 19:11:59 +02001698 set ff=unix
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001699 " Test for gp gP
1700 call append(1, range(1,10))
1701 1
1702 norm! 1yy
1703 3
1704 norm! gp
1705 call assert_equal([0, 5, 1, 0, 1], getcurpos())
1706 $
1707 norm! gP
1708 call assert_equal([0, 14, 1, 0, 1], getcurpos())
1709
1710 " Test for go
1711 norm! 26go
1712 call assert_equal([0, 1, 26, 0, 26], getcurpos())
1713 norm! 27go
1714 call assert_equal([0, 1, 26, 0, 26], getcurpos())
1715 norm! 28go
1716 call assert_equal([0, 2, 1, 0, 1], getcurpos())
1717 set ff=dos
1718 norm! 29go
1719 call assert_equal([0, 2, 1, 0, 1], getcurpos())
1720 set ff=unix
1721 norm! gg0
1722 norm! 101go
1723 call assert_equal([0, 13, 26, 0, 26], getcurpos())
1724 norm! 103go
1725 call assert_equal([0, 14, 1, 0, 1], getcurpos())
1726 " count > buffer content
1727 norm! 120go
1728 call assert_equal([0, 14, 1, 0, 2147483647], getcurpos())
1729 " clean up
1730 bw!
1731endfu
1732
1733fun! Test_normal37_g_cmd6()
1734 " basic test for gt and gT
1735 tabnew 1.txt
1736 tabnew 2.txt
1737 tabnew 3.txt
1738 norm! 1gt
1739 call assert_equal(1, tabpagenr())
1740 norm! 3gt
1741 call assert_equal(3, tabpagenr())
1742 norm! 1gT
1743 " count gT goes not to the absolute tabpagenumber
1744 " but, but goes to the count previous tabpagenumber
1745 call assert_equal(2, tabpagenr())
1746 " wrap around
1747 norm! 3gT
1748 call assert_equal(3, tabpagenr())
1749 " gt does not wrap around
1750 norm! 5gt
1751 call assert_equal(3, tabpagenr())
1752
1753 for i in range(3)
1754 tabclose
1755 endfor
1756 " clean up
1757 call assert_fails(':tabclose', 'E784')
1758endfu
1759
1760fun! Test_normal38_nvhome()
1761 " Test for <Home> and <C-Home> key
1762 new
1763 call setline(1, range(10))
1764 $
1765 setl et sw=2
1766 norm! V10>$
1767 " count is ignored
1768 exe "norm! 10\<home>"
1769 call assert_equal(1, col('.'))
1770 exe "norm! \<home>"
1771 call assert_equal([0, 10, 1, 0, 1], getcurpos())
1772 exe "norm! 5\<c-home>"
1773 call assert_equal([0, 5, 1, 0, 1], getcurpos())
1774 exe "norm! \<c-home>"
1775 call assert_equal([0, 1, 1, 0, 1], getcurpos())
1776
1777 " clean up
1778 bw!
1779endfu
1780
1781fun! Test_normal39_cw()
1782 " Test for cw and cW on whitespace
1783 " and cpo+=w setting
1784 new
1785 set tw=0
1786 call append(0, 'here are some words')
1787 norm! 1gg0elcwZZZ
1788 call assert_equal('hereZZZare some words', getline('.'))
1789 norm! 1gg0elcWYYY
1790 call assert_equal('hereZZZareYYYsome words', getline('.'))
1791 set cpo+=w
1792 call setline(1, 'here are some words')
1793 norm! 1gg0elcwZZZ
1794 call assert_equal('hereZZZ are some words', getline('.'))
1795 norm! 1gg2elcWYYY
1796 call assert_equal('hereZZZ areYYY some words', getline('.'))
1797 set cpo-=w
1798 norm! 2gg0cwfoo
1799 call assert_equal('foo', getline('.'))
1800
1801 " clean up
1802 bw!
1803endfu
1804
1805fun! Test_normal40_ctrl_bsl()
1806 " Basic test for CTRL-\ commands
1807 new
1808 call append(0, 'here are some words')
1809 exe "norm! 1gg0a\<C-\>\<C-N>"
1810 call assert_equal('n', mode())
1811 call assert_equal(1, col('.'))
1812 call assert_equal('', visualmode())
1813 exe "norm! 1gg0viw\<C-\>\<C-N>"
1814 call assert_equal('n', mode())
1815 call assert_equal(4, col('.'))
1816 exe "norm! 1gg0a\<C-\>\<C-G>"
1817 call assert_equal('n', mode())
1818 call assert_equal(1, col('.'))
1819 "imap <buffer> , <c-\><c-n>
1820 set im
1821 exe ":norm! \<c-\>\<c-n>dw"
1822 set noim
1823 call assert_equal('are some words', getline(1))
1824 call assert_false(&insertmode)
1825
1826 " clean up
1827 bw!
1828endfu
1829
1830fun! Test_normal41_insert_reg()
1831 " Test for <c-r>=, <c-r><c-r>= and <c-r><c-o>=
1832 " in insert mode
1833 new
1834 set sts=2 sw=2 ts=8 tw=0
1835 call append(0, ["aaa\tbbb\tccc", '', '', ''])
1836 let a=getline(1)
1837 norm! 2gg0
1838 exe "norm! a\<c-r>=a\<cr>"
1839 norm! 3gg0
1840 exe "norm! a\<c-r>\<c-r>=a\<cr>"
1841 norm! 4gg0
1842 exe "norm! a\<c-r>\<c-o>=a\<cr>"
1843 call assert_equal(['aaa bbb ccc', 'aaa bbb ccc', 'aaa bbb ccc', 'aaa bbb ccc', ''], getline(1, '$'))
1844
1845 " clean up
1846 set sts=0 sw=8 ts=8
Bram Moolenaar31845092016-09-05 22:58:31 +02001847 bw!
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001848endfu
1849
1850func! Test_normal42_halfpage()
1851 " basic test for Ctrl-D and Ctrl-U
1852 call Setup_NewWindow()
1853 call assert_equal(5, &scroll)
1854 exe "norm! \<c-d>"
1855 call assert_equal('6', getline('.'))
1856 exe "norm! 2\<c-d>"
1857 call assert_equal('8', getline('.'))
1858 call assert_equal(2, &scroll)
1859 set scroll=5
1860 exe "norm! \<c-u>"
1861 call assert_equal('3', getline('.'))
1862 1
1863 set scrolloff=5
1864 exe "norm! \<c-d>"
1865 call assert_equal('10', getline('.'))
1866 exe "norm! \<c-u>"
1867 call assert_equal('5', getline('.'))
1868 1
1869 set scrolloff=99
1870 exe "norm! \<c-d>"
1871 call assert_equal('10', getline('.'))
1872 set scrolloff=0
1873 100
1874 exe "norm! $\<c-u>"
1875 call assert_equal('95', getline('.'))
1876 call assert_equal([0, 95, 1, 0, 1], getcurpos())
1877 100
1878 set nostartofline
1879 exe "norm! $\<c-u>"
1880 call assert_equal('95', getline('.'))
1881 call assert_equal([0, 95, 2, 0, 2147483647], getcurpos())
1882 " cleanup
1883 set startofline
1884 bw!
1885endfu
1886
1887fun! Test_normal43_textobject1()
1888 " basic tests for text object aw
1889 new
1890 call append(0, ['foobar,eins,foobar', 'foo,zwei,foo '])
1891 " diw
1892 norm! 1gg0diw
1893 call assert_equal([',eins,foobar', 'foo,zwei,foo ', ''], getline(1,'$'))
1894 " daw
1895 norm! 2ggEdaw
1896 call assert_equal([',eins,foobar', 'foo,zwei,', ''], getline(1, '$'))
1897 %d
1898 call append(0, ["foo\teins\tfoobar", "foo\tzwei\tfoo "])
1899 " diW
1900 norm! 2ggwd2iW
1901 call assert_equal(['foo eins foobar', 'foo foo ', ''], getline(1,'$'))
1902 " daW
1903 norm! 1ggd2aW
1904 call assert_equal(['foobar', 'foo foo ', ''], getline(1,'$'))
1905
1906 %d
1907 call append(0, ["foo\teins\tfoobar", "foo\tzwei\tfoo "])
1908 " aw in visual line mode switches to characterwise mode
1909 norm! 2gg$Vawd
1910 call assert_equal(['foo eins foobar', 'foo zwei foo'], getline(1,'$'))
1911 norm! 1gg$Viwd
1912 call assert_equal(['foo eins ', 'foo zwei foo'], getline(1,'$'))
1913
1914 " clean up
1915 bw!
1916endfu
1917
1918func! Test_normal44_textobjects2()
1919 " basic testing for is and as text objects
1920 new
1921 call append(0, ['This is a test. With some sentences!', '', 'Even with a question? And one more. And no sentence here'])
1922 " Test for dis - does not remove trailing whitespace
1923 norm! 1gg0dis
1924 call assert_equal([' With some sentences!', '', 'Even with a question? And one more. And no sentence here', ''], getline(1,'$'))
1925 " Test for das - removes leading whitespace
1926 norm! 3ggf?ldas
1927 call assert_equal([' With some sentences!', '', 'Even with a question? And no sentence here', ''], getline(1,'$'))
1928 " when used in visual mode, is made characterwise
1929 norm! 3gg$Visy
1930 call assert_equal('v', visualmode())
1931 " reset visualmode()
1932 norm! 3ggVy
1933 norm! 3gg$Vasy
1934 call assert_equal('v', visualmode())
1935 " basic testing for textobjects a< and at
1936 %d
1937 call setline(1, ['<div> ','<a href="foobar" class="foo">xyz</a>',' </div>', ' '])
1938 " a<
1939 norm! 1gg0da<
1940 call assert_equal([' ', '<a href="foobar" class="foo">xyz</a>', ' </div>', ' '], getline(1,'$'))
1941 norm! 1pj
1942 call assert_equal([' <div>', '<a href="foobar" class="foo">xyz</a>', ' </div>', ' '], getline(1,'$'))
1943 " at
1944 norm! d2at
1945 call assert_equal([' '], getline(1,'$'))
1946 %d
1947 call setline(1, ['<div> ','<a href="foobar" class="foo">xyz</a>',' </div>', ' '])
1948 " i<
1949 norm! 1gg0di<
1950 call assert_equal(['<> ', '<a href="foobar" class="foo">xyz</a>', ' </div>', ' '], getline(1,'$'))
1951 norm! 1Pj
1952 call assert_equal(['<div> ', '<a href="foobar" class="foo">xyz</a>', ' </div>', ' '], getline(1,'$'))
1953 norm! d2it
1954 call assert_equal(['<div></div>',' '], getline(1,'$'))
1955 " basic testing for a[ and i[ text object
1956 %d
1957 call setline(1, [' ', '[', 'one [two]', 'thre', ']'])
1958 norm! 3gg0di[
1959 call assert_equal([' ', '[', ']'], getline(1,'$'))
1960 call setline(1, [' ', '[', 'one [two]', 'thre', ']'])
1961 norm! 3gg0ftd2a[
1962 call assert_equal([' '], getline(1,'$'))
1963 %d
1964 " Test for i" when cursor is in front of a quoted object
1965 call append(0, 'foo "bar"')
1966 norm! 1gg0di"
1967 call assert_equal(['foo ""', ''], getline(1,'$'))
1968
1969 " clean up
1970 bw!
1971endfu
1972
1973func! Test_normal45_drop()
1974 if !has("dnd")
1975 return
1976 endif
1977 " basic test for :drop command
1978 " unfortunately, without a gui, we can't really test much here,
1979 " so simply test that ~p fails (which uses the drop register)
1980 new
1981 call assert_fails(':norm! "~p', 'E353')
1982 call assert_equal([], getreg('~', 1, 1))
1983 " the ~ register is read only
1984 call assert_fails(':let @~="1"', 'E354')
1985 bw!
1986endfu
1987
1988func! Test_normal46_ignore()
1989 new
1990 " How to test this?
1991 " let's just for now test, that the buffer
1992 " does not change
1993 call feedkeys("\<c-s>", 't')
1994 call assert_equal([''], getline(1,'$'))
1995
1996 " clean up
1997 bw!
1998endfu