blob: 83a95f9f66f3821f0bc719d581acab5b4f6b9a95 [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=
367 bw!
368 unlet! g:opt
369endfunc
370
Bram Moolenaar1bbb6192018-11-10 16:02:01 +0100371func Test_normal10_expand()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200372 " Test for expand()
373 10new
374 call setline(1, ['1', 'ifooar,,cbar'])
375 2
376 norm! $
Bram Moolenaar65f08472017-09-10 18:16:20 +0200377 call assert_equal('cbar', expand('<cword>'))
378 call assert_equal('ifooar,,cbar', expand('<cWORD>'))
379
380 call setline(1, ['prx = list[idx];'])
381 1
382 let expected = ['', 'prx', 'prx', 'prx',
383 \ 'list', 'list', 'list', 'list', 'list', 'list', 'list',
384 \ 'idx', 'idx', 'idx', 'idx',
385 \ 'list[idx]',
386 \ '];',
387 \ ]
388 for i in range(1, 16)
389 exe 'norm ' . i . '|'
390 call assert_equal(expected[i], expand('<cexpr>'), 'i == ' . i)
391 endfor
392
Bram Moolenaarae6f8652017-12-20 22:32:20 +0100393 if executable('echo')
394 " Test expand(`...`) i.e. backticks command expansion.
Bram Moolenaar077ff432019-10-28 00:42:21 +0100395 call assert_equal('abcde', expand('`echo abcde`'))
Bram Moolenaarae6f8652017-12-20 22:32:20 +0100396 endif
397
398 " Test expand(`=...`) i.e. backticks expression expansion
399 call assert_equal('5', expand('`=2+3`'))
Bram Moolenaar8b633132020-03-20 18:20:51 +0100400 call assert_equal('3.14', expand('`=3.14`'))
Bram Moolenaarae6f8652017-12-20 22:32:20 +0100401
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200402 " clean up
403 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +0200404endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200405
Bram Moolenaar1bbb6192018-11-10 16:02:01 +0100406func Test_normal11_showcmd()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200407 " test for 'showcmd'
408 10new
409 exe "norm! ofoobar\<esc>"
410 call assert_equal(2, line('$'))
411 set showcmd
412 exe "norm! ofoobar2\<esc>"
413 call assert_equal(3, line('$'))
414 exe "norm! VAfoobar3\<esc>"
415 call assert_equal(3, line('$'))
416 exe "norm! 0d3\<del>2l"
417 call assert_equal('obar2foobar3', getline('.'))
418 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +0200419endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200420
Bram Moolenaar1671f442020-03-10 07:48:13 +0100421" Test for nv_error and normal command errors
Bram Moolenaar1bbb6192018-11-10 16:02:01 +0100422func Test_normal12_nv_error()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200423 10new
424 call setline(1, range(1,5))
425 " should not do anything, just beep
Bram Moolenaarf5f1e102020-03-08 05:13:15 +0100426 call assert_beeps('exe "norm! <c-k>"')
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200427 call assert_equal(map(range(1,5), 'string(v:val)'), getline(1,'$'))
Bram Moolenaarf5f1e102020-03-08 05:13:15 +0100428 call assert_beeps('normal! G2dd')
429 call assert_beeps("normal! g\<C-A>")
430 call assert_beeps("normal! g\<C-X>")
431 call assert_beeps("normal! g\<C-B>")
Bram Moolenaar1671f442020-03-10 07:48:13 +0100432 call assert_beeps("normal! vQ\<Esc>")
433 call assert_beeps("normal! 2[[")
434 call assert_beeps("normal! 2]]")
435 call assert_beeps("normal! 2[]")
436 call assert_beeps("normal! 2][")
437 call assert_beeps("normal! 4[z")
438 call assert_beeps("normal! 4]z")
439 call assert_beeps("normal! 4[c")
440 call assert_beeps("normal! 4]c")
441 call assert_beeps("normal! 200%")
442 call assert_beeps("normal! %")
443 call assert_beeps("normal! 2{")
444 call assert_beeps("normal! 2}")
445 call assert_beeps("normal! r\<Right>")
446 call assert_beeps("normal! 8ry")
447 call assert_beeps('normal! "@')
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200448 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +0200449endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200450
Bram Moolenaar1bbb6192018-11-10 16:02:01 +0100451func Test_normal13_help()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200452 " Test for F1
453 call assert_equal(1, winnr())
454 call feedkeys("\<f1>", 'txi')
455 call assert_match('help\.txt', bufname('%'))
456 call assert_equal(2, winnr('$'))
457 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +0200458endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200459
Bram Moolenaar1bbb6192018-11-10 16:02:01 +0100460func Test_normal14_page()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200461 " basic test for Ctrl-F and Ctrl-B
462 call Setup_NewWindow()
463 exe "norm! \<c-f>"
464 call assert_equal('9', getline('.'))
465 exe "norm! 2\<c-f>"
466 call assert_equal('25', getline('.'))
467 exe "norm! 2\<c-b>"
468 call assert_equal('18', getline('.'))
469 1
470 set scrolloff=5
471 exe "norm! 2\<c-f>"
472 call assert_equal('21', getline('.'))
473 exe "norm! \<c-b>"
474 call assert_equal('13', getline('.'))
475 1
476 set scrolloff=99
477 exe "norm! \<c-f>"
478 call assert_equal('13', getline('.'))
479 set scrolloff=0
480 100
481 exe "norm! $\<c-b>"
482 call assert_equal('92', getline('.'))
483 call assert_equal([0, 92, 1, 0, 1], getcurpos())
484 100
485 set nostartofline
486 exe "norm! $\<c-b>"
487 call assert_equal('92', getline('.'))
488 call assert_equal([0, 92, 2, 0, 2147483647], getcurpos())
489 " cleanup
490 set startofline
491 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +0200492endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200493
Bram Moolenaar1bbb6192018-11-10 16:02:01 +0100494func Test_normal14_page_eol()
Bram Moolenaarbc54f3f2016-09-04 14:34:28 +0200495 10new
496 norm oxxxxxxx
497 exe "norm 2\<c-f>"
498 " check with valgrind that cursor is put back in column 1
499 exe "norm 2\<c-b>"
500 bw!
501endfunc
502
Bram Moolenaar1671f442020-03-10 07:48:13 +0100503" Test for errors with z command
504func Test_normal_z_error()
505 call assert_beeps('normal! z2p')
506 call assert_beeps('normal! zp')
507endfunc
508
Bram Moolenaar1bbb6192018-11-10 16:02:01 +0100509func Test_normal15_z_scroll_vert()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200510 " basic test for z commands that scroll the window
511 call Setup_NewWindow()
512 100
513 norm! >>
514 " Test for z<cr>
515 exe "norm! z\<cr>"
516 call assert_equal(' 100', getline('.'))
517 call assert_equal(100, winsaveview()['topline'])
518 call assert_equal([0, 100, 2, 0, 9], getcurpos())
519
520 " Test for zt
521 21
522 norm! >>0zt
523 call assert_equal(' 21', getline('.'))
524 call assert_equal(21, winsaveview()['topline'])
525 call assert_equal([0, 21, 1, 0, 8], getcurpos())
526
527 " Test for zb
528 30
529 norm! >>$ztzb
530 call assert_equal(' 30', getline('.'))
531 call assert_equal(30, winsaveview()['topline']+winheight(0)-1)
532 call assert_equal([0, 30, 3, 0, 2147483647], getcurpos())
533
534 " Test for z-
535 1
536 30
537 norm! 0z-
538 call assert_equal(' 30', getline('.'))
539 call assert_equal(30, winsaveview()['topline']+winheight(0)-1)
540 call assert_equal([0, 30, 2, 0, 9], getcurpos())
541
542 " Test for z{height}<cr>
543 call assert_equal(10, winheight(0))
544 exe "norm! z12\<cr>"
545 call assert_equal(12, winheight(0))
546 exe "norm! z10\<cr>"
547 call assert_equal(10, winheight(0))
548
549 " Test for z.
550 1
551 21
552 norm! 0z.
553 call assert_equal(' 21', getline('.'))
554 call assert_equal(17, winsaveview()['topline'])
555 call assert_equal([0, 21, 2, 0, 9], getcurpos())
556
557 " Test for zz
558 1
559 21
560 norm! 0zz
561 call assert_equal(' 21', getline('.'))
562 call assert_equal(17, winsaveview()['topline'])
563 call assert_equal([0, 21, 1, 0, 8], getcurpos())
564
565 " Test for z+
566 11
567 norm! zt
568 norm! z+
569 call assert_equal(' 21', getline('.'))
570 call assert_equal(21, winsaveview()['topline'])
571 call assert_equal([0, 21, 2, 0, 9], getcurpos())
572
573 " Test for [count]z+
574 1
575 norm! 21z+
576 call assert_equal(' 21', getline('.'))
577 call assert_equal(21, winsaveview()['topline'])
578 call assert_equal([0, 21, 2, 0, 9], getcurpos())
579
580 " Test for z^
581 norm! 22z+0
582 norm! z^
583 call assert_equal(' 21', getline('.'))
584 call assert_equal(12, winsaveview()['topline'])
585 call assert_equal([0, 21, 2, 0, 9], getcurpos())
586
587 " Test for [count]z^
588 1
589 norm! 30z^
590 call assert_equal(' 21', getline('.'))
591 call assert_equal(12, winsaveview()['topline'])
592 call assert_equal([0, 21, 2, 0, 9], getcurpos())
593
594 " cleanup
595 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +0200596endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200597
Bram Moolenaar1bbb6192018-11-10 16:02:01 +0100598func Test_normal16_z_scroll_hor()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200599 " basic test for z commands that scroll the window
600 10new
601 15vsp
602 set nowrap listchars=
603 let lineA='abcdefghijklmnopqrstuvwxyz'
604 let lineB='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'
605 $put =lineA
606 $put =lineB
607 1d
608
Bram Moolenaar1671f442020-03-10 07:48:13 +0100609 " Test for zl and zh with a count
610 norm! 0z10l
611 call assert_equal([11, 1], [col('.'), wincol()])
612 norm! z4h
613 call assert_equal([11, 5], [col('.'), wincol()])
614 normal! 2gg
615
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200616 " Test for zl
617 1
618 norm! 5zl
619 call assert_equal(lineA, getline('.'))
620 call assert_equal(6, col('.'))
621 call assert_equal(5, winsaveview()['leftcol'])
622 norm! yl
623 call assert_equal('f', @0)
624
625 " Test for zh
626 norm! 2zh
627 call assert_equal(lineA, getline('.'))
628 call assert_equal(6, col('.'))
629 norm! yl
630 call assert_equal('f', @0)
631 call assert_equal(3, winsaveview()['leftcol'])
632
633 " Test for zL
634 norm! zL
635 call assert_equal(11, col('.'))
636 norm! yl
637 call assert_equal('k', @0)
638 call assert_equal(10, winsaveview()['leftcol'])
639 norm! 2zL
640 call assert_equal(25, col('.'))
641 norm! yl
642 call assert_equal('y', @0)
643 call assert_equal(24, winsaveview()['leftcol'])
644
645 " Test for zH
646 norm! 2zH
647 call assert_equal(25, col('.'))
648 call assert_equal(10, winsaveview()['leftcol'])
649 norm! yl
650 call assert_equal('y', @0)
651
652 " Test for zs
653 norm! $zs
654 call assert_equal(26, col('.'))
655 call assert_equal(25, winsaveview()['leftcol'])
656 norm! yl
657 call assert_equal('z', @0)
658
659 " Test for ze
660 norm! ze
661 call assert_equal(26, col('.'))
662 call assert_equal(11, winsaveview()['leftcol'])
663 norm! yl
664 call assert_equal('z', @0)
665
666 " cleanup
667 set wrap listchars=eol:$
668 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +0200669endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200670
Bram Moolenaar1bbb6192018-11-10 16:02:01 +0100671func Test_normal17_z_scroll_hor2()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200672 " basic test for z commands that scroll the window
673 " using 'sidescrolloff' setting
674 10new
675 20vsp
676 set nowrap listchars= sidescrolloff=5
677 let lineA='abcdefghijklmnopqrstuvwxyz'
678 let lineB='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'
679 $put =lineA
680 $put =lineB
681 1d
682
683 " Test for zl
684 1
685 norm! 5zl
686 call assert_equal(lineA, getline('.'))
687 call assert_equal(11, col('.'))
688 call assert_equal(5, winsaveview()['leftcol'])
689 norm! yl
690 call assert_equal('k', @0)
691
692 " Test for zh
693 norm! 2zh
694 call assert_equal(lineA, getline('.'))
695 call assert_equal(11, col('.'))
696 norm! yl
697 call assert_equal('k', @0)
698 call assert_equal(3, winsaveview()['leftcol'])
699
700 " Test for zL
701 norm! 0zL
702 call assert_equal(16, col('.'))
703 norm! yl
704 call assert_equal('p', @0)
705 call assert_equal(10, winsaveview()['leftcol'])
706 norm! 2zL
707 call assert_equal(26, col('.'))
708 norm! yl
709 call assert_equal('z', @0)
710 call assert_equal(15, winsaveview()['leftcol'])
711
712 " Test for zH
713 norm! 2zH
714 call assert_equal(15, col('.'))
715 call assert_equal(0, winsaveview()['leftcol'])
716 norm! yl
717 call assert_equal('o', @0)
718
719 " Test for zs
720 norm! $zs
721 call assert_equal(26, col('.'))
722 call assert_equal(20, winsaveview()['leftcol'])
723 norm! yl
724 call assert_equal('z', @0)
725
726 " Test for ze
727 norm! ze
728 call assert_equal(26, col('.'))
729 call assert_equal(11, winsaveview()['leftcol'])
730 norm! yl
731 call assert_equal('z', @0)
732
733 " cleanup
734 set wrap listchars=eol:$ sidescrolloff=0
735 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +0200736endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200737
Bram Moolenaar1671f442020-03-10 07:48:13 +0100738" Test for H, M and L commands with folds
739func Test_scroll_cmds()
740 15new
741 call setline(1, range(1, 100))
742 exe "normal! 30ggz\<CR>"
743 set foldenable
744 33,36fold
745 40,43fold
746 46,49fold
747 let h = winheight(0)
748 " Top of the screen = 30
749 " Folded lines = 9
750 " Bottom of the screen = 30 + h + 9 - 1
751 normal! 4L
752 call assert_equal(35 + h, line('.'))
753 normal! 4H
754 call assert_equal(33, line('.'))
755 set foldenable&
756 close!
757endfunc
758
Bram Moolenaar1bbb6192018-11-10 16:02:01 +0100759func Test_normal18_z_fold()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200760 " basic tests for foldopen/folddelete
761 if !has("folding")
762 return
763 endif
764 call Setup_NewWindow()
765 50
766 setl foldenable fdm=marker foldlevel=5
767
Bram Moolenaar1671f442020-03-10 07:48:13 +0100768 call assert_beeps('normal! zj')
769 call assert_beeps('normal! zk')
770
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200771 " Test for zF
772 " First fold
773 norm! 4zF
774 " check that folds have been created
775 call assert_equal(['50/*{{{*/', '51', '52', '53/*}}}*/'], getline(50,53))
776
777 " Test for zd
778 51
779 norm! 2zF
780 call assert_equal(2, foldlevel('.'))
781 norm! kzd
782 call assert_equal(['50', '51/*{{{*/', '52/*}}}*/', '53'], getline(50,53))
783 norm! j
784 call assert_equal(1, foldlevel('.'))
785
786 " Test for zD
787 " also deletes partially selected folds recursively
788 51
789 norm! zF
790 call assert_equal(2, foldlevel('.'))
791 norm! kV2jzD
792 call assert_equal(['50', '51', '52', '53'], getline(50,53))
793
794 " Test for zE
795 85
796 norm! 4zF
797 86
798 norm! 2zF
799 90
800 norm! 4zF
801 call assert_equal(['85/*{{{*/', '86/*{{{*/', '87/*}}}*/', '88/*}}}*/', '89', '90/*{{{*/', '91', '92', '93/*}}}*/'], getline(85,93))
802 norm! zE
803 call assert_equal(['85', '86', '87', '88', '89', '90', '91', '92', '93'], getline(85,93))
804
805 " Test for zn
806 50
807 set foldlevel=0
808 norm! 2zF
809 norm! zn
810 norm! k
811 call assert_equal('49', getline('.'))
812 norm! j
813 call assert_equal('50/*{{{*/', getline('.'))
814 norm! j
815 call assert_equal('51/*}}}*/', getline('.'))
816 norm! j
817 call assert_equal('52', getline('.'))
818 call assert_equal(0, &foldenable)
819
820 " Test for zN
821 49
822 norm! zN
823 call assert_equal('49', getline('.'))
824 norm! j
825 call assert_equal('50/*{{{*/', getline('.'))
826 norm! j
827 call assert_equal('52', getline('.'))
828 call assert_equal(1, &foldenable)
829
830 " Test for zi
831 norm! zi
832 call assert_equal(0, &foldenable)
833 norm! zi
834 call assert_equal(1, &foldenable)
835 norm! zi
836 call assert_equal(0, &foldenable)
837 norm! zi
838 call assert_equal(1, &foldenable)
839
840 " Test for za
841 50
842 norm! za
843 norm! k
844 call assert_equal('49', getline('.'))
845 norm! j
846 call assert_equal('50/*{{{*/', getline('.'))
847 norm! j
848 call assert_equal('51/*}}}*/', getline('.'))
849 norm! j
850 call assert_equal('52', getline('.'))
851 50
852 norm! za
853 norm! k
854 call assert_equal('49', getline('.'))
855 norm! j
856 call assert_equal('50/*{{{*/', getline('.'))
857 norm! j
858 call assert_equal('52', getline('.'))
859
860 49
861 norm! 5zF
862 norm! k
863 call assert_equal('48', getline('.'))
864 norm! j
865 call assert_equal('49/*{{{*/', getline('.'))
866 norm! j
867 call assert_equal('55', getline('.'))
868 49
869 norm! za
870 call assert_equal('49/*{{{*/', getline('.'))
871 norm! j
872 call assert_equal('50/*{{{*/', getline('.'))
873 norm! j
874 call assert_equal('52', getline('.'))
875 set nofoldenable
876 " close fold and set foldenable
877 norm! za
878 call assert_equal(1, &foldenable)
879
880 50
881 " have to use {count}za to open all folds and make the cursor visible
882 norm! 2za
883 norm! 2k
884 call assert_equal('48', getline('.'))
885 norm! j
886 call assert_equal('49/*{{{*/', getline('.'))
887 norm! j
888 call assert_equal('50/*{{{*/', getline('.'))
889 norm! j
890 call assert_equal('51/*}}}*/', getline('.'))
891 norm! j
892 call assert_equal('52', getline('.'))
893
894 " Test for zA
895 49
896 set foldlevel=0
897 50
898 norm! zA
899 norm! 2k
900 call assert_equal('48', getline('.'))
901 norm! j
902 call assert_equal('49/*{{{*/', getline('.'))
903 norm! j
904 call assert_equal('50/*{{{*/', getline('.'))
905 norm! j
906 call assert_equal('51/*}}}*/', getline('.'))
907 norm! j
908 call assert_equal('52', getline('.'))
909
Bram Moolenaar395b6ba2017-04-07 20:09:51 +0200910 " zA on a opened fold when foldenable is not set
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200911 50
912 set nofoldenable
913 norm! zA
914 call assert_equal(1, &foldenable)
915 norm! k
916 call assert_equal('48', getline('.'))
917 norm! j
918 call assert_equal('49/*{{{*/', getline('.'))
919 norm! j
920 call assert_equal('55', getline('.'))
921
922 " Test for zc
923 norm! zE
924 50
925 norm! 2zF
926 49
927 norm! 5zF
928 set nofoldenable
929 50
930 " There most likely is a bug somewhere:
931 " https://groups.google.com/d/msg/vim_dev/v2EkfJ_KQjI/u-Cvv94uCAAJ
932 " TODO: Should this only close the inner most fold or both folds?
933 norm! zc
934 call assert_equal(1, &foldenable)
935 norm! k
936 call assert_equal('48', getline('.'))
937 norm! j
938 call assert_equal('49/*{{{*/', getline('.'))
939 norm! j
940 call assert_equal('55', getline('.'))
941 set nofoldenable
942 50
943 norm! Vjzc
944 norm! k
945 call assert_equal('48', getline('.'))
946 norm! j
947 call assert_equal('49/*{{{*/', getline('.'))
948 norm! j
949 call assert_equal('55', getline('.'))
950
951 " Test for zC
952 set nofoldenable
953 50
954 norm! zCk
955 call assert_equal('48', getline('.'))
956 norm! j
957 call assert_equal('49/*{{{*/', getline('.'))
958 norm! j
959 call assert_equal('55', getline('.'))
960
961 " Test for zx
962 " 1) close folds at line 49-54
963 set nofoldenable
964 48
965 norm! zx
966 call assert_equal(1, &foldenable)
967 norm! j
968 call assert_equal('49/*{{{*/', getline('.'))
969 norm! j
970 call assert_equal('55', getline('.'))
971
Bram Moolenaar395b6ba2017-04-07 20:09:51 +0200972 " 2) do not close fold under cursor
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200973 51
974 set nofoldenable
975 norm! zx
976 call assert_equal(1, &foldenable)
977 norm! 3k
978 call assert_equal('48', getline('.'))
979 norm! j
980 call assert_equal('49/*{{{*/', getline('.'))
981 norm! j
982 call assert_equal('50/*{{{*/', getline('.'))
983 norm! j
984 call assert_equal('51/*}}}*/', getline('.'))
985 norm! j
986 call assert_equal('52', getline('.'))
987 norm! j
988 call assert_equal('53', getline('.'))
989 norm! j
990 call assert_equal('54/*}}}*/', getline('.'))
991 norm! j
992 call assert_equal('55', getline('.'))
993
994 " 3) close one level of folds
995 48
996 set nofoldenable
997 set foldlevel=1
998 norm! zx
999 call assert_equal(1, &foldenable)
1000 call assert_equal('48', getline('.'))
1001 norm! j
1002 call assert_equal('49/*{{{*/', getline('.'))
1003 norm! j
1004 call assert_equal('50/*{{{*/', getline('.'))
1005 norm! j
1006 call assert_equal('52', getline('.'))
1007 norm! j
1008 call assert_equal('53', getline('.'))
1009 norm! j
1010 call assert_equal('54/*}}}*/', getline('.'))
1011 norm! j
1012 call assert_equal('55', getline('.'))
1013
1014 " Test for zX
1015 " Close all folds
1016 set foldlevel=0 nofoldenable
1017 50
1018 norm! zX
1019 call assert_equal(1, &foldenable)
1020 norm! k
1021 call assert_equal('48', getline('.'))
1022 norm! j
1023 call assert_equal('49/*{{{*/', getline('.'))
1024 norm! j
1025 call assert_equal('55', getline('.'))
1026
1027 " Test for zm
1028 50
1029 set nofoldenable foldlevel=2
1030 norm! zm
1031 call assert_equal(1, &foldenable)
1032 call assert_equal(1, &foldlevel)
1033 norm! zm
1034 call assert_equal(0, &foldlevel)
1035 norm! zm
1036 call assert_equal(0, &foldlevel)
1037 norm! k
1038 call assert_equal('48', getline('.'))
1039 norm! j
1040 call assert_equal('49/*{{{*/', getline('.'))
1041 norm! j
1042 call assert_equal('55', getline('.'))
1043
1044 " Test for zM
1045 48
1046 set nofoldenable foldlevel=99
1047 norm! zM
1048 call assert_equal(1, &foldenable)
1049 call assert_equal(0, &foldlevel)
1050 call assert_equal('48', getline('.'))
1051 norm! j
1052 call assert_equal('49/*{{{*/', getline('.'))
1053 norm! j
1054 call assert_equal('55', getline('.'))
1055
1056 " Test for zr
1057 48
1058 set nofoldenable foldlevel=0
1059 norm! zr
1060 call assert_equal(0, &foldenable)
1061 call assert_equal(1, &foldlevel)
1062 set foldlevel=0 foldenable
1063 norm! zr
1064 call assert_equal(1, &foldenable)
1065 call assert_equal(1, &foldlevel)
1066 norm! zr
1067 call assert_equal(2, &foldlevel)
1068 call assert_equal('48', getline('.'))
1069 norm! j
1070 call assert_equal('49/*{{{*/', getline('.'))
1071 norm! j
1072 call assert_equal('50/*{{{*/', getline('.'))
1073 norm! j
1074 call assert_equal('51/*}}}*/', getline('.'))
1075 norm! j
1076 call assert_equal('52', getline('.'))
1077
1078 " Test for zR
1079 48
1080 set nofoldenable foldlevel=0
1081 norm! zR
1082 call assert_equal(0, &foldenable)
1083 call assert_equal(2, &foldlevel)
1084 set foldenable foldlevel=0
1085 norm! zR
1086 call assert_equal(1, &foldenable)
1087 call assert_equal(2, &foldlevel)
1088 call assert_equal('48', getline('.'))
1089 norm! j
1090 call assert_equal('49/*{{{*/', getline('.'))
1091 norm! j
1092 call assert_equal('50/*{{{*/', getline('.'))
1093 norm! j
1094 call assert_equal('51/*}}}*/', getline('.'))
1095 norm! j
1096 call assert_equal('52', getline('.'))
1097 call append(50, ['a /*{{{*/', 'b /*}}}*/'])
1098 48
1099 call assert_equal('48', getline('.'))
1100 norm! j
1101 call assert_equal('49/*{{{*/', getline('.'))
1102 norm! j
1103 call assert_equal('50/*{{{*/', getline('.'))
1104 norm! j
1105 call assert_equal('a /*{{{*/', getline('.'))
1106 norm! j
1107 call assert_equal('51/*}}}*/', getline('.'))
1108 norm! j
1109 call assert_equal('52', getline('.'))
1110 48
1111 norm! zR
1112 call assert_equal(1, &foldenable)
1113 call assert_equal(3, &foldlevel)
1114 call assert_equal('48', getline('.'))
1115 norm! j
1116 call assert_equal('49/*{{{*/', getline('.'))
1117 norm! j
1118 call assert_equal('50/*{{{*/', getline('.'))
1119 norm! j
1120 call assert_equal('a /*{{{*/', getline('.'))
1121 norm! j
1122 call assert_equal('b /*}}}*/', getline('.'))
1123 norm! j
1124 call assert_equal('51/*}}}*/', getline('.'))
1125 norm! j
1126 call assert_equal('52', getline('.'))
1127
1128 " clean up
1129 setl nofoldenable fdm=marker foldlevel=0
1130 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02001131endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001132
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01001133func Test_normal20_exmode()
Bram Moolenaar0913a102016-09-03 19:11:59 +02001134 if !has("unix")
1135 " Reading from redirected file doesn't work on MS-Windows
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001136 return
1137 endif
1138 call writefile(['1a', 'foo', 'bar', '.', 'w! Xfile2', 'q!'], 'Xscript')
1139 call writefile(['1', '2'], 'Xfile')
Bram Moolenaar93344c22019-08-14 21:12:05 +02001140 call system(GetVimCommand() .. ' -e -s < Xscript Xfile')
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001141 let a=readfile('Xfile2')
1142 call assert_equal(['1', 'foo', 'bar', '2'], a)
1143
1144 " clean up
1145 for file in ['Xfile', 'Xfile2', 'Xscript']
1146 call delete(file)
1147 endfor
1148 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02001149endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001150
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01001151func Test_normal21_nv_hat()
1152
1153 " Edit a fresh file and wipe the buffer list so that there is no alternate
1154 " file present. Next, check for the expected command failures.
1155 edit Xfoo | %bw
1156 call assert_fails(':buffer #', 'E86')
1157 call assert_fails(':execute "normal! \<C-^>"', 'E23')
1158
1159 " Test for the expected behavior when switching between two named buffers.
1160 edit Xfoo | edit Xbar
1161 call feedkeys("\<C-^>", 'tx')
1162 call assert_equal('Xfoo', fnamemodify(bufname('%'), ':t'))
1163 call feedkeys("\<C-^>", 'tx')
1164 call assert_equal('Xbar', fnamemodify(bufname('%'), ':t'))
1165
1166 " Test for the expected behavior when only one buffer is named.
1167 enew | let l:nr = bufnr('%')
1168 call feedkeys("\<C-^>", 'tx')
1169 call assert_equal('Xbar', fnamemodify(bufname('%'), ':t'))
1170 call feedkeys("\<C-^>", 'tx')
1171 call assert_equal('', bufname('%'))
1172 call assert_equal(l:nr, bufnr('%'))
1173
1174 " Test that no action is taken by "<C-^>" when an operator is pending.
1175 edit Xfoo
1176 call feedkeys("ci\<C-^>", 'tx')
1177 call assert_equal('Xfoo', fnamemodify(bufname('%'), ':t'))
1178
1179 %bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02001180endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001181
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01001182func Test_normal22_zet()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001183 " Test for ZZ
Bram Moolenaar0913a102016-09-03 19:11:59 +02001184 " let shell = &shell
1185 " let &shell = 'sh'
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001186 call writefile(['1', '2'], 'Xfile')
Bram Moolenaar93344c22019-08-14 21:12:05 +02001187 let args = ' -N -i NONE --noplugins -X --not-a-term'
1188 call system(GetVimCommand() .. args .. ' -c "%d" -c ":norm! ZZ" Xfile')
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001189 let a = readfile('Xfile')
1190 call assert_equal([], a)
1191 " Test for ZQ
1192 call writefile(['1', '2'], 'Xfile')
Bram Moolenaar93344c22019-08-14 21:12:05 +02001193 call system(GetVimCommand() . args . ' -c "%d" -c ":norm! ZQ" Xfile')
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001194 let a = readfile('Xfile')
1195 call assert_equal(['1', '2'], a)
1196
Bram Moolenaar1671f442020-03-10 07:48:13 +01001197 " Unsupported Z command
1198 call assert_beeps('normal! ZW')
1199
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001200 " clean up
1201 for file in ['Xfile']
1202 call delete(file)
1203 endfor
Bram Moolenaar0913a102016-09-03 19:11:59 +02001204 " let &shell = shell
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02001205endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001206
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01001207func Test_normal23_K()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001208 " Test for K command
1209 new
Bram Moolenaar426f3752016-11-04 21:22:37 +01001210 call append(0, ['version8.txt', 'man', 'aa%bb', 'cc|dd'])
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001211 let k = &keywordprg
1212 set keywordprg=:help
1213 1
1214 norm! VK
1215 call assert_equal('version8.txt', fnamemodify(bufname('%'), ':t'))
1216 call assert_equal('help', &ft)
1217 call assert_match('\*version8.txt\*', getline('.'))
1218 helpclose
1219 norm! 0K
1220 call assert_equal('version8.txt', fnamemodify(bufname('%'), ':t'))
1221 call assert_equal('help', &ft)
Bram Moolenaarb1c91982018-05-17 17:04:55 +02001222 call assert_match('\*version8\.\d\*', getline('.'))
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001223 helpclose
1224
Bram Moolenaar426f3752016-11-04 21:22:37 +01001225 set keywordprg=:new
1226 set iskeyword+=%
1227 set iskeyword+=\|
1228 2
1229 norm! K
1230 call assert_equal('man', fnamemodify(bufname('%'), ':t'))
1231 bwipe!
1232 3
1233 norm! K
1234 call assert_equal('aa%bb', fnamemodify(bufname('%'), ':t'))
1235 bwipe!
Bram Moolenaareb828d02016-11-05 19:54:01 +01001236 if !has('win32')
1237 4
1238 norm! K
1239 call assert_equal('cc|dd', fnamemodify(bufname('%'), ':t'))
1240 bwipe!
1241 endif
Bram Moolenaar426f3752016-11-04 21:22:37 +01001242 set iskeyword-=%
1243 set iskeyword-=\|
1244
Bram Moolenaar0913a102016-09-03 19:11:59 +02001245 " Only expect "man" to work on Unix
1246 if !has("unix")
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001247 let &keywordprg = k
1248 bw!
1249 return
1250 endif
Bram Moolenaarc6b37db2019-04-27 18:00:34 +02001251
Bram Moolenaar9134f1e2019-11-29 20:26:13 +01001252 let not_gnu_man = has('mac') || has('bsd')
1253 if not_gnu_man
Bram Moolenaarc7d2a572019-11-28 21:16:06 +01001254 " In MacOS and BSD, the option for specifying a pager is different
Bram Moolenaarc6b37db2019-04-27 18:00:34 +02001255 set keywordprg=man\ -P\ cat
1256 else
1257 set keywordprg=man\ --pager=cat
1258 endif
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001259 " Test for using man
1260 2
1261 let a = execute('unsilent norm! K')
Bram Moolenaar9134f1e2019-11-29 20:26:13 +01001262 if not_gnu_man
Bram Moolenaarc6b37db2019-04-27 18:00:34 +02001263 call assert_match("man -P cat 'man'", a)
1264 else
1265 call assert_match("man --pager=cat 'man'", a)
1266 endif
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001267
Bram Moolenaar1671f442020-03-10 07:48:13 +01001268 " Error cases
1269 call setline(1, '#$#')
1270 call assert_fails('normal! ggK', 'E349:')
1271 call setline(1, '---')
1272 call assert_fails('normal! ggv2lK', 'E349:')
1273 call setline(1, ['abc', 'xyz'])
1274 call assert_fails("normal! gg2lv2h\<C-]>", 'E426:')
1275 call assert_beeps("normal! ggVjK")
1276
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001277 " clean up
1278 let &keywordprg = k
1279 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02001280endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001281
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01001282func Test_normal24_rot13()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001283 " Testing for g?? g?g?
1284 new
1285 call append(0, 'abcdefghijklmnopqrstuvwxyzäüö')
1286 1
1287 norm! g??
1288 call assert_equal('nopqrstuvwxyzabcdefghijklmäüö', getline('.'))
1289 norm! g?g?
1290 call assert_equal('abcdefghijklmnopqrstuvwxyzäüö', getline('.'))
1291
1292 " clean up
1293 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02001294endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001295
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01001296func Test_normal25_tag()
Bram Moolenaar5a4c3082019-12-01 15:23:11 +01001297 CheckFeature quickfix
1298
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001299 " Testing for CTRL-] g CTRL-] g]
1300 " CTRL-W g] CTRL-W CTRL-] CTRL-W g CTRL-]
1301 h
1302 " Test for CTRL-]
1303 call search('\<x\>$')
1304 exe "norm! \<c-]>"
1305 call assert_equal("change.txt", fnamemodify(bufname('%'), ':t'))
1306 norm! yiW
1307 call assert_equal("*x*", @0)
1308 exe ":norm \<c-o>"
1309
1310 " Test for g_CTRL-]
1311 call search('\<v_u\>$')
1312 exe "norm! g\<c-]>"
1313 call assert_equal("change.txt", fnamemodify(bufname('%'), ':t'))
1314 norm! yiW
1315 call assert_equal("*v_u*", @0)
1316 exe ":norm \<c-o>"
1317
1318 " Test for g]
1319 call search('\<i_<Esc>$')
1320 let a = execute(":norm! g]")
1321 call assert_match('i_<Esc>.*insert.txt', a)
1322
1323 if !empty(exepath('cscope')) && has('cscope')
1324 " setting cscopetag changes how g] works
1325 set cst
1326 exe "norm! g]"
1327 call assert_equal("insert.txt", fnamemodify(bufname('%'), ':t'))
1328 norm! yiW
1329 call assert_equal("*i_<Esc>*", @0)
1330 exe ":norm \<c-o>"
1331 " Test for CTRL-W g]
1332 exe "norm! \<C-W>g]"
1333 call assert_equal("insert.txt", fnamemodify(bufname('%'), ':t'))
1334 norm! yiW
1335 call assert_equal("*i_<Esc>*", @0)
1336 call assert_equal(3, winnr('$'))
1337 helpclose
1338 set nocst
1339 endif
1340
1341 " Test for CTRL-W g]
1342 let a = execute("norm! \<C-W>g]")
1343 call assert_match('i_<Esc>.*insert.txt', a)
1344
1345 " Test for CTRL-W CTRL-]
1346 exe "norm! \<C-W>\<C-]>"
1347 call assert_equal("insert.txt", fnamemodify(bufname('%'), ':t'))
1348 norm! yiW
1349 call assert_equal("*i_<Esc>*", @0)
1350 call assert_equal(3, winnr('$'))
1351 helpclose
1352
1353 " Test for CTRL-W g CTRL-]
1354 exe "norm! \<C-W>g\<C-]>"
1355 call assert_equal("insert.txt", fnamemodify(bufname('%'), ':t'))
1356 norm! yiW
1357 call assert_equal("*i_<Esc>*", @0)
1358 call assert_equal(3, winnr('$'))
1359 helpclose
1360
1361 " clean up
1362 helpclose
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02001363endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001364
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01001365func Test_normal26_put()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001366 " Test for ]p ]P [p and [P
1367 new
1368 call append(0, ['while read LINE', 'do', ' ((count++))', ' if [ $? -ne 0 ]; then', " echo 'Error writing file'", ' fi', 'done'])
1369 1
1370 /Error/y a
1371 2
1372 norm! "a]pj"a[p
1373 call assert_equal(['do', "echo 'Error writing file'", " echo 'Error writing file'", ' ((count++))'], getline(2,5))
1374 1
1375 /^\s\{4}/
1376 exe "norm! \"a]P3Eldt'"
1377 exe "norm! j\"a[P2Eldt'"
1378 call assert_equal([' if [ $? -ne 0 ]; then', " echo 'Error writing'", " echo 'Error'", " echo 'Error writing file'", ' fi'], getline(6,10))
1379
1380 " clean up
1381 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02001382endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001383
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01001384func Test_normal27_bracket()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001385 " Test for [' [` ]' ]`
1386 call Setup_NewWindow()
1387 1,21s/.\+/ & b/
1388 1
1389 norm! $ma
1390 5
1391 norm! $mb
1392 10
1393 norm! $mc
1394 15
1395 norm! $md
1396 20
1397 norm! $me
1398
1399 " Test for ['
1400 9
1401 norm! 2['
1402 call assert_equal(' 1 b', getline('.'))
1403 call assert_equal(1, line('.'))
1404 call assert_equal(3, col('.'))
1405
1406 " Test for ]'
1407 norm! ]'
1408 call assert_equal(' 5 b', getline('.'))
1409 call assert_equal(5, line('.'))
1410 call assert_equal(3, col('.'))
1411
1412 " No mark after line 21, cursor moves to first non blank on current line
1413 21
1414 norm! $]'
1415 call assert_equal(' 21 b', getline('.'))
1416 call assert_equal(21, line('.'))
1417 call assert_equal(3, col('.'))
1418
1419 " Test for [`
1420 norm! 2[`
1421 call assert_equal(' 15 b', getline('.'))
1422 call assert_equal(15, line('.'))
1423 call assert_equal(8, col('.'))
1424
1425 " Test for ]`
1426 norm! ]`
1427 call assert_equal(' 20 b', getline('.'))
1428 call assert_equal(20, line('.'))
1429 call assert_equal(8, col('.'))
1430
1431 " clean up
1432 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02001433endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001434
Bram Moolenaar1671f442020-03-10 07:48:13 +01001435" Test for ( and ) sentence movements
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01001436func Test_normal28_parenthesis()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001437 new
1438 call append(0, ['This is a test. With some sentences!', '', 'Even with a question? And one more. And no sentence here'])
1439
1440 $
1441 norm! d(
1442 call assert_equal(['This is a test. With some sentences!', '', 'Even with a question? And one more. ', ''], getline(1, '$'))
1443 norm! 2d(
1444 call assert_equal(['This is a test. With some sentences!', '', ' ', ''], getline(1, '$'))
1445 1
1446 norm! 0d)
1447 call assert_equal(['With some sentences!', '', ' ', ''], getline(1, '$'))
1448
1449 call append('$', ['This is a long sentence', '', 'spanning', 'over several lines. '])
1450 $
1451 norm! $d(
1452 call assert_equal(['With some sentences!', '', ' ', '', 'This is a long sentence', ''], getline(1, '$'))
1453
Bram Moolenaar1671f442020-03-10 07:48:13 +01001454 " It is an error if a next sentence is not found
1455 %d
1456 call setline(1, '.SH')
1457 call assert_beeps('normal )')
1458
1459 " Jumping to a fold should open the fold
1460 call setline(1, ['', '', 'one', 'two', 'three'])
1461 set foldenable
1462 2,$fold
1463 call feedkeys(')', 'xt')
1464 call assert_equal(3, line('.'))
1465 call assert_equal(1, foldlevel('.'))
1466 call assert_equal(-1, foldclosed('.'))
1467 set foldenable&
1468
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001469 " clean up
1470 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02001471endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001472
Bram Moolenaar1671f442020-03-10 07:48:13 +01001473" Test for { and } paragraph movements
1474func Test_normal29_brace()
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001475 let text =<< trim [DATA]
Bram Moolenaare7eb9272019-06-24 00:58:07 +02001476 A paragraph begins after each empty line, and also at each of a set of
1477 paragraph macros, specified by the pairs of characters in the 'paragraphs'
1478 option. The default is "IPLPPPQPP TPHPLIPpLpItpplpipbp", which corresponds to
1479 the macros ".IP", ".LP", etc. (These are nroff macros, so the dot must be in
1480 the first column). A section boundary is also a paragraph boundary.
1481 Note that a blank line (only containing white space) is NOT a paragraph
1482 boundary.
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001483
1484
Bram Moolenaare7eb9272019-06-24 00:58:07 +02001485 Also note that this does not include a '{' or '}' in the first column. When
1486 the '{' flag is in 'cpoptions' then '{' in the first column is used as a
1487 paragraph boundary |posix|.
1488 {
1489 This is no paragraph
1490 unless the '{' is set
1491 in 'cpoptions'
1492 }
1493 .IP
1494 The nroff macros IP separates a paragraph
1495 That means, it must be a '.'
1496 followed by IP
1497 .LPIt does not matter, if afterwards some
1498 more characters follow.
1499 .SHAlso section boundaries from the nroff
1500 macros terminate a paragraph. That means
1501 a character like this:
1502 .NH
1503 End of text here
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001504 [DATA]
1505
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001506 new
1507 call append(0, text)
1508 1
1509 norm! 0d2}
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001510
1511 let expected =<< trim [DATA]
Bram Moolenaare7eb9272019-06-24 00:58:07 +02001512 .IP
1513 The nroff macros IP separates a paragraph
1514 That means, it must be a '.'
1515 followed by IP
1516 .LPIt does not matter, if afterwards some
1517 more characters follow.
1518 .SHAlso section boundaries from the nroff
1519 macros terminate a paragraph. That means
1520 a character like this:
1521 .NH
1522 End of text here
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001523
1524 [DATA]
1525 call assert_equal(expected, getline(1, '$'))
1526
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001527 norm! 0d}
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001528
1529 let expected =<< trim [DATA]
Bram Moolenaare7eb9272019-06-24 00:58:07 +02001530 .LPIt does not matter, if afterwards some
1531 more characters follow.
1532 .SHAlso section boundaries from the nroff
1533 macros terminate a paragraph. That means
1534 a character like this:
1535 .NH
1536 End of text here
1537
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001538 [DATA]
1539 call assert_equal(expected, getline(1, '$'))
1540
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001541 $
1542 norm! d{
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001543
1544 let expected =<< trim [DATA]
Bram Moolenaare7eb9272019-06-24 00:58:07 +02001545 .LPIt does not matter, if afterwards some
1546 more characters follow.
1547 .SHAlso section boundaries from the nroff
1548 macros terminate a paragraph. That means
1549 a character like this:
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001550
1551 [DATA]
1552 call assert_equal(expected, getline(1, '$'))
1553
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001554 norm! d{
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001555
1556 let expected =<< trim [DATA]
Bram Moolenaare7eb9272019-06-24 00:58:07 +02001557 .LPIt does not matter, if afterwards some
1558 more characters follow.
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001559
1560 [DATA]
1561 call assert_equal(expected, getline(1, '$'))
1562
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001563 " Test with { in cpooptions
1564 %d
1565 call append(0, text)
1566 set cpo+={
1567 1
1568 norm! 0d2}
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001569
1570 let expected =<< trim [DATA]
Bram Moolenaare7eb9272019-06-24 00:58:07 +02001571 {
1572 This is no paragraph
1573 unless the '{' is set
1574 in 'cpoptions'
1575 }
1576 .IP
1577 The nroff macros IP separates a paragraph
1578 That means, it must be a '.'
1579 followed by IP
1580 .LPIt does not matter, if afterwards some
1581 more characters follow.
1582 .SHAlso section boundaries from the nroff
1583 macros terminate a paragraph. That means
1584 a character like this:
1585 .NH
1586 End of text here
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001587
1588 [DATA]
1589 call assert_equal(expected, getline(1, '$'))
1590
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001591 $
1592 norm! d}
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001593
1594 let expected =<< trim [DATA]
Bram Moolenaare7eb9272019-06-24 00:58:07 +02001595 {
1596 This is no paragraph
1597 unless the '{' is set
1598 in 'cpoptions'
1599 }
1600 .IP
1601 The nroff macros IP separates a paragraph
1602 That means, it must be a '.'
1603 followed by IP
1604 .LPIt does not matter, if afterwards some
1605 more characters follow.
1606 .SHAlso section boundaries from the nroff
1607 macros terminate a paragraph. That means
1608 a character like this:
1609 .NH
1610 End of text here
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001611
1612 [DATA]
1613 call assert_equal(expected, getline(1, '$'))
1614
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001615 norm! gg}
1616 norm! d5}
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001617
1618 let expected =<< trim [DATA]
Bram Moolenaare7eb9272019-06-24 00:58:07 +02001619 {
1620 This is no paragraph
1621 unless the '{' is set
1622 in 'cpoptions'
1623 }
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001624
1625 [DATA]
1626 call assert_equal(expected, getline(1, '$'))
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001627
Bram Moolenaar1671f442020-03-10 07:48:13 +01001628 " Jumping to a fold should open the fold
1629 %d
1630 call setline(1, ['', 'one', 'two', ''])
1631 set foldenable
1632 2,$fold
1633 call feedkeys('}', 'xt')
1634 call assert_equal(4, line('.'))
1635 call assert_equal(1, foldlevel('.'))
1636 call assert_equal(-1, foldclosed('.'))
1637 set foldenable&
1638
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001639 " clean up
1640 set cpo-={
1641 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02001642endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001643
Bram Moolenaar1671f442020-03-10 07:48:13 +01001644" Test for ~ command
1645func Test_normal30_changecase()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001646 new
1647 call append(0, 'This is a simple test: äüöß')
1648 norm! 1ggVu
1649 call assert_equal('this is a simple test: äüöß', getline('.'))
1650 norm! VU
1651 call assert_equal('THIS IS A SIMPLE TEST: ÄÜÖSS', getline('.'))
1652 norm! guu
1653 call assert_equal('this is a simple test: äüöss', getline('.'))
1654 norm! gUgU
1655 call assert_equal('THIS IS A SIMPLE TEST: ÄÜÖSS', getline('.'))
1656 norm! gugu
1657 call assert_equal('this is a simple test: äüöss', getline('.'))
1658 norm! gUU
1659 call assert_equal('THIS IS A SIMPLE TEST: ÄÜÖSS', getline('.'))
1660 norm! 010~
1661 call assert_equal('this is a SIMPLE TEST: ÄÜÖSS', getline('.'))
1662 norm! V~
1663 call assert_equal('THIS IS A simple test: äüöss', getline('.'))
1664
Bram Moolenaar1671f442020-03-10 07:48:13 +01001665 " Test for changing case across lines using 'whichwrap'
1666 call setline(1, ['aaaaaa', 'aaaaaa'])
1667 normal! gg10~
1668 call assert_equal(['AAAAAA', 'aaaaaa'], getline(1, 2))
1669 set whichwrap+=~
1670 normal! gg10~
1671 call assert_equal(['aaaaaa', 'AAAAaa'], getline(1, 2))
1672 set whichwrap&
1673
1674 " clean up
1675 bw!
1676endfunc
1677
1678" Turkish ASCII turns to multi-byte. On some systems Turkish locale
1679" is available but toupper()/tolower() don't do the right thing.
1680func Test_normal_changecase_turkish()
1681 new
Bram Moolenaarf1c118b2018-09-03 22:08:10 +02001682 try
1683 lang tr_TR.UTF-8
1684 set casemap=
1685 let iupper = toupper('i')
1686 if iupper == "\u0130"
Bram Moolenaar9f4de1f2017-04-08 19:39:43 +02001687 call setline(1, 'iI')
1688 1normal gUU
1689 call assert_equal("\u0130I", getline(1))
1690 call assert_equal("\u0130I", toupper("iI"))
Bram Moolenaar3317d5e2017-04-08 19:12:06 +02001691
Bram Moolenaar9f4de1f2017-04-08 19:39:43 +02001692 call setline(1, 'iI')
1693 1normal guu
1694 call assert_equal("i\u0131", getline(1))
1695 call assert_equal("i\u0131", tolower("iI"))
Bram Moolenaarf1c118b2018-09-03 22:08:10 +02001696 elseif iupper == "I"
Bram Moolenaar1cc48202017-04-09 13:41:59 +02001697 call setline(1, 'iI')
1698 1normal gUU
1699 call assert_equal("II", getline(1))
1700 call assert_equal("II", toupper("iI"))
1701
1702 call setline(1, 'iI')
1703 1normal guu
1704 call assert_equal("ii", getline(1))
1705 call assert_equal("ii", tolower("iI"))
Bram Moolenaarf1c118b2018-09-03 22:08:10 +02001706 else
1707 call assert_true(false, "expected toupper('i') to be either 'I' or '\u0130'")
1708 endif
1709 set casemap&
1710 call setline(1, 'iI')
1711 1normal gUU
1712 call assert_equal("II", getline(1))
1713 call assert_equal("II", toupper("iI"))
Bram Moolenaar1cc48202017-04-09 13:41:59 +02001714
Bram Moolenaarf1c118b2018-09-03 22:08:10 +02001715 call setline(1, 'iI')
1716 1normal guu
1717 call assert_equal("ii", getline(1))
1718 call assert_equal("ii", tolower("iI"))
1719
1720 lang en_US.UTF-8
1721 catch /E197:/
1722 " can't use Turkish locale
1723 throw 'Skipped: Turkish locale not available'
1724 endtry
Bram Moolenaar1671f442020-03-10 07:48:13 +01001725 close!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02001726endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001727
Bram Moolenaar1671f442020-03-10 07:48:13 +01001728" Test for r (replace) command
1729func Test_normal31_r_cmd()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001730 new
1731 call append(0, 'This is a simple test: abcd')
1732 exe "norm! 1gg$r\<cr>"
1733 call assert_equal(['This is a simple test: abc', '', ''], getline(1,'$'))
1734 exe "norm! 1gg2wlr\<cr>"
1735 call assert_equal(['This is a', 'simple test: abc', '', ''], getline(1,'$'))
1736 exe "norm! 2gg0W5r\<cr>"
1737 call assert_equal(['This is a', 'simple ', ' abc', '', ''], getline('1', '$'))
1738 set autoindent
1739 call setline(2, ['simple test: abc', ''])
1740 exe "norm! 2gg0W5r\<cr>"
1741 call assert_equal(['This is a', 'simple ', 'abc', '', '', ''], getline('1', '$'))
1742 exe "norm! 1ggVr\<cr>"
1743 call assert_equal('^M^M^M^M^M^M^M^M^M', strtrans(getline(1)))
1744 call setline(1, 'This is a')
1745 exe "norm! 1gg05rf"
1746 call assert_equal('fffffis a', getline(1))
1747
Bram Moolenaar1671f442020-03-10 07:48:13 +01001748 " When replacing characters, copy characters from above and below lines
1749 " using CTRL-Y and CTRL-E.
1750 " Different code paths are used for utf-8 and latin1 encodings
1751 set showmatch
1752 for enc in ['latin1', 'utf-8']
1753 enew!
1754 let &encoding = enc
1755 call setline(1, [' {a}', 'xxxxxxxxxx', ' [b]'])
1756 exe "norm! 2gg5r\<C-Y>l5r\<C-E>"
1757 call assert_equal(' {a}x [b]x', getline(2))
1758 endfor
1759 set showmatch&
1760
1761 " r command should fail in operator pending mode
1762 call assert_beeps('normal! cr')
1763
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001764 " clean up
1765 set noautoindent
1766 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02001767endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001768
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01001769" Test for g*, g#
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01001770func Test_normal32_g_cmd1()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001771 new
1772 call append(0, ['abc.x_foo', 'x_foobar.abc'])
1773 1
1774 norm! $g*
1775 call assert_equal('x_foo', @/)
1776 call assert_equal('x_foobar.abc', getline('.'))
1777 norm! $g#
1778 call assert_equal('abc', @/)
1779 call assert_equal('abc.x_foo', getline('.'))
1780
1781 " clean up
1782 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02001783endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001784
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01001785" Test for g`, g;, g,, g&, gv, gk, gj, gJ, g0, g^, g_, gm, g$, gM, g CTRL-G,
1786" gi and gI commands
Bram Moolenaar1671f442020-03-10 07:48:13 +01001787func Test_normal33_g_cmd2()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001788 if !has("jumplist")
1789 return
1790 endif
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001791 call Setup_NewWindow()
1792 " Test for g`
1793 clearjumps
1794 norm! ma10j
1795 let a=execute(':jumps')
1796 " empty jumplist
1797 call assert_equal('>', a[-1:])
1798 norm! g`a
1799 call assert_equal('>', a[-1:])
1800 call assert_equal(1, line('.'))
1801 call assert_equal('1', getline('.'))
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01001802 call cursor(10, 1)
1803 norm! g'a
1804 call assert_equal('>', a[-1:])
1805 call assert_equal(1, line('.'))
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001806
1807 " Test for g; and g,
1808 norm! g;
1809 " there is only one change in the changelist
1810 " currently, when we setup the window
1811 call assert_equal(2, line('.'))
1812 call assert_fails(':norm! g;', 'E662')
1813 call assert_fails(':norm! g,', 'E663')
1814 let &ul=&ul
1815 call append('$', ['a', 'b', 'c', 'd'])
1816 let &ul=&ul
1817 call append('$', ['Z', 'Y', 'X', 'W'])
1818 let a = execute(':changes')
1819 call assert_match('2\s\+0\s\+2', a)
1820 call assert_match('101\s\+0\s\+a', a)
1821 call assert_match('105\s\+0\s\+Z', a)
1822 norm! 3g;
1823 call assert_equal(2, line('.'))
1824 norm! 2g,
1825 call assert_equal(105, line('.'))
1826
1827 " Test for g& - global substitute
1828 %d
1829 call setline(1, range(1,10))
1830 call append('$', ['a', 'b', 'c', 'd'])
1831 $s/\w/&&/g
1832 exe "norm! /[1-8]\<cr>"
1833 norm! g&
1834 call assert_equal(['11', '22', '33', '44', '55', '66', '77', '88', '9', '110', 'a', 'b', 'c', 'dd'], getline(1, '$'))
1835
Bram Moolenaar1671f442020-03-10 07:48:13 +01001836 " Jumping to a fold using gg should open the fold
1837 set foldenable
1838 set foldopen+=jump
1839 5,8fold
1840 call feedkeys('6gg', 'xt')
1841 call assert_equal(1, foldlevel('.'))
1842 call assert_equal(-1, foldclosed('.'))
1843 set foldopen-=jump
1844 set foldenable&
1845
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001846 " Test for gv
1847 %d
1848 call append('$', repeat(['abcdefgh'], 8))
1849 exe "norm! 2gg02l\<c-v>2j2ly"
1850 call assert_equal(['cde', 'cde', 'cde'], getreg(0, 1, 1))
1851 " in visual mode, gv swaps current and last selected region
1852 exe "norm! G0\<c-v>4k4lgvd"
1853 call assert_equal(['', 'abfgh', 'abfgh', 'abfgh', 'abcdefgh', 'abcdefgh', 'abcdefgh', 'abcdefgh', 'abcdefgh'], getline(1,'$'))
1854 exe "norm! G0\<c-v>4k4ly"
1855 exe "norm! gvood"
1856 call assert_equal(['', 'abfgh', 'abfgh', 'abfgh', 'fgh', 'fgh', 'fgh', 'fgh', 'fgh'], getline(1,'$'))
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01001857 " gv cannot be used in operator pending mode
1858 call assert_beeps('normal! cgv')
1859 " gv should beep without a previously selected visual area
1860 new
1861 call assert_beeps('normal! gv')
1862 close
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001863
1864 " Test for gk/gj
1865 %d
1866 15vsp
1867 set wrap listchars= sbr=
1868 let lineA='abcdefghijklmnopqrstuvwxyz'
1869 let lineB='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'
Bram Moolenaar8b530c12019-10-28 02:13:05 +01001870 let lineC='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz01234567890123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001871 $put =lineA
1872 $put =lineB
1873
1874 norm! 3gg0dgk
1875 call assert_equal(['', 'abcdefghijklmno', '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'], getline(1, '$'))
1876 set nu
1877 norm! 3gg0gjdgj
1878 call assert_equal(['', 'abcdefghijklmno', '0123456789AMNOPQRSTUVWXYZ'], getline(1,'$'))
1879
1880 " Test for gJ
1881 norm! 2gggJ
1882 call assert_equal(['', 'abcdefghijklmno0123456789AMNOPQRSTUVWXYZ'], getline(1,'$'))
1883 call assert_equal(16, col('.'))
1884 " shouldn't do anything
1885 norm! 10gJ
1886 call assert_equal(1, col('.'))
1887
1888 " Test for g0 g^ gm g$
1889 exe "norm! 2gg0gji "
1890 call assert_equal(['', 'abcdefghijk lmno0123456789AMNOPQRSTUVWXYZ'], getline(1,'$'))
1891 norm! g0yl
1892 call assert_equal(12, col('.'))
1893 call assert_equal(' ', getreg(0))
1894 norm! g$yl
1895 call assert_equal(22, col('.'))
1896 call assert_equal('3', getreg(0))
1897 norm! gmyl
1898 call assert_equal(17, col('.'))
1899 call assert_equal('n', getreg(0))
1900 norm! g^yl
1901 call assert_equal(15, col('.'))
1902 call assert_equal('l', getreg(0))
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01001903 call assert_beeps('normal 5g$')
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001904
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01001905 " Test for g_
1906 call assert_beeps('normal! 100g_')
1907 call setline(2, [' foo ', ' foobar '])
1908 normal! 2ggg_
1909 call assert_equal(5, col('.'))
1910 normal! 2g_
1911 call assert_equal(8, col('.'))
1912
1913 norm! 2ggdG
Bram Moolenaar8b530c12019-10-28 02:13:05 +01001914 $put =lineC
1915
1916 " Test for gM
1917 norm! gMyl
1918 call assert_equal(73, col('.'))
1919 call assert_equal('0', getreg(0))
1920 " Test for 20gM
1921 norm! 20gMyl
1922 call assert_equal(29, col('.'))
1923 call assert_equal('S', getreg(0))
1924 " Test for 60gM
1925 norm! 60gMyl
1926 call assert_equal(87, col('.'))
1927 call assert_equal('E', getreg(0))
1928
1929 " Test for g Ctrl-G
1930 set ff=unix
1931 let a=execute(":norm! g\<c-g>")
1932 call assert_match('Col 87 of 144; Line 2 of 2; Word 1 of 1; Byte 88 of 146', a)
1933
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001934 " Test for gI
1935 norm! gIfoo
Bram Moolenaar8b530c12019-10-28 02:13:05 +01001936 call assert_equal(['', 'foo0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz01234567890123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'], getline(1,'$'))
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001937
1938 " Test for gi
1939 wincmd c
1940 %d
1941 set tw=0
1942 call setline(1, ['foobar', 'new line'])
1943 norm! A next word
1944 $put ='third line'
1945 norm! gi another word
1946 call assert_equal(['foobar next word another word', 'new line', 'third line'], getline(1,'$'))
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01001947 call setline(1, 'foobar')
1948 normal! Ggifirst line
1949 call assert_equal('foobarfirst line', getline(1))
1950 " Test gi in 'virtualedit' mode with cursor after the end of the line
1951 set virtualedit=all
1952 call setline(1, 'foo')
1953 exe "normal! Abar\<Right>\<Right>\<Right>\<Right>"
1954 call setline(1, 'foo')
1955 normal! Ggifirst line
1956 call assert_equal('foo first line', getline(1))
1957 set virtualedit&
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001958
Bram Moolenaar1671f442020-03-10 07:48:13 +01001959 " Test for aboring a g command using CTRL-\ CTRL-G
1960 exe "normal! g\<C-\>\<C-G>"
1961 call assert_equal('foo first line', getline('.'))
1962
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001963 " clean up
1964 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02001965endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001966
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01001967" Test for g CTRL-G
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01001968func Test_g_ctrl_g()
Bram Moolenaar05295832018-08-24 22:07:58 +02001969 new
1970
1971 let a = execute(":norm! g\<c-g>")
1972 call assert_equal("\n--No lines in buffer--", a)
1973
Bram Moolenaar1671f442020-03-10 07:48:13 +01001974 " Test for CTRL-G (same as :file)
1975 let a = execute(":norm! \<c-g>")
1976 call assert_equal("\n\n\"[No Name]\" --No lines in buffer--", a)
1977
Bram Moolenaar05295832018-08-24 22:07:58 +02001978 call setline(1, ['first line', 'second line'])
1979
1980 " Test g CTRL-g with dos, mac and unix file type.
1981 norm! gojll
1982 set ff=dos
1983 let a = execute(":norm! g\<c-g>")
1984 call assert_equal("\nCol 3 of 11; Line 2 of 2; Word 3 of 4; Byte 15 of 25", a)
1985
1986 set ff=mac
1987 let a = execute(":norm! g\<c-g>")
1988 call assert_equal("\nCol 3 of 11; Line 2 of 2; Word 3 of 4; Byte 14 of 23", a)
1989
1990 set ff=unix
1991 let a = execute(":norm! g\<c-g>")
1992 call assert_equal("\nCol 3 of 11; Line 2 of 2; Word 3 of 4; Byte 14 of 23", a)
1993
1994 " Test g CTRL-g in visual mode (v)
1995 let a = execute(":norm! gojllvlg\<c-g>")
1996 call assert_equal("\nSelected 1 of 2 Lines; 1 of 4 Words; 2 of 23 Bytes", a)
1997
1998 " Test g CTRL-g in visual mode (CTRL-V) with end col > start col
1999 let a = execute(":norm! \<Esc>gojll\<C-V>kllg\<c-g>")
2000 call assert_equal("\nSelected 3 Cols; 2 of 2 Lines; 2 of 4 Words; 6 of 23 Bytes", a)
2001
2002 " Test g_CTRL-g in visual mode (CTRL-V) with end col < start col
2003 let a = execute(":norm! \<Esc>goll\<C-V>jhhg\<c-g>")
2004 call assert_equal("\nSelected 3 Cols; 2 of 2 Lines; 2 of 4 Words; 6 of 23 Bytes", a)
2005
2006 " Test g CTRL-g in visual mode (CTRL-V) with end_vcol being MAXCOL
2007 let a = execute(":norm! \<Esc>gojll\<C-V>k$g\<c-g>")
2008 call assert_equal("\nSelected 2 of 2 Lines; 4 of 4 Words; 17 of 23 Bytes", a)
2009
2010 " There should be one byte less with noeol
2011 set bin noeol
2012 let a = execute(":norm! \<Esc>gog\<c-g>")
2013 call assert_equal("\nCol 1 of 10; Line 1 of 2; Word 1 of 4; Char 1 of 23; Byte 1 of 22", a)
2014 set bin & eol&
2015
Bram Moolenaar30276f22019-01-24 17:59:39 +01002016 call setline(1, ['Français', '日本語'])
Bram Moolenaar05295832018-08-24 22:07:58 +02002017
Bram Moolenaar30276f22019-01-24 17:59:39 +01002018 let a = execute(":norm! \<Esc>gojlg\<c-g>")
2019 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 +02002020
Bram Moolenaar30276f22019-01-24 17:59:39 +01002021 let a = execute(":norm! \<Esc>gojvlg\<c-g>")
2022 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 +02002023
Bram Moolenaar30276f22019-01-24 17:59:39 +01002024 let a = execute(":norm! \<Esc>goll\<c-v>jlg\<c-g>")
2025 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 +02002026
Bram Moolenaar30276f22019-01-24 17:59:39 +01002027 set fenc=utf8 bomb
2028 let a = execute(":norm! \<Esc>gojlg\<c-g>")
2029 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 +02002030
Bram Moolenaar30276f22019-01-24 17:59:39 +01002031 set fenc=utf16 bomb
2032 let a = execute(":norm! g\<c-g>")
2033 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 +02002034
Bram Moolenaar30276f22019-01-24 17:59:39 +01002035 set fenc=utf32 bomb
2036 let a = execute(":norm! g\<c-g>")
2037 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 +02002038
Bram Moolenaar30276f22019-01-24 17:59:39 +01002039 set fenc& bomb&
Bram Moolenaar05295832018-08-24 22:07:58 +02002040
2041 set ff&
2042 bwipe!
2043endfunc
2044
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01002045" Test for g8
Bram Moolenaar1671f442020-03-10 07:48:13 +01002046func Test_normal34_g_cmd3()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002047 new
Bram Moolenaar395b6ba2017-04-07 20:09:51 +02002048 let a=execute(':norm! 1G0g8')
2049 call assert_equal("\nNUL", a)
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002050
Bram Moolenaar395b6ba2017-04-07 20:09:51 +02002051 call setline(1, 'abcdefghijklmnopqrstuvwxyzäüö')
2052 let a=execute(':norm! 1G$g8')
2053 call assert_equal("\nc3 b6 ", a)
2054
2055 call setline(1, "a\u0302")
2056 let a=execute(':norm! 1G0g8')
2057 call assert_equal("\n61 + cc 82 ", a)
2058
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002059 " clean up
2060 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002061endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002062
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01002063" Test 8g8 which finds invalid utf8 at or after the cursor.
Bram Moolenaar395b6ba2017-04-07 20:09:51 +02002064func Test_normal_8g8()
Bram Moolenaar395b6ba2017-04-07 20:09:51 +02002065 new
2066
Bram Moolenaar395b6ba2017-04-07 20:09:51 +02002067 " With invalid byte.
2068 call setline(1, "___\xff___")
2069 norm! 1G08g8g
2070 call assert_equal([0, 1, 4, 0, 1], getcurpos())
2071
2072 " With invalid byte before the cursor.
2073 call setline(1, "___\xff___")
2074 norm! 1G$h8g8g
2075 call assert_equal([0, 1, 6, 0, 9], getcurpos())
2076
2077 " With truncated sequence.
2078 call setline(1, "___\xE2\x82___")
2079 norm! 1G08g8g
2080 call assert_equal([0, 1, 4, 0, 1], getcurpos())
2081
2082 " With overlong sequence.
2083 call setline(1, "___\xF0\x82\x82\xAC___")
2084 norm! 1G08g8g
2085 call assert_equal([0, 1, 4, 0, 1], getcurpos())
2086
2087 " With valid utf8.
2088 call setline(1, "café")
2089 norm! 1G08g8
2090 call assert_equal([0, 1, 1, 0, 1], getcurpos())
2091
2092 bw!
2093endfunc
2094
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01002095" Test for g<
Bram Moolenaar1671f442020-03-10 07:48:13 +01002096func Test_normal35_g_cmd4()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002097 " Cannot capture its output,
2098 " probably a bug, therefore, test disabled:
Bram Moolenaar31845092016-09-05 22:58:31 +02002099 throw "Skipped: output of g< can't be tested currently"
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002100 echo "a\nb\nc\nd"
2101 let b=execute(':norm! g<')
2102 call assert_true(!empty(b), 'failed `execute(g<)`')
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002103endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002104
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01002105" Test for gp gP go
Bram Moolenaar1671f442020-03-10 07:48:13 +01002106func Test_normal36_g_cmd5()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002107 new
2108 call append(0, 'abcdefghijklmnopqrstuvwxyz')
Bram Moolenaar0913a102016-09-03 19:11:59 +02002109 set ff=unix
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002110 " Test for gp gP
2111 call append(1, range(1,10))
2112 1
2113 norm! 1yy
2114 3
2115 norm! gp
2116 call assert_equal([0, 5, 1, 0, 1], getcurpos())
2117 $
2118 norm! gP
2119 call assert_equal([0, 14, 1, 0, 1], getcurpos())
2120
2121 " Test for go
2122 norm! 26go
2123 call assert_equal([0, 1, 26, 0, 26], getcurpos())
2124 norm! 27go
2125 call assert_equal([0, 1, 26, 0, 26], getcurpos())
2126 norm! 28go
2127 call assert_equal([0, 2, 1, 0, 1], getcurpos())
2128 set ff=dos
2129 norm! 29go
2130 call assert_equal([0, 2, 1, 0, 1], getcurpos())
2131 set ff=unix
2132 norm! gg0
2133 norm! 101go
2134 call assert_equal([0, 13, 26, 0, 26], getcurpos())
2135 norm! 103go
2136 call assert_equal([0, 14, 1, 0, 1], getcurpos())
2137 " count > buffer content
2138 norm! 120go
2139 call assert_equal([0, 14, 1, 0, 2147483647], getcurpos())
2140 " clean up
2141 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002142endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002143
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01002144" Test for gt and gT
Bram Moolenaar1671f442020-03-10 07:48:13 +01002145func Test_normal37_g_cmd6()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002146 tabnew 1.txt
2147 tabnew 2.txt
2148 tabnew 3.txt
2149 norm! 1gt
2150 call assert_equal(1, tabpagenr())
2151 norm! 3gt
2152 call assert_equal(3, tabpagenr())
2153 norm! 1gT
2154 " count gT goes not to the absolute tabpagenumber
2155 " but, but goes to the count previous tabpagenumber
2156 call assert_equal(2, tabpagenr())
2157 " wrap around
2158 norm! 3gT
2159 call assert_equal(3, tabpagenr())
2160 " gt does not wrap around
2161 norm! 5gt
2162 call assert_equal(3, tabpagenr())
2163
2164 for i in range(3)
2165 tabclose
2166 endfor
2167 " clean up
Bram Moolenaarbc2b71d2020-02-17 21:33:30 +01002168 call assert_fails(':tabclose', 'E784:')
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002169endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002170
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01002171" Test for <Home> and <C-Home> key
Bram Moolenaar1671f442020-03-10 07:48:13 +01002172func Test_normal38_nvhome()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002173 new
2174 call setline(1, range(10))
2175 $
2176 setl et sw=2
2177 norm! V10>$
2178 " count is ignored
2179 exe "norm! 10\<home>"
2180 call assert_equal(1, col('.'))
2181 exe "norm! \<home>"
2182 call assert_equal([0, 10, 1, 0, 1], getcurpos())
2183 exe "norm! 5\<c-home>"
2184 call assert_equal([0, 5, 1, 0, 1], getcurpos())
2185 exe "norm! \<c-home>"
2186 call assert_equal([0, 1, 1, 0, 1], getcurpos())
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01002187 exe "norm! G\<c-kHome>"
2188 call assert_equal([0, 1, 1, 0, 1], getcurpos())
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002189
2190 " clean up
2191 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002192endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002193
Bram Moolenaar1671f442020-03-10 07:48:13 +01002194" Test for <End> and <C-End> keys
2195func Test_normal_nvend()
2196 new
2197 call setline(1, map(range(1, 10), '"line" .. v:val'))
2198 exe "normal! \<End>"
2199 call assert_equal(5, col('.'))
2200 exe "normal! 4\<End>"
2201 call assert_equal([4, 5], [line('.'), col('.')])
2202 exe "normal! \<C-End>"
2203 call assert_equal([10, 6], [line('.'), col('.')])
2204 close!
2205endfunc
2206
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01002207" Test for cw cW ce
Bram Moolenaar1671f442020-03-10 07:48:13 +01002208func Test_normal39_cw()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002209 " Test for cw and cW on whitespace
2210 " and cpo+=w setting
2211 new
2212 set tw=0
2213 call append(0, 'here are some words')
2214 norm! 1gg0elcwZZZ
2215 call assert_equal('hereZZZare some words', getline('.'))
2216 norm! 1gg0elcWYYY
2217 call assert_equal('hereZZZareYYYsome words', getline('.'))
2218 set cpo+=w
2219 call setline(1, 'here are some words')
2220 norm! 1gg0elcwZZZ
2221 call assert_equal('hereZZZ are some words', getline('.'))
2222 norm! 1gg2elcWYYY
2223 call assert_equal('hereZZZ areYYY some words', getline('.'))
2224 set cpo-=w
2225 norm! 2gg0cwfoo
2226 call assert_equal('foo', getline('.'))
2227
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01002228 call setline(1, 'one; two')
2229 call cursor(1, 1)
2230 call feedkeys('cwvim', 'xt')
2231 call assert_equal('vim; two', getline(1))
2232 call feedkeys('0cWone', 'xt')
2233 call assert_equal('one two', getline(1))
2234 "When cursor is at the end of a word 'ce' will change until the end of the
2235 "next word, but 'cw' will change only one character
2236 call setline(1, 'one two')
2237 call feedkeys('0ecwce', 'xt')
2238 call assert_equal('once two', getline(1))
2239 call setline(1, 'one two')
2240 call feedkeys('0ecely', 'xt')
2241 call assert_equal('only', getline(1))
2242
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002243 " clean up
2244 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002245endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002246
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01002247" Test for CTRL-\ commands
Bram Moolenaar1671f442020-03-10 07:48:13 +01002248func Test_normal40_ctrl_bsl()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002249 new
2250 call append(0, 'here are some words')
2251 exe "norm! 1gg0a\<C-\>\<C-N>"
2252 call assert_equal('n', mode())
2253 call assert_equal(1, col('.'))
2254 call assert_equal('', visualmode())
2255 exe "norm! 1gg0viw\<C-\>\<C-N>"
2256 call assert_equal('n', mode())
2257 call assert_equal(4, col('.'))
2258 exe "norm! 1gg0a\<C-\>\<C-G>"
2259 call assert_equal('n', mode())
2260 call assert_equal(1, col('.'))
2261 "imap <buffer> , <c-\><c-n>
2262 set im
2263 exe ":norm! \<c-\>\<c-n>dw"
2264 set noim
2265 call assert_equal('are some words', getline(1))
2266 call assert_false(&insertmode)
Bram Moolenaar1671f442020-03-10 07:48:13 +01002267 call assert_beeps("normal! \<C-\>\<C-A>", 'xt')
2268
2269 " Using CTRL-\ CTRL-N in cmd window should close the window
2270 call feedkeys("q:\<C-\>\<C-N>", 'xt')
2271 call assert_equal('', getcmdwintype())
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002272
2273 " clean up
2274 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002275endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002276
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01002277" Test for <c-r>=, <c-r><c-r>= and <c-r><c-o>= in insert mode
Bram Moolenaar1671f442020-03-10 07:48:13 +01002278func Test_normal41_insert_reg()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002279 new
2280 set sts=2 sw=2 ts=8 tw=0
2281 call append(0, ["aaa\tbbb\tccc", '', '', ''])
2282 let a=getline(1)
2283 norm! 2gg0
2284 exe "norm! a\<c-r>=a\<cr>"
2285 norm! 3gg0
2286 exe "norm! a\<c-r>\<c-r>=a\<cr>"
2287 norm! 4gg0
2288 exe "norm! a\<c-r>\<c-o>=a\<cr>"
2289 call assert_equal(['aaa bbb ccc', 'aaa bbb ccc', 'aaa bbb ccc', 'aaa bbb ccc', ''], getline(1, '$'))
2290
2291 " clean up
2292 set sts=0 sw=8 ts=8
Bram Moolenaar31845092016-09-05 22:58:31 +02002293 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002294endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002295
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01002296" Test for Ctrl-D and Ctrl-U
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01002297func Test_normal42_halfpage()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002298 call Setup_NewWindow()
2299 call assert_equal(5, &scroll)
2300 exe "norm! \<c-d>"
2301 call assert_equal('6', getline('.'))
2302 exe "norm! 2\<c-d>"
2303 call assert_equal('8', getline('.'))
2304 call assert_equal(2, &scroll)
2305 set scroll=5
2306 exe "norm! \<c-u>"
2307 call assert_equal('3', getline('.'))
2308 1
2309 set scrolloff=5
2310 exe "norm! \<c-d>"
2311 call assert_equal('10', getline('.'))
2312 exe "norm! \<c-u>"
2313 call assert_equal('5', getline('.'))
2314 1
2315 set scrolloff=99
2316 exe "norm! \<c-d>"
2317 call assert_equal('10', getline('.'))
2318 set scrolloff=0
2319 100
2320 exe "norm! $\<c-u>"
2321 call assert_equal('95', getline('.'))
2322 call assert_equal([0, 95, 1, 0, 1], getcurpos())
2323 100
2324 set nostartofline
2325 exe "norm! $\<c-u>"
2326 call assert_equal('95', getline('.'))
2327 call assert_equal([0, 95, 2, 0, 2147483647], getcurpos())
2328 " cleanup
2329 set startofline
2330 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002331endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002332
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01002333" Tests for text object aw
Bram Moolenaar1671f442020-03-10 07:48:13 +01002334func Test_normal43_textobject1()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002335 new
2336 call append(0, ['foobar,eins,foobar', 'foo,zwei,foo '])
2337 " diw
2338 norm! 1gg0diw
2339 call assert_equal([',eins,foobar', 'foo,zwei,foo ', ''], getline(1,'$'))
2340 " daw
2341 norm! 2ggEdaw
2342 call assert_equal([',eins,foobar', 'foo,zwei,', ''], getline(1, '$'))
2343 %d
2344 call append(0, ["foo\teins\tfoobar", "foo\tzwei\tfoo "])
2345 " diW
2346 norm! 2ggwd2iW
2347 call assert_equal(['foo eins foobar', 'foo foo ', ''], getline(1,'$'))
2348 " daW
2349 norm! 1ggd2aW
2350 call assert_equal(['foobar', 'foo foo ', ''], getline(1,'$'))
2351
2352 %d
2353 call append(0, ["foo\teins\tfoobar", "foo\tzwei\tfoo "])
2354 " aw in visual line mode switches to characterwise mode
2355 norm! 2gg$Vawd
2356 call assert_equal(['foo eins foobar', 'foo zwei foo'], getline(1,'$'))
2357 norm! 1gg$Viwd
2358 call assert_equal(['foo eins ', 'foo zwei foo'], getline(1,'$'))
2359
2360 " clean up
2361 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002362endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002363
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01002364" Test for is and as text objects
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01002365func Test_normal44_textobjects2()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002366 new
2367 call append(0, ['This is a test. With some sentences!', '', 'Even with a question? And one more. And no sentence here'])
2368 " Test for dis - does not remove trailing whitespace
2369 norm! 1gg0dis
2370 call assert_equal([' With some sentences!', '', 'Even with a question? And one more. And no sentence here', ''], getline(1,'$'))
2371 " Test for das - removes leading whitespace
2372 norm! 3ggf?ldas
2373 call assert_equal([' With some sentences!', '', 'Even with a question? And no sentence here', ''], getline(1,'$'))
2374 " when used in visual mode, is made characterwise
2375 norm! 3gg$Visy
2376 call assert_equal('v', visualmode())
2377 " reset visualmode()
2378 norm! 3ggVy
2379 norm! 3gg$Vasy
2380 call assert_equal('v', visualmode())
2381 " basic testing for textobjects a< and at
2382 %d
2383 call setline(1, ['<div> ','<a href="foobar" class="foo">xyz</a>',' </div>', ' '])
2384 " a<
2385 norm! 1gg0da<
2386 call assert_equal([' ', '<a href="foobar" class="foo">xyz</a>', ' </div>', ' '], getline(1,'$'))
2387 norm! 1pj
2388 call assert_equal([' <div>', '<a href="foobar" class="foo">xyz</a>', ' </div>', ' '], getline(1,'$'))
2389 " at
2390 norm! d2at
2391 call assert_equal([' '], getline(1,'$'))
2392 %d
2393 call setline(1, ['<div> ','<a href="foobar" class="foo">xyz</a>',' </div>', ' '])
2394 " i<
2395 norm! 1gg0di<
2396 call assert_equal(['<> ', '<a href="foobar" class="foo">xyz</a>', ' </div>', ' '], getline(1,'$'))
2397 norm! 1Pj
2398 call assert_equal(['<div> ', '<a href="foobar" class="foo">xyz</a>', ' </div>', ' '], getline(1,'$'))
2399 norm! d2it
2400 call assert_equal(['<div></div>',' '], getline(1,'$'))
2401 " basic testing for a[ and i[ text object
2402 %d
2403 call setline(1, [' ', '[', 'one [two]', 'thre', ']'])
2404 norm! 3gg0di[
2405 call assert_equal([' ', '[', ']'], getline(1,'$'))
2406 call setline(1, [' ', '[', 'one [two]', 'thre', ']'])
2407 norm! 3gg0ftd2a[
2408 call assert_equal([' '], getline(1,'$'))
2409 %d
2410 " Test for i" when cursor is in front of a quoted object
2411 call append(0, 'foo "bar"')
2412 norm! 1gg0di"
2413 call assert_equal(['foo ""', ''], getline(1,'$'))
2414
2415 " clean up
2416 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002417endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002418
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01002419func Test_normal45_drop()
Bram Moolenaar29495952018-02-12 22:49:00 +01002420 if !has('dnd')
Bram Moolenaarb48e96f2018-02-13 12:26:14 +01002421 " The ~ register does not exist
2422 call assert_beeps('norm! "~')
Bram Moolenaar29495952018-02-12 22:49:00 +01002423 return
2424 endif
2425
2426 " basic test for drag-n-drop
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002427 " unfortunately, without a gui, we can't really test much here,
2428 " so simply test that ~p fails (which uses the drop register)
2429 new
2430 call assert_fails(':norm! "~p', 'E353')
2431 call assert_equal([], getreg('~', 1, 1))
2432 " the ~ register is read only
2433 call assert_fails(':let @~="1"', 'E354')
2434 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002435endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002436
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01002437func Test_normal46_ignore()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002438 new
2439 " How to test this?
2440 " let's just for now test, that the buffer
2441 " does not change
2442 call feedkeys("\<c-s>", 't')
2443 call assert_equal([''], getline(1,'$'))
2444
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002445 " no valid commands
2446 exe "norm! \<char-0x100>"
2447 call assert_equal([''], getline(1,'$'))
2448
2449 exe "norm! ä"
2450 call assert_equal([''], getline(1,'$'))
2451
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002452 " clean up
2453 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002454endfunc
Bram Moolenaarc4a908e2016-09-08 23:35:30 +02002455
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01002456func Test_normal47_visual_buf_wipe()
Bram Moolenaarc4a908e2016-09-08 23:35:30 +02002457 " This was causing a crash or ml_get error.
2458 enew!
2459 call setline(1,'xxx')
2460 normal $
2461 new
2462 call setline(1, range(1,2))
2463 2
2464 exe "norm \<C-V>$"
2465 bw!
2466 norm yp
2467 set nomodified
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002468endfunc
2469
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01002470func Test_normal47_autocmd()
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002471 " disabled, does not seem to be possible currently
2472 throw "Skipped: not possible to test cursorhold autocmd while waiting for input in normal_cmd"
2473 new
2474 call append(0, repeat('-',20))
2475 au CursorHold * call feedkeys('2l', '')
2476 1
2477 set updatetime=20
2478 " should delete 12 chars (d12l)
2479 call feedkeys('d1', '!')
2480 call assert_equal('--------', getline(1))
2481
2482 " clean up
2483 au! CursorHold
2484 set updatetime=4000
2485 bw!
2486endfunc
2487
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01002488func Test_normal48_wincmd()
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002489 new
2490 exe "norm! \<c-w>c"
2491 call assert_equal(1, winnr('$'))
2492 call assert_fails(":norm! \<c-w>c", "E444")
2493endfunc
2494
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01002495func Test_normal49_counts()
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002496 new
2497 call setline(1, 'one two three four five six seven eight nine ten')
2498 1
2499 norm! 3d2w
2500 call assert_equal('seven eight nine ten', getline(1))
2501 bw!
2502endfunc
2503
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01002504func Test_normal50_commandline()
Bram Moolenaar4033c552017-09-16 20:54:51 +02002505 if !has("timers") || !has("cmdline_hist")
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002506 return
2507 endif
2508 func! DoTimerWork(id)
2509 call assert_equal('[Command Line]', bufname(''))
2510 " should fail, with E11, but does fail with E23?
2511 "call feedkeys("\<c-^>", 'tm')
2512
2513 " should also fail with E11
2514 call assert_fails(":wincmd p", 'E11')
2515 " return from commandline window
2516 call feedkeys("\<cr>")
2517 endfunc
2518
2519 let oldlang=v:lang
2520 lang C
2521 set updatetime=20
2522 call timer_start(100, 'DoTimerWork')
2523 try
2524 " throws E23, for whatever reason...
2525 call feedkeys('q:', 'x!')
2526 catch /E23/
2527 " no-op
2528 endtry
2529 " clean up
2530 set updatetime=4000
2531 exe "lang" oldlang
2532 bw!
2533endfunc
2534
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01002535func Test_normal51_FileChangedRO()
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002536 if !has("autocmd")
2537 return
2538 endif
Bram Moolenaare5f2a072017-02-01 22:31:49 +01002539 " Don't sleep after the warning message.
2540 call test_settime(1)
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002541 call writefile(['foo'], 'Xreadonly.log')
2542 new Xreadonly.log
2543 setl ro
2544 au FileChangedRO <buffer> :call feedkeys("\<c-^>", 'tix')
2545 call assert_fails(":norm! Af", 'E788')
2546 call assert_equal(['foo'], getline(1,'$'))
2547 call assert_equal('Xreadonly.log', bufname(''))
2548
2549 " cleanup
Bram Moolenaare5f2a072017-02-01 22:31:49 +01002550 call test_settime(0)
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002551 bw!
2552 call delete("Xreadonly.log")
2553endfunc
2554
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01002555func Test_normal52_rl()
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002556 if !has("rightleft")
2557 return
2558 endif
2559 new
2560 call setline(1, 'abcde fghij klmnopq')
2561 norm! 1gg$
2562 set rl
2563 call assert_equal(19, col('.'))
2564 call feedkeys('l', 'tx')
2565 call assert_equal(18, col('.'))
2566 call feedkeys('h', 'tx')
2567 call assert_equal(19, col('.'))
2568 call feedkeys("\<right>", 'tx')
2569 call assert_equal(18, col('.'))
Bram Moolenaar1671f442020-03-10 07:48:13 +01002570 call feedkeys("\<left>", 'tx')
2571 call assert_equal(19, col('.'))
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002572 call feedkeys("\<s-right>", 'tx')
2573 call assert_equal(13, col('.'))
2574 call feedkeys("\<c-right>", 'tx')
2575 call assert_equal(7, col('.'))
2576 call feedkeys("\<c-left>", 'tx')
2577 call assert_equal(13, col('.'))
2578 call feedkeys("\<s-left>", 'tx')
2579 call assert_equal(19, col('.'))
2580 call feedkeys("<<", 'tx')
2581 call assert_equal(' abcde fghij klmnopq',getline(1))
2582 call feedkeys(">>", 'tx')
2583 call assert_equal('abcde fghij klmnopq',getline(1))
2584
2585 " cleanup
2586 set norl
2587 bw!
2588endfunc
2589
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01002590func Test_normal53_digraph()
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002591 if !has('digraphs')
2592 return
2593 endif
2594 new
2595 call setline(1, 'abcdefgh|')
2596 exe "norm! 1gg0f\<c-k>!!"
2597 call assert_equal(9, col('.'))
2598 set cpo+=D
2599 exe "norm! 1gg0f\<c-k>!!"
2600 call assert_equal(1, col('.'))
2601
2602 set cpo-=D
2603 bw!
2604endfunc
2605
Bram Moolenaarb1e04fc2017-03-29 13:08:35 +02002606func Test_normal54_Ctrl_bsl()
2607 new
2608 call setline(1, 'abcdefghijklmn')
2609 exe "norm! df\<c-\>\<c-n>"
2610 call assert_equal(['abcdefghijklmn'], getline(1,'$'))
2611 exe "norm! df\<c-\>\<c-g>"
2612 call assert_equal(['abcdefghijklmn'], getline(1,'$'))
2613 exe "norm! df\<c-\>m"
2614 call assert_equal(['abcdefghijklmn'], getline(1,'$'))
Bram Moolenaar30276f22019-01-24 17:59:39 +01002615
Bram Moolenaarb1e04fc2017-03-29 13:08:35 +02002616 call setline(2, 'abcdefghijklmnāf')
2617 norm! 2gg0
2618 exe "norm! df\<Char-0x101>"
2619 call assert_equal(['abcdefghijklmn', 'f'], getline(1,'$'))
2620 norm! 1gg0
2621 exe "norm! df\<esc>"
2622 call assert_equal(['abcdefghijklmn', 'f'], getline(1,'$'))
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002623
Bram Moolenaarb1e04fc2017-03-29 13:08:35 +02002624 " clean up
2625 bw!
2626endfunc
2627
2628func Test_normal_large_count()
2629 " This may fail with 32bit long, how do we detect that?
2630 new
2631 normal o
2632 normal 6666666666dL
2633 bwipe!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002634endfunc
Bram Moolenaarbf3d5802017-03-29 19:48:11 +02002635
2636func Test_delete_until_paragraph()
Bram Moolenaarbf3d5802017-03-29 19:48:11 +02002637 new
2638 normal grádv}
2639 call assert_equal('á', getline(1))
2640 normal grád}
2641 call assert_equal('', getline(1))
2642 bwipe!
2643endfunc
Bram Moolenaarfb094e12017-11-05 20:59:28 +01002644
2645" Test for the gr (virtual replace) command
2646" Test for the bug fixed by 7.4.387
2647func Test_gr_command()
2648 enew!
2649 let save_cpo = &cpo
2650 call append(0, ['First line', 'Second line', 'Third line'])
2651 exe "normal i\<C-G>u"
2652 call cursor(2, 1)
2653 set cpo-=X
2654 normal 4gro
2655 call assert_equal('oooond line', getline(2))
2656 undo
2657 set cpo+=X
2658 normal 4gro
2659 call assert_equal('ooooecond line', getline(2))
2660 let &cpo = save_cpo
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01002661 normal! ggvegrx
2662 call assert_equal('xxxxx line', getline(1))
2663 exe "normal! gggr\<C-V>122"
2664 call assert_equal('zxxxx line', getline(1))
2665 set virtualedit=all
2666 normal! 15|grl
2667 call assert_equal('zxxxx line l', getline(1))
2668 set virtualedit&
2669 set nomodifiable
2670 call assert_fails('normal! grx', 'E21:')
2671 call assert_fails('normal! gRx', 'E21:')
2672 set modifiable&
Bram Moolenaarfb094e12017-11-05 20:59:28 +01002673 enew!
2674endfunc
2675
2676" When splitting a window the changelist position is wrong.
2677" Test the changelist position after splitting a window.
2678" Test for the bug fixed by 7.4.386
2679func Test_changelist()
2680 let save_ul = &ul
2681 enew!
2682 call append('$', ['1', '2'])
2683 exe "normal i\<C-G>u"
2684 exe "normal Gkylpa\<C-G>u"
2685 set ul=100
2686 exe "normal Gylpa\<C-G>u"
2687 set ul=100
2688 normal gg
2689 vsplit
2690 normal g;
2691 call assert_equal([3, 2], [line('.'), col('.')])
2692 normal g;
2693 call assert_equal([2, 2], [line('.'), col('.')])
2694 call assert_fails('normal g;', 'E662:')
Bram Moolenaar1671f442020-03-10 07:48:13 +01002695 new
2696 call assert_fails('normal g;', 'E664:')
Bram Moolenaarfb094e12017-11-05 20:59:28 +01002697 %bwipe!
2698 let &ul = save_ul
2699endfunc
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01002700
2701func Test_nv_hat_count()
2702 %bwipeout!
2703 let l:nr = bufnr('%') + 1
2704 call assert_fails(':execute "normal! ' . l:nr . '\<C-^>"', 'E92')
2705
2706 edit Xfoo
2707 let l:foo_nr = bufnr('Xfoo')
2708
2709 edit Xbar
2710 let l:bar_nr = bufnr('Xbar')
2711
2712 " Make sure we are not just using the alternate file.
2713 edit Xbaz
2714
2715 call feedkeys(l:foo_nr . "\<C-^>", 'tx')
2716 call assert_equal('Xfoo', fnamemodify(bufname('%'), ':t'))
2717
2718 call feedkeys(l:bar_nr . "\<C-^>", 'tx')
2719 call assert_equal('Xbar', fnamemodify(bufname('%'), ':t'))
2720
2721 %bwipeout!
2722endfunc
Bram Moolenaara84a3dd2019-03-25 22:21:24 +01002723
2724func Test_message_when_using_ctrl_c()
Bram Moolenaar553e5a52019-03-25 23:16:34 +01002725 " Make sure no buffers are changed.
2726 %bwipe!
2727
Bram Moolenaara84a3dd2019-03-25 22:21:24 +01002728 exe "normal \<C-C>"
2729 call assert_match("Type :qa and press <Enter> to exit Vim", Screenline(&lines))
Bram Moolenaar553e5a52019-03-25 23:16:34 +01002730
Bram Moolenaara84a3dd2019-03-25 22:21:24 +01002731 new
2732 cal setline(1, 'hi!')
2733 exe "normal \<C-C>"
2734 call assert_match("Type :qa! and press <Enter> to abandon all changes and exit Vim", Screenline(&lines))
Bram Moolenaar553e5a52019-03-25 23:16:34 +01002735
Bram Moolenaara84a3dd2019-03-25 22:21:24 +01002736 bwipe!
2737endfunc
Bram Moolenaarc6b37db2019-04-27 18:00:34 +02002738
2739" Test for '[m', ']m', '[M' and ']M'
2740" Jumping to beginning and end of methods in Java-like languages
2741func Test_java_motion()
2742 new
Bram Moolenaar1671f442020-03-10 07:48:13 +01002743 call assert_beeps('normal! [m')
2744 call assert_beeps('normal! ]m')
2745 call assert_beeps('normal! [M')
2746 call assert_beeps('normal! ]M')
Bram Moolenaarc6b37db2019-04-27 18:00:34 +02002747 a
2748Piece of Java
2749{
2750 tt m1 {
2751 t1;
2752 } e1
2753
2754 tt m2 {
2755 t2;
2756 } e2
2757
2758 tt m3 {
2759 if (x)
2760 {
2761 t3;
2762 }
2763 } e3
2764}
2765.
2766
2767 normal gg
2768
2769 normal 2]maA
2770 call assert_equal("\ttt m1 {A", getline('.'))
2771 call assert_equal([3, 9, 16], [line('.'), col('.'), virtcol('.')])
2772
2773 normal j]maB
2774 call assert_equal("\ttt m2 {B", getline('.'))
2775 call assert_equal([7, 9, 16], [line('.'), col('.'), virtcol('.')])
2776
2777 normal ]maC
2778 call assert_equal("\ttt m3 {C", getline('.'))
2779 call assert_equal([11, 9, 16], [line('.'), col('.'), virtcol('.')])
2780
2781 normal [maD
2782 call assert_equal("\ttt m3 {DC", getline('.'))
2783 call assert_equal([11, 9, 16], [line('.'), col('.'), virtcol('.')])
2784
2785 normal k2[maE
2786 call assert_equal("\ttt m1 {EA", getline('.'))
2787 call assert_equal([3, 9, 16], [line('.'), col('.'), virtcol('.')])
2788
2789 normal 3[maF
2790 call assert_equal("{F", getline('.'))
2791 call assert_equal([2, 2, 2], [line('.'), col('.'), virtcol('.')])
2792
2793 normal ]MaG
2794 call assert_equal("\t}G e1", getline('.'))
2795 call assert_equal([5, 3, 10], [line('.'), col('.'), virtcol('.')])
2796
2797 normal j2]MaH
2798 call assert_equal("\t}H e3", getline('.'))
2799 call assert_equal([16, 3, 10], [line('.'), col('.'), virtcol('.')])
2800
2801 normal ]M]M
2802 normal aI
2803 call assert_equal("}I", getline('.'))
2804 call assert_equal([17, 2, 2], [line('.'), col('.'), virtcol('.')])
2805
2806 normal 2[MaJ
2807 call assert_equal("\t}JH e3", getline('.'))
2808 call assert_equal([16, 3, 10], [line('.'), col('.'), virtcol('.')])
2809
2810 normal k[MaK
2811 call assert_equal("\t}K e2", getline('.'))
2812 call assert_equal([9, 3, 10], [line('.'), col('.'), virtcol('.')])
2813
2814 normal 3[MaL
2815 call assert_equal("{LF", getline('.'))
2816 call assert_equal([2, 2, 2], [line('.'), col('.'), virtcol('.')])
2817
2818 close!
2819endfunc
Bram Moolenaard5c82342019-07-27 18:44:57 +02002820
Bram Moolenaar1671f442020-03-10 07:48:13 +01002821func Test_normal_gdollar_cmd()
Bram Moolenaard5c82342019-07-27 18:44:57 +02002822 if !has("jumplist")
2823 return
2824 endif
2825 " Tests for g cmds
2826 call Setup_NewWindow()
2827 " Make long lines that will wrap
2828 %s/$/\=repeat(' foobar', 10)/
2829 20vsp
2830 set wrap
2831 " Test for g$ with count
2832 norm! gg
2833 norm! 0vg$y
2834 call assert_equal(20, col("'>"))
2835 call assert_equal('1 foobar foobar foob', getreg(0))
2836 norm! gg
2837 norm! 0v4g$y
2838 call assert_equal(72, col("'>"))
2839 call assert_equal('1 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar'.."\n", getreg(0))
2840 norm! gg
2841 norm! 0v6g$y
2842 call assert_equal(40, col("'>"))
2843 call assert_equal('1 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar'.. "\n"..
2844 \ '2 foobar foobar foobar foobar foobar foo', getreg(0))
2845 set nowrap
2846 " clean up
2847 norm! gg
2848 norm! 0vg$y
2849 call assert_equal(20, col("'>"))
2850 call assert_equal('1 foobar foobar foob', getreg(0))
2851 norm! gg
2852 norm! 0v4g$y
2853 call assert_equal(20, col("'>"))
2854 call assert_equal('1 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar'.. "\n"..
2855 \ '2 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar'.. "\n"..
2856 \ '3 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar'.. "\n"..
2857 \ '4 foobar foobar foob', getreg(0))
2858 norm! gg
2859 norm! 0v6g$y
2860 call assert_equal(20, col("'>"))
2861 call assert_equal('1 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar'.. "\n"..
2862 \ '2 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar'.. "\n"..
2863 \ '3 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar'.. "\n"..
2864 \ '4 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar'.. "\n"..
2865 \ '5 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar'.. "\n"..
2866 \ '6 foobar foobar foob', getreg(0))
2867 " Move to last line, also down movement is not possible, should still move
2868 " the cursor to the last visible char
2869 norm! G
2870 norm! 0v6g$y
2871 call assert_equal(20, col("'>"))
2872 call assert_equal('100 foobar foobar fo', getreg(0))
2873 bw!
2874endfunc
Bram Moolenaar03ac52f2019-09-24 22:47:46 +02002875
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01002876func Test_normal_gk_gj()
Bram Moolenaar03ac52f2019-09-24 22:47:46 +02002877 " needs 80 column new window
2878 new
2879 vert 80new
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01002880 call assert_beeps('normal gk')
Bram Moolenaar03ac52f2019-09-24 22:47:46 +02002881 put =[repeat('x',90)..' {{{1', 'x {{{1']
2882 norm! gk
2883 " In a 80 column wide terminal the window will be only 78 char
2884 " (because Vim will leave space for the other window),
2885 " but if the terminal is larger, it will be 80 chars, so verify the
2886 " cursor column correctly.
2887 call assert_equal(winwidth(0)+1, col('.'))
2888 call assert_equal(winwidth(0)+1, virtcol('.'))
2889 norm! j
2890 call assert_equal(6, col('.'))
2891 call assert_equal(6, virtcol('.'))
2892 norm! gk
2893 call assert_equal(95, col('.'))
2894 call assert_equal(95, virtcol('.'))
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01002895 %bw!
Bram Moolenaarceba3dd2019-10-12 16:12:54 +02002896
2897 " needs 80 column new window
2898 new
2899 vert 80new
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01002900 call assert_beeps('normal gj')
Bram Moolenaarceba3dd2019-10-12 16:12:54 +02002901 set number
2902 set numberwidth=10
2903 set cpoptions+=n
2904 put =[repeat('0',90), repeat('1',90)]
2905 norm! 075l
2906 call assert_equal(76, col('.'))
2907 norm! gk
2908 call assert_equal(1, col('.'))
2909 norm! gk
2910 call assert_equal(76, col('.'))
2911 norm! gk
2912 call assert_equal(1, col('.'))
2913 norm! gj
2914 call assert_equal(76, col('.'))
2915 norm! gj
2916 call assert_equal(1, col('.'))
2917 norm! gj
2918 call assert_equal(76, col('.'))
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01002919 " When 'nowrap' is set, gk and gj behave like k and j
2920 set nowrap
2921 normal! gk
2922 call assert_equal([2, 76], [line('.'), col('.')])
2923 normal! gj
2924 call assert_equal([3, 76], [line('.'), col('.')])
2925 %bw!
2926 set cpoptions& number& numberwidth& wrap&
Bram Moolenaar03ac52f2019-09-24 22:47:46 +02002927endfunc
Bram Moolenaarf0cee192020-02-16 13:33:56 +01002928
2929" Test for cursor movement with '-' in 'cpoptions'
2930func Test_normal_cpo_minus()
2931 new
2932 call setline(1, ['foo', 'bar', 'baz'])
2933 let save_cpo = &cpo
2934 set cpo+=-
2935 call assert_beeps('normal 10j')
2936 call assert_equal(1, line('.'))
2937 normal G
2938 call assert_beeps('normal 10k')
2939 call assert_equal(3, line('.'))
2940 call assert_fails(10, 'E16:')
2941 let &cpo = save_cpo
2942 close!
2943endfunc
Bram Moolenaar818fc9a2020-02-21 17:54:45 +01002944
Bram Moolenaarca68ae12020-03-30 19:32:53 +02002945" Test for displaying dollar when changing text ('$' flag in 'cpoptions')
2946func Test_normal_cpo_dollar()
2947 new
2948 let g:Line = ''
2949 func SaveFirstLine()
2950 let g:Line = Screenline(1)
2951 return ''
2952 endfunc
2953 inoremap <expr> <buffer> <F2> SaveFirstLine()
2954 call test_override('redraw_flag', 1)
2955 set cpo+=$
2956 call setline(1, 'one two three')
2957 redraw!
2958 exe "normal c2w\<F2>vim"
2959 call assert_equal('one tw$ three', g:Line)
2960 call assert_equal('vim three', getline(1))
2961 set cpo-=$
2962 call test_override('ALL', 0)
2963 delfunc SaveFirstLine
2964 %bw!
2965endfunc
2966
Bram Moolenaar818fc9a2020-02-21 17:54:45 +01002967" Test for using : to run a multi-line Ex command in operator pending mode
2968func Test_normal_yank_with_excmd()
2969 new
2970 call setline(1, ['foo', 'bar', 'baz'])
2971 let @a = ''
2972 call feedkeys("\"ay:if v:true\<CR>normal l\<CR>endif\<CR>", 'xt')
2973 call assert_equal('f', @a)
2974 close!
2975endfunc
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01002976
2977" Test for supplying a count to a normal-mode command across a cursorhold call
2978func Test_normal_cursorhold_with_count()
2979 func s:cHold()
2980 let g:cHold_Called += 1
2981 endfunc
2982 new
2983 augroup normalcHoldTest
2984 au!
2985 au CursorHold <buffer> call s:cHold()
2986 augroup END
2987 let g:cHold_Called = 0
2988 call feedkeys("3\<CursorHold>2ix", 'xt')
2989 call assert_equal(1, g:cHold_Called)
2990 call assert_equal(repeat('x', 32), getline(1))
2991 augroup normalcHoldTest
2992 au!
2993 augroup END
2994 au! normalcHoldTest
2995 close!
2996 delfunc s:cHold
2997endfunc
2998
2999" Test for using a count and a command with CTRL-W
3000func Test_wincmd_with_count()
3001 call feedkeys("\<C-W>12n", 'xt')
3002 call assert_equal(12, winheight(0))
3003endfunc
3004
3005" Test for 'b', 'B' 'ge' and 'gE' commands
Bram Moolenaar1671f442020-03-10 07:48:13 +01003006func Test_horiz_motion()
3007 new
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01003008 normal! gg
3009 call assert_beeps('normal! b')
3010 call assert_beeps('normal! B')
3011 call assert_beeps('normal! gE')
3012 call assert_beeps('normal! ge')
Bram Moolenaar1671f442020-03-10 07:48:13 +01003013 " <S-Backspace> moves one word left and <C-Backspace> moves one WORD left
3014 call setline(1, 'one ,two ,three')
3015 exe "normal! $\<S-BS>"
3016 call assert_equal(11, col('.'))
3017 exe "normal! $\<C-BS>"
3018 call assert_equal(10, col('.'))
3019 close!
3020endfunc
3021
3022" Test for using a : command in operator pending mode
3023func Test_normal_colon_op()
3024 new
3025 call setline(1, ['one', 'two'])
3026 call assert_beeps("normal! Gc:d\<CR>")
3027 close!
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01003028endfunc
3029
3030" vim: shiftwidth=2 sts=2 expandtab