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