blob: 68aae534eb922901752fa8dfee75f767b20b5dff [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 Moolenaarca68ae12020-03-30 19:32:53 +02005source view_util.vim
Bram Moolenaara84a3dd2019-03-25 22:21:24 +01006
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01007func Setup_NewWindow()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02008 10new
9 call setline(1, range(1,100))
10endfunc
11
Bram Moolenaar1bbb6192018-11-10 16:02:01 +010012func MyFormatExpr()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +020013 " Adds '->$' at lines having numbers followed by trailing whitespace
14 for ln in range(v:lnum, v:lnum+v:count-1)
15 let line = getline(ln)
16 if getline(ln) =~# '\d\s\+$'
17 call setline(ln, substitute(line, '\s\+$', '', '') . '->$')
18 endif
19 endfor
Bram Moolenaar2931f2a2016-09-09 16:59:08 +020020endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +020021
Bram Moolenaar1bbb6192018-11-10 16:02:01 +010022func CountSpaces(type, ...)
Bram Moolenaar87bc3f72016-09-03 17:33:54 +020023 " for testing operatorfunc
24 " will count the number of spaces
25 " and return the result in g:a
26 let sel_save = &selection
27 let &selection = "inclusive"
28 let reg_save = @@
29
30 if a:0 " Invoked from Visual mode, use gv command.
31 silent exe "normal! gvy"
32 elseif a:type == 'line'
33 silent exe "normal! '[V']y"
34 else
35 silent exe "normal! `[v`]y"
36 endif
37 let g:a=strlen(substitute(@@, '[^ ]', '', 'g'))
38 let &selection = sel_save
39 let @@ = reg_save
Bram Moolenaar2931f2a2016-09-09 16:59:08 +020040endfunc
41
Bram Moolenaar1bbb6192018-11-10 16:02:01 +010042func OpfuncDummy(type, ...)
Bram Moolenaar4a08b0d2016-11-05 21:55:13 +010043 " for testing operatorfunc
44 let g:opt=&linebreak
45
46 if a:0 " Invoked from Visual mode, use gv command.
47 silent exe "normal! gvy"
48 elseif a:type == 'line'
49 silent exe "normal! '[V']y"
50 else
51 silent exe "normal! `[v`]y"
52 endif
53 " Create a new dummy window
54 new
55 let g:bufnr=bufnr('%')
Bram Moolenaar2931f2a2016-09-09 16:59:08 +020056endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +020057
Bram Moolenaar1671f442020-03-10 07:48:13 +010058func Test_normal00_optrans()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +020059 new
60 call append(0, ['1 This is a simple test: abcd', '2 This is the second line', '3 this is the third line'])
61 1
62 exe "norm! Sfoobar\<esc>"
63 call assert_equal(['foobar', '2 This is the second line', '3 this is the third line', ''], getline(1,'$'))
64 2
Bram Moolenaar87bc3f72016-09-03 17:33:54 +020065 exe "norm! $vbsone"
66 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 +020067 norm! VS Second line here
68 call assert_equal(['foobar', ' Second line here', '3 this is the third line', ''], getline(1, '$'))
69 %d
70 call append(0, ['4 This is a simple test: abcd', '5 This is the second line', '6 this is the third line'])
71 call append(0, ['1 This is a simple test: abcd', '2 This is the second line', '3 this is the third line'])
72
73 1
74 norm! 2D
75 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,'$'))
76 set cpo+=#
77 norm! 4D
78 call assert_equal(['', '4 This is a simple test: abcd', '5 This is the second line', '6 this is the third line', ''], getline(1,'$'))
79
80 " clean up
81 set cpo-=#
82 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +020083endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +020084
Bram Moolenaar1bbb6192018-11-10 16:02:01 +010085func Test_normal01_keymodel()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +020086 call Setup_NewWindow()
87 " Test 1: depending on 'keymodel' <s-down> does something different
Bram Moolenaar2931f2a2016-09-09 16:59:08 +020088 50
Bram Moolenaar87bc3f72016-09-03 17:33:54 +020089 call feedkeys("V\<S-Up>y", 'tx')
90 call assert_equal(['47', '48', '49', '50'], getline("'<", "'>"))
Bram Moolenaar2931f2a2016-09-09 16:59:08 +020091 set keymodel=startsel
92 50
Bram Moolenaar87bc3f72016-09-03 17:33:54 +020093 call feedkeys("V\<S-Up>y", 'tx')
94 call assert_equal(['49', '50'], getline("'<", "'>"))
95 " Start visual mode when keymodel = startsel
Bram Moolenaar2931f2a2016-09-09 16:59:08 +020096 50
Bram Moolenaar87bc3f72016-09-03 17:33:54 +020097 call feedkeys("\<S-Up>y", 'tx')
98 call assert_equal(['49', '5'], getreg(0, 0, 1))
Bram Moolenaar1671f442020-03-10 07:48:13 +010099 " Use the different Shift special keys
100 50
101 call feedkeys("\<S-Right>\<S-Left>\<S-Up>\<S-Down>\<S-Home>\<S-End>y", 'tx')
102 call assert_equal(['50'], getline("'<", "'>"))
103 call assert_equal(['50', ''], getreg(0, 0, 1))
104
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200105 " Do not start visual mode when keymodel=
Bram Moolenaar2931f2a2016-09-09 16:59:08 +0200106 set keymodel=
107 50
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200108 call feedkeys("\<S-Up>y$", 'tx')
109 call assert_equal(['42'], getreg(0, 0, 1))
Bram Moolenaar2931f2a2016-09-09 16:59:08 +0200110 " Stop visual mode when keymodel=stopsel
111 set keymodel=stopsel
112 50
113 call feedkeys("Vkk\<Up>yy", 'tx')
114 call assert_equal(['47'], getreg(0, 0, 1))
115
116 set keymodel=
117 50
118 call feedkeys("Vkk\<Up>yy", 'tx')
119 call assert_equal(['47', '48', '49', '50'], getreg(0, 0, 1))
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200120
121 " clean up
122 bw!
123endfunc
124
Bram Moolenaar1bbb6192018-11-10 16:02:01 +0100125func Test_normal03_join()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200126 " basic join test
127 call Setup_NewWindow()
128 50
129 norm! VJ
130 call assert_equal('50 51', getline('.'))
131 $
132 norm! J
133 call assert_equal('100', getline('.'))
134 $
135 norm! V9-gJ
136 call assert_equal('919293949596979899100', getline('.'))
137 call setline(1, range(1,100))
138 $
139 :j 10
140 call assert_equal('100', getline('.'))
Bram Moolenaar004a6782020-04-11 17:09:31 +0200141 call assert_beeps('normal GVJ')
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200142 " clean up
143 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +0200144endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200145
Bram Moolenaar004a6782020-04-11 17:09:31 +0200146" basic filter test
Bram Moolenaar1bbb6192018-11-10 16:02:01 +0100147func Test_normal04_filter()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200148 " only test on non windows platform
Bram Moolenaar004a6782020-04-11 17:09:31 +0200149 CheckNotMSWindows
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200150 call Setup_NewWindow()
151 1
152 call feedkeys("!!sed -e 's/^/| /'\n", 'tx')
153 call assert_equal('| 1', getline('.'))
154 90
155 :sil :!echo one
156 call feedkeys('.', 'tx')
157 call assert_equal('| 90', getline('.'))
158 95
159 set cpo+=!
160 " 2 <CR>, 1: for executing the command,
161 " 2: clear hit-enter-prompt
162 call feedkeys("!!\n", 'tx')
163 call feedkeys(":!echo one\n\n", 'tx')
164 call feedkeys(".", 'tx')
165 call assert_equal('one', getline('.'))
166 set cpo-=!
167 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +0200168endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200169
Bram Moolenaar1bbb6192018-11-10 16:02:01 +0100170func Test_normal05_formatexpr()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200171 " basic formatexpr test
172 call Setup_NewWindow()
173 %d_
174 call setline(1, ['here: 1 ', '2', 'here: 3 ', '4', 'not here: '])
175 1
176 set formatexpr=MyFormatExpr()
177 norm! gqG
178 call assert_equal(['here: 1->$', '2', 'here: 3->$', '4', 'not here: '], getline(1,'$'))
179 set formatexpr=
180 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +0200181endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200182
Bram Moolenaard77f9d52016-09-04 15:13:39 +0200183func Test_normal05_formatexpr_newbuf()
184 " Edit another buffer in the 'formatexpr' function
185 new
186 func! Format()
187 edit another
188 endfunc
189 set formatexpr=Format()
190 norm gqG
191 bw!
192 set formatexpr=
193endfunc
194
195func Test_normal05_formatexpr_setopt()
196 " Change the 'formatexpr' value in the function
197 new
198 func! Format()
199 set formatexpr=
200 endfunc
201 set formatexpr=Format()
202 norm gqG
203 bw!
204 set formatexpr=
205endfunc
206
Bram Moolenaar2eaeaf32020-05-03 16:04:43 +0200207" When 'formatexpr' returns non-zero, internal formatting is used.
208func Test_normal_formatexpr_returns_nonzero()
209 new
210 call setline(1, ['one', 'two'])
211 func! Format()
212 return 1
213 endfunc
214 setlocal formatexpr=Format()
215 normal VGgq
216 call assert_equal(['one two'], getline(1, '$'))
217 setlocal formatexpr=
218 delfunc Format
219 close!
220endfunc
221
Bram Moolenaar004a6782020-04-11 17:09:31 +0200222" basic test for formatprg
Bram Moolenaar1bbb6192018-11-10 16:02:01 +0100223func Test_normal06_formatprg()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200224 " only test on non windows platform
Bram Moolenaar004a6782020-04-11 17:09:31 +0200225 CheckNotMSWindows
Bram Moolenaar9be7c042017-01-14 14:28:30 +0100226
227 " uses sed to number non-empty lines
228 call writefile(['#!/bin/sh', 'sed ''/./=''|sed ''/./{', 'N', 's/\n/ /', '}'''], 'Xsed_format.sh')
229 call system('chmod +x ./Xsed_format.sh')
230 let text = ['a', '', 'c', '', ' ', 'd', 'e']
231 let expected = ['1 a', '', '3 c', '', '5 ', '6 d', '7 e']
232
233 10new
234 call setline(1, text)
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200235 set formatprg=./Xsed_format.sh
236 norm! gggqG
Bram Moolenaar9be7c042017-01-14 14:28:30 +0100237 call assert_equal(expected, getline(1, '$'))
Bram Moolenaar004a6782020-04-11 17:09:31 +0200238 %d
Bram Moolenaar9be7c042017-01-14 14:28:30 +0100239
Bram Moolenaar9be7c042017-01-14 14:28:30 +0100240 call setline(1, text)
241 set formatprg=donothing
242 setlocal formatprg=./Xsed_format.sh
243 norm! gggqG
244 call assert_equal(expected, getline(1, '$'))
Bram Moolenaar004a6782020-04-11 17:09:31 +0200245 %d
Bram Moolenaar9be7c042017-01-14 14:28:30 +0100246
Bram Moolenaar004a6782020-04-11 17:09:31 +0200247 " Check for the command-line ranges added to 'formatprg'
248 set formatprg=cat
249 call setline(1, ['one', 'two', 'three', 'four', 'five'])
250 call feedkeys('gggqG', 'xt')
251 call assert_equal('.,$!cat', @:)
252 call feedkeys('2Ggq2j', 'xt')
253 call assert_equal('.,.+2!cat', @:)
254
255 bw!
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200256 " clean up
257 set formatprg=
Bram Moolenaar9be7c042017-01-14 14:28:30 +0100258 setlocal formatprg=
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200259 call delete('Xsed_format.sh')
Bram Moolenaar2931f2a2016-09-09 16:59:08 +0200260endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200261
Bram Moolenaar1bbb6192018-11-10 16:02:01 +0100262func Test_normal07_internalfmt()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200263 " basic test for internal formmatter to textwidth of 12
264 let list=range(1,11)
265 call map(list, 'v:val." "')
266 10new
267 call setline(1, list)
268 set tw=12
Bram Moolenaar004a6782020-04-11 17:09:31 +0200269 norm! ggVGgq
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200270 call assert_equal(['1 2 3', '4 5 6', '7 8 9', '10 11 '], getline(1, '$'))
271 " clean up
Bram Moolenaar9be7c042017-01-14 14:28:30 +0100272 set tw=0
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200273 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +0200274endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200275
Bram Moolenaar004a6782020-04-11 17:09:31 +0200276" basic tests for foldopen/folddelete
Bram Moolenaar1bbb6192018-11-10 16:02:01 +0100277func Test_normal08_fold()
Bram Moolenaar004a6782020-04-11 17:09:31 +0200278 CheckFeature folding
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200279 call Setup_NewWindow()
280 50
281 setl foldenable fdm=marker
282 " First fold
283 norm! V4jzf
284 " check that folds have been created
285 call assert_equal(['50/*{{{*/', '51', '52', '53', '54/*}}}*/'], getline(50,54))
286 " Second fold
287 46
288 norm! V10jzf
289 " check that folds have been created
290 call assert_equal('46/*{{{*/', getline(46))
291 call assert_equal('60/*}}}*/', getline(60))
292 norm! k
293 call assert_equal('45', getline('.'))
294 norm! j
295 call assert_equal('46/*{{{*/', getline('.'))
296 norm! j
297 call assert_equal('61', getline('.'))
298 norm! k
299 " open a fold
300 norm! Vzo
301 norm! k
302 call assert_equal('45', getline('.'))
303 norm! j
304 call assert_equal('46/*{{{*/', getline('.'))
305 norm! j
306 call assert_equal('47', getline('.'))
307 norm! k
308 norm! zcVzO
309 call assert_equal('46/*{{{*/', getline('.'))
310 norm! j
311 call assert_equal('47', getline('.'))
312 norm! j
313 call assert_equal('48', getline('.'))
314 norm! j
315 call assert_equal('49', getline('.'))
316 norm! j
317 call assert_equal('50/*{{{*/', getline('.'))
318 norm! j
319 call assert_equal('51', getline('.'))
320 " delete folds
321 :46
322 " collapse fold
323 norm! V14jzC
324 " delete all folds recursively
325 norm! VzD
326 call assert_equal(['46', '47', '48', '49', '50', '51', '52', '53', '54', '55', '56', '57', '58', '59', '60'], getline(46,60))
327
328 " clean up
329 setl nofoldenable fdm=marker
330 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +0200331endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200332
Bram Moolenaar1bbb6192018-11-10 16:02:01 +0100333func Test_normal09_operatorfunc()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200334 " Test operatorfunc
335 call Setup_NewWindow()
336 " Add some spaces for counting
337 50,60s/$/ /
338 unlet! g:a
339 let g:a=0
340 nmap <buffer><silent> ,, :set opfunc=CountSpaces<CR>g@
341 vmap <buffer><silent> ,, :<C-U>call CountSpaces(visualmode(), 1)<CR>
342 50
343 norm V2j,,
344 call assert_equal(6, g:a)
345 norm V,,
346 call assert_equal(2, g:a)
347 norm ,,l
348 call assert_equal(0, g:a)
349 50
350 exe "norm 0\<c-v>10j2l,,"
351 call assert_equal(11, g:a)
352 50
353 norm V10j,,
354 call assert_equal(22, g:a)
355
356 " clean up
357 unmap <buffer> ,,
358 set opfunc=
Bram Moolenaar4a08b0d2016-11-05 21:55:13 +0100359 unlet! g:a
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200360 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +0200361endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200362
Bram Moolenaar1bbb6192018-11-10 16:02:01 +0100363func Test_normal09a_operatorfunc()
Bram Moolenaar4a08b0d2016-11-05 21:55:13 +0100364 " Test operatorfunc
365 call Setup_NewWindow()
366 " Add some spaces for counting
367 50,60s/$/ /
368 unlet! g:opt
369 set linebreak
370 nmap <buffer><silent> ,, :set opfunc=OpfuncDummy<CR>g@
371 50
372 norm ,,j
373 exe "bd!" g:bufnr
374 call assert_true(&linebreak)
375 call assert_equal(g:opt, &linebreak)
376 set nolinebreak
377 norm ,,j
378 exe "bd!" g:bufnr
379 call assert_false(&linebreak)
380 call assert_equal(g:opt, &linebreak)
381
382 " clean up
383 unmap <buffer> ,,
384 set opfunc=
Bram Moolenaaree4e0c12020-04-06 21:35:05 +0200385 call assert_fails('normal Vg@', 'E774:')
Bram Moolenaar4a08b0d2016-11-05 21:55:13 +0100386 bw!
387 unlet! g:opt
388endfunc
389
Bram Moolenaar1bbb6192018-11-10 16:02:01 +0100390func Test_normal10_expand()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200391 " Test for expand()
392 10new
393 call setline(1, ['1', 'ifooar,,cbar'])
394 2
395 norm! $
Bram Moolenaar65f08472017-09-10 18:16:20 +0200396 call assert_equal('cbar', expand('<cword>'))
397 call assert_equal('ifooar,,cbar', expand('<cWORD>'))
398
399 call setline(1, ['prx = list[idx];'])
400 1
401 let expected = ['', 'prx', 'prx', 'prx',
402 \ 'list', 'list', 'list', 'list', 'list', 'list', 'list',
403 \ 'idx', 'idx', 'idx', 'idx',
404 \ 'list[idx]',
405 \ '];',
406 \ ]
407 for i in range(1, 16)
408 exe 'norm ' . i . '|'
409 call assert_equal(expected[i], expand('<cexpr>'), 'i == ' . i)
410 endfor
411
Bram Moolenaarae6f8652017-12-20 22:32:20 +0100412 if executable('echo')
413 " Test expand(`...`) i.e. backticks command expansion.
Bram Moolenaar077ff432019-10-28 00:42:21 +0100414 call assert_equal('abcde', expand('`echo abcde`'))
Bram Moolenaarae6f8652017-12-20 22:32:20 +0100415 endif
416
417 " Test expand(`=...`) i.e. backticks expression expansion
418 call assert_equal('5', expand('`=2+3`'))
Bram Moolenaar8b633132020-03-20 18:20:51 +0100419 call assert_equal('3.14', expand('`=3.14`'))
Bram Moolenaarae6f8652017-12-20 22:32:20 +0100420
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200421 " clean up
422 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +0200423endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200424
Bram Moolenaar1bbb6192018-11-10 16:02:01 +0100425func Test_normal11_showcmd()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200426 " test for 'showcmd'
427 10new
428 exe "norm! ofoobar\<esc>"
429 call assert_equal(2, line('$'))
430 set showcmd
431 exe "norm! ofoobar2\<esc>"
432 call assert_equal(3, line('$'))
433 exe "norm! VAfoobar3\<esc>"
434 call assert_equal(3, line('$'))
435 exe "norm! 0d3\<del>2l"
436 call assert_equal('obar2foobar3', getline('.'))
437 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +0200438endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200439
Bram Moolenaar1671f442020-03-10 07:48:13 +0100440" Test for nv_error and normal command errors
Bram Moolenaar1bbb6192018-11-10 16:02:01 +0100441func Test_normal12_nv_error()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200442 10new
443 call setline(1, range(1,5))
444 " should not do anything, just beep
Bram Moolenaarf5f1e102020-03-08 05:13:15 +0100445 call assert_beeps('exe "norm! <c-k>"')
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200446 call assert_equal(map(range(1,5), 'string(v:val)'), getline(1,'$'))
Bram Moolenaarf5f1e102020-03-08 05:13:15 +0100447 call assert_beeps('normal! G2dd')
448 call assert_beeps("normal! g\<C-A>")
449 call assert_beeps("normal! g\<C-X>")
450 call assert_beeps("normal! g\<C-B>")
Bram Moolenaar1671f442020-03-10 07:48:13 +0100451 call assert_beeps("normal! vQ\<Esc>")
452 call assert_beeps("normal! 2[[")
453 call assert_beeps("normal! 2]]")
454 call assert_beeps("normal! 2[]")
455 call assert_beeps("normal! 2][")
456 call assert_beeps("normal! 4[z")
457 call assert_beeps("normal! 4]z")
458 call assert_beeps("normal! 4[c")
459 call assert_beeps("normal! 4]c")
460 call assert_beeps("normal! 200%")
461 call assert_beeps("normal! %")
462 call assert_beeps("normal! 2{")
463 call assert_beeps("normal! 2}")
464 call assert_beeps("normal! r\<Right>")
465 call assert_beeps("normal! 8ry")
466 call assert_beeps('normal! "@')
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200467 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +0200468endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200469
Bram Moolenaar1bbb6192018-11-10 16:02:01 +0100470func Test_normal13_help()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200471 " Test for F1
472 call assert_equal(1, winnr())
473 call feedkeys("\<f1>", 'txi')
474 call assert_match('help\.txt', bufname('%'))
475 call assert_equal(2, winnr('$'))
476 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +0200477endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200478
Bram Moolenaar1bbb6192018-11-10 16:02:01 +0100479func Test_normal14_page()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200480 " basic test for Ctrl-F and Ctrl-B
481 call Setup_NewWindow()
482 exe "norm! \<c-f>"
483 call assert_equal('9', getline('.'))
484 exe "norm! 2\<c-f>"
485 call assert_equal('25', getline('.'))
486 exe "norm! 2\<c-b>"
487 call assert_equal('18', getline('.'))
488 1
489 set scrolloff=5
490 exe "norm! 2\<c-f>"
491 call assert_equal('21', getline('.'))
492 exe "norm! \<c-b>"
493 call assert_equal('13', getline('.'))
494 1
495 set scrolloff=99
496 exe "norm! \<c-f>"
497 call assert_equal('13', getline('.'))
498 set scrolloff=0
499 100
500 exe "norm! $\<c-b>"
501 call assert_equal('92', getline('.'))
502 call assert_equal([0, 92, 1, 0, 1], getcurpos())
503 100
504 set nostartofline
505 exe "norm! $\<c-b>"
506 call assert_equal('92', getline('.'))
507 call assert_equal([0, 92, 2, 0, 2147483647], getcurpos())
508 " cleanup
509 set startofline
510 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +0200511endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200512
Bram Moolenaar1bbb6192018-11-10 16:02:01 +0100513func Test_normal14_page_eol()
Bram Moolenaarbc54f3f2016-09-04 14:34:28 +0200514 10new
515 norm oxxxxxxx
516 exe "norm 2\<c-f>"
517 " check with valgrind that cursor is put back in column 1
518 exe "norm 2\<c-b>"
519 bw!
520endfunc
521
Bram Moolenaar1671f442020-03-10 07:48:13 +0100522" Test for errors with z command
523func Test_normal_z_error()
524 call assert_beeps('normal! z2p')
525 call assert_beeps('normal! zp')
526endfunc
527
Bram Moolenaar1bbb6192018-11-10 16:02:01 +0100528func Test_normal15_z_scroll_vert()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200529 " basic test for z commands that scroll the window
530 call Setup_NewWindow()
531 100
532 norm! >>
533 " Test for z<cr>
534 exe "norm! z\<cr>"
535 call assert_equal(' 100', getline('.'))
536 call assert_equal(100, winsaveview()['topline'])
537 call assert_equal([0, 100, 2, 0, 9], getcurpos())
538
539 " Test for zt
540 21
541 norm! >>0zt
542 call assert_equal(' 21', getline('.'))
543 call assert_equal(21, winsaveview()['topline'])
544 call assert_equal([0, 21, 1, 0, 8], getcurpos())
545
546 " Test for zb
547 30
548 norm! >>$ztzb
549 call assert_equal(' 30', getline('.'))
550 call assert_equal(30, winsaveview()['topline']+winheight(0)-1)
551 call assert_equal([0, 30, 3, 0, 2147483647], getcurpos())
552
553 " Test for z-
554 1
555 30
556 norm! 0z-
557 call assert_equal(' 30', getline('.'))
558 call assert_equal(30, winsaveview()['topline']+winheight(0)-1)
559 call assert_equal([0, 30, 2, 0, 9], getcurpos())
560
561 " Test for z{height}<cr>
562 call assert_equal(10, winheight(0))
563 exe "norm! z12\<cr>"
564 call assert_equal(12, winheight(0))
565 exe "norm! z10\<cr>"
566 call assert_equal(10, winheight(0))
567
568 " Test for z.
569 1
570 21
571 norm! 0z.
572 call assert_equal(' 21', getline('.'))
573 call assert_equal(17, winsaveview()['topline'])
574 call assert_equal([0, 21, 2, 0, 9], getcurpos())
575
576 " Test for zz
577 1
578 21
579 norm! 0zz
580 call assert_equal(' 21', getline('.'))
581 call assert_equal(17, winsaveview()['topline'])
582 call assert_equal([0, 21, 1, 0, 8], getcurpos())
583
584 " Test for z+
585 11
586 norm! zt
587 norm! z+
588 call assert_equal(' 21', getline('.'))
589 call assert_equal(21, winsaveview()['topline'])
590 call assert_equal([0, 21, 2, 0, 9], getcurpos())
591
592 " Test for [count]z+
593 1
594 norm! 21z+
595 call assert_equal(' 21', getline('.'))
596 call assert_equal(21, winsaveview()['topline'])
597 call assert_equal([0, 21, 2, 0, 9], getcurpos())
598
599 " Test for z^
600 norm! 22z+0
601 norm! z^
602 call assert_equal(' 21', getline('.'))
603 call assert_equal(12, winsaveview()['topline'])
604 call assert_equal([0, 21, 2, 0, 9], getcurpos())
605
606 " Test for [count]z^
607 1
608 norm! 30z^
609 call assert_equal(' 21', getline('.'))
610 call assert_equal(12, winsaveview()['topline'])
611 call assert_equal([0, 21, 2, 0, 9], getcurpos())
612
613 " cleanup
614 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +0200615endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200616
Bram Moolenaar1bbb6192018-11-10 16:02:01 +0100617func Test_normal16_z_scroll_hor()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200618 " basic test for z commands that scroll the window
619 10new
620 15vsp
621 set nowrap listchars=
622 let lineA='abcdefghijklmnopqrstuvwxyz'
623 let lineB='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'
624 $put =lineA
625 $put =lineB
626 1d
627
Bram Moolenaar1671f442020-03-10 07:48:13 +0100628 " Test for zl and zh with a count
629 norm! 0z10l
630 call assert_equal([11, 1], [col('.'), wincol()])
631 norm! z4h
632 call assert_equal([11, 5], [col('.'), wincol()])
633 normal! 2gg
634
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200635 " Test for zl
636 1
637 norm! 5zl
638 call assert_equal(lineA, getline('.'))
639 call assert_equal(6, col('.'))
640 call assert_equal(5, winsaveview()['leftcol'])
641 norm! yl
642 call assert_equal('f', @0)
643
644 " Test for zh
645 norm! 2zh
646 call assert_equal(lineA, getline('.'))
647 call assert_equal(6, col('.'))
648 norm! yl
649 call assert_equal('f', @0)
650 call assert_equal(3, winsaveview()['leftcol'])
651
652 " Test for zL
653 norm! zL
654 call assert_equal(11, col('.'))
655 norm! yl
656 call assert_equal('k', @0)
657 call assert_equal(10, winsaveview()['leftcol'])
658 norm! 2zL
659 call assert_equal(25, col('.'))
660 norm! yl
661 call assert_equal('y', @0)
662 call assert_equal(24, winsaveview()['leftcol'])
663
664 " Test for zH
665 norm! 2zH
666 call assert_equal(25, col('.'))
667 call assert_equal(10, winsaveview()['leftcol'])
668 norm! yl
669 call assert_equal('y', @0)
670
671 " Test for zs
672 norm! $zs
673 call assert_equal(26, col('.'))
674 call assert_equal(25, winsaveview()['leftcol'])
675 norm! yl
676 call assert_equal('z', @0)
677
678 " Test for ze
679 norm! ze
680 call assert_equal(26, col('.'))
681 call assert_equal(11, winsaveview()['leftcol'])
682 norm! yl
683 call assert_equal('z', @0)
684
685 " cleanup
686 set wrap listchars=eol:$
687 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +0200688endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200689
Bram Moolenaar1bbb6192018-11-10 16:02:01 +0100690func Test_normal17_z_scroll_hor2()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200691 " basic test for z commands that scroll the window
692 " using 'sidescrolloff' setting
693 10new
694 20vsp
695 set nowrap listchars= sidescrolloff=5
696 let lineA='abcdefghijklmnopqrstuvwxyz'
697 let lineB='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'
698 $put =lineA
699 $put =lineB
700 1d
701
702 " Test for zl
703 1
704 norm! 5zl
705 call assert_equal(lineA, getline('.'))
706 call assert_equal(11, col('.'))
707 call assert_equal(5, winsaveview()['leftcol'])
708 norm! yl
709 call assert_equal('k', @0)
710
711 " Test for zh
712 norm! 2zh
713 call assert_equal(lineA, getline('.'))
714 call assert_equal(11, col('.'))
715 norm! yl
716 call assert_equal('k', @0)
717 call assert_equal(3, winsaveview()['leftcol'])
718
719 " Test for zL
720 norm! 0zL
721 call assert_equal(16, col('.'))
722 norm! yl
723 call assert_equal('p', @0)
724 call assert_equal(10, winsaveview()['leftcol'])
725 norm! 2zL
726 call assert_equal(26, col('.'))
727 norm! yl
728 call assert_equal('z', @0)
729 call assert_equal(15, winsaveview()['leftcol'])
730
731 " Test for zH
732 norm! 2zH
733 call assert_equal(15, col('.'))
734 call assert_equal(0, winsaveview()['leftcol'])
735 norm! yl
736 call assert_equal('o', @0)
737
738 " Test for zs
739 norm! $zs
740 call assert_equal(26, col('.'))
741 call assert_equal(20, winsaveview()['leftcol'])
742 norm! yl
743 call assert_equal('z', @0)
744
745 " Test for ze
746 norm! ze
747 call assert_equal(26, col('.'))
748 call assert_equal(11, winsaveview()['leftcol'])
749 norm! yl
750 call assert_equal('z', @0)
751
752 " cleanup
753 set wrap listchars=eol:$ sidescrolloff=0
754 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +0200755endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200756
Bram Moolenaarbdd2c292020-06-22 21:34:30 +0200757" Test for commands that scroll the window horizontally. Test with folds.
758" H, M, L, CTRL-E, CTRL-Y, CTRL-U, CTRL-D, PageUp, PageDown commands
759func Test_vert_scroll_cmds()
Bram Moolenaar1671f442020-03-10 07:48:13 +0100760 15new
761 call setline(1, range(1, 100))
762 exe "normal! 30ggz\<CR>"
763 set foldenable
764 33,36fold
765 40,43fold
766 46,49fold
767 let h = winheight(0)
Bram Moolenaarbdd2c292020-06-22 21:34:30 +0200768
769 " Test for H, M and L commands
Bram Moolenaar1671f442020-03-10 07:48:13 +0100770 " Top of the screen = 30
771 " Folded lines = 9
772 " Bottom of the screen = 30 + h + 9 - 1
773 normal! 4L
774 call assert_equal(35 + h, line('.'))
775 normal! 4H
776 call assert_equal(33, line('.'))
Bram Moolenaarbdd2c292020-06-22 21:34:30 +0200777
778 " Test for the CTRL-E and CTRL-Y commands with folds
779 %d
780 call setline(1, range(1, 10))
781 3,5fold
782 exe "normal 6G3\<C-E>"
783 call assert_equal(6, line('w0'))
784 exe "normal 2\<C-Y>"
785 call assert_equal(2, line('w0'))
786
787 " Test for CTRL-Y on a folded line
788 %d
789 call setline(1, range(1, 100))
790 exe (h + 2) .. "," .. (h + 4) .. "fold"
791 exe h + 5
792 normal z-
793 exe "normal \<C-Y>\<C-Y>"
794 call assert_equal(h + 1, line('w$'))
795
796 " Using <PageUp> and <PageDown> in an empty buffer should beep
797 %d
798 call assert_beeps('exe "normal \<PageUp>"')
799 call assert_beeps('exe "normal \<C-B>"')
800 call assert_beeps('exe "normal \<PageDown>"')
801 call assert_beeps('exe "normal \<C-F>"')
802
803 " Test for <C-U> and <C-D> with fold
804 %d
805 call setline(1, range(1, 100))
806 10,35fold
807 set scroll=10
808 exe "normal \<C-D>"
809 call assert_equal(36, line('.'))
810 exe "normal \<C-D>"
811 call assert_equal(46, line('.'))
812 exe "normal \<C-U>"
813 call assert_equal(36, line('.'))
814 exe "normal \<C-U>"
815 call assert_equal(10, line('.'))
816 exe "normal \<C-U>"
817 call assert_equal(1, line('.'))
818 set scroll&
819
820 " Test for scrolling to the top of the file with <C-U> and a fold
821 10
822 normal ztL
823 exe "normal \<C-U>\<C-U>"
824 call assert_equal(1, line('w0'))
825
826 " Test for CTRL-D on a folded line
827 %d
828 call setline(1, range(1, 100))
829 50,100fold
830 75
831 normal z-
832 exe "normal \<C-D>"
833 call assert_equal(50, line('.'))
834 call assert_equal(100, line('w$'))
835 normal z.
836 let lnum = winline()
837 exe "normal \<C-D>"
838 call assert_equal(lnum, winline())
839 call assert_equal(50, line('.'))
840 normal zt
841 exe "normal \<C-D>"
842 call assert_equal(50, line('w0'))
843
Bram Moolenaar1671f442020-03-10 07:48:13 +0100844 set foldenable&
845 close!
846endfunc
847
Bram Moolenaarbdd2c292020-06-22 21:34:30 +0200848" Test for the 'sidescroll' option
849func Test_sidescroll_opt()
850 new
851 20vnew
852
853 " scroll by 2 characters horizontally
854 set sidescroll=2 nowrap
855 call setline(1, repeat('a', 40))
856 normal g$l
857 call assert_equal(19, screenpos(0, 1, 21).col)
858 normal l
859 call assert_equal(20, screenpos(0, 1, 22).col)
860 normal g0h
861 call assert_equal(2, screenpos(0, 1, 2).col)
862 call assert_equal(20, screenpos(0, 1, 20).col)
863
864 " when 'sidescroll' is 0, cursor positioned at the center
865 set sidescroll=0
866 normal g$l
867 call assert_equal(11, screenpos(0, 1, 21).col)
868 normal g0h
869 call assert_equal(10, screenpos(0, 1, 10).col)
870
871 %bw!
872 set wrap& sidescroll&
873endfunc
874
Bram Moolenaar004a6782020-04-11 17:09:31 +0200875" basic tests for foldopen/folddelete
Bram Moolenaar1bbb6192018-11-10 16:02:01 +0100876func Test_normal18_z_fold()
Bram Moolenaar004a6782020-04-11 17:09:31 +0200877 CheckFeature folding
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200878 call Setup_NewWindow()
879 50
880 setl foldenable fdm=marker foldlevel=5
881
Bram Moolenaar1671f442020-03-10 07:48:13 +0100882 call assert_beeps('normal! zj')
883 call assert_beeps('normal! zk')
884
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200885 " Test for zF
886 " First fold
887 norm! 4zF
888 " check that folds have been created
889 call assert_equal(['50/*{{{*/', '51', '52', '53/*}}}*/'], getline(50,53))
890
891 " Test for zd
892 51
893 norm! 2zF
894 call assert_equal(2, foldlevel('.'))
895 norm! kzd
896 call assert_equal(['50', '51/*{{{*/', '52/*}}}*/', '53'], getline(50,53))
897 norm! j
898 call assert_equal(1, foldlevel('.'))
899
900 " Test for zD
901 " also deletes partially selected folds recursively
902 51
903 norm! zF
904 call assert_equal(2, foldlevel('.'))
905 norm! kV2jzD
906 call assert_equal(['50', '51', '52', '53'], getline(50,53))
907
908 " Test for zE
909 85
910 norm! 4zF
911 86
912 norm! 2zF
913 90
914 norm! 4zF
915 call assert_equal(['85/*{{{*/', '86/*{{{*/', '87/*}}}*/', '88/*}}}*/', '89', '90/*{{{*/', '91', '92', '93/*}}}*/'], getline(85,93))
916 norm! zE
917 call assert_equal(['85', '86', '87', '88', '89', '90', '91', '92', '93'], getline(85,93))
918
919 " Test for zn
920 50
921 set foldlevel=0
922 norm! 2zF
923 norm! zn
924 norm! k
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 call assert_equal(0, &foldenable)
933
934 " Test for zN
935 49
936 norm! zN
937 call assert_equal('49', getline('.'))
938 norm! j
939 call assert_equal('50/*{{{*/', getline('.'))
940 norm! j
941 call assert_equal('52', getline('.'))
942 call assert_equal(1, &foldenable)
943
944 " Test for zi
945 norm! zi
946 call assert_equal(0, &foldenable)
947 norm! zi
948 call assert_equal(1, &foldenable)
949 norm! zi
950 call assert_equal(0, &foldenable)
951 norm! zi
952 call assert_equal(1, &foldenable)
953
954 " Test for za
955 50
956 norm! za
957 norm! k
958 call assert_equal('49', getline('.'))
959 norm! j
960 call assert_equal('50/*{{{*/', getline('.'))
961 norm! j
962 call assert_equal('51/*}}}*/', getline('.'))
963 norm! j
964 call assert_equal('52', getline('.'))
965 50
966 norm! za
967 norm! k
968 call assert_equal('49', getline('.'))
969 norm! j
970 call assert_equal('50/*{{{*/', getline('.'))
971 norm! j
972 call assert_equal('52', getline('.'))
973
974 49
975 norm! 5zF
976 norm! k
977 call assert_equal('48', getline('.'))
978 norm! j
979 call assert_equal('49/*{{{*/', getline('.'))
980 norm! j
981 call assert_equal('55', getline('.'))
982 49
983 norm! za
984 call assert_equal('49/*{{{*/', getline('.'))
985 norm! j
986 call assert_equal('50/*{{{*/', getline('.'))
987 norm! j
988 call assert_equal('52', getline('.'))
989 set nofoldenable
990 " close fold and set foldenable
991 norm! za
992 call assert_equal(1, &foldenable)
993
994 50
995 " have to use {count}za to open all folds and make the cursor visible
996 norm! 2za
997 norm! 2k
998 call assert_equal('48', getline('.'))
999 norm! j
1000 call assert_equal('49/*{{{*/', getline('.'))
1001 norm! j
1002 call assert_equal('50/*{{{*/', getline('.'))
1003 norm! j
1004 call assert_equal('51/*}}}*/', getline('.'))
1005 norm! j
1006 call assert_equal('52', getline('.'))
1007
1008 " Test for zA
1009 49
1010 set foldlevel=0
1011 50
1012 norm! zA
1013 norm! 2k
1014 call assert_equal('48', getline('.'))
1015 norm! j
1016 call assert_equal('49/*{{{*/', getline('.'))
1017 norm! j
1018 call assert_equal('50/*{{{*/', getline('.'))
1019 norm! j
1020 call assert_equal('51/*}}}*/', getline('.'))
1021 norm! j
1022 call assert_equal('52', getline('.'))
1023
Bram Moolenaar395b6ba2017-04-07 20:09:51 +02001024 " zA on a opened fold when foldenable is not set
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001025 50
1026 set nofoldenable
1027 norm! zA
1028 call assert_equal(1, &foldenable)
1029 norm! k
1030 call assert_equal('48', getline('.'))
1031 norm! j
1032 call assert_equal('49/*{{{*/', getline('.'))
1033 norm! j
1034 call assert_equal('55', getline('.'))
1035
1036 " Test for zc
1037 norm! zE
1038 50
1039 norm! 2zF
1040 49
1041 norm! 5zF
1042 set nofoldenable
1043 50
1044 " There most likely is a bug somewhere:
1045 " https://groups.google.com/d/msg/vim_dev/v2EkfJ_KQjI/u-Cvv94uCAAJ
1046 " TODO: Should this only close the inner most fold or both folds?
1047 norm! zc
1048 call assert_equal(1, &foldenable)
1049 norm! k
1050 call assert_equal('48', getline('.'))
1051 norm! j
1052 call assert_equal('49/*{{{*/', getline('.'))
1053 norm! j
1054 call assert_equal('55', getline('.'))
1055 set nofoldenable
1056 50
1057 norm! Vjzc
1058 norm! k
1059 call assert_equal('48', getline('.'))
1060 norm! j
1061 call assert_equal('49/*{{{*/', getline('.'))
1062 norm! j
1063 call assert_equal('55', getline('.'))
1064
1065 " Test for zC
1066 set nofoldenable
1067 50
1068 norm! zCk
1069 call assert_equal('48', getline('.'))
1070 norm! j
1071 call assert_equal('49/*{{{*/', getline('.'))
1072 norm! j
1073 call assert_equal('55', getline('.'))
1074
1075 " Test for zx
1076 " 1) close folds at line 49-54
1077 set nofoldenable
1078 48
1079 norm! zx
1080 call assert_equal(1, &foldenable)
1081 norm! j
1082 call assert_equal('49/*{{{*/', getline('.'))
1083 norm! j
1084 call assert_equal('55', getline('.'))
1085
Bram Moolenaar395b6ba2017-04-07 20:09:51 +02001086 " 2) do not close fold under cursor
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001087 51
1088 set nofoldenable
1089 norm! zx
1090 call assert_equal(1, &foldenable)
1091 norm! 3k
1092 call assert_equal('48', getline('.'))
1093 norm! j
1094 call assert_equal('49/*{{{*/', getline('.'))
1095 norm! j
1096 call assert_equal('50/*{{{*/', getline('.'))
1097 norm! j
1098 call assert_equal('51/*}}}*/', getline('.'))
1099 norm! j
1100 call assert_equal('52', getline('.'))
1101 norm! j
1102 call assert_equal('53', getline('.'))
1103 norm! j
1104 call assert_equal('54/*}}}*/', getline('.'))
1105 norm! j
1106 call assert_equal('55', getline('.'))
1107
1108 " 3) close one level of folds
1109 48
1110 set nofoldenable
1111 set foldlevel=1
1112 norm! zx
1113 call assert_equal(1, &foldenable)
1114 call assert_equal('48', getline('.'))
1115 norm! j
1116 call assert_equal('49/*{{{*/', getline('.'))
1117 norm! j
1118 call assert_equal('50/*{{{*/', getline('.'))
1119 norm! j
1120 call assert_equal('52', getline('.'))
1121 norm! j
1122 call assert_equal('53', getline('.'))
1123 norm! j
1124 call assert_equal('54/*}}}*/', getline('.'))
1125 norm! j
1126 call assert_equal('55', getline('.'))
1127
1128 " Test for zX
1129 " Close all folds
1130 set foldlevel=0 nofoldenable
1131 50
1132 norm! zX
1133 call assert_equal(1, &foldenable)
1134 norm! k
1135 call assert_equal('48', getline('.'))
1136 norm! j
1137 call assert_equal('49/*{{{*/', getline('.'))
1138 norm! j
1139 call assert_equal('55', getline('.'))
1140
1141 " Test for zm
1142 50
1143 set nofoldenable foldlevel=2
1144 norm! zm
1145 call assert_equal(1, &foldenable)
1146 call assert_equal(1, &foldlevel)
1147 norm! zm
1148 call assert_equal(0, &foldlevel)
1149 norm! zm
1150 call assert_equal(0, &foldlevel)
1151 norm! k
1152 call assert_equal('48', getline('.'))
1153 norm! j
1154 call assert_equal('49/*{{{*/', getline('.'))
1155 norm! j
1156 call assert_equal('55', getline('.'))
1157
1158 " Test for zM
1159 48
1160 set nofoldenable foldlevel=99
1161 norm! zM
1162 call assert_equal(1, &foldenable)
1163 call assert_equal(0, &foldlevel)
1164 call assert_equal('48', getline('.'))
1165 norm! j
1166 call assert_equal('49/*{{{*/', getline('.'))
1167 norm! j
1168 call assert_equal('55', getline('.'))
1169
1170 " Test for zr
1171 48
1172 set nofoldenable foldlevel=0
1173 norm! zr
1174 call assert_equal(0, &foldenable)
1175 call assert_equal(1, &foldlevel)
1176 set foldlevel=0 foldenable
1177 norm! zr
1178 call assert_equal(1, &foldenable)
1179 call assert_equal(1, &foldlevel)
1180 norm! zr
1181 call assert_equal(2, &foldlevel)
1182 call assert_equal('48', getline('.'))
1183 norm! j
1184 call assert_equal('49/*{{{*/', getline('.'))
1185 norm! j
1186 call assert_equal('50/*{{{*/', getline('.'))
1187 norm! j
1188 call assert_equal('51/*}}}*/', getline('.'))
1189 norm! j
1190 call assert_equal('52', getline('.'))
1191
1192 " Test for zR
1193 48
1194 set nofoldenable foldlevel=0
1195 norm! zR
1196 call assert_equal(0, &foldenable)
1197 call assert_equal(2, &foldlevel)
1198 set foldenable foldlevel=0
1199 norm! zR
1200 call assert_equal(1, &foldenable)
1201 call assert_equal(2, &foldlevel)
1202 call assert_equal('48', getline('.'))
1203 norm! j
1204 call assert_equal('49/*{{{*/', getline('.'))
1205 norm! j
1206 call assert_equal('50/*{{{*/', getline('.'))
1207 norm! j
1208 call assert_equal('51/*}}}*/', getline('.'))
1209 norm! j
1210 call assert_equal('52', getline('.'))
1211 call append(50, ['a /*{{{*/', 'b /*}}}*/'])
1212 48
1213 call assert_equal('48', getline('.'))
1214 norm! j
1215 call assert_equal('49/*{{{*/', getline('.'))
1216 norm! j
1217 call assert_equal('50/*{{{*/', getline('.'))
1218 norm! j
1219 call assert_equal('a /*{{{*/', getline('.'))
1220 norm! j
1221 call assert_equal('51/*}}}*/', getline('.'))
1222 norm! j
1223 call assert_equal('52', getline('.'))
1224 48
1225 norm! zR
1226 call assert_equal(1, &foldenable)
1227 call assert_equal(3, &foldlevel)
1228 call assert_equal('48', getline('.'))
1229 norm! j
1230 call assert_equal('49/*{{{*/', getline('.'))
1231 norm! j
1232 call assert_equal('50/*{{{*/', getline('.'))
1233 norm! j
1234 call assert_equal('a /*{{{*/', getline('.'))
1235 norm! j
1236 call assert_equal('b /*}}}*/', getline('.'))
1237 norm! j
1238 call assert_equal('51/*}}}*/', getline('.'))
1239 norm! j
1240 call assert_equal('52', getline('.'))
1241
1242 " clean up
1243 setl nofoldenable fdm=marker foldlevel=0
1244 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02001245endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001246
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01001247func Test_normal20_exmode()
Bram Moolenaar004a6782020-04-11 17:09:31 +02001248 " Reading from redirected file doesn't work on MS-Windows
1249 CheckNotMSWindows
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001250 call writefile(['1a', 'foo', 'bar', '.', 'w! Xfile2', 'q!'], 'Xscript')
1251 call writefile(['1', '2'], 'Xfile')
Bram Moolenaar93344c22019-08-14 21:12:05 +02001252 call system(GetVimCommand() .. ' -e -s < Xscript Xfile')
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001253 let a=readfile('Xfile2')
1254 call assert_equal(['1', 'foo', 'bar', '2'], a)
1255
1256 " clean up
1257 for file in ['Xfile', 'Xfile2', 'Xscript']
1258 call delete(file)
1259 endfor
1260 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02001261endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001262
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01001263func Test_normal21_nv_hat()
1264
1265 " Edit a fresh file and wipe the buffer list so that there is no alternate
1266 " file present. Next, check for the expected command failures.
1267 edit Xfoo | %bw
1268 call assert_fails(':buffer #', 'E86')
1269 call assert_fails(':execute "normal! \<C-^>"', 'E23')
Bram Moolenaarb7e24832020-06-24 13:37:35 +02001270 call assert_fails("normal i\<C-R>#", 'E23:')
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01001271
1272 " Test for the expected behavior when switching between two named buffers.
1273 edit Xfoo | edit Xbar
1274 call feedkeys("\<C-^>", 'tx')
1275 call assert_equal('Xfoo', fnamemodify(bufname('%'), ':t'))
1276 call feedkeys("\<C-^>", 'tx')
1277 call assert_equal('Xbar', fnamemodify(bufname('%'), ':t'))
1278
1279 " Test for the expected behavior when only one buffer is named.
1280 enew | let l:nr = bufnr('%')
1281 call feedkeys("\<C-^>", 'tx')
1282 call assert_equal('Xbar', fnamemodify(bufname('%'), ':t'))
1283 call feedkeys("\<C-^>", 'tx')
1284 call assert_equal('', bufname('%'))
1285 call assert_equal(l:nr, bufnr('%'))
1286
1287 " Test that no action is taken by "<C-^>" when an operator is pending.
1288 edit Xfoo
1289 call feedkeys("ci\<C-^>", 'tx')
1290 call assert_equal('Xfoo', fnamemodify(bufname('%'), ':t'))
1291
1292 %bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02001293endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001294
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01001295func Test_normal22_zet()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001296 " Test for ZZ
Bram Moolenaar0913a102016-09-03 19:11:59 +02001297 " let shell = &shell
1298 " let &shell = 'sh'
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001299 call writefile(['1', '2'], 'Xfile')
Bram Moolenaar93344c22019-08-14 21:12:05 +02001300 let args = ' -N -i NONE --noplugins -X --not-a-term'
1301 call system(GetVimCommand() .. args .. ' -c "%d" -c ":norm! ZZ" Xfile')
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001302 let a = readfile('Xfile')
1303 call assert_equal([], a)
1304 " Test for ZQ
1305 call writefile(['1', '2'], 'Xfile')
Bram Moolenaar93344c22019-08-14 21:12:05 +02001306 call system(GetVimCommand() . args . ' -c "%d" -c ":norm! ZQ" Xfile')
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001307 let a = readfile('Xfile')
1308 call assert_equal(['1', '2'], a)
1309
Bram Moolenaar1671f442020-03-10 07:48:13 +01001310 " Unsupported Z command
1311 call assert_beeps('normal! ZW')
1312
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001313 " clean up
1314 for file in ['Xfile']
1315 call delete(file)
1316 endfor
Bram Moolenaar0913a102016-09-03 19:11:59 +02001317 " let &shell = shell
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02001318endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001319
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01001320func Test_normal23_K()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001321 " Test for K command
1322 new
Bram Moolenaar426f3752016-11-04 21:22:37 +01001323 call append(0, ['version8.txt', 'man', 'aa%bb', 'cc|dd'])
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001324 let k = &keywordprg
1325 set keywordprg=:help
1326 1
1327 norm! VK
1328 call assert_equal('version8.txt', fnamemodify(bufname('%'), ':t'))
1329 call assert_equal('help', &ft)
1330 call assert_match('\*version8.txt\*', getline('.'))
1331 helpclose
1332 norm! 0K
1333 call assert_equal('version8.txt', fnamemodify(bufname('%'), ':t'))
1334 call assert_equal('help', &ft)
Bram Moolenaarb1c91982018-05-17 17:04:55 +02001335 call assert_match('\*version8\.\d\*', getline('.'))
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001336 helpclose
1337
Bram Moolenaar426f3752016-11-04 21:22:37 +01001338 set keywordprg=:new
1339 set iskeyword+=%
1340 set iskeyword+=\|
1341 2
1342 norm! K
1343 call assert_equal('man', fnamemodify(bufname('%'), ':t'))
1344 bwipe!
1345 3
1346 norm! K
1347 call assert_equal('aa%bb', fnamemodify(bufname('%'), ':t'))
1348 bwipe!
Bram Moolenaareb828d02016-11-05 19:54:01 +01001349 if !has('win32')
1350 4
1351 norm! K
1352 call assert_equal('cc|dd', fnamemodify(bufname('%'), ':t'))
1353 bwipe!
1354 endif
Bram Moolenaar426f3752016-11-04 21:22:37 +01001355 set iskeyword-=%
1356 set iskeyword-=\|
1357
Bram Moolenaar0913a102016-09-03 19:11:59 +02001358 " Only expect "man" to work on Unix
1359 if !has("unix")
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001360 let &keywordprg = k
1361 bw!
1362 return
1363 endif
Bram Moolenaarc6b37db2019-04-27 18:00:34 +02001364
Bram Moolenaar9134f1e2019-11-29 20:26:13 +01001365 let not_gnu_man = has('mac') || has('bsd')
1366 if not_gnu_man
Bram Moolenaarc7d2a572019-11-28 21:16:06 +01001367 " In MacOS and BSD, the option for specifying a pager is different
Bram Moolenaarc6b37db2019-04-27 18:00:34 +02001368 set keywordprg=man\ -P\ cat
1369 else
1370 set keywordprg=man\ --pager=cat
1371 endif
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001372 " Test for using man
1373 2
1374 let a = execute('unsilent norm! K')
Bram Moolenaar9134f1e2019-11-29 20:26:13 +01001375 if not_gnu_man
Bram Moolenaarc6b37db2019-04-27 18:00:34 +02001376 call assert_match("man -P cat 'man'", a)
1377 else
1378 call assert_match("man --pager=cat 'man'", a)
1379 endif
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001380
Bram Moolenaar1671f442020-03-10 07:48:13 +01001381 " Error cases
1382 call setline(1, '#$#')
1383 call assert_fails('normal! ggK', 'E349:')
1384 call setline(1, '---')
1385 call assert_fails('normal! ggv2lK', 'E349:')
1386 call setline(1, ['abc', 'xyz'])
Bram Moolenaar9b7bf9e2020-07-11 22:14:59 +02001387 call assert_fails("normal! gg2lv2h\<C-]>", 'E433:')
Bram Moolenaar1671f442020-03-10 07:48:13 +01001388 call assert_beeps("normal! ggVjK")
1389
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001390 " clean up
1391 let &keywordprg = k
1392 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02001393endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001394
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01001395func Test_normal24_rot13()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001396 " Testing for g?? g?g?
1397 new
1398 call append(0, 'abcdefghijklmnopqrstuvwxyzäüö')
1399 1
1400 norm! g??
1401 call assert_equal('nopqrstuvwxyzabcdefghijklmäüö', getline('.'))
1402 norm! g?g?
1403 call assert_equal('abcdefghijklmnopqrstuvwxyzäüö', getline('.'))
1404
1405 " clean up
1406 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02001407endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001408
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01001409func Test_normal25_tag()
Bram Moolenaar5a4c3082019-12-01 15:23:11 +01001410 CheckFeature quickfix
1411
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001412 " Testing for CTRL-] g CTRL-] g]
1413 " CTRL-W g] CTRL-W CTRL-] CTRL-W g CTRL-]
1414 h
1415 " Test for CTRL-]
1416 call search('\<x\>$')
1417 exe "norm! \<c-]>"
1418 call assert_equal("change.txt", fnamemodify(bufname('%'), ':t'))
1419 norm! yiW
1420 call assert_equal("*x*", @0)
1421 exe ":norm \<c-o>"
1422
1423 " Test for g_CTRL-]
1424 call search('\<v_u\>$')
1425 exe "norm! g\<c-]>"
1426 call assert_equal("change.txt", fnamemodify(bufname('%'), ':t'))
1427 norm! yiW
1428 call assert_equal("*v_u*", @0)
1429 exe ":norm \<c-o>"
1430
1431 " Test for g]
1432 call search('\<i_<Esc>$')
1433 let a = execute(":norm! g]")
1434 call assert_match('i_<Esc>.*insert.txt', a)
1435
1436 if !empty(exepath('cscope')) && has('cscope')
1437 " setting cscopetag changes how g] works
1438 set cst
1439 exe "norm! g]"
1440 call assert_equal("insert.txt", fnamemodify(bufname('%'), ':t'))
1441 norm! yiW
1442 call assert_equal("*i_<Esc>*", @0)
1443 exe ":norm \<c-o>"
1444 " Test for CTRL-W g]
1445 exe "norm! \<C-W>g]"
1446 call assert_equal("insert.txt", fnamemodify(bufname('%'), ':t'))
1447 norm! yiW
1448 call assert_equal("*i_<Esc>*", @0)
1449 call assert_equal(3, winnr('$'))
1450 helpclose
1451 set nocst
1452 endif
1453
1454 " Test for CTRL-W g]
1455 let a = execute("norm! \<C-W>g]")
1456 call assert_match('i_<Esc>.*insert.txt', a)
1457
1458 " Test for CTRL-W CTRL-]
1459 exe "norm! \<C-W>\<C-]>"
1460 call assert_equal("insert.txt", fnamemodify(bufname('%'), ':t'))
1461 norm! yiW
1462 call assert_equal("*i_<Esc>*", @0)
1463 call assert_equal(3, winnr('$'))
1464 helpclose
1465
1466 " Test for CTRL-W g CTRL-]
1467 exe "norm! \<C-W>g\<C-]>"
1468 call assert_equal("insert.txt", fnamemodify(bufname('%'), ':t'))
1469 norm! yiW
1470 call assert_equal("*i_<Esc>*", @0)
1471 call assert_equal(3, winnr('$'))
1472 helpclose
1473
1474 " clean up
1475 helpclose
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02001476endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001477
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01001478func Test_normal26_put()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001479 " Test for ]p ]P [p and [P
1480 new
1481 call append(0, ['while read LINE', 'do', ' ((count++))', ' if [ $? -ne 0 ]; then', " echo 'Error writing file'", ' fi', 'done'])
1482 1
1483 /Error/y a
1484 2
1485 norm! "a]pj"a[p
1486 call assert_equal(['do', "echo 'Error writing file'", " echo 'Error writing file'", ' ((count++))'], getline(2,5))
1487 1
1488 /^\s\{4}/
1489 exe "norm! \"a]P3Eldt'"
1490 exe "norm! j\"a[P2Eldt'"
1491 call assert_equal([' if [ $? -ne 0 ]; then', " echo 'Error writing'", " echo 'Error'", " echo 'Error writing file'", ' fi'], getline(6,10))
1492
1493 " clean up
1494 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02001495endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001496
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01001497func Test_normal27_bracket()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001498 " Test for [' [` ]' ]`
1499 call Setup_NewWindow()
1500 1,21s/.\+/ & b/
1501 1
1502 norm! $ma
1503 5
1504 norm! $mb
1505 10
1506 norm! $mc
1507 15
1508 norm! $md
1509 20
1510 norm! $me
1511
1512 " Test for ['
1513 9
1514 norm! 2['
1515 call assert_equal(' 1 b', getline('.'))
1516 call assert_equal(1, line('.'))
1517 call assert_equal(3, col('.'))
1518
1519 " Test for ]'
1520 norm! ]'
1521 call assert_equal(' 5 b', getline('.'))
1522 call assert_equal(5, line('.'))
1523 call assert_equal(3, col('.'))
1524
1525 " No mark after line 21, cursor moves to first non blank on current line
1526 21
1527 norm! $]'
1528 call assert_equal(' 21 b', getline('.'))
1529 call assert_equal(21, line('.'))
1530 call assert_equal(3, col('.'))
1531
1532 " Test for [`
1533 norm! 2[`
1534 call assert_equal(' 15 b', getline('.'))
1535 call assert_equal(15, line('.'))
1536 call assert_equal(8, col('.'))
1537
1538 " Test for ]`
1539 norm! ]`
1540 call assert_equal(' 20 b', getline('.'))
1541 call assert_equal(20, line('.'))
1542 call assert_equal(8, col('.'))
1543
1544 " clean up
1545 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02001546endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001547
Bram Moolenaar1671f442020-03-10 07:48:13 +01001548" Test for ( and ) sentence movements
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01001549func Test_normal28_parenthesis()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001550 new
1551 call append(0, ['This is a test. With some sentences!', '', 'Even with a question? And one more. And no sentence here'])
1552
1553 $
1554 norm! d(
1555 call assert_equal(['This is a test. With some sentences!', '', 'Even with a question? And one more. ', ''], getline(1, '$'))
1556 norm! 2d(
1557 call assert_equal(['This is a test. With some sentences!', '', ' ', ''], getline(1, '$'))
1558 1
1559 norm! 0d)
1560 call assert_equal(['With some sentences!', '', ' ', ''], getline(1, '$'))
1561
1562 call append('$', ['This is a long sentence', '', 'spanning', 'over several lines. '])
1563 $
1564 norm! $d(
1565 call assert_equal(['With some sentences!', '', ' ', '', 'This is a long sentence', ''], getline(1, '$'))
1566
Bram Moolenaar224a5f12020-04-28 20:29:07 +02001567 " Move to the next sentence from a paragraph macro
1568 %d
1569 call setline(1, ['.LP', 'blue sky!. blue sky.', 'blue sky. blue sky.'])
1570 call cursor(1, 1)
1571 normal )
1572 call assert_equal([2, 1], [line('.'), col('.')])
1573 normal )
1574 call assert_equal([2, 12], [line('.'), col('.')])
1575 normal ((
1576 call assert_equal([1, 1], [line('.'), col('.')])
1577
Bram Moolenaar1671f442020-03-10 07:48:13 +01001578 " It is an error if a next sentence is not found
1579 %d
1580 call setline(1, '.SH')
1581 call assert_beeps('normal )')
1582
Bram Moolenaar224a5f12020-04-28 20:29:07 +02001583 " If only dot is present, don't treat that as a sentence
1584 call setline(1, '. This is a sentence.')
1585 normal $((
1586 call assert_equal(3, col('.'))
1587
Bram Moolenaar1671f442020-03-10 07:48:13 +01001588 " Jumping to a fold should open the fold
1589 call setline(1, ['', '', 'one', 'two', 'three'])
1590 set foldenable
1591 2,$fold
1592 call feedkeys(')', 'xt')
1593 call assert_equal(3, line('.'))
1594 call assert_equal(1, foldlevel('.'))
1595 call assert_equal(-1, foldclosed('.'))
1596 set foldenable&
1597
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001598 " clean up
1599 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02001600endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001601
Bram Moolenaar1671f442020-03-10 07:48:13 +01001602" Test for { and } paragraph movements
1603func Test_normal29_brace()
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001604 let text =<< trim [DATA]
Bram Moolenaare7eb9272019-06-24 00:58:07 +02001605 A paragraph begins after each empty line, and also at each of a set of
1606 paragraph macros, specified by the pairs of characters in the 'paragraphs'
1607 option. The default is "IPLPPPQPP TPHPLIPpLpItpplpipbp", which corresponds to
1608 the macros ".IP", ".LP", etc. (These are nroff macros, so the dot must be in
1609 the first column). A section boundary is also a paragraph boundary.
1610 Note that a blank line (only containing white space) is NOT a paragraph
1611 boundary.
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001612
1613
Bram Moolenaare7eb9272019-06-24 00:58:07 +02001614 Also note that this does not include a '{' or '}' in the first column. When
1615 the '{' flag is in 'cpoptions' then '{' in the first column is used as a
1616 paragraph boundary |posix|.
1617 {
1618 This is no paragraph
1619 unless the '{' is set
1620 in 'cpoptions'
1621 }
1622 .IP
1623 The nroff macros IP separates a paragraph
1624 That means, it must be a '.'
1625 followed by IP
1626 .LPIt does not matter, if afterwards some
1627 more characters follow.
1628 .SHAlso section boundaries from the nroff
1629 macros terminate a paragraph. That means
1630 a character like this:
1631 .NH
1632 End of text here
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001633 [DATA]
1634
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001635 new
1636 call append(0, text)
1637 1
1638 norm! 0d2}
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001639
1640 let expected =<< trim [DATA]
Bram Moolenaare7eb9272019-06-24 00:58:07 +02001641 .IP
1642 The nroff macros IP separates a paragraph
1643 That means, it must be a '.'
1644 followed by IP
1645 .LPIt does not matter, if afterwards some
1646 more characters follow.
1647 .SHAlso section boundaries from the nroff
1648 macros terminate a paragraph. That means
1649 a character like this:
1650 .NH
1651 End of text here
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001652
1653 [DATA]
1654 call assert_equal(expected, getline(1, '$'))
1655
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001656 norm! 0d}
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001657
1658 let expected =<< trim [DATA]
Bram Moolenaare7eb9272019-06-24 00:58:07 +02001659 .LPIt does not matter, if afterwards some
1660 more characters follow.
1661 .SHAlso section boundaries from the nroff
1662 macros terminate a paragraph. That means
1663 a character like this:
1664 .NH
1665 End of text here
1666
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001667 [DATA]
1668 call assert_equal(expected, getline(1, '$'))
1669
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001670 $
1671 norm! d{
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001672
1673 let expected =<< trim [DATA]
Bram Moolenaare7eb9272019-06-24 00:58:07 +02001674 .LPIt does not matter, if afterwards some
1675 more characters follow.
1676 .SHAlso section boundaries from the nroff
1677 macros terminate a paragraph. That means
1678 a character like this:
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001679
1680 [DATA]
1681 call assert_equal(expected, getline(1, '$'))
1682
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001683 norm! d{
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001684
1685 let expected =<< trim [DATA]
Bram Moolenaare7eb9272019-06-24 00:58:07 +02001686 .LPIt does not matter, if afterwards some
1687 more characters follow.
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001688
1689 [DATA]
1690 call assert_equal(expected, getline(1, '$'))
1691
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001692 " Test with { in cpooptions
1693 %d
1694 call append(0, text)
1695 set cpo+={
1696 1
1697 norm! 0d2}
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001698
1699 let expected =<< trim [DATA]
Bram Moolenaare7eb9272019-06-24 00:58:07 +02001700 {
1701 This is no paragraph
1702 unless the '{' is set
1703 in 'cpoptions'
1704 }
1705 .IP
1706 The nroff macros IP separates a paragraph
1707 That means, it must be a '.'
1708 followed by IP
1709 .LPIt does not matter, if afterwards some
1710 more characters follow.
1711 .SHAlso section boundaries from the nroff
1712 macros terminate a paragraph. That means
1713 a character like this:
1714 .NH
1715 End of text here
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001716
1717 [DATA]
1718 call assert_equal(expected, getline(1, '$'))
1719
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001720 $
1721 norm! d}
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001722
1723 let expected =<< trim [DATA]
Bram Moolenaare7eb9272019-06-24 00:58:07 +02001724 {
1725 This is no paragraph
1726 unless the '{' is set
1727 in 'cpoptions'
1728 }
1729 .IP
1730 The nroff macros IP separates a paragraph
1731 That means, it must be a '.'
1732 followed by IP
1733 .LPIt does not matter, if afterwards some
1734 more characters follow.
1735 .SHAlso section boundaries from the nroff
1736 macros terminate a paragraph. That means
1737 a character like this:
1738 .NH
1739 End of text here
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001740
1741 [DATA]
1742 call assert_equal(expected, getline(1, '$'))
1743
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001744 norm! gg}
1745 norm! d5}
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001746
1747 let expected =<< trim [DATA]
Bram Moolenaare7eb9272019-06-24 00:58:07 +02001748 {
1749 This is no paragraph
1750 unless the '{' is set
1751 in 'cpoptions'
1752 }
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001753
1754 [DATA]
1755 call assert_equal(expected, getline(1, '$'))
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001756
Bram Moolenaar1671f442020-03-10 07:48:13 +01001757 " Jumping to a fold should open the fold
1758 %d
1759 call setline(1, ['', 'one', 'two', ''])
1760 set foldenable
1761 2,$fold
1762 call feedkeys('}', 'xt')
1763 call assert_equal(4, line('.'))
1764 call assert_equal(1, foldlevel('.'))
1765 call assert_equal(-1, foldclosed('.'))
1766 set foldenable&
1767
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001768 " clean up
1769 set cpo-={
1770 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02001771endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001772
Bram Moolenaar1671f442020-03-10 07:48:13 +01001773" Test for ~ command
1774func Test_normal30_changecase()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001775 new
1776 call append(0, 'This is a simple test: äüöß')
1777 norm! 1ggVu
1778 call assert_equal('this is a simple test: äüöß', getline('.'))
1779 norm! VU
1780 call assert_equal('THIS IS A SIMPLE TEST: ÄÜÖSS', getline('.'))
1781 norm! guu
1782 call assert_equal('this is a simple test: äüöss', getline('.'))
1783 norm! gUgU
1784 call assert_equal('THIS IS A SIMPLE TEST: ÄÜÖSS', getline('.'))
1785 norm! gugu
1786 call assert_equal('this is a simple test: äüöss', getline('.'))
1787 norm! gUU
1788 call assert_equal('THIS IS A SIMPLE TEST: ÄÜÖSS', getline('.'))
1789 norm! 010~
1790 call assert_equal('this is a SIMPLE TEST: ÄÜÖSS', getline('.'))
1791 norm! V~
1792 call assert_equal('THIS IS A simple test: äüöss', getline('.'))
1793
Bram Moolenaar1671f442020-03-10 07:48:13 +01001794 " Test for changing case across lines using 'whichwrap'
1795 call setline(1, ['aaaaaa', 'aaaaaa'])
1796 normal! gg10~
1797 call assert_equal(['AAAAAA', 'aaaaaa'], getline(1, 2))
1798 set whichwrap+=~
1799 normal! gg10~
1800 call assert_equal(['aaaaaa', 'AAAAaa'], getline(1, 2))
1801 set whichwrap&
1802
1803 " clean up
1804 bw!
1805endfunc
1806
1807" Turkish ASCII turns to multi-byte. On some systems Turkish locale
1808" is available but toupper()/tolower() don't do the right thing.
1809func Test_normal_changecase_turkish()
1810 new
Bram Moolenaarf1c118b2018-09-03 22:08:10 +02001811 try
1812 lang tr_TR.UTF-8
1813 set casemap=
1814 let iupper = toupper('i')
1815 if iupper == "\u0130"
Bram Moolenaar9f4de1f2017-04-08 19:39:43 +02001816 call setline(1, 'iI')
1817 1normal gUU
1818 call assert_equal("\u0130I", getline(1))
1819 call assert_equal("\u0130I", toupper("iI"))
Bram Moolenaar3317d5e2017-04-08 19:12:06 +02001820
Bram Moolenaar9f4de1f2017-04-08 19:39:43 +02001821 call setline(1, 'iI')
1822 1normal guu
1823 call assert_equal("i\u0131", getline(1))
1824 call assert_equal("i\u0131", tolower("iI"))
Bram Moolenaarf1c118b2018-09-03 22:08:10 +02001825 elseif iupper == "I"
Bram Moolenaar1cc48202017-04-09 13:41:59 +02001826 call setline(1, 'iI')
1827 1normal gUU
1828 call assert_equal("II", getline(1))
1829 call assert_equal("II", toupper("iI"))
1830
1831 call setline(1, 'iI')
1832 1normal guu
1833 call assert_equal("ii", getline(1))
1834 call assert_equal("ii", tolower("iI"))
Bram Moolenaarf1c118b2018-09-03 22:08:10 +02001835 else
1836 call assert_true(false, "expected toupper('i') to be either 'I' or '\u0130'")
1837 endif
1838 set casemap&
1839 call setline(1, 'iI')
1840 1normal gUU
1841 call assert_equal("II", getline(1))
1842 call assert_equal("II", toupper("iI"))
Bram Moolenaar1cc48202017-04-09 13:41:59 +02001843
Bram Moolenaarf1c118b2018-09-03 22:08:10 +02001844 call setline(1, 'iI')
1845 1normal guu
1846 call assert_equal("ii", getline(1))
1847 call assert_equal("ii", tolower("iI"))
1848
1849 lang en_US.UTF-8
1850 catch /E197:/
1851 " can't use Turkish locale
1852 throw 'Skipped: Turkish locale not available'
1853 endtry
Bram Moolenaar1671f442020-03-10 07:48:13 +01001854 close!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02001855endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001856
Bram Moolenaar1671f442020-03-10 07:48:13 +01001857" Test for r (replace) command
1858func Test_normal31_r_cmd()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001859 new
1860 call append(0, 'This is a simple test: abcd')
1861 exe "norm! 1gg$r\<cr>"
1862 call assert_equal(['This is a simple test: abc', '', ''], getline(1,'$'))
1863 exe "norm! 1gg2wlr\<cr>"
1864 call assert_equal(['This is a', 'simple test: abc', '', ''], getline(1,'$'))
1865 exe "norm! 2gg0W5r\<cr>"
1866 call assert_equal(['This is a', 'simple ', ' abc', '', ''], getline('1', '$'))
1867 set autoindent
1868 call setline(2, ['simple test: abc', ''])
1869 exe "norm! 2gg0W5r\<cr>"
1870 call assert_equal(['This is a', 'simple ', 'abc', '', '', ''], getline('1', '$'))
1871 exe "norm! 1ggVr\<cr>"
1872 call assert_equal('^M^M^M^M^M^M^M^M^M', strtrans(getline(1)))
1873 call setline(1, 'This is a')
1874 exe "norm! 1gg05rf"
1875 call assert_equal('fffffis a', getline(1))
1876
Bram Moolenaar1671f442020-03-10 07:48:13 +01001877 " When replacing characters, copy characters from above and below lines
1878 " using CTRL-Y and CTRL-E.
1879 " Different code paths are used for utf-8 and latin1 encodings
1880 set showmatch
1881 for enc in ['latin1', 'utf-8']
1882 enew!
1883 let &encoding = enc
1884 call setline(1, [' {a}', 'xxxxxxxxxx', ' [b]'])
1885 exe "norm! 2gg5r\<C-Y>l5r\<C-E>"
1886 call assert_equal(' {a}x [b]x', getline(2))
1887 endfor
1888 set showmatch&
1889
1890 " r command should fail in operator pending mode
1891 call assert_beeps('normal! cr')
1892
Bram Moolenaar004a6782020-04-11 17:09:31 +02001893 " replace a tab character in visual mode
1894 %d
1895 call setline(1, ["a\tb", "c\td", "e\tf"])
1896 normal gglvjjrx
1897 call assert_equal(['axx', 'xxx', 'xxf'], getline(1, '$'))
1898
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001899 " clean up
1900 set noautoindent
1901 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02001902endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001903
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01001904" Test for g*, g#
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01001905func Test_normal32_g_cmd1()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001906 new
1907 call append(0, ['abc.x_foo', 'x_foobar.abc'])
1908 1
1909 norm! $g*
1910 call assert_equal('x_foo', @/)
1911 call assert_equal('x_foobar.abc', getline('.'))
1912 norm! $g#
1913 call assert_equal('abc', @/)
1914 call assert_equal('abc.x_foo', getline('.'))
1915
1916 " clean up
1917 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02001918endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001919
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01001920" Test for g`, g;, g,, g&, gv, gk, gj, gJ, g0, g^, g_, gm, g$, gM, g CTRL-G,
1921" gi and gI commands
Bram Moolenaar1671f442020-03-10 07:48:13 +01001922func Test_normal33_g_cmd2()
Bram Moolenaar004a6782020-04-11 17:09:31 +02001923 CheckFeature jumplist
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001924 call Setup_NewWindow()
1925 " Test for g`
1926 clearjumps
1927 norm! ma10j
1928 let a=execute(':jumps')
1929 " empty jumplist
1930 call assert_equal('>', a[-1:])
1931 norm! g`a
1932 call assert_equal('>', a[-1:])
1933 call assert_equal(1, line('.'))
1934 call assert_equal('1', getline('.'))
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01001935 call cursor(10, 1)
1936 norm! g'a
1937 call assert_equal('>', a[-1:])
1938 call assert_equal(1, line('.'))
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001939
1940 " Test for g; and g,
1941 norm! g;
1942 " there is only one change in the changelist
1943 " currently, when we setup the window
1944 call assert_equal(2, line('.'))
1945 call assert_fails(':norm! g;', 'E662')
1946 call assert_fails(':norm! g,', 'E663')
1947 let &ul=&ul
1948 call append('$', ['a', 'b', 'c', 'd'])
1949 let &ul=&ul
1950 call append('$', ['Z', 'Y', 'X', 'W'])
1951 let a = execute(':changes')
1952 call assert_match('2\s\+0\s\+2', a)
1953 call assert_match('101\s\+0\s\+a', a)
1954 call assert_match('105\s\+0\s\+Z', a)
1955 norm! 3g;
1956 call assert_equal(2, line('.'))
1957 norm! 2g,
1958 call assert_equal(105, line('.'))
1959
1960 " Test for g& - global substitute
1961 %d
1962 call setline(1, range(1,10))
1963 call append('$', ['a', 'b', 'c', 'd'])
1964 $s/\w/&&/g
1965 exe "norm! /[1-8]\<cr>"
1966 norm! g&
1967 call assert_equal(['11', '22', '33', '44', '55', '66', '77', '88', '9', '110', 'a', 'b', 'c', 'dd'], getline(1, '$'))
1968
Bram Moolenaar1671f442020-03-10 07:48:13 +01001969 " Jumping to a fold using gg should open the fold
1970 set foldenable
1971 set foldopen+=jump
1972 5,8fold
1973 call feedkeys('6gg', 'xt')
1974 call assert_equal(1, foldlevel('.'))
1975 call assert_equal(-1, foldclosed('.'))
1976 set foldopen-=jump
1977 set foldenable&
1978
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001979 " Test for gv
1980 %d
1981 call append('$', repeat(['abcdefgh'], 8))
1982 exe "norm! 2gg02l\<c-v>2j2ly"
1983 call assert_equal(['cde', 'cde', 'cde'], getreg(0, 1, 1))
1984 " in visual mode, gv swaps current and last selected region
1985 exe "norm! G0\<c-v>4k4lgvd"
1986 call assert_equal(['', 'abfgh', 'abfgh', 'abfgh', 'abcdefgh', 'abcdefgh', 'abcdefgh', 'abcdefgh', 'abcdefgh'], getline(1,'$'))
1987 exe "norm! G0\<c-v>4k4ly"
1988 exe "norm! gvood"
1989 call assert_equal(['', 'abfgh', 'abfgh', 'abfgh', 'fgh', 'fgh', 'fgh', 'fgh', 'fgh'], getline(1,'$'))
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01001990 " gv cannot be used in operator pending mode
1991 call assert_beeps('normal! cgv')
1992 " gv should beep without a previously selected visual area
1993 new
1994 call assert_beeps('normal! gv')
1995 close
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001996
1997 " Test for gk/gj
1998 %d
1999 15vsp
2000 set wrap listchars= sbr=
2001 let lineA='abcdefghijklmnopqrstuvwxyz'
2002 let lineB='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'
Bram Moolenaar8b530c12019-10-28 02:13:05 +01002003 let lineC='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz01234567890123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002004 $put =lineA
2005 $put =lineB
2006
2007 norm! 3gg0dgk
2008 call assert_equal(['', 'abcdefghijklmno', '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'], getline(1, '$'))
2009 set nu
2010 norm! 3gg0gjdgj
2011 call assert_equal(['', 'abcdefghijklmno', '0123456789AMNOPQRSTUVWXYZ'], getline(1,'$'))
2012
2013 " Test for gJ
2014 norm! 2gggJ
2015 call assert_equal(['', 'abcdefghijklmno0123456789AMNOPQRSTUVWXYZ'], getline(1,'$'))
2016 call assert_equal(16, col('.'))
2017 " shouldn't do anything
2018 norm! 10gJ
2019 call assert_equal(1, col('.'))
2020
2021 " Test for g0 g^ gm g$
2022 exe "norm! 2gg0gji "
2023 call assert_equal(['', 'abcdefghijk lmno0123456789AMNOPQRSTUVWXYZ'], getline(1,'$'))
2024 norm! g0yl
2025 call assert_equal(12, col('.'))
2026 call assert_equal(' ', getreg(0))
2027 norm! g$yl
2028 call assert_equal(22, col('.'))
2029 call assert_equal('3', getreg(0))
2030 norm! gmyl
2031 call assert_equal(17, col('.'))
2032 call assert_equal('n', getreg(0))
2033 norm! g^yl
2034 call assert_equal(15, col('.'))
2035 call assert_equal('l', getreg(0))
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01002036 call assert_beeps('normal 5g$')
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002037
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01002038 " Test for g_
2039 call assert_beeps('normal! 100g_')
2040 call setline(2, [' foo ', ' foobar '])
2041 normal! 2ggg_
2042 call assert_equal(5, col('.'))
2043 normal! 2g_
2044 call assert_equal(8, col('.'))
2045
2046 norm! 2ggdG
Bram Moolenaar8b530c12019-10-28 02:13:05 +01002047 $put =lineC
2048
2049 " Test for gM
2050 norm! gMyl
2051 call assert_equal(73, col('.'))
2052 call assert_equal('0', getreg(0))
2053 " Test for 20gM
2054 norm! 20gMyl
2055 call assert_equal(29, col('.'))
2056 call assert_equal('S', getreg(0))
2057 " Test for 60gM
2058 norm! 60gMyl
2059 call assert_equal(87, col('.'))
2060 call assert_equal('E', getreg(0))
2061
2062 " Test for g Ctrl-G
2063 set ff=unix
2064 let a=execute(":norm! g\<c-g>")
2065 call assert_match('Col 87 of 144; Line 2 of 2; Word 1 of 1; Byte 88 of 146', a)
2066
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002067 " Test for gI
2068 norm! gIfoo
Bram Moolenaar8b530c12019-10-28 02:13:05 +01002069 call assert_equal(['', 'foo0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz01234567890123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'], getline(1,'$'))
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002070
2071 " Test for gi
2072 wincmd c
2073 %d
2074 set tw=0
2075 call setline(1, ['foobar', 'new line'])
2076 norm! A next word
2077 $put ='third line'
2078 norm! gi another word
2079 call assert_equal(['foobar next word another word', 'new line', 'third line'], getline(1,'$'))
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01002080 call setline(1, 'foobar')
2081 normal! Ggifirst line
2082 call assert_equal('foobarfirst line', getline(1))
2083 " Test gi in 'virtualedit' mode with cursor after the end of the line
2084 set virtualedit=all
2085 call setline(1, 'foo')
2086 exe "normal! Abar\<Right>\<Right>\<Right>\<Right>"
2087 call setline(1, 'foo')
2088 normal! Ggifirst line
2089 call assert_equal('foo first line', getline(1))
2090 set virtualedit&
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002091
Bram Moolenaar1671f442020-03-10 07:48:13 +01002092 " Test for aboring a g command using CTRL-\ CTRL-G
2093 exe "normal! g\<C-\>\<C-G>"
2094 call assert_equal('foo first line', getline('.'))
2095
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002096 " clean up
2097 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002098endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002099
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01002100" Test for g CTRL-G
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01002101func Test_g_ctrl_g()
Bram Moolenaar05295832018-08-24 22:07:58 +02002102 new
2103
2104 let a = execute(":norm! g\<c-g>")
2105 call assert_equal("\n--No lines in buffer--", a)
2106
Bram Moolenaar1671f442020-03-10 07:48:13 +01002107 " Test for CTRL-G (same as :file)
2108 let a = execute(":norm! \<c-g>")
2109 call assert_equal("\n\n\"[No Name]\" --No lines in buffer--", a)
2110
Bram Moolenaar05295832018-08-24 22:07:58 +02002111 call setline(1, ['first line', 'second line'])
2112
2113 " Test g CTRL-g with dos, mac and unix file type.
2114 norm! gojll
2115 set ff=dos
2116 let a = execute(":norm! g\<c-g>")
2117 call assert_equal("\nCol 3 of 11; Line 2 of 2; Word 3 of 4; Byte 15 of 25", a)
2118
2119 set ff=mac
2120 let a = execute(":norm! g\<c-g>")
2121 call assert_equal("\nCol 3 of 11; Line 2 of 2; Word 3 of 4; Byte 14 of 23", a)
2122
2123 set ff=unix
2124 let a = execute(":norm! g\<c-g>")
2125 call assert_equal("\nCol 3 of 11; Line 2 of 2; Word 3 of 4; Byte 14 of 23", a)
2126
2127 " Test g CTRL-g in visual mode (v)
2128 let a = execute(":norm! gojllvlg\<c-g>")
2129 call assert_equal("\nSelected 1 of 2 Lines; 1 of 4 Words; 2 of 23 Bytes", a)
2130
2131 " Test g CTRL-g in visual mode (CTRL-V) with end col > start col
2132 let a = execute(":norm! \<Esc>gojll\<C-V>kllg\<c-g>")
2133 call assert_equal("\nSelected 3 Cols; 2 of 2 Lines; 2 of 4 Words; 6 of 23 Bytes", a)
2134
2135 " Test g_CTRL-g in visual mode (CTRL-V) with end col < start col
2136 let a = execute(":norm! \<Esc>goll\<C-V>jhhg\<c-g>")
2137 call assert_equal("\nSelected 3 Cols; 2 of 2 Lines; 2 of 4 Words; 6 of 23 Bytes", a)
2138
2139 " Test g CTRL-g in visual mode (CTRL-V) with end_vcol being MAXCOL
2140 let a = execute(":norm! \<Esc>gojll\<C-V>k$g\<c-g>")
2141 call assert_equal("\nSelected 2 of 2 Lines; 4 of 4 Words; 17 of 23 Bytes", a)
2142
2143 " There should be one byte less with noeol
2144 set bin noeol
2145 let a = execute(":norm! \<Esc>gog\<c-g>")
2146 call assert_equal("\nCol 1 of 10; Line 1 of 2; Word 1 of 4; Char 1 of 23; Byte 1 of 22", a)
2147 set bin & eol&
2148
Bram Moolenaar30276f22019-01-24 17:59:39 +01002149 call setline(1, ['Français', '日本語'])
Bram Moolenaar05295832018-08-24 22:07:58 +02002150
Bram Moolenaar30276f22019-01-24 17:59:39 +01002151 let a = execute(":norm! \<Esc>gojlg\<c-g>")
2152 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 +02002153
Bram Moolenaar30276f22019-01-24 17:59:39 +01002154 let a = execute(":norm! \<Esc>gojvlg\<c-g>")
2155 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 +02002156
Bram Moolenaar30276f22019-01-24 17:59:39 +01002157 let a = execute(":norm! \<Esc>goll\<c-v>jlg\<c-g>")
2158 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 +02002159
Bram Moolenaar30276f22019-01-24 17:59:39 +01002160 set fenc=utf8 bomb
2161 let a = execute(":norm! \<Esc>gojlg\<c-g>")
2162 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 +02002163
Bram Moolenaar30276f22019-01-24 17:59:39 +01002164 set fenc=utf16 bomb
2165 let a = execute(":norm! g\<c-g>")
2166 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 +02002167
Bram Moolenaar30276f22019-01-24 17:59:39 +01002168 set fenc=utf32 bomb
2169 let a = execute(":norm! g\<c-g>")
2170 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 +02002171
Bram Moolenaar30276f22019-01-24 17:59:39 +01002172 set fenc& bomb&
Bram Moolenaar05295832018-08-24 22:07:58 +02002173
2174 set ff&
2175 bwipe!
2176endfunc
2177
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01002178" Test for g8
Bram Moolenaar1671f442020-03-10 07:48:13 +01002179func Test_normal34_g_cmd3()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002180 new
Bram Moolenaar395b6ba2017-04-07 20:09:51 +02002181 let a=execute(':norm! 1G0g8')
2182 call assert_equal("\nNUL", a)
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002183
Bram Moolenaar395b6ba2017-04-07 20:09:51 +02002184 call setline(1, 'abcdefghijklmnopqrstuvwxyzäüö')
2185 let a=execute(':norm! 1G$g8')
2186 call assert_equal("\nc3 b6 ", a)
2187
2188 call setline(1, "a\u0302")
2189 let a=execute(':norm! 1G0g8')
2190 call assert_equal("\n61 + cc 82 ", a)
2191
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002192 " clean up
2193 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002194endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002195
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01002196" Test 8g8 which finds invalid utf8 at or after the cursor.
Bram Moolenaar395b6ba2017-04-07 20:09:51 +02002197func Test_normal_8g8()
Bram Moolenaar395b6ba2017-04-07 20:09:51 +02002198 new
2199
Bram Moolenaar395b6ba2017-04-07 20:09:51 +02002200 " With invalid byte.
2201 call setline(1, "___\xff___")
2202 norm! 1G08g8g
2203 call assert_equal([0, 1, 4, 0, 1], getcurpos())
2204
2205 " With invalid byte before the cursor.
2206 call setline(1, "___\xff___")
2207 norm! 1G$h8g8g
2208 call assert_equal([0, 1, 6, 0, 9], getcurpos())
2209
2210 " With truncated sequence.
2211 call setline(1, "___\xE2\x82___")
2212 norm! 1G08g8g
2213 call assert_equal([0, 1, 4, 0, 1], getcurpos())
2214
2215 " With overlong sequence.
2216 call setline(1, "___\xF0\x82\x82\xAC___")
2217 norm! 1G08g8g
2218 call assert_equal([0, 1, 4, 0, 1], getcurpos())
2219
2220 " With valid utf8.
2221 call setline(1, "café")
2222 norm! 1G08g8
2223 call assert_equal([0, 1, 1, 0, 1], getcurpos())
2224
2225 bw!
2226endfunc
2227
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01002228" Test for g<
Bram Moolenaar1671f442020-03-10 07:48:13 +01002229func Test_normal35_g_cmd4()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002230 " Cannot capture its output,
2231 " probably a bug, therefore, test disabled:
Bram Moolenaar31845092016-09-05 22:58:31 +02002232 throw "Skipped: output of g< can't be tested currently"
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002233 echo "a\nb\nc\nd"
2234 let b=execute(':norm! g<')
2235 call assert_true(!empty(b), 'failed `execute(g<)`')
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002236endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002237
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01002238" Test for gp gP go
Bram Moolenaar1671f442020-03-10 07:48:13 +01002239func Test_normal36_g_cmd5()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002240 new
2241 call append(0, 'abcdefghijklmnopqrstuvwxyz')
Bram Moolenaar0913a102016-09-03 19:11:59 +02002242 set ff=unix
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002243 " Test for gp gP
2244 call append(1, range(1,10))
2245 1
2246 norm! 1yy
2247 3
2248 norm! gp
2249 call assert_equal([0, 5, 1, 0, 1], getcurpos())
2250 $
2251 norm! gP
2252 call assert_equal([0, 14, 1, 0, 1], getcurpos())
2253
2254 " Test for go
2255 norm! 26go
2256 call assert_equal([0, 1, 26, 0, 26], getcurpos())
2257 norm! 27go
2258 call assert_equal([0, 1, 26, 0, 26], getcurpos())
2259 norm! 28go
2260 call assert_equal([0, 2, 1, 0, 1], getcurpos())
2261 set ff=dos
2262 norm! 29go
2263 call assert_equal([0, 2, 1, 0, 1], getcurpos())
2264 set ff=unix
2265 norm! gg0
2266 norm! 101go
2267 call assert_equal([0, 13, 26, 0, 26], getcurpos())
2268 norm! 103go
2269 call assert_equal([0, 14, 1, 0, 1], getcurpos())
2270 " count > buffer content
2271 norm! 120go
2272 call assert_equal([0, 14, 1, 0, 2147483647], getcurpos())
2273 " clean up
2274 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002275endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002276
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01002277" Test for gt and gT
Bram Moolenaar1671f442020-03-10 07:48:13 +01002278func Test_normal37_g_cmd6()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002279 tabnew 1.txt
2280 tabnew 2.txt
2281 tabnew 3.txt
2282 norm! 1gt
2283 call assert_equal(1, tabpagenr())
2284 norm! 3gt
2285 call assert_equal(3, tabpagenr())
2286 norm! 1gT
2287 " count gT goes not to the absolute tabpagenumber
2288 " but, but goes to the count previous tabpagenumber
2289 call assert_equal(2, tabpagenr())
2290 " wrap around
2291 norm! 3gT
2292 call assert_equal(3, tabpagenr())
2293 " gt does not wrap around
2294 norm! 5gt
2295 call assert_equal(3, tabpagenr())
2296
2297 for i in range(3)
2298 tabclose
2299 endfor
2300 " clean up
Bram Moolenaarbc2b71d2020-02-17 21:33:30 +01002301 call assert_fails(':tabclose', 'E784:')
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002302endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002303
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01002304" Test for <Home> and <C-Home> key
Bram Moolenaar1671f442020-03-10 07:48:13 +01002305func Test_normal38_nvhome()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002306 new
2307 call setline(1, range(10))
2308 $
2309 setl et sw=2
2310 norm! V10>$
2311 " count is ignored
2312 exe "norm! 10\<home>"
2313 call assert_equal(1, col('.'))
2314 exe "norm! \<home>"
2315 call assert_equal([0, 10, 1, 0, 1], getcurpos())
2316 exe "norm! 5\<c-home>"
2317 call assert_equal([0, 5, 1, 0, 1], getcurpos())
2318 exe "norm! \<c-home>"
2319 call assert_equal([0, 1, 1, 0, 1], getcurpos())
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01002320 exe "norm! G\<c-kHome>"
2321 call assert_equal([0, 1, 1, 0, 1], getcurpos())
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002322
2323 " clean up
2324 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002325endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002326
Bram Moolenaar1671f442020-03-10 07:48:13 +01002327" Test for <End> and <C-End> keys
2328func Test_normal_nvend()
2329 new
2330 call setline(1, map(range(1, 10), '"line" .. v:val'))
2331 exe "normal! \<End>"
2332 call assert_equal(5, col('.'))
2333 exe "normal! 4\<End>"
2334 call assert_equal([4, 5], [line('.'), col('.')])
2335 exe "normal! \<C-End>"
2336 call assert_equal([10, 6], [line('.'), col('.')])
2337 close!
2338endfunc
2339
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01002340" Test for cw cW ce
Bram Moolenaar1671f442020-03-10 07:48:13 +01002341func Test_normal39_cw()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002342 " Test for cw and cW on whitespace
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002343 new
2344 set tw=0
2345 call append(0, 'here are some words')
2346 norm! 1gg0elcwZZZ
2347 call assert_equal('hereZZZare some words', getline('.'))
2348 norm! 1gg0elcWYYY
2349 call assert_equal('hereZZZareYYYsome words', getline('.'))
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002350 norm! 2gg0cwfoo
2351 call assert_equal('foo', getline('.'))
2352
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01002353 call setline(1, 'one; two')
2354 call cursor(1, 1)
2355 call feedkeys('cwvim', 'xt')
2356 call assert_equal('vim; two', getline(1))
2357 call feedkeys('0cWone', 'xt')
2358 call assert_equal('one two', getline(1))
2359 "When cursor is at the end of a word 'ce' will change until the end of the
2360 "next word, but 'cw' will change only one character
2361 call setline(1, 'one two')
2362 call feedkeys('0ecwce', 'xt')
2363 call assert_equal('once two', getline(1))
2364 call setline(1, 'one two')
2365 call feedkeys('0ecely', 'xt')
2366 call assert_equal('only', getline(1))
2367
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002368 " clean up
2369 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002370endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002371
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01002372" Test for CTRL-\ commands
Bram Moolenaar1671f442020-03-10 07:48:13 +01002373func Test_normal40_ctrl_bsl()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002374 new
2375 call append(0, 'here are some words')
2376 exe "norm! 1gg0a\<C-\>\<C-N>"
2377 call assert_equal('n', mode())
2378 call assert_equal(1, col('.'))
2379 call assert_equal('', visualmode())
2380 exe "norm! 1gg0viw\<C-\>\<C-N>"
2381 call assert_equal('n', mode())
2382 call assert_equal(4, col('.'))
2383 exe "norm! 1gg0a\<C-\>\<C-G>"
2384 call assert_equal('n', mode())
2385 call assert_equal(1, col('.'))
2386 "imap <buffer> , <c-\><c-n>
2387 set im
2388 exe ":norm! \<c-\>\<c-n>dw"
2389 set noim
2390 call assert_equal('are some words', getline(1))
2391 call assert_false(&insertmode)
Bram Moolenaar1671f442020-03-10 07:48:13 +01002392 call assert_beeps("normal! \<C-\>\<C-A>", 'xt')
2393
2394 " Using CTRL-\ CTRL-N in cmd window should close the window
2395 call feedkeys("q:\<C-\>\<C-N>", 'xt')
2396 call assert_equal('', getcmdwintype())
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002397
2398 " clean up
2399 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002400endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002401
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01002402" Test for <c-r>=, <c-r><c-r>= and <c-r><c-o>= in insert mode
Bram Moolenaar1671f442020-03-10 07:48:13 +01002403func Test_normal41_insert_reg()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002404 new
2405 set sts=2 sw=2 ts=8 tw=0
2406 call append(0, ["aaa\tbbb\tccc", '', '', ''])
2407 let a=getline(1)
2408 norm! 2gg0
2409 exe "norm! a\<c-r>=a\<cr>"
2410 norm! 3gg0
2411 exe "norm! a\<c-r>\<c-r>=a\<cr>"
2412 norm! 4gg0
2413 exe "norm! a\<c-r>\<c-o>=a\<cr>"
2414 call assert_equal(['aaa bbb ccc', 'aaa bbb ccc', 'aaa bbb ccc', 'aaa bbb ccc', ''], getline(1, '$'))
2415
2416 " clean up
2417 set sts=0 sw=8 ts=8
Bram Moolenaar31845092016-09-05 22:58:31 +02002418 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002419endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002420
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01002421" Test for Ctrl-D and Ctrl-U
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01002422func Test_normal42_halfpage()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002423 call Setup_NewWindow()
2424 call assert_equal(5, &scroll)
2425 exe "norm! \<c-d>"
2426 call assert_equal('6', getline('.'))
2427 exe "norm! 2\<c-d>"
2428 call assert_equal('8', getline('.'))
2429 call assert_equal(2, &scroll)
2430 set scroll=5
2431 exe "norm! \<c-u>"
2432 call assert_equal('3', getline('.'))
2433 1
2434 set scrolloff=5
2435 exe "norm! \<c-d>"
2436 call assert_equal('10', getline('.'))
2437 exe "norm! \<c-u>"
2438 call assert_equal('5', getline('.'))
2439 1
2440 set scrolloff=99
2441 exe "norm! \<c-d>"
2442 call assert_equal('10', getline('.'))
2443 set scrolloff=0
2444 100
2445 exe "norm! $\<c-u>"
2446 call assert_equal('95', getline('.'))
2447 call assert_equal([0, 95, 1, 0, 1], getcurpos())
2448 100
2449 set nostartofline
2450 exe "norm! $\<c-u>"
2451 call assert_equal('95', getline('.'))
2452 call assert_equal([0, 95, 2, 0, 2147483647], getcurpos())
2453 " cleanup
2454 set startofline
2455 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002456endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002457
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01002458func Test_normal45_drop()
Bram Moolenaar29495952018-02-12 22:49:00 +01002459 if !has('dnd')
Bram Moolenaarb48e96f2018-02-13 12:26:14 +01002460 " The ~ register does not exist
2461 call assert_beeps('norm! "~')
Bram Moolenaar29495952018-02-12 22:49:00 +01002462 return
2463 endif
2464
2465 " basic test for drag-n-drop
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002466 " unfortunately, without a gui, we can't really test much here,
2467 " so simply test that ~p fails (which uses the drop register)
2468 new
2469 call assert_fails(':norm! "~p', 'E353')
2470 call assert_equal([], getreg('~', 1, 1))
2471 " the ~ register is read only
2472 call assert_fails(':let @~="1"', 'E354')
2473 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002474endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002475
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01002476func Test_normal46_ignore()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002477 new
2478 " How to test this?
2479 " let's just for now test, that the buffer
2480 " does not change
2481 call feedkeys("\<c-s>", 't')
2482 call assert_equal([''], getline(1,'$'))
2483
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002484 " no valid commands
2485 exe "norm! \<char-0x100>"
2486 call assert_equal([''], getline(1,'$'))
2487
2488 exe "norm! ä"
2489 call assert_equal([''], getline(1,'$'))
2490
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002491 " clean up
2492 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002493endfunc
Bram Moolenaarc4a908e2016-09-08 23:35:30 +02002494
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01002495func Test_normal47_visual_buf_wipe()
Bram Moolenaarc4a908e2016-09-08 23:35:30 +02002496 " This was causing a crash or ml_get error.
2497 enew!
2498 call setline(1,'xxx')
2499 normal $
2500 new
2501 call setline(1, range(1,2))
2502 2
2503 exe "norm \<C-V>$"
2504 bw!
2505 norm yp
2506 set nomodified
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002507endfunc
2508
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01002509func Test_normal47_autocmd()
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002510 " disabled, does not seem to be possible currently
2511 throw "Skipped: not possible to test cursorhold autocmd while waiting for input in normal_cmd"
2512 new
2513 call append(0, repeat('-',20))
2514 au CursorHold * call feedkeys('2l', '')
2515 1
2516 set updatetime=20
2517 " should delete 12 chars (d12l)
2518 call feedkeys('d1', '!')
2519 call assert_equal('--------', getline(1))
2520
2521 " clean up
2522 au! CursorHold
2523 set updatetime=4000
2524 bw!
2525endfunc
2526
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01002527func Test_normal48_wincmd()
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002528 new
2529 exe "norm! \<c-w>c"
2530 call assert_equal(1, winnr('$'))
2531 call assert_fails(":norm! \<c-w>c", "E444")
2532endfunc
2533
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01002534func Test_normal49_counts()
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002535 new
2536 call setline(1, 'one two three four five six seven eight nine ten')
2537 1
2538 norm! 3d2w
2539 call assert_equal('seven eight nine ten', getline(1))
2540 bw!
2541endfunc
2542
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01002543func Test_normal50_commandline()
Bram Moolenaar004a6782020-04-11 17:09:31 +02002544 CheckFeature timers
2545 CheckFeature cmdline_hist
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002546 func! DoTimerWork(id)
2547 call assert_equal('[Command Line]', bufname(''))
2548 " should fail, with E11, but does fail with E23?
2549 "call feedkeys("\<c-^>", 'tm')
2550
2551 " should also fail with E11
2552 call assert_fails(":wincmd p", 'E11')
2553 " return from commandline window
2554 call feedkeys("\<cr>")
2555 endfunc
2556
2557 let oldlang=v:lang
2558 lang C
2559 set updatetime=20
2560 call timer_start(100, 'DoTimerWork')
2561 try
2562 " throws E23, for whatever reason...
2563 call feedkeys('q:', 'x!')
2564 catch /E23/
2565 " no-op
2566 endtry
2567 " clean up
2568 set updatetime=4000
2569 exe "lang" oldlang
2570 bw!
2571endfunc
2572
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01002573func Test_normal51_FileChangedRO()
Bram Moolenaar004a6782020-04-11 17:09:31 +02002574 CheckFeature autocmd
Bram Moolenaare5f2a072017-02-01 22:31:49 +01002575 " Don't sleep after the warning message.
2576 call test_settime(1)
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002577 call writefile(['foo'], 'Xreadonly.log')
2578 new Xreadonly.log
2579 setl ro
2580 au FileChangedRO <buffer> :call feedkeys("\<c-^>", 'tix')
2581 call assert_fails(":norm! Af", 'E788')
2582 call assert_equal(['foo'], getline(1,'$'))
2583 call assert_equal('Xreadonly.log', bufname(''))
2584
2585 " cleanup
Bram Moolenaare5f2a072017-02-01 22:31:49 +01002586 call test_settime(0)
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002587 bw!
2588 call delete("Xreadonly.log")
2589endfunc
2590
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01002591func Test_normal52_rl()
Bram Moolenaar004a6782020-04-11 17:09:31 +02002592 CheckFeature rightleft
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002593 new
2594 call setline(1, 'abcde fghij klmnopq')
2595 norm! 1gg$
2596 set rl
2597 call assert_equal(19, col('.'))
2598 call feedkeys('l', 'tx')
2599 call assert_equal(18, col('.'))
2600 call feedkeys('h', 'tx')
2601 call assert_equal(19, col('.'))
2602 call feedkeys("\<right>", 'tx')
2603 call assert_equal(18, col('.'))
Bram Moolenaar1671f442020-03-10 07:48:13 +01002604 call feedkeys("\<left>", 'tx')
2605 call assert_equal(19, col('.'))
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002606 call feedkeys("\<s-right>", 'tx')
2607 call assert_equal(13, col('.'))
2608 call feedkeys("\<c-right>", 'tx')
2609 call assert_equal(7, col('.'))
2610 call feedkeys("\<c-left>", 'tx')
2611 call assert_equal(13, col('.'))
2612 call feedkeys("\<s-left>", 'tx')
2613 call assert_equal(19, col('.'))
2614 call feedkeys("<<", 'tx')
2615 call assert_equal(' abcde fghij klmnopq',getline(1))
2616 call feedkeys(">>", 'tx')
2617 call assert_equal('abcde fghij klmnopq',getline(1))
2618
2619 " cleanup
2620 set norl
2621 bw!
2622endfunc
2623
Bram Moolenaarb1e04fc2017-03-29 13:08:35 +02002624func Test_normal54_Ctrl_bsl()
2625 new
2626 call setline(1, 'abcdefghijklmn')
2627 exe "norm! df\<c-\>\<c-n>"
2628 call assert_equal(['abcdefghijklmn'], getline(1,'$'))
2629 exe "norm! df\<c-\>\<c-g>"
2630 call assert_equal(['abcdefghijklmn'], getline(1,'$'))
2631 exe "norm! df\<c-\>m"
2632 call assert_equal(['abcdefghijklmn'], getline(1,'$'))
Bram Moolenaar30276f22019-01-24 17:59:39 +01002633
Bram Moolenaarb1e04fc2017-03-29 13:08:35 +02002634 call setline(2, 'abcdefghijklmnāf')
2635 norm! 2gg0
2636 exe "norm! df\<Char-0x101>"
2637 call assert_equal(['abcdefghijklmn', 'f'], getline(1,'$'))
2638 norm! 1gg0
2639 exe "norm! df\<esc>"
2640 call assert_equal(['abcdefghijklmn', 'f'], getline(1,'$'))
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002641
Bram Moolenaarb1e04fc2017-03-29 13:08:35 +02002642 " clean up
2643 bw!
2644endfunc
2645
2646func Test_normal_large_count()
2647 " This may fail with 32bit long, how do we detect that?
2648 new
2649 normal o
2650 normal 6666666666dL
2651 bwipe!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002652endfunc
Bram Moolenaarbf3d5802017-03-29 19:48:11 +02002653
2654func Test_delete_until_paragraph()
Bram Moolenaarbf3d5802017-03-29 19:48:11 +02002655 new
2656 normal grádv}
2657 call assert_equal('á', getline(1))
2658 normal grád}
2659 call assert_equal('', getline(1))
2660 bwipe!
2661endfunc
Bram Moolenaarfb094e12017-11-05 20:59:28 +01002662
2663" Test for the gr (virtual replace) command
2664" Test for the bug fixed by 7.4.387
2665func Test_gr_command()
2666 enew!
2667 let save_cpo = &cpo
2668 call append(0, ['First line', 'Second line', 'Third line'])
2669 exe "normal i\<C-G>u"
2670 call cursor(2, 1)
2671 set cpo-=X
2672 normal 4gro
2673 call assert_equal('oooond line', getline(2))
2674 undo
2675 set cpo+=X
2676 normal 4gro
2677 call assert_equal('ooooecond line', getline(2))
2678 let &cpo = save_cpo
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01002679 normal! ggvegrx
2680 call assert_equal('xxxxx line', getline(1))
2681 exe "normal! gggr\<C-V>122"
2682 call assert_equal('zxxxx line', getline(1))
2683 set virtualedit=all
2684 normal! 15|grl
2685 call assert_equal('zxxxx line l', getline(1))
2686 set virtualedit&
2687 set nomodifiable
2688 call assert_fails('normal! grx', 'E21:')
2689 call assert_fails('normal! gRx', 'E21:')
2690 set modifiable&
Bram Moolenaarfb094e12017-11-05 20:59:28 +01002691 enew!
2692endfunc
2693
2694" When splitting a window the changelist position is wrong.
2695" Test the changelist position after splitting a window.
2696" Test for the bug fixed by 7.4.386
2697func Test_changelist()
2698 let save_ul = &ul
2699 enew!
2700 call append('$', ['1', '2'])
2701 exe "normal i\<C-G>u"
2702 exe "normal Gkylpa\<C-G>u"
2703 set ul=100
2704 exe "normal Gylpa\<C-G>u"
2705 set ul=100
2706 normal gg
2707 vsplit
2708 normal g;
2709 call assert_equal([3, 2], [line('.'), col('.')])
2710 normal g;
2711 call assert_equal([2, 2], [line('.'), col('.')])
2712 call assert_fails('normal g;', 'E662:')
Bram Moolenaar1671f442020-03-10 07:48:13 +01002713 new
2714 call assert_fails('normal g;', 'E664:')
Bram Moolenaarfb094e12017-11-05 20:59:28 +01002715 %bwipe!
2716 let &ul = save_ul
2717endfunc
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01002718
2719func Test_nv_hat_count()
2720 %bwipeout!
2721 let l:nr = bufnr('%') + 1
2722 call assert_fails(':execute "normal! ' . l:nr . '\<C-^>"', 'E92')
2723
2724 edit Xfoo
2725 let l:foo_nr = bufnr('Xfoo')
2726
2727 edit Xbar
2728 let l:bar_nr = bufnr('Xbar')
2729
2730 " Make sure we are not just using the alternate file.
2731 edit Xbaz
2732
2733 call feedkeys(l:foo_nr . "\<C-^>", 'tx')
2734 call assert_equal('Xfoo', fnamemodify(bufname('%'), ':t'))
2735
2736 call feedkeys(l:bar_nr . "\<C-^>", 'tx')
2737 call assert_equal('Xbar', fnamemodify(bufname('%'), ':t'))
2738
2739 %bwipeout!
2740endfunc
Bram Moolenaara84a3dd2019-03-25 22:21:24 +01002741
2742func Test_message_when_using_ctrl_c()
Bram Moolenaar553e5a52019-03-25 23:16:34 +01002743 " Make sure no buffers are changed.
2744 %bwipe!
2745
Bram Moolenaara84a3dd2019-03-25 22:21:24 +01002746 exe "normal \<C-C>"
2747 call assert_match("Type :qa and press <Enter> to exit Vim", Screenline(&lines))
Bram Moolenaar553e5a52019-03-25 23:16:34 +01002748
Bram Moolenaara84a3dd2019-03-25 22:21:24 +01002749 new
2750 cal setline(1, 'hi!')
2751 exe "normal \<C-C>"
2752 call assert_match("Type :qa! and press <Enter> to abandon all changes and exit Vim", Screenline(&lines))
Bram Moolenaar553e5a52019-03-25 23:16:34 +01002753
Bram Moolenaara84a3dd2019-03-25 22:21:24 +01002754 bwipe!
2755endfunc
Bram Moolenaarc6b37db2019-04-27 18:00:34 +02002756
2757" Test for '[m', ']m', '[M' and ']M'
2758" Jumping to beginning and end of methods in Java-like languages
2759func Test_java_motion()
2760 new
Bram Moolenaar1671f442020-03-10 07:48:13 +01002761 call assert_beeps('normal! [m')
2762 call assert_beeps('normal! ]m')
2763 call assert_beeps('normal! [M')
2764 call assert_beeps('normal! ]M')
Bram Moolenaarc6b37db2019-04-27 18:00:34 +02002765 a
2766Piece of Java
2767{
2768 tt m1 {
2769 t1;
2770 } e1
2771
2772 tt m2 {
2773 t2;
2774 } e2
2775
2776 tt m3 {
2777 if (x)
2778 {
2779 t3;
2780 }
2781 } e3
2782}
2783.
2784
2785 normal gg
2786
2787 normal 2]maA
2788 call assert_equal("\ttt m1 {A", getline('.'))
2789 call assert_equal([3, 9, 16], [line('.'), col('.'), virtcol('.')])
2790
2791 normal j]maB
2792 call assert_equal("\ttt m2 {B", getline('.'))
2793 call assert_equal([7, 9, 16], [line('.'), col('.'), virtcol('.')])
2794
2795 normal ]maC
2796 call assert_equal("\ttt m3 {C", getline('.'))
2797 call assert_equal([11, 9, 16], [line('.'), col('.'), virtcol('.')])
2798
2799 normal [maD
2800 call assert_equal("\ttt m3 {DC", getline('.'))
2801 call assert_equal([11, 9, 16], [line('.'), col('.'), virtcol('.')])
2802
2803 normal k2[maE
2804 call assert_equal("\ttt m1 {EA", getline('.'))
2805 call assert_equal([3, 9, 16], [line('.'), col('.'), virtcol('.')])
2806
2807 normal 3[maF
2808 call assert_equal("{F", getline('.'))
2809 call assert_equal([2, 2, 2], [line('.'), col('.'), virtcol('.')])
2810
2811 normal ]MaG
2812 call assert_equal("\t}G e1", getline('.'))
2813 call assert_equal([5, 3, 10], [line('.'), col('.'), virtcol('.')])
2814
2815 normal j2]MaH
2816 call assert_equal("\t}H e3", getline('.'))
2817 call assert_equal([16, 3, 10], [line('.'), col('.'), virtcol('.')])
2818
2819 normal ]M]M
2820 normal aI
2821 call assert_equal("}I", getline('.'))
2822 call assert_equal([17, 2, 2], [line('.'), col('.'), virtcol('.')])
2823
2824 normal 2[MaJ
2825 call assert_equal("\t}JH e3", getline('.'))
2826 call assert_equal([16, 3, 10], [line('.'), col('.'), virtcol('.')])
2827
2828 normal k[MaK
2829 call assert_equal("\t}K e2", getline('.'))
2830 call assert_equal([9, 3, 10], [line('.'), col('.'), virtcol('.')])
2831
2832 normal 3[MaL
2833 call assert_equal("{LF", getline('.'))
2834 call assert_equal([2, 2, 2], [line('.'), col('.'), virtcol('.')])
2835
2836 close!
2837endfunc
Bram Moolenaard5c82342019-07-27 18:44:57 +02002838
Bram Moolenaar004a6782020-04-11 17:09:31 +02002839" Tests for g cmds
Bram Moolenaar1671f442020-03-10 07:48:13 +01002840func Test_normal_gdollar_cmd()
Bram Moolenaar004a6782020-04-11 17:09:31 +02002841 CheckFeature jumplist
Bram Moolenaard5c82342019-07-27 18:44:57 +02002842 call Setup_NewWindow()
2843 " Make long lines that will wrap
2844 %s/$/\=repeat(' foobar', 10)/
2845 20vsp
2846 set wrap
2847 " Test for g$ with count
2848 norm! gg
2849 norm! 0vg$y
2850 call assert_equal(20, col("'>"))
2851 call assert_equal('1 foobar foobar foob', getreg(0))
2852 norm! gg
2853 norm! 0v4g$y
2854 call assert_equal(72, col("'>"))
2855 call assert_equal('1 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar'.."\n", getreg(0))
2856 norm! gg
2857 norm! 0v6g$y
2858 call assert_equal(40, col("'>"))
2859 call assert_equal('1 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar'.. "\n"..
2860 \ '2 foobar foobar foobar foobar foobar foo', getreg(0))
2861 set nowrap
2862 " clean up
2863 norm! gg
2864 norm! 0vg$y
2865 call assert_equal(20, col("'>"))
2866 call assert_equal('1 foobar foobar foob', getreg(0))
2867 norm! gg
2868 norm! 0v4g$y
2869 call assert_equal(20, col("'>"))
2870 call assert_equal('1 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar'.. "\n"..
2871 \ '2 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar'.. "\n"..
2872 \ '3 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar'.. "\n"..
2873 \ '4 foobar foobar foob', getreg(0))
2874 norm! gg
2875 norm! 0v6g$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 foobar foobar foobar foobar foobar foobar foobar foobar'.. "\n"..
2881 \ '5 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar'.. "\n"..
2882 \ '6 foobar foobar foob', getreg(0))
2883 " Move to last line, also down movement is not possible, should still move
2884 " the cursor to the last visible char
2885 norm! G
2886 norm! 0v6g$y
2887 call assert_equal(20, col("'>"))
2888 call assert_equal('100 foobar foobar fo', getreg(0))
2889 bw!
2890endfunc
Bram Moolenaar03ac52f2019-09-24 22:47:46 +02002891
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01002892func Test_normal_gk_gj()
Bram Moolenaar03ac52f2019-09-24 22:47:46 +02002893 " needs 80 column new window
2894 new
2895 vert 80new
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01002896 call assert_beeps('normal gk')
Bram Moolenaar03ac52f2019-09-24 22:47:46 +02002897 put =[repeat('x',90)..' {{{1', 'x {{{1']
2898 norm! gk
2899 " In a 80 column wide terminal the window will be only 78 char
2900 " (because Vim will leave space for the other window),
2901 " but if the terminal is larger, it will be 80 chars, so verify the
2902 " cursor column correctly.
2903 call assert_equal(winwidth(0)+1, col('.'))
2904 call assert_equal(winwidth(0)+1, virtcol('.'))
2905 norm! j
2906 call assert_equal(6, col('.'))
2907 call assert_equal(6, virtcol('.'))
2908 norm! gk
2909 call assert_equal(95, col('.'))
2910 call assert_equal(95, virtcol('.'))
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01002911 %bw!
Bram Moolenaarceba3dd2019-10-12 16:12:54 +02002912
2913 " needs 80 column new window
2914 new
2915 vert 80new
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01002916 call assert_beeps('normal gj')
Bram Moolenaarceba3dd2019-10-12 16:12:54 +02002917 set number
2918 set numberwidth=10
2919 set cpoptions+=n
2920 put =[repeat('0',90), repeat('1',90)]
2921 norm! 075l
2922 call assert_equal(76, col('.'))
2923 norm! gk
2924 call assert_equal(1, col('.'))
2925 norm! gk
2926 call assert_equal(76, col('.'))
2927 norm! gk
2928 call assert_equal(1, col('.'))
2929 norm! gj
2930 call assert_equal(76, col('.'))
2931 norm! gj
2932 call assert_equal(1, col('.'))
2933 norm! gj
2934 call assert_equal(76, col('.'))
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01002935 " When 'nowrap' is set, gk and gj behave like k and j
2936 set nowrap
2937 normal! gk
2938 call assert_equal([2, 76], [line('.'), col('.')])
2939 normal! gj
2940 call assert_equal([3, 76], [line('.'), col('.')])
2941 %bw!
2942 set cpoptions& number& numberwidth& wrap&
Bram Moolenaar03ac52f2019-09-24 22:47:46 +02002943endfunc
Bram Moolenaarf0cee192020-02-16 13:33:56 +01002944
Bram Moolenaar818fc9a2020-02-21 17:54:45 +01002945" Test for using : to run a multi-line Ex command in operator pending mode
2946func Test_normal_yank_with_excmd()
2947 new
2948 call setline(1, ['foo', 'bar', 'baz'])
2949 let @a = ''
2950 call feedkeys("\"ay:if v:true\<CR>normal l\<CR>endif\<CR>", 'xt')
2951 call assert_equal('f', @a)
2952 close!
2953endfunc
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01002954
2955" Test for supplying a count to a normal-mode command across a cursorhold call
2956func Test_normal_cursorhold_with_count()
2957 func s:cHold()
2958 let g:cHold_Called += 1
2959 endfunc
2960 new
2961 augroup normalcHoldTest
2962 au!
2963 au CursorHold <buffer> call s:cHold()
2964 augroup END
2965 let g:cHold_Called = 0
2966 call feedkeys("3\<CursorHold>2ix", 'xt')
2967 call assert_equal(1, g:cHold_Called)
2968 call assert_equal(repeat('x', 32), getline(1))
2969 augroup normalcHoldTest
2970 au!
2971 augroup END
2972 au! normalcHoldTest
2973 close!
2974 delfunc s:cHold
2975endfunc
2976
2977" Test for using a count and a command with CTRL-W
2978func Test_wincmd_with_count()
2979 call feedkeys("\<C-W>12n", 'xt')
2980 call assert_equal(12, winheight(0))
2981endfunc
2982
2983" Test for 'b', 'B' 'ge' and 'gE' commands
Bram Moolenaar1671f442020-03-10 07:48:13 +01002984func Test_horiz_motion()
2985 new
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01002986 normal! gg
2987 call assert_beeps('normal! b')
2988 call assert_beeps('normal! B')
2989 call assert_beeps('normal! gE')
2990 call assert_beeps('normal! ge')
Bram Moolenaar1671f442020-03-10 07:48:13 +01002991 " <S-Backspace> moves one word left and <C-Backspace> moves one WORD left
2992 call setline(1, 'one ,two ,three')
2993 exe "normal! $\<S-BS>"
2994 call assert_equal(11, col('.'))
2995 exe "normal! $\<C-BS>"
2996 call assert_equal(10, col('.'))
2997 close!
2998endfunc
2999
3000" Test for using a : command in operator pending mode
3001func Test_normal_colon_op()
3002 new
3003 call setline(1, ['one', 'two'])
3004 call assert_beeps("normal! Gc:d\<CR>")
3005 close!
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01003006endfunc
3007
Bram Moolenaar004a6782020-04-11 17:09:31 +02003008" Test for d and D commands
3009func Test_normal_delete_cmd()
3010 new
3011 " D in an empty line
3012 call setline(1, '')
3013 normal D
3014 call assert_equal('', getline(1))
3015 " D in an empty line in virtualedit mode
3016 set virtualedit=all
3017 normal D
3018 call assert_equal('', getline(1))
3019 set virtualedit&
3020 " delete to a readonly register
3021 call setline(1, ['abcd'])
3022 call assert_beeps('normal ":d2l')
3023 close!
3024endfunc
3025
Bram Moolenaar224a5f12020-04-28 20:29:07 +02003026" Test for 'w' and 'b' commands
3027func Test_normal_word_move()
3028 new
3029 call setline(1, ['foo bar a', '', 'foo bar b'])
3030 " copy a single character word at the end of a line
3031 normal 1G$yw
3032 call assert_equal('a', @")
3033 " copy a single character word at the end of a file
3034 normal G$yw
3035 call assert_equal('b', @")
3036 " check for a word movement handling an empty line properly
3037 normal 1G$vwy
3038 call assert_equal("a\n\n", @")
3039
3040 " copy using 'b' command
3041 %d
3042 " non-empty blank line at the start of file
3043 call setline(1, [' ', 'foo bar'])
3044 normal 2Gyb
3045 call assert_equal(" \n", @")
3046 " try to copy backwards from the start of the file
3047 call setline(1, ['one two', 'foo bar'])
3048 call assert_beeps('normal ggyb')
3049 " 'b' command should stop at an empty line
3050 call setline(1, ['one two', '', 'foo bar'])
3051 normal 3Gyb
3052 call assert_equal("\n", @")
3053 normal 3Gy2b
3054 call assert_equal("two\n", @")
3055 " 'b' command should not stop at a non-empty blank line
3056 call setline(1, ['one two', ' ', 'foo bar'])
3057 normal 3Gyb
3058 call assert_equal("two\n ", @")
3059
3060 close!
3061endfunc
3062
Bram Moolenaarbdd2c292020-06-22 21:34:30 +02003063" Test for 'scrolloff' with a long line that doesn't fit in the screen
3064func Test_normal_scroloff()
3065 10new
3066 80vnew
3067 call setline(1, repeat('a', 1000))
3068 set scrolloff=10
3069 normal gg10gj
3070 call assert_equal(8, winline())
3071 normal 10gj
3072 call assert_equal(10, winline())
3073 normal 10gk
3074 call assert_equal(3, winline())
3075 set scrolloff&
3076 close!
3077endfunc
3078
3079" Test for vertical scrolling with CTRL-F and CTRL-B with a long line
3080func Test_normal_vert_scroll_longline()
3081 10new
3082 80vnew
3083 call setline(1, range(1, 10))
3084 call append(5, repeat('a', 1000))
3085 exe "normal gg\<C-F>"
3086 call assert_equal(6, line('.'))
3087 exe "normal \<C-F>\<C-F>"
3088 call assert_equal(11, line('.'))
3089 call assert_equal(1, winline())
3090 exe "normal \<C-B>"
3091 call assert_equal(10, line('.'))
3092 call assert_equal(3, winline())
3093 exe "normal \<C-B>\<C-B>"
3094 call assert_equal(5, line('.'))
3095 call assert_equal(5, winline())
3096 close!
3097endfunc
3098
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01003099" vim: shiftwidth=2 sts=2 expandtab