Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 1 | " Test for various Normal mode commands |
| 2 | |
| 3 | func! Setup_NewWindow() |
| 4 | 10new |
| 5 | call setline(1, range(1,100)) |
| 6 | endfunc |
| 7 | |
| 8 | func! MyFormatExpr() |
| 9 | " Adds '->$' at lines having numbers followed by trailing whitespace |
| 10 | for ln in range(v:lnum, v:lnum+v:count-1) |
| 11 | let line = getline(ln) |
| 12 | if getline(ln) =~# '\d\s\+$' |
| 13 | call setline(ln, substitute(line, '\s\+$', '', '') . '->$') |
| 14 | endif |
| 15 | endfor |
| 16 | endfu |
| 17 | |
| 18 | function! CountSpaces(type, ...) |
| 19 | " for testing operatorfunc |
| 20 | " will count the number of spaces |
| 21 | " and return the result in g:a |
| 22 | let sel_save = &selection |
| 23 | let &selection = "inclusive" |
| 24 | let reg_save = @@ |
| 25 | |
| 26 | if a:0 " Invoked from Visual mode, use gv command. |
| 27 | silent exe "normal! gvy" |
| 28 | elseif a:type == 'line' |
| 29 | silent exe "normal! '[V']y" |
| 30 | else |
| 31 | silent exe "normal! `[v`]y" |
| 32 | endif |
| 33 | let g:a=strlen(substitute(@@, '[^ ]', '', 'g')) |
| 34 | let &selection = sel_save |
| 35 | let @@ = reg_save |
| 36 | endfunction |
| 37 | |
| 38 | fun! Test_normal00_optrans() |
| 39 | " Attention: This needs to be the very first test, |
| 40 | " it will fail, if it runs later, don't know why! |
| 41 | " Test for S s and alike comamnds, that are internally handled aliased |
| 42 | new |
| 43 | call append(0, ['1 This is a simple test: abcd', '2 This is the second line', '3 this is the third line']) |
| 44 | 1 |
| 45 | exe "norm! Sfoobar\<esc>" |
| 46 | call assert_equal(['foobar', '2 This is the second line', '3 this is the third line', ''], getline(1,'$')) |
| 47 | 2 |
| 48 | " Test does not work |
| 49 | " TODO: Why does it not work? |
| 50 | " Adds an additional linebreak if used in visual mode... |
| 51 | " When run in the test, this returns: |
| 52 | " ,-------- |
| 53 | " |foobar |
| 54 | " |2 This is |
| 55 | " |the second |
| 56 | " |one |
| 57 | " |3 this is the third line |
| 58 | " `----------- |
| 59 | " instead of |
| 60 | " ,-------- |
| 61 | " |foobar |
| 62 | " |2 This is the second one |
| 63 | " |3 this is the third line |
| 64 | " `----------- |
| 65 | exe "norm! $vbsone" |
| 66 | call assert_equal(['foobar', '2 This is the second one', '3 this is the third line', ''], getline(1,'$')) |
| 67 | " When run in the test, this returns: |
| 68 | " ,-------- |
| 69 | " |foobar |
| 70 | " |Second line |
| 71 | " |here |
| 72 | " |3 this is the third line |
| 73 | " `----------- |
| 74 | " instead of |
| 75 | " ,-------- |
| 76 | " |foobar |
| 77 | " |Second line here |
| 78 | " |3 this is the third line |
| 79 | " `----------- |
| 80 | norm! VS Second line here |
| 81 | call assert_equal(['foobar', ' Second line here', '3 this is the third line', ''], getline(1, '$')) |
| 82 | %d |
| 83 | call append(0, ['4 This is a simple test: abcd', '5 This is the second line', '6 this is the third line']) |
| 84 | call append(0, ['1 This is a simple test: abcd', '2 This is the second line', '3 this is the third line']) |
| 85 | |
| 86 | 1 |
| 87 | norm! 2D |
| 88 | 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,'$')) |
| 89 | set cpo+=# |
| 90 | norm! 4D |
| 91 | call assert_equal(['', '4 This is a simple test: abcd', '5 This is the second line', '6 this is the third line', ''], getline(1,'$')) |
| 92 | |
| 93 | " clean up |
| 94 | set cpo-=# |
| 95 | bw! |
| 96 | endfu |
| 97 | |
| 98 | func! Test_normal01_keymodel() |
| 99 | call Setup_NewWindow() |
| 100 | " Test 1: depending on 'keymodel' <s-down> does something different |
| 101 | :50 |
| 102 | call feedkeys("V\<S-Up>y", 'tx') |
| 103 | call assert_equal(['47', '48', '49', '50'], getline("'<", "'>")) |
| 104 | :set keymodel=startsel |
| 105 | :50 |
| 106 | call feedkeys("V\<S-Up>y", 'tx') |
| 107 | call assert_equal(['49', '50'], getline("'<", "'>")) |
| 108 | " Start visual mode when keymodel = startsel |
| 109 | :50 |
| 110 | call feedkeys("\<S-Up>y", 'tx') |
| 111 | call assert_equal(['49', '5'], getreg(0, 0, 1)) |
| 112 | " Do not start visual mode when keymodel= |
| 113 | :set keymodel= |
| 114 | :50 |
| 115 | call feedkeys("\<S-Up>y$", 'tx') |
| 116 | call assert_equal(['42'], getreg(0, 0, 1)) |
| 117 | |
| 118 | " clean up |
| 119 | bw! |
| 120 | endfunc |
| 121 | |
| 122 | func! Test_normal02_selectmode() |
| 123 | " some basic select mode tests |
| 124 | call Setup_NewWindow() |
| 125 | 50 |
| 126 | norm! gHy |
| 127 | call assert_equal('y51', getline('.')) |
| 128 | call setline(1, range(1,100)) |
| 129 | 50 |
| 130 | exe ":norm! V9jo\<c-g>y" |
| 131 | call assert_equal('y60', getline('.')) |
| 132 | " clean up |
| 133 | bw! |
| 134 | endfu |
| 135 | |
| 136 | func! Test_normal03_join() |
| 137 | " basic join test |
| 138 | call Setup_NewWindow() |
| 139 | 50 |
| 140 | norm! VJ |
| 141 | call assert_equal('50 51', getline('.')) |
| 142 | $ |
| 143 | norm! J |
| 144 | call assert_equal('100', getline('.')) |
| 145 | $ |
| 146 | norm! V9-gJ |
| 147 | call assert_equal('919293949596979899100', getline('.')) |
| 148 | call setline(1, range(1,100)) |
| 149 | $ |
| 150 | :j 10 |
| 151 | call assert_equal('100', getline('.')) |
| 152 | " clean up |
| 153 | bw! |
| 154 | endfu |
| 155 | |
| 156 | func! Test_normal04_filter() |
| 157 | " basic filter test |
| 158 | " only test on non windows platform |
| 159 | if has("win32") || has("win64") || has("win95") |
| 160 | return |
| 161 | endif |
| 162 | call Setup_NewWindow() |
| 163 | 1 |
| 164 | call feedkeys("!!sed -e 's/^/| /'\n", 'tx') |
| 165 | call assert_equal('| 1', getline('.')) |
| 166 | 90 |
| 167 | :sil :!echo one |
| 168 | call feedkeys('.', 'tx') |
| 169 | call assert_equal('| 90', getline('.')) |
| 170 | 95 |
| 171 | set cpo+=! |
| 172 | " 2 <CR>, 1: for executing the command, |
| 173 | " 2: clear hit-enter-prompt |
| 174 | call feedkeys("!!\n", 'tx') |
| 175 | call feedkeys(":!echo one\n\n", 'tx') |
| 176 | call feedkeys(".", 'tx') |
| 177 | call assert_equal('one', getline('.')) |
| 178 | set cpo-=! |
| 179 | bw! |
| 180 | endfu |
| 181 | |
| 182 | func! Test_normal05_formatexpr() |
| 183 | " basic formatexpr test |
| 184 | call Setup_NewWindow() |
| 185 | %d_ |
| 186 | call setline(1, ['here: 1 ', '2', 'here: 3 ', '4', 'not here: ']) |
| 187 | 1 |
| 188 | set formatexpr=MyFormatExpr() |
| 189 | norm! gqG |
| 190 | call assert_equal(['here: 1->$', '2', 'here: 3->$', '4', 'not here: '], getline(1,'$')) |
| 191 | set formatexpr= |
| 192 | bw! |
| 193 | endfu |
| 194 | |
| 195 | func! Test_normal06_formatprg() |
| 196 | " basic test for formatprg |
| 197 | " only test on non windows platform |
| 198 | if has("win32") || has("win64") || has("win95") |
| 199 | return |
| 200 | else |
| 201 | " uses sed to number non-empty lines |
| 202 | call writefile(['#!/bin/sh', 'sed ''/./=''|sed ''/./{', 'N', 's/\n/ /', '}'''], 'Xsed_format.sh') |
| 203 | call system('chmod +x ./Xsed_format.sh') |
| 204 | endif |
| 205 | call Setup_NewWindow() |
| 206 | %d |
| 207 | call setline(1, ['a', '', 'c', '', ' ', 'd', 'e']) |
| 208 | set formatprg=./Xsed_format.sh |
| 209 | norm! gggqG |
| 210 | call assert_equal(['1 a', '', '3 c', '', '5 ', '6 d', '7 e'], getline(1, '$')) |
| 211 | " clean up |
| 212 | set formatprg= |
| 213 | call delete('Xsed_format.sh') |
| 214 | bw! |
| 215 | endfu |
| 216 | |
| 217 | func! Test_normal07_internalfmt() |
| 218 | " basic test for internal formmatter to textwidth of 12 |
| 219 | let list=range(1,11) |
| 220 | call map(list, 'v:val." "') |
| 221 | 10new |
| 222 | call setline(1, list) |
| 223 | set tw=12 |
| 224 | norm! gggqG |
| 225 | call assert_equal(['1 2 3', '4 5 6', '7 8 9', '10 11 '], getline(1, '$')) |
| 226 | " clean up |
| 227 | set formatprg= |
| 228 | bw! |
| 229 | endfu |
| 230 | |
| 231 | func! Test_normal08_fold() |
| 232 | " basic tests for foldopen/folddelete |
| 233 | if !has("folding") |
| 234 | return |
| 235 | endif |
| 236 | call Setup_NewWindow() |
| 237 | 50 |
| 238 | setl foldenable fdm=marker |
| 239 | " First fold |
| 240 | norm! V4jzf |
| 241 | " check that folds have been created |
| 242 | call assert_equal(['50/*{{{*/', '51', '52', '53', '54/*}}}*/'], getline(50,54)) |
| 243 | " Second fold |
| 244 | 46 |
| 245 | norm! V10jzf |
| 246 | " check that folds have been created |
| 247 | call assert_equal('46/*{{{*/', getline(46)) |
| 248 | call assert_equal('60/*}}}*/', getline(60)) |
| 249 | norm! k |
| 250 | call assert_equal('45', getline('.')) |
| 251 | norm! j |
| 252 | call assert_equal('46/*{{{*/', getline('.')) |
| 253 | norm! j |
| 254 | call assert_equal('61', getline('.')) |
| 255 | norm! k |
| 256 | " open a fold |
| 257 | norm! Vzo |
| 258 | norm! k |
| 259 | call assert_equal('45', getline('.')) |
| 260 | norm! j |
| 261 | call assert_equal('46/*{{{*/', getline('.')) |
| 262 | norm! j |
| 263 | call assert_equal('47', getline('.')) |
| 264 | norm! k |
| 265 | norm! zcVzO |
| 266 | call assert_equal('46/*{{{*/', getline('.')) |
| 267 | norm! j |
| 268 | call assert_equal('47', getline('.')) |
| 269 | norm! j |
| 270 | call assert_equal('48', getline('.')) |
| 271 | norm! j |
| 272 | call assert_equal('49', getline('.')) |
| 273 | norm! j |
| 274 | call assert_equal('50/*{{{*/', getline('.')) |
| 275 | norm! j |
| 276 | call assert_equal('51', getline('.')) |
| 277 | " delete folds |
| 278 | :46 |
| 279 | " collapse fold |
| 280 | norm! V14jzC |
| 281 | " delete all folds recursively |
| 282 | norm! VzD |
| 283 | call assert_equal(['46', '47', '48', '49', '50', '51', '52', '53', '54', '55', '56', '57', '58', '59', '60'], getline(46,60)) |
| 284 | |
| 285 | " clean up |
| 286 | setl nofoldenable fdm=marker |
| 287 | bw! |
| 288 | endfu |
| 289 | |
| 290 | func! Test_normal09_operatorfunc() |
| 291 | " Test operatorfunc |
| 292 | call Setup_NewWindow() |
| 293 | " Add some spaces for counting |
| 294 | 50,60s/$/ / |
| 295 | unlet! g:a |
| 296 | let g:a=0 |
| 297 | nmap <buffer><silent> ,, :set opfunc=CountSpaces<CR>g@ |
| 298 | vmap <buffer><silent> ,, :<C-U>call CountSpaces(visualmode(), 1)<CR> |
| 299 | 50 |
| 300 | norm V2j,, |
| 301 | call assert_equal(6, g:a) |
| 302 | norm V,, |
| 303 | call assert_equal(2, g:a) |
| 304 | norm ,,l |
| 305 | call assert_equal(0, g:a) |
| 306 | 50 |
| 307 | exe "norm 0\<c-v>10j2l,," |
| 308 | call assert_equal(11, g:a) |
| 309 | 50 |
| 310 | norm V10j,, |
| 311 | call assert_equal(22, g:a) |
| 312 | |
| 313 | " clean up |
| 314 | unmap <buffer> ,, |
| 315 | set opfunc= |
| 316 | bw! |
| 317 | endfu |
| 318 | |
| 319 | func! Test_normal10_expand() |
| 320 | " Test for expand() |
| 321 | 10new |
| 322 | call setline(1, ['1', 'ifooar,,cbar']) |
| 323 | 2 |
| 324 | norm! $ |
| 325 | let a=expand('<cword>') |
| 326 | let b=expand('<cWORD>') |
| 327 | call assert_equal('cbar', a) |
| 328 | call assert_equal('ifooar,,cbar', b) |
| 329 | " clean up |
| 330 | bw! |
| 331 | endfu |
| 332 | |
| 333 | func! Test_normal11_showcmd() |
| 334 | " test for 'showcmd' |
| 335 | 10new |
| 336 | exe "norm! ofoobar\<esc>" |
| 337 | call assert_equal(2, line('$')) |
| 338 | set showcmd |
| 339 | exe "norm! ofoobar2\<esc>" |
| 340 | call assert_equal(3, line('$')) |
| 341 | exe "norm! VAfoobar3\<esc>" |
| 342 | call assert_equal(3, line('$')) |
| 343 | exe "norm! 0d3\<del>2l" |
| 344 | call assert_equal('obar2foobar3', getline('.')) |
| 345 | bw! |
| 346 | endfu |
| 347 | |
| 348 | func! Test_normal12_nv_error() |
| 349 | " Test for nv_error |
| 350 | 10new |
| 351 | call setline(1, range(1,5)) |
| 352 | " should not do anything, just beep |
| 353 | exe "norm! <c-k>" |
| 354 | call assert_equal(map(range(1,5), 'string(v:val)'), getline(1,'$')) |
| 355 | bw! |
| 356 | endfu |
| 357 | |
| 358 | func! Test_normal13_help() |
| 359 | " Test for F1 |
| 360 | call assert_equal(1, winnr()) |
| 361 | call feedkeys("\<f1>", 'txi') |
| 362 | call assert_match('help\.txt', bufname('%')) |
| 363 | call assert_equal(2, winnr('$')) |
| 364 | bw! |
| 365 | endfu |
| 366 | |
| 367 | func! Test_normal14_page() |
| 368 | " basic test for Ctrl-F and Ctrl-B |
| 369 | call Setup_NewWindow() |
| 370 | exe "norm! \<c-f>" |
| 371 | call assert_equal('9', getline('.')) |
| 372 | exe "norm! 2\<c-f>" |
| 373 | call assert_equal('25', getline('.')) |
| 374 | exe "norm! 2\<c-b>" |
| 375 | call assert_equal('18', getline('.')) |
| 376 | 1 |
| 377 | set scrolloff=5 |
| 378 | exe "norm! 2\<c-f>" |
| 379 | call assert_equal('21', getline('.')) |
| 380 | exe "norm! \<c-b>" |
| 381 | call assert_equal('13', getline('.')) |
| 382 | 1 |
| 383 | set scrolloff=99 |
| 384 | exe "norm! \<c-f>" |
| 385 | call assert_equal('13', getline('.')) |
| 386 | set scrolloff=0 |
| 387 | 100 |
| 388 | exe "norm! $\<c-b>" |
| 389 | call assert_equal('92', getline('.')) |
| 390 | call assert_equal([0, 92, 1, 0, 1], getcurpos()) |
| 391 | 100 |
| 392 | set nostartofline |
| 393 | exe "norm! $\<c-b>" |
| 394 | call assert_equal('92', getline('.')) |
| 395 | call assert_equal([0, 92, 2, 0, 2147483647], getcurpos()) |
| 396 | " cleanup |
| 397 | set startofline |
| 398 | bw! |
| 399 | endfu |
| 400 | |
| 401 | func! Test_normal15_z_scroll_vert() |
| 402 | " basic test for z commands that scroll the window |
| 403 | call Setup_NewWindow() |
| 404 | 100 |
| 405 | norm! >> |
| 406 | " Test for z<cr> |
| 407 | exe "norm! z\<cr>" |
| 408 | call assert_equal(' 100', getline('.')) |
| 409 | call assert_equal(100, winsaveview()['topline']) |
| 410 | call assert_equal([0, 100, 2, 0, 9], getcurpos()) |
| 411 | |
| 412 | " Test for zt |
| 413 | 21 |
| 414 | norm! >>0zt |
| 415 | call assert_equal(' 21', getline('.')) |
| 416 | call assert_equal(21, winsaveview()['topline']) |
| 417 | call assert_equal([0, 21, 1, 0, 8], getcurpos()) |
| 418 | |
| 419 | " Test for zb |
| 420 | 30 |
| 421 | norm! >>$ztzb |
| 422 | call assert_equal(' 30', getline('.')) |
| 423 | call assert_equal(30, winsaveview()['topline']+winheight(0)-1) |
| 424 | call assert_equal([0, 30, 3, 0, 2147483647], getcurpos()) |
| 425 | |
| 426 | " Test for z- |
| 427 | 1 |
| 428 | 30 |
| 429 | norm! 0z- |
| 430 | call assert_equal(' 30', getline('.')) |
| 431 | call assert_equal(30, winsaveview()['topline']+winheight(0)-1) |
| 432 | call assert_equal([0, 30, 2, 0, 9], getcurpos()) |
| 433 | |
| 434 | " Test for z{height}<cr> |
| 435 | call assert_equal(10, winheight(0)) |
| 436 | exe "norm! z12\<cr>" |
| 437 | call assert_equal(12, winheight(0)) |
| 438 | exe "norm! z10\<cr>" |
| 439 | call assert_equal(10, winheight(0)) |
| 440 | |
| 441 | " Test for z. |
| 442 | 1 |
| 443 | 21 |
| 444 | norm! 0z. |
| 445 | call assert_equal(' 21', getline('.')) |
| 446 | call assert_equal(17, winsaveview()['topline']) |
| 447 | call assert_equal([0, 21, 2, 0, 9], getcurpos()) |
| 448 | |
| 449 | " Test for zz |
| 450 | 1 |
| 451 | 21 |
| 452 | norm! 0zz |
| 453 | call assert_equal(' 21', getline('.')) |
| 454 | call assert_equal(17, winsaveview()['topline']) |
| 455 | call assert_equal([0, 21, 1, 0, 8], getcurpos()) |
| 456 | |
| 457 | " Test for z+ |
| 458 | 11 |
| 459 | norm! zt |
| 460 | norm! z+ |
| 461 | call assert_equal(' 21', getline('.')) |
| 462 | call assert_equal(21, winsaveview()['topline']) |
| 463 | call assert_equal([0, 21, 2, 0, 9], getcurpos()) |
| 464 | |
| 465 | " Test for [count]z+ |
| 466 | 1 |
| 467 | norm! 21z+ |
| 468 | call assert_equal(' 21', getline('.')) |
| 469 | call assert_equal(21, winsaveview()['topline']) |
| 470 | call assert_equal([0, 21, 2, 0, 9], getcurpos()) |
| 471 | |
| 472 | " Test for z^ |
| 473 | norm! 22z+0 |
| 474 | norm! z^ |
| 475 | call assert_equal(' 21', getline('.')) |
| 476 | call assert_equal(12, winsaveview()['topline']) |
| 477 | call assert_equal([0, 21, 2, 0, 9], getcurpos()) |
| 478 | |
| 479 | " Test for [count]z^ |
| 480 | 1 |
| 481 | norm! 30z^ |
| 482 | call assert_equal(' 21', getline('.')) |
| 483 | call assert_equal(12, winsaveview()['topline']) |
| 484 | call assert_equal([0, 21, 2, 0, 9], getcurpos()) |
| 485 | |
| 486 | " cleanup |
| 487 | bw! |
| 488 | endfu |
| 489 | |
| 490 | func! Test_normal16_z_scroll_hor() |
| 491 | " basic test for z commands that scroll the window |
| 492 | 10new |
| 493 | 15vsp |
| 494 | set nowrap listchars= |
| 495 | let lineA='abcdefghijklmnopqrstuvwxyz' |
| 496 | let lineB='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ' |
| 497 | $put =lineA |
| 498 | $put =lineB |
| 499 | 1d |
| 500 | |
| 501 | " Test for zl |
| 502 | 1 |
| 503 | norm! 5zl |
| 504 | call assert_equal(lineA, getline('.')) |
| 505 | call assert_equal(6, col('.')) |
| 506 | call assert_equal(5, winsaveview()['leftcol']) |
| 507 | norm! yl |
| 508 | call assert_equal('f', @0) |
| 509 | |
| 510 | " Test for zh |
| 511 | norm! 2zh |
| 512 | call assert_equal(lineA, getline('.')) |
| 513 | call assert_equal(6, col('.')) |
| 514 | norm! yl |
| 515 | call assert_equal('f', @0) |
| 516 | call assert_equal(3, winsaveview()['leftcol']) |
| 517 | |
| 518 | " Test for zL |
| 519 | norm! zL |
| 520 | call assert_equal(11, col('.')) |
| 521 | norm! yl |
| 522 | call assert_equal('k', @0) |
| 523 | call assert_equal(10, winsaveview()['leftcol']) |
| 524 | norm! 2zL |
| 525 | call assert_equal(25, col('.')) |
| 526 | norm! yl |
| 527 | call assert_equal('y', @0) |
| 528 | call assert_equal(24, winsaveview()['leftcol']) |
| 529 | |
| 530 | " Test for zH |
| 531 | norm! 2zH |
| 532 | call assert_equal(25, col('.')) |
| 533 | call assert_equal(10, winsaveview()['leftcol']) |
| 534 | norm! yl |
| 535 | call assert_equal('y', @0) |
| 536 | |
| 537 | " Test for zs |
| 538 | norm! $zs |
| 539 | call assert_equal(26, col('.')) |
| 540 | call assert_equal(25, winsaveview()['leftcol']) |
| 541 | norm! yl |
| 542 | call assert_equal('z', @0) |
| 543 | |
| 544 | " Test for ze |
| 545 | norm! ze |
| 546 | call assert_equal(26, col('.')) |
| 547 | call assert_equal(11, winsaveview()['leftcol']) |
| 548 | norm! yl |
| 549 | call assert_equal('z', @0) |
| 550 | |
| 551 | " cleanup |
| 552 | set wrap listchars=eol:$ |
| 553 | bw! |
| 554 | endfu |
| 555 | |
| 556 | func! Test_normal17_z_scroll_hor2() |
| 557 | " basic test for z commands that scroll the window |
| 558 | " using 'sidescrolloff' setting |
| 559 | 10new |
| 560 | 20vsp |
| 561 | set nowrap listchars= sidescrolloff=5 |
| 562 | let lineA='abcdefghijklmnopqrstuvwxyz' |
| 563 | let lineB='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ' |
| 564 | $put =lineA |
| 565 | $put =lineB |
| 566 | 1d |
| 567 | |
| 568 | " Test for zl |
| 569 | 1 |
| 570 | norm! 5zl |
| 571 | call assert_equal(lineA, getline('.')) |
| 572 | call assert_equal(11, col('.')) |
| 573 | call assert_equal(5, winsaveview()['leftcol']) |
| 574 | norm! yl |
| 575 | call assert_equal('k', @0) |
| 576 | |
| 577 | " Test for zh |
| 578 | norm! 2zh |
| 579 | call assert_equal(lineA, getline('.')) |
| 580 | call assert_equal(11, col('.')) |
| 581 | norm! yl |
| 582 | call assert_equal('k', @0) |
| 583 | call assert_equal(3, winsaveview()['leftcol']) |
| 584 | |
| 585 | " Test for zL |
| 586 | norm! 0zL |
| 587 | call assert_equal(16, col('.')) |
| 588 | norm! yl |
| 589 | call assert_equal('p', @0) |
| 590 | call assert_equal(10, winsaveview()['leftcol']) |
| 591 | norm! 2zL |
| 592 | call assert_equal(26, col('.')) |
| 593 | norm! yl |
| 594 | call assert_equal('z', @0) |
| 595 | call assert_equal(15, winsaveview()['leftcol']) |
| 596 | |
| 597 | " Test for zH |
| 598 | norm! 2zH |
| 599 | call assert_equal(15, col('.')) |
| 600 | call assert_equal(0, winsaveview()['leftcol']) |
| 601 | norm! yl |
| 602 | call assert_equal('o', @0) |
| 603 | |
| 604 | " Test for zs |
| 605 | norm! $zs |
| 606 | call assert_equal(26, col('.')) |
| 607 | call assert_equal(20, winsaveview()['leftcol']) |
| 608 | norm! yl |
| 609 | call assert_equal('z', @0) |
| 610 | |
| 611 | " Test for ze |
| 612 | norm! ze |
| 613 | call assert_equal(26, col('.')) |
| 614 | call assert_equal(11, winsaveview()['leftcol']) |
| 615 | norm! yl |
| 616 | call assert_equal('z', @0) |
| 617 | |
| 618 | " cleanup |
| 619 | set wrap listchars=eol:$ sidescrolloff=0 |
| 620 | bw! |
| 621 | endfu |
| 622 | |
| 623 | func! Test_normal18_z_fold() |
| 624 | " basic tests for foldopen/folddelete |
| 625 | if !has("folding") |
| 626 | return |
| 627 | endif |
| 628 | call Setup_NewWindow() |
| 629 | 50 |
| 630 | setl foldenable fdm=marker foldlevel=5 |
| 631 | |
| 632 | " Test for zF |
| 633 | " First fold |
| 634 | norm! 4zF |
| 635 | " check that folds have been created |
| 636 | call assert_equal(['50/*{{{*/', '51', '52', '53/*}}}*/'], getline(50,53)) |
| 637 | |
| 638 | " Test for zd |
| 639 | 51 |
| 640 | norm! 2zF |
| 641 | call assert_equal(2, foldlevel('.')) |
| 642 | norm! kzd |
| 643 | call assert_equal(['50', '51/*{{{*/', '52/*}}}*/', '53'], getline(50,53)) |
| 644 | norm! j |
| 645 | call assert_equal(1, foldlevel('.')) |
| 646 | |
| 647 | " Test for zD |
| 648 | " also deletes partially selected folds recursively |
| 649 | 51 |
| 650 | norm! zF |
| 651 | call assert_equal(2, foldlevel('.')) |
| 652 | norm! kV2jzD |
| 653 | call assert_equal(['50', '51', '52', '53'], getline(50,53)) |
| 654 | |
| 655 | " Test for zE |
| 656 | 85 |
| 657 | norm! 4zF |
| 658 | 86 |
| 659 | norm! 2zF |
| 660 | 90 |
| 661 | norm! 4zF |
| 662 | call assert_equal(['85/*{{{*/', '86/*{{{*/', '87/*}}}*/', '88/*}}}*/', '89', '90/*{{{*/', '91', '92', '93/*}}}*/'], getline(85,93)) |
| 663 | norm! zE |
| 664 | call assert_equal(['85', '86', '87', '88', '89', '90', '91', '92', '93'], getline(85,93)) |
| 665 | |
| 666 | " Test for zn |
| 667 | 50 |
| 668 | set foldlevel=0 |
| 669 | norm! 2zF |
| 670 | norm! zn |
| 671 | norm! k |
| 672 | call assert_equal('49', getline('.')) |
| 673 | norm! j |
| 674 | call assert_equal('50/*{{{*/', getline('.')) |
| 675 | norm! j |
| 676 | call assert_equal('51/*}}}*/', getline('.')) |
| 677 | norm! j |
| 678 | call assert_equal('52', getline('.')) |
| 679 | call assert_equal(0, &foldenable) |
| 680 | |
| 681 | " Test for zN |
| 682 | 49 |
| 683 | norm! zN |
| 684 | call assert_equal('49', getline('.')) |
| 685 | norm! j |
| 686 | call assert_equal('50/*{{{*/', getline('.')) |
| 687 | norm! j |
| 688 | call assert_equal('52', getline('.')) |
| 689 | call assert_equal(1, &foldenable) |
| 690 | |
| 691 | " Test for zi |
| 692 | norm! zi |
| 693 | call assert_equal(0, &foldenable) |
| 694 | norm! zi |
| 695 | call assert_equal(1, &foldenable) |
| 696 | norm! zi |
| 697 | call assert_equal(0, &foldenable) |
| 698 | norm! zi |
| 699 | call assert_equal(1, &foldenable) |
| 700 | |
| 701 | " Test for za |
| 702 | 50 |
| 703 | norm! za |
| 704 | norm! k |
| 705 | call assert_equal('49', getline('.')) |
| 706 | norm! j |
| 707 | call assert_equal('50/*{{{*/', getline('.')) |
| 708 | norm! j |
| 709 | call assert_equal('51/*}}}*/', getline('.')) |
| 710 | norm! j |
| 711 | call assert_equal('52', getline('.')) |
| 712 | 50 |
| 713 | norm! za |
| 714 | norm! k |
| 715 | call assert_equal('49', getline('.')) |
| 716 | norm! j |
| 717 | call assert_equal('50/*{{{*/', getline('.')) |
| 718 | norm! j |
| 719 | call assert_equal('52', getline('.')) |
| 720 | |
| 721 | 49 |
| 722 | norm! 5zF |
| 723 | norm! k |
| 724 | call assert_equal('48', getline('.')) |
| 725 | norm! j |
| 726 | call assert_equal('49/*{{{*/', getline('.')) |
| 727 | norm! j |
| 728 | call assert_equal('55', getline('.')) |
| 729 | 49 |
| 730 | norm! za |
| 731 | call assert_equal('49/*{{{*/', getline('.')) |
| 732 | norm! j |
| 733 | call assert_equal('50/*{{{*/', getline('.')) |
| 734 | norm! j |
| 735 | call assert_equal('52', getline('.')) |
| 736 | set nofoldenable |
| 737 | " close fold and set foldenable |
| 738 | norm! za |
| 739 | call assert_equal(1, &foldenable) |
| 740 | |
| 741 | 50 |
| 742 | " have to use {count}za to open all folds and make the cursor visible |
| 743 | norm! 2za |
| 744 | norm! 2k |
| 745 | call assert_equal('48', getline('.')) |
| 746 | norm! j |
| 747 | call assert_equal('49/*{{{*/', getline('.')) |
| 748 | norm! j |
| 749 | call assert_equal('50/*{{{*/', getline('.')) |
| 750 | norm! j |
| 751 | call assert_equal('51/*}}}*/', getline('.')) |
| 752 | norm! j |
| 753 | call assert_equal('52', getline('.')) |
| 754 | |
| 755 | " Test for zA |
| 756 | 49 |
| 757 | set foldlevel=0 |
| 758 | 50 |
| 759 | norm! zA |
| 760 | norm! 2k |
| 761 | call assert_equal('48', getline('.')) |
| 762 | norm! j |
| 763 | call assert_equal('49/*{{{*/', getline('.')) |
| 764 | norm! j |
| 765 | call assert_equal('50/*{{{*/', getline('.')) |
| 766 | norm! j |
| 767 | call assert_equal('51/*}}}*/', getline('.')) |
| 768 | norm! j |
| 769 | call assert_equal('52', getline('.')) |
| 770 | |
| 771 | " zA on a opened fold when foldenale is not set |
| 772 | 50 |
| 773 | set nofoldenable |
| 774 | norm! zA |
| 775 | call assert_equal(1, &foldenable) |
| 776 | norm! k |
| 777 | call assert_equal('48', getline('.')) |
| 778 | norm! j |
| 779 | call assert_equal('49/*{{{*/', getline('.')) |
| 780 | norm! j |
| 781 | call assert_equal('55', getline('.')) |
| 782 | |
| 783 | " Test for zc |
| 784 | norm! zE |
| 785 | 50 |
| 786 | norm! 2zF |
| 787 | 49 |
| 788 | norm! 5zF |
| 789 | set nofoldenable |
| 790 | 50 |
| 791 | " There most likely is a bug somewhere: |
| 792 | " https://groups.google.com/d/msg/vim_dev/v2EkfJ_KQjI/u-Cvv94uCAAJ |
| 793 | " TODO: Should this only close the inner most fold or both folds? |
| 794 | norm! zc |
| 795 | call assert_equal(1, &foldenable) |
| 796 | norm! k |
| 797 | call assert_equal('48', getline('.')) |
| 798 | norm! j |
| 799 | call assert_equal('49/*{{{*/', getline('.')) |
| 800 | norm! j |
| 801 | call assert_equal('55', getline('.')) |
| 802 | set nofoldenable |
| 803 | 50 |
| 804 | norm! Vjzc |
| 805 | norm! k |
| 806 | call assert_equal('48', getline('.')) |
| 807 | norm! j |
| 808 | call assert_equal('49/*{{{*/', getline('.')) |
| 809 | norm! j |
| 810 | call assert_equal('55', getline('.')) |
| 811 | |
| 812 | " Test for zC |
| 813 | set nofoldenable |
| 814 | 50 |
| 815 | norm! zCk |
| 816 | call assert_equal('48', getline('.')) |
| 817 | norm! j |
| 818 | call assert_equal('49/*{{{*/', getline('.')) |
| 819 | norm! j |
| 820 | call assert_equal('55', getline('.')) |
| 821 | |
| 822 | " Test for zx |
| 823 | " 1) close folds at line 49-54 |
| 824 | set nofoldenable |
| 825 | 48 |
| 826 | norm! zx |
| 827 | call assert_equal(1, &foldenable) |
| 828 | norm! j |
| 829 | call assert_equal('49/*{{{*/', getline('.')) |
| 830 | norm! j |
| 831 | call assert_equal('55', getline('.')) |
| 832 | |
| 833 | " 2) do not close fold under curser |
| 834 | 51 |
| 835 | set nofoldenable |
| 836 | norm! zx |
| 837 | call assert_equal(1, &foldenable) |
| 838 | norm! 3k |
| 839 | call assert_equal('48', getline('.')) |
| 840 | norm! j |
| 841 | call assert_equal('49/*{{{*/', getline('.')) |
| 842 | norm! j |
| 843 | call assert_equal('50/*{{{*/', getline('.')) |
| 844 | norm! j |
| 845 | call assert_equal('51/*}}}*/', getline('.')) |
| 846 | norm! j |
| 847 | call assert_equal('52', getline('.')) |
| 848 | norm! j |
| 849 | call assert_equal('53', getline('.')) |
| 850 | norm! j |
| 851 | call assert_equal('54/*}}}*/', getline('.')) |
| 852 | norm! j |
| 853 | call assert_equal('55', getline('.')) |
| 854 | |
| 855 | " 3) close one level of folds |
| 856 | 48 |
| 857 | set nofoldenable |
| 858 | set foldlevel=1 |
| 859 | norm! zx |
| 860 | call assert_equal(1, &foldenable) |
| 861 | call assert_equal('48', getline('.')) |
| 862 | norm! j |
| 863 | call assert_equal('49/*{{{*/', getline('.')) |
| 864 | norm! j |
| 865 | call assert_equal('50/*{{{*/', getline('.')) |
| 866 | norm! j |
| 867 | call assert_equal('52', getline('.')) |
| 868 | norm! j |
| 869 | call assert_equal('53', getline('.')) |
| 870 | norm! j |
| 871 | call assert_equal('54/*}}}*/', getline('.')) |
| 872 | norm! j |
| 873 | call assert_equal('55', getline('.')) |
| 874 | |
| 875 | " Test for zX |
| 876 | " Close all folds |
| 877 | set foldlevel=0 nofoldenable |
| 878 | 50 |
| 879 | norm! zX |
| 880 | call assert_equal(1, &foldenable) |
| 881 | norm! k |
| 882 | call assert_equal('48', getline('.')) |
| 883 | norm! j |
| 884 | call assert_equal('49/*{{{*/', getline('.')) |
| 885 | norm! j |
| 886 | call assert_equal('55', getline('.')) |
| 887 | |
| 888 | " Test for zm |
| 889 | 50 |
| 890 | set nofoldenable foldlevel=2 |
| 891 | norm! zm |
| 892 | call assert_equal(1, &foldenable) |
| 893 | call assert_equal(1, &foldlevel) |
| 894 | norm! zm |
| 895 | call assert_equal(0, &foldlevel) |
| 896 | norm! zm |
| 897 | call assert_equal(0, &foldlevel) |
| 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 | |
| 905 | " Test for zM |
| 906 | 48 |
| 907 | set nofoldenable foldlevel=99 |
| 908 | norm! zM |
| 909 | call assert_equal(1, &foldenable) |
| 910 | call assert_equal(0, &foldlevel) |
| 911 | call assert_equal('48', getline('.')) |
| 912 | norm! j |
| 913 | call assert_equal('49/*{{{*/', getline('.')) |
| 914 | norm! j |
| 915 | call assert_equal('55', getline('.')) |
| 916 | |
| 917 | " Test for zr |
| 918 | 48 |
| 919 | set nofoldenable foldlevel=0 |
| 920 | norm! zr |
| 921 | call assert_equal(0, &foldenable) |
| 922 | call assert_equal(1, &foldlevel) |
| 923 | set foldlevel=0 foldenable |
| 924 | norm! zr |
| 925 | call assert_equal(1, &foldenable) |
| 926 | call assert_equal(1, &foldlevel) |
| 927 | norm! zr |
| 928 | call assert_equal(2, &foldlevel) |
| 929 | call assert_equal('48', getline('.')) |
| 930 | norm! j |
| 931 | call assert_equal('49/*{{{*/', getline('.')) |
| 932 | norm! j |
| 933 | call assert_equal('50/*{{{*/', getline('.')) |
| 934 | norm! j |
| 935 | call assert_equal('51/*}}}*/', getline('.')) |
| 936 | norm! j |
| 937 | call assert_equal('52', getline('.')) |
| 938 | |
| 939 | " Test for zR |
| 940 | 48 |
| 941 | set nofoldenable foldlevel=0 |
| 942 | norm! zR |
| 943 | call assert_equal(0, &foldenable) |
| 944 | call assert_equal(2, &foldlevel) |
| 945 | set foldenable foldlevel=0 |
| 946 | norm! zR |
| 947 | call assert_equal(1, &foldenable) |
| 948 | call assert_equal(2, &foldlevel) |
| 949 | call assert_equal('48', getline('.')) |
| 950 | norm! j |
| 951 | call assert_equal('49/*{{{*/', getline('.')) |
| 952 | norm! j |
| 953 | call assert_equal('50/*{{{*/', getline('.')) |
| 954 | norm! j |
| 955 | call assert_equal('51/*}}}*/', getline('.')) |
| 956 | norm! j |
| 957 | call assert_equal('52', getline('.')) |
| 958 | call append(50, ['a /*{{{*/', 'b /*}}}*/']) |
| 959 | 48 |
| 960 | call assert_equal('48', getline('.')) |
| 961 | norm! j |
| 962 | call assert_equal('49/*{{{*/', getline('.')) |
| 963 | norm! j |
| 964 | call assert_equal('50/*{{{*/', getline('.')) |
| 965 | norm! j |
| 966 | call assert_equal('a /*{{{*/', getline('.')) |
| 967 | norm! j |
| 968 | call assert_equal('51/*}}}*/', getline('.')) |
| 969 | norm! j |
| 970 | call assert_equal('52', getline('.')) |
| 971 | 48 |
| 972 | norm! zR |
| 973 | call assert_equal(1, &foldenable) |
| 974 | call assert_equal(3, &foldlevel) |
| 975 | call assert_equal('48', getline('.')) |
| 976 | norm! j |
| 977 | call assert_equal('49/*{{{*/', getline('.')) |
| 978 | norm! j |
| 979 | call assert_equal('50/*{{{*/', getline('.')) |
| 980 | norm! j |
| 981 | call assert_equal('a /*{{{*/', getline('.')) |
| 982 | norm! j |
| 983 | call assert_equal('b /*}}}*/', getline('.')) |
| 984 | norm! j |
| 985 | call assert_equal('51/*}}}*/', getline('.')) |
| 986 | norm! j |
| 987 | call assert_equal('52', getline('.')) |
| 988 | |
| 989 | " clean up |
| 990 | setl nofoldenable fdm=marker foldlevel=0 |
| 991 | bw! |
| 992 | endfu |
| 993 | |
| 994 | func! Test_normal19_z_spell() |
| 995 | if !has("spell") || !has('syntax') |
| 996 | return |
| 997 | endif |
| 998 | new |
| 999 | call append(0, ['1 good', '2 goood', '3 goood']) |
| 1000 | set spell spellfile=./Xspellfile.add spelllang=en |
| 1001 | let oldlang=v:lang |
| 1002 | lang C |
| 1003 | |
| 1004 | " Test for zg |
| 1005 | 1 |
| 1006 | norm! ]s |
| 1007 | call assert_equal('2 goood', getline('.')) |
| 1008 | norm! zg |
| 1009 | 1 |
| 1010 | let a=execute('unsilent :norm! ]s') |
| 1011 | call assert_equal('1 good', getline('.')) |
| 1012 | call assert_equal('search hit BOTTOM, continuing at TOP', a[1:]) |
| 1013 | let cnt=readfile('./Xspellfile.add') |
| 1014 | call assert_equal('goood', cnt[0]) |
| 1015 | |
| 1016 | " Test for zw |
| 1017 | 2 |
| 1018 | norm! $zw |
| 1019 | 1 |
| 1020 | norm! ]s |
| 1021 | call assert_equal('2 goood', getline('.')) |
| 1022 | let cnt=readfile('./Xspellfile.add') |
| 1023 | call assert_equal('#oood', cnt[0]) |
| 1024 | call assert_equal('goood/!', cnt[1]) |
| 1025 | |
| 1026 | " Test for zg in visual mode |
| 1027 | let a=execute('unsilent :norm! V$zg') |
| 1028 | call assert_equal("Word '2 goood' added to ./Xspellfile.add", a[1:]) |
| 1029 | 1 |
| 1030 | norm! ]s |
| 1031 | call assert_equal('3 goood', getline('.')) |
| 1032 | let cnt=readfile('./Xspellfile.add') |
| 1033 | call assert_equal('2 goood', cnt[2]) |
| 1034 | " Remove "2 good" from spellfile |
| 1035 | 2 |
| 1036 | let a=execute('unsilent norm! V$zw') |
| 1037 | call assert_equal("Word '2 goood' added to ./Xspellfile.add", a[1:]) |
| 1038 | let cnt=readfile('./Xspellfile.add') |
| 1039 | call assert_equal('2 goood/!', cnt[3]) |
| 1040 | |
| 1041 | " Test for zG |
| 1042 | let a=execute('unsilent norm! V$zG') |
| 1043 | call assert_match("Word '2 goood' added to .*", a) |
| 1044 | let fname=matchstr(a, 'to\s\+\zs\f\+$') |
| 1045 | let cnt=readfile(fname) |
| 1046 | call assert_equal('2 goood', cnt[0]) |
| 1047 | |
| 1048 | " Test for zW |
| 1049 | let a=execute('unsilent norm! V$zW') |
| 1050 | call assert_match("Word '2 goood' added to .*", a) |
| 1051 | let cnt=readfile(fname) |
| 1052 | call assert_equal('# goood', cnt[0]) |
| 1053 | call assert_equal('2 goood/!', cnt[1]) |
| 1054 | |
| 1055 | " Test for zuW |
| 1056 | let a=execute('unsilent norm! V$zuW') |
| 1057 | call assert_match("Word '2 goood' removed from .*", a) |
| 1058 | let cnt=readfile(fname) |
| 1059 | call assert_equal('# goood', cnt[0]) |
| 1060 | call assert_equal('# goood/!', cnt[1]) |
| 1061 | |
| 1062 | " Test for zuG |
| 1063 | let a=execute('unsilent norm! $zG') |
| 1064 | call assert_match("Word 'goood' added to .*", a) |
| 1065 | let cnt=readfile(fname) |
| 1066 | call assert_equal('# goood', cnt[0]) |
| 1067 | call assert_equal('# goood/!', cnt[1]) |
| 1068 | call assert_equal('goood', cnt[2]) |
| 1069 | let a=execute('unsilent norm! $zuG') |
| 1070 | let cnt=readfile(fname) |
| 1071 | call assert_match("Word 'goood' removed from .*", a) |
| 1072 | call assert_equal('# goood', cnt[0]) |
| 1073 | call assert_equal('# goood/!', cnt[1]) |
| 1074 | call assert_equal('#oood', cnt[2]) |
| 1075 | " word not found in wordlist |
| 1076 | let a=execute('unsilent norm! V$zuG') |
| 1077 | let cnt=readfile(fname) |
| 1078 | call assert_match("", a) |
| 1079 | call assert_equal('# goood', cnt[0]) |
| 1080 | call assert_equal('# goood/!', cnt[1]) |
| 1081 | call assert_equal('#oood', cnt[2]) |
| 1082 | |
| 1083 | " Test for zug |
| 1084 | call delete('./Xspellfile.add') |
| 1085 | 2 |
| 1086 | let a=execute('unsilent norm! $zg') |
| 1087 | let cnt=readfile('./Xspellfile.add') |
| 1088 | call assert_equal('goood', cnt[0]) |
| 1089 | let a=execute('unsilent norm! $zug') |
| 1090 | call assert_match("Word 'goood' removed from \./Xspellfile.add", a) |
| 1091 | let cnt=readfile('./Xspellfile.add') |
| 1092 | call assert_equal('#oood', cnt[0]) |
| 1093 | " word not in wordlist |
| 1094 | let a=execute('unsilent norm! V$zug') |
| 1095 | call assert_match('', a) |
| 1096 | let cnt=readfile('./Xspellfile.add') |
| 1097 | call assert_equal('#oood', cnt[0]) |
| 1098 | |
| 1099 | " Test for zuw |
| 1100 | call delete('./Xspellfile.add') |
| 1101 | 2 |
| 1102 | let a=execute('unsilent norm! Vzw') |
| 1103 | let cnt=readfile('./Xspellfile.add') |
| 1104 | call assert_equal('2 goood/!', cnt[0]) |
| 1105 | let a=execute('unsilent norm! Vzuw') |
| 1106 | call assert_match("Word '2 goood' removed from \./Xspellfile.add", a) |
| 1107 | let cnt=readfile('./Xspellfile.add') |
| 1108 | call assert_equal('# goood/!', cnt[0]) |
| 1109 | " word not in wordlist |
| 1110 | let a=execute('unsilent norm! $zug') |
| 1111 | call assert_match('', a) |
| 1112 | let cnt=readfile('./Xspellfile.add') |
| 1113 | call assert_equal('# goood/!', cnt[0]) |
| 1114 | |
| 1115 | " add second entry to spellfile setting |
| 1116 | set spellfile=./Xspellfile.add,./Xspellfile2.add |
| 1117 | call delete('./Xspellfile.add') |
| 1118 | 2 |
| 1119 | let a=execute('unsilent norm! $2zg') |
| 1120 | let cnt=readfile('./Xspellfile2.add') |
| 1121 | call assert_match("Word 'goood' added to ./Xspellfile2.add", a) |
| 1122 | call assert_equal('goood', cnt[0]) |
| 1123 | |
| 1124 | " clean up |
| 1125 | exe "lang" oldlang |
| 1126 | call delete("./Xspellfile.add") |
| 1127 | call delete("./Xspellfile2.add") |
| 1128 | |
| 1129 | " zux -> no-op |
| 1130 | 2 |
| 1131 | norm! $zux |
| 1132 | call assert_equal([], glob('Xspellfile.add',0,1)) |
| 1133 | call assert_equal([], glob('Xspellfile2.add',0,1)) |
| 1134 | |
| 1135 | set spellfile= |
| 1136 | bw! |
| 1137 | endfu |
| 1138 | |
| 1139 | func! Test_normal20_exmode() |
| 1140 | if !(has("win32") || has("win64")) |
| 1141 | return |
| 1142 | endif |
| 1143 | call writefile(['1a', 'foo', 'bar', '.', 'w! Xfile2', 'q!'], 'Xscript') |
| 1144 | call writefile(['1', '2'], 'Xfile') |
| 1145 | call system(v:progpath .' -e -s < Xscript Xfile') |
| 1146 | let a=readfile('Xfile2') |
| 1147 | call assert_equal(['1', 'foo', 'bar', '2'], a) |
| 1148 | |
| 1149 | " clean up |
| 1150 | for file in ['Xfile', 'Xfile2', 'Xscript'] |
| 1151 | call delete(file) |
| 1152 | endfor |
| 1153 | bw! |
| 1154 | endfu |
| 1155 | |
| 1156 | func! Test_normal21_nv_hat() |
| 1157 | set hidden |
| 1158 | e Xfoobar |
| 1159 | e Xfile2 |
| 1160 | call feedkeys("\<c-^>", 't') |
| 1161 | call assert_equal("Xfile2", fnamemodify(bufname('%'), ':t')) |
| 1162 | call feedkeys("f\<c-^>", 't') |
| 1163 | call assert_equal("Xfile2", fnamemodify(bufname('%'), ':t')) |
| 1164 | " clean up |
| 1165 | set nohidden |
| 1166 | bw! |
| 1167 | endfu |
| 1168 | |
| 1169 | func! Test_normal22_zet() |
| 1170 | " Test for ZZ |
| 1171 | let shell = &shell |
| 1172 | let &shell = 'sh' |
| 1173 | call writefile(['1', '2'], 'Xfile') |
| 1174 | let args = ' -u NONE -N -U NONE -i NONE --noplugins -X --not-a-term' |
| 1175 | call system(v:progpath . args . ' -c "%d" -c ":norm! ZZ" Xfile') |
| 1176 | let a = readfile('Xfile') |
| 1177 | call assert_equal([], a) |
| 1178 | " Test for ZQ |
| 1179 | call writefile(['1', '2'], 'Xfile') |
| 1180 | call system(v:progpath . args . ' -c "%d" -c ":norm! ZQ" Xfile') |
| 1181 | let a = readfile('Xfile') |
| 1182 | call assert_equal(['1', '2'], a) |
| 1183 | |
| 1184 | " clean up |
| 1185 | for file in ['Xfile'] |
| 1186 | call delete(file) |
| 1187 | endfor |
| 1188 | let &shell = shell |
| 1189 | endfu |
| 1190 | |
| 1191 | func! Test_normal23_K() |
| 1192 | " Test for K command |
| 1193 | new |
| 1194 | call append(0, ['version8.txt', 'man']) |
| 1195 | let k = &keywordprg |
| 1196 | set keywordprg=:help |
| 1197 | 1 |
| 1198 | norm! VK |
| 1199 | call assert_equal('version8.txt', fnamemodify(bufname('%'), ':t')) |
| 1200 | call assert_equal('help', &ft) |
| 1201 | call assert_match('\*version8.txt\*', getline('.')) |
| 1202 | helpclose |
| 1203 | norm! 0K |
| 1204 | call assert_equal('version8.txt', fnamemodify(bufname('%'), ':t')) |
| 1205 | call assert_equal('help', &ft) |
| 1206 | call assert_match('\*version8\.0\*', getline('.')) |
| 1207 | helpclose |
| 1208 | |
| 1209 | if !(has("win32") || has("win64")) |
| 1210 | let &keywordprg = k |
| 1211 | bw! |
| 1212 | return |
| 1213 | endif |
| 1214 | set keywordprg=man\ --pager=cat |
| 1215 | " Test for using man |
| 1216 | 2 |
| 1217 | let a = execute('unsilent norm! K') |
| 1218 | call assert_match("man --pager=cat 'man'", a) |
| 1219 | |
| 1220 | " clean up |
| 1221 | let &keywordprg = k |
| 1222 | bw! |
| 1223 | endfu |
| 1224 | |
| 1225 | func! Test_normal24_rot13() |
| 1226 | " This test uses multi byte characters |
| 1227 | if !has("multi_byte") |
| 1228 | return |
| 1229 | endif |
| 1230 | " Testing for g?? g?g? |
| 1231 | new |
| 1232 | call append(0, 'abcdefghijklmnopqrstuvwxyzäüö') |
| 1233 | 1 |
| 1234 | norm! g?? |
| 1235 | call assert_equal('nopqrstuvwxyzabcdefghijklmäüö', getline('.')) |
| 1236 | norm! g?g? |
| 1237 | call assert_equal('abcdefghijklmnopqrstuvwxyzäüö', getline('.')) |
| 1238 | |
| 1239 | " clean up |
| 1240 | bw! |
| 1241 | endfu |
| 1242 | |
| 1243 | func! Test_normal25_tag() |
| 1244 | " Testing for CTRL-] g CTRL-] g] |
| 1245 | " CTRL-W g] CTRL-W CTRL-] CTRL-W g CTRL-] |
| 1246 | h |
| 1247 | " Test for CTRL-] |
| 1248 | call search('\<x\>$') |
| 1249 | exe "norm! \<c-]>" |
| 1250 | call assert_equal("change.txt", fnamemodify(bufname('%'), ':t')) |
| 1251 | norm! yiW |
| 1252 | call assert_equal("*x*", @0) |
| 1253 | exe ":norm \<c-o>" |
| 1254 | |
| 1255 | " Test for g_CTRL-] |
| 1256 | call search('\<v_u\>$') |
| 1257 | exe "norm! g\<c-]>" |
| 1258 | call assert_equal("change.txt", fnamemodify(bufname('%'), ':t')) |
| 1259 | norm! yiW |
| 1260 | call assert_equal("*v_u*", @0) |
| 1261 | exe ":norm \<c-o>" |
| 1262 | |
| 1263 | " Test for g] |
| 1264 | call search('\<i_<Esc>$') |
| 1265 | let a = execute(":norm! g]") |
| 1266 | call assert_match('i_<Esc>.*insert.txt', a) |
| 1267 | |
| 1268 | if !empty(exepath('cscope')) && has('cscope') |
| 1269 | " setting cscopetag changes how g] works |
| 1270 | set cst |
| 1271 | exe "norm! g]" |
| 1272 | call assert_equal("insert.txt", fnamemodify(bufname('%'), ':t')) |
| 1273 | norm! yiW |
| 1274 | call assert_equal("*i_<Esc>*", @0) |
| 1275 | exe ":norm \<c-o>" |
| 1276 | " Test for CTRL-W g] |
| 1277 | exe "norm! \<C-W>g]" |
| 1278 | call assert_equal("insert.txt", fnamemodify(bufname('%'), ':t')) |
| 1279 | norm! yiW |
| 1280 | call assert_equal("*i_<Esc>*", @0) |
| 1281 | call assert_equal(3, winnr('$')) |
| 1282 | helpclose |
| 1283 | set nocst |
| 1284 | endif |
| 1285 | |
| 1286 | " Test for CTRL-W g] |
| 1287 | let a = execute("norm! \<C-W>g]") |
| 1288 | call assert_match('i_<Esc>.*insert.txt', a) |
| 1289 | |
| 1290 | " Test for CTRL-W CTRL-] |
| 1291 | exe "norm! \<C-W>\<C-]>" |
| 1292 | call assert_equal("insert.txt", fnamemodify(bufname('%'), ':t')) |
| 1293 | norm! yiW |
| 1294 | call assert_equal("*i_<Esc>*", @0) |
| 1295 | call assert_equal(3, winnr('$')) |
| 1296 | helpclose |
| 1297 | |
| 1298 | " Test for CTRL-W g CTRL-] |
| 1299 | exe "norm! \<C-W>g\<C-]>" |
| 1300 | call assert_equal("insert.txt", fnamemodify(bufname('%'), ':t')) |
| 1301 | norm! yiW |
| 1302 | call assert_equal("*i_<Esc>*", @0) |
| 1303 | call assert_equal(3, winnr('$')) |
| 1304 | helpclose |
| 1305 | |
| 1306 | " clean up |
| 1307 | helpclose |
| 1308 | endfu |
| 1309 | |
| 1310 | func! Test_normal26_put() |
| 1311 | " Test for ]p ]P [p and [P |
| 1312 | new |
| 1313 | call append(0, ['while read LINE', 'do', ' ((count++))', ' if [ $? -ne 0 ]; then', " echo 'Error writing file'", ' fi', 'done']) |
| 1314 | 1 |
| 1315 | /Error/y a |
| 1316 | 2 |
| 1317 | norm! "a]pj"a[p |
| 1318 | call assert_equal(['do', "echo 'Error writing file'", " echo 'Error writing file'", ' ((count++))'], getline(2,5)) |
| 1319 | 1 |
| 1320 | /^\s\{4}/ |
| 1321 | exe "norm! \"a]P3Eldt'" |
| 1322 | exe "norm! j\"a[P2Eldt'" |
| 1323 | call assert_equal([' if [ $? -ne 0 ]; then', " echo 'Error writing'", " echo 'Error'", " echo 'Error writing file'", ' fi'], getline(6,10)) |
| 1324 | |
| 1325 | " clean up |
| 1326 | bw! |
| 1327 | endfu |
| 1328 | |
| 1329 | func! Test_normal27_bracket() |
| 1330 | " Test for [' [` ]' ]` |
| 1331 | call Setup_NewWindow() |
| 1332 | 1,21s/.\+/ & b/ |
| 1333 | 1 |
| 1334 | norm! $ma |
| 1335 | 5 |
| 1336 | norm! $mb |
| 1337 | 10 |
| 1338 | norm! $mc |
| 1339 | 15 |
| 1340 | norm! $md |
| 1341 | 20 |
| 1342 | norm! $me |
| 1343 | |
| 1344 | " Test for [' |
| 1345 | 9 |
| 1346 | norm! 2[' |
| 1347 | call assert_equal(' 1 b', getline('.')) |
| 1348 | call assert_equal(1, line('.')) |
| 1349 | call assert_equal(3, col('.')) |
| 1350 | |
| 1351 | " Test for ]' |
| 1352 | norm! ]' |
| 1353 | call assert_equal(' 5 b', getline('.')) |
| 1354 | call assert_equal(5, line('.')) |
| 1355 | call assert_equal(3, col('.')) |
| 1356 | |
| 1357 | " No mark after line 21, cursor moves to first non blank on current line |
| 1358 | 21 |
| 1359 | norm! $]' |
| 1360 | call assert_equal(' 21 b', getline('.')) |
| 1361 | call assert_equal(21, line('.')) |
| 1362 | call assert_equal(3, col('.')) |
| 1363 | |
| 1364 | " Test for [` |
| 1365 | norm! 2[` |
| 1366 | call assert_equal(' 15 b', getline('.')) |
| 1367 | call assert_equal(15, line('.')) |
| 1368 | call assert_equal(8, col('.')) |
| 1369 | |
| 1370 | " Test for ]` |
| 1371 | norm! ]` |
| 1372 | call assert_equal(' 20 b', getline('.')) |
| 1373 | call assert_equal(20, line('.')) |
| 1374 | call assert_equal(8, col('.')) |
| 1375 | |
| 1376 | " clean up |
| 1377 | bw! |
| 1378 | endfu |
| 1379 | |
| 1380 | func! Test_normal28_parenthesis() |
| 1381 | " basic testing for ( and ) |
| 1382 | new |
| 1383 | call append(0, ['This is a test. With some sentences!', '', 'Even with a question? And one more. And no sentence here']) |
| 1384 | |
| 1385 | $ |
| 1386 | norm! d( |
| 1387 | call assert_equal(['This is a test. With some sentences!', '', 'Even with a question? And one more. ', ''], getline(1, '$')) |
| 1388 | norm! 2d( |
| 1389 | call assert_equal(['This is a test. With some sentences!', '', ' ', ''], getline(1, '$')) |
| 1390 | 1 |
| 1391 | norm! 0d) |
| 1392 | call assert_equal(['With some sentences!', '', ' ', ''], getline(1, '$')) |
| 1393 | |
| 1394 | call append('$', ['This is a long sentence', '', 'spanning', 'over several lines. ']) |
| 1395 | $ |
| 1396 | norm! $d( |
| 1397 | call assert_equal(['With some sentences!', '', ' ', '', 'This is a long sentence', ''], getline(1, '$')) |
| 1398 | |
| 1399 | " clean up |
| 1400 | bw! |
| 1401 | endfu |
| 1402 | |
| 1403 | fun! Test_normal29_brace() |
| 1404 | " basic test for { and } movements |
| 1405 | let text= ['A paragraph begins after each empty line, and also at each of a set of', |
| 1406 | \ 'paragraph macros, specified by the pairs of characters in the ''paragraphs''', |
| 1407 | \ 'option. The default is "IPLPPPQPP TPHPLIPpLpItpplpipbp", which corresponds to', |
| 1408 | \ 'the macros ".IP", ".LP", etc. (These are nroff macros, so the dot must be in', |
| 1409 | \ 'the first column). A section boundary is also a paragraph boundary.', |
| 1410 | \ 'Note that a blank line (only containing white space) is NOT a paragraph', |
| 1411 | \ 'boundary.', |
| 1412 | \ '', |
| 1413 | \ '', |
| 1414 | \ 'Also note that this does not include a ''{'' or ''}'' in the first column. When', |
| 1415 | \ 'the ''{'' flag is in ''cpoptions'' then ''{'' in the first column is used as a', |
| 1416 | \ 'paragraph boundary |posix|.', |
| 1417 | \ '{', |
| 1418 | \ 'This is no paragaraph', |
| 1419 | \ 'unless the ''{'' is set', |
| 1420 | \ 'in ''cpoptions''', |
| 1421 | \ '}', |
| 1422 | \ '.IP', |
| 1423 | \ 'The nroff macros IP seperates a paragraph', |
| 1424 | \ 'That means, it must be a ''.''', |
| 1425 | \ 'followed by IP', |
| 1426 | \ '.LPIt does not matter, if afterwards some', |
| 1427 | \ 'more characters follow.', |
| 1428 | \ '.SHAlso section boundaries from the nroff', |
| 1429 | \ 'macros terminate a paragraph. That means', |
| 1430 | \ 'a character like this:', |
| 1431 | \ '.NH', |
| 1432 | \ 'End of text here'] |
| 1433 | new |
| 1434 | call append(0, text) |
| 1435 | 1 |
| 1436 | norm! 0d2} |
| 1437 | call assert_equal(['.IP', |
| 1438 | \ 'The nroff macros IP seperates a paragraph', 'That means, it must be a ''.''', 'followed by IP', |
| 1439 | \ '.LPIt does not matter, if afterwards some', 'more characters follow.', '.SHAlso section boundaries from the nroff', |
| 1440 | \ 'macros terminate a paragraph. That means', 'a character like this:', '.NH', 'End of text here', ''], getline(1,'$')) |
| 1441 | norm! 0d} |
| 1442 | call assert_equal(['.LPIt does not matter, if afterwards some', 'more characters follow.', |
| 1443 | \ '.SHAlso section boundaries from the nroff', 'macros terminate a paragraph. That means', |
| 1444 | \ 'a character like this:', '.NH', 'End of text here', ''], getline(1, '$')) |
| 1445 | $ |
| 1446 | norm! d{ |
| 1447 | call assert_equal(['.LPIt does not matter, if afterwards some', 'more characters follow.', |
| 1448 | \ '.SHAlso section boundaries from the nroff', 'macros terminate a paragraph. That means', 'a character like this:', ''], getline(1, '$')) |
| 1449 | norm! d{ |
| 1450 | call assert_equal(['.LPIt does not matter, if afterwards some', 'more characters follow.', ''], getline(1,'$')) |
| 1451 | " Test with { in cpooptions |
| 1452 | %d |
| 1453 | call append(0, text) |
| 1454 | set cpo+={ |
| 1455 | 1 |
| 1456 | norm! 0d2} |
| 1457 | call assert_equal(['{', 'This is no paragaraph', 'unless the ''{'' is set', 'in ''cpoptions''', '}', |
| 1458 | \ '.IP', 'The nroff macros IP seperates a paragraph', 'That means, it must be a ''.''', |
| 1459 | \ 'followed by IP', '.LPIt does not matter, if afterwards some', 'more characters follow.', |
| 1460 | \ '.SHAlso section boundaries from the nroff', 'macros terminate a paragraph. That means', |
| 1461 | \ 'a character like this:', '.NH', 'End of text here', ''], getline(1,'$')) |
| 1462 | $ |
| 1463 | norm! d} |
| 1464 | call assert_equal(['{', 'This is no paragaraph', 'unless the ''{'' is set', 'in ''cpoptions''', '}', |
| 1465 | \ '.IP', 'The nroff macros IP seperates a paragraph', 'That means, it must be a ''.''', |
| 1466 | \ 'followed by IP', '.LPIt does not matter, if afterwards some', 'more characters follow.', |
| 1467 | \ '.SHAlso section boundaries from the nroff', 'macros terminate a paragraph. That means', |
| 1468 | \ 'a character like this:', '.NH', 'End of text here', ''], getline(1,'$')) |
| 1469 | norm! gg} |
| 1470 | norm! d5} |
| 1471 | call assert_equal(['{', 'This is no paragaraph', 'unless the ''{'' is set', 'in ''cpoptions''', '}', ''], getline(1,'$')) |
| 1472 | |
| 1473 | " clean up |
| 1474 | set cpo-={ |
| 1475 | bw! |
| 1476 | endfu |
| 1477 | |
| 1478 | fun! Test_normal30_changecase() |
| 1479 | " This test uses multi byte characters |
| 1480 | if !has("multi_byte") |
| 1481 | return |
| 1482 | endif |
| 1483 | new |
| 1484 | call append(0, 'This is a simple test: äüöß') |
| 1485 | norm! 1ggVu |
| 1486 | call assert_equal('this is a simple test: äüöß', getline('.')) |
| 1487 | norm! VU |
| 1488 | call assert_equal('THIS IS A SIMPLE TEST: ÄÜÖSS', getline('.')) |
| 1489 | norm! guu |
| 1490 | call assert_equal('this is a simple test: äüöss', getline('.')) |
| 1491 | norm! gUgU |
| 1492 | call assert_equal('THIS IS A SIMPLE TEST: ÄÜÖSS', getline('.')) |
| 1493 | norm! gugu |
| 1494 | call assert_equal('this is a simple test: äüöss', getline('.')) |
| 1495 | norm! gUU |
| 1496 | call assert_equal('THIS IS A SIMPLE TEST: ÄÜÖSS', getline('.')) |
| 1497 | norm! 010~ |
| 1498 | call assert_equal('this is a SIMPLE TEST: ÄÜÖSS', getline('.')) |
| 1499 | norm! V~ |
| 1500 | call assert_equal('THIS IS A simple test: äüöss', getline('.')) |
| 1501 | |
| 1502 | " clean up |
| 1503 | bw! |
| 1504 | endfu |
| 1505 | |
| 1506 | fun! Test_normal31_r_cmd() |
| 1507 | " Test for r command |
| 1508 | new |
| 1509 | call append(0, 'This is a simple test: abcd') |
| 1510 | exe "norm! 1gg$r\<cr>" |
| 1511 | call assert_equal(['This is a simple test: abc', '', ''], getline(1,'$')) |
| 1512 | exe "norm! 1gg2wlr\<cr>" |
| 1513 | call assert_equal(['This is a', 'simple test: abc', '', ''], getline(1,'$')) |
| 1514 | exe "norm! 2gg0W5r\<cr>" |
| 1515 | call assert_equal(['This is a', 'simple ', ' abc', '', ''], getline('1', '$')) |
| 1516 | set autoindent |
| 1517 | call setline(2, ['simple test: abc', '']) |
| 1518 | exe "norm! 2gg0W5r\<cr>" |
| 1519 | call assert_equal(['This is a', 'simple ', 'abc', '', '', ''], getline('1', '$')) |
| 1520 | exe "norm! 1ggVr\<cr>" |
| 1521 | call assert_equal('^M^M^M^M^M^M^M^M^M', strtrans(getline(1))) |
| 1522 | call setline(1, 'This is a') |
| 1523 | exe "norm! 1gg05rf" |
| 1524 | call assert_equal('fffffis a', getline(1)) |
| 1525 | |
| 1526 | " clean up |
| 1527 | set noautoindent |
| 1528 | bw! |
| 1529 | endfu |
| 1530 | |
| 1531 | func! Test_normal32_g_cmd1() |
| 1532 | " Test for g*, g# |
| 1533 | new |
| 1534 | call append(0, ['abc.x_foo', 'x_foobar.abc']) |
| 1535 | 1 |
| 1536 | norm! $g* |
| 1537 | call assert_equal('x_foo', @/) |
| 1538 | call assert_equal('x_foobar.abc', getline('.')) |
| 1539 | norm! $g# |
| 1540 | call assert_equal('abc', @/) |
| 1541 | call assert_equal('abc.x_foo', getline('.')) |
| 1542 | |
| 1543 | " clean up |
| 1544 | bw! |
| 1545 | endfu |
| 1546 | |
| 1547 | fun! Test_normal33_g_cmd2() |
| 1548 | if !has("jumplist") |
| 1549 | return |
| 1550 | endif |
| 1551 | " Tests for g cmds |
| 1552 | call Setup_NewWindow() |
| 1553 | " Test for g` |
| 1554 | clearjumps |
| 1555 | norm! ma10j |
| 1556 | let a=execute(':jumps') |
| 1557 | " empty jumplist |
| 1558 | call assert_equal('>', a[-1:]) |
| 1559 | norm! g`a |
| 1560 | call assert_equal('>', a[-1:]) |
| 1561 | call assert_equal(1, line('.')) |
| 1562 | call assert_equal('1', getline('.')) |
| 1563 | |
| 1564 | " Test for g; and g, |
| 1565 | norm! g; |
| 1566 | " there is only one change in the changelist |
| 1567 | " currently, when we setup the window |
| 1568 | call assert_equal(2, line('.')) |
| 1569 | call assert_fails(':norm! g;', 'E662') |
| 1570 | call assert_fails(':norm! g,', 'E663') |
| 1571 | let &ul=&ul |
| 1572 | call append('$', ['a', 'b', 'c', 'd']) |
| 1573 | let &ul=&ul |
| 1574 | call append('$', ['Z', 'Y', 'X', 'W']) |
| 1575 | let a = execute(':changes') |
| 1576 | call assert_match('2\s\+0\s\+2', a) |
| 1577 | call assert_match('101\s\+0\s\+a', a) |
| 1578 | call assert_match('105\s\+0\s\+Z', a) |
| 1579 | norm! 3g; |
| 1580 | call assert_equal(2, line('.')) |
| 1581 | norm! 2g, |
| 1582 | call assert_equal(105, line('.')) |
| 1583 | |
| 1584 | " Test for g& - global substitute |
| 1585 | %d |
| 1586 | call setline(1, range(1,10)) |
| 1587 | call append('$', ['a', 'b', 'c', 'd']) |
| 1588 | $s/\w/&&/g |
| 1589 | exe "norm! /[1-8]\<cr>" |
| 1590 | norm! g& |
| 1591 | call assert_equal(['11', '22', '33', '44', '55', '66', '77', '88', '9', '110', 'a', 'b', 'c', 'dd'], getline(1, '$')) |
| 1592 | |
| 1593 | " Test for gv |
| 1594 | %d |
| 1595 | call append('$', repeat(['abcdefgh'], 8)) |
| 1596 | exe "norm! 2gg02l\<c-v>2j2ly" |
| 1597 | call assert_equal(['cde', 'cde', 'cde'], getreg(0, 1, 1)) |
| 1598 | " in visual mode, gv swaps current and last selected region |
| 1599 | exe "norm! G0\<c-v>4k4lgvd" |
| 1600 | call assert_equal(['', 'abfgh', 'abfgh', 'abfgh', 'abcdefgh', 'abcdefgh', 'abcdefgh', 'abcdefgh', 'abcdefgh'], getline(1,'$')) |
| 1601 | exe "norm! G0\<c-v>4k4ly" |
| 1602 | exe "norm! gvood" |
| 1603 | call assert_equal(['', 'abfgh', 'abfgh', 'abfgh', 'fgh', 'fgh', 'fgh', 'fgh', 'fgh'], getline(1,'$')) |
| 1604 | |
| 1605 | " Test for gk/gj |
| 1606 | %d |
| 1607 | 15vsp |
| 1608 | set wrap listchars= sbr= |
| 1609 | let lineA='abcdefghijklmnopqrstuvwxyz' |
| 1610 | let lineB='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ' |
| 1611 | $put =lineA |
| 1612 | $put =lineB |
| 1613 | |
| 1614 | norm! 3gg0dgk |
| 1615 | call assert_equal(['', 'abcdefghijklmno', '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'], getline(1, '$')) |
| 1616 | set nu |
| 1617 | norm! 3gg0gjdgj |
| 1618 | call assert_equal(['', 'abcdefghijklmno', '0123456789AMNOPQRSTUVWXYZ'], getline(1,'$')) |
| 1619 | |
| 1620 | " Test for gJ |
| 1621 | norm! 2gggJ |
| 1622 | call assert_equal(['', 'abcdefghijklmno0123456789AMNOPQRSTUVWXYZ'], getline(1,'$')) |
| 1623 | call assert_equal(16, col('.')) |
| 1624 | " shouldn't do anything |
| 1625 | norm! 10gJ |
| 1626 | call assert_equal(1, col('.')) |
| 1627 | |
| 1628 | " Test for g0 g^ gm g$ |
| 1629 | exe "norm! 2gg0gji " |
| 1630 | call assert_equal(['', 'abcdefghijk lmno0123456789AMNOPQRSTUVWXYZ'], getline(1,'$')) |
| 1631 | norm! g0yl |
| 1632 | call assert_equal(12, col('.')) |
| 1633 | call assert_equal(' ', getreg(0)) |
| 1634 | norm! g$yl |
| 1635 | call assert_equal(22, col('.')) |
| 1636 | call assert_equal('3', getreg(0)) |
| 1637 | norm! gmyl |
| 1638 | call assert_equal(17, col('.')) |
| 1639 | call assert_equal('n', getreg(0)) |
| 1640 | norm! g^yl |
| 1641 | call assert_equal(15, col('.')) |
| 1642 | call assert_equal('l', getreg(0)) |
| 1643 | |
| 1644 | " Test for g Ctrl-G |
| 1645 | let a=execute(":norm! g\<c-g>") |
| 1646 | call assert_match('Col 15 of 43; Line 2 of 2; Word 2 of 2; Byte 16 of 45', a) |
| 1647 | |
| 1648 | " Test for gI |
| 1649 | norm! gIfoo |
| 1650 | call assert_equal(['', 'fooabcdefghijk lmno0123456789AMNOPQRSTUVWXYZ'], getline(1,'$')) |
| 1651 | |
| 1652 | " Test for gi |
| 1653 | wincmd c |
| 1654 | %d |
| 1655 | set tw=0 |
| 1656 | call setline(1, ['foobar', 'new line']) |
| 1657 | norm! A next word |
| 1658 | $put ='third line' |
| 1659 | norm! gi another word |
| 1660 | call assert_equal(['foobar next word another word', 'new line', 'third line'], getline(1,'$')) |
| 1661 | |
| 1662 | " clean up |
| 1663 | bw! |
| 1664 | endfu |
| 1665 | |
| 1666 | fun! Test_normal34_g_cmd3() |
| 1667 | if !has("multi_byte") |
| 1668 | return |
| 1669 | endif |
| 1670 | " Test for g8 |
| 1671 | new |
| 1672 | call append(0, 'abcdefghijklmnopqrstuvwxyzäüö') |
| 1673 | let a=execute(':norm! 1gg$g8') |
| 1674 | call assert_equal('c3 b6 ', a[1:]) |
| 1675 | |
| 1676 | " Test for gp gP |
| 1677 | call append(1, range(1,10)) |
| 1678 | " clean up |
| 1679 | bw! |
| 1680 | endfu |
| 1681 | |
| 1682 | fun! Test_normal35_g_cmd4() |
| 1683 | " Test for g< |
| 1684 | " Cannot capture its output, |
| 1685 | " probably a bug, therefore, test disabled: |
| 1686 | return |
| 1687 | echo "a\nb\nc\nd" |
| 1688 | let b=execute(':norm! g<') |
| 1689 | call assert_true(!empty(b), 'failed `execute(g<)`') |
| 1690 | endfu |
| 1691 | |
| 1692 | fun! Test_normal36_g_cmd5() |
| 1693 | new |
| 1694 | call append(0, 'abcdefghijklmnopqrstuvwxyz') |
| 1695 | " Test for gp gP |
| 1696 | call append(1, range(1,10)) |
| 1697 | 1 |
| 1698 | norm! 1yy |
| 1699 | 3 |
| 1700 | norm! gp |
| 1701 | call assert_equal([0, 5, 1, 0, 1], getcurpos()) |
| 1702 | $ |
| 1703 | norm! gP |
| 1704 | call assert_equal([0, 14, 1, 0, 1], getcurpos()) |
| 1705 | |
| 1706 | " Test for go |
| 1707 | norm! 26go |
| 1708 | call assert_equal([0, 1, 26, 0, 26], getcurpos()) |
| 1709 | norm! 27go |
| 1710 | call assert_equal([0, 1, 26, 0, 26], getcurpos()) |
| 1711 | norm! 28go |
| 1712 | call assert_equal([0, 2, 1, 0, 1], getcurpos()) |
| 1713 | set ff=dos |
| 1714 | norm! 29go |
| 1715 | call assert_equal([0, 2, 1, 0, 1], getcurpos()) |
| 1716 | set ff=unix |
| 1717 | norm! gg0 |
| 1718 | norm! 101go |
| 1719 | call assert_equal([0, 13, 26, 0, 26], getcurpos()) |
| 1720 | norm! 103go |
| 1721 | call assert_equal([0, 14, 1, 0, 1], getcurpos()) |
| 1722 | " count > buffer content |
| 1723 | norm! 120go |
| 1724 | call assert_equal([0, 14, 1, 0, 2147483647], getcurpos()) |
| 1725 | " clean up |
| 1726 | bw! |
| 1727 | endfu |
| 1728 | |
| 1729 | fun! Test_normal37_g_cmd6() |
| 1730 | " basic test for gt and gT |
| 1731 | tabnew 1.txt |
| 1732 | tabnew 2.txt |
| 1733 | tabnew 3.txt |
| 1734 | norm! 1gt |
| 1735 | call assert_equal(1, tabpagenr()) |
| 1736 | norm! 3gt |
| 1737 | call assert_equal(3, tabpagenr()) |
| 1738 | norm! 1gT |
| 1739 | " count gT goes not to the absolute tabpagenumber |
| 1740 | " but, but goes to the count previous tabpagenumber |
| 1741 | call assert_equal(2, tabpagenr()) |
| 1742 | " wrap around |
| 1743 | norm! 3gT |
| 1744 | call assert_equal(3, tabpagenr()) |
| 1745 | " gt does not wrap around |
| 1746 | norm! 5gt |
| 1747 | call assert_equal(3, tabpagenr()) |
| 1748 | |
| 1749 | for i in range(3) |
| 1750 | tabclose |
| 1751 | endfor |
| 1752 | " clean up |
| 1753 | call assert_fails(':tabclose', 'E784') |
| 1754 | endfu |
| 1755 | |
| 1756 | fun! Test_normal38_nvhome() |
| 1757 | " Test for <Home> and <C-Home> key |
| 1758 | new |
| 1759 | call setline(1, range(10)) |
| 1760 | $ |
| 1761 | setl et sw=2 |
| 1762 | norm! V10>$ |
| 1763 | " count is ignored |
| 1764 | exe "norm! 10\<home>" |
| 1765 | call assert_equal(1, col('.')) |
| 1766 | exe "norm! \<home>" |
| 1767 | call assert_equal([0, 10, 1, 0, 1], getcurpos()) |
| 1768 | exe "norm! 5\<c-home>" |
| 1769 | call assert_equal([0, 5, 1, 0, 1], getcurpos()) |
| 1770 | exe "norm! \<c-home>" |
| 1771 | call assert_equal([0, 1, 1, 0, 1], getcurpos()) |
| 1772 | |
| 1773 | " clean up |
| 1774 | bw! |
| 1775 | endfu |
| 1776 | |
| 1777 | fun! Test_normal39_cw() |
| 1778 | " Test for cw and cW on whitespace |
| 1779 | " and cpo+=w setting |
| 1780 | new |
| 1781 | set tw=0 |
| 1782 | call append(0, 'here are some words') |
| 1783 | norm! 1gg0elcwZZZ |
| 1784 | call assert_equal('hereZZZare some words', getline('.')) |
| 1785 | norm! 1gg0elcWYYY |
| 1786 | call assert_equal('hereZZZareYYYsome words', getline('.')) |
| 1787 | set cpo+=w |
| 1788 | call setline(1, 'here are some words') |
| 1789 | norm! 1gg0elcwZZZ |
| 1790 | call assert_equal('hereZZZ are some words', getline('.')) |
| 1791 | norm! 1gg2elcWYYY |
| 1792 | call assert_equal('hereZZZ areYYY some words', getline('.')) |
| 1793 | set cpo-=w |
| 1794 | norm! 2gg0cwfoo |
| 1795 | call assert_equal('foo', getline('.')) |
| 1796 | |
| 1797 | " clean up |
| 1798 | bw! |
| 1799 | endfu |
| 1800 | |
| 1801 | fun! Test_normal40_ctrl_bsl() |
| 1802 | " Basic test for CTRL-\ commands |
| 1803 | new |
| 1804 | call append(0, 'here are some words') |
| 1805 | exe "norm! 1gg0a\<C-\>\<C-N>" |
| 1806 | call assert_equal('n', mode()) |
| 1807 | call assert_equal(1, col('.')) |
| 1808 | call assert_equal('', visualmode()) |
| 1809 | exe "norm! 1gg0viw\<C-\>\<C-N>" |
| 1810 | call assert_equal('n', mode()) |
| 1811 | call assert_equal(4, col('.')) |
| 1812 | exe "norm! 1gg0a\<C-\>\<C-G>" |
| 1813 | call assert_equal('n', mode()) |
| 1814 | call assert_equal(1, col('.')) |
| 1815 | "imap <buffer> , <c-\><c-n> |
| 1816 | set im |
| 1817 | exe ":norm! \<c-\>\<c-n>dw" |
| 1818 | set noim |
| 1819 | call assert_equal('are some words', getline(1)) |
| 1820 | call assert_false(&insertmode) |
| 1821 | |
| 1822 | " clean up |
| 1823 | bw! |
| 1824 | endfu |
| 1825 | |
| 1826 | fun! Test_normal41_insert_reg() |
| 1827 | " Test for <c-r>=, <c-r><c-r>= and <c-r><c-o>= |
| 1828 | " in insert mode |
| 1829 | new |
| 1830 | set sts=2 sw=2 ts=8 tw=0 |
| 1831 | call append(0, ["aaa\tbbb\tccc", '', '', '']) |
| 1832 | let a=getline(1) |
| 1833 | norm! 2gg0 |
| 1834 | exe "norm! a\<c-r>=a\<cr>" |
| 1835 | norm! 3gg0 |
| 1836 | exe "norm! a\<c-r>\<c-r>=a\<cr>" |
| 1837 | norm! 4gg0 |
| 1838 | exe "norm! a\<c-r>\<c-o>=a\<cr>" |
| 1839 | call assert_equal(['aaa bbb ccc', 'aaa bbb ccc', 'aaa bbb ccc', 'aaa bbb ccc', ''], getline(1, '$')) |
| 1840 | |
| 1841 | " clean up |
| 1842 | set sts=0 sw=8 ts=8 |
| 1843 | "bw! |
| 1844 | endfu |
| 1845 | |
| 1846 | func! Test_normal42_halfpage() |
| 1847 | " basic test for Ctrl-D and Ctrl-U |
| 1848 | call Setup_NewWindow() |
| 1849 | call assert_equal(5, &scroll) |
| 1850 | exe "norm! \<c-d>" |
| 1851 | call assert_equal('6', getline('.')) |
| 1852 | exe "norm! 2\<c-d>" |
| 1853 | call assert_equal('8', getline('.')) |
| 1854 | call assert_equal(2, &scroll) |
| 1855 | set scroll=5 |
| 1856 | exe "norm! \<c-u>" |
| 1857 | call assert_equal('3', getline('.')) |
| 1858 | 1 |
| 1859 | set scrolloff=5 |
| 1860 | exe "norm! \<c-d>" |
| 1861 | call assert_equal('10', getline('.')) |
| 1862 | exe "norm! \<c-u>" |
| 1863 | call assert_equal('5', getline('.')) |
| 1864 | 1 |
| 1865 | set scrolloff=99 |
| 1866 | exe "norm! \<c-d>" |
| 1867 | call assert_equal('10', getline('.')) |
| 1868 | set scrolloff=0 |
| 1869 | 100 |
| 1870 | exe "norm! $\<c-u>" |
| 1871 | call assert_equal('95', getline('.')) |
| 1872 | call assert_equal([0, 95, 1, 0, 1], getcurpos()) |
| 1873 | 100 |
| 1874 | set nostartofline |
| 1875 | exe "norm! $\<c-u>" |
| 1876 | call assert_equal('95', getline('.')) |
| 1877 | call assert_equal([0, 95, 2, 0, 2147483647], getcurpos()) |
| 1878 | " cleanup |
| 1879 | set startofline |
| 1880 | bw! |
| 1881 | endfu |
| 1882 | |
| 1883 | fun! Test_normal43_textobject1() |
| 1884 | " basic tests for text object aw |
| 1885 | new |
| 1886 | call append(0, ['foobar,eins,foobar', 'foo,zwei,foo ']) |
| 1887 | " diw |
| 1888 | norm! 1gg0diw |
| 1889 | call assert_equal([',eins,foobar', 'foo,zwei,foo ', ''], getline(1,'$')) |
| 1890 | " daw |
| 1891 | norm! 2ggEdaw |
| 1892 | call assert_equal([',eins,foobar', 'foo,zwei,', ''], getline(1, '$')) |
| 1893 | %d |
| 1894 | call append(0, ["foo\teins\tfoobar", "foo\tzwei\tfoo "]) |
| 1895 | " diW |
| 1896 | norm! 2ggwd2iW |
| 1897 | call assert_equal(['foo eins foobar', 'foo foo ', ''], getline(1,'$')) |
| 1898 | " daW |
| 1899 | norm! 1ggd2aW |
| 1900 | call assert_equal(['foobar', 'foo foo ', ''], getline(1,'$')) |
| 1901 | |
| 1902 | %d |
| 1903 | call append(0, ["foo\teins\tfoobar", "foo\tzwei\tfoo "]) |
| 1904 | " aw in visual line mode switches to characterwise mode |
| 1905 | norm! 2gg$Vawd |
| 1906 | call assert_equal(['foo eins foobar', 'foo zwei foo'], getline(1,'$')) |
| 1907 | norm! 1gg$Viwd |
| 1908 | call assert_equal(['foo eins ', 'foo zwei foo'], getline(1,'$')) |
| 1909 | |
| 1910 | " clean up |
| 1911 | bw! |
| 1912 | endfu |
| 1913 | |
| 1914 | func! Test_normal44_textobjects2() |
| 1915 | " basic testing for is and as text objects |
| 1916 | new |
| 1917 | call append(0, ['This is a test. With some sentences!', '', 'Even with a question? And one more. And no sentence here']) |
| 1918 | " Test for dis - does not remove trailing whitespace |
| 1919 | norm! 1gg0dis |
| 1920 | call assert_equal([' With some sentences!', '', 'Even with a question? And one more. And no sentence here', ''], getline(1,'$')) |
| 1921 | " Test for das - removes leading whitespace |
| 1922 | norm! 3ggf?ldas |
| 1923 | call assert_equal([' With some sentences!', '', 'Even with a question? And no sentence here', ''], getline(1,'$')) |
| 1924 | " when used in visual mode, is made characterwise |
| 1925 | norm! 3gg$Visy |
| 1926 | call assert_equal('v', visualmode()) |
| 1927 | " reset visualmode() |
| 1928 | norm! 3ggVy |
| 1929 | norm! 3gg$Vasy |
| 1930 | call assert_equal('v', visualmode()) |
| 1931 | " basic testing for textobjects a< and at |
| 1932 | %d |
| 1933 | call setline(1, ['<div> ','<a href="foobar" class="foo">xyz</a>',' </div>', ' ']) |
| 1934 | " a< |
| 1935 | norm! 1gg0da< |
| 1936 | call assert_equal([' ', '<a href="foobar" class="foo">xyz</a>', ' </div>', ' '], getline(1,'$')) |
| 1937 | norm! 1pj |
| 1938 | call assert_equal([' <div>', '<a href="foobar" class="foo">xyz</a>', ' </div>', ' '], getline(1,'$')) |
| 1939 | " at |
| 1940 | norm! d2at |
| 1941 | call assert_equal([' '], getline(1,'$')) |
| 1942 | %d |
| 1943 | call setline(1, ['<div> ','<a href="foobar" class="foo">xyz</a>',' </div>', ' ']) |
| 1944 | " i< |
| 1945 | norm! 1gg0di< |
| 1946 | call assert_equal(['<> ', '<a href="foobar" class="foo">xyz</a>', ' </div>', ' '], getline(1,'$')) |
| 1947 | norm! 1Pj |
| 1948 | call assert_equal(['<div> ', '<a href="foobar" class="foo">xyz</a>', ' </div>', ' '], getline(1,'$')) |
| 1949 | norm! d2it |
| 1950 | call assert_equal(['<div></div>',' '], getline(1,'$')) |
| 1951 | " basic testing for a[ and i[ text object |
| 1952 | %d |
| 1953 | call setline(1, [' ', '[', 'one [two]', 'thre', ']']) |
| 1954 | norm! 3gg0di[ |
| 1955 | call assert_equal([' ', '[', ']'], getline(1,'$')) |
| 1956 | call setline(1, [' ', '[', 'one [two]', 'thre', ']']) |
| 1957 | norm! 3gg0ftd2a[ |
| 1958 | call assert_equal([' '], getline(1,'$')) |
| 1959 | %d |
| 1960 | " Test for i" when cursor is in front of a quoted object |
| 1961 | call append(0, 'foo "bar"') |
| 1962 | norm! 1gg0di" |
| 1963 | call assert_equal(['foo ""', ''], getline(1,'$')) |
| 1964 | |
| 1965 | " clean up |
| 1966 | bw! |
| 1967 | endfu |
| 1968 | |
| 1969 | func! Test_normal45_drop() |
| 1970 | if !has("dnd") |
| 1971 | return |
| 1972 | endif |
| 1973 | " basic test for :drop command |
| 1974 | " unfortunately, without a gui, we can't really test much here, |
| 1975 | " so simply test that ~p fails (which uses the drop register) |
| 1976 | new |
| 1977 | call assert_fails(':norm! "~p', 'E353') |
| 1978 | call assert_equal([], getreg('~', 1, 1)) |
| 1979 | " the ~ register is read only |
| 1980 | call assert_fails(':let @~="1"', 'E354') |
| 1981 | bw! |
| 1982 | endfu |
| 1983 | |
| 1984 | func! Test_normal46_ignore() |
| 1985 | new |
| 1986 | " How to test this? |
| 1987 | " let's just for now test, that the buffer |
| 1988 | " does not change |
| 1989 | call feedkeys("\<c-s>", 't') |
| 1990 | call assert_equal([''], getline(1,'$')) |
| 1991 | |
| 1992 | " clean up |
| 1993 | bw! |
| 1994 | endfu |