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