blob: 6c2c6296c6f222ab36b9771bac2015a0d2c791cf [file] [log] [blame]
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001" Test for various Normal mode commands
2
Bram Moolenaara84a3dd2019-03-25 22:21:24 +01003source shared.vim
Bram Moolenaar5a4c3082019-12-01 15:23:11 +01004source check.vim
Bram Moolenaara84a3dd2019-03-25 22:21:24 +01005
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01006func Setup_NewWindow()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02007 10new
8 call setline(1, range(1,100))
9endfunc
10
Bram Moolenaar1bbb6192018-11-10 16:02:01 +010011func MyFormatExpr()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +020012 " Adds '->$' at lines having numbers followed by trailing whitespace
13 for ln in range(v:lnum, v:lnum+v:count-1)
14 let line = getline(ln)
15 if getline(ln) =~# '\d\s\+$'
16 call setline(ln, substitute(line, '\s\+$', '', '') . '->$')
17 endif
18 endfor
Bram Moolenaar2931f2a2016-09-09 16:59:08 +020019endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +020020
Bram Moolenaar1bbb6192018-11-10 16:02:01 +010021func CountSpaces(type, ...)
Bram Moolenaar87bc3f72016-09-03 17:33:54 +020022 " for testing operatorfunc
23 " will count the number of spaces
24 " and return the result in g:a
25 let sel_save = &selection
26 let &selection = "inclusive"
27 let reg_save = @@
28
29 if a:0 " Invoked from Visual mode, use gv command.
30 silent exe "normal! gvy"
31 elseif a:type == 'line'
32 silent exe "normal! '[V']y"
33 else
34 silent exe "normal! `[v`]y"
35 endif
36 let g:a=strlen(substitute(@@, '[^ ]', '', 'g'))
37 let &selection = sel_save
38 let @@ = reg_save
Bram Moolenaar2931f2a2016-09-09 16:59:08 +020039endfunc
40
Bram Moolenaar1bbb6192018-11-10 16:02:01 +010041func OpfuncDummy(type, ...)
Bram Moolenaar4a08b0d2016-11-05 21:55:13 +010042 " for testing operatorfunc
43 let g:opt=&linebreak
44
45 if a:0 " Invoked from Visual mode, use gv command.
46 silent exe "normal! gvy"
47 elseif a:type == 'line'
48 silent exe "normal! '[V']y"
49 else
50 silent exe "normal! `[v`]y"
51 endif
52 " Create a new dummy window
53 new
54 let g:bufnr=bufnr('%')
Bram Moolenaar2931f2a2016-09-09 16:59:08 +020055endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +020056
57fun! Test_normal00_optrans()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +020058 new
59 call append(0, ['1 This is a simple test: abcd', '2 This is the second line', '3 this is the third line'])
60 1
61 exe "norm! Sfoobar\<esc>"
62 call assert_equal(['foobar', '2 This is the second line', '3 this is the third line', ''], getline(1,'$'))
63 2
Bram Moolenaar87bc3f72016-09-03 17:33:54 +020064 exe "norm! $vbsone"
65 call assert_equal(['foobar', '2 This is the second one', '3 this is the third line', ''], getline(1,'$'))
Bram Moolenaar87bc3f72016-09-03 17:33:54 +020066 norm! VS Second line here
67 call assert_equal(['foobar', ' Second line here', '3 this is the third line', ''], getline(1, '$'))
68 %d
69 call append(0, ['4 This is a simple test: abcd', '5 This is the second line', '6 this is the third line'])
70 call append(0, ['1 This is a simple test: abcd', '2 This is the second line', '3 this is the third line'])
71
72 1
73 norm! 2D
74 call assert_equal(['3 this is the third line', '4 This is a simple test: abcd', '5 This is the second line', '6 this is the third line', ''], getline(1,'$'))
75 set cpo+=#
76 norm! 4D
77 call assert_equal(['', '4 This is a simple test: abcd', '5 This is the second line', '6 this is the third line', ''], getline(1,'$'))
78
79 " clean up
80 set cpo-=#
81 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +020082endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +020083
Bram Moolenaar1bbb6192018-11-10 16:02:01 +010084func Test_normal01_keymodel()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +020085 call Setup_NewWindow()
86 " Test 1: depending on 'keymodel' <s-down> does something different
Bram Moolenaar2931f2a2016-09-09 16:59:08 +020087 50
Bram Moolenaar87bc3f72016-09-03 17:33:54 +020088 call feedkeys("V\<S-Up>y", 'tx')
89 call assert_equal(['47', '48', '49', '50'], getline("'<", "'>"))
Bram Moolenaar2931f2a2016-09-09 16:59:08 +020090 set keymodel=startsel
91 50
Bram Moolenaar87bc3f72016-09-03 17:33:54 +020092 call feedkeys("V\<S-Up>y", 'tx')
93 call assert_equal(['49', '50'], getline("'<", "'>"))
94 " Start visual mode when keymodel = startsel
Bram Moolenaar2931f2a2016-09-09 16:59:08 +020095 50
Bram Moolenaar87bc3f72016-09-03 17:33:54 +020096 call feedkeys("\<S-Up>y", 'tx')
97 call assert_equal(['49', '5'], getreg(0, 0, 1))
98 " Do not start visual mode when keymodel=
Bram Moolenaar2931f2a2016-09-09 16:59:08 +020099 set keymodel=
100 50
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200101 call feedkeys("\<S-Up>y$", 'tx')
102 call assert_equal(['42'], getreg(0, 0, 1))
Bram Moolenaar2931f2a2016-09-09 16:59:08 +0200103 " Stop visual mode when keymodel=stopsel
104 set keymodel=stopsel
105 50
106 call feedkeys("Vkk\<Up>yy", 'tx')
107 call assert_equal(['47'], getreg(0, 0, 1))
108
109 set keymodel=
110 50
111 call feedkeys("Vkk\<Up>yy", 'tx')
112 call assert_equal(['47', '48', '49', '50'], getreg(0, 0, 1))
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200113
114 " clean up
115 bw!
116endfunc
117
Bram Moolenaarf5f1e102020-03-08 05:13:15 +0100118" Test for select mode
Bram Moolenaar1bbb6192018-11-10 16:02:01 +0100119func Test_normal02_selectmode()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200120 call Setup_NewWindow()
121 50
122 norm! gHy
123 call assert_equal('y51', getline('.'))
124 call setline(1, range(1,100))
125 50
126 exe ":norm! V9jo\<c-g>y"
127 call assert_equal('y60', getline('.'))
128 " clean up
129 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +0200130endfunc
131
Bram Moolenaar1bbb6192018-11-10 16:02:01 +0100132func Test_normal02_selectmode2()
Bram Moolenaar2931f2a2016-09-09 16:59:08 +0200133 " some basic select mode tests
134 call Setup_NewWindow()
135 50
136 call feedkeys(":set im\n\<c-o>gHc\<c-o>:set noim\n", 'tx')
137 call assert_equal('c51', getline('.'))
138 " clean up
139 bw!
140endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200141
Bram Moolenaar1bbb6192018-11-10 16:02:01 +0100142func Test_normal03_join()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200143 " basic join test
144 call Setup_NewWindow()
145 50
146 norm! VJ
147 call assert_equal('50 51', getline('.'))
148 $
149 norm! J
150 call assert_equal('100', getline('.'))
151 $
152 norm! V9-gJ
153 call assert_equal('919293949596979899100', getline('.'))
154 call setline(1, range(1,100))
155 $
156 :j 10
157 call assert_equal('100', getline('.'))
158 " clean up
159 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +0200160endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200161
Bram Moolenaar1bbb6192018-11-10 16:02:01 +0100162func Test_normal04_filter()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200163 " basic filter test
164 " only test on non windows platform
Bram Moolenaar4a08b0d2016-11-05 21:55:13 +0100165 if has('win32')
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200166 return
167 endif
168 call Setup_NewWindow()
169 1
170 call feedkeys("!!sed -e 's/^/| /'\n", 'tx')
171 call assert_equal('| 1', getline('.'))
172 90
173 :sil :!echo one
174 call feedkeys('.', 'tx')
175 call assert_equal('| 90', getline('.'))
176 95
177 set cpo+=!
178 " 2 <CR>, 1: for executing the command,
179 " 2: clear hit-enter-prompt
180 call feedkeys("!!\n", 'tx')
181 call feedkeys(":!echo one\n\n", 'tx')
182 call feedkeys(".", 'tx')
183 call assert_equal('one', getline('.'))
184 set cpo-=!
185 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +0200186endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200187
Bram Moolenaar1bbb6192018-11-10 16:02:01 +0100188func Test_normal05_formatexpr()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200189 " basic formatexpr test
190 call Setup_NewWindow()
191 %d_
192 call setline(1, ['here: 1 ', '2', 'here: 3 ', '4', 'not here: '])
193 1
194 set formatexpr=MyFormatExpr()
195 norm! gqG
196 call assert_equal(['here: 1->$', '2', 'here: 3->$', '4', 'not here: '], getline(1,'$'))
197 set formatexpr=
198 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +0200199endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200200
Bram Moolenaard77f9d52016-09-04 15:13:39 +0200201func Test_normal05_formatexpr_newbuf()
202 " Edit another buffer in the 'formatexpr' function
203 new
204 func! Format()
205 edit another
206 endfunc
207 set formatexpr=Format()
208 norm gqG
209 bw!
210 set formatexpr=
211endfunc
212
213func Test_normal05_formatexpr_setopt()
214 " Change the 'formatexpr' value in the function
215 new
216 func! Format()
217 set formatexpr=
218 endfunc
219 set formatexpr=Format()
220 norm gqG
221 bw!
222 set formatexpr=
223endfunc
224
Bram Moolenaar1bbb6192018-11-10 16:02:01 +0100225func Test_normal06_formatprg()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200226 " basic test for formatprg
227 " only test on non windows platform
Bram Moolenaar4a08b0d2016-11-05 21:55:13 +0100228 if has('win32')
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200229 return
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200230 endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +0100231
232 " uses sed to number non-empty lines
233 call writefile(['#!/bin/sh', 'sed ''/./=''|sed ''/./{', 'N', 's/\n/ /', '}'''], 'Xsed_format.sh')
234 call system('chmod +x ./Xsed_format.sh')
235 let text = ['a', '', 'c', '', ' ', 'd', 'e']
236 let expected = ['1 a', '', '3 c', '', '5 ', '6 d', '7 e']
237
238 10new
239 call setline(1, text)
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200240 set formatprg=./Xsed_format.sh
241 norm! gggqG
Bram Moolenaar9be7c042017-01-14 14:28:30 +0100242 call assert_equal(expected, getline(1, '$'))
243 bw!
244
245 10new
246 call setline(1, text)
247 set formatprg=donothing
248 setlocal formatprg=./Xsed_format.sh
249 norm! gggqG
250 call assert_equal(expected, getline(1, '$'))
251 bw!
252
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200253 " clean up
254 set formatprg=
Bram Moolenaar9be7c042017-01-14 14:28:30 +0100255 setlocal formatprg=
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200256 call delete('Xsed_format.sh')
Bram Moolenaar2931f2a2016-09-09 16:59:08 +0200257endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200258
Bram Moolenaar1bbb6192018-11-10 16:02:01 +0100259func Test_normal07_internalfmt()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200260 " basic test for internal formmatter to textwidth of 12
261 let list=range(1,11)
262 call map(list, 'v:val." "')
263 10new
264 call setline(1, list)
265 set tw=12
266 norm! gggqG
267 call assert_equal(['1 2 3', '4 5 6', '7 8 9', '10 11 '], getline(1, '$'))
268 " clean up
Bram Moolenaar9be7c042017-01-14 14:28:30 +0100269 set tw=0
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200270 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +0200271endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200272
Bram Moolenaar1bbb6192018-11-10 16:02:01 +0100273func Test_normal08_fold()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200274 " basic tests for foldopen/folddelete
275 if !has("folding")
276 return
277 endif
278 call Setup_NewWindow()
279 50
280 setl foldenable fdm=marker
281 " First fold
282 norm! V4jzf
283 " check that folds have been created
284 call assert_equal(['50/*{{{*/', '51', '52', '53', '54/*}}}*/'], getline(50,54))
285 " Second fold
286 46
287 norm! V10jzf
288 " check that folds have been created
289 call assert_equal('46/*{{{*/', getline(46))
290 call assert_equal('60/*}}}*/', getline(60))
291 norm! k
292 call assert_equal('45', getline('.'))
293 norm! j
294 call assert_equal('46/*{{{*/', getline('.'))
295 norm! j
296 call assert_equal('61', getline('.'))
297 norm! k
298 " open a fold
299 norm! Vzo
300 norm! k
301 call assert_equal('45', getline('.'))
302 norm! j
303 call assert_equal('46/*{{{*/', getline('.'))
304 norm! j
305 call assert_equal('47', getline('.'))
306 norm! k
307 norm! zcVzO
308 call assert_equal('46/*{{{*/', getline('.'))
309 norm! j
310 call assert_equal('47', getline('.'))
311 norm! j
312 call assert_equal('48', getline('.'))
313 norm! j
314 call assert_equal('49', getline('.'))
315 norm! j
316 call assert_equal('50/*{{{*/', getline('.'))
317 norm! j
318 call assert_equal('51', getline('.'))
319 " delete folds
320 :46
321 " collapse fold
322 norm! V14jzC
323 " delete all folds recursively
324 norm! VzD
325 call assert_equal(['46', '47', '48', '49', '50', '51', '52', '53', '54', '55', '56', '57', '58', '59', '60'], getline(46,60))
326
327 " clean up
328 setl nofoldenable fdm=marker
329 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +0200330endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200331
Bram Moolenaar1bbb6192018-11-10 16:02:01 +0100332func Test_normal09_operatorfunc()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200333 " Test operatorfunc
334 call Setup_NewWindow()
335 " Add some spaces for counting
336 50,60s/$/ /
337 unlet! g:a
338 let g:a=0
339 nmap <buffer><silent> ,, :set opfunc=CountSpaces<CR>g@
340 vmap <buffer><silent> ,, :<C-U>call CountSpaces(visualmode(), 1)<CR>
341 50
342 norm V2j,,
343 call assert_equal(6, g:a)
344 norm V,,
345 call assert_equal(2, g:a)
346 norm ,,l
347 call assert_equal(0, g:a)
348 50
349 exe "norm 0\<c-v>10j2l,,"
350 call assert_equal(11, g:a)
351 50
352 norm V10j,,
353 call assert_equal(22, g:a)
354
355 " clean up
356 unmap <buffer> ,,
357 set opfunc=
Bram Moolenaar4a08b0d2016-11-05 21:55:13 +0100358 unlet! g:a
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200359 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +0200360endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200361
Bram Moolenaar1bbb6192018-11-10 16:02:01 +0100362func Test_normal09a_operatorfunc()
Bram Moolenaar4a08b0d2016-11-05 21:55:13 +0100363 " Test operatorfunc
364 call Setup_NewWindow()
365 " Add some spaces for counting
366 50,60s/$/ /
367 unlet! g:opt
368 set linebreak
369 nmap <buffer><silent> ,, :set opfunc=OpfuncDummy<CR>g@
370 50
371 norm ,,j
372 exe "bd!" g:bufnr
373 call assert_true(&linebreak)
374 call assert_equal(g:opt, &linebreak)
375 set nolinebreak
376 norm ,,j
377 exe "bd!" g:bufnr
378 call assert_false(&linebreak)
379 call assert_equal(g:opt, &linebreak)
380
381 " clean up
382 unmap <buffer> ,,
383 set opfunc=
384 bw!
385 unlet! g:opt
386endfunc
387
Bram Moolenaar1bbb6192018-11-10 16:02:01 +0100388func Test_normal10_expand()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200389 " Test for expand()
390 10new
391 call setline(1, ['1', 'ifooar,,cbar'])
392 2
393 norm! $
Bram Moolenaar65f08472017-09-10 18:16:20 +0200394 call assert_equal('cbar', expand('<cword>'))
395 call assert_equal('ifooar,,cbar', expand('<cWORD>'))
396
397 call setline(1, ['prx = list[idx];'])
398 1
399 let expected = ['', 'prx', 'prx', 'prx',
400 \ 'list', 'list', 'list', 'list', 'list', 'list', 'list',
401 \ 'idx', 'idx', 'idx', 'idx',
402 \ 'list[idx]',
403 \ '];',
404 \ ]
405 for i in range(1, 16)
406 exe 'norm ' . i . '|'
407 call assert_equal(expected[i], expand('<cexpr>'), 'i == ' . i)
408 endfor
409
Bram Moolenaarae6f8652017-12-20 22:32:20 +0100410 if executable('echo')
411 " Test expand(`...`) i.e. backticks command expansion.
Bram Moolenaar077ff432019-10-28 00:42:21 +0100412 call assert_equal('abcde', expand('`echo abcde`'))
Bram Moolenaarae6f8652017-12-20 22:32:20 +0100413 endif
414
415 " Test expand(`=...`) i.e. backticks expression expansion
416 call assert_equal('5', expand('`=2+3`'))
417
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200418 " clean up
419 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +0200420endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200421
Bram Moolenaar1bbb6192018-11-10 16:02:01 +0100422func Test_normal11_showcmd()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200423 " test for 'showcmd'
424 10new
425 exe "norm! ofoobar\<esc>"
426 call assert_equal(2, line('$'))
427 set showcmd
428 exe "norm! ofoobar2\<esc>"
429 call assert_equal(3, line('$'))
430 exe "norm! VAfoobar3\<esc>"
431 call assert_equal(3, line('$'))
432 exe "norm! 0d3\<del>2l"
433 call assert_equal('obar2foobar3', getline('.'))
434 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +0200435endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200436
Bram Moolenaar1bbb6192018-11-10 16:02:01 +0100437func Test_normal12_nv_error()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200438 " Test for nv_error
439 10new
440 call setline(1, range(1,5))
441 " should not do anything, just beep
Bram Moolenaarf5f1e102020-03-08 05:13:15 +0100442 call assert_beeps('exe "norm! <c-k>"')
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200443 call assert_equal(map(range(1,5), 'string(v:val)'), getline(1,'$'))
Bram Moolenaarf5f1e102020-03-08 05:13:15 +0100444 call assert_beeps('normal! G2dd')
445 call assert_beeps("normal! g\<C-A>")
446 call assert_beeps("normal! g\<C-X>")
447 call assert_beeps("normal! g\<C-B>")
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 Moolenaar1bbb6192018-11-10 16:02:01 +0100503func Test_normal15_z_scroll_vert()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200504 " basic test for z commands that scroll the window
505 call Setup_NewWindow()
506 100
507 norm! >>
508 " Test for z<cr>
509 exe "norm! z\<cr>"
510 call assert_equal(' 100', getline('.'))
511 call assert_equal(100, winsaveview()['topline'])
512 call assert_equal([0, 100, 2, 0, 9], getcurpos())
513
514 " Test for zt
515 21
516 norm! >>0zt
517 call assert_equal(' 21', getline('.'))
518 call assert_equal(21, winsaveview()['topline'])
519 call assert_equal([0, 21, 1, 0, 8], getcurpos())
520
521 " Test for zb
522 30
523 norm! >>$ztzb
524 call assert_equal(' 30', getline('.'))
525 call assert_equal(30, winsaveview()['topline']+winheight(0)-1)
526 call assert_equal([0, 30, 3, 0, 2147483647], getcurpos())
527
528 " Test for z-
529 1
530 30
531 norm! 0z-
532 call assert_equal(' 30', getline('.'))
533 call assert_equal(30, winsaveview()['topline']+winheight(0)-1)
534 call assert_equal([0, 30, 2, 0, 9], getcurpos())
535
536 " Test for z{height}<cr>
537 call assert_equal(10, winheight(0))
538 exe "norm! z12\<cr>"
539 call assert_equal(12, winheight(0))
540 exe "norm! z10\<cr>"
541 call assert_equal(10, winheight(0))
542
543 " Test for z.
544 1
545 21
546 norm! 0z.
547 call assert_equal(' 21', getline('.'))
548 call assert_equal(17, winsaveview()['topline'])
549 call assert_equal([0, 21, 2, 0, 9], getcurpos())
550
551 " Test for zz
552 1
553 21
554 norm! 0zz
555 call assert_equal(' 21', getline('.'))
556 call assert_equal(17, winsaveview()['topline'])
557 call assert_equal([0, 21, 1, 0, 8], getcurpos())
558
559 " Test for z+
560 11
561 norm! zt
562 norm! z+
563 call assert_equal(' 21', getline('.'))
564 call assert_equal(21, winsaveview()['topline'])
565 call assert_equal([0, 21, 2, 0, 9], getcurpos())
566
567 " Test for [count]z+
568 1
569 norm! 21z+
570 call assert_equal(' 21', getline('.'))
571 call assert_equal(21, winsaveview()['topline'])
572 call assert_equal([0, 21, 2, 0, 9], getcurpos())
573
574 " Test for z^
575 norm! 22z+0
576 norm! z^
577 call assert_equal(' 21', getline('.'))
578 call assert_equal(12, winsaveview()['topline'])
579 call assert_equal([0, 21, 2, 0, 9], getcurpos())
580
581 " Test for [count]z^
582 1
583 norm! 30z^
584 call assert_equal(' 21', getline('.'))
585 call assert_equal(12, winsaveview()['topline'])
586 call assert_equal([0, 21, 2, 0, 9], getcurpos())
587
588 " cleanup
589 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +0200590endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200591
Bram Moolenaar1bbb6192018-11-10 16:02:01 +0100592func Test_normal16_z_scroll_hor()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200593 " basic test for z commands that scroll the window
594 10new
595 15vsp
596 set nowrap listchars=
597 let lineA='abcdefghijklmnopqrstuvwxyz'
598 let lineB='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'
599 $put =lineA
600 $put =lineB
601 1d
602
603 " Test for zl
604 1
605 norm! 5zl
606 call assert_equal(lineA, getline('.'))
607 call assert_equal(6, col('.'))
608 call assert_equal(5, winsaveview()['leftcol'])
609 norm! yl
610 call assert_equal('f', @0)
611
612 " Test for zh
613 norm! 2zh
614 call assert_equal(lineA, getline('.'))
615 call assert_equal(6, col('.'))
616 norm! yl
617 call assert_equal('f', @0)
618 call assert_equal(3, winsaveview()['leftcol'])
619
620 " Test for zL
621 norm! zL
622 call assert_equal(11, col('.'))
623 norm! yl
624 call assert_equal('k', @0)
625 call assert_equal(10, winsaveview()['leftcol'])
626 norm! 2zL
627 call assert_equal(25, col('.'))
628 norm! yl
629 call assert_equal('y', @0)
630 call assert_equal(24, winsaveview()['leftcol'])
631
632 " Test for zH
633 norm! 2zH
634 call assert_equal(25, col('.'))
635 call assert_equal(10, winsaveview()['leftcol'])
636 norm! yl
637 call assert_equal('y', @0)
638
639 " Test for zs
640 norm! $zs
641 call assert_equal(26, col('.'))
642 call assert_equal(25, winsaveview()['leftcol'])
643 norm! yl
644 call assert_equal('z', @0)
645
646 " Test for ze
647 norm! ze
648 call assert_equal(26, col('.'))
649 call assert_equal(11, winsaveview()['leftcol'])
650 norm! yl
651 call assert_equal('z', @0)
652
653 " cleanup
654 set wrap listchars=eol:$
655 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +0200656endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200657
Bram Moolenaar1bbb6192018-11-10 16:02:01 +0100658func Test_normal17_z_scroll_hor2()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200659 " basic test for z commands that scroll the window
660 " using 'sidescrolloff' setting
661 10new
662 20vsp
663 set nowrap listchars= sidescrolloff=5
664 let lineA='abcdefghijklmnopqrstuvwxyz'
665 let lineB='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'
666 $put =lineA
667 $put =lineB
668 1d
669
670 " Test for zl
671 1
672 norm! 5zl
673 call assert_equal(lineA, getline('.'))
674 call assert_equal(11, col('.'))
675 call assert_equal(5, winsaveview()['leftcol'])
676 norm! yl
677 call assert_equal('k', @0)
678
679 " Test for zh
680 norm! 2zh
681 call assert_equal(lineA, getline('.'))
682 call assert_equal(11, col('.'))
683 norm! yl
684 call assert_equal('k', @0)
685 call assert_equal(3, winsaveview()['leftcol'])
686
687 " Test for zL
688 norm! 0zL
689 call assert_equal(16, col('.'))
690 norm! yl
691 call assert_equal('p', @0)
692 call assert_equal(10, winsaveview()['leftcol'])
693 norm! 2zL
694 call assert_equal(26, col('.'))
695 norm! yl
696 call assert_equal('z', @0)
697 call assert_equal(15, winsaveview()['leftcol'])
698
699 " Test for zH
700 norm! 2zH
701 call assert_equal(15, col('.'))
702 call assert_equal(0, winsaveview()['leftcol'])
703 norm! yl
704 call assert_equal('o', @0)
705
706 " Test for zs
707 norm! $zs
708 call assert_equal(26, col('.'))
709 call assert_equal(20, winsaveview()['leftcol'])
710 norm! yl
711 call assert_equal('z', @0)
712
713 " Test for ze
714 norm! ze
715 call assert_equal(26, col('.'))
716 call assert_equal(11, winsaveview()['leftcol'])
717 norm! yl
718 call assert_equal('z', @0)
719
720 " cleanup
721 set wrap listchars=eol:$ sidescrolloff=0
722 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +0200723endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200724
Bram Moolenaar1bbb6192018-11-10 16:02:01 +0100725func Test_normal18_z_fold()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200726 " basic tests for foldopen/folddelete
727 if !has("folding")
728 return
729 endif
730 call Setup_NewWindow()
731 50
732 setl foldenable fdm=marker foldlevel=5
733
734 " Test for zF
735 " First fold
736 norm! 4zF
737 " check that folds have been created
738 call assert_equal(['50/*{{{*/', '51', '52', '53/*}}}*/'], getline(50,53))
739
740 " Test for zd
741 51
742 norm! 2zF
743 call assert_equal(2, foldlevel('.'))
744 norm! kzd
745 call assert_equal(['50', '51/*{{{*/', '52/*}}}*/', '53'], getline(50,53))
746 norm! j
747 call assert_equal(1, foldlevel('.'))
748
749 " Test for zD
750 " also deletes partially selected folds recursively
751 51
752 norm! zF
753 call assert_equal(2, foldlevel('.'))
754 norm! kV2jzD
755 call assert_equal(['50', '51', '52', '53'], getline(50,53))
756
757 " Test for zE
758 85
759 norm! 4zF
760 86
761 norm! 2zF
762 90
763 norm! 4zF
764 call assert_equal(['85/*{{{*/', '86/*{{{*/', '87/*}}}*/', '88/*}}}*/', '89', '90/*{{{*/', '91', '92', '93/*}}}*/'], getline(85,93))
765 norm! zE
766 call assert_equal(['85', '86', '87', '88', '89', '90', '91', '92', '93'], getline(85,93))
767
768 " Test for zn
769 50
770 set foldlevel=0
771 norm! 2zF
772 norm! zn
773 norm! k
774 call assert_equal('49', getline('.'))
775 norm! j
776 call assert_equal('50/*{{{*/', getline('.'))
777 norm! j
778 call assert_equal('51/*}}}*/', getline('.'))
779 norm! j
780 call assert_equal('52', getline('.'))
781 call assert_equal(0, &foldenable)
782
783 " Test for zN
784 49
785 norm! zN
786 call assert_equal('49', getline('.'))
787 norm! j
788 call assert_equal('50/*{{{*/', getline('.'))
789 norm! j
790 call assert_equal('52', getline('.'))
791 call assert_equal(1, &foldenable)
792
793 " Test for zi
794 norm! zi
795 call assert_equal(0, &foldenable)
796 norm! zi
797 call assert_equal(1, &foldenable)
798 norm! zi
799 call assert_equal(0, &foldenable)
800 norm! zi
801 call assert_equal(1, &foldenable)
802
803 " Test for za
804 50
805 norm! za
806 norm! k
807 call assert_equal('49', getline('.'))
808 norm! j
809 call assert_equal('50/*{{{*/', getline('.'))
810 norm! j
811 call assert_equal('51/*}}}*/', getline('.'))
812 norm! j
813 call assert_equal('52', getline('.'))
814 50
815 norm! za
816 norm! k
817 call assert_equal('49', getline('.'))
818 norm! j
819 call assert_equal('50/*{{{*/', getline('.'))
820 norm! j
821 call assert_equal('52', getline('.'))
822
823 49
824 norm! 5zF
825 norm! k
826 call assert_equal('48', getline('.'))
827 norm! j
828 call assert_equal('49/*{{{*/', getline('.'))
829 norm! j
830 call assert_equal('55', getline('.'))
831 49
832 norm! za
833 call assert_equal('49/*{{{*/', getline('.'))
834 norm! j
835 call assert_equal('50/*{{{*/', getline('.'))
836 norm! j
837 call assert_equal('52', getline('.'))
838 set nofoldenable
839 " close fold and set foldenable
840 norm! za
841 call assert_equal(1, &foldenable)
842
843 50
844 " have to use {count}za to open all folds and make the cursor visible
845 norm! 2za
846 norm! 2k
847 call assert_equal('48', getline('.'))
848 norm! j
849 call assert_equal('49/*{{{*/', getline('.'))
850 norm! j
851 call assert_equal('50/*{{{*/', getline('.'))
852 norm! j
853 call assert_equal('51/*}}}*/', getline('.'))
854 norm! j
855 call assert_equal('52', getline('.'))
856
857 " Test for zA
858 49
859 set foldlevel=0
860 50
861 norm! zA
862 norm! 2k
863 call assert_equal('48', getline('.'))
864 norm! j
865 call assert_equal('49/*{{{*/', getline('.'))
866 norm! j
867 call assert_equal('50/*{{{*/', getline('.'))
868 norm! j
869 call assert_equal('51/*}}}*/', getline('.'))
870 norm! j
871 call assert_equal('52', getline('.'))
872
Bram Moolenaar395b6ba2017-04-07 20:09:51 +0200873 " zA on a opened fold when foldenable is not set
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200874 50
875 set nofoldenable
876 norm! zA
877 call assert_equal(1, &foldenable)
878 norm! k
879 call assert_equal('48', getline('.'))
880 norm! j
881 call assert_equal('49/*{{{*/', getline('.'))
882 norm! j
883 call assert_equal('55', getline('.'))
884
885 " Test for zc
886 norm! zE
887 50
888 norm! 2zF
889 49
890 norm! 5zF
891 set nofoldenable
892 50
893 " There most likely is a bug somewhere:
894 " https://groups.google.com/d/msg/vim_dev/v2EkfJ_KQjI/u-Cvv94uCAAJ
895 " TODO: Should this only close the inner most fold or both folds?
896 norm! zc
897 call assert_equal(1, &foldenable)
898 norm! k
899 call assert_equal('48', getline('.'))
900 norm! j
901 call assert_equal('49/*{{{*/', getline('.'))
902 norm! j
903 call assert_equal('55', getline('.'))
904 set nofoldenable
905 50
906 norm! Vjzc
907 norm! k
908 call assert_equal('48', getline('.'))
909 norm! j
910 call assert_equal('49/*{{{*/', getline('.'))
911 norm! j
912 call assert_equal('55', getline('.'))
913
914 " Test for zC
915 set nofoldenable
916 50
917 norm! zCk
918 call assert_equal('48', getline('.'))
919 norm! j
920 call assert_equal('49/*{{{*/', getline('.'))
921 norm! j
922 call assert_equal('55', getline('.'))
923
924 " Test for zx
925 " 1) close folds at line 49-54
926 set nofoldenable
927 48
928 norm! zx
929 call assert_equal(1, &foldenable)
930 norm! j
931 call assert_equal('49/*{{{*/', getline('.'))
932 norm! j
933 call assert_equal('55', getline('.'))
934
Bram Moolenaar395b6ba2017-04-07 20:09:51 +0200935 " 2) do not close fold under cursor
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200936 51
937 set nofoldenable
938 norm! zx
939 call assert_equal(1, &foldenable)
940 norm! 3k
941 call assert_equal('48', getline('.'))
942 norm! j
943 call assert_equal('49/*{{{*/', getline('.'))
944 norm! j
945 call assert_equal('50/*{{{*/', getline('.'))
946 norm! j
947 call assert_equal('51/*}}}*/', getline('.'))
948 norm! j
949 call assert_equal('52', getline('.'))
950 norm! j
951 call assert_equal('53', getline('.'))
952 norm! j
953 call assert_equal('54/*}}}*/', getline('.'))
954 norm! j
955 call assert_equal('55', getline('.'))
956
957 " 3) close one level of folds
958 48
959 set nofoldenable
960 set foldlevel=1
961 norm! zx
962 call assert_equal(1, &foldenable)
963 call assert_equal('48', getline('.'))
964 norm! j
965 call assert_equal('49/*{{{*/', getline('.'))
966 norm! j
967 call assert_equal('50/*{{{*/', getline('.'))
968 norm! j
969 call assert_equal('52', getline('.'))
970 norm! j
971 call assert_equal('53', getline('.'))
972 norm! j
973 call assert_equal('54/*}}}*/', getline('.'))
974 norm! j
975 call assert_equal('55', getline('.'))
976
977 " Test for zX
978 " Close all folds
979 set foldlevel=0 nofoldenable
980 50
981 norm! zX
982 call assert_equal(1, &foldenable)
983 norm! k
984 call assert_equal('48', getline('.'))
985 norm! j
986 call assert_equal('49/*{{{*/', getline('.'))
987 norm! j
988 call assert_equal('55', getline('.'))
989
990 " Test for zm
991 50
992 set nofoldenable foldlevel=2
993 norm! zm
994 call assert_equal(1, &foldenable)
995 call assert_equal(1, &foldlevel)
996 norm! zm
997 call assert_equal(0, &foldlevel)
998 norm! zm
999 call assert_equal(0, &foldlevel)
1000 norm! k
1001 call assert_equal('48', getline('.'))
1002 norm! j
1003 call assert_equal('49/*{{{*/', getline('.'))
1004 norm! j
1005 call assert_equal('55', getline('.'))
1006
1007 " Test for zM
1008 48
1009 set nofoldenable foldlevel=99
1010 norm! zM
1011 call assert_equal(1, &foldenable)
1012 call assert_equal(0, &foldlevel)
1013 call assert_equal('48', getline('.'))
1014 norm! j
1015 call assert_equal('49/*{{{*/', getline('.'))
1016 norm! j
1017 call assert_equal('55', getline('.'))
1018
1019 " Test for zr
1020 48
1021 set nofoldenable foldlevel=0
1022 norm! zr
1023 call assert_equal(0, &foldenable)
1024 call assert_equal(1, &foldlevel)
1025 set foldlevel=0 foldenable
1026 norm! zr
1027 call assert_equal(1, &foldenable)
1028 call assert_equal(1, &foldlevel)
1029 norm! zr
1030 call assert_equal(2, &foldlevel)
1031 call assert_equal('48', getline('.'))
1032 norm! j
1033 call assert_equal('49/*{{{*/', getline('.'))
1034 norm! j
1035 call assert_equal('50/*{{{*/', getline('.'))
1036 norm! j
1037 call assert_equal('51/*}}}*/', getline('.'))
1038 norm! j
1039 call assert_equal('52', getline('.'))
1040
1041 " Test for zR
1042 48
1043 set nofoldenable foldlevel=0
1044 norm! zR
1045 call assert_equal(0, &foldenable)
1046 call assert_equal(2, &foldlevel)
1047 set foldenable foldlevel=0
1048 norm! zR
1049 call assert_equal(1, &foldenable)
1050 call assert_equal(2, &foldlevel)
1051 call assert_equal('48', getline('.'))
1052 norm! j
1053 call assert_equal('49/*{{{*/', getline('.'))
1054 norm! j
1055 call assert_equal('50/*{{{*/', getline('.'))
1056 norm! j
1057 call assert_equal('51/*}}}*/', getline('.'))
1058 norm! j
1059 call assert_equal('52', getline('.'))
1060 call append(50, ['a /*{{{*/', 'b /*}}}*/'])
1061 48
1062 call assert_equal('48', getline('.'))
1063 norm! j
1064 call assert_equal('49/*{{{*/', getline('.'))
1065 norm! j
1066 call assert_equal('50/*{{{*/', getline('.'))
1067 norm! j
1068 call assert_equal('a /*{{{*/', getline('.'))
1069 norm! j
1070 call assert_equal('51/*}}}*/', getline('.'))
1071 norm! j
1072 call assert_equal('52', getline('.'))
1073 48
1074 norm! zR
1075 call assert_equal(1, &foldenable)
1076 call assert_equal(3, &foldlevel)
1077 call assert_equal('48', getline('.'))
1078 norm! j
1079 call assert_equal('49/*{{{*/', getline('.'))
1080 norm! j
1081 call assert_equal('50/*{{{*/', getline('.'))
1082 norm! j
1083 call assert_equal('a /*{{{*/', getline('.'))
1084 norm! j
1085 call assert_equal('b /*}}}*/', getline('.'))
1086 norm! j
1087 call assert_equal('51/*}}}*/', getline('.'))
1088 norm! j
1089 call assert_equal('52', getline('.'))
1090
1091 " clean up
1092 setl nofoldenable fdm=marker foldlevel=0
1093 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02001094endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001095
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01001096func Test_normal20_exmode()
Bram Moolenaar0913a102016-09-03 19:11:59 +02001097 if !has("unix")
1098 " Reading from redirected file doesn't work on MS-Windows
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001099 return
1100 endif
1101 call writefile(['1a', 'foo', 'bar', '.', 'w! Xfile2', 'q!'], 'Xscript')
1102 call writefile(['1', '2'], 'Xfile')
Bram Moolenaar93344c22019-08-14 21:12:05 +02001103 call system(GetVimCommand() .. ' -e -s < Xscript Xfile')
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001104 let a=readfile('Xfile2')
1105 call assert_equal(['1', 'foo', 'bar', '2'], a)
1106
1107 " clean up
1108 for file in ['Xfile', 'Xfile2', 'Xscript']
1109 call delete(file)
1110 endfor
1111 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02001112endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001113
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01001114func Test_normal21_nv_hat()
1115
1116 " Edit a fresh file and wipe the buffer list so that there is no alternate
1117 " file present. Next, check for the expected command failures.
1118 edit Xfoo | %bw
1119 call assert_fails(':buffer #', 'E86')
1120 call assert_fails(':execute "normal! \<C-^>"', 'E23')
1121
1122 " Test for the expected behavior when switching between two named buffers.
1123 edit Xfoo | edit Xbar
1124 call feedkeys("\<C-^>", 'tx')
1125 call assert_equal('Xfoo', fnamemodify(bufname('%'), ':t'))
1126 call feedkeys("\<C-^>", 'tx')
1127 call assert_equal('Xbar', fnamemodify(bufname('%'), ':t'))
1128
1129 " Test for the expected behavior when only one buffer is named.
1130 enew | let l:nr = bufnr('%')
1131 call feedkeys("\<C-^>", 'tx')
1132 call assert_equal('Xbar', fnamemodify(bufname('%'), ':t'))
1133 call feedkeys("\<C-^>", 'tx')
1134 call assert_equal('', bufname('%'))
1135 call assert_equal(l:nr, bufnr('%'))
1136
1137 " Test that no action is taken by "<C-^>" when an operator is pending.
1138 edit Xfoo
1139 call feedkeys("ci\<C-^>", 'tx')
1140 call assert_equal('Xfoo', fnamemodify(bufname('%'), ':t'))
1141
1142 %bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02001143endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001144
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01001145func Test_normal22_zet()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001146 " Test for ZZ
Bram Moolenaar0913a102016-09-03 19:11:59 +02001147 " let shell = &shell
1148 " let &shell = 'sh'
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001149 call writefile(['1', '2'], 'Xfile')
Bram Moolenaar93344c22019-08-14 21:12:05 +02001150 let args = ' -N -i NONE --noplugins -X --not-a-term'
1151 call system(GetVimCommand() .. args .. ' -c "%d" -c ":norm! ZZ" Xfile')
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001152 let a = readfile('Xfile')
1153 call assert_equal([], a)
1154 " Test for ZQ
1155 call writefile(['1', '2'], 'Xfile')
Bram Moolenaar93344c22019-08-14 21:12:05 +02001156 call system(GetVimCommand() . args . ' -c "%d" -c ":norm! ZQ" Xfile')
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001157 let a = readfile('Xfile')
1158 call assert_equal(['1', '2'], a)
1159
1160 " clean up
1161 for file in ['Xfile']
1162 call delete(file)
1163 endfor
Bram Moolenaar0913a102016-09-03 19:11:59 +02001164 " let &shell = shell
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02001165endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001166
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01001167func Test_normal23_K()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001168 " Test for K command
1169 new
Bram Moolenaar426f3752016-11-04 21:22:37 +01001170 call append(0, ['version8.txt', 'man', 'aa%bb', 'cc|dd'])
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001171 let k = &keywordprg
1172 set keywordprg=:help
1173 1
1174 norm! VK
1175 call assert_equal('version8.txt', fnamemodify(bufname('%'), ':t'))
1176 call assert_equal('help', &ft)
1177 call assert_match('\*version8.txt\*', getline('.'))
1178 helpclose
1179 norm! 0K
1180 call assert_equal('version8.txt', fnamemodify(bufname('%'), ':t'))
1181 call assert_equal('help', &ft)
Bram Moolenaarb1c91982018-05-17 17:04:55 +02001182 call assert_match('\*version8\.\d\*', getline('.'))
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001183 helpclose
1184
Bram Moolenaar426f3752016-11-04 21:22:37 +01001185 set keywordprg=:new
1186 set iskeyword+=%
1187 set iskeyword+=\|
1188 2
1189 norm! K
1190 call assert_equal('man', fnamemodify(bufname('%'), ':t'))
1191 bwipe!
1192 3
1193 norm! K
1194 call assert_equal('aa%bb', fnamemodify(bufname('%'), ':t'))
1195 bwipe!
Bram Moolenaareb828d02016-11-05 19:54:01 +01001196 if !has('win32')
1197 4
1198 norm! K
1199 call assert_equal('cc|dd', fnamemodify(bufname('%'), ':t'))
1200 bwipe!
1201 endif
Bram Moolenaar426f3752016-11-04 21:22:37 +01001202 set iskeyword-=%
1203 set iskeyword-=\|
1204
Bram Moolenaar0913a102016-09-03 19:11:59 +02001205 " Only expect "man" to work on Unix
1206 if !has("unix")
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001207 let &keywordprg = k
1208 bw!
1209 return
1210 endif
Bram Moolenaarc6b37db2019-04-27 18:00:34 +02001211
Bram Moolenaar9134f1e2019-11-29 20:26:13 +01001212 let not_gnu_man = has('mac') || has('bsd')
1213 if not_gnu_man
Bram Moolenaarc7d2a572019-11-28 21:16:06 +01001214 " In MacOS and BSD, the option for specifying a pager is different
Bram Moolenaarc6b37db2019-04-27 18:00:34 +02001215 set keywordprg=man\ -P\ cat
1216 else
1217 set keywordprg=man\ --pager=cat
1218 endif
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001219 " Test for using man
1220 2
1221 let a = execute('unsilent norm! K')
Bram Moolenaar9134f1e2019-11-29 20:26:13 +01001222 if not_gnu_man
Bram Moolenaarc6b37db2019-04-27 18:00:34 +02001223 call assert_match("man -P cat 'man'", a)
1224 else
1225 call assert_match("man --pager=cat 'man'", a)
1226 endif
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001227
1228 " clean up
1229 let &keywordprg = k
1230 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02001231endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001232
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01001233func Test_normal24_rot13()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001234 " Testing for g?? g?g?
1235 new
1236 call append(0, 'abcdefghijklmnopqrstuvwxyzäüö')
1237 1
1238 norm! g??
1239 call assert_equal('nopqrstuvwxyzabcdefghijklmäüö', getline('.'))
1240 norm! g?g?
1241 call assert_equal('abcdefghijklmnopqrstuvwxyzäüö', getline('.'))
1242
1243 " clean up
1244 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02001245endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001246
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01001247func Test_normal25_tag()
Bram Moolenaar5a4c3082019-12-01 15:23:11 +01001248 CheckFeature quickfix
1249
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001250 " Testing for CTRL-] g CTRL-] g]
1251 " CTRL-W g] CTRL-W CTRL-] CTRL-W g CTRL-]
1252 h
1253 " Test for CTRL-]
1254 call search('\<x\>$')
1255 exe "norm! \<c-]>"
1256 call assert_equal("change.txt", fnamemodify(bufname('%'), ':t'))
1257 norm! yiW
1258 call assert_equal("*x*", @0)
1259 exe ":norm \<c-o>"
1260
1261 " Test for g_CTRL-]
1262 call search('\<v_u\>$')
1263 exe "norm! g\<c-]>"
1264 call assert_equal("change.txt", fnamemodify(bufname('%'), ':t'))
1265 norm! yiW
1266 call assert_equal("*v_u*", @0)
1267 exe ":norm \<c-o>"
1268
1269 " Test for g]
1270 call search('\<i_<Esc>$')
1271 let a = execute(":norm! g]")
1272 call assert_match('i_<Esc>.*insert.txt', a)
1273
1274 if !empty(exepath('cscope')) && has('cscope')
1275 " setting cscopetag changes how g] works
1276 set cst
1277 exe "norm! g]"
1278 call assert_equal("insert.txt", fnamemodify(bufname('%'), ':t'))
1279 norm! yiW
1280 call assert_equal("*i_<Esc>*", @0)
1281 exe ":norm \<c-o>"
1282 " Test for CTRL-W g]
1283 exe "norm! \<C-W>g]"
1284 call assert_equal("insert.txt", fnamemodify(bufname('%'), ':t'))
1285 norm! yiW
1286 call assert_equal("*i_<Esc>*", @0)
1287 call assert_equal(3, winnr('$'))
1288 helpclose
1289 set nocst
1290 endif
1291
1292 " Test for CTRL-W g]
1293 let a = execute("norm! \<C-W>g]")
1294 call assert_match('i_<Esc>.*insert.txt', a)
1295
1296 " Test for CTRL-W CTRL-]
1297 exe "norm! \<C-W>\<C-]>"
1298 call assert_equal("insert.txt", fnamemodify(bufname('%'), ':t'))
1299 norm! yiW
1300 call assert_equal("*i_<Esc>*", @0)
1301 call assert_equal(3, winnr('$'))
1302 helpclose
1303
1304 " Test for CTRL-W g CTRL-]
1305 exe "norm! \<C-W>g\<C-]>"
1306 call assert_equal("insert.txt", fnamemodify(bufname('%'), ':t'))
1307 norm! yiW
1308 call assert_equal("*i_<Esc>*", @0)
1309 call assert_equal(3, winnr('$'))
1310 helpclose
1311
1312 " clean up
1313 helpclose
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02001314endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001315
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01001316func Test_normal26_put()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001317 " Test for ]p ]P [p and [P
1318 new
1319 call append(0, ['while read LINE', 'do', ' ((count++))', ' if [ $? -ne 0 ]; then', " echo 'Error writing file'", ' fi', 'done'])
1320 1
1321 /Error/y a
1322 2
1323 norm! "a]pj"a[p
1324 call assert_equal(['do', "echo 'Error writing file'", " echo 'Error writing file'", ' ((count++))'], getline(2,5))
1325 1
1326 /^\s\{4}/
1327 exe "norm! \"a]P3Eldt'"
1328 exe "norm! j\"a[P2Eldt'"
1329 call assert_equal([' if [ $? -ne 0 ]; then', " echo 'Error writing'", " echo 'Error'", " echo 'Error writing file'", ' fi'], getline(6,10))
1330
1331 " clean up
1332 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02001333endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001334
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01001335func Test_normal27_bracket()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001336 " Test for [' [` ]' ]`
1337 call Setup_NewWindow()
1338 1,21s/.\+/ & b/
1339 1
1340 norm! $ma
1341 5
1342 norm! $mb
1343 10
1344 norm! $mc
1345 15
1346 norm! $md
1347 20
1348 norm! $me
1349
1350 " Test for ['
1351 9
1352 norm! 2['
1353 call assert_equal(' 1 b', getline('.'))
1354 call assert_equal(1, line('.'))
1355 call assert_equal(3, col('.'))
1356
1357 " Test for ]'
1358 norm! ]'
1359 call assert_equal(' 5 b', getline('.'))
1360 call assert_equal(5, line('.'))
1361 call assert_equal(3, col('.'))
1362
1363 " No mark after line 21, cursor moves to first non blank on current line
1364 21
1365 norm! $]'
1366 call assert_equal(' 21 b', getline('.'))
1367 call assert_equal(21, line('.'))
1368 call assert_equal(3, col('.'))
1369
1370 " Test for [`
1371 norm! 2[`
1372 call assert_equal(' 15 b', getline('.'))
1373 call assert_equal(15, line('.'))
1374 call assert_equal(8, col('.'))
1375
1376 " Test for ]`
1377 norm! ]`
1378 call assert_equal(' 20 b', getline('.'))
1379 call assert_equal(20, line('.'))
1380 call assert_equal(8, col('.'))
1381
1382 " clean up
1383 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02001384endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001385
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01001386func Test_normal28_parenthesis()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001387 " basic testing for ( and )
1388 new
1389 call append(0, ['This is a test. With some sentences!', '', 'Even with a question? And one more. And no sentence here'])
1390
1391 $
1392 norm! d(
1393 call assert_equal(['This is a test. With some sentences!', '', 'Even with a question? And one more. ', ''], getline(1, '$'))
1394 norm! 2d(
1395 call assert_equal(['This is a test. With some sentences!', '', ' ', ''], getline(1, '$'))
1396 1
1397 norm! 0d)
1398 call assert_equal(['With some sentences!', '', ' ', ''], getline(1, '$'))
1399
1400 call append('$', ['This is a long sentence', '', 'spanning', 'over several lines. '])
1401 $
1402 norm! $d(
1403 call assert_equal(['With some sentences!', '', ' ', '', 'This is a long sentence', ''], getline(1, '$'))
1404
1405 " clean up
1406 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02001407endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001408
1409fun! Test_normal29_brace()
1410 " basic test for { and } movements
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001411 let text =<< trim [DATA]
Bram Moolenaare7eb9272019-06-24 00:58:07 +02001412 A paragraph begins after each empty line, and also at each of a set of
1413 paragraph macros, specified by the pairs of characters in the 'paragraphs'
1414 option. The default is "IPLPPPQPP TPHPLIPpLpItpplpipbp", which corresponds to
1415 the macros ".IP", ".LP", etc. (These are nroff macros, so the dot must be in
1416 the first column). A section boundary is also a paragraph boundary.
1417 Note that a blank line (only containing white space) is NOT a paragraph
1418 boundary.
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001419
1420
Bram Moolenaare7eb9272019-06-24 00:58:07 +02001421 Also note that this does not include a '{' or '}' in the first column. When
1422 the '{' flag is in 'cpoptions' then '{' in the first column is used as a
1423 paragraph boundary |posix|.
1424 {
1425 This is no paragraph
1426 unless the '{' is set
1427 in 'cpoptions'
1428 }
1429 .IP
1430 The nroff macros IP separates a paragraph
1431 That means, it must be a '.'
1432 followed by IP
1433 .LPIt does not matter, if afterwards some
1434 more characters follow.
1435 .SHAlso section boundaries from the nroff
1436 macros terminate a paragraph. That means
1437 a character like this:
1438 .NH
1439 End of text here
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001440 [DATA]
1441
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001442 new
1443 call append(0, text)
1444 1
1445 norm! 0d2}
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001446
1447 let expected =<< trim [DATA]
Bram Moolenaare7eb9272019-06-24 00:58:07 +02001448 .IP
1449 The nroff macros IP separates a paragraph
1450 That means, it must be a '.'
1451 followed by IP
1452 .LPIt does not matter, if afterwards some
1453 more characters follow.
1454 .SHAlso section boundaries from the nroff
1455 macros terminate a paragraph. That means
1456 a character like this:
1457 .NH
1458 End of text here
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001459
1460 [DATA]
1461 call assert_equal(expected, getline(1, '$'))
1462
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001463 norm! 0d}
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001464
1465 let expected =<< trim [DATA]
Bram Moolenaare7eb9272019-06-24 00:58:07 +02001466 .LPIt does not matter, if afterwards some
1467 more characters follow.
1468 .SHAlso section boundaries from the nroff
1469 macros terminate a paragraph. That means
1470 a character like this:
1471 .NH
1472 End of text here
1473
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001474 [DATA]
1475 call assert_equal(expected, getline(1, '$'))
1476
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001477 $
1478 norm! d{
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001479
1480 let expected =<< trim [DATA]
Bram Moolenaare7eb9272019-06-24 00:58:07 +02001481 .LPIt does not matter, if afterwards some
1482 more characters follow.
1483 .SHAlso section boundaries from the nroff
1484 macros terminate a paragraph. That means
1485 a character like this:
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001486
1487 [DATA]
1488 call assert_equal(expected, getline(1, '$'))
1489
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001490 norm! d{
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001491
1492 let expected =<< trim [DATA]
Bram Moolenaare7eb9272019-06-24 00:58:07 +02001493 .LPIt does not matter, if afterwards some
1494 more characters follow.
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001495
1496 [DATA]
1497 call assert_equal(expected, getline(1, '$'))
1498
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001499 " Test with { in cpooptions
1500 %d
1501 call append(0, text)
1502 set cpo+={
1503 1
1504 norm! 0d2}
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001505
1506 let expected =<< trim [DATA]
Bram Moolenaare7eb9272019-06-24 00:58:07 +02001507 {
1508 This is no paragraph
1509 unless the '{' is set
1510 in 'cpoptions'
1511 }
1512 .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 $
1528 norm! d}
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001529
1530 let expected =<< trim [DATA]
Bram Moolenaare7eb9272019-06-24 00:58:07 +02001531 {
1532 This is no paragraph
1533 unless the '{' is set
1534 in 'cpoptions'
1535 }
1536 .IP
1537 The nroff macros IP separates a paragraph
1538 That means, it must be a '.'
1539 followed by IP
1540 .LPIt does not matter, if afterwards some
1541 more characters follow.
1542 .SHAlso section boundaries from the nroff
1543 macros terminate a paragraph. That means
1544 a character like this:
1545 .NH
1546 End of text here
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001547
1548 [DATA]
1549 call assert_equal(expected, getline(1, '$'))
1550
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001551 norm! gg}
1552 norm! d5}
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001553
1554 let expected =<< trim [DATA]
Bram Moolenaare7eb9272019-06-24 00:58:07 +02001555 {
1556 This is no paragraph
1557 unless the '{' is set
1558 in 'cpoptions'
1559 }
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001560
1561 [DATA]
1562 call assert_equal(expected, getline(1, '$'))
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001563
1564 " clean up
1565 set cpo-={
1566 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02001567endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001568
1569fun! Test_normal30_changecase()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001570 new
1571 call append(0, 'This is a simple test: äüöß')
1572 norm! 1ggVu
1573 call assert_equal('this is a simple test: äüöß', getline('.'))
1574 norm! VU
1575 call assert_equal('THIS IS A SIMPLE TEST: ÄÜÖSS', getline('.'))
1576 norm! guu
1577 call assert_equal('this is a simple test: äüöss', getline('.'))
1578 norm! gUgU
1579 call assert_equal('THIS IS A SIMPLE TEST: ÄÜÖSS', getline('.'))
1580 norm! gugu
1581 call assert_equal('this is a simple test: äüöss', getline('.'))
1582 norm! gUU
1583 call assert_equal('THIS IS A SIMPLE TEST: ÄÜÖSS', getline('.'))
1584 norm! 010~
1585 call assert_equal('this is a SIMPLE TEST: ÄÜÖSS', getline('.'))
1586 norm! V~
1587 call assert_equal('THIS IS A simple test: äüöss', getline('.'))
1588
Bram Moolenaarf1c118b2018-09-03 22:08:10 +02001589 " Turkish ASCII turns to multi-byte. On some systems Turkish locale
1590 " is available but toupper()/tolower() don't do the right thing.
1591 try
1592 lang tr_TR.UTF-8
1593 set casemap=
1594 let iupper = toupper('i')
1595 if iupper == "\u0130"
Bram Moolenaar9f4de1f2017-04-08 19:39:43 +02001596 call setline(1, 'iI')
1597 1normal gUU
1598 call assert_equal("\u0130I", getline(1))
1599 call assert_equal("\u0130I", toupper("iI"))
Bram Moolenaar3317d5e2017-04-08 19:12:06 +02001600
Bram Moolenaar9f4de1f2017-04-08 19:39:43 +02001601 call setline(1, 'iI')
1602 1normal guu
1603 call assert_equal("i\u0131", getline(1))
1604 call assert_equal("i\u0131", tolower("iI"))
Bram Moolenaarf1c118b2018-09-03 22:08:10 +02001605 elseif iupper == "I"
Bram Moolenaar1cc48202017-04-09 13:41:59 +02001606 call setline(1, 'iI')
1607 1normal gUU
1608 call assert_equal("II", getline(1))
1609 call assert_equal("II", toupper("iI"))
1610
1611 call setline(1, 'iI')
1612 1normal guu
1613 call assert_equal("ii", getline(1))
1614 call assert_equal("ii", tolower("iI"))
Bram Moolenaarf1c118b2018-09-03 22:08:10 +02001615 else
1616 call assert_true(false, "expected toupper('i') to be either 'I' or '\u0130'")
1617 endif
1618 set casemap&
1619 call setline(1, 'iI')
1620 1normal gUU
1621 call assert_equal("II", getline(1))
1622 call assert_equal("II", toupper("iI"))
Bram Moolenaar1cc48202017-04-09 13:41:59 +02001623
Bram Moolenaarf1c118b2018-09-03 22:08:10 +02001624 call setline(1, 'iI')
1625 1normal guu
1626 call assert_equal("ii", getline(1))
1627 call assert_equal("ii", tolower("iI"))
1628
1629 lang en_US.UTF-8
1630 catch /E197:/
1631 " can't use Turkish locale
1632 throw 'Skipped: Turkish locale not available'
1633 endtry
Bram Moolenaar3317d5e2017-04-08 19:12:06 +02001634
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01001635 call setline(1, ['aaaaaa', 'aaaaaa'])
1636 normal! gg10~
1637 call assert_equal(['AAAAAA', 'aaaaaa'], getline(1, 2))
1638 set whichwrap+=~
1639 normal! gg10~
1640 call assert_equal(['aaaaaa', 'AAAAaa'], getline(1, 2))
1641 set whichwrap&
1642
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001643 " clean up
1644 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02001645endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001646
1647fun! Test_normal31_r_cmd()
1648 " Test for r command
1649 new
1650 call append(0, 'This is a simple test: abcd')
1651 exe "norm! 1gg$r\<cr>"
1652 call assert_equal(['This is a simple test: abc', '', ''], getline(1,'$'))
1653 exe "norm! 1gg2wlr\<cr>"
1654 call assert_equal(['This is a', 'simple test: abc', '', ''], getline(1,'$'))
1655 exe "norm! 2gg0W5r\<cr>"
1656 call assert_equal(['This is a', 'simple ', ' abc', '', ''], getline('1', '$'))
1657 set autoindent
1658 call setline(2, ['simple test: abc', ''])
1659 exe "norm! 2gg0W5r\<cr>"
1660 call assert_equal(['This is a', 'simple ', 'abc', '', '', ''], getline('1', '$'))
1661 exe "norm! 1ggVr\<cr>"
1662 call assert_equal('^M^M^M^M^M^M^M^M^M', strtrans(getline(1)))
1663 call setline(1, 'This is a')
1664 exe "norm! 1gg05rf"
1665 call assert_equal('fffffis a', getline(1))
1666
1667 " clean up
1668 set noautoindent
1669 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02001670endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001671
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01001672" Test for g*, g#
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01001673func Test_normal32_g_cmd1()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001674 new
1675 call append(0, ['abc.x_foo', 'x_foobar.abc'])
1676 1
1677 norm! $g*
1678 call assert_equal('x_foo', @/)
1679 call assert_equal('x_foobar.abc', getline('.'))
1680 norm! $g#
1681 call assert_equal('abc', @/)
1682 call assert_equal('abc.x_foo', getline('.'))
1683
1684 " clean up
1685 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02001686endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001687
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01001688" Test for g`, g;, g,, g&, gv, gk, gj, gJ, g0, g^, g_, gm, g$, gM, g CTRL-G,
1689" gi and gI commands
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001690fun! Test_normal33_g_cmd2()
1691 if !has("jumplist")
1692 return
1693 endif
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001694 call Setup_NewWindow()
1695 " Test for g`
1696 clearjumps
1697 norm! ma10j
1698 let a=execute(':jumps')
1699 " empty jumplist
1700 call assert_equal('>', a[-1:])
1701 norm! g`a
1702 call assert_equal('>', a[-1:])
1703 call assert_equal(1, line('.'))
1704 call assert_equal('1', getline('.'))
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01001705 call cursor(10, 1)
1706 norm! g'a
1707 call assert_equal('>', a[-1:])
1708 call assert_equal(1, line('.'))
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001709
1710 " Test for g; and g,
1711 norm! g;
1712 " there is only one change in the changelist
1713 " currently, when we setup the window
1714 call assert_equal(2, line('.'))
1715 call assert_fails(':norm! g;', 'E662')
1716 call assert_fails(':norm! g,', 'E663')
1717 let &ul=&ul
1718 call append('$', ['a', 'b', 'c', 'd'])
1719 let &ul=&ul
1720 call append('$', ['Z', 'Y', 'X', 'W'])
1721 let a = execute(':changes')
1722 call assert_match('2\s\+0\s\+2', a)
1723 call assert_match('101\s\+0\s\+a', a)
1724 call assert_match('105\s\+0\s\+Z', a)
1725 norm! 3g;
1726 call assert_equal(2, line('.'))
1727 norm! 2g,
1728 call assert_equal(105, line('.'))
1729
1730 " Test for g& - global substitute
1731 %d
1732 call setline(1, range(1,10))
1733 call append('$', ['a', 'b', 'c', 'd'])
1734 $s/\w/&&/g
1735 exe "norm! /[1-8]\<cr>"
1736 norm! g&
1737 call assert_equal(['11', '22', '33', '44', '55', '66', '77', '88', '9', '110', 'a', 'b', 'c', 'dd'], getline(1, '$'))
1738
1739 " Test for gv
1740 %d
1741 call append('$', repeat(['abcdefgh'], 8))
1742 exe "norm! 2gg02l\<c-v>2j2ly"
1743 call assert_equal(['cde', 'cde', 'cde'], getreg(0, 1, 1))
1744 " in visual mode, gv swaps current and last selected region
1745 exe "norm! G0\<c-v>4k4lgvd"
1746 call assert_equal(['', 'abfgh', 'abfgh', 'abfgh', 'abcdefgh', 'abcdefgh', 'abcdefgh', 'abcdefgh', 'abcdefgh'], getline(1,'$'))
1747 exe "norm! G0\<c-v>4k4ly"
1748 exe "norm! gvood"
1749 call assert_equal(['', 'abfgh', 'abfgh', 'abfgh', 'fgh', 'fgh', 'fgh', 'fgh', 'fgh'], getline(1,'$'))
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01001750 " gv cannot be used in operator pending mode
1751 call assert_beeps('normal! cgv')
1752 " gv should beep without a previously selected visual area
1753 new
1754 call assert_beeps('normal! gv')
1755 close
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001756
1757 " Test for gk/gj
1758 %d
1759 15vsp
1760 set wrap listchars= sbr=
1761 let lineA='abcdefghijklmnopqrstuvwxyz'
1762 let lineB='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'
Bram Moolenaar8b530c12019-10-28 02:13:05 +01001763 let lineC='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz01234567890123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001764 $put =lineA
1765 $put =lineB
1766
1767 norm! 3gg0dgk
1768 call assert_equal(['', 'abcdefghijklmno', '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'], getline(1, '$'))
1769 set nu
1770 norm! 3gg0gjdgj
1771 call assert_equal(['', 'abcdefghijklmno', '0123456789AMNOPQRSTUVWXYZ'], getline(1,'$'))
1772
1773 " Test for gJ
1774 norm! 2gggJ
1775 call assert_equal(['', 'abcdefghijklmno0123456789AMNOPQRSTUVWXYZ'], getline(1,'$'))
1776 call assert_equal(16, col('.'))
1777 " shouldn't do anything
1778 norm! 10gJ
1779 call assert_equal(1, col('.'))
1780
1781 " Test for g0 g^ gm g$
1782 exe "norm! 2gg0gji "
1783 call assert_equal(['', 'abcdefghijk lmno0123456789AMNOPQRSTUVWXYZ'], getline(1,'$'))
1784 norm! g0yl
1785 call assert_equal(12, col('.'))
1786 call assert_equal(' ', getreg(0))
1787 norm! g$yl
1788 call assert_equal(22, col('.'))
1789 call assert_equal('3', getreg(0))
1790 norm! gmyl
1791 call assert_equal(17, col('.'))
1792 call assert_equal('n', getreg(0))
1793 norm! g^yl
1794 call assert_equal(15, col('.'))
1795 call assert_equal('l', getreg(0))
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01001796 call assert_beeps('normal 5g$')
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001797
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01001798 " Test for g_
1799 call assert_beeps('normal! 100g_')
1800 call setline(2, [' foo ', ' foobar '])
1801 normal! 2ggg_
1802 call assert_equal(5, col('.'))
1803 normal! 2g_
1804 call assert_equal(8, col('.'))
1805
1806 norm! 2ggdG
Bram Moolenaar8b530c12019-10-28 02:13:05 +01001807 $put =lineC
1808
1809 " Test for gM
1810 norm! gMyl
1811 call assert_equal(73, col('.'))
1812 call assert_equal('0', getreg(0))
1813 " Test for 20gM
1814 norm! 20gMyl
1815 call assert_equal(29, col('.'))
1816 call assert_equal('S', getreg(0))
1817 " Test for 60gM
1818 norm! 60gMyl
1819 call assert_equal(87, col('.'))
1820 call assert_equal('E', getreg(0))
1821
1822 " Test for g Ctrl-G
1823 set ff=unix
1824 let a=execute(":norm! g\<c-g>")
1825 call assert_match('Col 87 of 144; Line 2 of 2; Word 1 of 1; Byte 88 of 146', a)
1826
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001827 " Test for gI
1828 norm! gIfoo
Bram Moolenaar8b530c12019-10-28 02:13:05 +01001829 call assert_equal(['', 'foo0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz01234567890123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'], getline(1,'$'))
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001830
1831 " Test for gi
1832 wincmd c
1833 %d
1834 set tw=0
1835 call setline(1, ['foobar', 'new line'])
1836 norm! A next word
1837 $put ='third line'
1838 norm! gi another word
1839 call assert_equal(['foobar next word another word', 'new line', 'third line'], getline(1,'$'))
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01001840 call setline(1, 'foobar')
1841 normal! Ggifirst line
1842 call assert_equal('foobarfirst line', getline(1))
1843 " Test gi in 'virtualedit' mode with cursor after the end of the line
1844 set virtualedit=all
1845 call setline(1, 'foo')
1846 exe "normal! Abar\<Right>\<Right>\<Right>\<Right>"
1847 call setline(1, 'foo')
1848 normal! Ggifirst line
1849 call assert_equal('foo first line', getline(1))
1850 set virtualedit&
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001851
1852 " clean up
1853 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02001854endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001855
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01001856" Test for g CTRL-G
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01001857func Test_g_ctrl_g()
Bram Moolenaar05295832018-08-24 22:07:58 +02001858 new
1859
1860 let a = execute(":norm! g\<c-g>")
1861 call assert_equal("\n--No lines in buffer--", a)
1862
1863 call setline(1, ['first line', 'second line'])
1864
1865 " Test g CTRL-g with dos, mac and unix file type.
1866 norm! gojll
1867 set ff=dos
1868 let a = execute(":norm! g\<c-g>")
1869 call assert_equal("\nCol 3 of 11; Line 2 of 2; Word 3 of 4; Byte 15 of 25", a)
1870
1871 set ff=mac
1872 let a = execute(":norm! g\<c-g>")
1873 call assert_equal("\nCol 3 of 11; Line 2 of 2; Word 3 of 4; Byte 14 of 23", a)
1874
1875 set ff=unix
1876 let a = execute(":norm! g\<c-g>")
1877 call assert_equal("\nCol 3 of 11; Line 2 of 2; Word 3 of 4; Byte 14 of 23", a)
1878
1879 " Test g CTRL-g in visual mode (v)
1880 let a = execute(":norm! gojllvlg\<c-g>")
1881 call assert_equal("\nSelected 1 of 2 Lines; 1 of 4 Words; 2 of 23 Bytes", a)
1882
1883 " Test g CTRL-g in visual mode (CTRL-V) with end col > start col
1884 let a = execute(":norm! \<Esc>gojll\<C-V>kllg\<c-g>")
1885 call assert_equal("\nSelected 3 Cols; 2 of 2 Lines; 2 of 4 Words; 6 of 23 Bytes", a)
1886
1887 " Test g_CTRL-g in visual mode (CTRL-V) with end col < start col
1888 let a = execute(":norm! \<Esc>goll\<C-V>jhhg\<c-g>")
1889 call assert_equal("\nSelected 3 Cols; 2 of 2 Lines; 2 of 4 Words; 6 of 23 Bytes", a)
1890
1891 " Test g CTRL-g in visual mode (CTRL-V) with end_vcol being MAXCOL
1892 let a = execute(":norm! \<Esc>gojll\<C-V>k$g\<c-g>")
1893 call assert_equal("\nSelected 2 of 2 Lines; 4 of 4 Words; 17 of 23 Bytes", a)
1894
1895 " There should be one byte less with noeol
1896 set bin noeol
1897 let a = execute(":norm! \<Esc>gog\<c-g>")
1898 call assert_equal("\nCol 1 of 10; Line 1 of 2; Word 1 of 4; Char 1 of 23; Byte 1 of 22", a)
1899 set bin & eol&
1900
Bram Moolenaar30276f22019-01-24 17:59:39 +01001901 call setline(1, ['Français', '日本語'])
Bram Moolenaar05295832018-08-24 22:07:58 +02001902
Bram Moolenaar30276f22019-01-24 17:59:39 +01001903 let a = execute(":norm! \<Esc>gojlg\<c-g>")
1904 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 +02001905
Bram Moolenaar30276f22019-01-24 17:59:39 +01001906 let a = execute(":norm! \<Esc>gojvlg\<c-g>")
1907 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 +02001908
Bram Moolenaar30276f22019-01-24 17:59:39 +01001909 let a = execute(":norm! \<Esc>goll\<c-v>jlg\<c-g>")
1910 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 +02001911
Bram Moolenaar30276f22019-01-24 17:59:39 +01001912 set fenc=utf8 bomb
1913 let a = execute(":norm! \<Esc>gojlg\<c-g>")
1914 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 +02001915
Bram Moolenaar30276f22019-01-24 17:59:39 +01001916 set fenc=utf16 bomb
1917 let a = execute(":norm! g\<c-g>")
1918 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 +02001919
Bram Moolenaar30276f22019-01-24 17:59:39 +01001920 set fenc=utf32 bomb
1921 let a = execute(":norm! g\<c-g>")
1922 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 +02001923
Bram Moolenaar30276f22019-01-24 17:59:39 +01001924 set fenc& bomb&
Bram Moolenaar05295832018-08-24 22:07:58 +02001925
1926 set ff&
1927 bwipe!
1928endfunc
1929
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01001930" Test for g8
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001931fun! Test_normal34_g_cmd3()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001932 new
Bram Moolenaar395b6ba2017-04-07 20:09:51 +02001933 let a=execute(':norm! 1G0g8')
1934 call assert_equal("\nNUL", a)
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001935
Bram Moolenaar395b6ba2017-04-07 20:09:51 +02001936 call setline(1, 'abcdefghijklmnopqrstuvwxyzäüö')
1937 let a=execute(':norm! 1G$g8')
1938 call assert_equal("\nc3 b6 ", a)
1939
1940 call setline(1, "a\u0302")
1941 let a=execute(':norm! 1G0g8')
1942 call assert_equal("\n61 + cc 82 ", a)
1943
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001944 " clean up
1945 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02001946endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001947
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01001948" Test 8g8 which finds invalid utf8 at or after the cursor.
Bram Moolenaar395b6ba2017-04-07 20:09:51 +02001949func Test_normal_8g8()
Bram Moolenaar395b6ba2017-04-07 20:09:51 +02001950 new
1951
Bram Moolenaar395b6ba2017-04-07 20:09:51 +02001952 " With invalid byte.
1953 call setline(1, "___\xff___")
1954 norm! 1G08g8g
1955 call assert_equal([0, 1, 4, 0, 1], getcurpos())
1956
1957 " With invalid byte before the cursor.
1958 call setline(1, "___\xff___")
1959 norm! 1G$h8g8g
1960 call assert_equal([0, 1, 6, 0, 9], getcurpos())
1961
1962 " With truncated sequence.
1963 call setline(1, "___\xE2\x82___")
1964 norm! 1G08g8g
1965 call assert_equal([0, 1, 4, 0, 1], getcurpos())
1966
1967 " With overlong sequence.
1968 call setline(1, "___\xF0\x82\x82\xAC___")
1969 norm! 1G08g8g
1970 call assert_equal([0, 1, 4, 0, 1], getcurpos())
1971
1972 " With valid utf8.
1973 call setline(1, "café")
1974 norm! 1G08g8
1975 call assert_equal([0, 1, 1, 0, 1], getcurpos())
1976
1977 bw!
1978endfunc
1979
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01001980" Test for g<
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001981fun! Test_normal35_g_cmd4()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001982 " Cannot capture its output,
1983 " probably a bug, therefore, test disabled:
Bram Moolenaar31845092016-09-05 22:58:31 +02001984 throw "Skipped: output of g< can't be tested currently"
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001985 echo "a\nb\nc\nd"
1986 let b=execute(':norm! g<')
1987 call assert_true(!empty(b), 'failed `execute(g<)`')
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02001988endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001989
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01001990" Test for gp gP go
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001991fun! Test_normal36_g_cmd5()
1992 new
1993 call append(0, 'abcdefghijklmnopqrstuvwxyz')
Bram Moolenaar0913a102016-09-03 19:11:59 +02001994 set ff=unix
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001995 " Test for gp gP
1996 call append(1, range(1,10))
1997 1
1998 norm! 1yy
1999 3
2000 norm! gp
2001 call assert_equal([0, 5, 1, 0, 1], getcurpos())
2002 $
2003 norm! gP
2004 call assert_equal([0, 14, 1, 0, 1], getcurpos())
2005
2006 " Test for go
2007 norm! 26go
2008 call assert_equal([0, 1, 26, 0, 26], getcurpos())
2009 norm! 27go
2010 call assert_equal([0, 1, 26, 0, 26], getcurpos())
2011 norm! 28go
2012 call assert_equal([0, 2, 1, 0, 1], getcurpos())
2013 set ff=dos
2014 norm! 29go
2015 call assert_equal([0, 2, 1, 0, 1], getcurpos())
2016 set ff=unix
2017 norm! gg0
2018 norm! 101go
2019 call assert_equal([0, 13, 26, 0, 26], getcurpos())
2020 norm! 103go
2021 call assert_equal([0, 14, 1, 0, 1], getcurpos())
2022 " count > buffer content
2023 norm! 120go
2024 call assert_equal([0, 14, 1, 0, 2147483647], getcurpos())
2025 " clean up
2026 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002027endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002028
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01002029" Test for gt and gT
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002030fun! Test_normal37_g_cmd6()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002031 tabnew 1.txt
2032 tabnew 2.txt
2033 tabnew 3.txt
2034 norm! 1gt
2035 call assert_equal(1, tabpagenr())
2036 norm! 3gt
2037 call assert_equal(3, tabpagenr())
2038 norm! 1gT
2039 " count gT goes not to the absolute tabpagenumber
2040 " but, but goes to the count previous tabpagenumber
2041 call assert_equal(2, tabpagenr())
2042 " wrap around
2043 norm! 3gT
2044 call assert_equal(3, tabpagenr())
2045 " gt does not wrap around
2046 norm! 5gt
2047 call assert_equal(3, tabpagenr())
2048
2049 for i in range(3)
2050 tabclose
2051 endfor
2052 " clean up
Bram Moolenaarbc2b71d2020-02-17 21:33:30 +01002053 call assert_fails(':tabclose', 'E784:')
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002054endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002055
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01002056" Test for <Home> and <C-Home> key
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002057fun! Test_normal38_nvhome()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002058 new
2059 call setline(1, range(10))
2060 $
2061 setl et sw=2
2062 norm! V10>$
2063 " count is ignored
2064 exe "norm! 10\<home>"
2065 call assert_equal(1, col('.'))
2066 exe "norm! \<home>"
2067 call assert_equal([0, 10, 1, 0, 1], getcurpos())
2068 exe "norm! 5\<c-home>"
2069 call assert_equal([0, 5, 1, 0, 1], getcurpos())
2070 exe "norm! \<c-home>"
2071 call assert_equal([0, 1, 1, 0, 1], getcurpos())
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01002072 exe "norm! G\<c-kHome>"
2073 call assert_equal([0, 1, 1, 0, 1], getcurpos())
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002074
2075 " clean up
2076 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002077endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002078
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01002079" Test for cw cW ce
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002080fun! Test_normal39_cw()
2081 " Test for cw and cW on whitespace
2082 " and cpo+=w setting
2083 new
2084 set tw=0
2085 call append(0, 'here are some words')
2086 norm! 1gg0elcwZZZ
2087 call assert_equal('hereZZZare some words', getline('.'))
2088 norm! 1gg0elcWYYY
2089 call assert_equal('hereZZZareYYYsome words', getline('.'))
2090 set cpo+=w
2091 call setline(1, 'here are some words')
2092 norm! 1gg0elcwZZZ
2093 call assert_equal('hereZZZ are some words', getline('.'))
2094 norm! 1gg2elcWYYY
2095 call assert_equal('hereZZZ areYYY some words', getline('.'))
2096 set cpo-=w
2097 norm! 2gg0cwfoo
2098 call assert_equal('foo', getline('.'))
2099
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01002100 call setline(1, 'one; two')
2101 call cursor(1, 1)
2102 call feedkeys('cwvim', 'xt')
2103 call assert_equal('vim; two', getline(1))
2104 call feedkeys('0cWone', 'xt')
2105 call assert_equal('one two', getline(1))
2106 "When cursor is at the end of a word 'ce' will change until the end of the
2107 "next word, but 'cw' will change only one character
2108 call setline(1, 'one two')
2109 call feedkeys('0ecwce', 'xt')
2110 call assert_equal('once two', getline(1))
2111 call setline(1, 'one two')
2112 call feedkeys('0ecely', 'xt')
2113 call assert_equal('only', getline(1))
2114
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002115 " clean up
2116 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002117endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002118
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01002119" Test for CTRL-\ commands
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002120fun! Test_normal40_ctrl_bsl()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002121 new
2122 call append(0, 'here are some words')
2123 exe "norm! 1gg0a\<C-\>\<C-N>"
2124 call assert_equal('n', mode())
2125 call assert_equal(1, col('.'))
2126 call assert_equal('', visualmode())
2127 exe "norm! 1gg0viw\<C-\>\<C-N>"
2128 call assert_equal('n', mode())
2129 call assert_equal(4, col('.'))
2130 exe "norm! 1gg0a\<C-\>\<C-G>"
2131 call assert_equal('n', mode())
2132 call assert_equal(1, col('.'))
2133 "imap <buffer> , <c-\><c-n>
2134 set im
2135 exe ":norm! \<c-\>\<c-n>dw"
2136 set noim
2137 call assert_equal('are some words', getline(1))
2138 call assert_false(&insertmode)
2139
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 <c-r>=, <c-r><c-r>= and <c-r><c-o>= in insert mode
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002145fun! Test_normal41_insert_reg()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002146 new
2147 set sts=2 sw=2 ts=8 tw=0
2148 call append(0, ["aaa\tbbb\tccc", '', '', ''])
2149 let a=getline(1)
2150 norm! 2gg0
2151 exe "norm! a\<c-r>=a\<cr>"
2152 norm! 3gg0
2153 exe "norm! a\<c-r>\<c-r>=a\<cr>"
2154 norm! 4gg0
2155 exe "norm! a\<c-r>\<c-o>=a\<cr>"
2156 call assert_equal(['aaa bbb ccc', 'aaa bbb ccc', 'aaa bbb ccc', 'aaa bbb ccc', ''], getline(1, '$'))
2157
2158 " clean up
2159 set sts=0 sw=8 ts=8
Bram Moolenaar31845092016-09-05 22:58:31 +02002160 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002161endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002162
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01002163" Test for Ctrl-D and Ctrl-U
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01002164func Test_normal42_halfpage()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002165 call Setup_NewWindow()
2166 call assert_equal(5, &scroll)
2167 exe "norm! \<c-d>"
2168 call assert_equal('6', getline('.'))
2169 exe "norm! 2\<c-d>"
2170 call assert_equal('8', getline('.'))
2171 call assert_equal(2, &scroll)
2172 set scroll=5
2173 exe "norm! \<c-u>"
2174 call assert_equal('3', getline('.'))
2175 1
2176 set scrolloff=5
2177 exe "norm! \<c-d>"
2178 call assert_equal('10', getline('.'))
2179 exe "norm! \<c-u>"
2180 call assert_equal('5', getline('.'))
2181 1
2182 set scrolloff=99
2183 exe "norm! \<c-d>"
2184 call assert_equal('10', getline('.'))
2185 set scrolloff=0
2186 100
2187 exe "norm! $\<c-u>"
2188 call assert_equal('95', getline('.'))
2189 call assert_equal([0, 95, 1, 0, 1], getcurpos())
2190 100
2191 set nostartofline
2192 exe "norm! $\<c-u>"
2193 call assert_equal('95', getline('.'))
2194 call assert_equal([0, 95, 2, 0, 2147483647], getcurpos())
2195 " cleanup
2196 set startofline
2197 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002198endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002199
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01002200" Tests for text object aw
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002201fun! Test_normal43_textobject1()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002202 new
2203 call append(0, ['foobar,eins,foobar', 'foo,zwei,foo '])
2204 " diw
2205 norm! 1gg0diw
2206 call assert_equal([',eins,foobar', 'foo,zwei,foo ', ''], getline(1,'$'))
2207 " daw
2208 norm! 2ggEdaw
2209 call assert_equal([',eins,foobar', 'foo,zwei,', ''], getline(1, '$'))
2210 %d
2211 call append(0, ["foo\teins\tfoobar", "foo\tzwei\tfoo "])
2212 " diW
2213 norm! 2ggwd2iW
2214 call assert_equal(['foo eins foobar', 'foo foo ', ''], getline(1,'$'))
2215 " daW
2216 norm! 1ggd2aW
2217 call assert_equal(['foobar', 'foo foo ', ''], getline(1,'$'))
2218
2219 %d
2220 call append(0, ["foo\teins\tfoobar", "foo\tzwei\tfoo "])
2221 " aw in visual line mode switches to characterwise mode
2222 norm! 2gg$Vawd
2223 call assert_equal(['foo eins foobar', 'foo zwei foo'], getline(1,'$'))
2224 norm! 1gg$Viwd
2225 call assert_equal(['foo eins ', 'foo zwei foo'], getline(1,'$'))
2226
2227 " clean up
2228 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002229endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002230
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01002231" Test for is and as text objects
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01002232func Test_normal44_textobjects2()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002233 new
2234 call append(0, ['This is a test. With some sentences!', '', 'Even with a question? And one more. And no sentence here'])
2235 " Test for dis - does not remove trailing whitespace
2236 norm! 1gg0dis
2237 call assert_equal([' With some sentences!', '', 'Even with a question? And one more. And no sentence here', ''], getline(1,'$'))
2238 " Test for das - removes leading whitespace
2239 norm! 3ggf?ldas
2240 call assert_equal([' With some sentences!', '', 'Even with a question? And no sentence here', ''], getline(1,'$'))
2241 " when used in visual mode, is made characterwise
2242 norm! 3gg$Visy
2243 call assert_equal('v', visualmode())
2244 " reset visualmode()
2245 norm! 3ggVy
2246 norm! 3gg$Vasy
2247 call assert_equal('v', visualmode())
2248 " basic testing for textobjects a< and at
2249 %d
2250 call setline(1, ['<div> ','<a href="foobar" class="foo">xyz</a>',' </div>', ' '])
2251 " a<
2252 norm! 1gg0da<
2253 call assert_equal([' ', '<a href="foobar" class="foo">xyz</a>', ' </div>', ' '], getline(1,'$'))
2254 norm! 1pj
2255 call assert_equal([' <div>', '<a href="foobar" class="foo">xyz</a>', ' </div>', ' '], getline(1,'$'))
2256 " at
2257 norm! d2at
2258 call assert_equal([' '], getline(1,'$'))
2259 %d
2260 call setline(1, ['<div> ','<a href="foobar" class="foo">xyz</a>',' </div>', ' '])
2261 " i<
2262 norm! 1gg0di<
2263 call assert_equal(['<> ', '<a href="foobar" class="foo">xyz</a>', ' </div>', ' '], getline(1,'$'))
2264 norm! 1Pj
2265 call assert_equal(['<div> ', '<a href="foobar" class="foo">xyz</a>', ' </div>', ' '], getline(1,'$'))
2266 norm! d2it
2267 call assert_equal(['<div></div>',' '], getline(1,'$'))
2268 " basic testing for a[ and i[ text object
2269 %d
2270 call setline(1, [' ', '[', 'one [two]', 'thre', ']'])
2271 norm! 3gg0di[
2272 call assert_equal([' ', '[', ']'], getline(1,'$'))
2273 call setline(1, [' ', '[', 'one [two]', 'thre', ']'])
2274 norm! 3gg0ftd2a[
2275 call assert_equal([' '], getline(1,'$'))
2276 %d
2277 " Test for i" when cursor is in front of a quoted object
2278 call append(0, 'foo "bar"')
2279 norm! 1gg0di"
2280 call assert_equal(['foo ""', ''], getline(1,'$'))
2281
2282 " clean up
2283 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002284endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002285
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01002286func Test_normal45_drop()
Bram Moolenaar29495952018-02-12 22:49:00 +01002287 if !has('dnd')
Bram Moolenaarb48e96f2018-02-13 12:26:14 +01002288 " The ~ register does not exist
2289 call assert_beeps('norm! "~')
Bram Moolenaar29495952018-02-12 22:49:00 +01002290 return
2291 endif
2292
2293 " basic test for drag-n-drop
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002294 " unfortunately, without a gui, we can't really test much here,
2295 " so simply test that ~p fails (which uses the drop register)
2296 new
2297 call assert_fails(':norm! "~p', 'E353')
2298 call assert_equal([], getreg('~', 1, 1))
2299 " the ~ register is read only
2300 call assert_fails(':let @~="1"', 'E354')
2301 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002302endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002303
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01002304func Test_normal46_ignore()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002305 new
2306 " How to test this?
2307 " let's just for now test, that the buffer
2308 " does not change
2309 call feedkeys("\<c-s>", 't')
2310 call assert_equal([''], getline(1,'$'))
2311
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002312 " no valid commands
2313 exe "norm! \<char-0x100>"
2314 call assert_equal([''], getline(1,'$'))
2315
2316 exe "norm! ä"
2317 call assert_equal([''], getline(1,'$'))
2318
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002319 " clean up
2320 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002321endfunc
Bram Moolenaarc4a908e2016-09-08 23:35:30 +02002322
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01002323func Test_normal47_visual_buf_wipe()
Bram Moolenaarc4a908e2016-09-08 23:35:30 +02002324 " This was causing a crash or ml_get error.
2325 enew!
2326 call setline(1,'xxx')
2327 normal $
2328 new
2329 call setline(1, range(1,2))
2330 2
2331 exe "norm \<C-V>$"
2332 bw!
2333 norm yp
2334 set nomodified
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002335endfunc
2336
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01002337func Test_normal47_autocmd()
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002338 " disabled, does not seem to be possible currently
2339 throw "Skipped: not possible to test cursorhold autocmd while waiting for input in normal_cmd"
2340 new
2341 call append(0, repeat('-',20))
2342 au CursorHold * call feedkeys('2l', '')
2343 1
2344 set updatetime=20
2345 " should delete 12 chars (d12l)
2346 call feedkeys('d1', '!')
2347 call assert_equal('--------', getline(1))
2348
2349 " clean up
2350 au! CursorHold
2351 set updatetime=4000
2352 bw!
2353endfunc
2354
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01002355func Test_normal48_wincmd()
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002356 new
2357 exe "norm! \<c-w>c"
2358 call assert_equal(1, winnr('$'))
2359 call assert_fails(":norm! \<c-w>c", "E444")
2360endfunc
2361
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01002362func Test_normal49_counts()
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002363 new
2364 call setline(1, 'one two three four five six seven eight nine ten')
2365 1
2366 norm! 3d2w
2367 call assert_equal('seven eight nine ten', getline(1))
2368 bw!
2369endfunc
2370
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01002371func Test_normal50_commandline()
Bram Moolenaar4033c552017-09-16 20:54:51 +02002372 if !has("timers") || !has("cmdline_hist")
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002373 return
2374 endif
2375 func! DoTimerWork(id)
2376 call assert_equal('[Command Line]', bufname(''))
2377 " should fail, with E11, but does fail with E23?
2378 "call feedkeys("\<c-^>", 'tm')
2379
2380 " should also fail with E11
2381 call assert_fails(":wincmd p", 'E11')
2382 " return from commandline window
2383 call feedkeys("\<cr>")
2384 endfunc
2385
2386 let oldlang=v:lang
2387 lang C
2388 set updatetime=20
2389 call timer_start(100, 'DoTimerWork')
2390 try
2391 " throws E23, for whatever reason...
2392 call feedkeys('q:', 'x!')
2393 catch /E23/
2394 " no-op
2395 endtry
2396 " clean up
2397 set updatetime=4000
2398 exe "lang" oldlang
2399 bw!
2400endfunc
2401
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01002402func Test_normal51_FileChangedRO()
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002403 if !has("autocmd")
2404 return
2405 endif
Bram Moolenaare5f2a072017-02-01 22:31:49 +01002406 " Don't sleep after the warning message.
2407 call test_settime(1)
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002408 call writefile(['foo'], 'Xreadonly.log')
2409 new Xreadonly.log
2410 setl ro
2411 au FileChangedRO <buffer> :call feedkeys("\<c-^>", 'tix')
2412 call assert_fails(":norm! Af", 'E788')
2413 call assert_equal(['foo'], getline(1,'$'))
2414 call assert_equal('Xreadonly.log', bufname(''))
2415
2416 " cleanup
Bram Moolenaare5f2a072017-02-01 22:31:49 +01002417 call test_settime(0)
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002418 bw!
2419 call delete("Xreadonly.log")
2420endfunc
2421
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01002422func Test_normal52_rl()
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002423 if !has("rightleft")
2424 return
2425 endif
2426 new
2427 call setline(1, 'abcde fghij klmnopq')
2428 norm! 1gg$
2429 set rl
2430 call assert_equal(19, col('.'))
2431 call feedkeys('l', 'tx')
2432 call assert_equal(18, col('.'))
2433 call feedkeys('h', 'tx')
2434 call assert_equal(19, col('.'))
2435 call feedkeys("\<right>", 'tx')
2436 call assert_equal(18, col('.'))
2437 call feedkeys("\<s-right>", 'tx')
2438 call assert_equal(13, col('.'))
2439 call feedkeys("\<c-right>", 'tx')
2440 call assert_equal(7, col('.'))
2441 call feedkeys("\<c-left>", 'tx')
2442 call assert_equal(13, col('.'))
2443 call feedkeys("\<s-left>", 'tx')
2444 call assert_equal(19, col('.'))
2445 call feedkeys("<<", 'tx')
2446 call assert_equal(' abcde fghij klmnopq',getline(1))
2447 call feedkeys(">>", 'tx')
2448 call assert_equal('abcde fghij klmnopq',getline(1))
2449
2450 " cleanup
2451 set norl
2452 bw!
2453endfunc
2454
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01002455func Test_normal53_digraph()
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002456 if !has('digraphs')
2457 return
2458 endif
2459 new
2460 call setline(1, 'abcdefgh|')
2461 exe "norm! 1gg0f\<c-k>!!"
2462 call assert_equal(9, col('.'))
2463 set cpo+=D
2464 exe "norm! 1gg0f\<c-k>!!"
2465 call assert_equal(1, col('.'))
2466
2467 set cpo-=D
2468 bw!
2469endfunc
2470
Bram Moolenaarb1e04fc2017-03-29 13:08:35 +02002471func Test_normal54_Ctrl_bsl()
2472 new
2473 call setline(1, 'abcdefghijklmn')
2474 exe "norm! df\<c-\>\<c-n>"
2475 call assert_equal(['abcdefghijklmn'], getline(1,'$'))
2476 exe "norm! df\<c-\>\<c-g>"
2477 call assert_equal(['abcdefghijklmn'], getline(1,'$'))
2478 exe "norm! df\<c-\>m"
2479 call assert_equal(['abcdefghijklmn'], getline(1,'$'))
Bram Moolenaar30276f22019-01-24 17:59:39 +01002480
Bram Moolenaarb1e04fc2017-03-29 13:08:35 +02002481 call setline(2, 'abcdefghijklmnāf')
2482 norm! 2gg0
2483 exe "norm! df\<Char-0x101>"
2484 call assert_equal(['abcdefghijklmn', 'f'], getline(1,'$'))
2485 norm! 1gg0
2486 exe "norm! df\<esc>"
2487 call assert_equal(['abcdefghijklmn', 'f'], getline(1,'$'))
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002488
Bram Moolenaarb1e04fc2017-03-29 13:08:35 +02002489 " clean up
2490 bw!
2491endfunc
2492
2493func Test_normal_large_count()
2494 " This may fail with 32bit long, how do we detect that?
2495 new
2496 normal o
2497 normal 6666666666dL
2498 bwipe!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002499endfunc
Bram Moolenaarbf3d5802017-03-29 19:48:11 +02002500
2501func Test_delete_until_paragraph()
Bram Moolenaarbf3d5802017-03-29 19:48:11 +02002502 new
2503 normal grádv}
2504 call assert_equal('á', getline(1))
2505 normal grád}
2506 call assert_equal('', getline(1))
2507 bwipe!
2508endfunc
Bram Moolenaarfb094e12017-11-05 20:59:28 +01002509
2510" Test for the gr (virtual replace) command
2511" Test for the bug fixed by 7.4.387
2512func Test_gr_command()
2513 enew!
2514 let save_cpo = &cpo
2515 call append(0, ['First line', 'Second line', 'Third line'])
2516 exe "normal i\<C-G>u"
2517 call cursor(2, 1)
2518 set cpo-=X
2519 normal 4gro
2520 call assert_equal('oooond line', getline(2))
2521 undo
2522 set cpo+=X
2523 normal 4gro
2524 call assert_equal('ooooecond line', getline(2))
2525 let &cpo = save_cpo
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01002526 normal! ggvegrx
2527 call assert_equal('xxxxx line', getline(1))
2528 exe "normal! gggr\<C-V>122"
2529 call assert_equal('zxxxx line', getline(1))
2530 set virtualedit=all
2531 normal! 15|grl
2532 call assert_equal('zxxxx line l', getline(1))
2533 set virtualedit&
2534 set nomodifiable
2535 call assert_fails('normal! grx', 'E21:')
2536 call assert_fails('normal! gRx', 'E21:')
2537 set modifiable&
Bram Moolenaarfb094e12017-11-05 20:59:28 +01002538 enew!
2539endfunc
2540
2541" When splitting a window the changelist position is wrong.
2542" Test the changelist position after splitting a window.
2543" Test for the bug fixed by 7.4.386
2544func Test_changelist()
2545 let save_ul = &ul
2546 enew!
2547 call append('$', ['1', '2'])
2548 exe "normal i\<C-G>u"
2549 exe "normal Gkylpa\<C-G>u"
2550 set ul=100
2551 exe "normal Gylpa\<C-G>u"
2552 set ul=100
2553 normal gg
2554 vsplit
2555 normal g;
2556 call assert_equal([3, 2], [line('.'), col('.')])
2557 normal g;
2558 call assert_equal([2, 2], [line('.'), col('.')])
2559 call assert_fails('normal g;', 'E662:')
2560 %bwipe!
2561 let &ul = save_ul
2562endfunc
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01002563
2564func Test_nv_hat_count()
2565 %bwipeout!
2566 let l:nr = bufnr('%') + 1
2567 call assert_fails(':execute "normal! ' . l:nr . '\<C-^>"', 'E92')
2568
2569 edit Xfoo
2570 let l:foo_nr = bufnr('Xfoo')
2571
2572 edit Xbar
2573 let l:bar_nr = bufnr('Xbar')
2574
2575 " Make sure we are not just using the alternate file.
2576 edit Xbaz
2577
2578 call feedkeys(l:foo_nr . "\<C-^>", 'tx')
2579 call assert_equal('Xfoo', fnamemodify(bufname('%'), ':t'))
2580
2581 call feedkeys(l:bar_nr . "\<C-^>", 'tx')
2582 call assert_equal('Xbar', fnamemodify(bufname('%'), ':t'))
2583
2584 %bwipeout!
2585endfunc
Bram Moolenaara84a3dd2019-03-25 22:21:24 +01002586
2587func Test_message_when_using_ctrl_c()
Bram Moolenaar553e5a52019-03-25 23:16:34 +01002588 " Make sure no buffers are changed.
2589 %bwipe!
2590
Bram Moolenaara84a3dd2019-03-25 22:21:24 +01002591 exe "normal \<C-C>"
2592 call assert_match("Type :qa and press <Enter> to exit Vim", Screenline(&lines))
Bram Moolenaar553e5a52019-03-25 23:16:34 +01002593
Bram Moolenaara84a3dd2019-03-25 22:21:24 +01002594 new
2595 cal setline(1, 'hi!')
2596 exe "normal \<C-C>"
2597 call assert_match("Type :qa! and press <Enter> to abandon all changes and exit Vim", Screenline(&lines))
Bram Moolenaar553e5a52019-03-25 23:16:34 +01002598
Bram Moolenaara84a3dd2019-03-25 22:21:24 +01002599 bwipe!
2600endfunc
Bram Moolenaarc6b37db2019-04-27 18:00:34 +02002601
2602" Test for '[m', ']m', '[M' and ']M'
2603" Jumping to beginning and end of methods in Java-like languages
2604func Test_java_motion()
2605 new
2606 a
2607Piece of Java
2608{
2609 tt m1 {
2610 t1;
2611 } e1
2612
2613 tt m2 {
2614 t2;
2615 } e2
2616
2617 tt m3 {
2618 if (x)
2619 {
2620 t3;
2621 }
2622 } e3
2623}
2624.
2625
2626 normal gg
2627
2628 normal 2]maA
2629 call assert_equal("\ttt m1 {A", getline('.'))
2630 call assert_equal([3, 9, 16], [line('.'), col('.'), virtcol('.')])
2631
2632 normal j]maB
2633 call assert_equal("\ttt m2 {B", getline('.'))
2634 call assert_equal([7, 9, 16], [line('.'), col('.'), virtcol('.')])
2635
2636 normal ]maC
2637 call assert_equal("\ttt m3 {C", getline('.'))
2638 call assert_equal([11, 9, 16], [line('.'), col('.'), virtcol('.')])
2639
2640 normal [maD
2641 call assert_equal("\ttt m3 {DC", getline('.'))
2642 call assert_equal([11, 9, 16], [line('.'), col('.'), virtcol('.')])
2643
2644 normal k2[maE
2645 call assert_equal("\ttt m1 {EA", getline('.'))
2646 call assert_equal([3, 9, 16], [line('.'), col('.'), virtcol('.')])
2647
2648 normal 3[maF
2649 call assert_equal("{F", getline('.'))
2650 call assert_equal([2, 2, 2], [line('.'), col('.'), virtcol('.')])
2651
2652 normal ]MaG
2653 call assert_equal("\t}G e1", getline('.'))
2654 call assert_equal([5, 3, 10], [line('.'), col('.'), virtcol('.')])
2655
2656 normal j2]MaH
2657 call assert_equal("\t}H e3", getline('.'))
2658 call assert_equal([16, 3, 10], [line('.'), col('.'), virtcol('.')])
2659
2660 normal ]M]M
2661 normal aI
2662 call assert_equal("}I", getline('.'))
2663 call assert_equal([17, 2, 2], [line('.'), col('.'), virtcol('.')])
2664
2665 normal 2[MaJ
2666 call assert_equal("\t}JH e3", getline('.'))
2667 call assert_equal([16, 3, 10], [line('.'), col('.'), virtcol('.')])
2668
2669 normal k[MaK
2670 call assert_equal("\t}K e2", getline('.'))
2671 call assert_equal([9, 3, 10], [line('.'), col('.'), virtcol('.')])
2672
2673 normal 3[MaL
2674 call assert_equal("{LF", getline('.'))
2675 call assert_equal([2, 2, 2], [line('.'), col('.'), virtcol('.')])
2676
2677 close!
2678endfunc
Bram Moolenaard5c82342019-07-27 18:44:57 +02002679
2680fun! Test_normal_gdollar_cmd()
2681 if !has("jumplist")
2682 return
2683 endif
2684 " Tests for g cmds
2685 call Setup_NewWindow()
2686 " Make long lines that will wrap
2687 %s/$/\=repeat(' foobar', 10)/
2688 20vsp
2689 set wrap
2690 " Test for g$ with count
2691 norm! gg
2692 norm! 0vg$y
2693 call assert_equal(20, col("'>"))
2694 call assert_equal('1 foobar foobar foob', getreg(0))
2695 norm! gg
2696 norm! 0v4g$y
2697 call assert_equal(72, col("'>"))
2698 call assert_equal('1 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar'.."\n", getreg(0))
2699 norm! gg
2700 norm! 0v6g$y
2701 call assert_equal(40, col("'>"))
2702 call assert_equal('1 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar'.. "\n"..
2703 \ '2 foobar foobar foobar foobar foobar foo', getreg(0))
2704 set nowrap
2705 " clean up
2706 norm! gg
2707 norm! 0vg$y
2708 call assert_equal(20, col("'>"))
2709 call assert_equal('1 foobar foobar foob', getreg(0))
2710 norm! gg
2711 norm! 0v4g$y
2712 call assert_equal(20, col("'>"))
2713 call assert_equal('1 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar'.. "\n"..
2714 \ '2 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar'.. "\n"..
2715 \ '3 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar'.. "\n"..
2716 \ '4 foobar foobar foob', getreg(0))
2717 norm! gg
2718 norm! 0v6g$y
2719 call assert_equal(20, col("'>"))
2720 call assert_equal('1 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar'.. "\n"..
2721 \ '2 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar'.. "\n"..
2722 \ '3 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar'.. "\n"..
2723 \ '4 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar'.. "\n"..
2724 \ '5 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar'.. "\n"..
2725 \ '6 foobar foobar foob', getreg(0))
2726 " Move to last line, also down movement is not possible, should still move
2727 " the cursor to the last visible char
2728 norm! G
2729 norm! 0v6g$y
2730 call assert_equal(20, col("'>"))
2731 call assert_equal('100 foobar foobar fo', getreg(0))
2732 bw!
2733endfunc
Bram Moolenaar03ac52f2019-09-24 22:47:46 +02002734
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01002735func Test_normal_gk_gj()
Bram Moolenaar03ac52f2019-09-24 22:47:46 +02002736 " needs 80 column new window
2737 new
2738 vert 80new
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01002739 call assert_beeps('normal gk')
Bram Moolenaar03ac52f2019-09-24 22:47:46 +02002740 put =[repeat('x',90)..' {{{1', 'x {{{1']
2741 norm! gk
2742 " In a 80 column wide terminal the window will be only 78 char
2743 " (because Vim will leave space for the other window),
2744 " but if the terminal is larger, it will be 80 chars, so verify the
2745 " cursor column correctly.
2746 call assert_equal(winwidth(0)+1, col('.'))
2747 call assert_equal(winwidth(0)+1, virtcol('.'))
2748 norm! j
2749 call assert_equal(6, col('.'))
2750 call assert_equal(6, virtcol('.'))
2751 norm! gk
2752 call assert_equal(95, col('.'))
2753 call assert_equal(95, virtcol('.'))
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01002754 %bw!
Bram Moolenaarceba3dd2019-10-12 16:12:54 +02002755
2756 " needs 80 column new window
2757 new
2758 vert 80new
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01002759 call assert_beeps('normal gj')
Bram Moolenaarceba3dd2019-10-12 16:12:54 +02002760 set number
2761 set numberwidth=10
2762 set cpoptions+=n
2763 put =[repeat('0',90), repeat('1',90)]
2764 norm! 075l
2765 call assert_equal(76, col('.'))
2766 norm! gk
2767 call assert_equal(1, col('.'))
2768 norm! gk
2769 call assert_equal(76, col('.'))
2770 norm! gk
2771 call assert_equal(1, col('.'))
2772 norm! gj
2773 call assert_equal(76, col('.'))
2774 norm! gj
2775 call assert_equal(1, col('.'))
2776 norm! gj
2777 call assert_equal(76, col('.'))
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01002778 " When 'nowrap' is set, gk and gj behave like k and j
2779 set nowrap
2780 normal! gk
2781 call assert_equal([2, 76], [line('.'), col('.')])
2782 normal! gj
2783 call assert_equal([3, 76], [line('.'), col('.')])
2784 %bw!
2785 set cpoptions& number& numberwidth& wrap&
Bram Moolenaar03ac52f2019-09-24 22:47:46 +02002786endfunc
Bram Moolenaarf0cee192020-02-16 13:33:56 +01002787
2788" Test for cursor movement with '-' in 'cpoptions'
2789func Test_normal_cpo_minus()
2790 new
2791 call setline(1, ['foo', 'bar', 'baz'])
2792 let save_cpo = &cpo
2793 set cpo+=-
2794 call assert_beeps('normal 10j')
2795 call assert_equal(1, line('.'))
2796 normal G
2797 call assert_beeps('normal 10k')
2798 call assert_equal(3, line('.'))
2799 call assert_fails(10, 'E16:')
2800 let &cpo = save_cpo
2801 close!
2802endfunc
Bram Moolenaar818fc9a2020-02-21 17:54:45 +01002803
2804" Test for using : to run a multi-line Ex command in operator pending mode
2805func Test_normal_yank_with_excmd()
2806 new
2807 call setline(1, ['foo', 'bar', 'baz'])
2808 let @a = ''
2809 call feedkeys("\"ay:if v:true\<CR>normal l\<CR>endif\<CR>", 'xt')
2810 call assert_equal('f', @a)
2811 close!
2812endfunc
Bram Moolenaarf5f1e102020-03-08 05:13:15 +01002813
2814" Test for supplying a count to a normal-mode command across a cursorhold call
2815func Test_normal_cursorhold_with_count()
2816 func s:cHold()
2817 let g:cHold_Called += 1
2818 endfunc
2819 new
2820 augroup normalcHoldTest
2821 au!
2822 au CursorHold <buffer> call s:cHold()
2823 augroup END
2824 let g:cHold_Called = 0
2825 call feedkeys("3\<CursorHold>2ix", 'xt')
2826 call assert_equal(1, g:cHold_Called)
2827 call assert_equal(repeat('x', 32), getline(1))
2828 augroup normalcHoldTest
2829 au!
2830 augroup END
2831 au! normalcHoldTest
2832 close!
2833 delfunc s:cHold
2834endfunc
2835
2836" Test for using a count and a command with CTRL-W
2837func Test_wincmd_with_count()
2838 call feedkeys("\<C-W>12n", 'xt')
2839 call assert_equal(12, winheight(0))
2840endfunc
2841
2842" Test for 'b', 'B' 'ge' and 'gE' commands
2843func Test_backward_motion()
2844 normal! gg
2845 call assert_beeps('normal! b')
2846 call assert_beeps('normal! B')
2847 call assert_beeps('normal! gE')
2848 call assert_beeps('normal! ge')
2849endfunc
2850
2851" vim: shiftwidth=2 sts=2 expandtab