blob: 39c66f8fec19cdee7c3d7acd00cacb483eae12e3 [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
4
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01005func Setup_NewWindow()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02006 10new
7 call setline(1, range(1,100))
8endfunc
9
Bram Moolenaar1bbb6192018-11-10 16:02:01 +010010func MyFormatExpr()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +020011 " Adds '->$' at lines having numbers followed by trailing whitespace
12 for ln in range(v:lnum, v:lnum+v:count-1)
13 let line = getline(ln)
14 if getline(ln) =~# '\d\s\+$'
15 call setline(ln, substitute(line, '\s\+$', '', '') . '->$')
16 endif
17 endfor
Bram Moolenaar2931f2a2016-09-09 16:59:08 +020018endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +020019
Bram Moolenaar1bbb6192018-11-10 16:02:01 +010020func CountSpaces(type, ...)
Bram Moolenaar87bc3f72016-09-03 17:33:54 +020021 " for testing operatorfunc
22 " will count the number of spaces
23 " and return the result in g:a
24 let sel_save = &selection
25 let &selection = "inclusive"
26 let reg_save = @@
27
28 if a:0 " Invoked from Visual mode, use gv command.
29 silent exe "normal! gvy"
30 elseif a:type == 'line'
31 silent exe "normal! '[V']y"
32 else
33 silent exe "normal! `[v`]y"
34 endif
35 let g:a=strlen(substitute(@@, '[^ ]', '', 'g'))
36 let &selection = sel_save
37 let @@ = reg_save
Bram Moolenaar2931f2a2016-09-09 16:59:08 +020038endfunc
39
Bram Moolenaar1bbb6192018-11-10 16:02:01 +010040func OpfuncDummy(type, ...)
Bram Moolenaar4a08b0d2016-11-05 21:55:13 +010041 " for testing operatorfunc
42 let g:opt=&linebreak
43
44 if a:0 " Invoked from Visual mode, use gv command.
45 silent exe "normal! gvy"
46 elseif a:type == 'line'
47 silent exe "normal! '[V']y"
48 else
49 silent exe "normal! `[v`]y"
50 endif
51 " Create a new dummy window
52 new
53 let g:bufnr=bufnr('%')
Bram Moolenaar2931f2a2016-09-09 16:59:08 +020054endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +020055
56fun! Test_normal00_optrans()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +020057 new
58 call append(0, ['1 This is a simple test: abcd', '2 This is the second line', '3 this is the third line'])
59 1
60 exe "norm! Sfoobar\<esc>"
61 call assert_equal(['foobar', '2 This is the second line', '3 this is the third line', ''], getline(1,'$'))
62 2
Bram Moolenaar87bc3f72016-09-03 17:33:54 +020063 exe "norm! $vbsone"
64 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 +020065 norm! VS Second line here
66 call assert_equal(['foobar', ' Second line here', '3 this is the third line', ''], getline(1, '$'))
67 %d
68 call append(0, ['4 This is a simple test: abcd', '5 This is the second line', '6 this is the third line'])
69 call append(0, ['1 This is a simple test: abcd', '2 This is the second line', '3 this is the third line'])
70
71 1
72 norm! 2D
73 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,'$'))
74 set cpo+=#
75 norm! 4D
76 call assert_equal(['', '4 This is a simple test: abcd', '5 This is the second line', '6 this is the third line', ''], getline(1,'$'))
77
78 " clean up
79 set cpo-=#
80 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +020081endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +020082
Bram Moolenaar1bbb6192018-11-10 16:02:01 +010083func Test_normal01_keymodel()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +020084 call Setup_NewWindow()
85 " Test 1: depending on 'keymodel' <s-down> does something different
Bram Moolenaar2931f2a2016-09-09 16:59:08 +020086 50
Bram Moolenaar87bc3f72016-09-03 17:33:54 +020087 call feedkeys("V\<S-Up>y", 'tx')
88 call assert_equal(['47', '48', '49', '50'], getline("'<", "'>"))
Bram Moolenaar2931f2a2016-09-09 16:59:08 +020089 set keymodel=startsel
90 50
Bram Moolenaar87bc3f72016-09-03 17:33:54 +020091 call feedkeys("V\<S-Up>y", 'tx')
92 call assert_equal(['49', '50'], getline("'<", "'>"))
93 " Start visual mode when keymodel = startsel
Bram Moolenaar2931f2a2016-09-09 16:59:08 +020094 50
Bram Moolenaar87bc3f72016-09-03 17:33:54 +020095 call feedkeys("\<S-Up>y", 'tx')
96 call assert_equal(['49', '5'], getreg(0, 0, 1))
97 " Do not start visual mode when keymodel=
Bram Moolenaar2931f2a2016-09-09 16:59:08 +020098 set keymodel=
99 50
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200100 call feedkeys("\<S-Up>y$", 'tx')
101 call assert_equal(['42'], getreg(0, 0, 1))
Bram Moolenaar2931f2a2016-09-09 16:59:08 +0200102 " Stop visual mode when keymodel=stopsel
103 set keymodel=stopsel
104 50
105 call feedkeys("Vkk\<Up>yy", 'tx')
106 call assert_equal(['47'], getreg(0, 0, 1))
107
108 set keymodel=
109 50
110 call feedkeys("Vkk\<Up>yy", 'tx')
111 call assert_equal(['47', '48', '49', '50'], getreg(0, 0, 1))
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200112
113 " clean up
114 bw!
115endfunc
116
Bram Moolenaar1bbb6192018-11-10 16:02:01 +0100117func Test_normal02_selectmode()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200118 " some basic select mode tests
119 call Setup_NewWindow()
120 50
121 norm! gHy
122 call assert_equal('y51', getline('.'))
123 call setline(1, range(1,100))
124 50
125 exe ":norm! V9jo\<c-g>y"
126 call assert_equal('y60', getline('.'))
127 " clean up
128 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +0200129endfunc
130
Bram Moolenaar1bbb6192018-11-10 16:02:01 +0100131func Test_normal02_selectmode2()
Bram Moolenaar2931f2a2016-09-09 16:59:08 +0200132 " some basic select mode tests
133 call Setup_NewWindow()
134 50
135 call feedkeys(":set im\n\<c-o>gHc\<c-o>:set noim\n", 'tx')
136 call assert_equal('c51', getline('.'))
137 " clean up
138 bw!
139endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200140
Bram Moolenaar1bbb6192018-11-10 16:02:01 +0100141func Test_normal03_join()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200142 " basic join test
143 call Setup_NewWindow()
144 50
145 norm! VJ
146 call assert_equal('50 51', getline('.'))
147 $
148 norm! J
149 call assert_equal('100', getline('.'))
150 $
151 norm! V9-gJ
152 call assert_equal('919293949596979899100', getline('.'))
153 call setline(1, range(1,100))
154 $
155 :j 10
156 call assert_equal('100', getline('.'))
157 " clean up
158 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +0200159endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200160
Bram Moolenaar1bbb6192018-11-10 16:02:01 +0100161func Test_normal04_filter()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200162 " basic filter test
163 " only test on non windows platform
Bram Moolenaar4a08b0d2016-11-05 21:55:13 +0100164 if has('win32')
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200165 return
166 endif
167 call Setup_NewWindow()
168 1
169 call feedkeys("!!sed -e 's/^/| /'\n", 'tx')
170 call assert_equal('| 1', getline('.'))
171 90
172 :sil :!echo one
173 call feedkeys('.', 'tx')
174 call assert_equal('| 90', getline('.'))
175 95
176 set cpo+=!
177 " 2 <CR>, 1: for executing the command,
178 " 2: clear hit-enter-prompt
179 call feedkeys("!!\n", 'tx')
180 call feedkeys(":!echo one\n\n", 'tx')
181 call feedkeys(".", 'tx')
182 call assert_equal('one', getline('.'))
183 set cpo-=!
184 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +0200185endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200186
Bram Moolenaar1bbb6192018-11-10 16:02:01 +0100187func Test_normal05_formatexpr()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200188 " basic formatexpr test
189 call Setup_NewWindow()
190 %d_
191 call setline(1, ['here: 1 ', '2', 'here: 3 ', '4', 'not here: '])
192 1
193 set formatexpr=MyFormatExpr()
194 norm! gqG
195 call assert_equal(['here: 1->$', '2', 'here: 3->$', '4', 'not here: '], getline(1,'$'))
196 set formatexpr=
197 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +0200198endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200199
Bram Moolenaard77f9d52016-09-04 15:13:39 +0200200func Test_normal05_formatexpr_newbuf()
201 " Edit another buffer in the 'formatexpr' function
202 new
203 func! Format()
204 edit another
205 endfunc
206 set formatexpr=Format()
207 norm gqG
208 bw!
209 set formatexpr=
210endfunc
211
212func Test_normal05_formatexpr_setopt()
213 " Change the 'formatexpr' value in the function
214 new
215 func! Format()
216 set formatexpr=
217 endfunc
218 set formatexpr=Format()
219 norm gqG
220 bw!
221 set formatexpr=
222endfunc
223
Bram Moolenaar1bbb6192018-11-10 16:02:01 +0100224func Test_normal06_formatprg()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200225 " basic test for formatprg
226 " only test on non windows platform
Bram Moolenaar4a08b0d2016-11-05 21:55:13 +0100227 if has('win32')
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200228 return
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200229 endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +0100230
231 " uses sed to number non-empty lines
232 call writefile(['#!/bin/sh', 'sed ''/./=''|sed ''/./{', 'N', 's/\n/ /', '}'''], 'Xsed_format.sh')
233 call system('chmod +x ./Xsed_format.sh')
234 let text = ['a', '', 'c', '', ' ', 'd', 'e']
235 let expected = ['1 a', '', '3 c', '', '5 ', '6 d', '7 e']
236
237 10new
238 call setline(1, text)
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200239 set formatprg=./Xsed_format.sh
240 norm! gggqG
Bram Moolenaar9be7c042017-01-14 14:28:30 +0100241 call assert_equal(expected, getline(1, '$'))
242 bw!
243
244 10new
245 call setline(1, text)
246 set formatprg=donothing
247 setlocal formatprg=./Xsed_format.sh
248 norm! gggqG
249 call assert_equal(expected, getline(1, '$'))
250 bw!
251
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200252 " clean up
253 set formatprg=
Bram Moolenaar9be7c042017-01-14 14:28:30 +0100254 setlocal formatprg=
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200255 call delete('Xsed_format.sh')
Bram Moolenaar2931f2a2016-09-09 16:59:08 +0200256endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200257
Bram Moolenaar1bbb6192018-11-10 16:02:01 +0100258func Test_normal07_internalfmt()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200259 " basic test for internal formmatter to textwidth of 12
260 let list=range(1,11)
261 call map(list, 'v:val." "')
262 10new
263 call setline(1, list)
264 set tw=12
265 norm! gggqG
266 call assert_equal(['1 2 3', '4 5 6', '7 8 9', '10 11 '], getline(1, '$'))
267 " clean up
Bram Moolenaar9be7c042017-01-14 14:28:30 +0100268 set tw=0
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200269 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +0200270endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200271
Bram Moolenaar1bbb6192018-11-10 16:02:01 +0100272func Test_normal08_fold()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200273 " basic tests for foldopen/folddelete
274 if !has("folding")
275 return
276 endif
277 call Setup_NewWindow()
278 50
279 setl foldenable fdm=marker
280 " First fold
281 norm! V4jzf
282 " check that folds have been created
283 call assert_equal(['50/*{{{*/', '51', '52', '53', '54/*}}}*/'], getline(50,54))
284 " Second fold
285 46
286 norm! V10jzf
287 " check that folds have been created
288 call assert_equal('46/*{{{*/', getline(46))
289 call assert_equal('60/*}}}*/', getline(60))
290 norm! k
291 call assert_equal('45', getline('.'))
292 norm! j
293 call assert_equal('46/*{{{*/', getline('.'))
294 norm! j
295 call assert_equal('61', getline('.'))
296 norm! k
297 " open a fold
298 norm! Vzo
299 norm! k
300 call assert_equal('45', getline('.'))
301 norm! j
302 call assert_equal('46/*{{{*/', getline('.'))
303 norm! j
304 call assert_equal('47', getline('.'))
305 norm! k
306 norm! zcVzO
307 call assert_equal('46/*{{{*/', getline('.'))
308 norm! j
309 call assert_equal('47', getline('.'))
310 norm! j
311 call assert_equal('48', getline('.'))
312 norm! j
313 call assert_equal('49', getline('.'))
314 norm! j
315 call assert_equal('50/*{{{*/', getline('.'))
316 norm! j
317 call assert_equal('51', getline('.'))
318 " delete folds
319 :46
320 " collapse fold
321 norm! V14jzC
322 " delete all folds recursively
323 norm! VzD
324 call assert_equal(['46', '47', '48', '49', '50', '51', '52', '53', '54', '55', '56', '57', '58', '59', '60'], getline(46,60))
325
326 " clean up
327 setl nofoldenable fdm=marker
328 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +0200329endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200330
Bram Moolenaar1bbb6192018-11-10 16:02:01 +0100331func Test_normal09_operatorfunc()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200332 " Test operatorfunc
333 call Setup_NewWindow()
334 " Add some spaces for counting
335 50,60s/$/ /
336 unlet! g:a
337 let g:a=0
338 nmap <buffer><silent> ,, :set opfunc=CountSpaces<CR>g@
339 vmap <buffer><silent> ,, :<C-U>call CountSpaces(visualmode(), 1)<CR>
340 50
341 norm V2j,,
342 call assert_equal(6, g:a)
343 norm V,,
344 call assert_equal(2, g:a)
345 norm ,,l
346 call assert_equal(0, g:a)
347 50
348 exe "norm 0\<c-v>10j2l,,"
349 call assert_equal(11, g:a)
350 50
351 norm V10j,,
352 call assert_equal(22, g:a)
353
354 " clean up
355 unmap <buffer> ,,
356 set opfunc=
Bram Moolenaar4a08b0d2016-11-05 21:55:13 +0100357 unlet! g:a
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200358 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +0200359endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200360
Bram Moolenaar1bbb6192018-11-10 16:02:01 +0100361func Test_normal09a_operatorfunc()
Bram Moolenaar4a08b0d2016-11-05 21:55:13 +0100362 " Test operatorfunc
363 call Setup_NewWindow()
364 " Add some spaces for counting
365 50,60s/$/ /
366 unlet! g:opt
367 set linebreak
368 nmap <buffer><silent> ,, :set opfunc=OpfuncDummy<CR>g@
369 50
370 norm ,,j
371 exe "bd!" g:bufnr
372 call assert_true(&linebreak)
373 call assert_equal(g:opt, &linebreak)
374 set nolinebreak
375 norm ,,j
376 exe "bd!" g:bufnr
377 call assert_false(&linebreak)
378 call assert_equal(g:opt, &linebreak)
379
380 " clean up
381 unmap <buffer> ,,
382 set opfunc=
383 bw!
384 unlet! g:opt
385endfunc
386
Bram Moolenaar1bbb6192018-11-10 16:02:01 +0100387func Test_normal10_expand()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200388 " Test for expand()
389 10new
390 call setline(1, ['1', 'ifooar,,cbar'])
391 2
392 norm! $
Bram Moolenaar65f08472017-09-10 18:16:20 +0200393 call assert_equal('cbar', expand('<cword>'))
394 call assert_equal('ifooar,,cbar', expand('<cWORD>'))
395
396 call setline(1, ['prx = list[idx];'])
397 1
398 let expected = ['', 'prx', 'prx', 'prx',
399 \ 'list', 'list', 'list', 'list', 'list', 'list', 'list',
400 \ 'idx', 'idx', 'idx', 'idx',
401 \ 'list[idx]',
402 \ '];',
403 \ ]
404 for i in range(1, 16)
405 exe 'norm ' . i . '|'
406 call assert_equal(expected[i], expand('<cexpr>'), 'i == ' . i)
407 endfor
408
Bram Moolenaarae6f8652017-12-20 22:32:20 +0100409 if executable('echo')
410 " Test expand(`...`) i.e. backticks command expansion.
411 " MS-Windows has a trailing space.
412 call assert_match('^abcde *$', expand('`echo abcde`'))
413 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
442 exe "norm! <c-k>"
443 call assert_equal(map(range(1,5), 'string(v:val)'), getline(1,'$'))
444 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +0200445endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200446
Bram Moolenaar1bbb6192018-11-10 16:02:01 +0100447func Test_normal13_help()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200448 " Test for F1
449 call assert_equal(1, winnr())
450 call feedkeys("\<f1>", 'txi')
451 call assert_match('help\.txt', bufname('%'))
452 call assert_equal(2, winnr('$'))
453 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +0200454endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200455
Bram Moolenaar1bbb6192018-11-10 16:02:01 +0100456func Test_normal14_page()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200457 " basic test for Ctrl-F and Ctrl-B
458 call Setup_NewWindow()
459 exe "norm! \<c-f>"
460 call assert_equal('9', getline('.'))
461 exe "norm! 2\<c-f>"
462 call assert_equal('25', getline('.'))
463 exe "norm! 2\<c-b>"
464 call assert_equal('18', getline('.'))
465 1
466 set scrolloff=5
467 exe "norm! 2\<c-f>"
468 call assert_equal('21', getline('.'))
469 exe "norm! \<c-b>"
470 call assert_equal('13', getline('.'))
471 1
472 set scrolloff=99
473 exe "norm! \<c-f>"
474 call assert_equal('13', getline('.'))
475 set scrolloff=0
476 100
477 exe "norm! $\<c-b>"
478 call assert_equal('92', getline('.'))
479 call assert_equal([0, 92, 1, 0, 1], getcurpos())
480 100
481 set nostartofline
482 exe "norm! $\<c-b>"
483 call assert_equal('92', getline('.'))
484 call assert_equal([0, 92, 2, 0, 2147483647], getcurpos())
485 " cleanup
486 set startofline
487 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +0200488endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200489
Bram Moolenaar1bbb6192018-11-10 16:02:01 +0100490func Test_normal14_page_eol()
Bram Moolenaarbc54f3f2016-09-04 14:34:28 +0200491 10new
492 norm oxxxxxxx
493 exe "norm 2\<c-f>"
494 " check with valgrind that cursor is put back in column 1
495 exe "norm 2\<c-b>"
496 bw!
497endfunc
498
Bram Moolenaar1bbb6192018-11-10 16:02:01 +0100499func Test_normal15_z_scroll_vert()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200500 " basic test for z commands that scroll the window
501 call Setup_NewWindow()
502 100
503 norm! >>
504 " Test for z<cr>
505 exe "norm! z\<cr>"
506 call assert_equal(' 100', getline('.'))
507 call assert_equal(100, winsaveview()['topline'])
508 call assert_equal([0, 100, 2, 0, 9], getcurpos())
509
510 " Test for zt
511 21
512 norm! >>0zt
513 call assert_equal(' 21', getline('.'))
514 call assert_equal(21, winsaveview()['topline'])
515 call assert_equal([0, 21, 1, 0, 8], getcurpos())
516
517 " Test for zb
518 30
519 norm! >>$ztzb
520 call assert_equal(' 30', getline('.'))
521 call assert_equal(30, winsaveview()['topline']+winheight(0)-1)
522 call assert_equal([0, 30, 3, 0, 2147483647], getcurpos())
523
524 " Test for z-
525 1
526 30
527 norm! 0z-
528 call assert_equal(' 30', getline('.'))
529 call assert_equal(30, winsaveview()['topline']+winheight(0)-1)
530 call assert_equal([0, 30, 2, 0, 9], getcurpos())
531
532 " Test for z{height}<cr>
533 call assert_equal(10, winheight(0))
534 exe "norm! z12\<cr>"
535 call assert_equal(12, winheight(0))
536 exe "norm! z10\<cr>"
537 call assert_equal(10, winheight(0))
538
539 " Test for z.
540 1
541 21
542 norm! 0z.
543 call assert_equal(' 21', getline('.'))
544 call assert_equal(17, winsaveview()['topline'])
545 call assert_equal([0, 21, 2, 0, 9], getcurpos())
546
547 " Test for zz
548 1
549 21
550 norm! 0zz
551 call assert_equal(' 21', getline('.'))
552 call assert_equal(17, winsaveview()['topline'])
553 call assert_equal([0, 21, 1, 0, 8], getcurpos())
554
555 " Test for z+
556 11
557 norm! zt
558 norm! z+
559 call assert_equal(' 21', getline('.'))
560 call assert_equal(21, winsaveview()['topline'])
561 call assert_equal([0, 21, 2, 0, 9], getcurpos())
562
563 " Test for [count]z+
564 1
565 norm! 21z+
566 call assert_equal(' 21', getline('.'))
567 call assert_equal(21, winsaveview()['topline'])
568 call assert_equal([0, 21, 2, 0, 9], getcurpos())
569
570 " Test for z^
571 norm! 22z+0
572 norm! z^
573 call assert_equal(' 21', getline('.'))
574 call assert_equal(12, winsaveview()['topline'])
575 call assert_equal([0, 21, 2, 0, 9], getcurpos())
576
577 " Test for [count]z^
578 1
579 norm! 30z^
580 call assert_equal(' 21', getline('.'))
581 call assert_equal(12, winsaveview()['topline'])
582 call assert_equal([0, 21, 2, 0, 9], getcurpos())
583
584 " cleanup
585 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +0200586endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200587
Bram Moolenaar1bbb6192018-11-10 16:02:01 +0100588func Test_normal16_z_scroll_hor()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200589 " basic test for z commands that scroll the window
590 10new
591 15vsp
592 set nowrap listchars=
593 let lineA='abcdefghijklmnopqrstuvwxyz'
594 let lineB='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'
595 $put =lineA
596 $put =lineB
597 1d
598
599 " Test for zl
600 1
601 norm! 5zl
602 call assert_equal(lineA, getline('.'))
603 call assert_equal(6, col('.'))
604 call assert_equal(5, winsaveview()['leftcol'])
605 norm! yl
606 call assert_equal('f', @0)
607
608 " Test for zh
609 norm! 2zh
610 call assert_equal(lineA, getline('.'))
611 call assert_equal(6, col('.'))
612 norm! yl
613 call assert_equal('f', @0)
614 call assert_equal(3, winsaveview()['leftcol'])
615
616 " Test for zL
617 norm! zL
618 call assert_equal(11, col('.'))
619 norm! yl
620 call assert_equal('k', @0)
621 call assert_equal(10, winsaveview()['leftcol'])
622 norm! 2zL
623 call assert_equal(25, col('.'))
624 norm! yl
625 call assert_equal('y', @0)
626 call assert_equal(24, winsaveview()['leftcol'])
627
628 " Test for zH
629 norm! 2zH
630 call assert_equal(25, col('.'))
631 call assert_equal(10, winsaveview()['leftcol'])
632 norm! yl
633 call assert_equal('y', @0)
634
635 " Test for zs
636 norm! $zs
637 call assert_equal(26, col('.'))
638 call assert_equal(25, winsaveview()['leftcol'])
639 norm! yl
640 call assert_equal('z', @0)
641
642 " Test for ze
643 norm! ze
644 call assert_equal(26, col('.'))
645 call assert_equal(11, winsaveview()['leftcol'])
646 norm! yl
647 call assert_equal('z', @0)
648
649 " cleanup
650 set wrap listchars=eol:$
651 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +0200652endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200653
Bram Moolenaar1bbb6192018-11-10 16:02:01 +0100654func Test_normal17_z_scroll_hor2()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200655 " basic test for z commands that scroll the window
656 " using 'sidescrolloff' setting
657 10new
658 20vsp
659 set nowrap listchars= sidescrolloff=5
660 let lineA='abcdefghijklmnopqrstuvwxyz'
661 let lineB='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'
662 $put =lineA
663 $put =lineB
664 1d
665
666 " Test for zl
667 1
668 norm! 5zl
669 call assert_equal(lineA, getline('.'))
670 call assert_equal(11, col('.'))
671 call assert_equal(5, winsaveview()['leftcol'])
672 norm! yl
673 call assert_equal('k', @0)
674
675 " Test for zh
676 norm! 2zh
677 call assert_equal(lineA, getline('.'))
678 call assert_equal(11, col('.'))
679 norm! yl
680 call assert_equal('k', @0)
681 call assert_equal(3, winsaveview()['leftcol'])
682
683 " Test for zL
684 norm! 0zL
685 call assert_equal(16, col('.'))
686 norm! yl
687 call assert_equal('p', @0)
688 call assert_equal(10, winsaveview()['leftcol'])
689 norm! 2zL
690 call assert_equal(26, col('.'))
691 norm! yl
692 call assert_equal('z', @0)
693 call assert_equal(15, winsaveview()['leftcol'])
694
695 " Test for zH
696 norm! 2zH
697 call assert_equal(15, col('.'))
698 call assert_equal(0, winsaveview()['leftcol'])
699 norm! yl
700 call assert_equal('o', @0)
701
702 " Test for zs
703 norm! $zs
704 call assert_equal(26, col('.'))
705 call assert_equal(20, winsaveview()['leftcol'])
706 norm! yl
707 call assert_equal('z', @0)
708
709 " Test for ze
710 norm! ze
711 call assert_equal(26, col('.'))
712 call assert_equal(11, winsaveview()['leftcol'])
713 norm! yl
714 call assert_equal('z', @0)
715
716 " cleanup
717 set wrap listchars=eol:$ sidescrolloff=0
718 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +0200719endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200720
Bram Moolenaar1bbb6192018-11-10 16:02:01 +0100721func Test_normal18_z_fold()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200722 " basic tests for foldopen/folddelete
723 if !has("folding")
724 return
725 endif
726 call Setup_NewWindow()
727 50
728 setl foldenable fdm=marker foldlevel=5
729
730 " Test for zF
731 " First fold
732 norm! 4zF
733 " check that folds have been created
734 call assert_equal(['50/*{{{*/', '51', '52', '53/*}}}*/'], getline(50,53))
735
736 " Test for zd
737 51
738 norm! 2zF
739 call assert_equal(2, foldlevel('.'))
740 norm! kzd
741 call assert_equal(['50', '51/*{{{*/', '52/*}}}*/', '53'], getline(50,53))
742 norm! j
743 call assert_equal(1, foldlevel('.'))
744
745 " Test for zD
746 " also deletes partially selected folds recursively
747 51
748 norm! zF
749 call assert_equal(2, foldlevel('.'))
750 norm! kV2jzD
751 call assert_equal(['50', '51', '52', '53'], getline(50,53))
752
753 " Test for zE
754 85
755 norm! 4zF
756 86
757 norm! 2zF
758 90
759 norm! 4zF
760 call assert_equal(['85/*{{{*/', '86/*{{{*/', '87/*}}}*/', '88/*}}}*/', '89', '90/*{{{*/', '91', '92', '93/*}}}*/'], getline(85,93))
761 norm! zE
762 call assert_equal(['85', '86', '87', '88', '89', '90', '91', '92', '93'], getline(85,93))
763
764 " Test for zn
765 50
766 set foldlevel=0
767 norm! 2zF
768 norm! zn
769 norm! k
770 call assert_equal('49', getline('.'))
771 norm! j
772 call assert_equal('50/*{{{*/', getline('.'))
773 norm! j
774 call assert_equal('51/*}}}*/', getline('.'))
775 norm! j
776 call assert_equal('52', getline('.'))
777 call assert_equal(0, &foldenable)
778
779 " Test for zN
780 49
781 norm! zN
782 call assert_equal('49', getline('.'))
783 norm! j
784 call assert_equal('50/*{{{*/', getline('.'))
785 norm! j
786 call assert_equal('52', getline('.'))
787 call assert_equal(1, &foldenable)
788
789 " Test for zi
790 norm! zi
791 call assert_equal(0, &foldenable)
792 norm! zi
793 call assert_equal(1, &foldenable)
794 norm! zi
795 call assert_equal(0, &foldenable)
796 norm! zi
797 call assert_equal(1, &foldenable)
798
799 " Test for za
800 50
801 norm! za
802 norm! k
803 call assert_equal('49', getline('.'))
804 norm! j
805 call assert_equal('50/*{{{*/', getline('.'))
806 norm! j
807 call assert_equal('51/*}}}*/', getline('.'))
808 norm! j
809 call assert_equal('52', getline('.'))
810 50
811 norm! za
812 norm! k
813 call assert_equal('49', getline('.'))
814 norm! j
815 call assert_equal('50/*{{{*/', getline('.'))
816 norm! j
817 call assert_equal('52', getline('.'))
818
819 49
820 norm! 5zF
821 norm! k
822 call assert_equal('48', getline('.'))
823 norm! j
824 call assert_equal('49/*{{{*/', getline('.'))
825 norm! j
826 call assert_equal('55', getline('.'))
827 49
828 norm! za
829 call assert_equal('49/*{{{*/', getline('.'))
830 norm! j
831 call assert_equal('50/*{{{*/', getline('.'))
832 norm! j
833 call assert_equal('52', getline('.'))
834 set nofoldenable
835 " close fold and set foldenable
836 norm! za
837 call assert_equal(1, &foldenable)
838
839 50
840 " have to use {count}za to open all folds and make the cursor visible
841 norm! 2za
842 norm! 2k
843 call assert_equal('48', getline('.'))
844 norm! j
845 call assert_equal('49/*{{{*/', getline('.'))
846 norm! j
847 call assert_equal('50/*{{{*/', getline('.'))
848 norm! j
849 call assert_equal('51/*}}}*/', getline('.'))
850 norm! j
851 call assert_equal('52', getline('.'))
852
853 " Test for zA
854 49
855 set foldlevel=0
856 50
857 norm! zA
858 norm! 2k
859 call assert_equal('48', getline('.'))
860 norm! j
861 call assert_equal('49/*{{{*/', getline('.'))
862 norm! j
863 call assert_equal('50/*{{{*/', getline('.'))
864 norm! j
865 call assert_equal('51/*}}}*/', getline('.'))
866 norm! j
867 call assert_equal('52', getline('.'))
868
Bram Moolenaar395b6ba2017-04-07 20:09:51 +0200869 " zA on a opened fold when foldenable is not set
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200870 50
871 set nofoldenable
872 norm! zA
873 call assert_equal(1, &foldenable)
874 norm! k
875 call assert_equal('48', getline('.'))
876 norm! j
877 call assert_equal('49/*{{{*/', getline('.'))
878 norm! j
879 call assert_equal('55', getline('.'))
880
881 " Test for zc
882 norm! zE
883 50
884 norm! 2zF
885 49
886 norm! 5zF
887 set nofoldenable
888 50
889 " There most likely is a bug somewhere:
890 " https://groups.google.com/d/msg/vim_dev/v2EkfJ_KQjI/u-Cvv94uCAAJ
891 " TODO: Should this only close the inner most fold or both folds?
892 norm! zc
893 call assert_equal(1, &foldenable)
894 norm! k
895 call assert_equal('48', getline('.'))
896 norm! j
897 call assert_equal('49/*{{{*/', getline('.'))
898 norm! j
899 call assert_equal('55', getline('.'))
900 set nofoldenable
901 50
902 norm! Vjzc
903 norm! k
904 call assert_equal('48', getline('.'))
905 norm! j
906 call assert_equal('49/*{{{*/', getline('.'))
907 norm! j
908 call assert_equal('55', getline('.'))
909
910 " Test for zC
911 set nofoldenable
912 50
913 norm! zCk
914 call assert_equal('48', getline('.'))
915 norm! j
916 call assert_equal('49/*{{{*/', getline('.'))
917 norm! j
918 call assert_equal('55', getline('.'))
919
920 " Test for zx
921 " 1) close folds at line 49-54
922 set nofoldenable
923 48
924 norm! zx
925 call assert_equal(1, &foldenable)
926 norm! j
927 call assert_equal('49/*{{{*/', getline('.'))
928 norm! j
929 call assert_equal('55', getline('.'))
930
Bram Moolenaar395b6ba2017-04-07 20:09:51 +0200931 " 2) do not close fold under cursor
Bram Moolenaar87bc3f72016-09-03 17:33:54 +0200932 51
933 set nofoldenable
934 norm! zx
935 call assert_equal(1, &foldenable)
936 norm! 3k
937 call assert_equal('48', getline('.'))
938 norm! j
939 call assert_equal('49/*{{{*/', getline('.'))
940 norm! j
941 call assert_equal('50/*{{{*/', getline('.'))
942 norm! j
943 call assert_equal('51/*}}}*/', getline('.'))
944 norm! j
945 call assert_equal('52', getline('.'))
946 norm! j
947 call assert_equal('53', getline('.'))
948 norm! j
949 call assert_equal('54/*}}}*/', getline('.'))
950 norm! j
951 call assert_equal('55', getline('.'))
952
953 " 3) close one level of folds
954 48
955 set nofoldenable
956 set foldlevel=1
957 norm! zx
958 call assert_equal(1, &foldenable)
959 call assert_equal('48', getline('.'))
960 norm! j
961 call assert_equal('49/*{{{*/', getline('.'))
962 norm! j
963 call assert_equal('50/*{{{*/', getline('.'))
964 norm! j
965 call assert_equal('52', getline('.'))
966 norm! j
967 call assert_equal('53', getline('.'))
968 norm! j
969 call assert_equal('54/*}}}*/', getline('.'))
970 norm! j
971 call assert_equal('55', getline('.'))
972
973 " Test for zX
974 " Close all folds
975 set foldlevel=0 nofoldenable
976 50
977 norm! zX
978 call assert_equal(1, &foldenable)
979 norm! k
980 call assert_equal('48', getline('.'))
981 norm! j
982 call assert_equal('49/*{{{*/', getline('.'))
983 norm! j
984 call assert_equal('55', getline('.'))
985
986 " Test for zm
987 50
988 set nofoldenable foldlevel=2
989 norm! zm
990 call assert_equal(1, &foldenable)
991 call assert_equal(1, &foldlevel)
992 norm! zm
993 call assert_equal(0, &foldlevel)
994 norm! zm
995 call assert_equal(0, &foldlevel)
996 norm! k
997 call assert_equal('48', getline('.'))
998 norm! j
999 call assert_equal('49/*{{{*/', getline('.'))
1000 norm! j
1001 call assert_equal('55', getline('.'))
1002
1003 " Test for zM
1004 48
1005 set nofoldenable foldlevel=99
1006 norm! zM
1007 call assert_equal(1, &foldenable)
1008 call assert_equal(0, &foldlevel)
1009 call assert_equal('48', getline('.'))
1010 norm! j
1011 call assert_equal('49/*{{{*/', getline('.'))
1012 norm! j
1013 call assert_equal('55', getline('.'))
1014
1015 " Test for zr
1016 48
1017 set nofoldenable foldlevel=0
1018 norm! zr
1019 call assert_equal(0, &foldenable)
1020 call assert_equal(1, &foldlevel)
1021 set foldlevel=0 foldenable
1022 norm! zr
1023 call assert_equal(1, &foldenable)
1024 call assert_equal(1, &foldlevel)
1025 norm! zr
1026 call assert_equal(2, &foldlevel)
1027 call assert_equal('48', getline('.'))
1028 norm! j
1029 call assert_equal('49/*{{{*/', getline('.'))
1030 norm! j
1031 call assert_equal('50/*{{{*/', getline('.'))
1032 norm! j
1033 call assert_equal('51/*}}}*/', getline('.'))
1034 norm! j
1035 call assert_equal('52', getline('.'))
1036
1037 " Test for zR
1038 48
1039 set nofoldenable foldlevel=0
1040 norm! zR
1041 call assert_equal(0, &foldenable)
1042 call assert_equal(2, &foldlevel)
1043 set foldenable foldlevel=0
1044 norm! zR
1045 call assert_equal(1, &foldenable)
1046 call assert_equal(2, &foldlevel)
1047 call assert_equal('48', getline('.'))
1048 norm! j
1049 call assert_equal('49/*{{{*/', getline('.'))
1050 norm! j
1051 call assert_equal('50/*{{{*/', getline('.'))
1052 norm! j
1053 call assert_equal('51/*}}}*/', getline('.'))
1054 norm! j
1055 call assert_equal('52', getline('.'))
1056 call append(50, ['a /*{{{*/', 'b /*}}}*/'])
1057 48
1058 call assert_equal('48', getline('.'))
1059 norm! j
1060 call assert_equal('49/*{{{*/', getline('.'))
1061 norm! j
1062 call assert_equal('50/*{{{*/', getline('.'))
1063 norm! j
1064 call assert_equal('a /*{{{*/', getline('.'))
1065 norm! j
1066 call assert_equal('51/*}}}*/', getline('.'))
1067 norm! j
1068 call assert_equal('52', getline('.'))
1069 48
1070 norm! zR
1071 call assert_equal(1, &foldenable)
1072 call assert_equal(3, &foldlevel)
1073 call assert_equal('48', getline('.'))
1074 norm! j
1075 call assert_equal('49/*{{{*/', getline('.'))
1076 norm! j
1077 call assert_equal('50/*{{{*/', getline('.'))
1078 norm! j
1079 call assert_equal('a /*{{{*/', getline('.'))
1080 norm! j
1081 call assert_equal('b /*}}}*/', getline('.'))
1082 norm! j
1083 call assert_equal('51/*}}}*/', getline('.'))
1084 norm! j
1085 call assert_equal('52', getline('.'))
1086
1087 " clean up
1088 setl nofoldenable fdm=marker foldlevel=0
1089 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02001090endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001091
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01001092func Test_normal19_z_spell()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001093 if !has("spell") || !has('syntax')
1094 return
1095 endif
1096 new
1097 call append(0, ['1 good', '2 goood', '3 goood'])
1098 set spell spellfile=./Xspellfile.add spelllang=en
1099 let oldlang=v:lang
1100 lang C
1101
1102 " Test for zg
1103 1
1104 norm! ]s
1105 call assert_equal('2 goood', getline('.'))
1106 norm! zg
1107 1
1108 let a=execute('unsilent :norm! ]s')
1109 call assert_equal('1 good', getline('.'))
1110 call assert_equal('search hit BOTTOM, continuing at TOP', a[1:])
1111 let cnt=readfile('./Xspellfile.add')
1112 call assert_equal('goood', cnt[0])
1113
1114 " Test for zw
1115 2
1116 norm! $zw
1117 1
1118 norm! ]s
1119 call assert_equal('2 goood', getline('.'))
1120 let cnt=readfile('./Xspellfile.add')
1121 call assert_equal('#oood', cnt[0])
1122 call assert_equal('goood/!', cnt[1])
1123
1124 " Test for zg in visual mode
1125 let a=execute('unsilent :norm! V$zg')
1126 call assert_equal("Word '2 goood' added to ./Xspellfile.add", a[1:])
1127 1
1128 norm! ]s
1129 call assert_equal('3 goood', getline('.'))
1130 let cnt=readfile('./Xspellfile.add')
1131 call assert_equal('2 goood', cnt[2])
1132 " Remove "2 good" from spellfile
1133 2
1134 let a=execute('unsilent norm! V$zw')
1135 call assert_equal("Word '2 goood' added to ./Xspellfile.add", a[1:])
1136 let cnt=readfile('./Xspellfile.add')
1137 call assert_equal('2 goood/!', cnt[3])
1138
1139 " Test for zG
1140 let a=execute('unsilent norm! V$zG')
1141 call assert_match("Word '2 goood' added to .*", a)
1142 let fname=matchstr(a, 'to\s\+\zs\f\+$')
1143 let cnt=readfile(fname)
1144 call assert_equal('2 goood', cnt[0])
1145
1146 " Test for zW
1147 let a=execute('unsilent norm! V$zW')
1148 call assert_match("Word '2 goood' added to .*", a)
1149 let cnt=readfile(fname)
1150 call assert_equal('# goood', cnt[0])
1151 call assert_equal('2 goood/!', cnt[1])
1152
1153 " Test for zuW
1154 let a=execute('unsilent norm! V$zuW')
1155 call assert_match("Word '2 goood' removed from .*", a)
1156 let cnt=readfile(fname)
1157 call assert_equal('# goood', cnt[0])
1158 call assert_equal('# goood/!', cnt[1])
1159
1160 " Test for zuG
1161 let a=execute('unsilent norm! $zG')
1162 call assert_match("Word 'goood' added to .*", a)
1163 let cnt=readfile(fname)
1164 call assert_equal('# goood', cnt[0])
1165 call assert_equal('# goood/!', cnt[1])
1166 call assert_equal('goood', cnt[2])
1167 let a=execute('unsilent norm! $zuG')
1168 let cnt=readfile(fname)
1169 call assert_match("Word 'goood' removed from .*", a)
1170 call assert_equal('# goood', cnt[0])
1171 call assert_equal('# goood/!', cnt[1])
1172 call assert_equal('#oood', cnt[2])
1173 " word not found in wordlist
1174 let a=execute('unsilent norm! V$zuG')
1175 let cnt=readfile(fname)
1176 call assert_match("", a)
1177 call assert_equal('# goood', cnt[0])
1178 call assert_equal('# goood/!', cnt[1])
1179 call assert_equal('#oood', cnt[2])
1180
1181 " Test for zug
1182 call delete('./Xspellfile.add')
1183 2
1184 let a=execute('unsilent norm! $zg')
1185 let cnt=readfile('./Xspellfile.add')
1186 call assert_equal('goood', cnt[0])
1187 let a=execute('unsilent norm! $zug')
1188 call assert_match("Word 'goood' removed from \./Xspellfile.add", a)
1189 let cnt=readfile('./Xspellfile.add')
1190 call assert_equal('#oood', cnt[0])
1191 " word not in wordlist
1192 let a=execute('unsilent norm! V$zug')
1193 call assert_match('', a)
1194 let cnt=readfile('./Xspellfile.add')
1195 call assert_equal('#oood', cnt[0])
1196
1197 " Test for zuw
1198 call delete('./Xspellfile.add')
1199 2
1200 let a=execute('unsilent norm! Vzw')
1201 let cnt=readfile('./Xspellfile.add')
1202 call assert_equal('2 goood/!', cnt[0])
1203 let a=execute('unsilent norm! Vzuw')
1204 call assert_match("Word '2 goood' removed from \./Xspellfile.add", a)
1205 let cnt=readfile('./Xspellfile.add')
1206 call assert_equal('# goood/!', cnt[0])
1207 " word not in wordlist
1208 let a=execute('unsilent norm! $zug')
1209 call assert_match('', a)
1210 let cnt=readfile('./Xspellfile.add')
1211 call assert_equal('# goood/!', cnt[0])
1212
1213 " add second entry to spellfile setting
1214 set spellfile=./Xspellfile.add,./Xspellfile2.add
1215 call delete('./Xspellfile.add')
1216 2
1217 let a=execute('unsilent norm! $2zg')
1218 let cnt=readfile('./Xspellfile2.add')
1219 call assert_match("Word 'goood' added to ./Xspellfile2.add", a)
1220 call assert_equal('goood', cnt[0])
1221
Bram Moolenaarf45938c2017-11-02 15:59:57 +01001222 " Test for :spellgood!
1223 let temp = execute(':spe!0/0')
1224 call assert_match('Invalid region', temp)
1225 let spellfile = matchstr(temp, 'Invalid region nr in \zs.*\ze line \d: 0')
1226 call assert_equal(['# goood', '# goood/!', '#oood', '0/0'], readfile(spellfile))
1227 call delete(spellfile)
1228
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001229 " clean up
1230 exe "lang" oldlang
1231 call delete("./Xspellfile.add")
1232 call delete("./Xspellfile2.add")
Bram Moolenaardf0db162016-09-06 20:37:41 +02001233 call delete("./Xspellfile.add.spl")
1234 call delete("./Xspellfile2.add.spl")
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001235
1236 " zux -> no-op
1237 2
1238 norm! $zux
1239 call assert_equal([], glob('Xspellfile.add',0,1))
1240 call assert_equal([], glob('Xspellfile2.add',0,1))
1241
1242 set spellfile=
1243 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02001244endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001245
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01001246func Test_normal20_exmode()
Bram Moolenaar0913a102016-09-03 19:11:59 +02001247 if !has("unix")
1248 " Reading from redirected file doesn't work on MS-Windows
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001249 return
1250 endif
1251 call writefile(['1a', 'foo', 'bar', '.', 'w! Xfile2', 'q!'], 'Xscript')
1252 call writefile(['1', '2'], 'Xfile')
1253 call system(v:progpath .' -e -s < Xscript Xfile')
1254 let a=readfile('Xfile2')
1255 call assert_equal(['1', 'foo', 'bar', '2'], a)
1256
1257 " clean up
1258 for file in ['Xfile', 'Xfile2', 'Xscript']
1259 call delete(file)
1260 endfor
1261 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02001262endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001263
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01001264func Test_normal21_nv_hat()
1265
1266 " Edit a fresh file and wipe the buffer list so that there is no alternate
1267 " file present. Next, check for the expected command failures.
1268 edit Xfoo | %bw
1269 call assert_fails(':buffer #', 'E86')
1270 call assert_fails(':execute "normal! \<C-^>"', 'E23')
1271
1272 " Test for the expected behavior when switching between two named buffers.
1273 edit Xfoo | edit Xbar
1274 call feedkeys("\<C-^>", 'tx')
1275 call assert_equal('Xfoo', fnamemodify(bufname('%'), ':t'))
1276 call feedkeys("\<C-^>", 'tx')
1277 call assert_equal('Xbar', fnamemodify(bufname('%'), ':t'))
1278
1279 " Test for the expected behavior when only one buffer is named.
1280 enew | let l:nr = bufnr('%')
1281 call feedkeys("\<C-^>", 'tx')
1282 call assert_equal('Xbar', fnamemodify(bufname('%'), ':t'))
1283 call feedkeys("\<C-^>", 'tx')
1284 call assert_equal('', bufname('%'))
1285 call assert_equal(l:nr, bufnr('%'))
1286
1287 " Test that no action is taken by "<C-^>" when an operator is pending.
1288 edit Xfoo
1289 call feedkeys("ci\<C-^>", 'tx')
1290 call assert_equal('Xfoo', fnamemodify(bufname('%'), ':t'))
1291
1292 %bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02001293endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001294
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01001295func Test_normal22_zet()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001296 " Test for ZZ
Bram Moolenaar0913a102016-09-03 19:11:59 +02001297 " let shell = &shell
1298 " let &shell = 'sh'
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001299 call writefile(['1', '2'], 'Xfile')
1300 let args = ' -u NONE -N -U NONE -i NONE --noplugins -X --not-a-term'
1301 call system(v:progpath . args . ' -c "%d" -c ":norm! ZZ" Xfile')
1302 let a = readfile('Xfile')
1303 call assert_equal([], a)
1304 " Test for ZQ
1305 call writefile(['1', '2'], 'Xfile')
1306 call system(v:progpath . args . ' -c "%d" -c ":norm! ZQ" Xfile')
1307 let a = readfile('Xfile')
1308 call assert_equal(['1', '2'], a)
1309
1310 " clean up
1311 for file in ['Xfile']
1312 call delete(file)
1313 endfor
Bram Moolenaar0913a102016-09-03 19:11:59 +02001314 " let &shell = shell
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02001315endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001316
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01001317func Test_normal23_K()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001318 " Test for K command
1319 new
Bram Moolenaar426f3752016-11-04 21:22:37 +01001320 call append(0, ['version8.txt', 'man', 'aa%bb', 'cc|dd'])
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001321 let k = &keywordprg
1322 set keywordprg=:help
1323 1
1324 norm! VK
1325 call assert_equal('version8.txt', fnamemodify(bufname('%'), ':t'))
1326 call assert_equal('help', &ft)
1327 call assert_match('\*version8.txt\*', getline('.'))
1328 helpclose
1329 norm! 0K
1330 call assert_equal('version8.txt', fnamemodify(bufname('%'), ':t'))
1331 call assert_equal('help', &ft)
Bram Moolenaarb1c91982018-05-17 17:04:55 +02001332 call assert_match('\*version8\.\d\*', getline('.'))
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001333 helpclose
1334
Bram Moolenaar426f3752016-11-04 21:22:37 +01001335 set keywordprg=:new
1336 set iskeyword+=%
1337 set iskeyword+=\|
1338 2
1339 norm! K
1340 call assert_equal('man', fnamemodify(bufname('%'), ':t'))
1341 bwipe!
1342 3
1343 norm! K
1344 call assert_equal('aa%bb', fnamemodify(bufname('%'), ':t'))
1345 bwipe!
Bram Moolenaareb828d02016-11-05 19:54:01 +01001346 if !has('win32')
1347 4
1348 norm! K
1349 call assert_equal('cc|dd', fnamemodify(bufname('%'), ':t'))
1350 bwipe!
1351 endif
Bram Moolenaar426f3752016-11-04 21:22:37 +01001352 set iskeyword-=%
1353 set iskeyword-=\|
1354
Bram Moolenaar0913a102016-09-03 19:11:59 +02001355 " Only expect "man" to work on Unix
1356 if !has("unix")
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001357 let &keywordprg = k
1358 bw!
1359 return
1360 endif
Bram Moolenaarc6b37db2019-04-27 18:00:34 +02001361
1362 if has('mac')
1363 " In MacOS, the option for specifying a pager is different
1364 set keywordprg=man\ -P\ cat
1365 else
1366 set keywordprg=man\ --pager=cat
1367 endif
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001368 " Test for using man
1369 2
1370 let a = execute('unsilent norm! K')
Bram Moolenaarc6b37db2019-04-27 18:00:34 +02001371 if has('mac')
1372 call assert_match("man -P cat 'man'", a)
1373 else
1374 call assert_match("man --pager=cat 'man'", a)
1375 endif
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001376
1377 " clean up
1378 let &keywordprg = k
1379 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02001380endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001381
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01001382func Test_normal24_rot13()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001383 " Testing for g?? g?g?
1384 new
1385 call append(0, 'abcdefghijklmnopqrstuvwxyzäüö')
1386 1
1387 norm! g??
1388 call assert_equal('nopqrstuvwxyzabcdefghijklmäüö', getline('.'))
1389 norm! g?g?
1390 call assert_equal('abcdefghijklmnopqrstuvwxyzäüö', getline('.'))
1391
1392 " clean up
1393 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02001394endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001395
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01001396func Test_normal25_tag()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001397 " Testing for CTRL-] g CTRL-] g]
1398 " CTRL-W g] CTRL-W CTRL-] CTRL-W g CTRL-]
1399 h
1400 " Test for CTRL-]
1401 call search('\<x\>$')
1402 exe "norm! \<c-]>"
1403 call assert_equal("change.txt", fnamemodify(bufname('%'), ':t'))
1404 norm! yiW
1405 call assert_equal("*x*", @0)
1406 exe ":norm \<c-o>"
1407
1408 " Test for g_CTRL-]
1409 call search('\<v_u\>$')
1410 exe "norm! g\<c-]>"
1411 call assert_equal("change.txt", fnamemodify(bufname('%'), ':t'))
1412 norm! yiW
1413 call assert_equal("*v_u*", @0)
1414 exe ":norm \<c-o>"
1415
1416 " Test for g]
1417 call search('\<i_<Esc>$')
1418 let a = execute(":norm! g]")
1419 call assert_match('i_<Esc>.*insert.txt', a)
1420
1421 if !empty(exepath('cscope')) && has('cscope')
1422 " setting cscopetag changes how g] works
1423 set cst
1424 exe "norm! g]"
1425 call assert_equal("insert.txt", fnamemodify(bufname('%'), ':t'))
1426 norm! yiW
1427 call assert_equal("*i_<Esc>*", @0)
1428 exe ":norm \<c-o>"
1429 " Test for CTRL-W g]
1430 exe "norm! \<C-W>g]"
1431 call assert_equal("insert.txt", fnamemodify(bufname('%'), ':t'))
1432 norm! yiW
1433 call assert_equal("*i_<Esc>*", @0)
1434 call assert_equal(3, winnr('$'))
1435 helpclose
1436 set nocst
1437 endif
1438
1439 " Test for CTRL-W g]
1440 let a = execute("norm! \<C-W>g]")
1441 call assert_match('i_<Esc>.*insert.txt', a)
1442
1443 " Test for CTRL-W CTRL-]
1444 exe "norm! \<C-W>\<C-]>"
1445 call assert_equal("insert.txt", fnamemodify(bufname('%'), ':t'))
1446 norm! yiW
1447 call assert_equal("*i_<Esc>*", @0)
1448 call assert_equal(3, winnr('$'))
1449 helpclose
1450
1451 " Test for CTRL-W g CTRL-]
1452 exe "norm! \<C-W>g\<C-]>"
1453 call assert_equal("insert.txt", fnamemodify(bufname('%'), ':t'))
1454 norm! yiW
1455 call assert_equal("*i_<Esc>*", @0)
1456 call assert_equal(3, winnr('$'))
1457 helpclose
1458
1459 " clean up
1460 helpclose
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02001461endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001462
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01001463func Test_normal26_put()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001464 " Test for ]p ]P [p and [P
1465 new
1466 call append(0, ['while read LINE', 'do', ' ((count++))', ' if [ $? -ne 0 ]; then', " echo 'Error writing file'", ' fi', 'done'])
1467 1
1468 /Error/y a
1469 2
1470 norm! "a]pj"a[p
1471 call assert_equal(['do', "echo 'Error writing file'", " echo 'Error writing file'", ' ((count++))'], getline(2,5))
1472 1
1473 /^\s\{4}/
1474 exe "norm! \"a]P3Eldt'"
1475 exe "norm! j\"a[P2Eldt'"
1476 call assert_equal([' if [ $? -ne 0 ]; then', " echo 'Error writing'", " echo 'Error'", " echo 'Error writing file'", ' fi'], getline(6,10))
1477
1478 " clean up
1479 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02001480endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001481
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01001482func Test_normal27_bracket()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001483 " Test for [' [` ]' ]`
1484 call Setup_NewWindow()
1485 1,21s/.\+/ & b/
1486 1
1487 norm! $ma
1488 5
1489 norm! $mb
1490 10
1491 norm! $mc
1492 15
1493 norm! $md
1494 20
1495 norm! $me
1496
1497 " Test for ['
1498 9
1499 norm! 2['
1500 call assert_equal(' 1 b', getline('.'))
1501 call assert_equal(1, line('.'))
1502 call assert_equal(3, col('.'))
1503
1504 " Test for ]'
1505 norm! ]'
1506 call assert_equal(' 5 b', getline('.'))
1507 call assert_equal(5, line('.'))
1508 call assert_equal(3, col('.'))
1509
1510 " No mark after line 21, cursor moves to first non blank on current line
1511 21
1512 norm! $]'
1513 call assert_equal(' 21 b', getline('.'))
1514 call assert_equal(21, line('.'))
1515 call assert_equal(3, col('.'))
1516
1517 " Test for [`
1518 norm! 2[`
1519 call assert_equal(' 15 b', getline('.'))
1520 call assert_equal(15, line('.'))
1521 call assert_equal(8, col('.'))
1522
1523 " Test for ]`
1524 norm! ]`
1525 call assert_equal(' 20 b', getline('.'))
1526 call assert_equal(20, line('.'))
1527 call assert_equal(8, col('.'))
1528
1529 " clean up
1530 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02001531endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001532
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01001533func Test_normal28_parenthesis()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001534 " basic testing for ( and )
1535 new
1536 call append(0, ['This is a test. With some sentences!', '', 'Even with a question? And one more. And no sentence here'])
1537
1538 $
1539 norm! d(
1540 call assert_equal(['This is a test. With some sentences!', '', 'Even with a question? And one more. ', ''], getline(1, '$'))
1541 norm! 2d(
1542 call assert_equal(['This is a test. With some sentences!', '', ' ', ''], getline(1, '$'))
1543 1
1544 norm! 0d)
1545 call assert_equal(['With some sentences!', '', ' ', ''], getline(1, '$'))
1546
1547 call append('$', ['This is a long sentence', '', 'spanning', 'over several lines. '])
1548 $
1549 norm! $d(
1550 call assert_equal(['With some sentences!', '', ' ', '', 'This is a long sentence', ''], getline(1, '$'))
1551
1552 " clean up
1553 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02001554endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001555
1556fun! Test_normal29_brace()
1557 " basic test for { and } movements
1558 let text= ['A paragraph begins after each empty line, and also at each of a set of',
1559 \ 'paragraph macros, specified by the pairs of characters in the ''paragraphs''',
1560 \ 'option. The default is "IPLPPPQPP TPHPLIPpLpItpplpipbp", which corresponds to',
1561 \ 'the macros ".IP", ".LP", etc. (These are nroff macros, so the dot must be in',
1562 \ 'the first column). A section boundary is also a paragraph boundary.',
1563 \ 'Note that a blank line (only containing white space) is NOT a paragraph',
1564 \ 'boundary.',
1565 \ '',
1566 \ '',
1567 \ 'Also note that this does not include a ''{'' or ''}'' in the first column. When',
1568 \ 'the ''{'' flag is in ''cpoptions'' then ''{'' in the first column is used as a',
1569 \ 'paragraph boundary |posix|.',
1570 \ '{',
Bram Moolenaarae6f8652017-12-20 22:32:20 +01001571 \ 'This is no paragraph',
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001572 \ 'unless the ''{'' is set',
1573 \ 'in ''cpoptions''',
1574 \ '}',
1575 \ '.IP',
Bram Moolenaarae6f8652017-12-20 22:32:20 +01001576 \ 'The nroff macros IP separates a paragraph',
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001577 \ 'That means, it must be a ''.''',
1578 \ 'followed by IP',
1579 \ '.LPIt does not matter, if afterwards some',
1580 \ 'more characters follow.',
1581 \ '.SHAlso section boundaries from the nroff',
1582 \ 'macros terminate a paragraph. That means',
1583 \ 'a character like this:',
1584 \ '.NH',
1585 \ 'End of text here']
1586 new
1587 call append(0, text)
1588 1
1589 norm! 0d2}
1590 call assert_equal(['.IP',
Bram Moolenaarae6f8652017-12-20 22:32:20 +01001591 \ 'The nroff macros IP separates a paragraph', 'That means, it must be a ''.''', 'followed by IP',
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001592 \ '.LPIt does not matter, if afterwards some', 'more characters follow.', '.SHAlso section boundaries from the nroff',
1593 \ 'macros terminate a paragraph. That means', 'a character like this:', '.NH', 'End of text here', ''], getline(1,'$'))
1594 norm! 0d}
1595 call assert_equal(['.LPIt does not matter, if afterwards some', 'more characters follow.',
1596 \ '.SHAlso section boundaries from the nroff', 'macros terminate a paragraph. That means',
1597 \ 'a character like this:', '.NH', 'End of text here', ''], getline(1, '$'))
1598 $
1599 norm! d{
1600 call assert_equal(['.LPIt does not matter, if afterwards some', 'more characters follow.',
1601 \ '.SHAlso section boundaries from the nroff', 'macros terminate a paragraph. That means', 'a character like this:', ''], getline(1, '$'))
1602 norm! d{
1603 call assert_equal(['.LPIt does not matter, if afterwards some', 'more characters follow.', ''], getline(1,'$'))
1604 " Test with { in cpooptions
1605 %d
1606 call append(0, text)
1607 set cpo+={
1608 1
1609 norm! 0d2}
Bram Moolenaarae6f8652017-12-20 22:32:20 +01001610 call assert_equal(['{', 'This is no paragraph', 'unless the ''{'' is set', 'in ''cpoptions''', '}',
1611 \ '.IP', 'The nroff macros IP separates a paragraph', 'That means, it must be a ''.''',
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001612 \ 'followed by IP', '.LPIt does not matter, if afterwards some', 'more characters follow.',
1613 \ '.SHAlso section boundaries from the nroff', 'macros terminate a paragraph. That means',
1614 \ 'a character like this:', '.NH', 'End of text here', ''], getline(1,'$'))
1615 $
1616 norm! d}
Bram Moolenaarae6f8652017-12-20 22:32:20 +01001617 call assert_equal(['{', 'This is no paragraph', 'unless the ''{'' is set', 'in ''cpoptions''', '}',
1618 \ '.IP', 'The nroff macros IP separates a paragraph', 'That means, it must be a ''.''',
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001619 \ 'followed by IP', '.LPIt does not matter, if afterwards some', 'more characters follow.',
1620 \ '.SHAlso section boundaries from the nroff', 'macros terminate a paragraph. That means',
1621 \ 'a character like this:', '.NH', 'End of text here', ''], getline(1,'$'))
1622 norm! gg}
1623 norm! d5}
Bram Moolenaarae6f8652017-12-20 22:32:20 +01001624 call assert_equal(['{', 'This is no paragraph', 'unless the ''{'' is set', 'in ''cpoptions''', '}', ''], getline(1,'$'))
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001625
1626 " clean up
1627 set cpo-={
1628 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02001629endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001630
1631fun! Test_normal30_changecase()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001632 new
1633 call append(0, 'This is a simple test: äüöß')
1634 norm! 1ggVu
1635 call assert_equal('this is a simple test: äüöß', getline('.'))
1636 norm! VU
1637 call assert_equal('THIS IS A SIMPLE TEST: ÄÜÖSS', getline('.'))
1638 norm! guu
1639 call assert_equal('this is a simple test: äüöss', getline('.'))
1640 norm! gUgU
1641 call assert_equal('THIS IS A SIMPLE TEST: ÄÜÖSS', getline('.'))
1642 norm! gugu
1643 call assert_equal('this is a simple test: äüöss', getline('.'))
1644 norm! gUU
1645 call assert_equal('THIS IS A SIMPLE TEST: ÄÜÖSS', getline('.'))
1646 norm! 010~
1647 call assert_equal('this is a SIMPLE TEST: ÄÜÖSS', getline('.'))
1648 norm! V~
1649 call assert_equal('THIS IS A simple test: äüöss', getline('.'))
1650
Bram Moolenaarf1c118b2018-09-03 22:08:10 +02001651 " Turkish ASCII turns to multi-byte. On some systems Turkish locale
1652 " is available but toupper()/tolower() don't do the right thing.
1653 try
1654 lang tr_TR.UTF-8
1655 set casemap=
1656 let iupper = toupper('i')
1657 if iupper == "\u0130"
Bram Moolenaar9f4de1f2017-04-08 19:39:43 +02001658 call setline(1, 'iI')
1659 1normal gUU
1660 call assert_equal("\u0130I", getline(1))
1661 call assert_equal("\u0130I", toupper("iI"))
Bram Moolenaar3317d5e2017-04-08 19:12:06 +02001662
Bram Moolenaar9f4de1f2017-04-08 19:39:43 +02001663 call setline(1, 'iI')
1664 1normal guu
1665 call assert_equal("i\u0131", getline(1))
1666 call assert_equal("i\u0131", tolower("iI"))
Bram Moolenaarf1c118b2018-09-03 22:08:10 +02001667 elseif iupper == "I"
Bram Moolenaar1cc48202017-04-09 13:41:59 +02001668 call setline(1, 'iI')
1669 1normal gUU
1670 call assert_equal("II", getline(1))
1671 call assert_equal("II", toupper("iI"))
1672
1673 call setline(1, 'iI')
1674 1normal guu
1675 call assert_equal("ii", getline(1))
1676 call assert_equal("ii", tolower("iI"))
Bram Moolenaarf1c118b2018-09-03 22:08:10 +02001677 else
1678 call assert_true(false, "expected toupper('i') to be either 'I' or '\u0130'")
1679 endif
1680 set casemap&
1681 call setline(1, 'iI')
1682 1normal gUU
1683 call assert_equal("II", getline(1))
1684 call assert_equal("II", toupper("iI"))
Bram Moolenaar1cc48202017-04-09 13:41:59 +02001685
Bram Moolenaarf1c118b2018-09-03 22:08:10 +02001686 call setline(1, 'iI')
1687 1normal guu
1688 call assert_equal("ii", getline(1))
1689 call assert_equal("ii", tolower("iI"))
1690
1691 lang en_US.UTF-8
1692 catch /E197:/
1693 " can't use Turkish locale
1694 throw 'Skipped: Turkish locale not available'
1695 endtry
Bram Moolenaar3317d5e2017-04-08 19:12:06 +02001696
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001697 " clean up
1698 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02001699endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001700
1701fun! Test_normal31_r_cmd()
1702 " Test for r command
1703 new
1704 call append(0, 'This is a simple test: abcd')
1705 exe "norm! 1gg$r\<cr>"
1706 call assert_equal(['This is a simple test: abc', '', ''], getline(1,'$'))
1707 exe "norm! 1gg2wlr\<cr>"
1708 call assert_equal(['This is a', 'simple test: abc', '', ''], getline(1,'$'))
1709 exe "norm! 2gg0W5r\<cr>"
1710 call assert_equal(['This is a', 'simple ', ' abc', '', ''], getline('1', '$'))
1711 set autoindent
1712 call setline(2, ['simple test: abc', ''])
1713 exe "norm! 2gg0W5r\<cr>"
1714 call assert_equal(['This is a', 'simple ', 'abc', '', '', ''], getline('1', '$'))
1715 exe "norm! 1ggVr\<cr>"
1716 call assert_equal('^M^M^M^M^M^M^M^M^M', strtrans(getline(1)))
1717 call setline(1, 'This is a')
1718 exe "norm! 1gg05rf"
1719 call assert_equal('fffffis a', getline(1))
1720
1721 " clean up
1722 set noautoindent
1723 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02001724endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001725
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01001726func Test_normal32_g_cmd1()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001727 " Test for g*, g#
1728 new
1729 call append(0, ['abc.x_foo', 'x_foobar.abc'])
1730 1
1731 norm! $g*
1732 call assert_equal('x_foo', @/)
1733 call assert_equal('x_foobar.abc', getline('.'))
1734 norm! $g#
1735 call assert_equal('abc', @/)
1736 call assert_equal('abc.x_foo', getline('.'))
1737
1738 " clean up
1739 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02001740endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001741
1742fun! Test_normal33_g_cmd2()
1743 if !has("jumplist")
1744 return
1745 endif
1746 " Tests for g cmds
1747 call Setup_NewWindow()
1748 " Test for g`
1749 clearjumps
1750 norm! ma10j
1751 let a=execute(':jumps')
1752 " empty jumplist
1753 call assert_equal('>', a[-1:])
1754 norm! g`a
1755 call assert_equal('>', a[-1:])
1756 call assert_equal(1, line('.'))
1757 call assert_equal('1', getline('.'))
1758
1759 " Test for g; and g,
1760 norm! g;
1761 " there is only one change in the changelist
1762 " currently, when we setup the window
1763 call assert_equal(2, line('.'))
1764 call assert_fails(':norm! g;', 'E662')
1765 call assert_fails(':norm! g,', 'E663')
1766 let &ul=&ul
1767 call append('$', ['a', 'b', 'c', 'd'])
1768 let &ul=&ul
1769 call append('$', ['Z', 'Y', 'X', 'W'])
1770 let a = execute(':changes')
1771 call assert_match('2\s\+0\s\+2', a)
1772 call assert_match('101\s\+0\s\+a', a)
1773 call assert_match('105\s\+0\s\+Z', a)
1774 norm! 3g;
1775 call assert_equal(2, line('.'))
1776 norm! 2g,
1777 call assert_equal(105, line('.'))
1778
1779 " Test for g& - global substitute
1780 %d
1781 call setline(1, range(1,10))
1782 call append('$', ['a', 'b', 'c', 'd'])
1783 $s/\w/&&/g
1784 exe "norm! /[1-8]\<cr>"
1785 norm! g&
1786 call assert_equal(['11', '22', '33', '44', '55', '66', '77', '88', '9', '110', 'a', 'b', 'c', 'dd'], getline(1, '$'))
1787
1788 " Test for gv
1789 %d
1790 call append('$', repeat(['abcdefgh'], 8))
1791 exe "norm! 2gg02l\<c-v>2j2ly"
1792 call assert_equal(['cde', 'cde', 'cde'], getreg(0, 1, 1))
1793 " in visual mode, gv swaps current and last selected region
1794 exe "norm! G0\<c-v>4k4lgvd"
1795 call assert_equal(['', 'abfgh', 'abfgh', 'abfgh', 'abcdefgh', 'abcdefgh', 'abcdefgh', 'abcdefgh', 'abcdefgh'], getline(1,'$'))
1796 exe "norm! G0\<c-v>4k4ly"
1797 exe "norm! gvood"
1798 call assert_equal(['', 'abfgh', 'abfgh', 'abfgh', 'fgh', 'fgh', 'fgh', 'fgh', 'fgh'], getline(1,'$'))
1799
1800 " Test for gk/gj
1801 %d
1802 15vsp
1803 set wrap listchars= sbr=
1804 let lineA='abcdefghijklmnopqrstuvwxyz'
1805 let lineB='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'
1806 $put =lineA
1807 $put =lineB
1808
1809 norm! 3gg0dgk
1810 call assert_equal(['', 'abcdefghijklmno', '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'], getline(1, '$'))
1811 set nu
1812 norm! 3gg0gjdgj
1813 call assert_equal(['', 'abcdefghijklmno', '0123456789AMNOPQRSTUVWXYZ'], getline(1,'$'))
1814
1815 " Test for gJ
1816 norm! 2gggJ
1817 call assert_equal(['', 'abcdefghijklmno0123456789AMNOPQRSTUVWXYZ'], getline(1,'$'))
1818 call assert_equal(16, col('.'))
1819 " shouldn't do anything
1820 norm! 10gJ
1821 call assert_equal(1, col('.'))
1822
1823 " Test for g0 g^ gm g$
1824 exe "norm! 2gg0gji "
1825 call assert_equal(['', 'abcdefghijk lmno0123456789AMNOPQRSTUVWXYZ'], getline(1,'$'))
1826 norm! g0yl
1827 call assert_equal(12, col('.'))
1828 call assert_equal(' ', getreg(0))
1829 norm! g$yl
1830 call assert_equal(22, col('.'))
1831 call assert_equal('3', getreg(0))
1832 norm! gmyl
1833 call assert_equal(17, col('.'))
1834 call assert_equal('n', getreg(0))
1835 norm! g^yl
1836 call assert_equal(15, col('.'))
1837 call assert_equal('l', getreg(0))
1838
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001839 " Test for gI
1840 norm! gIfoo
1841 call assert_equal(['', 'fooabcdefghijk lmno0123456789AMNOPQRSTUVWXYZ'], getline(1,'$'))
1842
1843 " Test for gi
1844 wincmd c
1845 %d
1846 set tw=0
1847 call setline(1, ['foobar', 'new line'])
1848 norm! A next word
1849 $put ='third line'
1850 norm! gi another word
1851 call assert_equal(['foobar next word another word', 'new line', 'third line'], getline(1,'$'))
1852
1853 " clean up
1854 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02001855endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001856
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 Moolenaar87bc3f72016-09-03 17:33:54 +02001930fun! Test_normal34_g_cmd3()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001931 " Test for g8
1932 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 Moolenaar395b6ba2017-04-07 20:09:51 +02001948func Test_normal_8g8()
Bram Moolenaar395b6ba2017-04-07 20:09:51 +02001949 new
1950
1951 " Test 8g8 which finds invalid utf8 at or after the cursor.
1952
1953 " With invalid byte.
1954 call setline(1, "___\xff___")
1955 norm! 1G08g8g
1956 call assert_equal([0, 1, 4, 0, 1], getcurpos())
1957
1958 " With invalid byte before the cursor.
1959 call setline(1, "___\xff___")
1960 norm! 1G$h8g8g
1961 call assert_equal([0, 1, 6, 0, 9], getcurpos())
1962
1963 " With truncated sequence.
1964 call setline(1, "___\xE2\x82___")
1965 norm! 1G08g8g
1966 call assert_equal([0, 1, 4, 0, 1], getcurpos())
1967
1968 " With overlong sequence.
1969 call setline(1, "___\xF0\x82\x82\xAC___")
1970 norm! 1G08g8g
1971 call assert_equal([0, 1, 4, 0, 1], getcurpos())
1972
1973 " With valid utf8.
1974 call setline(1, "café")
1975 norm! 1G08g8
1976 call assert_equal([0, 1, 1, 0, 1], getcurpos())
1977
1978 bw!
1979endfunc
1980
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001981fun! Test_normal35_g_cmd4()
1982 " Test for g<
1983 " Cannot capture its output,
1984 " probably a bug, therefore, test disabled:
Bram Moolenaar31845092016-09-05 22:58:31 +02001985 throw "Skipped: output of g< can't be tested currently"
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001986 echo "a\nb\nc\nd"
1987 let b=execute(':norm! g<')
1988 call assert_true(!empty(b), 'failed `execute(g<)`')
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02001989endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02001990
1991fun! 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
2029fun! Test_normal37_g_cmd6()
2030 " basic test for gt and gT
2031 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
2053 call assert_fails(':tabclose', 'E784')
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002054endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002055
2056fun! Test_normal38_nvhome()
2057 " Test for <Home> and <C-Home> key
2058 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())
2072
2073 " clean up
2074 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002075endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002076
2077fun! Test_normal39_cw()
2078 " Test for cw and cW on whitespace
2079 " and cpo+=w setting
2080 new
2081 set tw=0
2082 call append(0, 'here are some words')
2083 norm! 1gg0elcwZZZ
2084 call assert_equal('hereZZZare some words', getline('.'))
2085 norm! 1gg0elcWYYY
2086 call assert_equal('hereZZZareYYYsome words', getline('.'))
2087 set cpo+=w
2088 call setline(1, 'here are some words')
2089 norm! 1gg0elcwZZZ
2090 call assert_equal('hereZZZ are some words', getline('.'))
2091 norm! 1gg2elcWYYY
2092 call assert_equal('hereZZZ areYYY some words', getline('.'))
2093 set cpo-=w
2094 norm! 2gg0cwfoo
2095 call assert_equal('foo', getline('.'))
2096
2097 " clean up
2098 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002099endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002100
2101fun! Test_normal40_ctrl_bsl()
2102 " Basic test for CTRL-\ commands
2103 new
2104 call append(0, 'here are some words')
2105 exe "norm! 1gg0a\<C-\>\<C-N>"
2106 call assert_equal('n', mode())
2107 call assert_equal(1, col('.'))
2108 call assert_equal('', visualmode())
2109 exe "norm! 1gg0viw\<C-\>\<C-N>"
2110 call assert_equal('n', mode())
2111 call assert_equal(4, col('.'))
2112 exe "norm! 1gg0a\<C-\>\<C-G>"
2113 call assert_equal('n', mode())
2114 call assert_equal(1, col('.'))
2115 "imap <buffer> , <c-\><c-n>
2116 set im
2117 exe ":norm! \<c-\>\<c-n>dw"
2118 set noim
2119 call assert_equal('are some words', getline(1))
2120 call assert_false(&insertmode)
2121
2122 " clean up
2123 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002124endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002125
2126fun! Test_normal41_insert_reg()
2127 " Test for <c-r>=, <c-r><c-r>= and <c-r><c-o>=
2128 " in insert mode
2129 new
2130 set sts=2 sw=2 ts=8 tw=0
2131 call append(0, ["aaa\tbbb\tccc", '', '', ''])
2132 let a=getline(1)
2133 norm! 2gg0
2134 exe "norm! a\<c-r>=a\<cr>"
2135 norm! 3gg0
2136 exe "norm! a\<c-r>\<c-r>=a\<cr>"
2137 norm! 4gg0
2138 exe "norm! a\<c-r>\<c-o>=a\<cr>"
2139 call assert_equal(['aaa bbb ccc', 'aaa bbb ccc', 'aaa bbb ccc', 'aaa bbb ccc', ''], getline(1, '$'))
2140
2141 " clean up
2142 set sts=0 sw=8 ts=8
Bram Moolenaar31845092016-09-05 22:58:31 +02002143 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002144endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002145
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01002146func Test_normal42_halfpage()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002147 " basic test for Ctrl-D and Ctrl-U
2148 call Setup_NewWindow()
2149 call assert_equal(5, &scroll)
2150 exe "norm! \<c-d>"
2151 call assert_equal('6', getline('.'))
2152 exe "norm! 2\<c-d>"
2153 call assert_equal('8', getline('.'))
2154 call assert_equal(2, &scroll)
2155 set scroll=5
2156 exe "norm! \<c-u>"
2157 call assert_equal('3', getline('.'))
2158 1
2159 set scrolloff=5
2160 exe "norm! \<c-d>"
2161 call assert_equal('10', getline('.'))
2162 exe "norm! \<c-u>"
2163 call assert_equal('5', getline('.'))
2164 1
2165 set scrolloff=99
2166 exe "norm! \<c-d>"
2167 call assert_equal('10', getline('.'))
2168 set scrolloff=0
2169 100
2170 exe "norm! $\<c-u>"
2171 call assert_equal('95', getline('.'))
2172 call assert_equal([0, 95, 1, 0, 1], getcurpos())
2173 100
2174 set nostartofline
2175 exe "norm! $\<c-u>"
2176 call assert_equal('95', getline('.'))
2177 call assert_equal([0, 95, 2, 0, 2147483647], getcurpos())
2178 " cleanup
2179 set startofline
2180 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002181endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002182
2183fun! Test_normal43_textobject1()
2184 " basic tests for text object aw
2185 new
2186 call append(0, ['foobar,eins,foobar', 'foo,zwei,foo '])
2187 " diw
2188 norm! 1gg0diw
2189 call assert_equal([',eins,foobar', 'foo,zwei,foo ', ''], getline(1,'$'))
2190 " daw
2191 norm! 2ggEdaw
2192 call assert_equal([',eins,foobar', 'foo,zwei,', ''], getline(1, '$'))
2193 %d
2194 call append(0, ["foo\teins\tfoobar", "foo\tzwei\tfoo "])
2195 " diW
2196 norm! 2ggwd2iW
2197 call assert_equal(['foo eins foobar', 'foo foo ', ''], getline(1,'$'))
2198 " daW
2199 norm! 1ggd2aW
2200 call assert_equal(['foobar', 'foo foo ', ''], getline(1,'$'))
2201
2202 %d
2203 call append(0, ["foo\teins\tfoobar", "foo\tzwei\tfoo "])
2204 " aw in visual line mode switches to characterwise mode
2205 norm! 2gg$Vawd
2206 call assert_equal(['foo eins foobar', 'foo zwei foo'], getline(1,'$'))
2207 norm! 1gg$Viwd
2208 call assert_equal(['foo eins ', 'foo zwei foo'], getline(1,'$'))
2209
2210 " clean up
2211 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002212endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002213
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01002214func Test_normal44_textobjects2()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002215 " basic testing for is and as text objects
2216 new
2217 call append(0, ['This is a test. With some sentences!', '', 'Even with a question? And one more. And no sentence here'])
2218 " Test for dis - does not remove trailing whitespace
2219 norm! 1gg0dis
2220 call assert_equal([' With some sentences!', '', 'Even with a question? And one more. And no sentence here', ''], getline(1,'$'))
2221 " Test for das - removes leading whitespace
2222 norm! 3ggf?ldas
2223 call assert_equal([' With some sentences!', '', 'Even with a question? And no sentence here', ''], getline(1,'$'))
2224 " when used in visual mode, is made characterwise
2225 norm! 3gg$Visy
2226 call assert_equal('v', visualmode())
2227 " reset visualmode()
2228 norm! 3ggVy
2229 norm! 3gg$Vasy
2230 call assert_equal('v', visualmode())
2231 " basic testing for textobjects a< and at
2232 %d
2233 call setline(1, ['<div> ','<a href="foobar" class="foo">xyz</a>',' </div>', ' '])
2234 " a<
2235 norm! 1gg0da<
2236 call assert_equal([' ', '<a href="foobar" class="foo">xyz</a>', ' </div>', ' '], getline(1,'$'))
2237 norm! 1pj
2238 call assert_equal([' <div>', '<a href="foobar" class="foo">xyz</a>', ' </div>', ' '], getline(1,'$'))
2239 " at
2240 norm! d2at
2241 call assert_equal([' '], getline(1,'$'))
2242 %d
2243 call setline(1, ['<div> ','<a href="foobar" class="foo">xyz</a>',' </div>', ' '])
2244 " i<
2245 norm! 1gg0di<
2246 call assert_equal(['<> ', '<a href="foobar" class="foo">xyz</a>', ' </div>', ' '], getline(1,'$'))
2247 norm! 1Pj
2248 call assert_equal(['<div> ', '<a href="foobar" class="foo">xyz</a>', ' </div>', ' '], getline(1,'$'))
2249 norm! d2it
2250 call assert_equal(['<div></div>',' '], getline(1,'$'))
2251 " basic testing for a[ and i[ text object
2252 %d
2253 call setline(1, [' ', '[', 'one [two]', 'thre', ']'])
2254 norm! 3gg0di[
2255 call assert_equal([' ', '[', ']'], getline(1,'$'))
2256 call setline(1, [' ', '[', 'one [two]', 'thre', ']'])
2257 norm! 3gg0ftd2a[
2258 call assert_equal([' '], getline(1,'$'))
2259 %d
2260 " Test for i" when cursor is in front of a quoted object
2261 call append(0, 'foo "bar"')
2262 norm! 1gg0di"
2263 call assert_equal(['foo ""', ''], getline(1,'$'))
2264
2265 " clean up
2266 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002267endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002268
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01002269func Test_normal45_drop()
Bram Moolenaar29495952018-02-12 22:49:00 +01002270 if !has('dnd')
Bram Moolenaarb48e96f2018-02-13 12:26:14 +01002271 " The ~ register does not exist
2272 call assert_beeps('norm! "~')
Bram Moolenaar29495952018-02-12 22:49:00 +01002273 return
2274 endif
2275
2276 " basic test for drag-n-drop
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002277 " unfortunately, without a gui, we can't really test much here,
2278 " so simply test that ~p fails (which uses the drop register)
2279 new
2280 call assert_fails(':norm! "~p', 'E353')
2281 call assert_equal([], getreg('~', 1, 1))
2282 " the ~ register is read only
2283 call assert_fails(':let @~="1"', 'E354')
2284 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002285endfunc
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002286
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01002287func Test_normal46_ignore()
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002288 new
2289 " How to test this?
2290 " let's just for now test, that the buffer
2291 " does not change
2292 call feedkeys("\<c-s>", 't')
2293 call assert_equal([''], getline(1,'$'))
2294
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002295 " no valid commands
2296 exe "norm! \<char-0x100>"
2297 call assert_equal([''], getline(1,'$'))
2298
2299 exe "norm! ä"
2300 call assert_equal([''], getline(1,'$'))
2301
Bram Moolenaar87bc3f72016-09-03 17:33:54 +02002302 " clean up
2303 bw!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002304endfunc
Bram Moolenaarc4a908e2016-09-08 23:35:30 +02002305
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01002306func Test_normal47_visual_buf_wipe()
Bram Moolenaarc4a908e2016-09-08 23:35:30 +02002307 " This was causing a crash or ml_get error.
2308 enew!
2309 call setline(1,'xxx')
2310 normal $
2311 new
2312 call setline(1, range(1,2))
2313 2
2314 exe "norm \<C-V>$"
2315 bw!
2316 norm yp
2317 set nomodified
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002318endfunc
2319
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01002320func Test_normal47_autocmd()
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002321 " disabled, does not seem to be possible currently
2322 throw "Skipped: not possible to test cursorhold autocmd while waiting for input in normal_cmd"
2323 new
2324 call append(0, repeat('-',20))
2325 au CursorHold * call feedkeys('2l', '')
2326 1
2327 set updatetime=20
2328 " should delete 12 chars (d12l)
2329 call feedkeys('d1', '!')
2330 call assert_equal('--------', getline(1))
2331
2332 " clean up
2333 au! CursorHold
2334 set updatetime=4000
2335 bw!
2336endfunc
2337
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01002338func Test_normal48_wincmd()
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002339 new
2340 exe "norm! \<c-w>c"
2341 call assert_equal(1, winnr('$'))
2342 call assert_fails(":norm! \<c-w>c", "E444")
2343endfunc
2344
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01002345func Test_normal49_counts()
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002346 new
2347 call setline(1, 'one two three four five six seven eight nine ten')
2348 1
2349 norm! 3d2w
2350 call assert_equal('seven eight nine ten', getline(1))
2351 bw!
2352endfunc
2353
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01002354func Test_normal50_commandline()
Bram Moolenaar4033c552017-09-16 20:54:51 +02002355 if !has("timers") || !has("cmdline_hist")
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002356 return
2357 endif
2358 func! DoTimerWork(id)
2359 call assert_equal('[Command Line]', bufname(''))
2360 " should fail, with E11, but does fail with E23?
2361 "call feedkeys("\<c-^>", 'tm')
2362
2363 " should also fail with E11
2364 call assert_fails(":wincmd p", 'E11')
2365 " return from commandline window
2366 call feedkeys("\<cr>")
2367 endfunc
2368
2369 let oldlang=v:lang
2370 lang C
2371 set updatetime=20
2372 call timer_start(100, 'DoTimerWork')
2373 try
2374 " throws E23, for whatever reason...
2375 call feedkeys('q:', 'x!')
2376 catch /E23/
2377 " no-op
2378 endtry
2379 " clean up
2380 set updatetime=4000
2381 exe "lang" oldlang
2382 bw!
2383endfunc
2384
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01002385func Test_normal51_FileChangedRO()
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002386 if !has("autocmd")
2387 return
2388 endif
Bram Moolenaare5f2a072017-02-01 22:31:49 +01002389 " Don't sleep after the warning message.
2390 call test_settime(1)
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002391 call writefile(['foo'], 'Xreadonly.log')
2392 new Xreadonly.log
2393 setl ro
2394 au FileChangedRO <buffer> :call feedkeys("\<c-^>", 'tix')
2395 call assert_fails(":norm! Af", 'E788')
2396 call assert_equal(['foo'], getline(1,'$'))
2397 call assert_equal('Xreadonly.log', bufname(''))
2398
2399 " cleanup
Bram Moolenaare5f2a072017-02-01 22:31:49 +01002400 call test_settime(0)
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002401 bw!
2402 call delete("Xreadonly.log")
2403endfunc
2404
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01002405func Test_normal52_rl()
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002406 if !has("rightleft")
2407 return
2408 endif
2409 new
2410 call setline(1, 'abcde fghij klmnopq')
2411 norm! 1gg$
2412 set rl
2413 call assert_equal(19, col('.'))
2414 call feedkeys('l', 'tx')
2415 call assert_equal(18, col('.'))
2416 call feedkeys('h', 'tx')
2417 call assert_equal(19, col('.'))
2418 call feedkeys("\<right>", 'tx')
2419 call assert_equal(18, col('.'))
2420 call feedkeys("\<s-right>", 'tx')
2421 call assert_equal(13, col('.'))
2422 call feedkeys("\<c-right>", 'tx')
2423 call assert_equal(7, col('.'))
2424 call feedkeys("\<c-left>", 'tx')
2425 call assert_equal(13, col('.'))
2426 call feedkeys("\<s-left>", 'tx')
2427 call assert_equal(19, col('.'))
2428 call feedkeys("<<", 'tx')
2429 call assert_equal(' abcde fghij klmnopq',getline(1))
2430 call feedkeys(">>", 'tx')
2431 call assert_equal('abcde fghij klmnopq',getline(1))
2432
2433 " cleanup
2434 set norl
2435 bw!
2436endfunc
2437
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01002438func Test_normal53_digraph()
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002439 if !has('digraphs')
2440 return
2441 endif
2442 new
2443 call setline(1, 'abcdefgh|')
2444 exe "norm! 1gg0f\<c-k>!!"
2445 call assert_equal(9, col('.'))
2446 set cpo+=D
2447 exe "norm! 1gg0f\<c-k>!!"
2448 call assert_equal(1, col('.'))
2449
2450 set cpo-=D
2451 bw!
2452endfunc
2453
Bram Moolenaarb1e04fc2017-03-29 13:08:35 +02002454func Test_normal54_Ctrl_bsl()
2455 new
2456 call setline(1, 'abcdefghijklmn')
2457 exe "norm! df\<c-\>\<c-n>"
2458 call assert_equal(['abcdefghijklmn'], getline(1,'$'))
2459 exe "norm! df\<c-\>\<c-g>"
2460 call assert_equal(['abcdefghijklmn'], getline(1,'$'))
2461 exe "norm! df\<c-\>m"
2462 call assert_equal(['abcdefghijklmn'], getline(1,'$'))
Bram Moolenaar30276f22019-01-24 17:59:39 +01002463
Bram Moolenaarb1e04fc2017-03-29 13:08:35 +02002464 call setline(2, 'abcdefghijklmnāf')
2465 norm! 2gg0
2466 exe "norm! df\<Char-0x101>"
2467 call assert_equal(['abcdefghijklmn', 'f'], getline(1,'$'))
2468 norm! 1gg0
2469 exe "norm! df\<esc>"
2470 call assert_equal(['abcdefghijklmn', 'f'], getline(1,'$'))
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002471
Bram Moolenaarb1e04fc2017-03-29 13:08:35 +02002472 " clean up
2473 bw!
2474endfunc
2475
2476func Test_normal_large_count()
2477 " This may fail with 32bit long, how do we detect that?
2478 new
2479 normal o
2480 normal 6666666666dL
2481 bwipe!
Bram Moolenaar2931f2a2016-09-09 16:59:08 +02002482endfunc
Bram Moolenaarbf3d5802017-03-29 19:48:11 +02002483
2484func Test_delete_until_paragraph()
Bram Moolenaarbf3d5802017-03-29 19:48:11 +02002485 new
2486 normal grádv}
2487 call assert_equal('á', getline(1))
2488 normal grád}
2489 call assert_equal('', getline(1))
2490 bwipe!
2491endfunc
Bram Moolenaarfb094e12017-11-05 20:59:28 +01002492
2493" Test for the gr (virtual replace) command
2494" Test for the bug fixed by 7.4.387
2495func Test_gr_command()
2496 enew!
2497 let save_cpo = &cpo
2498 call append(0, ['First line', 'Second line', 'Third line'])
2499 exe "normal i\<C-G>u"
2500 call cursor(2, 1)
2501 set cpo-=X
2502 normal 4gro
2503 call assert_equal('oooond line', getline(2))
2504 undo
2505 set cpo+=X
2506 normal 4gro
2507 call assert_equal('ooooecond line', getline(2))
2508 let &cpo = save_cpo
2509 enew!
2510endfunc
2511
2512" When splitting a window the changelist position is wrong.
2513" Test the changelist position after splitting a window.
2514" Test for the bug fixed by 7.4.386
2515func Test_changelist()
2516 let save_ul = &ul
2517 enew!
2518 call append('$', ['1', '2'])
2519 exe "normal i\<C-G>u"
2520 exe "normal Gkylpa\<C-G>u"
2521 set ul=100
2522 exe "normal Gylpa\<C-G>u"
2523 set ul=100
2524 normal gg
2525 vsplit
2526 normal g;
2527 call assert_equal([3, 2], [line('.'), col('.')])
2528 normal g;
2529 call assert_equal([2, 2], [line('.'), col('.')])
2530 call assert_fails('normal g;', 'E662:')
2531 %bwipe!
2532 let &ul = save_ul
2533endfunc
Bram Moolenaar1bbb6192018-11-10 16:02:01 +01002534
2535func Test_nv_hat_count()
2536 %bwipeout!
2537 let l:nr = bufnr('%') + 1
2538 call assert_fails(':execute "normal! ' . l:nr . '\<C-^>"', 'E92')
2539
2540 edit Xfoo
2541 let l:foo_nr = bufnr('Xfoo')
2542
2543 edit Xbar
2544 let l:bar_nr = bufnr('Xbar')
2545
2546 " Make sure we are not just using the alternate file.
2547 edit Xbaz
2548
2549 call feedkeys(l:foo_nr . "\<C-^>", 'tx')
2550 call assert_equal('Xfoo', fnamemodify(bufname('%'), ':t'))
2551
2552 call feedkeys(l:bar_nr . "\<C-^>", 'tx')
2553 call assert_equal('Xbar', fnamemodify(bufname('%'), ':t'))
2554
2555 %bwipeout!
2556endfunc
Bram Moolenaara84a3dd2019-03-25 22:21:24 +01002557
2558func Test_message_when_using_ctrl_c()
Bram Moolenaar553e5a52019-03-25 23:16:34 +01002559 " Make sure no buffers are changed.
2560 %bwipe!
2561
Bram Moolenaara84a3dd2019-03-25 22:21:24 +01002562 exe "normal \<C-C>"
2563 call assert_match("Type :qa and press <Enter> to exit Vim", Screenline(&lines))
Bram Moolenaar553e5a52019-03-25 23:16:34 +01002564
Bram Moolenaara84a3dd2019-03-25 22:21:24 +01002565 new
2566 cal setline(1, 'hi!')
2567 exe "normal \<C-C>"
2568 call assert_match("Type :qa! and press <Enter> to abandon all changes and exit Vim", Screenline(&lines))
Bram Moolenaar553e5a52019-03-25 23:16:34 +01002569
Bram Moolenaara84a3dd2019-03-25 22:21:24 +01002570 bwipe!
2571endfunc
Bram Moolenaarc6b37db2019-04-27 18:00:34 +02002572
2573" Test for '[m', ']m', '[M' and ']M'
2574" Jumping to beginning and end of methods in Java-like languages
2575func Test_java_motion()
2576 new
2577 a
2578Piece of Java
2579{
2580 tt m1 {
2581 t1;
2582 } e1
2583
2584 tt m2 {
2585 t2;
2586 } e2
2587
2588 tt m3 {
2589 if (x)
2590 {
2591 t3;
2592 }
2593 } e3
2594}
2595.
2596
2597 normal gg
2598
2599 normal 2]maA
2600 call assert_equal("\ttt m1 {A", getline('.'))
2601 call assert_equal([3, 9, 16], [line('.'), col('.'), virtcol('.')])
2602
2603 normal j]maB
2604 call assert_equal("\ttt m2 {B", getline('.'))
2605 call assert_equal([7, 9, 16], [line('.'), col('.'), virtcol('.')])
2606
2607 normal ]maC
2608 call assert_equal("\ttt m3 {C", getline('.'))
2609 call assert_equal([11, 9, 16], [line('.'), col('.'), virtcol('.')])
2610
2611 normal [maD
2612 call assert_equal("\ttt m3 {DC", getline('.'))
2613 call assert_equal([11, 9, 16], [line('.'), col('.'), virtcol('.')])
2614
2615 normal k2[maE
2616 call assert_equal("\ttt m1 {EA", getline('.'))
2617 call assert_equal([3, 9, 16], [line('.'), col('.'), virtcol('.')])
2618
2619 normal 3[maF
2620 call assert_equal("{F", getline('.'))
2621 call assert_equal([2, 2, 2], [line('.'), col('.'), virtcol('.')])
2622
2623 normal ]MaG
2624 call assert_equal("\t}G e1", getline('.'))
2625 call assert_equal([5, 3, 10], [line('.'), col('.'), virtcol('.')])
2626
2627 normal j2]MaH
2628 call assert_equal("\t}H e3", getline('.'))
2629 call assert_equal([16, 3, 10], [line('.'), col('.'), virtcol('.')])
2630
2631 normal ]M]M
2632 normal aI
2633 call assert_equal("}I", getline('.'))
2634 call assert_equal([17, 2, 2], [line('.'), col('.'), virtcol('.')])
2635
2636 normal 2[MaJ
2637 call assert_equal("\t}JH e3", getline('.'))
2638 call assert_equal([16, 3, 10], [line('.'), col('.'), virtcol('.')])
2639
2640 normal k[MaK
2641 call assert_equal("\t}K e2", getline('.'))
2642 call assert_equal([9, 3, 10], [line('.'), col('.'), virtcol('.')])
2643
2644 normal 3[MaL
2645 call assert_equal("{LF", getline('.'))
2646 call assert_equal([2, 2, 2], [line('.'), col('.'), virtcol('.')])
2647
2648 close!
2649endfunc