blob: d8afeea3eaa052138fc4b27a863419d6c6d3dda5 [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('.'))
141 " clean up
142 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +0200143endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200144
Bram Moolenaar1bbb6192018-11-10 16:02:01 +0100145func Test_normal04_filter()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200146 " basic filter test
147 " only test on non windows platform
Bram Moolenaar4a08b0d2016-11-05 21:55:13 +0100148 if has('win32')
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200149 return
150 endif
151 call Setup_NewWindow()
152 1
153 call feedkeys("!!sed -e 's/^/| /'\n", 'tx')
154 call assert_equal('| 1', getline('.'))
155 90
156 :sil :!echo one
157 call feedkeys('.', 'tx')
158 call assert_equal('| 90', getline('.'))
159 95
160 set cpo+=!
161 " 2 <CR>, 1: for executing the command,
162 " 2: clear hit-enter-prompt
163 call feedkeys("!!\n", 'tx')
164 call feedkeys(":!echo one\n\n", 'tx')
165 call feedkeys(".", 'tx')
166 call assert_equal('one', getline('.'))
167 set cpo-=!
168 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +0200169endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200170
Bram Moolenaar1bbb6192018-11-10 16:02:01 +0100171func Test_normal05_formatexpr()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200172 " basic formatexpr test
173 call Setup_NewWindow()
174 %d_
175 call setline(1, ['here: 1 ', '2', 'here: 3 ', '4', 'not here: '])
176 1
177 set formatexpr=MyFormatExpr()
178 norm! gqG
179 call assert_equal(['here: 1->$', '2', 'here: 3->$', '4', 'not here: '], getline(1,'$'))
180 set formatexpr=
181 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +0200182endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200183
Bram Moolenaard77f9d52016-09-04 15:13:39 +0200184func Test_normal05_formatexpr_newbuf()
185 " Edit another buffer in the 'formatexpr' function
186 new
187 func! Format()
188 edit another
189 endfunc
190 set formatexpr=Format()
191 norm gqG
192 bw!
193 set formatexpr=
194endfunc
195
196func Test_normal05_formatexpr_setopt()
197 " Change the 'formatexpr' value in the function
198 new
199 func! Format()
200 set formatexpr=
201 endfunc
202 set formatexpr=Format()
203 norm gqG
204 bw!
205 set formatexpr=
206endfunc
207
Bram Moolenaar1bbb6192018-11-10 16:02:01 +0100208func Test_normal06_formatprg()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200209 " basic test for formatprg
210 " only test on non windows platform
Bram Moolenaar4a08b0d2016-11-05 21:55:13 +0100211 if has('win32')
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200212 return
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200213 endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +0100214
215 " uses sed to number non-empty lines
216 call writefile(['#!/bin/sh', 'sed ''/./=''|sed ''/./{', 'N', 's/\n/ /', '}'''], 'Xsed_format.sh')
217 call system('chmod +x ./Xsed_format.sh')
218 let text = ['a', '', 'c', '', ' ', 'd', 'e']
219 let expected = ['1 a', '', '3 c', '', '5 ', '6 d', '7 e']
220
221 10new
222 call setline(1, text)
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200223 set formatprg=./Xsed_format.sh
224 norm! gggqG
Bram Moolenaar9be7c042017-01-14 14:28:30 +0100225 call assert_equal(expected, getline(1, '$'))
226 bw!
227
228 10new
229 call setline(1, text)
230 set formatprg=donothing
231 setlocal formatprg=./Xsed_format.sh
232 norm! gggqG
233 call assert_equal(expected, getline(1, '$'))
234 bw!
235
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200236 " clean up
237 set formatprg=
Bram Moolenaar9be7c042017-01-14 14:28:30 +0100238 setlocal formatprg=
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200239 call delete('Xsed_format.sh')
Bram Moolenaar2931f2a2016-09-09 16:59:08 +0200240endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200241
Bram Moolenaar1bbb6192018-11-10 16:02:01 +0100242func Test_normal07_internalfmt()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200243 " basic test for internal formmatter to textwidth of 12
244 let list=range(1,11)
245 call map(list, 'v:val." "')
246 10new
247 call setline(1, list)
248 set tw=12
249 norm! gggqG
250 call assert_equal(['1 2 3', '4 5 6', '7 8 9', '10 11 '], getline(1, '$'))
251 " clean up
Bram Moolenaar9be7c042017-01-14 14:28:30 +0100252 set tw=0
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200253 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +0200254endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200255
Bram Moolenaar1bbb6192018-11-10 16:02:01 +0100256func Test_normal08_fold()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200257 " basic tests for foldopen/folddelete
258 if !has("folding")
259 return
260 endif
261 call Setup_NewWindow()
262 50
263 setl foldenable fdm=marker
264 " First fold
265 norm! V4jzf
266 " check that folds have been created
267 call assert_equal(['50/*{{{*/', '51', '52', '53', '54/*}}}*/'], getline(50,54))
268 " Second fold
269 46
270 norm! V10jzf
271 " check that folds have been created
272 call assert_equal('46/*{{{*/', getline(46))
273 call assert_equal('60/*}}}*/', getline(60))
274 norm! k
275 call assert_equal('45', getline('.'))
276 norm! j
277 call assert_equal('46/*{{{*/', getline('.'))
278 norm! j
279 call assert_equal('61', getline('.'))
280 norm! k
281 " open a fold
282 norm! Vzo
283 norm! k
284 call assert_equal('45', getline('.'))
285 norm! j
286 call assert_equal('46/*{{{*/', getline('.'))
287 norm! j
288 call assert_equal('47', getline('.'))
289 norm! k
290 norm! zcVzO
291 call assert_equal('46/*{{{*/', getline('.'))
292 norm! j
293 call assert_equal('47', getline('.'))
294 norm! j
295 call assert_equal('48', getline('.'))
296 norm! j
297 call assert_equal('49', getline('.'))
298 norm! j
299 call assert_equal('50/*{{{*/', getline('.'))
300 norm! j
301 call assert_equal('51', getline('.'))
302 " delete folds
303 :46
304 " collapse fold
305 norm! V14jzC
306 " delete all folds recursively
307 norm! VzD
308 call assert_equal(['46', '47', '48', '49', '50', '51', '52', '53', '54', '55', '56', '57', '58', '59', '60'], getline(46,60))
309
310 " clean up
311 setl nofoldenable fdm=marker
312 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +0200313endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200314
Bram Moolenaar1bbb6192018-11-10 16:02:01 +0100315func Test_normal09_operatorfunc()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200316 " Test operatorfunc
317 call Setup_NewWindow()
318 " Add some spaces for counting
319 50,60s/$/ /
320 unlet! g:a
321 let g:a=0
322 nmap <buffer><silent> ,, :set opfunc=CountSpaces<CR>g@
323 vmap <buffer><silent> ,, :<C-U>call CountSpaces(visualmode(), 1)<CR>
324 50
325 norm V2j,,
326 call assert_equal(6, g:a)
327 norm V,,
328 call assert_equal(2, g:a)
329 norm ,,l
330 call assert_equal(0, g:a)
331 50
332 exe "norm 0\<c-v>10j2l,,"
333 call assert_equal(11, g:a)
334 50
335 norm V10j,,
336 call assert_equal(22, g:a)
337
338 " clean up
339 unmap <buffer> ,,
340 set opfunc=
Bram Moolenaar4a08b0d2016-11-05 21:55:13 +0100341 unlet! g:a
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200342 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +0200343endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200344
Bram Moolenaar1bbb6192018-11-10 16:02:01 +0100345func Test_normal09a_operatorfunc()
Bram Moolenaar4a08b0d2016-11-05 21:55:13 +0100346 " Test operatorfunc
347 call Setup_NewWindow()
348 " Add some spaces for counting
349 50,60s/$/ /
350 unlet! g:opt
351 set linebreak
352 nmap <buffer><silent> ,, :set opfunc=OpfuncDummy<CR>g@
353 50
354 norm ,,j
355 exe "bd!" g:bufnr
356 call assert_true(&linebreak)
357 call assert_equal(g:opt, &linebreak)
358 set nolinebreak
359 norm ,,j
360 exe "bd!" g:bufnr
361 call assert_false(&linebreak)
362 call assert_equal(g:opt, &linebreak)
363
364 " clean up
365 unmap <buffer> ,,
366 set opfunc=
Bram Moolenaaree4e0c12020-04-06 21:35:05 +0200367 call assert_fails('normal Vg@', 'E774:')
Bram Moolenaar4a08b0d2016-11-05 21:55:13 +0100368 bw!
369 unlet! g:opt
370endfunc
371
Bram Moolenaar1bbb6192018-11-10 16:02:01 +0100372func Test_normal10_expand()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200373 " Test for expand()
374 10new
375 call setline(1, ['1', 'ifooar,,cbar'])
376 2
377 norm! $
Bram Moolenaar65f08472017-09-10 18:16:20 +0200378 call assert_equal('cbar', expand('<cword>'))
379 call assert_equal('ifooar,,cbar', expand('<cWORD>'))
380
381 call setline(1, ['prx = list[idx];'])
382 1
383 let expected = ['', 'prx', 'prx', 'prx',
384 \ 'list', 'list', 'list', 'list', 'list', 'list', 'list',
385 \ 'idx', 'idx', 'idx', 'idx',
386 \ 'list[idx]',
387 \ '];',
388 \ ]
389 for i in range(1, 16)
390 exe 'norm ' . i . '|'
391 call assert_equal(expected[i], expand('<cexpr>'), 'i == ' . i)
392 endfor
393
Bram Moolenaarae6f8652017-12-20 22:32:20 +0100394 if executable('echo')
395 " Test expand(`...`) i.e. backticks command expansion.
Bram Moolenaar077ff432019-10-28 00:42:21 +0100396 call assert_equal('abcde', expand('`echo abcde`'))
Bram Moolenaarae6f8652017-12-20 22:32:20 +0100397 endif
398
399 " Test expand(`=...`) i.e. backticks expression expansion
400 call assert_equal('5', expand('`=2+3`'))
Bram Moolenaar8b633132020-03-20 18:20:51 +0100401 call assert_equal('3.14', expand('`=3.14`'))
Bram Moolenaarae6f8652017-12-20 22:32:20 +0100402
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200403 " clean up
404 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +0200405endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200406
Bram Moolenaar1bbb6192018-11-10 16:02:01 +0100407func Test_normal11_showcmd()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200408 " test for 'showcmd'
409 10new
410 exe "norm! ofoobar\<esc>"
411 call assert_equal(2, line('$'))
412 set showcmd
413 exe "norm! ofoobar2\<esc>"
414 call assert_equal(3, line('$'))
415 exe "norm! VAfoobar3\<esc>"
416 call assert_equal(3, line('$'))
417 exe "norm! 0d3\<del>2l"
418 call assert_equal('obar2foobar3', getline('.'))
419 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +0200420endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200421
Bram Moolenaar1671f442020-03-10 07:48:13 +0100422" Test for nv_error and normal command errors
Bram Moolenaar1bbb6192018-11-10 16:02:01 +0100423func Test_normal12_nv_error()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200424 10new
425 call setline(1, range(1,5))
426 " should not do anything, just beep
Bram Moolenaarf5f1e102020-03-08 05:13:15 +0100427 call assert_beeps('exe "norm! <c-k>"')
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200428 call assert_equal(map(range(1,5), 'string(v:val)'), getline(1,'$'))
Bram Moolenaarf5f1e102020-03-08 05:13:15 +0100429 call assert_beeps('normal! G2dd')
430 call assert_beeps("normal! g\<C-A>")
431 call assert_beeps("normal! g\<C-X>")
432 call assert_beeps("normal! g\<C-B>")
Bram Moolenaar1671f442020-03-10 07:48:13 +0100433 call assert_beeps("normal! vQ\<Esc>")
434 call assert_beeps("normal! 2[[")
435 call assert_beeps("normal! 2]]")
436 call assert_beeps("normal! 2[]")
437 call assert_beeps("normal! 2][")
438 call assert_beeps("normal! 4[z")
439 call assert_beeps("normal! 4]z")
440 call assert_beeps("normal! 4[c")
441 call assert_beeps("normal! 4]c")
442 call assert_beeps("normal! 200%")
443 call assert_beeps("normal! %")
444 call assert_beeps("normal! 2{")
445 call assert_beeps("normal! 2}")
446 call assert_beeps("normal! r\<Right>")
447 call assert_beeps("normal! 8ry")
448 call assert_beeps('normal! "@')
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200449 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +0200450endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200451
Bram Moolenaar1bbb6192018-11-10 16:02:01 +0100452func Test_normal13_help()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200453 " Test for F1
454 call assert_equal(1, winnr())
455 call feedkeys("\<f1>", 'txi')
456 call assert_match('help\.txt', bufname('%'))
457 call assert_equal(2, winnr('$'))
458 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +0200459endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200460
Bram Moolenaar1bbb6192018-11-10 16:02:01 +0100461func Test_normal14_page()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200462 " basic test for Ctrl-F and Ctrl-B
463 call Setup_NewWindow()
464 exe "norm! \<c-f>"
465 call assert_equal('9', getline('.'))
466 exe "norm! 2\<c-f>"
467 call assert_equal('25', getline('.'))
468 exe "norm! 2\<c-b>"
469 call assert_equal('18', getline('.'))
470 1
471 set scrolloff=5
472 exe "norm! 2\<c-f>"
473 call assert_equal('21', getline('.'))
474 exe "norm! \<c-b>"
475 call assert_equal('13', getline('.'))
476 1
477 set scrolloff=99
478 exe "norm! \<c-f>"
479 call assert_equal('13', getline('.'))
480 set scrolloff=0
481 100
482 exe "norm! $\<c-b>"
483 call assert_equal('92', getline('.'))
484 call assert_equal([0, 92, 1, 0, 1], getcurpos())
485 100
486 set nostartofline
487 exe "norm! $\<c-b>"
488 call assert_equal('92', getline('.'))
489 call assert_equal([0, 92, 2, 0, 2147483647], getcurpos())
490 " cleanup
491 set startofline
492 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +0200493endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200494
Bram Moolenaar1bbb6192018-11-10 16:02:01 +0100495func Test_normal14_page_eol()
Bram Moolenaarbc54f3f2016-09-04 14:34:28 +0200496 10new
497 norm oxxxxxxx
498 exe "norm 2\<c-f>"
499 " check with valgrind that cursor is put back in column 1
500 exe "norm 2\<c-b>"
501 bw!
502endfunc
503
Bram Moolenaar1671f442020-03-10 07:48:13 +0100504" Test for errors with z command
505func Test_normal_z_error()
506 call assert_beeps('normal! z2p')
507 call assert_beeps('normal! zp')
508endfunc
509
Bram Moolenaar1bbb6192018-11-10 16:02:01 +0100510func Test_normal15_z_scroll_vert()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200511 " basic test for z commands that scroll the window
512 call Setup_NewWindow()
513 100
514 norm! >>
515 " Test for z<cr>
516 exe "norm! z\<cr>"
517 call assert_equal(' 100', getline('.'))
518 call assert_equal(100, winsaveview()['topline'])
519 call assert_equal([0, 100, 2, 0, 9], getcurpos())
520
521 " Test for zt
522 21
523 norm! >>0zt
524 call assert_equal(' 21', getline('.'))
525 call assert_equal(21, winsaveview()['topline'])
526 call assert_equal([0, 21, 1, 0, 8], getcurpos())
527
528 " Test for zb
529 30
530 norm! >>$ztzb
531 call assert_equal(' 30', getline('.'))
532 call assert_equal(30, winsaveview()['topline']+winheight(0)-1)
533 call assert_equal([0, 30, 3, 0, 2147483647], getcurpos())
534
535 " Test for z-
536 1
537 30
538 norm! 0z-
539 call assert_equal(' 30', getline('.'))
540 call assert_equal(30, winsaveview()['topline']+winheight(0)-1)
541 call assert_equal([0, 30, 2, 0, 9], getcurpos())
542
543 " Test for z{height}<cr>
544 call assert_equal(10, winheight(0))
545 exe "norm! z12\<cr>"
546 call assert_equal(12, winheight(0))
547 exe "norm! z10\<cr>"
548 call assert_equal(10, winheight(0))
549
550 " Test for z.
551 1
552 21
553 norm! 0z.
554 call assert_equal(' 21', getline('.'))
555 call assert_equal(17, winsaveview()['topline'])
556 call assert_equal([0, 21, 2, 0, 9], getcurpos())
557
558 " Test for zz
559 1
560 21
561 norm! 0zz
562 call assert_equal(' 21', getline('.'))
563 call assert_equal(17, winsaveview()['topline'])
564 call assert_equal([0, 21, 1, 0, 8], getcurpos())
565
566 " Test for z+
567 11
568 norm! zt
569 norm! z+
570 call assert_equal(' 21', getline('.'))
571 call assert_equal(21, winsaveview()['topline'])
572 call assert_equal([0, 21, 2, 0, 9], getcurpos())
573
574 " Test for [count]z+
575 1
576 norm! 21z+
577 call assert_equal(' 21', getline('.'))
578 call assert_equal(21, winsaveview()['topline'])
579 call assert_equal([0, 21, 2, 0, 9], getcurpos())
580
581 " Test for z^
582 norm! 22z+0
583 norm! z^
584 call assert_equal(' 21', getline('.'))
585 call assert_equal(12, winsaveview()['topline'])
586 call assert_equal([0, 21, 2, 0, 9], getcurpos())
587
588 " Test for [count]z^
589 1
590 norm! 30z^
591 call assert_equal(' 21', getline('.'))
592 call assert_equal(12, winsaveview()['topline'])
593 call assert_equal([0, 21, 2, 0, 9], getcurpos())
594
595 " cleanup
596 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +0200597endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200598
Bram Moolenaar1bbb6192018-11-10 16:02:01 +0100599func Test_normal16_z_scroll_hor()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200600 " basic test for z commands that scroll the window
601 10new
602 15vsp
603 set nowrap listchars=
604 let lineA='abcdefghijklmnopqrstuvwxyz'
605 let lineB='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'
606 $put =lineA
607 $put =lineB
608 1d
609
Bram Moolenaar1671f442020-03-10 07:48:13 +0100610 " Test for zl and zh with a count
611 norm! 0z10l
612 call assert_equal([11, 1], [col('.'), wincol()])
613 norm! z4h
614 call assert_equal([11, 5], [col('.'), wincol()])
615 normal! 2gg
616
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200617 " Test for zl
618 1
619 norm! 5zl
620 call assert_equal(lineA, getline('.'))
621 call assert_equal(6, col('.'))
622 call assert_equal(5, winsaveview()['leftcol'])
623 norm! yl
624 call assert_equal('f', @0)
625
626 " Test for zh
627 norm! 2zh
628 call assert_equal(lineA, getline('.'))
629 call assert_equal(6, col('.'))
630 norm! yl
631 call assert_equal('f', @0)
632 call assert_equal(3, winsaveview()['leftcol'])
633
634 " Test for zL
635 norm! zL
636 call assert_equal(11, col('.'))
637 norm! yl
638 call assert_equal('k', @0)
639 call assert_equal(10, winsaveview()['leftcol'])
640 norm! 2zL
641 call assert_equal(25, col('.'))
642 norm! yl
643 call assert_equal('y', @0)
644 call assert_equal(24, winsaveview()['leftcol'])
645
646 " Test for zH
647 norm! 2zH
648 call assert_equal(25, col('.'))
649 call assert_equal(10, winsaveview()['leftcol'])
650 norm! yl
651 call assert_equal('y', @0)
652
653 " Test for zs
654 norm! $zs
655 call assert_equal(26, col('.'))
656 call assert_equal(25, winsaveview()['leftcol'])
657 norm! yl
658 call assert_equal('z', @0)
659
660 " Test for ze
661 norm! ze
662 call assert_equal(26, col('.'))
663 call assert_equal(11, winsaveview()['leftcol'])
664 norm! yl
665 call assert_equal('z', @0)
666
667 " cleanup
668 set wrap listchars=eol:$
669 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +0200670endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200671
Bram Moolenaar1bbb6192018-11-10 16:02:01 +0100672func Test_normal17_z_scroll_hor2()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200673 " basic test for z commands that scroll the window
674 " using 'sidescrolloff' setting
675 10new
676 20vsp
677 set nowrap listchars= sidescrolloff=5
678 let lineA='abcdefghijklmnopqrstuvwxyz'
679 let lineB='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'
680 $put =lineA
681 $put =lineB
682 1d
683
684 " Test for zl
685 1
686 norm! 5zl
687 call assert_equal(lineA, getline('.'))
688 call assert_equal(11, col('.'))
689 call assert_equal(5, winsaveview()['leftcol'])
690 norm! yl
691 call assert_equal('k', @0)
692
693 " Test for zh
694 norm! 2zh
695 call assert_equal(lineA, getline('.'))
696 call assert_equal(11, col('.'))
697 norm! yl
698 call assert_equal('k', @0)
699 call assert_equal(3, winsaveview()['leftcol'])
700
701 " Test for zL
702 norm! 0zL
703 call assert_equal(16, col('.'))
704 norm! yl
705 call assert_equal('p', @0)
706 call assert_equal(10, winsaveview()['leftcol'])
707 norm! 2zL
708 call assert_equal(26, col('.'))
709 norm! yl
710 call assert_equal('z', @0)
711 call assert_equal(15, winsaveview()['leftcol'])
712
713 " Test for zH
714 norm! 2zH
715 call assert_equal(15, col('.'))
716 call assert_equal(0, winsaveview()['leftcol'])
717 norm! yl
718 call assert_equal('o', @0)
719
720 " Test for zs
721 norm! $zs
722 call assert_equal(26, col('.'))
723 call assert_equal(20, winsaveview()['leftcol'])
724 norm! yl
725 call assert_equal('z', @0)
726
727 " Test for ze
728 norm! ze
729 call assert_equal(26, col('.'))
730 call assert_equal(11, winsaveview()['leftcol'])
731 norm! yl
732 call assert_equal('z', @0)
733
734 " cleanup
735 set wrap listchars=eol:$ sidescrolloff=0
736 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +0200737endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200738
Bram Moolenaar1671f442020-03-10 07:48:13 +0100739" Test for H, M and L commands with folds
740func Test_scroll_cmds()
741 15new
742 call setline(1, range(1, 100))
743 exe "normal! 30ggz\<CR>"
744 set foldenable
745 33,36fold
746 40,43fold
747 46,49fold
748 let h = winheight(0)
749 " Top of the screen = 30
750 " Folded lines = 9
751 " Bottom of the screen = 30 + h + 9 - 1
752 normal! 4L
753 call assert_equal(35 + h, line('.'))
754 normal! 4H
755 call assert_equal(33, line('.'))
756 set foldenable&
757 close!
758endfunc
759
Bram Moolenaar1bbb6192018-11-10 16:02:01 +0100760func Test_normal18_z_fold()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200761 " basic tests for foldopen/folddelete
762 if !has("folding")
763 return
764 endif
765 call Setup_NewWindow()
766 50
767 setl foldenable fdm=marker foldlevel=5
768
Bram Moolenaar1671f442020-03-10 07:48:13 +0100769 call assert_beeps('normal! zj')
770 call assert_beeps('normal! zk')
771
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200772 " Test for zF
773 " First fold
774 norm! 4zF
775 " check that folds have been created
776 call assert_equal(['50/*{{{*/', '51', '52', '53/*}}}*/'], getline(50,53))
777
778 " Test for zd
779 51
780 norm! 2zF
781 call assert_equal(2, foldlevel('.'))
782 norm! kzd
783 call assert_equal(['50', '51/*{{{*/', '52/*}}}*/', '53'], getline(50,53))
784 norm! j
785 call assert_equal(1, foldlevel('.'))
786
787 " Test for zD
788 " also deletes partially selected folds recursively
789 51
790 norm! zF
791 call assert_equal(2, foldlevel('.'))
792 norm! kV2jzD
793 call assert_equal(['50', '51', '52', '53'], getline(50,53))
794
795 " Test for zE
796 85
797 norm! 4zF
798 86
799 norm! 2zF
800 90
801 norm! 4zF
802 call assert_equal(['85/*{{{*/', '86/*{{{*/', '87/*}}}*/', '88/*}}}*/', '89', '90/*{{{*/', '91', '92', '93/*}}}*/'], getline(85,93))
803 norm! zE
804 call assert_equal(['85', '86', '87', '88', '89', '90', '91', '92', '93'], getline(85,93))
805
806 " Test for zn
807 50
808 set foldlevel=0
809 norm! 2zF
810 norm! zn
811 norm! k
812 call assert_equal('49', getline('.'))
813 norm! j
814 call assert_equal('50/*{{{*/', getline('.'))
815 norm! j
816 call assert_equal('51/*}}}*/', getline('.'))
817 norm! j
818 call assert_equal('52', getline('.'))
819 call assert_equal(0, &foldenable)
820
821 " Test for zN
822 49
823 norm! zN
824 call assert_equal('49', getline('.'))
825 norm! j
826 call assert_equal('50/*{{{*/', getline('.'))
827 norm! j
828 call assert_equal('52', getline('.'))
829 call assert_equal(1, &foldenable)
830
831 " Test for zi
832 norm! zi
833 call assert_equal(0, &foldenable)
834 norm! zi
835 call assert_equal(1, &foldenable)
836 norm! zi
837 call assert_equal(0, &foldenable)
838 norm! zi
839 call assert_equal(1, &foldenable)
840
841 " Test for za
842 50
843 norm! za
844 norm! k
845 call assert_equal('49', getline('.'))
846 norm! j
847 call assert_equal('50/*{{{*/', getline('.'))
848 norm! j
849 call assert_equal('51/*}}}*/', getline('.'))
850 norm! j
851 call assert_equal('52', getline('.'))
852 50
853 norm! za
854 norm! k
855 call assert_equal('49', getline('.'))
856 norm! j
857 call assert_equal('50/*{{{*/', getline('.'))
858 norm! j
859 call assert_equal('52', getline('.'))
860
861 49
862 norm! 5zF
863 norm! k
864 call assert_equal('48', getline('.'))
865 norm! j
866 call assert_equal('49/*{{{*/', getline('.'))
867 norm! j
868 call assert_equal('55', getline('.'))
869 49
870 norm! za
871 call assert_equal('49/*{{{*/', getline('.'))
872 norm! j
873 call assert_equal('50/*{{{*/', getline('.'))
874 norm! j
875 call assert_equal('52', getline('.'))
876 set nofoldenable
877 " close fold and set foldenable
878 norm! za
879 call assert_equal(1, &foldenable)
880
881 50
882 " have to use {count}za to open all folds and make the cursor visible
883 norm! 2za
884 norm! 2k
885 call assert_equal('48', getline('.'))
886 norm! j
887 call assert_equal('49/*{{{*/', getline('.'))
888 norm! j
889 call assert_equal('50/*{{{*/', getline('.'))
890 norm! j
891 call assert_equal('51/*}}}*/', getline('.'))
892 norm! j
893 call assert_equal('52', getline('.'))
894
895 " Test for zA
896 49
897 set foldlevel=0
898 50
899 norm! zA
900 norm! 2k
901 call assert_equal('48', getline('.'))
902 norm! j
903 call assert_equal('49/*{{{*/', getline('.'))
904 norm! j
905 call assert_equal('50/*{{{*/', getline('.'))
906 norm! j
907 call assert_equal('51/*}}}*/', getline('.'))
908 norm! j
909 call assert_equal('52', getline('.'))
910
Bram Moolenaar395b6ba2017-04-07 20:09:51 +0200911 " zA on a opened fold when foldenable is not set
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200912 50
913 set nofoldenable
914 norm! zA
915 call assert_equal(1, &foldenable)
916 norm! k
917 call assert_equal('48', getline('.'))
918 norm! j
919 call assert_equal('49/*{{{*/', getline('.'))
920 norm! j
921 call assert_equal('55', getline('.'))
922
923 " Test for zc
924 norm! zE
925 50
926 norm! 2zF
927 49
928 norm! 5zF
929 set nofoldenable
930 50
931 " There most likely is a bug somewhere:
932 " https://groups.google.com/d/msg/vim_dev/v2EkfJ_KQjI/u-Cvv94uCAAJ
933 " TODO: Should this only close the inner most fold or both folds?
934 norm! zc
935 call assert_equal(1, &foldenable)
936 norm! k
937 call assert_equal('48', getline('.'))
938 norm! j
939 call assert_equal('49/*{{{*/', getline('.'))
940 norm! j
941 call assert_equal('55', getline('.'))
942 set nofoldenable
943 50
944 norm! Vjzc
945 norm! k
946 call assert_equal('48', getline('.'))
947 norm! j
948 call assert_equal('49/*{{{*/', getline('.'))
949 norm! j
950 call assert_equal('55', getline('.'))
951
952 " Test for zC
953 set nofoldenable
954 50
955 norm! zCk
956 call assert_equal('48', getline('.'))
957 norm! j
958 call assert_equal('49/*{{{*/', getline('.'))
959 norm! j
960 call assert_equal('55', getline('.'))
961
962 " Test for zx
963 " 1) close folds at line 49-54
964 set nofoldenable
965 48
966 norm! zx
967 call assert_equal(1, &foldenable)
968 norm! j
969 call assert_equal('49/*{{{*/', getline('.'))
970 norm! j
971 call assert_equal('55', getline('.'))
972
Bram Moolenaar395b6ba2017-04-07 20:09:51 +0200973 " 2) do not close fold under cursor
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200974 51
975 set nofoldenable
976 norm! zx
977 call assert_equal(1, &foldenable)
978 norm! 3k
979 call assert_equal('48', getline('.'))
980 norm! j
981 call assert_equal('49/*{{{*/', getline('.'))
982 norm! j
983 call assert_equal('50/*{{{*/', getline('.'))
984 norm! j
985 call assert_equal('51/*}}}*/', getline('.'))
986 norm! j
987 call assert_equal('52', getline('.'))
988 norm! j
989 call assert_equal('53', getline('.'))
990 norm! j
991 call assert_equal('54/*}}}*/', getline('.'))
992 norm! j
993 call assert_equal('55', getline('.'))
994
995 " 3) close one level of folds
996 48
997 set nofoldenable
998 set foldlevel=1
999 norm! zx
1000 call assert_equal(1, &foldenable)
1001 call assert_equal('48', getline('.'))
1002 norm! j
1003 call assert_equal('49/*{{{*/', getline('.'))
1004 norm! j
1005 call assert_equal('50/*{{{*/', getline('.'))
1006 norm! j
1007 call assert_equal('52', getline('.'))
1008 norm! j
1009 call assert_equal('53', getline('.'))
1010 norm! j
1011 call assert_equal('54/*}}}*/', getline('.'))
1012 norm! j
1013 call assert_equal('55', getline('.'))
1014
1015 " Test for zX
1016 " Close all folds
1017 set foldlevel=0 nofoldenable
1018 50
1019 norm! zX
1020 call assert_equal(1, &foldenable)
1021 norm! k
1022 call assert_equal('48', getline('.'))
1023 norm! j
1024 call assert_equal('49/*{{{*/', getline('.'))
1025 norm! j
1026 call assert_equal('55', getline('.'))
1027
1028 " Test for zm
1029 50
1030 set nofoldenable foldlevel=2
1031 norm! zm
1032 call assert_equal(1, &foldenable)
1033 call assert_equal(1, &foldlevel)
1034 norm! zm
1035 call assert_equal(0, &foldlevel)
1036 norm! zm
1037 call assert_equal(0, &foldlevel)
1038 norm! k
1039 call assert_equal('48', getline('.'))
1040 norm! j
1041 call assert_equal('49/*{{{*/', getline('.'))
1042 norm! j
1043 call assert_equal('55', getline('.'))
1044
1045 " Test for zM
1046 48
1047 set nofoldenable foldlevel=99
1048 norm! zM
1049 call assert_equal(1, &foldenable)
1050 call assert_equal(0, &foldlevel)
1051 call assert_equal('48', getline('.'))
1052 norm! j
1053 call assert_equal('49/*{{{*/', getline('.'))
1054 norm! j
1055 call assert_equal('55', getline('.'))
1056
1057 " Test for zr
1058 48
1059 set nofoldenable foldlevel=0
1060 norm! zr
1061 call assert_equal(0, &foldenable)
1062 call assert_equal(1, &foldlevel)
1063 set foldlevel=0 foldenable
1064 norm! zr
1065 call assert_equal(1, &foldenable)
1066 call assert_equal(1, &foldlevel)
1067 norm! zr
1068 call assert_equal(2, &foldlevel)
1069 call assert_equal('48', getline('.'))
1070 norm! j
1071 call assert_equal('49/*{{{*/', getline('.'))
1072 norm! j
1073 call assert_equal('50/*{{{*/', getline('.'))
1074 norm! j
1075 call assert_equal('51/*}}}*/', getline('.'))
1076 norm! j
1077 call assert_equal('52', getline('.'))
1078
1079 " Test for zR
1080 48
1081 set nofoldenable foldlevel=0
1082 norm! zR
1083 call assert_equal(0, &foldenable)
1084 call assert_equal(2, &foldlevel)
1085 set foldenable foldlevel=0
1086 norm! zR
1087 call assert_equal(1, &foldenable)
1088 call assert_equal(2, &foldlevel)
1089 call assert_equal('48', getline('.'))
1090 norm! j
1091 call assert_equal('49/*{{{*/', getline('.'))
1092 norm! j
1093 call assert_equal('50/*{{{*/', getline('.'))
1094 norm! j
1095 call assert_equal('51/*}}}*/', getline('.'))
1096 norm! j
1097 call assert_equal('52', getline('.'))
1098 call append(50, ['a /*{{{*/', 'b /*}}}*/'])
1099 48
1100 call assert_equal('48', getline('.'))
1101 norm! j
1102 call assert_equal('49/*{{{*/', getline('.'))
1103 norm! j
1104 call assert_equal('50/*{{{*/', getline('.'))
1105 norm! j
1106 call assert_equal('a /*{{{*/', getline('.'))
1107 norm! j
1108 call assert_equal('51/*}}}*/', getline('.'))
1109 norm! j
1110 call assert_equal('52', getline('.'))
1111 48
1112 norm! zR
1113 call assert_equal(1, &foldenable)
1114 call assert_equal(3, &foldlevel)
1115 call assert_equal('48', getline('.'))
1116 norm! j
1117 call assert_equal('49/*{{{*/', getline('.'))
1118 norm! j
1119 call assert_equal('50/*{{{*/', getline('.'))
1120 norm! j
1121 call assert_equal('a /*{{{*/', getline('.'))
1122 norm! j
1123 call assert_equal('b /*}}}*/', getline('.'))
1124 norm! j
1125 call assert_equal('51/*}}}*/', getline('.'))
1126 norm! j
1127 call assert_equal('52', getline('.'))
1128
1129 " clean up
1130 setl nofoldenable fdm=marker foldlevel=0
1131 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02001132endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001133
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01001134func Test_normal20_exmode()
Bram Moolenaar0913a102016-09-03 19:11:59 +02001135 if !has("unix")
1136 " Reading from redirected file doesn't work on MS-Windows
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001137 return
1138 endif
1139 call writefile(['1a', 'foo', 'bar', '.', 'w! Xfile2', 'q!'], 'Xscript')
1140 call writefile(['1', '2'], 'Xfile')
Bram Moolenaar93344c22019-08-14 21:12:05 +02001141 call system(GetVimCommand() .. ' -e -s < Xscript Xfile')
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001142 let a=readfile('Xfile2')
1143 call assert_equal(['1', 'foo', 'bar', '2'], a)
1144
1145 " clean up
1146 for file in ['Xfile', 'Xfile2', 'Xscript']
1147 call delete(file)
1148 endfor
1149 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02001150endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001151
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01001152func Test_normal21_nv_hat()
1153
1154 " Edit a fresh file and wipe the buffer list so that there is no alternate
1155 " file present. Next, check for the expected command failures.
1156 edit Xfoo | %bw
1157 call assert_fails(':buffer #', 'E86')
1158 call assert_fails(':execute "normal! \<C-^>"', 'E23')
1159
1160 " Test for the expected behavior when switching between two named buffers.
1161 edit Xfoo | edit Xbar
1162 call feedkeys("\<C-^>", 'tx')
1163 call assert_equal('Xfoo', fnamemodify(bufname('%'), ':t'))
1164 call feedkeys("\<C-^>", 'tx')
1165 call assert_equal('Xbar', fnamemodify(bufname('%'), ':t'))
1166
1167 " Test for the expected behavior when only one buffer is named.
1168 enew | let l:nr = bufnr('%')
1169 call feedkeys("\<C-^>", 'tx')
1170 call assert_equal('Xbar', fnamemodify(bufname('%'), ':t'))
1171 call feedkeys("\<C-^>", 'tx')
1172 call assert_equal('', bufname('%'))
1173 call assert_equal(l:nr, bufnr('%'))
1174
1175 " Test that no action is taken by "<C-^>" when an operator is pending.
1176 edit Xfoo
1177 call feedkeys("ci\<C-^>", 'tx')
1178 call assert_equal('Xfoo', fnamemodify(bufname('%'), ':t'))
1179
1180 %bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02001181endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001182
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01001183func Test_normal22_zet()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001184 " Test for ZZ
Bram Moolenaar0913a102016-09-03 19:11:59 +02001185 " let shell = &shell
1186 " let &shell = 'sh'
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001187 call writefile(['1', '2'], 'Xfile')
Bram Moolenaar93344c22019-08-14 21:12:05 +02001188 let args = ' -N -i NONE --noplugins -X --not-a-term'
1189 call system(GetVimCommand() .. args .. ' -c "%d" -c ":norm! ZZ" Xfile')
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001190 let a = readfile('Xfile')
1191 call assert_equal([], a)
1192 " Test for ZQ
1193 call writefile(['1', '2'], 'Xfile')
Bram Moolenaar93344c22019-08-14 21:12:05 +02001194 call system(GetVimCommand() . args . ' -c "%d" -c ":norm! ZQ" Xfile')
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001195 let a = readfile('Xfile')
1196 call assert_equal(['1', '2'], a)
1197
Bram Moolenaar1671f442020-03-10 07:48:13 +01001198 " Unsupported Z command
1199 call assert_beeps('normal! ZW')
1200
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001201 " clean up
1202 for file in ['Xfile']
1203 call delete(file)
1204 endfor
Bram Moolenaar0913a102016-09-03 19:11:59 +02001205 " let &shell = shell
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02001206endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001207
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01001208func Test_normal23_K()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001209 " Test for K command
1210 new
Bram Moolenaar426f3752016-11-04 21:22:37 +01001211 call append(0, ['version8.txt', 'man', 'aa%bb', 'cc|dd'])
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001212 let k = &keywordprg
1213 set keywordprg=:help
1214 1
1215 norm! VK
1216 call assert_equal('version8.txt', fnamemodify(bufname('%'), ':t'))
1217 call assert_equal('help', &ft)
1218 call assert_match('\*version8.txt\*', getline('.'))
1219 helpclose
1220 norm! 0K
1221 call assert_equal('version8.txt', fnamemodify(bufname('%'), ':t'))
1222 call assert_equal('help', &ft)
Bram Moolenaarb1c91982018-05-17 17:04:55 +02001223 call assert_match('\*version8\.\d\*', getline('.'))
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001224 helpclose
1225
Bram Moolenaar426f3752016-11-04 21:22:37 +01001226 set keywordprg=:new
1227 set iskeyword+=%
1228 set iskeyword+=\|
1229 2
1230 norm! K
1231 call assert_equal('man', fnamemodify(bufname('%'), ':t'))
1232 bwipe!
1233 3
1234 norm! K
1235 call assert_equal('aa%bb', fnamemodify(bufname('%'), ':t'))
1236 bwipe!
Bram Moolenaareb828d02016-11-05 19:54:01 +01001237 if !has('win32')
1238 4
1239 norm! K
1240 call assert_equal('cc|dd', fnamemodify(bufname('%'), ':t'))
1241 bwipe!
1242 endif
Bram Moolenaar426f3752016-11-04 21:22:37 +01001243 set iskeyword-=%
1244 set iskeyword-=\|
1245
Bram Moolenaar0913a102016-09-03 19:11:59 +02001246 " Only expect "man" to work on Unix
1247 if !has("unix")
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001248 let &keywordprg = k
1249 bw!
1250 return
1251 endif
Bram Moolenaarc6b37db2019-04-27 18:00:34 +02001252
Bram Moolenaar9134f1e2019-11-29 20:26:13 +01001253 let not_gnu_man = has('mac') || has('bsd')
1254 if not_gnu_man
Bram Moolenaarc7d2a572019-11-28 21:16:06 +01001255 " In MacOS and BSD, the option for specifying a pager is different
Bram Moolenaarc6b37db2019-04-27 18:00:34 +02001256 set keywordprg=man\ -P\ cat
1257 else
1258 set keywordprg=man\ --pager=cat
1259 endif
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001260 " Test for using man
1261 2
1262 let a = execute('unsilent norm! K')
Bram Moolenaar9134f1e2019-11-29 20:26:13 +01001263 if not_gnu_man
Bram Moolenaarc6b37db2019-04-27 18:00:34 +02001264 call assert_match("man -P cat 'man'", a)
1265 else
1266 call assert_match("man --pager=cat 'man'", a)
1267 endif
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001268
Bram Moolenaar1671f442020-03-10 07:48:13 +01001269 " Error cases
1270 call setline(1, '#$#')
1271 call assert_fails('normal! ggK', 'E349:')
1272 call setline(1, '---')
1273 call assert_fails('normal! ggv2lK', 'E349:')
1274 call setline(1, ['abc', 'xyz'])
1275 call assert_fails("normal! gg2lv2h\<C-]>", 'E426:')
1276 call assert_beeps("normal! ggVjK")
1277
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001278 " clean up
1279 let &keywordprg = k
1280 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02001281endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001282
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01001283func Test_normal24_rot13()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001284 " Testing for g?? g?g?
1285 new
1286 call append(0, 'abcdefghijklmnopqrstuvwxyzäüö')
1287 1
1288 norm! g??
1289 call assert_equal('nopqrstuvwxyzabcdefghijklmäüö', getline('.'))
1290 norm! g?g?
1291 call assert_equal('abcdefghijklmnopqrstuvwxyzäüö', getline('.'))
1292
1293 " clean up
1294 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02001295endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001296
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01001297func Test_normal25_tag()
Bram Moolenaar5a4c3082019-12-01 15:23:11 +01001298 CheckFeature quickfix
1299
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001300 " Testing for CTRL-] g CTRL-] g]
1301 " CTRL-W g] CTRL-W CTRL-] CTRL-W g CTRL-]
1302 h
1303 " Test for CTRL-]
1304 call search('\<x\>$')
1305 exe "norm! \<c-]>"
1306 call assert_equal("change.txt", fnamemodify(bufname('%'), ':t'))
1307 norm! yiW
1308 call assert_equal("*x*", @0)
1309 exe ":norm \<c-o>"
1310
1311 " Test for g_CTRL-]
1312 call search('\<v_u\>$')
1313 exe "norm! g\<c-]>"
1314 call assert_equal("change.txt", fnamemodify(bufname('%'), ':t'))
1315 norm! yiW
1316 call assert_equal("*v_u*", @0)
1317 exe ":norm \<c-o>"
1318
1319 " Test for g]
1320 call search('\<i_<Esc>$')
1321 let a = execute(":norm! g]")
1322 call assert_match('i_<Esc>.*insert.txt', a)
1323
1324 if !empty(exepath('cscope')) && has('cscope')
1325 " setting cscopetag changes how g] works
1326 set cst
1327 exe "norm! g]"
1328 call assert_equal("insert.txt", fnamemodify(bufname('%'), ':t'))
1329 norm! yiW
1330 call assert_equal("*i_<Esc>*", @0)
1331 exe ":norm \<c-o>"
1332 " Test for CTRL-W g]
1333 exe "norm! \<C-W>g]"
1334 call assert_equal("insert.txt", fnamemodify(bufname('%'), ':t'))
1335 norm! yiW
1336 call assert_equal("*i_<Esc>*", @0)
1337 call assert_equal(3, winnr('$'))
1338 helpclose
1339 set nocst
1340 endif
1341
1342 " Test for CTRL-W g]
1343 let a = execute("norm! \<C-W>g]")
1344 call assert_match('i_<Esc>.*insert.txt', a)
1345
1346 " Test for CTRL-W CTRL-]
1347 exe "norm! \<C-W>\<C-]>"
1348 call assert_equal("insert.txt", fnamemodify(bufname('%'), ':t'))
1349 norm! yiW
1350 call assert_equal("*i_<Esc>*", @0)
1351 call assert_equal(3, winnr('$'))
1352 helpclose
1353
1354 " Test for CTRL-W g CTRL-]
1355 exe "norm! \<C-W>g\<C-]>"
1356 call assert_equal("insert.txt", fnamemodify(bufname('%'), ':t'))
1357 norm! yiW
1358 call assert_equal("*i_<Esc>*", @0)
1359 call assert_equal(3, winnr('$'))
1360 helpclose
1361
1362 " clean up
1363 helpclose
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02001364endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001365
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01001366func Test_normal26_put()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001367 " Test for ]p ]P [p and [P
1368 new
1369 call append(0, ['while read LINE', 'do', ' ((count++))', ' if [ $? -ne 0 ]; then', " echo 'Error writing file'", ' fi', 'done'])
1370 1
1371 /Error/y a
1372 2
1373 norm! "a]pj"a[p
1374 call assert_equal(['do', "echo 'Error writing file'", " echo 'Error writing file'", ' ((count++))'], getline(2,5))
1375 1
1376 /^\s\{4}/
1377 exe "norm! \"a]P3Eldt'"
1378 exe "norm! j\"a[P2Eldt'"
1379 call assert_equal([' if [ $? -ne 0 ]; then', " echo 'Error writing'", " echo 'Error'", " echo 'Error writing file'", ' fi'], getline(6,10))
1380
1381 " clean up
1382 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02001383endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001384
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01001385func Test_normal27_bracket()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001386 " Test for [' [` ]' ]`
1387 call Setup_NewWindow()
1388 1,21s/.\+/ & b/
1389 1
1390 norm! $ma
1391 5
1392 norm! $mb
1393 10
1394 norm! $mc
1395 15
1396 norm! $md
1397 20
1398 norm! $me
1399
1400 " Test for ['
1401 9
1402 norm! 2['
1403 call assert_equal(' 1 b', getline('.'))
1404 call assert_equal(1, line('.'))
1405 call assert_equal(3, col('.'))
1406
1407 " Test for ]'
1408 norm! ]'
1409 call assert_equal(' 5 b', getline('.'))
1410 call assert_equal(5, line('.'))
1411 call assert_equal(3, col('.'))
1412
1413 " No mark after line 21, cursor moves to first non blank on current line
1414 21
1415 norm! $]'
1416 call assert_equal(' 21 b', getline('.'))
1417 call assert_equal(21, line('.'))
1418 call assert_equal(3, col('.'))
1419
1420 " Test for [`
1421 norm! 2[`
1422 call assert_equal(' 15 b', getline('.'))
1423 call assert_equal(15, line('.'))
1424 call assert_equal(8, col('.'))
1425
1426 " Test for ]`
1427 norm! ]`
1428 call assert_equal(' 20 b', getline('.'))
1429 call assert_equal(20, line('.'))
1430 call assert_equal(8, col('.'))
1431
1432 " clean up
1433 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02001434endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001435
Bram Moolenaar1671f442020-03-10 07:48:13 +01001436" Test for ( and ) sentence movements
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01001437func Test_normal28_parenthesis()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001438 new
1439 call append(0, ['This is a test. With some sentences!', '', 'Even with a question? And one more. And no sentence here'])
1440
1441 $
1442 norm! d(
1443 call assert_equal(['This is a test. With some sentences!', '', 'Even with a question? And one more. ', ''], getline(1, '$'))
1444 norm! 2d(
1445 call assert_equal(['This is a test. With some sentences!', '', ' ', ''], getline(1, '$'))
1446 1
1447 norm! 0d)
1448 call assert_equal(['With some sentences!', '', ' ', ''], getline(1, '$'))
1449
1450 call append('$', ['This is a long sentence', '', 'spanning', 'over several lines. '])
1451 $
1452 norm! $d(
1453 call assert_equal(['With some sentences!', '', ' ', '', 'This is a long sentence', ''], getline(1, '$'))
1454
Bram Moolenaar1671f442020-03-10 07:48:13 +01001455 " It is an error if a next sentence is not found
1456 %d
1457 call setline(1, '.SH')
1458 call assert_beeps('normal )')
1459
1460 " Jumping to a fold should open the fold
1461 call setline(1, ['', '', 'one', 'two', 'three'])
1462 set foldenable
1463 2,$fold
1464 call feedkeys(')', 'xt')
1465 call assert_equal(3, line('.'))
1466 call assert_equal(1, foldlevel('.'))
1467 call assert_equal(-1, foldclosed('.'))
1468 set foldenable&
1469
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001470 " clean up
1471 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02001472endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001473
Bram Moolenaar1671f442020-03-10 07:48:13 +01001474" Test for { and } paragraph movements
1475func Test_normal29_brace()
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001476 let text =<< trim [DATA]
Bram Moolenaare7eb9272019-06-24 00:58:07 +02001477 A paragraph begins after each empty line, and also at each of a set of
1478 paragraph macros, specified by the pairs of characters in the 'paragraphs'
1479 option. The default is "IPLPPPQPP TPHPLIPpLpItpplpipbp", which corresponds to
1480 the macros ".IP", ".LP", etc. (These are nroff macros, so the dot must be in
1481 the first column). A section boundary is also a paragraph boundary.
1482 Note that a blank line (only containing white space) is NOT a paragraph
1483 boundary.
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001484
1485
Bram Moolenaare7eb9272019-06-24 00:58:07 +02001486 Also note that this does not include a '{' or '}' in the first column. When
1487 the '{' flag is in 'cpoptions' then '{' in the first column is used as a
1488 paragraph boundary |posix|.
1489 {
1490 This is no paragraph
1491 unless the '{' is set
1492 in 'cpoptions'
1493 }
1494 .IP
1495 The nroff macros IP separates a paragraph
1496 That means, it must be a '.'
1497 followed by IP
1498 .LPIt does not matter, if afterwards some
1499 more characters follow.
1500 .SHAlso section boundaries from the nroff
1501 macros terminate a paragraph. That means
1502 a character like this:
1503 .NH
1504 End of text here
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001505 [DATA]
1506
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001507 new
1508 call append(0, text)
1509 1
1510 norm! 0d2}
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001511
1512 let expected =<< trim [DATA]
Bram Moolenaare7eb9272019-06-24 00:58:07 +02001513 .IP
1514 The nroff macros IP separates a paragraph
1515 That means, it must be a '.'
1516 followed by IP
1517 .LPIt does not matter, if afterwards some
1518 more characters follow.
1519 .SHAlso section boundaries from the nroff
1520 macros terminate a paragraph. That means
1521 a character like this:
1522 .NH
1523 End of text here
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001524
1525 [DATA]
1526 call assert_equal(expected, getline(1, '$'))
1527
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001528 norm! 0d}
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001529
1530 let expected =<< trim [DATA]
Bram Moolenaare7eb9272019-06-24 00:58:07 +02001531 .LPIt does not matter, if afterwards some
1532 more characters follow.
1533 .SHAlso section boundaries from the nroff
1534 macros terminate a paragraph. That means
1535 a character like this:
1536 .NH
1537 End of text here
1538
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001539 [DATA]
1540 call assert_equal(expected, getline(1, '$'))
1541
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001542 $
1543 norm! d{
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001544
1545 let expected =<< trim [DATA]
Bram Moolenaare7eb9272019-06-24 00:58:07 +02001546 .LPIt does not matter, if afterwards some
1547 more characters follow.
1548 .SHAlso section boundaries from the nroff
1549 macros terminate a paragraph. That means
1550 a character like this:
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001551
1552 [DATA]
1553 call assert_equal(expected, getline(1, '$'))
1554
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001555 norm! d{
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001556
1557 let expected =<< trim [DATA]
Bram Moolenaare7eb9272019-06-24 00:58:07 +02001558 .LPIt does not matter, if afterwards some
1559 more characters follow.
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001560
1561 [DATA]
1562 call assert_equal(expected, getline(1, '$'))
1563
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001564 " Test with { in cpooptions
1565 %d
1566 call append(0, text)
1567 set cpo+={
1568 1
1569 norm! 0d2}
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001570
1571 let expected =<< trim [DATA]
Bram Moolenaare7eb9272019-06-24 00:58:07 +02001572 {
1573 This is no paragraph
1574 unless the '{' is set
1575 in 'cpoptions'
1576 }
1577 .IP
1578 The nroff macros IP separates a paragraph
1579 That means, it must be a '.'
1580 followed by IP
1581 .LPIt does not matter, if afterwards some
1582 more characters follow.
1583 .SHAlso section boundaries from the nroff
1584 macros terminate a paragraph. That means
1585 a character like this:
1586 .NH
1587 End of text here
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001588
1589 [DATA]
1590 call assert_equal(expected, getline(1, '$'))
1591
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001592 $
1593 norm! d}
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001594
1595 let expected =<< trim [DATA]
Bram Moolenaare7eb9272019-06-24 00:58:07 +02001596 {
1597 This is no paragraph
1598 unless the '{' is set
1599 in 'cpoptions'
1600 }
1601 .IP
1602 The nroff macros IP separates a paragraph
1603 That means, it must be a '.'
1604 followed by IP
1605 .LPIt does not matter, if afterwards some
1606 more characters follow.
1607 .SHAlso section boundaries from the nroff
1608 macros terminate a paragraph. That means
1609 a character like this:
1610 .NH
1611 End of text here
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001612
1613 [DATA]
1614 call assert_equal(expected, getline(1, '$'))
1615
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001616 norm! gg}
1617 norm! d5}
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001618
1619 let expected =<< trim [DATA]
Bram Moolenaare7eb9272019-06-24 00:58:07 +02001620 {
1621 This is no paragraph
1622 unless the '{' is set
1623 in 'cpoptions'
1624 }
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001625
1626 [DATA]
1627 call assert_equal(expected, getline(1, '$'))
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001628
Bram Moolenaar1671f442020-03-10 07:48:13 +01001629 " Jumping to a fold should open the fold
1630 %d
1631 call setline(1, ['', 'one', 'two', ''])
1632 set foldenable
1633 2,$fold
1634 call feedkeys('}', 'xt')
1635 call assert_equal(4, line('.'))
1636 call assert_equal(1, foldlevel('.'))
1637 call assert_equal(-1, foldclosed('.'))
1638 set foldenable&
1639
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001640 " clean up
1641 set cpo-={
1642 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02001643endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001644
Bram Moolenaar1671f442020-03-10 07:48:13 +01001645" Test for ~ command
1646func Test_normal30_changecase()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001647 new
1648 call append(0, 'This is a simple test: äüöß')
1649 norm! 1ggVu
1650 call assert_equal('this is a simple test: äüöß', getline('.'))
1651 norm! VU
1652 call assert_equal('THIS IS A SIMPLE TEST: ÄÜÖSS', getline('.'))
1653 norm! guu
1654 call assert_equal('this is a simple test: äüöss', getline('.'))
1655 norm! gUgU
1656 call assert_equal('THIS IS A SIMPLE TEST: ÄÜÖSS', getline('.'))
1657 norm! gugu
1658 call assert_equal('this is a simple test: äüöss', getline('.'))
1659 norm! gUU
1660 call assert_equal('THIS IS A SIMPLE TEST: ÄÜÖSS', getline('.'))
1661 norm! 010~
1662 call assert_equal('this is a SIMPLE TEST: ÄÜÖSS', getline('.'))
1663 norm! V~
1664 call assert_equal('THIS IS A simple test: äüöss', getline('.'))
1665
Bram Moolenaar1671f442020-03-10 07:48:13 +01001666 " Test for changing case across lines using 'whichwrap'
1667 call setline(1, ['aaaaaa', 'aaaaaa'])
1668 normal! gg10~
1669 call assert_equal(['AAAAAA', 'aaaaaa'], getline(1, 2))
1670 set whichwrap+=~
1671 normal! gg10~
1672 call assert_equal(['aaaaaa', 'AAAAaa'], getline(1, 2))
1673 set whichwrap&
1674
1675 " clean up
1676 bw!
1677endfunc
1678
1679" Turkish ASCII turns to multi-byte. On some systems Turkish locale
1680" is available but toupper()/tolower() don't do the right thing.
1681func Test_normal_changecase_turkish()
1682 new
Bram Moolenaarf1c118b2018-09-03 22:08:10 +02001683 try
1684 lang tr_TR.UTF-8
1685 set casemap=
1686 let iupper = toupper('i')
1687 if iupper == "\u0130"
Bram Moolenaar9f4de1f2017-04-08 19:39:43 +02001688 call setline(1, 'iI')
1689 1normal gUU
1690 call assert_equal("\u0130I", getline(1))
1691 call assert_equal("\u0130I", toupper("iI"))
Bram Moolenaar3317d5e2017-04-08 19:12:06 +02001692
Bram Moolenaar9f4de1f2017-04-08 19:39:43 +02001693 call setline(1, 'iI')
1694 1normal guu
1695 call assert_equal("i\u0131", getline(1))
1696 call assert_equal("i\u0131", tolower("iI"))
Bram Moolenaarf1c118b2018-09-03 22:08:10 +02001697 elseif iupper == "I"
Bram Moolenaar1cc48202017-04-09 13:41:59 +02001698 call setline(1, 'iI')
1699 1normal gUU
1700 call assert_equal("II", getline(1))
1701 call assert_equal("II", toupper("iI"))
1702
1703 call setline(1, 'iI')
1704 1normal guu
1705 call assert_equal("ii", getline(1))
1706 call assert_equal("ii", tolower("iI"))
Bram Moolenaarf1c118b2018-09-03 22:08:10 +02001707 else
1708 call assert_true(false, "expected toupper('i') to be either 'I' or '\u0130'")
1709 endif
1710 set casemap&
1711 call setline(1, 'iI')
1712 1normal gUU
1713 call assert_equal("II", getline(1))
1714 call assert_equal("II", toupper("iI"))
Bram Moolenaar1cc48202017-04-09 13:41:59 +02001715
Bram Moolenaarf1c118b2018-09-03 22:08:10 +02001716 call setline(1, 'iI')
1717 1normal guu
1718 call assert_equal("ii", getline(1))
1719 call assert_equal("ii", tolower("iI"))
1720
1721 lang en_US.UTF-8
1722 catch /E197:/
1723 " can't use Turkish locale
1724 throw 'Skipped: Turkish locale not available'
1725 endtry
Bram Moolenaar1671f442020-03-10 07:48:13 +01001726 close!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02001727endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001728
Bram Moolenaar1671f442020-03-10 07:48:13 +01001729" Test for r (replace) command
1730func Test_normal31_r_cmd()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001731 new
1732 call append(0, 'This is a simple test: abcd')
1733 exe "norm! 1gg$r\<cr>"
1734 call assert_equal(['This is a simple test: abc', '', ''], getline(1,'$'))
1735 exe "norm! 1gg2wlr\<cr>"
1736 call assert_equal(['This is a', 'simple test: abc', '', ''], getline(1,'$'))
1737 exe "norm! 2gg0W5r\<cr>"
1738 call assert_equal(['This is a', 'simple ', ' abc', '', ''], getline('1', '$'))
1739 set autoindent
1740 call setline(2, ['simple test: abc', ''])
1741 exe "norm! 2gg0W5r\<cr>"
1742 call assert_equal(['This is a', 'simple ', 'abc', '', '', ''], getline('1', '$'))
1743 exe "norm! 1ggVr\<cr>"
1744 call assert_equal('^M^M^M^M^M^M^M^M^M', strtrans(getline(1)))
1745 call setline(1, 'This is a')
1746 exe "norm! 1gg05rf"
1747 call assert_equal('fffffis a', getline(1))
1748
Bram Moolenaar1671f442020-03-10 07:48:13 +01001749 " When replacing characters, copy characters from above and below lines
1750 " using CTRL-Y and CTRL-E.
1751 " Different code paths are used for utf-8 and latin1 encodings
1752 set showmatch
1753 for enc in ['latin1', 'utf-8']
1754 enew!
1755 let &encoding = enc
1756 call setline(1, [' {a}', 'xxxxxxxxxx', ' [b]'])
1757 exe "norm! 2gg5r\<C-Y>l5r\<C-E>"
1758 call assert_equal(' {a}x [b]x', getline(2))
1759 endfor
1760 set showmatch&
1761
1762 " r command should fail in operator pending mode
1763 call assert_beeps('normal! cr')
1764
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001765 " clean up
1766 set noautoindent
1767 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02001768endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001769
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01001770" Test for g*, g#
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01001771func Test_normal32_g_cmd1()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001772 new
1773 call append(0, ['abc.x_foo', 'x_foobar.abc'])
1774 1
1775 norm! $g*
1776 call assert_equal('x_foo', @/)
1777 call assert_equal('x_foobar.abc', getline('.'))
1778 norm! $g#
1779 call assert_equal('abc', @/)
1780 call assert_equal('abc.x_foo', getline('.'))
1781
1782 " clean up
1783 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02001784endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001785
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01001786" Test for g`, g;, g,, g&, gv, gk, gj, gJ, g0, g^, g_, gm, g$, gM, g CTRL-G,
1787" gi and gI commands
Bram Moolenaar1671f442020-03-10 07:48:13 +01001788func Test_normal33_g_cmd2()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001789 if !has("jumplist")
1790 return
1791 endif
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001792 call Setup_NewWindow()
1793 " Test for g`
1794 clearjumps
1795 norm! ma10j
1796 let a=execute(':jumps')
1797 " empty jumplist
1798 call assert_equal('>', a[-1:])
1799 norm! g`a
1800 call assert_equal('>', a[-1:])
1801 call assert_equal(1, line('.'))
1802 call assert_equal('1', getline('.'))
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01001803 call cursor(10, 1)
1804 norm! g'a
1805 call assert_equal('>', a[-1:])
1806 call assert_equal(1, line('.'))
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001807
1808 " Test for g; and g,
1809 norm! g;
1810 " there is only one change in the changelist
1811 " currently, when we setup the window
1812 call assert_equal(2, line('.'))
1813 call assert_fails(':norm! g;', 'E662')
1814 call assert_fails(':norm! g,', 'E663')
1815 let &ul=&ul
1816 call append('$', ['a', 'b', 'c', 'd'])
1817 let &ul=&ul
1818 call append('$', ['Z', 'Y', 'X', 'W'])
1819 let a = execute(':changes')
1820 call assert_match('2\s\+0\s\+2', a)
1821 call assert_match('101\s\+0\s\+a', a)
1822 call assert_match('105\s\+0\s\+Z', a)
1823 norm! 3g;
1824 call assert_equal(2, line('.'))
1825 norm! 2g,
1826 call assert_equal(105, line('.'))
1827
1828 " Test for g& - global substitute
1829 %d
1830 call setline(1, range(1,10))
1831 call append('$', ['a', 'b', 'c', 'd'])
1832 $s/\w/&&/g
1833 exe "norm! /[1-8]\<cr>"
1834 norm! g&
1835 call assert_equal(['11', '22', '33', '44', '55', '66', '77', '88', '9', '110', 'a', 'b', 'c', 'dd'], getline(1, '$'))
1836
Bram Moolenaar1671f442020-03-10 07:48:13 +01001837 " Jumping to a fold using gg should open the fold
1838 set foldenable
1839 set foldopen+=jump
1840 5,8fold
1841 call feedkeys('6gg', 'xt')
1842 call assert_equal(1, foldlevel('.'))
1843 call assert_equal(-1, foldclosed('.'))
1844 set foldopen-=jump
1845 set foldenable&
1846
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001847 " Test for gv
1848 %d
1849 call append('$', repeat(['abcdefgh'], 8))
1850 exe "norm! 2gg02l\<c-v>2j2ly"
1851 call assert_equal(['cde', 'cde', 'cde'], getreg(0, 1, 1))
1852 " in visual mode, gv swaps current and last selected region
1853 exe "norm! G0\<c-v>4k4lgvd"
1854 call assert_equal(['', 'abfgh', 'abfgh', 'abfgh', 'abcdefgh', 'abcdefgh', 'abcdefgh', 'abcdefgh', 'abcdefgh'], getline(1,'$'))
1855 exe "norm! G0\<c-v>4k4ly"
1856 exe "norm! gvood"
1857 call assert_equal(['', 'abfgh', 'abfgh', 'abfgh', 'fgh', 'fgh', 'fgh', 'fgh', 'fgh'], getline(1,'$'))
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01001858 " gv cannot be used in operator pending mode
1859 call assert_beeps('normal! cgv')
1860 " gv should beep without a previously selected visual area
1861 new
1862 call assert_beeps('normal! gv')
1863 close
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001864
1865 " Test for gk/gj
1866 %d
1867 15vsp
1868 set wrap listchars= sbr=
1869 let lineA='abcdefghijklmnopqrstuvwxyz'
1870 let lineB='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'
Bram Moolenaar8b530c12019-10-28 02:13:05 +01001871 let lineC='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz01234567890123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001872 $put =lineA
1873 $put =lineB
1874
1875 norm! 3gg0dgk
1876 call assert_equal(['', 'abcdefghijklmno', '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'], getline(1, '$'))
1877 set nu
1878 norm! 3gg0gjdgj
1879 call assert_equal(['', 'abcdefghijklmno', '0123456789AMNOPQRSTUVWXYZ'], getline(1,'$'))
1880
1881 " Test for gJ
1882 norm! 2gggJ
1883 call assert_equal(['', 'abcdefghijklmno0123456789AMNOPQRSTUVWXYZ'], getline(1,'$'))
1884 call assert_equal(16, col('.'))
1885 " shouldn't do anything
1886 norm! 10gJ
1887 call assert_equal(1, col('.'))
1888
1889 " Test for g0 g^ gm g$
1890 exe "norm! 2gg0gji "
1891 call assert_equal(['', 'abcdefghijk lmno0123456789AMNOPQRSTUVWXYZ'], getline(1,'$'))
1892 norm! g0yl
1893 call assert_equal(12, col('.'))
1894 call assert_equal(' ', getreg(0))
1895 norm! g$yl
1896 call assert_equal(22, col('.'))
1897 call assert_equal('3', getreg(0))
1898 norm! gmyl
1899 call assert_equal(17, col('.'))
1900 call assert_equal('n', getreg(0))
1901 norm! g^yl
1902 call assert_equal(15, col('.'))
1903 call assert_equal('l', getreg(0))
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01001904 call assert_beeps('normal 5g$')
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001905
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01001906 " Test for g_
1907 call assert_beeps('normal! 100g_')
1908 call setline(2, [' foo ', ' foobar '])
1909 normal! 2ggg_
1910 call assert_equal(5, col('.'))
1911 normal! 2g_
1912 call assert_equal(8, col('.'))
1913
1914 norm! 2ggdG
Bram Moolenaar8b530c12019-10-28 02:13:05 +01001915 $put =lineC
1916
1917 " Test for gM
1918 norm! gMyl
1919 call assert_equal(73, col('.'))
1920 call assert_equal('0', getreg(0))
1921 " Test for 20gM
1922 norm! 20gMyl
1923 call assert_equal(29, col('.'))
1924 call assert_equal('S', getreg(0))
1925 " Test for 60gM
1926 norm! 60gMyl
1927 call assert_equal(87, col('.'))
1928 call assert_equal('E', getreg(0))
1929
1930 " Test for g Ctrl-G
1931 set ff=unix
1932 let a=execute(":norm! g\<c-g>")
1933 call assert_match('Col 87 of 144; Line 2 of 2; Word 1 of 1; Byte 88 of 146', a)
1934
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001935 " Test for gI
1936 norm! gIfoo
Bram Moolenaar8b530c12019-10-28 02:13:05 +01001937 call assert_equal(['', 'foo0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz01234567890123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'], getline(1,'$'))
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001938
1939 " Test for gi
1940 wincmd c
1941 %d
1942 set tw=0
1943 call setline(1, ['foobar', 'new line'])
1944 norm! A next word
1945 $put ='third line'
1946 norm! gi another word
1947 call assert_equal(['foobar next word another word', 'new line', 'third line'], getline(1,'$'))
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01001948 call setline(1, 'foobar')
1949 normal! Ggifirst line
1950 call assert_equal('foobarfirst line', getline(1))
1951 " Test gi in 'virtualedit' mode with cursor after the end of the line
1952 set virtualedit=all
1953 call setline(1, 'foo')
1954 exe "normal! Abar\<Right>\<Right>\<Right>\<Right>"
1955 call setline(1, 'foo')
1956 normal! Ggifirst line
1957 call assert_equal('foo first line', getline(1))
1958 set virtualedit&
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001959
Bram Moolenaar1671f442020-03-10 07:48:13 +01001960 " Test for aboring a g command using CTRL-\ CTRL-G
1961 exe "normal! g\<C-\>\<C-G>"
1962 call assert_equal('foo first line', getline('.'))
1963
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001964 " clean up
1965 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02001966endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001967
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01001968" Test for g CTRL-G
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01001969func Test_g_ctrl_g()
Bram Moolenaar05295832018-08-24 22:07:58 +02001970 new
1971
1972 let a = execute(":norm! g\<c-g>")
1973 call assert_equal("\n--No lines in buffer--", a)
1974
Bram Moolenaar1671f442020-03-10 07:48:13 +01001975 " Test for CTRL-G (same as :file)
1976 let a = execute(":norm! \<c-g>")
1977 call assert_equal("\n\n\"[No Name]\" --No lines in buffer--", a)
1978
Bram Moolenaar05295832018-08-24 22:07:58 +02001979 call setline(1, ['first line', 'second line'])
1980
1981 " Test g CTRL-g with dos, mac and unix file type.
1982 norm! gojll
1983 set ff=dos
1984 let a = execute(":norm! g\<c-g>")
1985 call assert_equal("\nCol 3 of 11; Line 2 of 2; Word 3 of 4; Byte 15 of 25", a)
1986
1987 set ff=mac
1988 let a = execute(":norm! g\<c-g>")
1989 call assert_equal("\nCol 3 of 11; Line 2 of 2; Word 3 of 4; Byte 14 of 23", a)
1990
1991 set ff=unix
1992 let a = execute(":norm! g\<c-g>")
1993 call assert_equal("\nCol 3 of 11; Line 2 of 2; Word 3 of 4; Byte 14 of 23", a)
1994
1995 " Test g CTRL-g in visual mode (v)
1996 let a = execute(":norm! gojllvlg\<c-g>")
1997 call assert_equal("\nSelected 1 of 2 Lines; 1 of 4 Words; 2 of 23 Bytes", a)
1998
1999 " Test g CTRL-g in visual mode (CTRL-V) with end col > start col
2000 let a = execute(":norm! \<Esc>gojll\<C-V>kllg\<c-g>")
2001 call assert_equal("\nSelected 3 Cols; 2 of 2 Lines; 2 of 4 Words; 6 of 23 Bytes", a)
2002
2003 " Test g_CTRL-g in visual mode (CTRL-V) with end col < start col
2004 let a = execute(":norm! \<Esc>goll\<C-V>jhhg\<c-g>")
2005 call assert_equal("\nSelected 3 Cols; 2 of 2 Lines; 2 of 4 Words; 6 of 23 Bytes", a)
2006
2007 " Test g CTRL-g in visual mode (CTRL-V) with end_vcol being MAXCOL
2008 let a = execute(":norm! \<Esc>gojll\<C-V>k$g\<c-g>")
2009 call assert_equal("\nSelected 2 of 2 Lines; 4 of 4 Words; 17 of 23 Bytes", a)
2010
2011 " There should be one byte less with noeol
2012 set bin noeol
2013 let a = execute(":norm! \<Esc>gog\<c-g>")
2014 call assert_equal("\nCol 1 of 10; Line 1 of 2; Word 1 of 4; Char 1 of 23; Byte 1 of 22", a)
2015 set bin & eol&
2016
Bram Moolenaar30276f22019-01-24 17:59:39 +01002017 call setline(1, ['Français', '日本語'])
Bram Moolenaar05295832018-08-24 22:07:58 +02002018
Bram Moolenaar30276f22019-01-24 17:59:39 +01002019 let a = execute(":norm! \<Esc>gojlg\<c-g>")
2020 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 +02002021
Bram Moolenaar30276f22019-01-24 17:59:39 +01002022 let a = execute(":norm! \<Esc>gojvlg\<c-g>")
2023 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 +02002024
Bram Moolenaar30276f22019-01-24 17:59:39 +01002025 let a = execute(":norm! \<Esc>goll\<c-v>jlg\<c-g>")
2026 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 +02002027
Bram Moolenaar30276f22019-01-24 17:59:39 +01002028 set fenc=utf8 bomb
2029 let a = execute(":norm! \<Esc>gojlg\<c-g>")
2030 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 +02002031
Bram Moolenaar30276f22019-01-24 17:59:39 +01002032 set fenc=utf16 bomb
2033 let a = execute(":norm! g\<c-g>")
2034 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 +02002035
Bram Moolenaar30276f22019-01-24 17:59:39 +01002036 set fenc=utf32 bomb
2037 let a = execute(":norm! g\<c-g>")
2038 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 +02002039
Bram Moolenaar30276f22019-01-24 17:59:39 +01002040 set fenc& bomb&
Bram Moolenaar05295832018-08-24 22:07:58 +02002041
2042 set ff&
2043 bwipe!
2044endfunc
2045
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01002046" Test for g8
Bram Moolenaar1671f442020-03-10 07:48:13 +01002047func Test_normal34_g_cmd3()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002048 new
Bram Moolenaar395b6ba2017-04-07 20:09:51 +02002049 let a=execute(':norm! 1G0g8')
2050 call assert_equal("\nNUL", a)
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002051
Bram Moolenaar395b6ba2017-04-07 20:09:51 +02002052 call setline(1, 'abcdefghijklmnopqrstuvwxyzäüö')
2053 let a=execute(':norm! 1G$g8')
2054 call assert_equal("\nc3 b6 ", a)
2055
2056 call setline(1, "a\u0302")
2057 let a=execute(':norm! 1G0g8')
2058 call assert_equal("\n61 + cc 82 ", a)
2059
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002060 " clean up
2061 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002062endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002063
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01002064" Test 8g8 which finds invalid utf8 at or after the cursor.
Bram Moolenaar395b6ba2017-04-07 20:09:51 +02002065func Test_normal_8g8()
Bram Moolenaar395b6ba2017-04-07 20:09:51 +02002066 new
2067
Bram Moolenaar395b6ba2017-04-07 20:09:51 +02002068 " With invalid byte.
2069 call setline(1, "___\xff___")
2070 norm! 1G08g8g
2071 call assert_equal([0, 1, 4, 0, 1], getcurpos())
2072
2073 " With invalid byte before the cursor.
2074 call setline(1, "___\xff___")
2075 norm! 1G$h8g8g
2076 call assert_equal([0, 1, 6, 0, 9], getcurpos())
2077
2078 " With truncated sequence.
2079 call setline(1, "___\xE2\x82___")
2080 norm! 1G08g8g
2081 call assert_equal([0, 1, 4, 0, 1], getcurpos())
2082
2083 " With overlong sequence.
2084 call setline(1, "___\xF0\x82\x82\xAC___")
2085 norm! 1G08g8g
2086 call assert_equal([0, 1, 4, 0, 1], getcurpos())
2087
2088 " With valid utf8.
2089 call setline(1, "café")
2090 norm! 1G08g8
2091 call assert_equal([0, 1, 1, 0, 1], getcurpos())
2092
2093 bw!
2094endfunc
2095
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01002096" Test for g<
Bram Moolenaar1671f442020-03-10 07:48:13 +01002097func Test_normal35_g_cmd4()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002098 " Cannot capture its output,
2099 " probably a bug, therefore, test disabled:
Bram Moolenaar31845092016-09-05 22:58:31 +02002100 throw "Skipped: output of g< can't be tested currently"
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002101 echo "a\nb\nc\nd"
2102 let b=execute(':norm! g<')
2103 call assert_true(!empty(b), 'failed `execute(g<)`')
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002104endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002105
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01002106" Test for gp gP go
Bram Moolenaar1671f442020-03-10 07:48:13 +01002107func Test_normal36_g_cmd5()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002108 new
2109 call append(0, 'abcdefghijklmnopqrstuvwxyz')
Bram Moolenaar0913a102016-09-03 19:11:59 +02002110 set ff=unix
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002111 " Test for gp gP
2112 call append(1, range(1,10))
2113 1
2114 norm! 1yy
2115 3
2116 norm! gp
2117 call assert_equal([0, 5, 1, 0, 1], getcurpos())
2118 $
2119 norm! gP
2120 call assert_equal([0, 14, 1, 0, 1], getcurpos())
2121
2122 " Test for go
2123 norm! 26go
2124 call assert_equal([0, 1, 26, 0, 26], getcurpos())
2125 norm! 27go
2126 call assert_equal([0, 1, 26, 0, 26], getcurpos())
2127 norm! 28go
2128 call assert_equal([0, 2, 1, 0, 1], getcurpos())
2129 set ff=dos
2130 norm! 29go
2131 call assert_equal([0, 2, 1, 0, 1], getcurpos())
2132 set ff=unix
2133 norm! gg0
2134 norm! 101go
2135 call assert_equal([0, 13, 26, 0, 26], getcurpos())
2136 norm! 103go
2137 call assert_equal([0, 14, 1, 0, 1], getcurpos())
2138 " count > buffer content
2139 norm! 120go
2140 call assert_equal([0, 14, 1, 0, 2147483647], getcurpos())
2141 " clean up
2142 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002143endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002144
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01002145" Test for gt and gT
Bram Moolenaar1671f442020-03-10 07:48:13 +01002146func Test_normal37_g_cmd6()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002147 tabnew 1.txt
2148 tabnew 2.txt
2149 tabnew 3.txt
2150 norm! 1gt
2151 call assert_equal(1, tabpagenr())
2152 norm! 3gt
2153 call assert_equal(3, tabpagenr())
2154 norm! 1gT
2155 " count gT goes not to the absolute tabpagenumber
2156 " but, but goes to the count previous tabpagenumber
2157 call assert_equal(2, tabpagenr())
2158 " wrap around
2159 norm! 3gT
2160 call assert_equal(3, tabpagenr())
2161 " gt does not wrap around
2162 norm! 5gt
2163 call assert_equal(3, tabpagenr())
2164
2165 for i in range(3)
2166 tabclose
2167 endfor
2168 " clean up
Bram Moolenaarbc2b71d2020-02-17 21:33:30 +01002169 call assert_fails(':tabclose', 'E784:')
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002170endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002171
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01002172" Test for <Home> and <C-Home> key
Bram Moolenaar1671f442020-03-10 07:48:13 +01002173func Test_normal38_nvhome()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002174 new
2175 call setline(1, range(10))
2176 $
2177 setl et sw=2
2178 norm! V10>$
2179 " count is ignored
2180 exe "norm! 10\<home>"
2181 call assert_equal(1, col('.'))
2182 exe "norm! \<home>"
2183 call assert_equal([0, 10, 1, 0, 1], getcurpos())
2184 exe "norm! 5\<c-home>"
2185 call assert_equal([0, 5, 1, 0, 1], getcurpos())
2186 exe "norm! \<c-home>"
2187 call assert_equal([0, 1, 1, 0, 1], getcurpos())
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01002188 exe "norm! G\<c-kHome>"
2189 call assert_equal([0, 1, 1, 0, 1], getcurpos())
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002190
2191 " clean up
2192 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002193endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002194
Bram Moolenaar1671f442020-03-10 07:48:13 +01002195" Test for <End> and <C-End> keys
2196func Test_normal_nvend()
2197 new
2198 call setline(1, map(range(1, 10), '"line" .. v:val'))
2199 exe "normal! \<End>"
2200 call assert_equal(5, col('.'))
2201 exe "normal! 4\<End>"
2202 call assert_equal([4, 5], [line('.'), col('.')])
2203 exe "normal! \<C-End>"
2204 call assert_equal([10, 6], [line('.'), col('.')])
2205 close!
2206endfunc
2207
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01002208" Test for cw cW ce
Bram Moolenaar1671f442020-03-10 07:48:13 +01002209func Test_normal39_cw()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002210 " Test for cw and cW on whitespace
2211 " and cpo+=w setting
2212 new
2213 set tw=0
2214 call append(0, 'here are some words')
2215 norm! 1gg0elcwZZZ
2216 call assert_equal('hereZZZare some words', getline('.'))
2217 norm! 1gg0elcWYYY
2218 call assert_equal('hereZZZareYYYsome words', getline('.'))
2219 set cpo+=w
2220 call setline(1, 'here are some words')
2221 norm! 1gg0elcwZZZ
2222 call assert_equal('hereZZZ are some words', getline('.'))
2223 norm! 1gg2elcWYYY
2224 call assert_equal('hereZZZ areYYY some words', getline('.'))
2225 set cpo-=w
2226 norm! 2gg0cwfoo
2227 call assert_equal('foo', getline('.'))
2228
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01002229 call setline(1, 'one; two')
2230 call cursor(1, 1)
2231 call feedkeys('cwvim', 'xt')
2232 call assert_equal('vim; two', getline(1))
2233 call feedkeys('0cWone', 'xt')
2234 call assert_equal('one two', getline(1))
2235 "When cursor is at the end of a word 'ce' will change until the end of the
2236 "next word, but 'cw' will change only one character
2237 call setline(1, 'one two')
2238 call feedkeys('0ecwce', 'xt')
2239 call assert_equal('once two', getline(1))
2240 call setline(1, 'one two')
2241 call feedkeys('0ecely', 'xt')
2242 call assert_equal('only', getline(1))
2243
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002244 " clean up
2245 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002246endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002247
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01002248" Test for CTRL-\ commands
Bram Moolenaar1671f442020-03-10 07:48:13 +01002249func Test_normal40_ctrl_bsl()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002250 new
2251 call append(0, 'here are some words')
2252 exe "norm! 1gg0a\<C-\>\<C-N>"
2253 call assert_equal('n', mode())
2254 call assert_equal(1, col('.'))
2255 call assert_equal('', visualmode())
2256 exe "norm! 1gg0viw\<C-\>\<C-N>"
2257 call assert_equal('n', mode())
2258 call assert_equal(4, col('.'))
2259 exe "norm! 1gg0a\<C-\>\<C-G>"
2260 call assert_equal('n', mode())
2261 call assert_equal(1, col('.'))
2262 "imap <buffer> , <c-\><c-n>
2263 set im
2264 exe ":norm! \<c-\>\<c-n>dw"
2265 set noim
2266 call assert_equal('are some words', getline(1))
2267 call assert_false(&insertmode)
Bram Moolenaar1671f442020-03-10 07:48:13 +01002268 call assert_beeps("normal! \<C-\>\<C-A>", 'xt')
2269
2270 " Using CTRL-\ CTRL-N in cmd window should close the window
2271 call feedkeys("q:\<C-\>\<C-N>", 'xt')
2272 call assert_equal('', getcmdwintype())
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002273
2274 " clean up
2275 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002276endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002277
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01002278" Test for <c-r>=, <c-r><c-r>= and <c-r><c-o>= in insert mode
Bram Moolenaar1671f442020-03-10 07:48:13 +01002279func Test_normal41_insert_reg()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002280 new
2281 set sts=2 sw=2 ts=8 tw=0
2282 call append(0, ["aaa\tbbb\tccc", '', '', ''])
2283 let a=getline(1)
2284 norm! 2gg0
2285 exe "norm! a\<c-r>=a\<cr>"
2286 norm! 3gg0
2287 exe "norm! a\<c-r>\<c-r>=a\<cr>"
2288 norm! 4gg0
2289 exe "norm! a\<c-r>\<c-o>=a\<cr>"
2290 call assert_equal(['aaa bbb ccc', 'aaa bbb ccc', 'aaa bbb ccc', 'aaa bbb ccc', ''], getline(1, '$'))
2291
2292 " clean up
2293 set sts=0 sw=8 ts=8
Bram Moolenaar31845092016-09-05 22:58:31 +02002294 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002295endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002296
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01002297" Test for Ctrl-D and Ctrl-U
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01002298func Test_normal42_halfpage()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002299 call Setup_NewWindow()
2300 call assert_equal(5, &scroll)
2301 exe "norm! \<c-d>"
2302 call assert_equal('6', getline('.'))
2303 exe "norm! 2\<c-d>"
2304 call assert_equal('8', getline('.'))
2305 call assert_equal(2, &scroll)
2306 set scroll=5
2307 exe "norm! \<c-u>"
2308 call assert_equal('3', getline('.'))
2309 1
2310 set scrolloff=5
2311 exe "norm! \<c-d>"
2312 call assert_equal('10', getline('.'))
2313 exe "norm! \<c-u>"
2314 call assert_equal('5', getline('.'))
2315 1
2316 set scrolloff=99
2317 exe "norm! \<c-d>"
2318 call assert_equal('10', getline('.'))
2319 set scrolloff=0
2320 100
2321 exe "norm! $\<c-u>"
2322 call assert_equal('95', getline('.'))
2323 call assert_equal([0, 95, 1, 0, 1], getcurpos())
2324 100
2325 set nostartofline
2326 exe "norm! $\<c-u>"
2327 call assert_equal('95', getline('.'))
2328 call assert_equal([0, 95, 2, 0, 2147483647], getcurpos())
2329 " cleanup
2330 set startofline
2331 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002332endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002333
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01002334" Tests for text object aw
Bram Moolenaar1671f442020-03-10 07:48:13 +01002335func Test_normal43_textobject1()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002336 new
2337 call append(0, ['foobar,eins,foobar', 'foo,zwei,foo '])
2338 " diw
2339 norm! 1gg0diw
2340 call assert_equal([',eins,foobar', 'foo,zwei,foo ', ''], getline(1,'$'))
2341 " daw
2342 norm! 2ggEdaw
2343 call assert_equal([',eins,foobar', 'foo,zwei,', ''], getline(1, '$'))
2344 %d
2345 call append(0, ["foo\teins\tfoobar", "foo\tzwei\tfoo "])
2346 " diW
2347 norm! 2ggwd2iW
2348 call assert_equal(['foo eins foobar', 'foo foo ', ''], getline(1,'$'))
2349 " daW
2350 norm! 1ggd2aW
2351 call assert_equal(['foobar', 'foo foo ', ''], getline(1,'$'))
2352
2353 %d
2354 call append(0, ["foo\teins\tfoobar", "foo\tzwei\tfoo "])
2355 " aw in visual line mode switches to characterwise mode
2356 norm! 2gg$Vawd
2357 call assert_equal(['foo eins foobar', 'foo zwei foo'], getline(1,'$'))
2358 norm! 1gg$Viwd
2359 call assert_equal(['foo eins ', 'foo zwei foo'], getline(1,'$'))
2360
2361 " clean up
2362 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002363endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002364
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01002365" Test for is and as text objects
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01002366func Test_normal44_textobjects2()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002367 new
2368 call append(0, ['This is a test. With some sentences!', '', 'Even with a question? And one more. And no sentence here'])
2369 " Test for dis - does not remove trailing whitespace
2370 norm! 1gg0dis
2371 call assert_equal([' With some sentences!', '', 'Even with a question? And one more. And no sentence here', ''], getline(1,'$'))
2372 " Test for das - removes leading whitespace
2373 norm! 3ggf?ldas
2374 call assert_equal([' With some sentences!', '', 'Even with a question? And no sentence here', ''], getline(1,'$'))
2375 " when used in visual mode, is made characterwise
2376 norm! 3gg$Visy
2377 call assert_equal('v', visualmode())
2378 " reset visualmode()
2379 norm! 3ggVy
2380 norm! 3gg$Vasy
2381 call assert_equal('v', visualmode())
2382 " basic testing for textobjects a< and at
2383 %d
2384 call setline(1, ['<div> ','<a href="foobar" class="foo">xyz</a>',' </div>', ' '])
2385 " a<
2386 norm! 1gg0da<
2387 call assert_equal([' ', '<a href="foobar" class="foo">xyz</a>', ' </div>', ' '], getline(1,'$'))
2388 norm! 1pj
2389 call assert_equal([' <div>', '<a href="foobar" class="foo">xyz</a>', ' </div>', ' '], getline(1,'$'))
2390 " at
2391 norm! d2at
2392 call assert_equal([' '], getline(1,'$'))
2393 %d
2394 call setline(1, ['<div> ','<a href="foobar" class="foo">xyz</a>',' </div>', ' '])
2395 " i<
2396 norm! 1gg0di<
2397 call assert_equal(['<> ', '<a href="foobar" class="foo">xyz</a>', ' </div>', ' '], getline(1,'$'))
2398 norm! 1Pj
2399 call assert_equal(['<div> ', '<a href="foobar" class="foo">xyz</a>', ' </div>', ' '], getline(1,'$'))
2400 norm! d2it
2401 call assert_equal(['<div></div>',' '], getline(1,'$'))
2402 " basic testing for a[ and i[ text object
2403 %d
2404 call setline(1, [' ', '[', 'one [two]', 'thre', ']'])
2405 norm! 3gg0di[
2406 call assert_equal([' ', '[', ']'], getline(1,'$'))
2407 call setline(1, [' ', '[', 'one [two]', 'thre', ']'])
2408 norm! 3gg0ftd2a[
2409 call assert_equal([' '], getline(1,'$'))
2410 %d
2411 " Test for i" when cursor is in front of a quoted object
2412 call append(0, 'foo "bar"')
2413 norm! 1gg0di"
2414 call assert_equal(['foo ""', ''], getline(1,'$'))
2415
2416 " clean up
2417 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002418endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002419
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01002420func Test_normal45_drop()
Bram Moolenaar29495952018-02-12 22:49:00 +01002421 if !has('dnd')
Bram Moolenaarb48e96f2018-02-13 12:26:14 +01002422 " The ~ register does not exist
2423 call assert_beeps('norm! "~')
Bram Moolenaar29495952018-02-12 22:49:00 +01002424 return
2425 endif
2426
2427 " basic test for drag-n-drop
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002428 " unfortunately, without a gui, we can't really test much here,
2429 " so simply test that ~p fails (which uses the drop register)
2430 new
2431 call assert_fails(':norm! "~p', 'E353')
2432 call assert_equal([], getreg('~', 1, 1))
2433 " the ~ register is read only
2434 call assert_fails(':let @~="1"', 'E354')
2435 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002436endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002437
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01002438func Test_normal46_ignore()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002439 new
2440 " How to test this?
2441 " let's just for now test, that the buffer
2442 " does not change
2443 call feedkeys("\<c-s>", 't')
2444 call assert_equal([''], getline(1,'$'))
2445
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002446 " no valid commands
2447 exe "norm! \<char-0x100>"
2448 call assert_equal([''], getline(1,'$'))
2449
2450 exe "norm! ä"
2451 call assert_equal([''], getline(1,'$'))
2452
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002453 " clean up
2454 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002455endfunc
Bram Moolenaarc4a908e2016-09-08 23:35:30 +02002456
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01002457func Test_normal47_visual_buf_wipe()
Bram Moolenaarc4a908e2016-09-08 23:35:30 +02002458 " This was causing a crash or ml_get error.
2459 enew!
2460 call setline(1,'xxx')
2461 normal $
2462 new
2463 call setline(1, range(1,2))
2464 2
2465 exe "norm \<C-V>$"
2466 bw!
2467 norm yp
2468 set nomodified
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002469endfunc
2470
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01002471func Test_normal47_autocmd()
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002472 " disabled, does not seem to be possible currently
2473 throw "Skipped: not possible to test cursorhold autocmd while waiting for input in normal_cmd"
2474 new
2475 call append(0, repeat('-',20))
2476 au CursorHold * call feedkeys('2l', '')
2477 1
2478 set updatetime=20
2479 " should delete 12 chars (d12l)
2480 call feedkeys('d1', '!')
2481 call assert_equal('--------', getline(1))
2482
2483 " clean up
2484 au! CursorHold
2485 set updatetime=4000
2486 bw!
2487endfunc
2488
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01002489func Test_normal48_wincmd()
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002490 new
2491 exe "norm! \<c-w>c"
2492 call assert_equal(1, winnr('$'))
2493 call assert_fails(":norm! \<c-w>c", "E444")
2494endfunc
2495
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01002496func Test_normal49_counts()
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002497 new
2498 call setline(1, 'one two three four five six seven eight nine ten')
2499 1
2500 norm! 3d2w
2501 call assert_equal('seven eight nine ten', getline(1))
2502 bw!
2503endfunc
2504
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01002505func Test_normal50_commandline()
Bram Moolenaar4033c552017-09-16 20:54:51 +02002506 if !has("timers") || !has("cmdline_hist")
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002507 return
2508 endif
2509 func! DoTimerWork(id)
2510 call assert_equal('[Command Line]', bufname(''))
2511 " should fail, with E11, but does fail with E23?
2512 "call feedkeys("\<c-^>", 'tm')
2513
2514 " should also fail with E11
2515 call assert_fails(":wincmd p", 'E11')
2516 " return from commandline window
2517 call feedkeys("\<cr>")
2518 endfunc
2519
2520 let oldlang=v:lang
2521 lang C
2522 set updatetime=20
2523 call timer_start(100, 'DoTimerWork')
2524 try
2525 " throws E23, for whatever reason...
2526 call feedkeys('q:', 'x!')
2527 catch /E23/
2528 " no-op
2529 endtry
2530 " clean up
2531 set updatetime=4000
2532 exe "lang" oldlang
2533 bw!
2534endfunc
2535
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01002536func Test_normal51_FileChangedRO()
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002537 if !has("autocmd")
2538 return
2539 endif
Bram Moolenaare5f2a072017-02-01 22:31:49 +01002540 " Don't sleep after the warning message.
2541 call test_settime(1)
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002542 call writefile(['foo'], 'Xreadonly.log')
2543 new Xreadonly.log
2544 setl ro
2545 au FileChangedRO <buffer> :call feedkeys("\<c-^>", 'tix')
2546 call assert_fails(":norm! Af", 'E788')
2547 call assert_equal(['foo'], getline(1,'$'))
2548 call assert_equal('Xreadonly.log', bufname(''))
2549
2550 " cleanup
Bram Moolenaare5f2a072017-02-01 22:31:49 +01002551 call test_settime(0)
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002552 bw!
2553 call delete("Xreadonly.log")
2554endfunc
2555
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01002556func Test_normal52_rl()
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002557 if !has("rightleft")
2558 return
2559 endif
2560 new
2561 call setline(1, 'abcde fghij klmnopq')
2562 norm! 1gg$
2563 set rl
2564 call assert_equal(19, col('.'))
2565 call feedkeys('l', 'tx')
2566 call assert_equal(18, col('.'))
2567 call feedkeys('h', 'tx')
2568 call assert_equal(19, col('.'))
2569 call feedkeys("\<right>", 'tx')
2570 call assert_equal(18, col('.'))
Bram Moolenaar1671f442020-03-10 07:48:13 +01002571 call feedkeys("\<left>", 'tx')
2572 call assert_equal(19, col('.'))
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002573 call feedkeys("\<s-right>", 'tx')
2574 call assert_equal(13, col('.'))
2575 call feedkeys("\<c-right>", 'tx')
2576 call assert_equal(7, col('.'))
2577 call feedkeys("\<c-left>", 'tx')
2578 call assert_equal(13, col('.'))
2579 call feedkeys("\<s-left>", 'tx')
2580 call assert_equal(19, col('.'))
2581 call feedkeys("<<", 'tx')
2582 call assert_equal(' abcde fghij klmnopq',getline(1))
2583 call feedkeys(">>", 'tx')
2584 call assert_equal('abcde fghij klmnopq',getline(1))
2585
2586 " cleanup
2587 set norl
2588 bw!
2589endfunc
2590
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01002591func Test_normal53_digraph()
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002592 if !has('digraphs')
2593 return
2594 endif
2595 new
2596 call setline(1, 'abcdefgh|')
2597 exe "norm! 1gg0f\<c-k>!!"
2598 call assert_equal(9, col('.'))
2599 set cpo+=D
2600 exe "norm! 1gg0f\<c-k>!!"
2601 call assert_equal(1, col('.'))
2602
2603 set cpo-=D
2604 bw!
2605endfunc
2606
Bram Moolenaarb1e04fc2017-03-29 13:08:35 +02002607func Test_normal54_Ctrl_bsl()
2608 new
2609 call setline(1, 'abcdefghijklmn')
2610 exe "norm! df\<c-\>\<c-n>"
2611 call assert_equal(['abcdefghijklmn'], getline(1,'$'))
2612 exe "norm! df\<c-\>\<c-g>"
2613 call assert_equal(['abcdefghijklmn'], getline(1,'$'))
2614 exe "norm! df\<c-\>m"
2615 call assert_equal(['abcdefghijklmn'], getline(1,'$'))
Bram Moolenaar30276f22019-01-24 17:59:39 +01002616
Bram Moolenaarb1e04fc2017-03-29 13:08:35 +02002617 call setline(2, 'abcdefghijklmnāf')
2618 norm! 2gg0
2619 exe "norm! df\<Char-0x101>"
2620 call assert_equal(['abcdefghijklmn', 'f'], getline(1,'$'))
2621 norm! 1gg0
2622 exe "norm! df\<esc>"
2623 call assert_equal(['abcdefghijklmn', 'f'], getline(1,'$'))
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002624
Bram Moolenaarb1e04fc2017-03-29 13:08:35 +02002625 " clean up
2626 bw!
2627endfunc
2628
2629func Test_normal_large_count()
2630 " This may fail with 32bit long, how do we detect that?
2631 new
2632 normal o
2633 normal 6666666666dL
2634 bwipe!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002635endfunc
Bram Moolenaarbf3d5802017-03-29 19:48:11 +02002636
2637func Test_delete_until_paragraph()
Bram Moolenaarbf3d5802017-03-29 19:48:11 +02002638 new
2639 normal grádv}
2640 call assert_equal('á', getline(1))
2641 normal grád}
2642 call assert_equal('', getline(1))
2643 bwipe!
2644endfunc
Bram Moolenaarfb094e12017-11-05 20:59:28 +01002645
2646" Test for the gr (virtual replace) command
2647" Test for the bug fixed by 7.4.387
2648func Test_gr_command()
2649 enew!
2650 let save_cpo = &cpo
2651 call append(0, ['First line', 'Second line', 'Third line'])
2652 exe "normal i\<C-G>u"
2653 call cursor(2, 1)
2654 set cpo-=X
2655 normal 4gro
2656 call assert_equal('oooond line', getline(2))
2657 undo
2658 set cpo+=X
2659 normal 4gro
2660 call assert_equal('ooooecond line', getline(2))
2661 let &cpo = save_cpo
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01002662 normal! ggvegrx
2663 call assert_equal('xxxxx line', getline(1))
2664 exe "normal! gggr\<C-V>122"
2665 call assert_equal('zxxxx line', getline(1))
2666 set virtualedit=all
2667 normal! 15|grl
2668 call assert_equal('zxxxx line l', getline(1))
2669 set virtualedit&
2670 set nomodifiable
2671 call assert_fails('normal! grx', 'E21:')
2672 call assert_fails('normal! gRx', 'E21:')
2673 set modifiable&
Bram Moolenaarfb094e12017-11-05 20:59:28 +01002674 enew!
2675endfunc
2676
2677" When splitting a window the changelist position is wrong.
2678" Test the changelist position after splitting a window.
2679" Test for the bug fixed by 7.4.386
2680func Test_changelist()
2681 let save_ul = &ul
2682 enew!
2683 call append('$', ['1', '2'])
2684 exe "normal i\<C-G>u"
2685 exe "normal Gkylpa\<C-G>u"
2686 set ul=100
2687 exe "normal Gylpa\<C-G>u"
2688 set ul=100
2689 normal gg
2690 vsplit
2691 normal g;
2692 call assert_equal([3, 2], [line('.'), col('.')])
2693 normal g;
2694 call assert_equal([2, 2], [line('.'), col('.')])
2695 call assert_fails('normal g;', 'E662:')
Bram Moolenaar1671f442020-03-10 07:48:13 +01002696 new
2697 call assert_fails('normal g;', 'E664:')
Bram Moolenaarfb094e12017-11-05 20:59:28 +01002698 %bwipe!
2699 let &ul = save_ul
2700endfunc
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01002701
2702func Test_nv_hat_count()
2703 %bwipeout!
2704 let l:nr = bufnr('%') + 1
2705 call assert_fails(':execute "normal! ' . l:nr . '\<C-^>"', 'E92')
2706
2707 edit Xfoo
2708 let l:foo_nr = bufnr('Xfoo')
2709
2710 edit Xbar
2711 let l:bar_nr = bufnr('Xbar')
2712
2713 " Make sure we are not just using the alternate file.
2714 edit Xbaz
2715
2716 call feedkeys(l:foo_nr . "\<C-^>", 'tx')
2717 call assert_equal('Xfoo', fnamemodify(bufname('%'), ':t'))
2718
2719 call feedkeys(l:bar_nr . "\<C-^>", 'tx')
2720 call assert_equal('Xbar', fnamemodify(bufname('%'), ':t'))
2721
2722 %bwipeout!
2723endfunc
Bram Moolenaara84a3dd2019-03-25 22:21:24 +01002724
2725func Test_message_when_using_ctrl_c()
Bram Moolenaar553e5a52019-03-25 23:16:34 +01002726 " Make sure no buffers are changed.
2727 %bwipe!
2728
Bram Moolenaara84a3dd2019-03-25 22:21:24 +01002729 exe "normal \<C-C>"
2730 call assert_match("Type :qa and press <Enter> to exit Vim", Screenline(&lines))
Bram Moolenaar553e5a52019-03-25 23:16:34 +01002731
Bram Moolenaara84a3dd2019-03-25 22:21:24 +01002732 new
2733 cal setline(1, 'hi!')
2734 exe "normal \<C-C>"
2735 call assert_match("Type :qa! and press <Enter> to abandon all changes and exit Vim", Screenline(&lines))
Bram Moolenaar553e5a52019-03-25 23:16:34 +01002736
Bram Moolenaara84a3dd2019-03-25 22:21:24 +01002737 bwipe!
2738endfunc
Bram Moolenaarc6b37db2019-04-27 18:00:34 +02002739
2740" Test for '[m', ']m', '[M' and ']M'
2741" Jumping to beginning and end of methods in Java-like languages
2742func Test_java_motion()
2743 new
Bram Moolenaar1671f442020-03-10 07:48:13 +01002744 call assert_beeps('normal! [m')
2745 call assert_beeps('normal! ]m')
2746 call assert_beeps('normal! [M')
2747 call assert_beeps('normal! ]M')
Bram Moolenaarc6b37db2019-04-27 18:00:34 +02002748 a
2749Piece of Java
2750{
2751 tt m1 {
2752 t1;
2753 } e1
2754
2755 tt m2 {
2756 t2;
2757 } e2
2758
2759 tt m3 {
2760 if (x)
2761 {
2762 t3;
2763 }
2764 } e3
2765}
2766.
2767
2768 normal gg
2769
2770 normal 2]maA
2771 call assert_equal("\ttt m1 {A", getline('.'))
2772 call assert_equal([3, 9, 16], [line('.'), col('.'), virtcol('.')])
2773
2774 normal j]maB
2775 call assert_equal("\ttt m2 {B", getline('.'))
2776 call assert_equal([7, 9, 16], [line('.'), col('.'), virtcol('.')])
2777
2778 normal ]maC
2779 call assert_equal("\ttt m3 {C", getline('.'))
2780 call assert_equal([11, 9, 16], [line('.'), col('.'), virtcol('.')])
2781
2782 normal [maD
2783 call assert_equal("\ttt m3 {DC", getline('.'))
2784 call assert_equal([11, 9, 16], [line('.'), col('.'), virtcol('.')])
2785
2786 normal k2[maE
2787 call assert_equal("\ttt m1 {EA", getline('.'))
2788 call assert_equal([3, 9, 16], [line('.'), col('.'), virtcol('.')])
2789
2790 normal 3[maF
2791 call assert_equal("{F", getline('.'))
2792 call assert_equal([2, 2, 2], [line('.'), col('.'), virtcol('.')])
2793
2794 normal ]MaG
2795 call assert_equal("\t}G e1", getline('.'))
2796 call assert_equal([5, 3, 10], [line('.'), col('.'), virtcol('.')])
2797
2798 normal j2]MaH
2799 call assert_equal("\t}H e3", getline('.'))
2800 call assert_equal([16, 3, 10], [line('.'), col('.'), virtcol('.')])
2801
2802 normal ]M]M
2803 normal aI
2804 call assert_equal("}I", getline('.'))
2805 call assert_equal([17, 2, 2], [line('.'), col('.'), virtcol('.')])
2806
2807 normal 2[MaJ
2808 call assert_equal("\t}JH e3", getline('.'))
2809 call assert_equal([16, 3, 10], [line('.'), col('.'), virtcol('.')])
2810
2811 normal k[MaK
2812 call assert_equal("\t}K e2", getline('.'))
2813 call assert_equal([9, 3, 10], [line('.'), col('.'), virtcol('.')])
2814
2815 normal 3[MaL
2816 call assert_equal("{LF", getline('.'))
2817 call assert_equal([2, 2, 2], [line('.'), col('.'), virtcol('.')])
2818
2819 close!
2820endfunc
Bram Moolenaard5c82342019-07-27 18:44:57 +02002821
Bram Moolenaar1671f442020-03-10 07:48:13 +01002822func Test_normal_gdollar_cmd()
Bram Moolenaard5c82342019-07-27 18:44:57 +02002823 if !has("jumplist")
2824 return
2825 endif
2826 " Tests for g cmds
2827 call Setup_NewWindow()
2828 " Make long lines that will wrap
2829 %s/$/\=repeat(' foobar', 10)/
2830 20vsp
2831 set wrap
2832 " Test for g$ with count
2833 norm! gg
2834 norm! 0vg$y
2835 call assert_equal(20, col("'>"))
2836 call assert_equal('1 foobar foobar foob', getreg(0))
2837 norm! gg
2838 norm! 0v4g$y
2839 call assert_equal(72, col("'>"))
2840 call assert_equal('1 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar'.."\n", getreg(0))
2841 norm! gg
2842 norm! 0v6g$y
2843 call assert_equal(40, col("'>"))
2844 call assert_equal('1 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar'.. "\n"..
2845 \ '2 foobar foobar foobar foobar foobar foo', getreg(0))
2846 set nowrap
2847 " clean up
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(20, col("'>"))
2855 call assert_equal('1 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar'.. "\n"..
2856 \ '2 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar'.. "\n"..
2857 \ '3 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar'.. "\n"..
2858 \ '4 foobar foobar foob', getreg(0))
2859 norm! gg
2860 norm! 0v6g$y
2861 call assert_equal(20, col("'>"))
2862 call assert_equal('1 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar'.. "\n"..
2863 \ '2 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar'.. "\n"..
2864 \ '3 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar'.. "\n"..
2865 \ '4 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar'.. "\n"..
2866 \ '5 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar'.. "\n"..
2867 \ '6 foobar foobar foob', getreg(0))
2868 " Move to last line, also down movement is not possible, should still move
2869 " the cursor to the last visible char
2870 norm! G
2871 norm! 0v6g$y
2872 call assert_equal(20, col("'>"))
2873 call assert_equal('100 foobar foobar fo', getreg(0))
2874 bw!
2875endfunc
Bram Moolenaar03ac52f2019-09-24 22:47:46 +02002876
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01002877func Test_normal_gk_gj()
Bram Moolenaar03ac52f2019-09-24 22:47:46 +02002878 " needs 80 column new window
2879 new
2880 vert 80new
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01002881 call assert_beeps('normal gk')
Bram Moolenaar03ac52f2019-09-24 22:47:46 +02002882 put =[repeat('x',90)..' {{{1', 'x {{{1']
2883 norm! gk
2884 " In a 80 column wide terminal the window will be only 78 char
2885 " (because Vim will leave space for the other window),
2886 " but if the terminal is larger, it will be 80 chars, so verify the
2887 " cursor column correctly.
2888 call assert_equal(winwidth(0)+1, col('.'))
2889 call assert_equal(winwidth(0)+1, virtcol('.'))
2890 norm! j
2891 call assert_equal(6, col('.'))
2892 call assert_equal(6, virtcol('.'))
2893 norm! gk
2894 call assert_equal(95, col('.'))
2895 call assert_equal(95, virtcol('.'))
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01002896 %bw!
Bram Moolenaarceba3dd2019-10-12 16:12:54 +02002897
2898 " needs 80 column new window
2899 new
2900 vert 80new
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01002901 call assert_beeps('normal gj')
Bram Moolenaarceba3dd2019-10-12 16:12:54 +02002902 set number
2903 set numberwidth=10
2904 set cpoptions+=n
2905 put =[repeat('0',90), repeat('1',90)]
2906 norm! 075l
2907 call assert_equal(76, col('.'))
2908 norm! gk
2909 call assert_equal(1, col('.'))
2910 norm! gk
2911 call assert_equal(76, col('.'))
2912 norm! gk
2913 call assert_equal(1, col('.'))
2914 norm! gj
2915 call assert_equal(76, col('.'))
2916 norm! gj
2917 call assert_equal(1, col('.'))
2918 norm! gj
2919 call assert_equal(76, col('.'))
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01002920 " When 'nowrap' is set, gk and gj behave like k and j
2921 set nowrap
2922 normal! gk
2923 call assert_equal([2, 76], [line('.'), col('.')])
2924 normal! gj
2925 call assert_equal([3, 76], [line('.'), col('.')])
2926 %bw!
2927 set cpoptions& number& numberwidth& wrap&
Bram Moolenaar03ac52f2019-09-24 22:47:46 +02002928endfunc
Bram Moolenaarf0cee192020-02-16 13:33:56 +01002929
2930" Test for cursor movement with '-' in 'cpoptions'
2931func Test_normal_cpo_minus()
2932 new
2933 call setline(1, ['foo', 'bar', 'baz'])
2934 let save_cpo = &cpo
2935 set cpo+=-
2936 call assert_beeps('normal 10j')
2937 call assert_equal(1, line('.'))
2938 normal G
2939 call assert_beeps('normal 10k')
2940 call assert_equal(3, line('.'))
2941 call assert_fails(10, 'E16:')
2942 let &cpo = save_cpo
2943 close!
2944endfunc
Bram Moolenaar818fc9a2020-02-21 17:54:45 +01002945
Bram Moolenaarca68ae12020-03-30 19:32:53 +02002946" Test for displaying dollar when changing text ('$' flag in 'cpoptions')
2947func Test_normal_cpo_dollar()
2948 new
2949 let g:Line = ''
2950 func SaveFirstLine()
2951 let g:Line = Screenline(1)
2952 return ''
2953 endfunc
2954 inoremap <expr> <buffer> <F2> SaveFirstLine()
2955 call test_override('redraw_flag', 1)
2956 set cpo+=$
2957 call setline(1, 'one two three')
2958 redraw!
2959 exe "normal c2w\<F2>vim"
2960 call assert_equal('one tw$ three', g:Line)
2961 call assert_equal('vim three', getline(1))
2962 set cpo-=$
2963 call test_override('ALL', 0)
2964 delfunc SaveFirstLine
2965 %bw!
2966endfunc
2967
Bram Moolenaar818fc9a2020-02-21 17:54:45 +01002968" Test for using : to run a multi-line Ex command in operator pending mode
2969func Test_normal_yank_with_excmd()
2970 new
2971 call setline(1, ['foo', 'bar', 'baz'])
2972 let @a = ''
2973 call feedkeys("\"ay:if v:true\<CR>normal l\<CR>endif\<CR>", 'xt')
2974 call assert_equal('f', @a)
2975 close!
2976endfunc
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01002977
2978" Test for supplying a count to a normal-mode command across a cursorhold call
2979func Test_normal_cursorhold_with_count()
2980 func s:cHold()
2981 let g:cHold_Called += 1
2982 endfunc
2983 new
2984 augroup normalcHoldTest
2985 au!
2986 au CursorHold <buffer> call s:cHold()
2987 augroup END
2988 let g:cHold_Called = 0
2989 call feedkeys("3\<CursorHold>2ix", 'xt')
2990 call assert_equal(1, g:cHold_Called)
2991 call assert_equal(repeat('x', 32), getline(1))
2992 augroup normalcHoldTest
2993 au!
2994 augroup END
2995 au! normalcHoldTest
2996 close!
2997 delfunc s:cHold
2998endfunc
2999
3000" Test for using a count and a command with CTRL-W
3001func Test_wincmd_with_count()
3002 call feedkeys("\<C-W>12n", 'xt')
3003 call assert_equal(12, winheight(0))
3004endfunc
3005
3006" Test for 'b', 'B' 'ge' and 'gE' commands
Bram Moolenaar1671f442020-03-10 07:48:13 +01003007func Test_horiz_motion()
3008 new
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01003009 normal! gg
3010 call assert_beeps('normal! b')
3011 call assert_beeps('normal! B')
3012 call assert_beeps('normal! gE')
3013 call assert_beeps('normal! ge')
Bram Moolenaar1671f442020-03-10 07:48:13 +01003014 " <S-Backspace> moves one word left and <C-Backspace> moves one WORD left
3015 call setline(1, 'one ,two ,three')
3016 exe "normal! $\<S-BS>"
3017 call assert_equal(11, col('.'))
3018 exe "normal! $\<C-BS>"
3019 call assert_equal(10, col('.'))
3020 close!
3021endfunc
3022
3023" Test for using a : command in operator pending mode
3024func Test_normal_colon_op()
3025 new
3026 call setline(1, ['one', 'two'])
3027 call assert_beeps("normal! Gc:d\<CR>")
3028 close!
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01003029endfunc
3030
3031" vim: shiftwidth=2 sts=2 expandtab