blob: 5882f531699db17ed47d931d1305181c86b479d4 [file] [log] [blame]
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001" Test for various Normal mode commands
2
Bram Moolenaara84a3dd2019-03-25 22:21:24 +01003source shared.vim
Bram Moolenaar5a4c3082019-12-01 15:23:11 +01004source check.vim
Bram Moolenaara84a3dd2019-03-25 22:21:24 +01005
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01006func Setup_NewWindow()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02007 10new
8 call setline(1, range(1,100))
9endfunc
10
Bram Moolenaar1bbb6192018-11-10 16:02:01 +010011func MyFormatExpr()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +020012 " Adds '->$' at lines having numbers followed by trailing whitespace
13 for ln in range(v:lnum, v:lnum+v:count-1)
14 let line = getline(ln)
15 if getline(ln) =~# '\d\s\+$'
16 call setline(ln, substitute(line, '\s\+$', '', '') . '->$')
17 endif
18 endfor
Bram Moolenaar2931f2a2016-09-09 16:59:08 +020019endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +020020
Bram Moolenaar1bbb6192018-11-10 16:02:01 +010021func CountSpaces(type, ...)
Bram Moolenaar87bc3f72016-09-03 17:33:54 +020022 " for testing operatorfunc
23 " will count the number of spaces
24 " and return the result in g:a
25 let sel_save = &selection
26 let &selection = "inclusive"
27 let reg_save = @@
28
29 if a:0 " Invoked from Visual mode, use gv command.
30 silent exe "normal! gvy"
31 elseif a:type == 'line'
32 silent exe "normal! '[V']y"
33 else
34 silent exe "normal! `[v`]y"
35 endif
36 let g:a=strlen(substitute(@@, '[^ ]', '', 'g'))
37 let &selection = sel_save
38 let @@ = reg_save
Bram Moolenaar2931f2a2016-09-09 16:59:08 +020039endfunc
40
Bram Moolenaar1bbb6192018-11-10 16:02:01 +010041func OpfuncDummy(type, ...)
Bram Moolenaar4a08b0d2016-11-05 21:55:13 +010042 " for testing operatorfunc
43 let g:opt=&linebreak
44
45 if a:0 " Invoked from Visual mode, use gv command.
46 silent exe "normal! gvy"
47 elseif a:type == 'line'
48 silent exe "normal! '[V']y"
49 else
50 silent exe "normal! `[v`]y"
51 endif
52 " Create a new dummy window
53 new
54 let g:bufnr=bufnr('%')
Bram Moolenaar2931f2a2016-09-09 16:59:08 +020055endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +020056
Bram Moolenaar1671f442020-03-10 07:48:13 +010057func Test_normal00_optrans()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +020058 new
59 call append(0, ['1 This is a simple test: abcd', '2 This is the second line', '3 this is the third line'])
60 1
61 exe "norm! Sfoobar\<esc>"
62 call assert_equal(['foobar', '2 This is the second line', '3 this is the third line', ''], getline(1,'$'))
63 2
Bram Moolenaar87bc3f72016-09-03 17:33:54 +020064 exe "norm! $vbsone"
65 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 +020066 norm! VS Second line here
67 call assert_equal(['foobar', ' Second line here', '3 this is the third line', ''], getline(1, '$'))
68 %d
69 call append(0, ['4 This is a simple test: abcd', '5 This is the second line', '6 this is the third line'])
70 call append(0, ['1 This is a simple test: abcd', '2 This is the second line', '3 this is the third line'])
71
72 1
73 norm! 2D
74 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,'$'))
75 set cpo+=#
76 norm! 4D
77 call assert_equal(['', '4 This is a simple test: abcd', '5 This is the second line', '6 this is the third line', ''], getline(1,'$'))
78
79 " clean up
80 set cpo-=#
81 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +020082endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +020083
Bram Moolenaar1bbb6192018-11-10 16:02:01 +010084func Test_normal01_keymodel()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +020085 call Setup_NewWindow()
86 " Test 1: depending on 'keymodel' <s-down> does something different
Bram Moolenaar2931f2a2016-09-09 16:59:08 +020087 50
Bram Moolenaar87bc3f72016-09-03 17:33:54 +020088 call feedkeys("V\<S-Up>y", 'tx')
89 call assert_equal(['47', '48', '49', '50'], getline("'<", "'>"))
Bram Moolenaar2931f2a2016-09-09 16:59:08 +020090 set keymodel=startsel
91 50
Bram Moolenaar87bc3f72016-09-03 17:33:54 +020092 call feedkeys("V\<S-Up>y", 'tx')
93 call assert_equal(['49', '50'], getline("'<", "'>"))
94 " Start visual mode when keymodel = startsel
Bram Moolenaar2931f2a2016-09-09 16:59:08 +020095 50
Bram Moolenaar87bc3f72016-09-03 17:33:54 +020096 call feedkeys("\<S-Up>y", 'tx')
97 call assert_equal(['49', '5'], getreg(0, 0, 1))
Bram Moolenaar1671f442020-03-10 07:48:13 +010098 " Use the different Shift special keys
99 50
100 call feedkeys("\<S-Right>\<S-Left>\<S-Up>\<S-Down>\<S-Home>\<S-End>y", 'tx')
101 call assert_equal(['50'], getline("'<", "'>"))
102 call assert_equal(['50', ''], getreg(0, 0, 1))
103
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200104 " Do not start visual mode when keymodel=
Bram Moolenaar2931f2a2016-09-09 16:59:08 +0200105 set keymodel=
106 50
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200107 call feedkeys("\<S-Up>y$", 'tx')
108 call assert_equal(['42'], getreg(0, 0, 1))
Bram Moolenaar2931f2a2016-09-09 16:59:08 +0200109 " Stop visual mode when keymodel=stopsel
110 set keymodel=stopsel
111 50
112 call feedkeys("Vkk\<Up>yy", 'tx')
113 call assert_equal(['47'], getreg(0, 0, 1))
114
115 set keymodel=
116 50
117 call feedkeys("Vkk\<Up>yy", 'tx')
118 call assert_equal(['47', '48', '49', '50'], getreg(0, 0, 1))
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200119
120 " clean up
121 bw!
122endfunc
123
Bram Moolenaarf5f1e102020-03-08 05:13:15 +0100124" Test for select mode
Bram Moolenaar1bbb6192018-11-10 16:02:01 +0100125func Test_normal02_selectmode()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200126 call Setup_NewWindow()
127 50
128 norm! gHy
129 call assert_equal('y51', getline('.'))
130 call setline(1, range(1,100))
131 50
132 exe ":norm! V9jo\<c-g>y"
133 call assert_equal('y60', getline('.'))
134 " clean up
135 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +0200136endfunc
137
Bram Moolenaar1bbb6192018-11-10 16:02:01 +0100138func Test_normal02_selectmode2()
Bram Moolenaar2931f2a2016-09-09 16:59:08 +0200139 " some basic select mode tests
140 call Setup_NewWindow()
141 50
142 call feedkeys(":set im\n\<c-o>gHc\<c-o>:set noim\n", 'tx')
143 call assert_equal('c51', getline('.'))
144 " clean up
145 bw!
146endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200147
Bram Moolenaar1bbb6192018-11-10 16:02:01 +0100148func Test_normal03_join()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200149 " basic join test
150 call Setup_NewWindow()
151 50
152 norm! VJ
153 call assert_equal('50 51', getline('.'))
154 $
155 norm! J
156 call assert_equal('100', getline('.'))
157 $
158 norm! V9-gJ
159 call assert_equal('919293949596979899100', getline('.'))
160 call setline(1, range(1,100))
161 $
162 :j 10
163 call assert_equal('100', getline('.'))
164 " clean up
165 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +0200166endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200167
Bram Moolenaar1bbb6192018-11-10 16:02:01 +0100168func Test_normal04_filter()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200169 " basic filter test
170 " only test on non windows platform
Bram Moolenaar4a08b0d2016-11-05 21:55:13 +0100171 if has('win32')
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200172 return
173 endif
174 call Setup_NewWindow()
175 1
176 call feedkeys("!!sed -e 's/^/| /'\n", 'tx')
177 call assert_equal('| 1', getline('.'))
178 90
179 :sil :!echo one
180 call feedkeys('.', 'tx')
181 call assert_equal('| 90', getline('.'))
182 95
183 set cpo+=!
184 " 2 <CR>, 1: for executing the command,
185 " 2: clear hit-enter-prompt
186 call feedkeys("!!\n", 'tx')
187 call feedkeys(":!echo one\n\n", 'tx')
188 call feedkeys(".", 'tx')
189 call assert_equal('one', getline('.'))
190 set cpo-=!
191 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +0200192endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200193
Bram Moolenaar1bbb6192018-11-10 16:02:01 +0100194func Test_normal05_formatexpr()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200195 " basic formatexpr test
196 call Setup_NewWindow()
197 %d_
198 call setline(1, ['here: 1 ', '2', 'here: 3 ', '4', 'not here: '])
199 1
200 set formatexpr=MyFormatExpr()
201 norm! gqG
202 call assert_equal(['here: 1->$', '2', 'here: 3->$', '4', 'not here: '], getline(1,'$'))
203 set formatexpr=
204 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +0200205endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200206
Bram Moolenaard77f9d52016-09-04 15:13:39 +0200207func Test_normal05_formatexpr_newbuf()
208 " Edit another buffer in the 'formatexpr' function
209 new
210 func! Format()
211 edit another
212 endfunc
213 set formatexpr=Format()
214 norm gqG
215 bw!
216 set formatexpr=
217endfunc
218
219func Test_normal05_formatexpr_setopt()
220 " Change the 'formatexpr' value in the function
221 new
222 func! Format()
223 set formatexpr=
224 endfunc
225 set formatexpr=Format()
226 norm gqG
227 bw!
228 set formatexpr=
229endfunc
230
Bram Moolenaar1bbb6192018-11-10 16:02:01 +0100231func Test_normal06_formatprg()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200232 " basic test for formatprg
233 " only test on non windows platform
Bram Moolenaar4a08b0d2016-11-05 21:55:13 +0100234 if has('win32')
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200235 return
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200236 endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +0100237
238 " uses sed to number non-empty lines
239 call writefile(['#!/bin/sh', 'sed ''/./=''|sed ''/./{', 'N', 's/\n/ /', '}'''], 'Xsed_format.sh')
240 call system('chmod +x ./Xsed_format.sh')
241 let text = ['a', '', 'c', '', ' ', 'd', 'e']
242 let expected = ['1 a', '', '3 c', '', '5 ', '6 d', '7 e']
243
244 10new
245 call setline(1, text)
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200246 set formatprg=./Xsed_format.sh
247 norm! gggqG
Bram Moolenaar9be7c042017-01-14 14:28:30 +0100248 call assert_equal(expected, getline(1, '$'))
249 bw!
250
251 10new
252 call setline(1, text)
253 set formatprg=donothing
254 setlocal formatprg=./Xsed_format.sh
255 norm! gggqG
256 call assert_equal(expected, getline(1, '$'))
257 bw!
258
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200259 " clean up
260 set formatprg=
Bram Moolenaar9be7c042017-01-14 14:28:30 +0100261 setlocal formatprg=
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200262 call delete('Xsed_format.sh')
Bram Moolenaar2931f2a2016-09-09 16:59:08 +0200263endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200264
Bram Moolenaar1bbb6192018-11-10 16:02:01 +0100265func Test_normal07_internalfmt()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200266 " basic test for internal formmatter to textwidth of 12
267 let list=range(1,11)
268 call map(list, 'v:val." "')
269 10new
270 call setline(1, list)
271 set tw=12
272 norm! gggqG
273 call assert_equal(['1 2 3', '4 5 6', '7 8 9', '10 11 '], getline(1, '$'))
274 " clean up
Bram Moolenaar9be7c042017-01-14 14:28:30 +0100275 set tw=0
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200276 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +0200277endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200278
Bram Moolenaar1bbb6192018-11-10 16:02:01 +0100279func Test_normal08_fold()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200280 " basic tests for foldopen/folddelete
281 if !has("folding")
282 return
283 endif
284 call Setup_NewWindow()
285 50
286 setl foldenable fdm=marker
287 " First fold
288 norm! V4jzf
289 " check that folds have been created
290 call assert_equal(['50/*{{{*/', '51', '52', '53', '54/*}}}*/'], getline(50,54))
291 " Second fold
292 46
293 norm! V10jzf
294 " check that folds have been created
295 call assert_equal('46/*{{{*/', getline(46))
296 call assert_equal('60/*}}}*/', getline(60))
297 norm! k
298 call assert_equal('45', getline('.'))
299 norm! j
300 call assert_equal('46/*{{{*/', getline('.'))
301 norm! j
302 call assert_equal('61', getline('.'))
303 norm! k
304 " open a fold
305 norm! Vzo
306 norm! k
307 call assert_equal('45', getline('.'))
308 norm! j
309 call assert_equal('46/*{{{*/', getline('.'))
310 norm! j
311 call assert_equal('47', getline('.'))
312 norm! k
313 norm! zcVzO
314 call assert_equal('46/*{{{*/', getline('.'))
315 norm! j
316 call assert_equal('47', getline('.'))
317 norm! j
318 call assert_equal('48', getline('.'))
319 norm! j
320 call assert_equal('49', getline('.'))
321 norm! j
322 call assert_equal('50/*{{{*/', getline('.'))
323 norm! j
324 call assert_equal('51', getline('.'))
325 " delete folds
326 :46
327 " collapse fold
328 norm! V14jzC
329 " delete all folds recursively
330 norm! VzD
331 call assert_equal(['46', '47', '48', '49', '50', '51', '52', '53', '54', '55', '56', '57', '58', '59', '60'], getline(46,60))
332
333 " clean up
334 setl nofoldenable fdm=marker
335 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +0200336endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200337
Bram Moolenaar1bbb6192018-11-10 16:02:01 +0100338func Test_normal09_operatorfunc()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200339 " Test operatorfunc
340 call Setup_NewWindow()
341 " Add some spaces for counting
342 50,60s/$/ /
343 unlet! g:a
344 let g:a=0
345 nmap <buffer><silent> ,, :set opfunc=CountSpaces<CR>g@
346 vmap <buffer><silent> ,, :<C-U>call CountSpaces(visualmode(), 1)<CR>
347 50
348 norm V2j,,
349 call assert_equal(6, g:a)
350 norm V,,
351 call assert_equal(2, g:a)
352 norm ,,l
353 call assert_equal(0, g:a)
354 50
355 exe "norm 0\<c-v>10j2l,,"
356 call assert_equal(11, g:a)
357 50
358 norm V10j,,
359 call assert_equal(22, g:a)
360
361 " clean up
362 unmap <buffer> ,,
363 set opfunc=
Bram Moolenaar4a08b0d2016-11-05 21:55:13 +0100364 unlet! g:a
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200365 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +0200366endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200367
Bram Moolenaar1bbb6192018-11-10 16:02:01 +0100368func Test_normal09a_operatorfunc()
Bram Moolenaar4a08b0d2016-11-05 21:55:13 +0100369 " Test operatorfunc
370 call Setup_NewWindow()
371 " Add some spaces for counting
372 50,60s/$/ /
373 unlet! g:opt
374 set linebreak
375 nmap <buffer><silent> ,, :set opfunc=OpfuncDummy<CR>g@
376 50
377 norm ,,j
378 exe "bd!" g:bufnr
379 call assert_true(&linebreak)
380 call assert_equal(g:opt, &linebreak)
381 set nolinebreak
382 norm ,,j
383 exe "bd!" g:bufnr
384 call assert_false(&linebreak)
385 call assert_equal(g:opt, &linebreak)
386
387 " clean up
388 unmap <buffer> ,,
389 set opfunc=
390 bw!
391 unlet! g:opt
392endfunc
393
Bram Moolenaar1bbb6192018-11-10 16:02:01 +0100394func Test_normal10_expand()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200395 " Test for expand()
396 10new
397 call setline(1, ['1', 'ifooar,,cbar'])
398 2
399 norm! $
Bram Moolenaar65f08472017-09-10 18:16:20 +0200400 call assert_equal('cbar', expand('<cword>'))
401 call assert_equal('ifooar,,cbar', expand('<cWORD>'))
402
403 call setline(1, ['prx = list[idx];'])
404 1
405 let expected = ['', 'prx', 'prx', 'prx',
406 \ 'list', 'list', 'list', 'list', 'list', 'list', 'list',
407 \ 'idx', 'idx', 'idx', 'idx',
408 \ 'list[idx]',
409 \ '];',
410 \ ]
411 for i in range(1, 16)
412 exe 'norm ' . i . '|'
413 call assert_equal(expected[i], expand('<cexpr>'), 'i == ' . i)
414 endfor
415
Bram Moolenaarae6f8652017-12-20 22:32:20 +0100416 if executable('echo')
417 " Test expand(`...`) i.e. backticks command expansion.
Bram Moolenaar077ff432019-10-28 00:42:21 +0100418 call assert_equal('abcde', expand('`echo abcde`'))
Bram Moolenaarae6f8652017-12-20 22:32:20 +0100419 endif
420
421 " Test expand(`=...`) i.e. backticks expression expansion
422 call assert_equal('5', expand('`=2+3`'))
Bram Moolenaar8b633132020-03-20 18:20:51 +0100423 call assert_equal('3.14', expand('`=3.14`'))
Bram Moolenaarae6f8652017-12-20 22:32:20 +0100424
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200425 " clean up
426 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +0200427endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200428
Bram Moolenaar1bbb6192018-11-10 16:02:01 +0100429func Test_normal11_showcmd()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200430 " test for 'showcmd'
431 10new
432 exe "norm! ofoobar\<esc>"
433 call assert_equal(2, line('$'))
434 set showcmd
435 exe "norm! ofoobar2\<esc>"
436 call assert_equal(3, line('$'))
437 exe "norm! VAfoobar3\<esc>"
438 call assert_equal(3, line('$'))
439 exe "norm! 0d3\<del>2l"
440 call assert_equal('obar2foobar3', getline('.'))
441 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +0200442endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200443
Bram Moolenaar1671f442020-03-10 07:48:13 +0100444" Test for nv_error and normal command errors
Bram Moolenaar1bbb6192018-11-10 16:02:01 +0100445func Test_normal12_nv_error()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200446 10new
447 call setline(1, range(1,5))
448 " should not do anything, just beep
Bram Moolenaarf5f1e102020-03-08 05:13:15 +0100449 call assert_beeps('exe "norm! <c-k>"')
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200450 call assert_equal(map(range(1,5), 'string(v:val)'), getline(1,'$'))
Bram Moolenaarf5f1e102020-03-08 05:13:15 +0100451 call assert_beeps('normal! G2dd')
452 call assert_beeps("normal! g\<C-A>")
453 call assert_beeps("normal! g\<C-X>")
454 call assert_beeps("normal! g\<C-B>")
Bram Moolenaar1671f442020-03-10 07:48:13 +0100455 call assert_beeps("normal! vQ\<Esc>")
456 call assert_beeps("normal! 2[[")
457 call assert_beeps("normal! 2]]")
458 call assert_beeps("normal! 2[]")
459 call assert_beeps("normal! 2][")
460 call assert_beeps("normal! 4[z")
461 call assert_beeps("normal! 4]z")
462 call assert_beeps("normal! 4[c")
463 call assert_beeps("normal! 4]c")
464 call assert_beeps("normal! 200%")
465 call assert_beeps("normal! %")
466 call assert_beeps("normal! 2{")
467 call assert_beeps("normal! 2}")
468 call assert_beeps("normal! r\<Right>")
469 call assert_beeps("normal! 8ry")
470 call assert_beeps('normal! "@')
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200471 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +0200472endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200473
Bram Moolenaar1bbb6192018-11-10 16:02:01 +0100474func Test_normal13_help()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200475 " Test for F1
476 call assert_equal(1, winnr())
477 call feedkeys("\<f1>", 'txi')
478 call assert_match('help\.txt', bufname('%'))
479 call assert_equal(2, winnr('$'))
480 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +0200481endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200482
Bram Moolenaar1bbb6192018-11-10 16:02:01 +0100483func Test_normal14_page()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200484 " basic test for Ctrl-F and Ctrl-B
485 call Setup_NewWindow()
486 exe "norm! \<c-f>"
487 call assert_equal('9', getline('.'))
488 exe "norm! 2\<c-f>"
489 call assert_equal('25', getline('.'))
490 exe "norm! 2\<c-b>"
491 call assert_equal('18', getline('.'))
492 1
493 set scrolloff=5
494 exe "norm! 2\<c-f>"
495 call assert_equal('21', getline('.'))
496 exe "norm! \<c-b>"
497 call assert_equal('13', getline('.'))
498 1
499 set scrolloff=99
500 exe "norm! \<c-f>"
501 call assert_equal('13', getline('.'))
502 set scrolloff=0
503 100
504 exe "norm! $\<c-b>"
505 call assert_equal('92', getline('.'))
506 call assert_equal([0, 92, 1, 0, 1], getcurpos())
507 100
508 set nostartofline
509 exe "norm! $\<c-b>"
510 call assert_equal('92', getline('.'))
511 call assert_equal([0, 92, 2, 0, 2147483647], getcurpos())
512 " cleanup
513 set startofline
514 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +0200515endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200516
Bram Moolenaar1bbb6192018-11-10 16:02:01 +0100517func Test_normal14_page_eol()
Bram Moolenaarbc54f3f2016-09-04 14:34:28 +0200518 10new
519 norm oxxxxxxx
520 exe "norm 2\<c-f>"
521 " check with valgrind that cursor is put back in column 1
522 exe "norm 2\<c-b>"
523 bw!
524endfunc
525
Bram Moolenaar1671f442020-03-10 07:48:13 +0100526" Test for errors with z command
527func Test_normal_z_error()
528 call assert_beeps('normal! z2p')
529 call assert_beeps('normal! zp')
530endfunc
531
Bram Moolenaar1bbb6192018-11-10 16:02:01 +0100532func Test_normal15_z_scroll_vert()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200533 " basic test for z commands that scroll the window
534 call Setup_NewWindow()
535 100
536 norm! >>
537 " Test for z<cr>
538 exe "norm! z\<cr>"
539 call assert_equal(' 100', getline('.'))
540 call assert_equal(100, winsaveview()['topline'])
541 call assert_equal([0, 100, 2, 0, 9], getcurpos())
542
543 " Test for zt
544 21
545 norm! >>0zt
546 call assert_equal(' 21', getline('.'))
547 call assert_equal(21, winsaveview()['topline'])
548 call assert_equal([0, 21, 1, 0, 8], getcurpos())
549
550 " Test for zb
551 30
552 norm! >>$ztzb
553 call assert_equal(' 30', getline('.'))
554 call assert_equal(30, winsaveview()['topline']+winheight(0)-1)
555 call assert_equal([0, 30, 3, 0, 2147483647], getcurpos())
556
557 " Test for z-
558 1
559 30
560 norm! 0z-
561 call assert_equal(' 30', getline('.'))
562 call assert_equal(30, winsaveview()['topline']+winheight(0)-1)
563 call assert_equal([0, 30, 2, 0, 9], getcurpos())
564
565 " Test for z{height}<cr>
566 call assert_equal(10, winheight(0))
567 exe "norm! z12\<cr>"
568 call assert_equal(12, winheight(0))
569 exe "norm! z10\<cr>"
570 call assert_equal(10, winheight(0))
571
572 " Test for z.
573 1
574 21
575 norm! 0z.
576 call assert_equal(' 21', getline('.'))
577 call assert_equal(17, winsaveview()['topline'])
578 call assert_equal([0, 21, 2, 0, 9], getcurpos())
579
580 " Test for zz
581 1
582 21
583 norm! 0zz
584 call assert_equal(' 21', getline('.'))
585 call assert_equal(17, winsaveview()['topline'])
586 call assert_equal([0, 21, 1, 0, 8], getcurpos())
587
588 " Test for z+
589 11
590 norm! zt
591 norm! z+
592 call assert_equal(' 21', getline('.'))
593 call assert_equal(21, winsaveview()['topline'])
594 call assert_equal([0, 21, 2, 0, 9], getcurpos())
595
596 " Test for [count]z+
597 1
598 norm! 21z+
599 call assert_equal(' 21', getline('.'))
600 call assert_equal(21, winsaveview()['topline'])
601 call assert_equal([0, 21, 2, 0, 9], getcurpos())
602
603 " Test for z^
604 norm! 22z+0
605 norm! z^
606 call assert_equal(' 21', getline('.'))
607 call assert_equal(12, winsaveview()['topline'])
608 call assert_equal([0, 21, 2, 0, 9], getcurpos())
609
610 " Test for [count]z^
611 1
612 norm! 30z^
613 call assert_equal(' 21', getline('.'))
614 call assert_equal(12, winsaveview()['topline'])
615 call assert_equal([0, 21, 2, 0, 9], getcurpos())
616
617 " cleanup
618 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +0200619endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200620
Bram Moolenaar1bbb6192018-11-10 16:02:01 +0100621func Test_normal16_z_scroll_hor()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200622 " basic test for z commands that scroll the window
623 10new
624 15vsp
625 set nowrap listchars=
626 let lineA='abcdefghijklmnopqrstuvwxyz'
627 let lineB='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'
628 $put =lineA
629 $put =lineB
630 1d
631
Bram Moolenaar1671f442020-03-10 07:48:13 +0100632 " Test for zl and zh with a count
633 norm! 0z10l
634 call assert_equal([11, 1], [col('.'), wincol()])
635 norm! z4h
636 call assert_equal([11, 5], [col('.'), wincol()])
637 normal! 2gg
638
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200639 " Test for zl
640 1
641 norm! 5zl
642 call assert_equal(lineA, getline('.'))
643 call assert_equal(6, col('.'))
644 call assert_equal(5, winsaveview()['leftcol'])
645 norm! yl
646 call assert_equal('f', @0)
647
648 " Test for zh
649 norm! 2zh
650 call assert_equal(lineA, getline('.'))
651 call assert_equal(6, col('.'))
652 norm! yl
653 call assert_equal('f', @0)
654 call assert_equal(3, winsaveview()['leftcol'])
655
656 " Test for zL
657 norm! zL
658 call assert_equal(11, col('.'))
659 norm! yl
660 call assert_equal('k', @0)
661 call assert_equal(10, winsaveview()['leftcol'])
662 norm! 2zL
663 call assert_equal(25, col('.'))
664 norm! yl
665 call assert_equal('y', @0)
666 call assert_equal(24, winsaveview()['leftcol'])
667
668 " Test for zH
669 norm! 2zH
670 call assert_equal(25, col('.'))
671 call assert_equal(10, winsaveview()['leftcol'])
672 norm! yl
673 call assert_equal('y', @0)
674
675 " Test for zs
676 norm! $zs
677 call assert_equal(26, col('.'))
678 call assert_equal(25, winsaveview()['leftcol'])
679 norm! yl
680 call assert_equal('z', @0)
681
682 " Test for ze
683 norm! ze
684 call assert_equal(26, col('.'))
685 call assert_equal(11, winsaveview()['leftcol'])
686 norm! yl
687 call assert_equal('z', @0)
688
689 " cleanup
690 set wrap listchars=eol:$
691 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +0200692endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200693
Bram Moolenaar1bbb6192018-11-10 16:02:01 +0100694func Test_normal17_z_scroll_hor2()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200695 " basic test for z commands that scroll the window
696 " using 'sidescrolloff' setting
697 10new
698 20vsp
699 set nowrap listchars= sidescrolloff=5
700 let lineA='abcdefghijklmnopqrstuvwxyz'
701 let lineB='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'
702 $put =lineA
703 $put =lineB
704 1d
705
706 " Test for zl
707 1
708 norm! 5zl
709 call assert_equal(lineA, getline('.'))
710 call assert_equal(11, col('.'))
711 call assert_equal(5, winsaveview()['leftcol'])
712 norm! yl
713 call assert_equal('k', @0)
714
715 " Test for zh
716 norm! 2zh
717 call assert_equal(lineA, getline('.'))
718 call assert_equal(11, col('.'))
719 norm! yl
720 call assert_equal('k', @0)
721 call assert_equal(3, winsaveview()['leftcol'])
722
723 " Test for zL
724 norm! 0zL
725 call assert_equal(16, col('.'))
726 norm! yl
727 call assert_equal('p', @0)
728 call assert_equal(10, winsaveview()['leftcol'])
729 norm! 2zL
730 call assert_equal(26, col('.'))
731 norm! yl
732 call assert_equal('z', @0)
733 call assert_equal(15, winsaveview()['leftcol'])
734
735 " Test for zH
736 norm! 2zH
737 call assert_equal(15, col('.'))
738 call assert_equal(0, winsaveview()['leftcol'])
739 norm! yl
740 call assert_equal('o', @0)
741
742 " Test for zs
743 norm! $zs
744 call assert_equal(26, col('.'))
745 call assert_equal(20, winsaveview()['leftcol'])
746 norm! yl
747 call assert_equal('z', @0)
748
749 " Test for ze
750 norm! ze
751 call assert_equal(26, col('.'))
752 call assert_equal(11, winsaveview()['leftcol'])
753 norm! yl
754 call assert_equal('z', @0)
755
756 " cleanup
757 set wrap listchars=eol:$ sidescrolloff=0
758 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +0200759endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200760
Bram Moolenaar1671f442020-03-10 07:48:13 +0100761" Test for H, M and L commands with folds
762func Test_scroll_cmds()
763 15new
764 call setline(1, range(1, 100))
765 exe "normal! 30ggz\<CR>"
766 set foldenable
767 33,36fold
768 40,43fold
769 46,49fold
770 let h = winheight(0)
771 " Top of the screen = 30
772 " Folded lines = 9
773 " Bottom of the screen = 30 + h + 9 - 1
774 normal! 4L
775 call assert_equal(35 + h, line('.'))
776 normal! 4H
777 call assert_equal(33, line('.'))
778 set foldenable&
779 close!
780endfunc
781
Bram Moolenaar1bbb6192018-11-10 16:02:01 +0100782func Test_normal18_z_fold()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200783 " basic tests for foldopen/folddelete
784 if !has("folding")
785 return
786 endif
787 call Setup_NewWindow()
788 50
789 setl foldenable fdm=marker foldlevel=5
790
Bram Moolenaar1671f442020-03-10 07:48:13 +0100791 call assert_beeps('normal! zj')
792 call assert_beeps('normal! zk')
793
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200794 " Test for zF
795 " First fold
796 norm! 4zF
797 " check that folds have been created
798 call assert_equal(['50/*{{{*/', '51', '52', '53/*}}}*/'], getline(50,53))
799
800 " Test for zd
801 51
802 norm! 2zF
803 call assert_equal(2, foldlevel('.'))
804 norm! kzd
805 call assert_equal(['50', '51/*{{{*/', '52/*}}}*/', '53'], getline(50,53))
806 norm! j
807 call assert_equal(1, foldlevel('.'))
808
809 " Test for zD
810 " also deletes partially selected folds recursively
811 51
812 norm! zF
813 call assert_equal(2, foldlevel('.'))
814 norm! kV2jzD
815 call assert_equal(['50', '51', '52', '53'], getline(50,53))
816
817 " Test for zE
818 85
819 norm! 4zF
820 86
821 norm! 2zF
822 90
823 norm! 4zF
824 call assert_equal(['85/*{{{*/', '86/*{{{*/', '87/*}}}*/', '88/*}}}*/', '89', '90/*{{{*/', '91', '92', '93/*}}}*/'], getline(85,93))
825 norm! zE
826 call assert_equal(['85', '86', '87', '88', '89', '90', '91', '92', '93'], getline(85,93))
827
828 " Test for zn
829 50
830 set foldlevel=0
831 norm! 2zF
832 norm! zn
833 norm! k
834 call assert_equal('49', getline('.'))
835 norm! j
836 call assert_equal('50/*{{{*/', getline('.'))
837 norm! j
838 call assert_equal('51/*}}}*/', getline('.'))
839 norm! j
840 call assert_equal('52', getline('.'))
841 call assert_equal(0, &foldenable)
842
843 " Test for zN
844 49
845 norm! zN
846 call assert_equal('49', getline('.'))
847 norm! j
848 call assert_equal('50/*{{{*/', getline('.'))
849 norm! j
850 call assert_equal('52', getline('.'))
851 call assert_equal(1, &foldenable)
852
853 " Test for zi
854 norm! zi
855 call assert_equal(0, &foldenable)
856 norm! zi
857 call assert_equal(1, &foldenable)
858 norm! zi
859 call assert_equal(0, &foldenable)
860 norm! zi
861 call assert_equal(1, &foldenable)
862
863 " Test for za
864 50
865 norm! za
866 norm! k
867 call assert_equal('49', getline('.'))
868 norm! j
869 call assert_equal('50/*{{{*/', getline('.'))
870 norm! j
871 call assert_equal('51/*}}}*/', getline('.'))
872 norm! j
873 call assert_equal('52', getline('.'))
874 50
875 norm! za
876 norm! k
877 call assert_equal('49', getline('.'))
878 norm! j
879 call assert_equal('50/*{{{*/', getline('.'))
880 norm! j
881 call assert_equal('52', getline('.'))
882
883 49
884 norm! 5zF
885 norm! k
886 call assert_equal('48', getline('.'))
887 norm! j
888 call assert_equal('49/*{{{*/', getline('.'))
889 norm! j
890 call assert_equal('55', getline('.'))
891 49
892 norm! za
893 call assert_equal('49/*{{{*/', getline('.'))
894 norm! j
895 call assert_equal('50/*{{{*/', getline('.'))
896 norm! j
897 call assert_equal('52', getline('.'))
898 set nofoldenable
899 " close fold and set foldenable
900 norm! za
901 call assert_equal(1, &foldenable)
902
903 50
904 " have to use {count}za to open all folds and make the cursor visible
905 norm! 2za
906 norm! 2k
907 call assert_equal('48', getline('.'))
908 norm! j
909 call assert_equal('49/*{{{*/', getline('.'))
910 norm! j
911 call assert_equal('50/*{{{*/', getline('.'))
912 norm! j
913 call assert_equal('51/*}}}*/', getline('.'))
914 norm! j
915 call assert_equal('52', getline('.'))
916
917 " Test for zA
918 49
919 set foldlevel=0
920 50
921 norm! zA
922 norm! 2k
923 call assert_equal('48', getline('.'))
924 norm! j
925 call assert_equal('49/*{{{*/', getline('.'))
926 norm! j
927 call assert_equal('50/*{{{*/', getline('.'))
928 norm! j
929 call assert_equal('51/*}}}*/', getline('.'))
930 norm! j
931 call assert_equal('52', getline('.'))
932
Bram Moolenaar395b6ba2017-04-07 20:09:51 +0200933 " zA on a opened fold when foldenable is not set
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200934 50
935 set nofoldenable
936 norm! zA
937 call assert_equal(1, &foldenable)
938 norm! k
939 call assert_equal('48', getline('.'))
940 norm! j
941 call assert_equal('49/*{{{*/', getline('.'))
942 norm! j
943 call assert_equal('55', getline('.'))
944
945 " Test for zc
946 norm! zE
947 50
948 norm! 2zF
949 49
950 norm! 5zF
951 set nofoldenable
952 50
953 " There most likely is a bug somewhere:
954 " https://groups.google.com/d/msg/vim_dev/v2EkfJ_KQjI/u-Cvv94uCAAJ
955 " TODO: Should this only close the inner most fold or both folds?
956 norm! zc
957 call assert_equal(1, &foldenable)
958 norm! k
959 call assert_equal('48', getline('.'))
960 norm! j
961 call assert_equal('49/*{{{*/', getline('.'))
962 norm! j
963 call assert_equal('55', getline('.'))
964 set nofoldenable
965 50
966 norm! Vjzc
967 norm! k
968 call assert_equal('48', getline('.'))
969 norm! j
970 call assert_equal('49/*{{{*/', getline('.'))
971 norm! j
972 call assert_equal('55', getline('.'))
973
974 " Test for zC
975 set nofoldenable
976 50
977 norm! zCk
978 call assert_equal('48', getline('.'))
979 norm! j
980 call assert_equal('49/*{{{*/', getline('.'))
981 norm! j
982 call assert_equal('55', getline('.'))
983
984 " Test for zx
985 " 1) close folds at line 49-54
986 set nofoldenable
987 48
988 norm! zx
989 call assert_equal(1, &foldenable)
990 norm! j
991 call assert_equal('49/*{{{*/', getline('.'))
992 norm! j
993 call assert_equal('55', getline('.'))
994
Bram Moolenaar395b6ba2017-04-07 20:09:51 +0200995 " 2) do not close fold under cursor
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200996 51
997 set nofoldenable
998 norm! zx
999 call assert_equal(1, &foldenable)
1000 norm! 3k
1001 call assert_equal('48', getline('.'))
1002 norm! j
1003 call assert_equal('49/*{{{*/', getline('.'))
1004 norm! j
1005 call assert_equal('50/*{{{*/', getline('.'))
1006 norm! j
1007 call assert_equal('51/*}}}*/', getline('.'))
1008 norm! j
1009 call assert_equal('52', getline('.'))
1010 norm! j
1011 call assert_equal('53', getline('.'))
1012 norm! j
1013 call assert_equal('54/*}}}*/', getline('.'))
1014 norm! j
1015 call assert_equal('55', getline('.'))
1016
1017 " 3) close one level of folds
1018 48
1019 set nofoldenable
1020 set foldlevel=1
1021 norm! zx
1022 call assert_equal(1, &foldenable)
1023 call assert_equal('48', getline('.'))
1024 norm! j
1025 call assert_equal('49/*{{{*/', getline('.'))
1026 norm! j
1027 call assert_equal('50/*{{{*/', getline('.'))
1028 norm! j
1029 call assert_equal('52', getline('.'))
1030 norm! j
1031 call assert_equal('53', getline('.'))
1032 norm! j
1033 call assert_equal('54/*}}}*/', getline('.'))
1034 norm! j
1035 call assert_equal('55', getline('.'))
1036
1037 " Test for zX
1038 " Close all folds
1039 set foldlevel=0 nofoldenable
1040 50
1041 norm! zX
1042 call assert_equal(1, &foldenable)
1043 norm! k
1044 call assert_equal('48', getline('.'))
1045 norm! j
1046 call assert_equal('49/*{{{*/', getline('.'))
1047 norm! j
1048 call assert_equal('55', getline('.'))
1049
1050 " Test for zm
1051 50
1052 set nofoldenable foldlevel=2
1053 norm! zm
1054 call assert_equal(1, &foldenable)
1055 call assert_equal(1, &foldlevel)
1056 norm! zm
1057 call assert_equal(0, &foldlevel)
1058 norm! zm
1059 call assert_equal(0, &foldlevel)
1060 norm! k
1061 call assert_equal('48', getline('.'))
1062 norm! j
1063 call assert_equal('49/*{{{*/', getline('.'))
1064 norm! j
1065 call assert_equal('55', getline('.'))
1066
1067 " Test for zM
1068 48
1069 set nofoldenable foldlevel=99
1070 norm! zM
1071 call assert_equal(1, &foldenable)
1072 call assert_equal(0, &foldlevel)
1073 call assert_equal('48', getline('.'))
1074 norm! j
1075 call assert_equal('49/*{{{*/', getline('.'))
1076 norm! j
1077 call assert_equal('55', getline('.'))
1078
1079 " Test for zr
1080 48
1081 set nofoldenable foldlevel=0
1082 norm! zr
1083 call assert_equal(0, &foldenable)
1084 call assert_equal(1, &foldlevel)
1085 set foldlevel=0 foldenable
1086 norm! zr
1087 call assert_equal(1, &foldenable)
1088 call assert_equal(1, &foldlevel)
1089 norm! zr
1090 call assert_equal(2, &foldlevel)
1091 call assert_equal('48', getline('.'))
1092 norm! j
1093 call assert_equal('49/*{{{*/', getline('.'))
1094 norm! j
1095 call assert_equal('50/*{{{*/', getline('.'))
1096 norm! j
1097 call assert_equal('51/*}}}*/', getline('.'))
1098 norm! j
1099 call assert_equal('52', getline('.'))
1100
1101 " Test for zR
1102 48
1103 set nofoldenable foldlevel=0
1104 norm! zR
1105 call assert_equal(0, &foldenable)
1106 call assert_equal(2, &foldlevel)
1107 set foldenable foldlevel=0
1108 norm! zR
1109 call assert_equal(1, &foldenable)
1110 call assert_equal(2, &foldlevel)
1111 call assert_equal('48', getline('.'))
1112 norm! j
1113 call assert_equal('49/*{{{*/', getline('.'))
1114 norm! j
1115 call assert_equal('50/*{{{*/', getline('.'))
1116 norm! j
1117 call assert_equal('51/*}}}*/', getline('.'))
1118 norm! j
1119 call assert_equal('52', getline('.'))
1120 call append(50, ['a /*{{{*/', 'b /*}}}*/'])
1121 48
1122 call assert_equal('48', getline('.'))
1123 norm! j
1124 call assert_equal('49/*{{{*/', getline('.'))
1125 norm! j
1126 call assert_equal('50/*{{{*/', getline('.'))
1127 norm! j
1128 call assert_equal('a /*{{{*/', getline('.'))
1129 norm! j
1130 call assert_equal('51/*}}}*/', getline('.'))
1131 norm! j
1132 call assert_equal('52', getline('.'))
1133 48
1134 norm! zR
1135 call assert_equal(1, &foldenable)
1136 call assert_equal(3, &foldlevel)
1137 call assert_equal('48', getline('.'))
1138 norm! j
1139 call assert_equal('49/*{{{*/', getline('.'))
1140 norm! j
1141 call assert_equal('50/*{{{*/', getline('.'))
1142 norm! j
1143 call assert_equal('a /*{{{*/', getline('.'))
1144 norm! j
1145 call assert_equal('b /*}}}*/', getline('.'))
1146 norm! j
1147 call assert_equal('51/*}}}*/', getline('.'))
1148 norm! j
1149 call assert_equal('52', getline('.'))
1150
1151 " clean up
1152 setl nofoldenable fdm=marker foldlevel=0
1153 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02001154endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001155
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01001156func Test_normal20_exmode()
Bram Moolenaar0913a102016-09-03 19:11:59 +02001157 if !has("unix")
1158 " Reading from redirected file doesn't work on MS-Windows
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001159 return
1160 endif
1161 call writefile(['1a', 'foo', 'bar', '.', 'w! Xfile2', 'q!'], 'Xscript')
1162 call writefile(['1', '2'], 'Xfile')
Bram Moolenaar93344c22019-08-14 21:12:05 +02001163 call system(GetVimCommand() .. ' -e -s < Xscript Xfile')
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001164 let a=readfile('Xfile2')
1165 call assert_equal(['1', 'foo', 'bar', '2'], a)
1166
1167 " clean up
1168 for file in ['Xfile', 'Xfile2', 'Xscript']
1169 call delete(file)
1170 endfor
1171 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02001172endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001173
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01001174func Test_normal21_nv_hat()
1175
1176 " Edit a fresh file and wipe the buffer list so that there is no alternate
1177 " file present. Next, check for the expected command failures.
1178 edit Xfoo | %bw
1179 call assert_fails(':buffer #', 'E86')
1180 call assert_fails(':execute "normal! \<C-^>"', 'E23')
1181
1182 " Test for the expected behavior when switching between two named buffers.
1183 edit Xfoo | edit Xbar
1184 call feedkeys("\<C-^>", 'tx')
1185 call assert_equal('Xfoo', fnamemodify(bufname('%'), ':t'))
1186 call feedkeys("\<C-^>", 'tx')
1187 call assert_equal('Xbar', fnamemodify(bufname('%'), ':t'))
1188
1189 " Test for the expected behavior when only one buffer is named.
1190 enew | let l:nr = bufnr('%')
1191 call feedkeys("\<C-^>", 'tx')
1192 call assert_equal('Xbar', fnamemodify(bufname('%'), ':t'))
1193 call feedkeys("\<C-^>", 'tx')
1194 call assert_equal('', bufname('%'))
1195 call assert_equal(l:nr, bufnr('%'))
1196
1197 " Test that no action is taken by "<C-^>" when an operator is pending.
1198 edit Xfoo
1199 call feedkeys("ci\<C-^>", 'tx')
1200 call assert_equal('Xfoo', fnamemodify(bufname('%'), ':t'))
1201
1202 %bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02001203endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001204
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01001205func Test_normal22_zet()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001206 " Test for ZZ
Bram Moolenaar0913a102016-09-03 19:11:59 +02001207 " let shell = &shell
1208 " let &shell = 'sh'
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001209 call writefile(['1', '2'], 'Xfile')
Bram Moolenaar93344c22019-08-14 21:12:05 +02001210 let args = ' -N -i NONE --noplugins -X --not-a-term'
1211 call system(GetVimCommand() .. args .. ' -c "%d" -c ":norm! ZZ" Xfile')
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001212 let a = readfile('Xfile')
1213 call assert_equal([], a)
1214 " Test for ZQ
1215 call writefile(['1', '2'], 'Xfile')
Bram Moolenaar93344c22019-08-14 21:12:05 +02001216 call system(GetVimCommand() . args . ' -c "%d" -c ":norm! ZQ" Xfile')
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001217 let a = readfile('Xfile')
1218 call assert_equal(['1', '2'], a)
1219
Bram Moolenaar1671f442020-03-10 07:48:13 +01001220 " Unsupported Z command
1221 call assert_beeps('normal! ZW')
1222
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001223 " clean up
1224 for file in ['Xfile']
1225 call delete(file)
1226 endfor
Bram Moolenaar0913a102016-09-03 19:11:59 +02001227 " let &shell = shell
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02001228endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001229
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01001230func Test_normal23_K()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001231 " Test for K command
1232 new
Bram Moolenaar426f3752016-11-04 21:22:37 +01001233 call append(0, ['version8.txt', 'man', 'aa%bb', 'cc|dd'])
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001234 let k = &keywordprg
1235 set keywordprg=:help
1236 1
1237 norm! VK
1238 call assert_equal('version8.txt', fnamemodify(bufname('%'), ':t'))
1239 call assert_equal('help', &ft)
1240 call assert_match('\*version8.txt\*', getline('.'))
1241 helpclose
1242 norm! 0K
1243 call assert_equal('version8.txt', fnamemodify(bufname('%'), ':t'))
1244 call assert_equal('help', &ft)
Bram Moolenaarb1c91982018-05-17 17:04:55 +02001245 call assert_match('\*version8\.\d\*', getline('.'))
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001246 helpclose
1247
Bram Moolenaar426f3752016-11-04 21:22:37 +01001248 set keywordprg=:new
1249 set iskeyword+=%
1250 set iskeyword+=\|
1251 2
1252 norm! K
1253 call assert_equal('man', fnamemodify(bufname('%'), ':t'))
1254 bwipe!
1255 3
1256 norm! K
1257 call assert_equal('aa%bb', fnamemodify(bufname('%'), ':t'))
1258 bwipe!
Bram Moolenaareb828d02016-11-05 19:54:01 +01001259 if !has('win32')
1260 4
1261 norm! K
1262 call assert_equal('cc|dd', fnamemodify(bufname('%'), ':t'))
1263 bwipe!
1264 endif
Bram Moolenaar426f3752016-11-04 21:22:37 +01001265 set iskeyword-=%
1266 set iskeyword-=\|
1267
Bram Moolenaar0913a102016-09-03 19:11:59 +02001268 " Only expect "man" to work on Unix
1269 if !has("unix")
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001270 let &keywordprg = k
1271 bw!
1272 return
1273 endif
Bram Moolenaarc6b37db2019-04-27 18:00:34 +02001274
Bram Moolenaar9134f1e2019-11-29 20:26:13 +01001275 let not_gnu_man = has('mac') || has('bsd')
1276 if not_gnu_man
Bram Moolenaarc7d2a572019-11-28 21:16:06 +01001277 " In MacOS and BSD, the option for specifying a pager is different
Bram Moolenaarc6b37db2019-04-27 18:00:34 +02001278 set keywordprg=man\ -P\ cat
1279 else
1280 set keywordprg=man\ --pager=cat
1281 endif
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001282 " Test for using man
1283 2
1284 let a = execute('unsilent norm! K')
Bram Moolenaar9134f1e2019-11-29 20:26:13 +01001285 if not_gnu_man
Bram Moolenaarc6b37db2019-04-27 18:00:34 +02001286 call assert_match("man -P cat 'man'", a)
1287 else
1288 call assert_match("man --pager=cat 'man'", a)
1289 endif
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001290
Bram Moolenaar1671f442020-03-10 07:48:13 +01001291 " Error cases
1292 call setline(1, '#$#')
1293 call assert_fails('normal! ggK', 'E349:')
1294 call setline(1, '---')
1295 call assert_fails('normal! ggv2lK', 'E349:')
1296 call setline(1, ['abc', 'xyz'])
1297 call assert_fails("normal! gg2lv2h\<C-]>", 'E426:')
1298 call assert_beeps("normal! ggVjK")
1299
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001300 " clean up
1301 let &keywordprg = k
1302 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02001303endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001304
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01001305func Test_normal24_rot13()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001306 " Testing for g?? g?g?
1307 new
1308 call append(0, 'abcdefghijklmnopqrstuvwxyzäüö')
1309 1
1310 norm! g??
1311 call assert_equal('nopqrstuvwxyzabcdefghijklmäüö', getline('.'))
1312 norm! g?g?
1313 call assert_equal('abcdefghijklmnopqrstuvwxyzäüö', getline('.'))
1314
1315 " clean up
1316 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02001317endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001318
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01001319func Test_normal25_tag()
Bram Moolenaar5a4c3082019-12-01 15:23:11 +01001320 CheckFeature quickfix
1321
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001322 " Testing for CTRL-] g CTRL-] g]
1323 " CTRL-W g] CTRL-W CTRL-] CTRL-W g CTRL-]
1324 h
1325 " Test for CTRL-]
1326 call search('\<x\>$')
1327 exe "norm! \<c-]>"
1328 call assert_equal("change.txt", fnamemodify(bufname('%'), ':t'))
1329 norm! yiW
1330 call assert_equal("*x*", @0)
1331 exe ":norm \<c-o>"
1332
1333 " Test for g_CTRL-]
1334 call search('\<v_u\>$')
1335 exe "norm! g\<c-]>"
1336 call assert_equal("change.txt", fnamemodify(bufname('%'), ':t'))
1337 norm! yiW
1338 call assert_equal("*v_u*", @0)
1339 exe ":norm \<c-o>"
1340
1341 " Test for g]
1342 call search('\<i_<Esc>$')
1343 let a = execute(":norm! g]")
1344 call assert_match('i_<Esc>.*insert.txt', a)
1345
1346 if !empty(exepath('cscope')) && has('cscope')
1347 " setting cscopetag changes how g] works
1348 set cst
1349 exe "norm! g]"
1350 call assert_equal("insert.txt", fnamemodify(bufname('%'), ':t'))
1351 norm! yiW
1352 call assert_equal("*i_<Esc>*", @0)
1353 exe ":norm \<c-o>"
1354 " Test for CTRL-W g]
1355 exe "norm! \<C-W>g]"
1356 call assert_equal("insert.txt", fnamemodify(bufname('%'), ':t'))
1357 norm! yiW
1358 call assert_equal("*i_<Esc>*", @0)
1359 call assert_equal(3, winnr('$'))
1360 helpclose
1361 set nocst
1362 endif
1363
1364 " Test for CTRL-W g]
1365 let a = execute("norm! \<C-W>g]")
1366 call assert_match('i_<Esc>.*insert.txt', a)
1367
1368 " Test for CTRL-W CTRL-]
1369 exe "norm! \<C-W>\<C-]>"
1370 call assert_equal("insert.txt", fnamemodify(bufname('%'), ':t'))
1371 norm! yiW
1372 call assert_equal("*i_<Esc>*", @0)
1373 call assert_equal(3, winnr('$'))
1374 helpclose
1375
1376 " Test for CTRL-W g CTRL-]
1377 exe "norm! \<C-W>g\<C-]>"
1378 call assert_equal("insert.txt", fnamemodify(bufname('%'), ':t'))
1379 norm! yiW
1380 call assert_equal("*i_<Esc>*", @0)
1381 call assert_equal(3, winnr('$'))
1382 helpclose
1383
1384 " clean up
1385 helpclose
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02001386endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001387
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01001388func Test_normal26_put()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001389 " Test for ]p ]P [p and [P
1390 new
1391 call append(0, ['while read LINE', 'do', ' ((count++))', ' if [ $? -ne 0 ]; then', " echo 'Error writing file'", ' fi', 'done'])
1392 1
1393 /Error/y a
1394 2
1395 norm! "a]pj"a[p
1396 call assert_equal(['do', "echo 'Error writing file'", " echo 'Error writing file'", ' ((count++))'], getline(2,5))
1397 1
1398 /^\s\{4}/
1399 exe "norm! \"a]P3Eldt'"
1400 exe "norm! j\"a[P2Eldt'"
1401 call assert_equal([' if [ $? -ne 0 ]; then', " echo 'Error writing'", " echo 'Error'", " echo 'Error writing file'", ' fi'], getline(6,10))
1402
1403 " clean up
1404 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02001405endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001406
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01001407func Test_normal27_bracket()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001408 " Test for [' [` ]' ]`
1409 call Setup_NewWindow()
1410 1,21s/.\+/ & b/
1411 1
1412 norm! $ma
1413 5
1414 norm! $mb
1415 10
1416 norm! $mc
1417 15
1418 norm! $md
1419 20
1420 norm! $me
1421
1422 " Test for ['
1423 9
1424 norm! 2['
1425 call assert_equal(' 1 b', getline('.'))
1426 call assert_equal(1, line('.'))
1427 call assert_equal(3, col('.'))
1428
1429 " Test for ]'
1430 norm! ]'
1431 call assert_equal(' 5 b', getline('.'))
1432 call assert_equal(5, line('.'))
1433 call assert_equal(3, col('.'))
1434
1435 " No mark after line 21, cursor moves to first non blank on current line
1436 21
1437 norm! $]'
1438 call assert_equal(' 21 b', getline('.'))
1439 call assert_equal(21, line('.'))
1440 call assert_equal(3, col('.'))
1441
1442 " Test for [`
1443 norm! 2[`
1444 call assert_equal(' 15 b', getline('.'))
1445 call assert_equal(15, line('.'))
1446 call assert_equal(8, col('.'))
1447
1448 " Test for ]`
1449 norm! ]`
1450 call assert_equal(' 20 b', getline('.'))
1451 call assert_equal(20, line('.'))
1452 call assert_equal(8, col('.'))
1453
1454 " clean up
1455 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02001456endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001457
Bram Moolenaar1671f442020-03-10 07:48:13 +01001458" Test for ( and ) sentence movements
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01001459func Test_normal28_parenthesis()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001460 new
1461 call append(0, ['This is a test. With some sentences!', '', 'Even with a question? And one more. And no sentence here'])
1462
1463 $
1464 norm! d(
1465 call assert_equal(['This is a test. With some sentences!', '', 'Even with a question? And one more. ', ''], getline(1, '$'))
1466 norm! 2d(
1467 call assert_equal(['This is a test. With some sentences!', '', ' ', ''], getline(1, '$'))
1468 1
1469 norm! 0d)
1470 call assert_equal(['With some sentences!', '', ' ', ''], getline(1, '$'))
1471
1472 call append('$', ['This is a long sentence', '', 'spanning', 'over several lines. '])
1473 $
1474 norm! $d(
1475 call assert_equal(['With some sentences!', '', ' ', '', 'This is a long sentence', ''], getline(1, '$'))
1476
Bram Moolenaar1671f442020-03-10 07:48:13 +01001477 " It is an error if a next sentence is not found
1478 %d
1479 call setline(1, '.SH')
1480 call assert_beeps('normal )')
1481
1482 " Jumping to a fold should open the fold
1483 call setline(1, ['', '', 'one', 'two', 'three'])
1484 set foldenable
1485 2,$fold
1486 call feedkeys(')', 'xt')
1487 call assert_equal(3, line('.'))
1488 call assert_equal(1, foldlevel('.'))
1489 call assert_equal(-1, foldclosed('.'))
1490 set foldenable&
1491
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001492 " clean up
1493 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02001494endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001495
Bram Moolenaar1671f442020-03-10 07:48:13 +01001496" Test for { and } paragraph movements
1497func Test_normal29_brace()
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001498 let text =<< trim [DATA]
Bram Moolenaare7eb9272019-06-24 00:58:07 +02001499 A paragraph begins after each empty line, and also at each of a set of
1500 paragraph macros, specified by the pairs of characters in the 'paragraphs'
1501 option. The default is "IPLPPPQPP TPHPLIPpLpItpplpipbp", which corresponds to
1502 the macros ".IP", ".LP", etc. (These are nroff macros, so the dot must be in
1503 the first column). A section boundary is also a paragraph boundary.
1504 Note that a blank line (only containing white space) is NOT a paragraph
1505 boundary.
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001506
1507
Bram Moolenaare7eb9272019-06-24 00:58:07 +02001508 Also note that this does not include a '{' or '}' in the first column. When
1509 the '{' flag is in 'cpoptions' then '{' in the first column is used as a
1510 paragraph boundary |posix|.
1511 {
1512 This is no paragraph
1513 unless the '{' is set
1514 in 'cpoptions'
1515 }
1516 .IP
1517 The nroff macros IP separates a paragraph
1518 That means, it must be a '.'
1519 followed by IP
1520 .LPIt does not matter, if afterwards some
1521 more characters follow.
1522 .SHAlso section boundaries from the nroff
1523 macros terminate a paragraph. That means
1524 a character like this:
1525 .NH
1526 End of text here
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001527 [DATA]
1528
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001529 new
1530 call append(0, text)
1531 1
1532 norm! 0d2}
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001533
1534 let expected =<< trim [DATA]
Bram Moolenaare7eb9272019-06-24 00:58:07 +02001535 .IP
1536 The nroff macros IP separates a paragraph
1537 That means, it must be a '.'
1538 followed by IP
1539 .LPIt does not matter, if afterwards some
1540 more characters follow.
1541 .SHAlso section boundaries from the nroff
1542 macros terminate a paragraph. That means
1543 a character like this:
1544 .NH
1545 End of text here
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001546
1547 [DATA]
1548 call assert_equal(expected, getline(1, '$'))
1549
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001550 norm! 0d}
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001551
1552 let expected =<< trim [DATA]
Bram Moolenaare7eb9272019-06-24 00:58:07 +02001553 .LPIt does not matter, if afterwards some
1554 more characters follow.
1555 .SHAlso section boundaries from the nroff
1556 macros terminate a paragraph. That means
1557 a character like this:
1558 .NH
1559 End of text here
1560
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001561 [DATA]
1562 call assert_equal(expected, getline(1, '$'))
1563
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001564 $
1565 norm! d{
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001566
1567 let expected =<< trim [DATA]
Bram Moolenaare7eb9272019-06-24 00:58:07 +02001568 .LPIt does not matter, if afterwards some
1569 more characters follow.
1570 .SHAlso section boundaries from the nroff
1571 macros terminate a paragraph. That means
1572 a character like this:
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001573
1574 [DATA]
1575 call assert_equal(expected, getline(1, '$'))
1576
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001577 norm! d{
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001578
1579 let expected =<< trim [DATA]
Bram Moolenaare7eb9272019-06-24 00:58:07 +02001580 .LPIt does not matter, if afterwards some
1581 more characters follow.
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001582
1583 [DATA]
1584 call assert_equal(expected, getline(1, '$'))
1585
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001586 " Test with { in cpooptions
1587 %d
1588 call append(0, text)
1589 set cpo+={
1590 1
1591 norm! 0d2}
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001592
1593 let expected =<< trim [DATA]
Bram Moolenaare7eb9272019-06-24 00:58:07 +02001594 {
1595 This is no paragraph
1596 unless the '{' is set
1597 in 'cpoptions'
1598 }
1599 .IP
1600 The nroff macros IP separates a paragraph
1601 That means, it must be a '.'
1602 followed by IP
1603 .LPIt does not matter, if afterwards some
1604 more characters follow.
1605 .SHAlso section boundaries from the nroff
1606 macros terminate a paragraph. That means
1607 a character like this:
1608 .NH
1609 End of text here
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001610
1611 [DATA]
1612 call assert_equal(expected, getline(1, '$'))
1613
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001614 $
1615 norm! d}
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001616
1617 let expected =<< trim [DATA]
Bram Moolenaare7eb9272019-06-24 00:58:07 +02001618 {
1619 This is no paragraph
1620 unless the '{' is set
1621 in 'cpoptions'
1622 }
1623 .IP
1624 The nroff macros IP separates a paragraph
1625 That means, it must be a '.'
1626 followed by IP
1627 .LPIt does not matter, if afterwards some
1628 more characters follow.
1629 .SHAlso section boundaries from the nroff
1630 macros terminate a paragraph. That means
1631 a character like this:
1632 .NH
1633 End of text here
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001634
1635 [DATA]
1636 call assert_equal(expected, getline(1, '$'))
1637
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001638 norm! gg}
1639 norm! d5}
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001640
1641 let expected =<< trim [DATA]
Bram Moolenaare7eb9272019-06-24 00:58:07 +02001642 {
1643 This is no paragraph
1644 unless the '{' is set
1645 in 'cpoptions'
1646 }
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001647
1648 [DATA]
1649 call assert_equal(expected, getline(1, '$'))
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001650
Bram Moolenaar1671f442020-03-10 07:48:13 +01001651 " Jumping to a fold should open the fold
1652 %d
1653 call setline(1, ['', 'one', 'two', ''])
1654 set foldenable
1655 2,$fold
1656 call feedkeys('}', 'xt')
1657 call assert_equal(4, line('.'))
1658 call assert_equal(1, foldlevel('.'))
1659 call assert_equal(-1, foldclosed('.'))
1660 set foldenable&
1661
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001662 " clean up
1663 set cpo-={
1664 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02001665endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001666
Bram Moolenaar1671f442020-03-10 07:48:13 +01001667" Test for ~ command
1668func Test_normal30_changecase()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001669 new
1670 call append(0, 'This is a simple test: äüöß')
1671 norm! 1ggVu
1672 call assert_equal('this is a simple test: äüöß', getline('.'))
1673 norm! VU
1674 call assert_equal('THIS IS A SIMPLE TEST: ÄÜÖSS', getline('.'))
1675 norm! guu
1676 call assert_equal('this is a simple test: äüöss', getline('.'))
1677 norm! gUgU
1678 call assert_equal('THIS IS A SIMPLE TEST: ÄÜÖSS', getline('.'))
1679 norm! gugu
1680 call assert_equal('this is a simple test: äüöss', getline('.'))
1681 norm! gUU
1682 call assert_equal('THIS IS A SIMPLE TEST: ÄÜÖSS', getline('.'))
1683 norm! 010~
1684 call assert_equal('this is a SIMPLE TEST: ÄÜÖSS', getline('.'))
1685 norm! V~
1686 call assert_equal('THIS IS A simple test: äüöss', getline('.'))
1687
Bram Moolenaar1671f442020-03-10 07:48:13 +01001688 " Test for changing case across lines using 'whichwrap'
1689 call setline(1, ['aaaaaa', 'aaaaaa'])
1690 normal! gg10~
1691 call assert_equal(['AAAAAA', 'aaaaaa'], getline(1, 2))
1692 set whichwrap+=~
1693 normal! gg10~
1694 call assert_equal(['aaaaaa', 'AAAAaa'], getline(1, 2))
1695 set whichwrap&
1696
1697 " clean up
1698 bw!
1699endfunc
1700
1701" Turkish ASCII turns to multi-byte. On some systems Turkish locale
1702" is available but toupper()/tolower() don't do the right thing.
1703func Test_normal_changecase_turkish()
1704 new
Bram Moolenaarf1c118b2018-09-03 22:08:10 +02001705 try
1706 lang tr_TR.UTF-8
1707 set casemap=
1708 let iupper = toupper('i')
1709 if iupper == "\u0130"
Bram Moolenaar9f4de1f2017-04-08 19:39:43 +02001710 call setline(1, 'iI')
1711 1normal gUU
1712 call assert_equal("\u0130I", getline(1))
1713 call assert_equal("\u0130I", toupper("iI"))
Bram Moolenaar3317d5e2017-04-08 19:12:06 +02001714
Bram Moolenaar9f4de1f2017-04-08 19:39:43 +02001715 call setline(1, 'iI')
1716 1normal guu
1717 call assert_equal("i\u0131", getline(1))
1718 call assert_equal("i\u0131", tolower("iI"))
Bram Moolenaarf1c118b2018-09-03 22:08:10 +02001719 elseif iupper == "I"
Bram Moolenaar1cc48202017-04-09 13:41:59 +02001720 call setline(1, 'iI')
1721 1normal gUU
1722 call assert_equal("II", getline(1))
1723 call assert_equal("II", toupper("iI"))
1724
1725 call setline(1, 'iI')
1726 1normal guu
1727 call assert_equal("ii", getline(1))
1728 call assert_equal("ii", tolower("iI"))
Bram Moolenaarf1c118b2018-09-03 22:08:10 +02001729 else
1730 call assert_true(false, "expected toupper('i') to be either 'I' or '\u0130'")
1731 endif
1732 set casemap&
1733 call setline(1, 'iI')
1734 1normal gUU
1735 call assert_equal("II", getline(1))
1736 call assert_equal("II", toupper("iI"))
Bram Moolenaar1cc48202017-04-09 13:41:59 +02001737
Bram Moolenaarf1c118b2018-09-03 22:08:10 +02001738 call setline(1, 'iI')
1739 1normal guu
1740 call assert_equal("ii", getline(1))
1741 call assert_equal("ii", tolower("iI"))
1742
1743 lang en_US.UTF-8
1744 catch /E197:/
1745 " can't use Turkish locale
1746 throw 'Skipped: Turkish locale not available'
1747 endtry
Bram Moolenaar1671f442020-03-10 07:48:13 +01001748 close!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02001749endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001750
Bram Moolenaar1671f442020-03-10 07:48:13 +01001751" Test for r (replace) command
1752func Test_normal31_r_cmd()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001753 new
1754 call append(0, 'This is a simple test: abcd')
1755 exe "norm! 1gg$r\<cr>"
1756 call assert_equal(['This is a simple test: abc', '', ''], getline(1,'$'))
1757 exe "norm! 1gg2wlr\<cr>"
1758 call assert_equal(['This is a', 'simple test: abc', '', ''], getline(1,'$'))
1759 exe "norm! 2gg0W5r\<cr>"
1760 call assert_equal(['This is a', 'simple ', ' abc', '', ''], getline('1', '$'))
1761 set autoindent
1762 call setline(2, ['simple test: abc', ''])
1763 exe "norm! 2gg0W5r\<cr>"
1764 call assert_equal(['This is a', 'simple ', 'abc', '', '', ''], getline('1', '$'))
1765 exe "norm! 1ggVr\<cr>"
1766 call assert_equal('^M^M^M^M^M^M^M^M^M', strtrans(getline(1)))
1767 call setline(1, 'This is a')
1768 exe "norm! 1gg05rf"
1769 call assert_equal('fffffis a', getline(1))
1770
Bram Moolenaar1671f442020-03-10 07:48:13 +01001771 " When replacing characters, copy characters from above and below lines
1772 " using CTRL-Y and CTRL-E.
1773 " Different code paths are used for utf-8 and latin1 encodings
1774 set showmatch
1775 for enc in ['latin1', 'utf-8']
1776 enew!
1777 let &encoding = enc
1778 call setline(1, [' {a}', 'xxxxxxxxxx', ' [b]'])
1779 exe "norm! 2gg5r\<C-Y>l5r\<C-E>"
1780 call assert_equal(' {a}x [b]x', getline(2))
1781 endfor
1782 set showmatch&
1783
1784 " r command should fail in operator pending mode
1785 call assert_beeps('normal! cr')
1786
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001787 " clean up
1788 set noautoindent
1789 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02001790endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001791
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01001792" Test for g*, g#
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01001793func Test_normal32_g_cmd1()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001794 new
1795 call append(0, ['abc.x_foo', 'x_foobar.abc'])
1796 1
1797 norm! $g*
1798 call assert_equal('x_foo', @/)
1799 call assert_equal('x_foobar.abc', getline('.'))
1800 norm! $g#
1801 call assert_equal('abc', @/)
1802 call assert_equal('abc.x_foo', getline('.'))
1803
1804 " clean up
1805 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02001806endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001807
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01001808" Test for g`, g;, g,, g&, gv, gk, gj, gJ, g0, g^, g_, gm, g$, gM, g CTRL-G,
1809" gi and gI commands
Bram Moolenaar1671f442020-03-10 07:48:13 +01001810func Test_normal33_g_cmd2()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001811 if !has("jumplist")
1812 return
1813 endif
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001814 call Setup_NewWindow()
1815 " Test for g`
1816 clearjumps
1817 norm! ma10j
1818 let a=execute(':jumps')
1819 " empty jumplist
1820 call assert_equal('>', a[-1:])
1821 norm! g`a
1822 call assert_equal('>', a[-1:])
1823 call assert_equal(1, line('.'))
1824 call assert_equal('1', getline('.'))
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01001825 call cursor(10, 1)
1826 norm! g'a
1827 call assert_equal('>', a[-1:])
1828 call assert_equal(1, line('.'))
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001829
1830 " Test for g; and g,
1831 norm! g;
1832 " there is only one change in the changelist
1833 " currently, when we setup the window
1834 call assert_equal(2, line('.'))
1835 call assert_fails(':norm! g;', 'E662')
1836 call assert_fails(':norm! g,', 'E663')
1837 let &ul=&ul
1838 call append('$', ['a', 'b', 'c', 'd'])
1839 let &ul=&ul
1840 call append('$', ['Z', 'Y', 'X', 'W'])
1841 let a = execute(':changes')
1842 call assert_match('2\s\+0\s\+2', a)
1843 call assert_match('101\s\+0\s\+a', a)
1844 call assert_match('105\s\+0\s\+Z', a)
1845 norm! 3g;
1846 call assert_equal(2, line('.'))
1847 norm! 2g,
1848 call assert_equal(105, line('.'))
1849
1850 " Test for g& - global substitute
1851 %d
1852 call setline(1, range(1,10))
1853 call append('$', ['a', 'b', 'c', 'd'])
1854 $s/\w/&&/g
1855 exe "norm! /[1-8]\<cr>"
1856 norm! g&
1857 call assert_equal(['11', '22', '33', '44', '55', '66', '77', '88', '9', '110', 'a', 'b', 'c', 'dd'], getline(1, '$'))
1858
Bram Moolenaar1671f442020-03-10 07:48:13 +01001859 " Jumping to a fold using gg should open the fold
1860 set foldenable
1861 set foldopen+=jump
1862 5,8fold
1863 call feedkeys('6gg', 'xt')
1864 call assert_equal(1, foldlevel('.'))
1865 call assert_equal(-1, foldclosed('.'))
1866 set foldopen-=jump
1867 set foldenable&
1868
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001869 " Test for gv
1870 %d
1871 call append('$', repeat(['abcdefgh'], 8))
1872 exe "norm! 2gg02l\<c-v>2j2ly"
1873 call assert_equal(['cde', 'cde', 'cde'], getreg(0, 1, 1))
1874 " in visual mode, gv swaps current and last selected region
1875 exe "norm! G0\<c-v>4k4lgvd"
1876 call assert_equal(['', 'abfgh', 'abfgh', 'abfgh', 'abcdefgh', 'abcdefgh', 'abcdefgh', 'abcdefgh', 'abcdefgh'], getline(1,'$'))
1877 exe "norm! G0\<c-v>4k4ly"
1878 exe "norm! gvood"
1879 call assert_equal(['', 'abfgh', 'abfgh', 'abfgh', 'fgh', 'fgh', 'fgh', 'fgh', 'fgh'], getline(1,'$'))
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01001880 " gv cannot be used in operator pending mode
1881 call assert_beeps('normal! cgv')
1882 " gv should beep without a previously selected visual area
1883 new
1884 call assert_beeps('normal! gv')
1885 close
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001886
1887 " Test for gk/gj
1888 %d
1889 15vsp
1890 set wrap listchars= sbr=
1891 let lineA='abcdefghijklmnopqrstuvwxyz'
1892 let lineB='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'
Bram Moolenaar8b530c12019-10-28 02:13:05 +01001893 let lineC='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz01234567890123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001894 $put =lineA
1895 $put =lineB
1896
1897 norm! 3gg0dgk
1898 call assert_equal(['', 'abcdefghijklmno', '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'], getline(1, '$'))
1899 set nu
1900 norm! 3gg0gjdgj
1901 call assert_equal(['', 'abcdefghijklmno', '0123456789AMNOPQRSTUVWXYZ'], getline(1,'$'))
1902
1903 " Test for gJ
1904 norm! 2gggJ
1905 call assert_equal(['', 'abcdefghijklmno0123456789AMNOPQRSTUVWXYZ'], getline(1,'$'))
1906 call assert_equal(16, col('.'))
1907 " shouldn't do anything
1908 norm! 10gJ
1909 call assert_equal(1, col('.'))
1910
1911 " Test for g0 g^ gm g$
1912 exe "norm! 2gg0gji "
1913 call assert_equal(['', 'abcdefghijk lmno0123456789AMNOPQRSTUVWXYZ'], getline(1,'$'))
1914 norm! g0yl
1915 call assert_equal(12, col('.'))
1916 call assert_equal(' ', getreg(0))
1917 norm! g$yl
1918 call assert_equal(22, col('.'))
1919 call assert_equal('3', getreg(0))
1920 norm! gmyl
1921 call assert_equal(17, col('.'))
1922 call assert_equal('n', getreg(0))
1923 norm! g^yl
1924 call assert_equal(15, col('.'))
1925 call assert_equal('l', getreg(0))
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01001926 call assert_beeps('normal 5g$')
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001927
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01001928 " Test for g_
1929 call assert_beeps('normal! 100g_')
1930 call setline(2, [' foo ', ' foobar '])
1931 normal! 2ggg_
1932 call assert_equal(5, col('.'))
1933 normal! 2g_
1934 call assert_equal(8, col('.'))
1935
1936 norm! 2ggdG
Bram Moolenaar8b530c12019-10-28 02:13:05 +01001937 $put =lineC
1938
1939 " Test for gM
1940 norm! gMyl
1941 call assert_equal(73, col('.'))
1942 call assert_equal('0', getreg(0))
1943 " Test for 20gM
1944 norm! 20gMyl
1945 call assert_equal(29, col('.'))
1946 call assert_equal('S', getreg(0))
1947 " Test for 60gM
1948 norm! 60gMyl
1949 call assert_equal(87, col('.'))
1950 call assert_equal('E', getreg(0))
1951
1952 " Test for g Ctrl-G
1953 set ff=unix
1954 let a=execute(":norm! g\<c-g>")
1955 call assert_match('Col 87 of 144; Line 2 of 2; Word 1 of 1; Byte 88 of 146', a)
1956
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001957 " Test for gI
1958 norm! gIfoo
Bram Moolenaar8b530c12019-10-28 02:13:05 +01001959 call assert_equal(['', 'foo0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz01234567890123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'], getline(1,'$'))
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001960
1961 " Test for gi
1962 wincmd c
1963 %d
1964 set tw=0
1965 call setline(1, ['foobar', 'new line'])
1966 norm! A next word
1967 $put ='third line'
1968 norm! gi another word
1969 call assert_equal(['foobar next word another word', 'new line', 'third line'], getline(1,'$'))
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01001970 call setline(1, 'foobar')
1971 normal! Ggifirst line
1972 call assert_equal('foobarfirst line', getline(1))
1973 " Test gi in 'virtualedit' mode with cursor after the end of the line
1974 set virtualedit=all
1975 call setline(1, 'foo')
1976 exe "normal! Abar\<Right>\<Right>\<Right>\<Right>"
1977 call setline(1, 'foo')
1978 normal! Ggifirst line
1979 call assert_equal('foo first line', getline(1))
1980 set virtualedit&
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001981
Bram Moolenaar1671f442020-03-10 07:48:13 +01001982 " Test for aboring a g command using CTRL-\ CTRL-G
1983 exe "normal! g\<C-\>\<C-G>"
1984 call assert_equal('foo first line', getline('.'))
1985
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001986 " clean up
1987 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02001988endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001989
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01001990" Test for g CTRL-G
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01001991func Test_g_ctrl_g()
Bram Moolenaar05295832018-08-24 22:07:58 +02001992 new
1993
1994 let a = execute(":norm! g\<c-g>")
1995 call assert_equal("\n--No lines in buffer--", a)
1996
Bram Moolenaar1671f442020-03-10 07:48:13 +01001997 " Test for CTRL-G (same as :file)
1998 let a = execute(":norm! \<c-g>")
1999 call assert_equal("\n\n\"[No Name]\" --No lines in buffer--", a)
2000
Bram Moolenaar05295832018-08-24 22:07:58 +02002001 call setline(1, ['first line', 'second line'])
2002
2003 " Test g CTRL-g with dos, mac and unix file type.
2004 norm! gojll
2005 set ff=dos
2006 let a = execute(":norm! g\<c-g>")
2007 call assert_equal("\nCol 3 of 11; Line 2 of 2; Word 3 of 4; Byte 15 of 25", a)
2008
2009 set ff=mac
2010 let a = execute(":norm! g\<c-g>")
2011 call assert_equal("\nCol 3 of 11; Line 2 of 2; Word 3 of 4; Byte 14 of 23", a)
2012
2013 set ff=unix
2014 let a = execute(":norm! g\<c-g>")
2015 call assert_equal("\nCol 3 of 11; Line 2 of 2; Word 3 of 4; Byte 14 of 23", a)
2016
2017 " Test g CTRL-g in visual mode (v)
2018 let a = execute(":norm! gojllvlg\<c-g>")
2019 call assert_equal("\nSelected 1 of 2 Lines; 1 of 4 Words; 2 of 23 Bytes", a)
2020
2021 " Test g CTRL-g in visual mode (CTRL-V) with end col > start col
2022 let a = execute(":norm! \<Esc>gojll\<C-V>kllg\<c-g>")
2023 call assert_equal("\nSelected 3 Cols; 2 of 2 Lines; 2 of 4 Words; 6 of 23 Bytes", a)
2024
2025 " Test g_CTRL-g in visual mode (CTRL-V) with end col < start col
2026 let a = execute(":norm! \<Esc>goll\<C-V>jhhg\<c-g>")
2027 call assert_equal("\nSelected 3 Cols; 2 of 2 Lines; 2 of 4 Words; 6 of 23 Bytes", a)
2028
2029 " Test g CTRL-g in visual mode (CTRL-V) with end_vcol being MAXCOL
2030 let a = execute(":norm! \<Esc>gojll\<C-V>k$g\<c-g>")
2031 call assert_equal("\nSelected 2 of 2 Lines; 4 of 4 Words; 17 of 23 Bytes", a)
2032
2033 " There should be one byte less with noeol
2034 set bin noeol
2035 let a = execute(":norm! \<Esc>gog\<c-g>")
2036 call assert_equal("\nCol 1 of 10; Line 1 of 2; Word 1 of 4; Char 1 of 23; Byte 1 of 22", a)
2037 set bin & eol&
2038
Bram Moolenaar30276f22019-01-24 17:59:39 +01002039 call setline(1, ['Français', '日本語'])
Bram Moolenaar05295832018-08-24 22:07:58 +02002040
Bram Moolenaar30276f22019-01-24 17:59:39 +01002041 let a = execute(":norm! \<Esc>gojlg\<c-g>")
2042 call assert_equal("\nCol 4-3 of 9-6; Line 2 of 2; Word 2 of 2; Char 11 of 13; Byte 16 of 20", a)
Bram Moolenaar05295832018-08-24 22:07:58 +02002043
Bram Moolenaar30276f22019-01-24 17:59:39 +01002044 let a = execute(":norm! \<Esc>gojvlg\<c-g>")
2045 call assert_equal("\nSelected 1 of 2 Lines; 1 of 2 Words; 2 of 13 Chars; 6 of 20 Bytes", a)
Bram Moolenaar05295832018-08-24 22:07:58 +02002046
Bram Moolenaar30276f22019-01-24 17:59:39 +01002047 let a = execute(":norm! \<Esc>goll\<c-v>jlg\<c-g>")
2048 call assert_equal("\nSelected 4 Cols; 2 of 2 Lines; 2 of 2 Words; 6 of 13 Chars; 11 of 20 Bytes", a)
Bram Moolenaar05295832018-08-24 22:07:58 +02002049
Bram Moolenaar30276f22019-01-24 17:59:39 +01002050 set fenc=utf8 bomb
2051 let a = execute(":norm! \<Esc>gojlg\<c-g>")
2052 call assert_equal("\nCol 4-3 of 9-6; Line 2 of 2; Word 2 of 2; Char 11 of 13; Byte 16 of 20(+3 for BOM)", a)
Bram Moolenaar05295832018-08-24 22:07:58 +02002053
Bram Moolenaar30276f22019-01-24 17:59:39 +01002054 set fenc=utf16 bomb
2055 let a = execute(":norm! g\<c-g>")
2056 call assert_equal("\nCol 4-3 of 9-6; Line 2 of 2; Word 2 of 2; Char 11 of 13; Byte 16 of 20(+2 for BOM)", a)
Bram Moolenaar05295832018-08-24 22:07:58 +02002057
Bram Moolenaar30276f22019-01-24 17:59:39 +01002058 set fenc=utf32 bomb
2059 let a = execute(":norm! g\<c-g>")
2060 call assert_equal("\nCol 4-3 of 9-6; Line 2 of 2; Word 2 of 2; Char 11 of 13; Byte 16 of 20(+4 for BOM)", a)
Bram Moolenaar05295832018-08-24 22:07:58 +02002061
Bram Moolenaar30276f22019-01-24 17:59:39 +01002062 set fenc& bomb&
Bram Moolenaar05295832018-08-24 22:07:58 +02002063
2064 set ff&
2065 bwipe!
2066endfunc
2067
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01002068" Test for g8
Bram Moolenaar1671f442020-03-10 07:48:13 +01002069func Test_normal34_g_cmd3()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002070 new
Bram Moolenaar395b6ba2017-04-07 20:09:51 +02002071 let a=execute(':norm! 1G0g8')
2072 call assert_equal("\nNUL", a)
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002073
Bram Moolenaar395b6ba2017-04-07 20:09:51 +02002074 call setline(1, 'abcdefghijklmnopqrstuvwxyzäüö')
2075 let a=execute(':norm! 1G$g8')
2076 call assert_equal("\nc3 b6 ", a)
2077
2078 call setline(1, "a\u0302")
2079 let a=execute(':norm! 1G0g8')
2080 call assert_equal("\n61 + cc 82 ", a)
2081
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002082 " clean up
2083 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002084endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002085
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01002086" Test 8g8 which finds invalid utf8 at or after the cursor.
Bram Moolenaar395b6ba2017-04-07 20:09:51 +02002087func Test_normal_8g8()
Bram Moolenaar395b6ba2017-04-07 20:09:51 +02002088 new
2089
Bram Moolenaar395b6ba2017-04-07 20:09:51 +02002090 " With invalid byte.
2091 call setline(1, "___\xff___")
2092 norm! 1G08g8g
2093 call assert_equal([0, 1, 4, 0, 1], getcurpos())
2094
2095 " With invalid byte before the cursor.
2096 call setline(1, "___\xff___")
2097 norm! 1G$h8g8g
2098 call assert_equal([0, 1, 6, 0, 9], getcurpos())
2099
2100 " With truncated sequence.
2101 call setline(1, "___\xE2\x82___")
2102 norm! 1G08g8g
2103 call assert_equal([0, 1, 4, 0, 1], getcurpos())
2104
2105 " With overlong sequence.
2106 call setline(1, "___\xF0\x82\x82\xAC___")
2107 norm! 1G08g8g
2108 call assert_equal([0, 1, 4, 0, 1], getcurpos())
2109
2110 " With valid utf8.
2111 call setline(1, "café")
2112 norm! 1G08g8
2113 call assert_equal([0, 1, 1, 0, 1], getcurpos())
2114
2115 bw!
2116endfunc
2117
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01002118" Test for g<
Bram Moolenaar1671f442020-03-10 07:48:13 +01002119func Test_normal35_g_cmd4()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002120 " Cannot capture its output,
2121 " probably a bug, therefore, test disabled:
Bram Moolenaar31845092016-09-05 22:58:31 +02002122 throw "Skipped: output of g< can't be tested currently"
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002123 echo "a\nb\nc\nd"
2124 let b=execute(':norm! g<')
2125 call assert_true(!empty(b), 'failed `execute(g<)`')
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002126endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002127
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01002128" Test for gp gP go
Bram Moolenaar1671f442020-03-10 07:48:13 +01002129func Test_normal36_g_cmd5()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002130 new
2131 call append(0, 'abcdefghijklmnopqrstuvwxyz')
Bram Moolenaar0913a102016-09-03 19:11:59 +02002132 set ff=unix
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002133 " Test for gp gP
2134 call append(1, range(1,10))
2135 1
2136 norm! 1yy
2137 3
2138 norm! gp
2139 call assert_equal([0, 5, 1, 0, 1], getcurpos())
2140 $
2141 norm! gP
2142 call assert_equal([0, 14, 1, 0, 1], getcurpos())
2143
2144 " Test for go
2145 norm! 26go
2146 call assert_equal([0, 1, 26, 0, 26], getcurpos())
2147 norm! 27go
2148 call assert_equal([0, 1, 26, 0, 26], getcurpos())
2149 norm! 28go
2150 call assert_equal([0, 2, 1, 0, 1], getcurpos())
2151 set ff=dos
2152 norm! 29go
2153 call assert_equal([0, 2, 1, 0, 1], getcurpos())
2154 set ff=unix
2155 norm! gg0
2156 norm! 101go
2157 call assert_equal([0, 13, 26, 0, 26], getcurpos())
2158 norm! 103go
2159 call assert_equal([0, 14, 1, 0, 1], getcurpos())
2160 " count > buffer content
2161 norm! 120go
2162 call assert_equal([0, 14, 1, 0, 2147483647], getcurpos())
2163 " clean up
2164 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002165endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002166
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01002167" Test for gt and gT
Bram Moolenaar1671f442020-03-10 07:48:13 +01002168func Test_normal37_g_cmd6()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002169 tabnew 1.txt
2170 tabnew 2.txt
2171 tabnew 3.txt
2172 norm! 1gt
2173 call assert_equal(1, tabpagenr())
2174 norm! 3gt
2175 call assert_equal(3, tabpagenr())
2176 norm! 1gT
2177 " count gT goes not to the absolute tabpagenumber
2178 " but, but goes to the count previous tabpagenumber
2179 call assert_equal(2, tabpagenr())
2180 " wrap around
2181 norm! 3gT
2182 call assert_equal(3, tabpagenr())
2183 " gt does not wrap around
2184 norm! 5gt
2185 call assert_equal(3, tabpagenr())
2186
2187 for i in range(3)
2188 tabclose
2189 endfor
2190 " clean up
Bram Moolenaarbc2b71d2020-02-17 21:33:30 +01002191 call assert_fails(':tabclose', 'E784:')
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002192endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002193
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01002194" Test for <Home> and <C-Home> key
Bram Moolenaar1671f442020-03-10 07:48:13 +01002195func Test_normal38_nvhome()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002196 new
2197 call setline(1, range(10))
2198 $
2199 setl et sw=2
2200 norm! V10>$
2201 " count is ignored
2202 exe "norm! 10\<home>"
2203 call assert_equal(1, col('.'))
2204 exe "norm! \<home>"
2205 call assert_equal([0, 10, 1, 0, 1], getcurpos())
2206 exe "norm! 5\<c-home>"
2207 call assert_equal([0, 5, 1, 0, 1], getcurpos())
2208 exe "norm! \<c-home>"
2209 call assert_equal([0, 1, 1, 0, 1], getcurpos())
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01002210 exe "norm! G\<c-kHome>"
2211 call assert_equal([0, 1, 1, 0, 1], getcurpos())
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002212
2213 " clean up
2214 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002215endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002216
Bram Moolenaar1671f442020-03-10 07:48:13 +01002217" Test for <End> and <C-End> keys
2218func Test_normal_nvend()
2219 new
2220 call setline(1, map(range(1, 10), '"line" .. v:val'))
2221 exe "normal! \<End>"
2222 call assert_equal(5, col('.'))
2223 exe "normal! 4\<End>"
2224 call assert_equal([4, 5], [line('.'), col('.')])
2225 exe "normal! \<C-End>"
2226 call assert_equal([10, 6], [line('.'), col('.')])
2227 close!
2228endfunc
2229
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01002230" Test for cw cW ce
Bram Moolenaar1671f442020-03-10 07:48:13 +01002231func Test_normal39_cw()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002232 " Test for cw and cW on whitespace
2233 " and cpo+=w setting
2234 new
2235 set tw=0
2236 call append(0, 'here are some words')
2237 norm! 1gg0elcwZZZ
2238 call assert_equal('hereZZZare some words', getline('.'))
2239 norm! 1gg0elcWYYY
2240 call assert_equal('hereZZZareYYYsome words', getline('.'))
2241 set cpo+=w
2242 call setline(1, 'here are some words')
2243 norm! 1gg0elcwZZZ
2244 call assert_equal('hereZZZ are some words', getline('.'))
2245 norm! 1gg2elcWYYY
2246 call assert_equal('hereZZZ areYYY some words', getline('.'))
2247 set cpo-=w
2248 norm! 2gg0cwfoo
2249 call assert_equal('foo', getline('.'))
2250
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01002251 call setline(1, 'one; two')
2252 call cursor(1, 1)
2253 call feedkeys('cwvim', 'xt')
2254 call assert_equal('vim; two', getline(1))
2255 call feedkeys('0cWone', 'xt')
2256 call assert_equal('one two', getline(1))
2257 "When cursor is at the end of a word 'ce' will change until the end of the
2258 "next word, but 'cw' will change only one character
2259 call setline(1, 'one two')
2260 call feedkeys('0ecwce', 'xt')
2261 call assert_equal('once two', getline(1))
2262 call setline(1, 'one two')
2263 call feedkeys('0ecely', 'xt')
2264 call assert_equal('only', getline(1))
2265
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002266 " clean up
2267 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002268endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002269
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01002270" Test for CTRL-\ commands
Bram Moolenaar1671f442020-03-10 07:48:13 +01002271func Test_normal40_ctrl_bsl()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002272 new
2273 call append(0, 'here are some words')
2274 exe "norm! 1gg0a\<C-\>\<C-N>"
2275 call assert_equal('n', mode())
2276 call assert_equal(1, col('.'))
2277 call assert_equal('', visualmode())
2278 exe "norm! 1gg0viw\<C-\>\<C-N>"
2279 call assert_equal('n', mode())
2280 call assert_equal(4, col('.'))
2281 exe "norm! 1gg0a\<C-\>\<C-G>"
2282 call assert_equal('n', mode())
2283 call assert_equal(1, col('.'))
2284 "imap <buffer> , <c-\><c-n>
2285 set im
2286 exe ":norm! \<c-\>\<c-n>dw"
2287 set noim
2288 call assert_equal('are some words', getline(1))
2289 call assert_false(&insertmode)
Bram Moolenaar1671f442020-03-10 07:48:13 +01002290 call assert_beeps("normal! \<C-\>\<C-A>", 'xt')
2291
2292 " Using CTRL-\ CTRL-N in cmd window should close the window
2293 call feedkeys("q:\<C-\>\<C-N>", 'xt')
2294 call assert_equal('', getcmdwintype())
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002295
2296 " clean up
2297 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002298endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002299
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01002300" Test for <c-r>=, <c-r><c-r>= and <c-r><c-o>= in insert mode
Bram Moolenaar1671f442020-03-10 07:48:13 +01002301func Test_normal41_insert_reg()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002302 new
2303 set sts=2 sw=2 ts=8 tw=0
2304 call append(0, ["aaa\tbbb\tccc", '', '', ''])
2305 let a=getline(1)
2306 norm! 2gg0
2307 exe "norm! a\<c-r>=a\<cr>"
2308 norm! 3gg0
2309 exe "norm! a\<c-r>\<c-r>=a\<cr>"
2310 norm! 4gg0
2311 exe "norm! a\<c-r>\<c-o>=a\<cr>"
2312 call assert_equal(['aaa bbb ccc', 'aaa bbb ccc', 'aaa bbb ccc', 'aaa bbb ccc', ''], getline(1, '$'))
2313
2314 " clean up
2315 set sts=0 sw=8 ts=8
Bram Moolenaar31845092016-09-05 22:58:31 +02002316 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002317endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002318
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01002319" Test for Ctrl-D and Ctrl-U
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01002320func Test_normal42_halfpage()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002321 call Setup_NewWindow()
2322 call assert_equal(5, &scroll)
2323 exe "norm! \<c-d>"
2324 call assert_equal('6', getline('.'))
2325 exe "norm! 2\<c-d>"
2326 call assert_equal('8', getline('.'))
2327 call assert_equal(2, &scroll)
2328 set scroll=5
2329 exe "norm! \<c-u>"
2330 call assert_equal('3', getline('.'))
2331 1
2332 set scrolloff=5
2333 exe "norm! \<c-d>"
2334 call assert_equal('10', getline('.'))
2335 exe "norm! \<c-u>"
2336 call assert_equal('5', getline('.'))
2337 1
2338 set scrolloff=99
2339 exe "norm! \<c-d>"
2340 call assert_equal('10', getline('.'))
2341 set scrolloff=0
2342 100
2343 exe "norm! $\<c-u>"
2344 call assert_equal('95', getline('.'))
2345 call assert_equal([0, 95, 1, 0, 1], getcurpos())
2346 100
2347 set nostartofline
2348 exe "norm! $\<c-u>"
2349 call assert_equal('95', getline('.'))
2350 call assert_equal([0, 95, 2, 0, 2147483647], getcurpos())
2351 " cleanup
2352 set startofline
2353 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002354endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002355
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01002356" Tests for text object aw
Bram Moolenaar1671f442020-03-10 07:48:13 +01002357func Test_normal43_textobject1()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002358 new
2359 call append(0, ['foobar,eins,foobar', 'foo,zwei,foo '])
2360 " diw
2361 norm! 1gg0diw
2362 call assert_equal([',eins,foobar', 'foo,zwei,foo ', ''], getline(1,'$'))
2363 " daw
2364 norm! 2ggEdaw
2365 call assert_equal([',eins,foobar', 'foo,zwei,', ''], getline(1, '$'))
2366 %d
2367 call append(0, ["foo\teins\tfoobar", "foo\tzwei\tfoo "])
2368 " diW
2369 norm! 2ggwd2iW
2370 call assert_equal(['foo eins foobar', 'foo foo ', ''], getline(1,'$'))
2371 " daW
2372 norm! 1ggd2aW
2373 call assert_equal(['foobar', 'foo foo ', ''], getline(1,'$'))
2374
2375 %d
2376 call append(0, ["foo\teins\tfoobar", "foo\tzwei\tfoo "])
2377 " aw in visual line mode switches to characterwise mode
2378 norm! 2gg$Vawd
2379 call assert_equal(['foo eins foobar', 'foo zwei foo'], getline(1,'$'))
2380 norm! 1gg$Viwd
2381 call assert_equal(['foo eins ', 'foo zwei foo'], getline(1,'$'))
2382
2383 " clean up
2384 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002385endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002386
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01002387" Test for is and as text objects
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01002388func Test_normal44_textobjects2()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002389 new
2390 call append(0, ['This is a test. With some sentences!', '', 'Even with a question? And one more. And no sentence here'])
2391 " Test for dis - does not remove trailing whitespace
2392 norm! 1gg0dis
2393 call assert_equal([' With some sentences!', '', 'Even with a question? And one more. And no sentence here', ''], getline(1,'$'))
2394 " Test for das - removes leading whitespace
2395 norm! 3ggf?ldas
2396 call assert_equal([' With some sentences!', '', 'Even with a question? And no sentence here', ''], getline(1,'$'))
2397 " when used in visual mode, is made characterwise
2398 norm! 3gg$Visy
2399 call assert_equal('v', visualmode())
2400 " reset visualmode()
2401 norm! 3ggVy
2402 norm! 3gg$Vasy
2403 call assert_equal('v', visualmode())
2404 " basic testing for textobjects a< and at
2405 %d
2406 call setline(1, ['<div> ','<a href="foobar" class="foo">xyz</a>',' </div>', ' '])
2407 " a<
2408 norm! 1gg0da<
2409 call assert_equal([' ', '<a href="foobar" class="foo">xyz</a>', ' </div>', ' '], getline(1,'$'))
2410 norm! 1pj
2411 call assert_equal([' <div>', '<a href="foobar" class="foo">xyz</a>', ' </div>', ' '], getline(1,'$'))
2412 " at
2413 norm! d2at
2414 call assert_equal([' '], getline(1,'$'))
2415 %d
2416 call setline(1, ['<div> ','<a href="foobar" class="foo">xyz</a>',' </div>', ' '])
2417 " i<
2418 norm! 1gg0di<
2419 call assert_equal(['<> ', '<a href="foobar" class="foo">xyz</a>', ' </div>', ' '], getline(1,'$'))
2420 norm! 1Pj
2421 call assert_equal(['<div> ', '<a href="foobar" class="foo">xyz</a>', ' </div>', ' '], getline(1,'$'))
2422 norm! d2it
2423 call assert_equal(['<div></div>',' '], getline(1,'$'))
2424 " basic testing for a[ and i[ text object
2425 %d
2426 call setline(1, [' ', '[', 'one [two]', 'thre', ']'])
2427 norm! 3gg0di[
2428 call assert_equal([' ', '[', ']'], getline(1,'$'))
2429 call setline(1, [' ', '[', 'one [two]', 'thre', ']'])
2430 norm! 3gg0ftd2a[
2431 call assert_equal([' '], getline(1,'$'))
2432 %d
2433 " Test for i" when cursor is in front of a quoted object
2434 call append(0, 'foo "bar"')
2435 norm! 1gg0di"
2436 call assert_equal(['foo ""', ''], getline(1,'$'))
2437
2438 " clean up
2439 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002440endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002441
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01002442func Test_normal45_drop()
Bram Moolenaar29495952018-02-12 22:49:00 +01002443 if !has('dnd')
Bram Moolenaarb48e96f2018-02-13 12:26:14 +01002444 " The ~ register does not exist
2445 call assert_beeps('norm! "~')
Bram Moolenaar29495952018-02-12 22:49:00 +01002446 return
2447 endif
2448
2449 " basic test for drag-n-drop
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002450 " unfortunately, without a gui, we can't really test much here,
2451 " so simply test that ~p fails (which uses the drop register)
2452 new
2453 call assert_fails(':norm! "~p', 'E353')
2454 call assert_equal([], getreg('~', 1, 1))
2455 " the ~ register is read only
2456 call assert_fails(':let @~="1"', 'E354')
2457 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002458endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002459
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01002460func Test_normal46_ignore()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002461 new
2462 " How to test this?
2463 " let's just for now test, that the buffer
2464 " does not change
2465 call feedkeys("\<c-s>", 't')
2466 call assert_equal([''], getline(1,'$'))
2467
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002468 " no valid commands
2469 exe "norm! \<char-0x100>"
2470 call assert_equal([''], getline(1,'$'))
2471
2472 exe "norm! ä"
2473 call assert_equal([''], getline(1,'$'))
2474
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002475 " clean up
2476 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002477endfunc
Bram Moolenaarc4a908e2016-09-08 23:35:30 +02002478
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01002479func Test_normal47_visual_buf_wipe()
Bram Moolenaarc4a908e2016-09-08 23:35:30 +02002480 " This was causing a crash or ml_get error.
2481 enew!
2482 call setline(1,'xxx')
2483 normal $
2484 new
2485 call setline(1, range(1,2))
2486 2
2487 exe "norm \<C-V>$"
2488 bw!
2489 norm yp
2490 set nomodified
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002491endfunc
2492
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01002493func Test_normal47_autocmd()
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002494 " disabled, does not seem to be possible currently
2495 throw "Skipped: not possible to test cursorhold autocmd while waiting for input in normal_cmd"
2496 new
2497 call append(0, repeat('-',20))
2498 au CursorHold * call feedkeys('2l', '')
2499 1
2500 set updatetime=20
2501 " should delete 12 chars (d12l)
2502 call feedkeys('d1', '!')
2503 call assert_equal('--------', getline(1))
2504
2505 " clean up
2506 au! CursorHold
2507 set updatetime=4000
2508 bw!
2509endfunc
2510
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01002511func Test_normal48_wincmd()
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002512 new
2513 exe "norm! \<c-w>c"
2514 call assert_equal(1, winnr('$'))
2515 call assert_fails(":norm! \<c-w>c", "E444")
2516endfunc
2517
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01002518func Test_normal49_counts()
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002519 new
2520 call setline(1, 'one two three four five six seven eight nine ten')
2521 1
2522 norm! 3d2w
2523 call assert_equal('seven eight nine ten', getline(1))
2524 bw!
2525endfunc
2526
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01002527func Test_normal50_commandline()
Bram Moolenaar4033c552017-09-16 20:54:51 +02002528 if !has("timers") || !has("cmdline_hist")
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002529 return
2530 endif
2531 func! DoTimerWork(id)
2532 call assert_equal('[Command Line]', bufname(''))
2533 " should fail, with E11, but does fail with E23?
2534 "call feedkeys("\<c-^>", 'tm')
2535
2536 " should also fail with E11
2537 call assert_fails(":wincmd p", 'E11')
2538 " return from commandline window
2539 call feedkeys("\<cr>")
2540 endfunc
2541
2542 let oldlang=v:lang
2543 lang C
2544 set updatetime=20
2545 call timer_start(100, 'DoTimerWork')
2546 try
2547 " throws E23, for whatever reason...
2548 call feedkeys('q:', 'x!')
2549 catch /E23/
2550 " no-op
2551 endtry
2552 " clean up
2553 set updatetime=4000
2554 exe "lang" oldlang
2555 bw!
2556endfunc
2557
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01002558func Test_normal51_FileChangedRO()
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002559 if !has("autocmd")
2560 return
2561 endif
Bram Moolenaare5f2a072017-02-01 22:31:49 +01002562 " Don't sleep after the warning message.
2563 call test_settime(1)
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002564 call writefile(['foo'], 'Xreadonly.log')
2565 new Xreadonly.log
2566 setl ro
2567 au FileChangedRO <buffer> :call feedkeys("\<c-^>", 'tix')
2568 call assert_fails(":norm! Af", 'E788')
2569 call assert_equal(['foo'], getline(1,'$'))
2570 call assert_equal('Xreadonly.log', bufname(''))
2571
2572 " cleanup
Bram Moolenaare5f2a072017-02-01 22:31:49 +01002573 call test_settime(0)
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002574 bw!
2575 call delete("Xreadonly.log")
2576endfunc
2577
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01002578func Test_normal52_rl()
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002579 if !has("rightleft")
2580 return
2581 endif
2582 new
2583 call setline(1, 'abcde fghij klmnopq')
2584 norm! 1gg$
2585 set rl
2586 call assert_equal(19, col('.'))
2587 call feedkeys('l', 'tx')
2588 call assert_equal(18, col('.'))
2589 call feedkeys('h', 'tx')
2590 call assert_equal(19, col('.'))
2591 call feedkeys("\<right>", 'tx')
2592 call assert_equal(18, col('.'))
Bram Moolenaar1671f442020-03-10 07:48:13 +01002593 call feedkeys("\<left>", 'tx')
2594 call assert_equal(19, col('.'))
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002595 call feedkeys("\<s-right>", 'tx')
2596 call assert_equal(13, col('.'))
2597 call feedkeys("\<c-right>", 'tx')
2598 call assert_equal(7, col('.'))
2599 call feedkeys("\<c-left>", 'tx')
2600 call assert_equal(13, col('.'))
2601 call feedkeys("\<s-left>", 'tx')
2602 call assert_equal(19, col('.'))
2603 call feedkeys("<<", 'tx')
2604 call assert_equal(' abcde fghij klmnopq',getline(1))
2605 call feedkeys(">>", 'tx')
2606 call assert_equal('abcde fghij klmnopq',getline(1))
2607
2608 " cleanup
2609 set norl
2610 bw!
2611endfunc
2612
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01002613func Test_normal53_digraph()
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002614 if !has('digraphs')
2615 return
2616 endif
2617 new
2618 call setline(1, 'abcdefgh|')
2619 exe "norm! 1gg0f\<c-k>!!"
2620 call assert_equal(9, col('.'))
2621 set cpo+=D
2622 exe "norm! 1gg0f\<c-k>!!"
2623 call assert_equal(1, col('.'))
2624
2625 set cpo-=D
2626 bw!
2627endfunc
2628
Bram Moolenaarb1e04fc2017-03-29 13:08:35 +02002629func Test_normal54_Ctrl_bsl()
2630 new
2631 call setline(1, 'abcdefghijklmn')
2632 exe "norm! df\<c-\>\<c-n>"
2633 call assert_equal(['abcdefghijklmn'], getline(1,'$'))
2634 exe "norm! df\<c-\>\<c-g>"
2635 call assert_equal(['abcdefghijklmn'], getline(1,'$'))
2636 exe "norm! df\<c-\>m"
2637 call assert_equal(['abcdefghijklmn'], getline(1,'$'))
Bram Moolenaar30276f22019-01-24 17:59:39 +01002638
Bram Moolenaarb1e04fc2017-03-29 13:08:35 +02002639 call setline(2, 'abcdefghijklmnāf')
2640 norm! 2gg0
2641 exe "norm! df\<Char-0x101>"
2642 call assert_equal(['abcdefghijklmn', 'f'], getline(1,'$'))
2643 norm! 1gg0
2644 exe "norm! df\<esc>"
2645 call assert_equal(['abcdefghijklmn', 'f'], getline(1,'$'))
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002646
Bram Moolenaarb1e04fc2017-03-29 13:08:35 +02002647 " clean up
2648 bw!
2649endfunc
2650
2651func Test_normal_large_count()
2652 " This may fail with 32bit long, how do we detect that?
2653 new
2654 normal o
2655 normal 6666666666dL
2656 bwipe!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002657endfunc
Bram Moolenaarbf3d5802017-03-29 19:48:11 +02002658
2659func Test_delete_until_paragraph()
Bram Moolenaarbf3d5802017-03-29 19:48:11 +02002660 new
2661 normal grádv}
2662 call assert_equal('á', getline(1))
2663 normal grád}
2664 call assert_equal('', getline(1))
2665 bwipe!
2666endfunc
Bram Moolenaarfb094e12017-11-05 20:59:28 +01002667
2668" Test for the gr (virtual replace) command
2669" Test for the bug fixed by 7.4.387
2670func Test_gr_command()
2671 enew!
2672 let save_cpo = &cpo
2673 call append(0, ['First line', 'Second line', 'Third line'])
2674 exe "normal i\<C-G>u"
2675 call cursor(2, 1)
2676 set cpo-=X
2677 normal 4gro
2678 call assert_equal('oooond line', getline(2))
2679 undo
2680 set cpo+=X
2681 normal 4gro
2682 call assert_equal('ooooecond line', getline(2))
2683 let &cpo = save_cpo
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01002684 normal! ggvegrx
2685 call assert_equal('xxxxx line', getline(1))
2686 exe "normal! gggr\<C-V>122"
2687 call assert_equal('zxxxx line', getline(1))
2688 set virtualedit=all
2689 normal! 15|grl
2690 call assert_equal('zxxxx line l', getline(1))
2691 set virtualedit&
2692 set nomodifiable
2693 call assert_fails('normal! grx', 'E21:')
2694 call assert_fails('normal! gRx', 'E21:')
2695 set modifiable&
Bram Moolenaarfb094e12017-11-05 20:59:28 +01002696 enew!
2697endfunc
2698
2699" When splitting a window the changelist position is wrong.
2700" Test the changelist position after splitting a window.
2701" Test for the bug fixed by 7.4.386
2702func Test_changelist()
2703 let save_ul = &ul
2704 enew!
2705 call append('$', ['1', '2'])
2706 exe "normal i\<C-G>u"
2707 exe "normal Gkylpa\<C-G>u"
2708 set ul=100
2709 exe "normal Gylpa\<C-G>u"
2710 set ul=100
2711 normal gg
2712 vsplit
2713 normal g;
2714 call assert_equal([3, 2], [line('.'), col('.')])
2715 normal g;
2716 call assert_equal([2, 2], [line('.'), col('.')])
2717 call assert_fails('normal g;', 'E662:')
Bram Moolenaar1671f442020-03-10 07:48:13 +01002718 new
2719 call assert_fails('normal g;', 'E664:')
Bram Moolenaarfb094e12017-11-05 20:59:28 +01002720 %bwipe!
2721 let &ul = save_ul
2722endfunc
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01002723
2724func Test_nv_hat_count()
2725 %bwipeout!
2726 let l:nr = bufnr('%') + 1
2727 call assert_fails(':execute "normal! ' . l:nr . '\<C-^>"', 'E92')
2728
2729 edit Xfoo
2730 let l:foo_nr = bufnr('Xfoo')
2731
2732 edit Xbar
2733 let l:bar_nr = bufnr('Xbar')
2734
2735 " Make sure we are not just using the alternate file.
2736 edit Xbaz
2737
2738 call feedkeys(l:foo_nr . "\<C-^>", 'tx')
2739 call assert_equal('Xfoo', fnamemodify(bufname('%'), ':t'))
2740
2741 call feedkeys(l:bar_nr . "\<C-^>", 'tx')
2742 call assert_equal('Xbar', fnamemodify(bufname('%'), ':t'))
2743
2744 %bwipeout!
2745endfunc
Bram Moolenaara84a3dd2019-03-25 22:21:24 +01002746
2747func Test_message_when_using_ctrl_c()
Bram Moolenaar553e5a52019-03-25 23:16:34 +01002748 " Make sure no buffers are changed.
2749 %bwipe!
2750
Bram Moolenaara84a3dd2019-03-25 22:21:24 +01002751 exe "normal \<C-C>"
2752 call assert_match("Type :qa and press <Enter> to exit Vim", Screenline(&lines))
Bram Moolenaar553e5a52019-03-25 23:16:34 +01002753
Bram Moolenaara84a3dd2019-03-25 22:21:24 +01002754 new
2755 cal setline(1, 'hi!')
2756 exe "normal \<C-C>"
2757 call assert_match("Type :qa! and press <Enter> to abandon all changes and exit Vim", Screenline(&lines))
Bram Moolenaar553e5a52019-03-25 23:16:34 +01002758
Bram Moolenaara84a3dd2019-03-25 22:21:24 +01002759 bwipe!
2760endfunc
Bram Moolenaarc6b37db2019-04-27 18:00:34 +02002761
2762" Test for '[m', ']m', '[M' and ']M'
2763" Jumping to beginning and end of methods in Java-like languages
2764func Test_java_motion()
2765 new
Bram Moolenaar1671f442020-03-10 07:48:13 +01002766 call assert_beeps('normal! [m')
2767 call assert_beeps('normal! ]m')
2768 call assert_beeps('normal! [M')
2769 call assert_beeps('normal! ]M')
Bram Moolenaarc6b37db2019-04-27 18:00:34 +02002770 a
2771Piece of Java
2772{
2773 tt m1 {
2774 t1;
2775 } e1
2776
2777 tt m2 {
2778 t2;
2779 } e2
2780
2781 tt m3 {
2782 if (x)
2783 {
2784 t3;
2785 }
2786 } e3
2787}
2788.
2789
2790 normal gg
2791
2792 normal 2]maA
2793 call assert_equal("\ttt m1 {A", getline('.'))
2794 call assert_equal([3, 9, 16], [line('.'), col('.'), virtcol('.')])
2795
2796 normal j]maB
2797 call assert_equal("\ttt m2 {B", getline('.'))
2798 call assert_equal([7, 9, 16], [line('.'), col('.'), virtcol('.')])
2799
2800 normal ]maC
2801 call assert_equal("\ttt m3 {C", getline('.'))
2802 call assert_equal([11, 9, 16], [line('.'), col('.'), virtcol('.')])
2803
2804 normal [maD
2805 call assert_equal("\ttt m3 {DC", getline('.'))
2806 call assert_equal([11, 9, 16], [line('.'), col('.'), virtcol('.')])
2807
2808 normal k2[maE
2809 call assert_equal("\ttt m1 {EA", getline('.'))
2810 call assert_equal([3, 9, 16], [line('.'), col('.'), virtcol('.')])
2811
2812 normal 3[maF
2813 call assert_equal("{F", getline('.'))
2814 call assert_equal([2, 2, 2], [line('.'), col('.'), virtcol('.')])
2815
2816 normal ]MaG
2817 call assert_equal("\t}G e1", getline('.'))
2818 call assert_equal([5, 3, 10], [line('.'), col('.'), virtcol('.')])
2819
2820 normal j2]MaH
2821 call assert_equal("\t}H e3", getline('.'))
2822 call assert_equal([16, 3, 10], [line('.'), col('.'), virtcol('.')])
2823
2824 normal ]M]M
2825 normal aI
2826 call assert_equal("}I", getline('.'))
2827 call assert_equal([17, 2, 2], [line('.'), col('.'), virtcol('.')])
2828
2829 normal 2[MaJ
2830 call assert_equal("\t}JH e3", getline('.'))
2831 call assert_equal([16, 3, 10], [line('.'), col('.'), virtcol('.')])
2832
2833 normal k[MaK
2834 call assert_equal("\t}K e2", getline('.'))
2835 call assert_equal([9, 3, 10], [line('.'), col('.'), virtcol('.')])
2836
2837 normal 3[MaL
2838 call assert_equal("{LF", getline('.'))
2839 call assert_equal([2, 2, 2], [line('.'), col('.'), virtcol('.')])
2840
2841 close!
2842endfunc
Bram Moolenaard5c82342019-07-27 18:44:57 +02002843
Bram Moolenaar1671f442020-03-10 07:48:13 +01002844func Test_normal_gdollar_cmd()
Bram Moolenaard5c82342019-07-27 18:44:57 +02002845 if !has("jumplist")
2846 return
2847 endif
2848 " Tests for g cmds
2849 call Setup_NewWindow()
2850 " Make long lines that will wrap
2851 %s/$/\=repeat(' foobar', 10)/
2852 20vsp
2853 set wrap
2854 " Test for g$ with count
2855 norm! gg
2856 norm! 0vg$y
2857 call assert_equal(20, col("'>"))
2858 call assert_equal('1 foobar foobar foob', getreg(0))
2859 norm! gg
2860 norm! 0v4g$y
2861 call assert_equal(72, col("'>"))
2862 call assert_equal('1 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar'.."\n", getreg(0))
2863 norm! gg
2864 norm! 0v6g$y
2865 call assert_equal(40, col("'>"))
2866 call assert_equal('1 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar'.. "\n"..
2867 \ '2 foobar foobar foobar foobar foobar foo', getreg(0))
2868 set nowrap
2869 " clean up
2870 norm! gg
2871 norm! 0vg$y
2872 call assert_equal(20, col("'>"))
2873 call assert_equal('1 foobar foobar foob', getreg(0))
2874 norm! gg
2875 norm! 0v4g$y
2876 call assert_equal(20, col("'>"))
2877 call assert_equal('1 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar'.. "\n"..
2878 \ '2 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar'.. "\n"..
2879 \ '3 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar'.. "\n"..
2880 \ '4 foobar foobar foob', getreg(0))
2881 norm! gg
2882 norm! 0v6g$y
2883 call assert_equal(20, col("'>"))
2884 call assert_equal('1 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar'.. "\n"..
2885 \ '2 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar'.. "\n"..
2886 \ '3 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar'.. "\n"..
2887 \ '4 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar'.. "\n"..
2888 \ '5 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar'.. "\n"..
2889 \ '6 foobar foobar foob', getreg(0))
2890 " Move to last line, also down movement is not possible, should still move
2891 " the cursor to the last visible char
2892 norm! G
2893 norm! 0v6g$y
2894 call assert_equal(20, col("'>"))
2895 call assert_equal('100 foobar foobar fo', getreg(0))
2896 bw!
2897endfunc
Bram Moolenaar03ac52f2019-09-24 22:47:46 +02002898
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01002899func Test_normal_gk_gj()
Bram Moolenaar03ac52f2019-09-24 22:47:46 +02002900 " needs 80 column new window
2901 new
2902 vert 80new
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01002903 call assert_beeps('normal gk')
Bram Moolenaar03ac52f2019-09-24 22:47:46 +02002904 put =[repeat('x',90)..' {{{1', 'x {{{1']
2905 norm! gk
2906 " In a 80 column wide terminal the window will be only 78 char
2907 " (because Vim will leave space for the other window),
2908 " but if the terminal is larger, it will be 80 chars, so verify the
2909 " cursor column correctly.
2910 call assert_equal(winwidth(0)+1, col('.'))
2911 call assert_equal(winwidth(0)+1, virtcol('.'))
2912 norm! j
2913 call assert_equal(6, col('.'))
2914 call assert_equal(6, virtcol('.'))
2915 norm! gk
2916 call assert_equal(95, col('.'))
2917 call assert_equal(95, virtcol('.'))
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01002918 %bw!
Bram Moolenaarceba3dd2019-10-12 16:12:54 +02002919
2920 " needs 80 column new window
2921 new
2922 vert 80new
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01002923 call assert_beeps('normal gj')
Bram Moolenaarceba3dd2019-10-12 16:12:54 +02002924 set number
2925 set numberwidth=10
2926 set cpoptions+=n
2927 put =[repeat('0',90), repeat('1',90)]
2928 norm! 075l
2929 call assert_equal(76, col('.'))
2930 norm! gk
2931 call assert_equal(1, col('.'))
2932 norm! gk
2933 call assert_equal(76, col('.'))
2934 norm! gk
2935 call assert_equal(1, col('.'))
2936 norm! gj
2937 call assert_equal(76, col('.'))
2938 norm! gj
2939 call assert_equal(1, col('.'))
2940 norm! gj
2941 call assert_equal(76, col('.'))
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01002942 " When 'nowrap' is set, gk and gj behave like k and j
2943 set nowrap
2944 normal! gk
2945 call assert_equal([2, 76], [line('.'), col('.')])
2946 normal! gj
2947 call assert_equal([3, 76], [line('.'), col('.')])
2948 %bw!
2949 set cpoptions& number& numberwidth& wrap&
Bram Moolenaar03ac52f2019-09-24 22:47:46 +02002950endfunc
Bram Moolenaarf0cee192020-02-16 13:33:56 +01002951
2952" Test for cursor movement with '-' in 'cpoptions'
2953func Test_normal_cpo_minus()
2954 new
2955 call setline(1, ['foo', 'bar', 'baz'])
2956 let save_cpo = &cpo
2957 set cpo+=-
2958 call assert_beeps('normal 10j')
2959 call assert_equal(1, line('.'))
2960 normal G
2961 call assert_beeps('normal 10k')
2962 call assert_equal(3, line('.'))
2963 call assert_fails(10, 'E16:')
2964 let &cpo = save_cpo
2965 close!
2966endfunc
Bram Moolenaar818fc9a2020-02-21 17:54:45 +01002967
2968" Test for using : to run a multi-line Ex command in operator pending mode
2969func Test_normal_yank_with_excmd()
2970 new
2971 call setline(1, ['foo', 'bar', 'baz'])
2972 let @a = ''
2973 call feedkeys("\"ay:if v:true\<CR>normal l\<CR>endif\<CR>", 'xt')
2974 call assert_equal('f', @a)
2975 close!
2976endfunc
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01002977
2978" Test for supplying a count to a normal-mode command across a cursorhold call
2979func Test_normal_cursorhold_with_count()
2980 func s:cHold()
2981 let g:cHold_Called += 1
2982 endfunc
2983 new
2984 augroup normalcHoldTest
2985 au!
2986 au CursorHold <buffer> call s:cHold()
2987 augroup END
2988 let g:cHold_Called = 0
2989 call feedkeys("3\<CursorHold>2ix", 'xt')
2990 call assert_equal(1, g:cHold_Called)
2991 call assert_equal(repeat('x', 32), getline(1))
2992 augroup normalcHoldTest
2993 au!
2994 augroup END
2995 au! normalcHoldTest
2996 close!
2997 delfunc s:cHold
2998endfunc
2999
3000" Test for using a count and a command with CTRL-W
3001func Test_wincmd_with_count()
3002 call feedkeys("\<C-W>12n", 'xt')
3003 call assert_equal(12, winheight(0))
3004endfunc
3005
3006" Test for 'b', 'B' 'ge' and 'gE' commands
Bram Moolenaar1671f442020-03-10 07:48:13 +01003007func Test_horiz_motion()
3008 new
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01003009 normal! gg
3010 call assert_beeps('normal! b')
3011 call assert_beeps('normal! B')
3012 call assert_beeps('normal! gE')
3013 call assert_beeps('normal! ge')
Bram Moolenaar1671f442020-03-10 07:48:13 +01003014 " <S-Backspace> moves one word left and <C-Backspace> moves one WORD left
3015 call setline(1, 'one ,two ,three')
3016 exe "normal! $\<S-BS>"
3017 call assert_equal(11, col('.'))
3018 exe "normal! $\<C-BS>"
3019 call assert_equal(10, col('.'))
3020 close!
3021endfunc
3022
3023" Test for using a : command in operator pending mode
3024func Test_normal_colon_op()
3025 new
3026 call setline(1, ['one', 'two'])
3027 call assert_beeps("normal! Gc:d\<CR>")
3028 close!
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01003029endfunc
3030
3031" vim: shiftwidth=2 sts=2 expandtab