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() |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 39 | new |
| 40 | call append(0, ['1 This is a simple test: abcd', '2 This is the second line', '3 this is the third line']) |
| 41 | 1 |
| 42 | exe "norm! Sfoobar\<esc>" |
| 43 | call assert_equal(['foobar', '2 This is the second line', '3 this is the third line', ''], getline(1,'$')) |
| 44 | 2 |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 45 | exe "norm! $vbsone" |
| 46 | call assert_equal(['foobar', '2 This is the second one', '3 this is the third line', ''], getline(1,'$')) |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 47 | norm! VS Second line here |
| 48 | call assert_equal(['foobar', ' Second line here', '3 this is the third line', ''], getline(1, '$')) |
| 49 | %d |
| 50 | call append(0, ['4 This is a simple test: abcd', '5 This is the second line', '6 this is the third line']) |
| 51 | call append(0, ['1 This is a simple test: abcd', '2 This is the second line', '3 this is the third line']) |
| 52 | |
| 53 | 1 |
| 54 | norm! 2D |
| 55 | 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,'$')) |
| 56 | set cpo+=# |
| 57 | norm! 4D |
| 58 | call assert_equal(['', '4 This is a simple test: abcd', '5 This is the second line', '6 this is the third line', ''], getline(1,'$')) |
| 59 | |
| 60 | " clean up |
| 61 | set cpo-=# |
| 62 | bw! |
| 63 | endfu |
| 64 | |
| 65 | func! Test_normal01_keymodel() |
| 66 | call Setup_NewWindow() |
| 67 | " Test 1: depending on 'keymodel' <s-down> does something different |
| 68 | :50 |
| 69 | call feedkeys("V\<S-Up>y", 'tx') |
| 70 | call assert_equal(['47', '48', '49', '50'], getline("'<", "'>")) |
| 71 | :set keymodel=startsel |
| 72 | :50 |
| 73 | call feedkeys("V\<S-Up>y", 'tx') |
| 74 | call assert_equal(['49', '50'], getline("'<", "'>")) |
| 75 | " Start visual mode when keymodel = startsel |
| 76 | :50 |
| 77 | call feedkeys("\<S-Up>y", 'tx') |
| 78 | call assert_equal(['49', '5'], getreg(0, 0, 1)) |
| 79 | " Do not start visual mode when keymodel= |
| 80 | :set keymodel= |
| 81 | :50 |
| 82 | call feedkeys("\<S-Up>y$", 'tx') |
| 83 | call assert_equal(['42'], getreg(0, 0, 1)) |
| 84 | |
| 85 | " clean up |
| 86 | bw! |
| 87 | endfunc |
| 88 | |
| 89 | func! Test_normal02_selectmode() |
| 90 | " some basic select mode tests |
| 91 | call Setup_NewWindow() |
| 92 | 50 |
| 93 | norm! gHy |
| 94 | call assert_equal('y51', getline('.')) |
| 95 | call setline(1, range(1,100)) |
| 96 | 50 |
| 97 | exe ":norm! V9jo\<c-g>y" |
| 98 | call assert_equal('y60', getline('.')) |
| 99 | " clean up |
| 100 | bw! |
| 101 | endfu |
| 102 | |
| 103 | func! Test_normal03_join() |
| 104 | " basic join test |
| 105 | call Setup_NewWindow() |
| 106 | 50 |
| 107 | norm! VJ |
| 108 | call assert_equal('50 51', getline('.')) |
| 109 | $ |
| 110 | norm! J |
| 111 | call assert_equal('100', getline('.')) |
| 112 | $ |
| 113 | norm! V9-gJ |
| 114 | call assert_equal('919293949596979899100', getline('.')) |
| 115 | call setline(1, range(1,100)) |
| 116 | $ |
| 117 | :j 10 |
| 118 | call assert_equal('100', getline('.')) |
| 119 | " clean up |
| 120 | bw! |
| 121 | endfu |
| 122 | |
| 123 | func! Test_normal04_filter() |
| 124 | " basic filter test |
| 125 | " only test on non windows platform |
| 126 | if has("win32") || has("win64") || has("win95") |
| 127 | return |
| 128 | endif |
| 129 | call Setup_NewWindow() |
| 130 | 1 |
| 131 | call feedkeys("!!sed -e 's/^/| /'\n", 'tx') |
| 132 | call assert_equal('| 1', getline('.')) |
| 133 | 90 |
| 134 | :sil :!echo one |
| 135 | call feedkeys('.', 'tx') |
| 136 | call assert_equal('| 90', getline('.')) |
| 137 | 95 |
| 138 | set cpo+=! |
| 139 | " 2 <CR>, 1: for executing the command, |
| 140 | " 2: clear hit-enter-prompt |
| 141 | call feedkeys("!!\n", 'tx') |
| 142 | call feedkeys(":!echo one\n\n", 'tx') |
| 143 | call feedkeys(".", 'tx') |
| 144 | call assert_equal('one', getline('.')) |
| 145 | set cpo-=! |
| 146 | bw! |
| 147 | endfu |
| 148 | |
| 149 | func! Test_normal05_formatexpr() |
| 150 | " basic formatexpr test |
| 151 | call Setup_NewWindow() |
| 152 | %d_ |
| 153 | call setline(1, ['here: 1 ', '2', 'here: 3 ', '4', 'not here: ']) |
| 154 | 1 |
| 155 | set formatexpr=MyFormatExpr() |
| 156 | norm! gqG |
| 157 | call assert_equal(['here: 1->$', '2', 'here: 3->$', '4', 'not here: '], getline(1,'$')) |
| 158 | set formatexpr= |
| 159 | bw! |
| 160 | endfu |
| 161 | |
Bram Moolenaar | d77f9d5 | 2016-09-04 15:13:39 +0200 | [diff] [blame] | 162 | func Test_normal05_formatexpr_newbuf() |
| 163 | " Edit another buffer in the 'formatexpr' function |
| 164 | new |
| 165 | func! Format() |
| 166 | edit another |
| 167 | endfunc |
| 168 | set formatexpr=Format() |
| 169 | norm gqG |
| 170 | bw! |
| 171 | set formatexpr= |
| 172 | endfunc |
| 173 | |
| 174 | func Test_normal05_formatexpr_setopt() |
| 175 | " Change the 'formatexpr' value in the function |
| 176 | new |
| 177 | func! Format() |
| 178 | set formatexpr= |
| 179 | endfunc |
| 180 | set formatexpr=Format() |
| 181 | norm gqG |
| 182 | bw! |
| 183 | set formatexpr= |
| 184 | endfunc |
| 185 | |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 186 | func! Test_normal06_formatprg() |
| 187 | " basic test for formatprg |
| 188 | " only test on non windows platform |
| 189 | if has("win32") || has("win64") || has("win95") |
| 190 | return |
| 191 | else |
| 192 | " uses sed to number non-empty lines |
| 193 | call writefile(['#!/bin/sh', 'sed ''/./=''|sed ''/./{', 'N', 's/\n/ /', '}'''], 'Xsed_format.sh') |
| 194 | call system('chmod +x ./Xsed_format.sh') |
| 195 | endif |
| 196 | call Setup_NewWindow() |
| 197 | %d |
| 198 | call setline(1, ['a', '', 'c', '', ' ', 'd', 'e']) |
| 199 | set formatprg=./Xsed_format.sh |
| 200 | norm! gggqG |
| 201 | call assert_equal(['1 a', '', '3 c', '', '5 ', '6 d', '7 e'], getline(1, '$')) |
| 202 | " clean up |
| 203 | set formatprg= |
| 204 | call delete('Xsed_format.sh') |
| 205 | bw! |
| 206 | endfu |
| 207 | |
| 208 | func! Test_normal07_internalfmt() |
| 209 | " basic test for internal formmatter to textwidth of 12 |
| 210 | let list=range(1,11) |
| 211 | call map(list, 'v:val." "') |
| 212 | 10new |
| 213 | call setline(1, list) |
| 214 | set tw=12 |
| 215 | norm! gggqG |
| 216 | call assert_equal(['1 2 3', '4 5 6', '7 8 9', '10 11 '], getline(1, '$')) |
| 217 | " clean up |
Bram Moolenaar | 3184509 | 2016-09-05 22:58:31 +0200 | [diff] [blame] | 218 | set formatprg= tw=0 |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 219 | bw! |
| 220 | endfu |
| 221 | |
| 222 | func! Test_normal08_fold() |
| 223 | " basic tests for foldopen/folddelete |
| 224 | if !has("folding") |
| 225 | return |
| 226 | endif |
| 227 | call Setup_NewWindow() |
| 228 | 50 |
| 229 | setl foldenable fdm=marker |
| 230 | " First fold |
| 231 | norm! V4jzf |
| 232 | " check that folds have been created |
| 233 | call assert_equal(['50/*{{{*/', '51', '52', '53', '54/*}}}*/'], getline(50,54)) |
| 234 | " Second fold |
| 235 | 46 |
| 236 | norm! V10jzf |
| 237 | " check that folds have been created |
| 238 | call assert_equal('46/*{{{*/', getline(46)) |
| 239 | call assert_equal('60/*}}}*/', getline(60)) |
| 240 | norm! k |
| 241 | call assert_equal('45', getline('.')) |
| 242 | norm! j |
| 243 | call assert_equal('46/*{{{*/', getline('.')) |
| 244 | norm! j |
| 245 | call assert_equal('61', getline('.')) |
| 246 | norm! k |
| 247 | " open a fold |
| 248 | norm! Vzo |
| 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('47', getline('.')) |
| 255 | norm! k |
| 256 | norm! zcVzO |
| 257 | call assert_equal('46/*{{{*/', getline('.')) |
| 258 | norm! j |
| 259 | call assert_equal('47', getline('.')) |
| 260 | norm! j |
| 261 | call assert_equal('48', getline('.')) |
| 262 | norm! j |
| 263 | call assert_equal('49', getline('.')) |
| 264 | norm! j |
| 265 | call assert_equal('50/*{{{*/', getline('.')) |
| 266 | norm! j |
| 267 | call assert_equal('51', getline('.')) |
| 268 | " delete folds |
| 269 | :46 |
| 270 | " collapse fold |
| 271 | norm! V14jzC |
| 272 | " delete all folds recursively |
| 273 | norm! VzD |
| 274 | call assert_equal(['46', '47', '48', '49', '50', '51', '52', '53', '54', '55', '56', '57', '58', '59', '60'], getline(46,60)) |
| 275 | |
| 276 | " clean up |
| 277 | setl nofoldenable fdm=marker |
| 278 | bw! |
| 279 | endfu |
| 280 | |
| 281 | func! Test_normal09_operatorfunc() |
| 282 | " Test operatorfunc |
| 283 | call Setup_NewWindow() |
| 284 | " Add some spaces for counting |
| 285 | 50,60s/$/ / |
| 286 | unlet! g:a |
| 287 | let g:a=0 |
| 288 | nmap <buffer><silent> ,, :set opfunc=CountSpaces<CR>g@ |
| 289 | vmap <buffer><silent> ,, :<C-U>call CountSpaces(visualmode(), 1)<CR> |
| 290 | 50 |
| 291 | norm V2j,, |
| 292 | call assert_equal(6, g:a) |
| 293 | norm V,, |
| 294 | call assert_equal(2, g:a) |
| 295 | norm ,,l |
| 296 | call assert_equal(0, g:a) |
| 297 | 50 |
| 298 | exe "norm 0\<c-v>10j2l,," |
| 299 | call assert_equal(11, g:a) |
| 300 | 50 |
| 301 | norm V10j,, |
| 302 | call assert_equal(22, g:a) |
| 303 | |
| 304 | " clean up |
| 305 | unmap <buffer> ,, |
| 306 | set opfunc= |
| 307 | bw! |
| 308 | endfu |
| 309 | |
| 310 | func! Test_normal10_expand() |
| 311 | " Test for expand() |
| 312 | 10new |
| 313 | call setline(1, ['1', 'ifooar,,cbar']) |
| 314 | 2 |
| 315 | norm! $ |
| 316 | let a=expand('<cword>') |
| 317 | let b=expand('<cWORD>') |
| 318 | call assert_equal('cbar', a) |
| 319 | call assert_equal('ifooar,,cbar', b) |
| 320 | " clean up |
| 321 | bw! |
| 322 | endfu |
| 323 | |
| 324 | func! Test_normal11_showcmd() |
| 325 | " test for 'showcmd' |
| 326 | 10new |
| 327 | exe "norm! ofoobar\<esc>" |
| 328 | call assert_equal(2, line('$')) |
| 329 | set showcmd |
| 330 | exe "norm! ofoobar2\<esc>" |
| 331 | call assert_equal(3, line('$')) |
| 332 | exe "norm! VAfoobar3\<esc>" |
| 333 | call assert_equal(3, line('$')) |
| 334 | exe "norm! 0d3\<del>2l" |
| 335 | call assert_equal('obar2foobar3', getline('.')) |
| 336 | bw! |
| 337 | endfu |
| 338 | |
| 339 | func! Test_normal12_nv_error() |
| 340 | " Test for nv_error |
| 341 | 10new |
| 342 | call setline(1, range(1,5)) |
| 343 | " should not do anything, just beep |
| 344 | exe "norm! <c-k>" |
| 345 | call assert_equal(map(range(1,5), 'string(v:val)'), getline(1,'$')) |
| 346 | bw! |
| 347 | endfu |
| 348 | |
| 349 | func! Test_normal13_help() |
| 350 | " Test for F1 |
| 351 | call assert_equal(1, winnr()) |
| 352 | call feedkeys("\<f1>", 'txi') |
| 353 | call assert_match('help\.txt', bufname('%')) |
| 354 | call assert_equal(2, winnr('$')) |
| 355 | bw! |
| 356 | endfu |
| 357 | |
| 358 | func! Test_normal14_page() |
| 359 | " basic test for Ctrl-F and Ctrl-B |
| 360 | call Setup_NewWindow() |
| 361 | exe "norm! \<c-f>" |
| 362 | call assert_equal('9', getline('.')) |
| 363 | exe "norm! 2\<c-f>" |
| 364 | call assert_equal('25', getline('.')) |
| 365 | exe "norm! 2\<c-b>" |
| 366 | call assert_equal('18', getline('.')) |
| 367 | 1 |
| 368 | set scrolloff=5 |
| 369 | exe "norm! 2\<c-f>" |
| 370 | call assert_equal('21', getline('.')) |
| 371 | exe "norm! \<c-b>" |
| 372 | call assert_equal('13', getline('.')) |
| 373 | 1 |
| 374 | set scrolloff=99 |
| 375 | exe "norm! \<c-f>" |
| 376 | call assert_equal('13', getline('.')) |
| 377 | set scrolloff=0 |
| 378 | 100 |
| 379 | exe "norm! $\<c-b>" |
| 380 | call assert_equal('92', getline('.')) |
| 381 | call assert_equal([0, 92, 1, 0, 1], getcurpos()) |
| 382 | 100 |
| 383 | set nostartofline |
| 384 | exe "norm! $\<c-b>" |
| 385 | call assert_equal('92', getline('.')) |
| 386 | call assert_equal([0, 92, 2, 0, 2147483647], getcurpos()) |
| 387 | " cleanup |
| 388 | set startofline |
| 389 | bw! |
| 390 | endfu |
| 391 | |
Bram Moolenaar | bc54f3f | 2016-09-04 14:34:28 +0200 | [diff] [blame] | 392 | func! Test_normal14_page_eol() |
| 393 | 10new |
| 394 | norm oxxxxxxx |
| 395 | exe "norm 2\<c-f>" |
| 396 | " check with valgrind that cursor is put back in column 1 |
| 397 | exe "norm 2\<c-b>" |
| 398 | bw! |
| 399 | endfunc |
| 400 | |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 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") |
Bram Moolenaar | df0db16 | 2016-09-06 20:37:41 +0200 | [diff] [blame^] | 1128 | call delete("./Xspellfile.add.spl") |
| 1129 | call delete("./Xspellfile2.add.spl") |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 1130 | |
| 1131 | " zux -> no-op |
| 1132 | 2 |
| 1133 | norm! $zux |
| 1134 | call assert_equal([], glob('Xspellfile.add',0,1)) |
| 1135 | call assert_equal([], glob('Xspellfile2.add',0,1)) |
| 1136 | |
| 1137 | set spellfile= |
| 1138 | bw! |
| 1139 | endfu |
| 1140 | |
| 1141 | func! Test_normal20_exmode() |
Bram Moolenaar | 0913a10 | 2016-09-03 19:11:59 +0200 | [diff] [blame] | 1142 | if !has("unix") |
| 1143 | " Reading from redirected file doesn't work on MS-Windows |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 1144 | return |
| 1145 | endif |
| 1146 | call writefile(['1a', 'foo', 'bar', '.', 'w! Xfile2', 'q!'], 'Xscript') |
| 1147 | call writefile(['1', '2'], 'Xfile') |
| 1148 | call system(v:progpath .' -e -s < Xscript Xfile') |
| 1149 | let a=readfile('Xfile2') |
| 1150 | call assert_equal(['1', 'foo', 'bar', '2'], a) |
| 1151 | |
| 1152 | " clean up |
| 1153 | for file in ['Xfile', 'Xfile2', 'Xscript'] |
| 1154 | call delete(file) |
| 1155 | endfor |
| 1156 | bw! |
| 1157 | endfu |
| 1158 | |
| 1159 | func! Test_normal21_nv_hat() |
| 1160 | set hidden |
| 1161 | e Xfoobar |
| 1162 | e Xfile2 |
| 1163 | call feedkeys("\<c-^>", 't') |
| 1164 | call assert_equal("Xfile2", fnamemodify(bufname('%'), ':t')) |
| 1165 | call feedkeys("f\<c-^>", 't') |
| 1166 | call assert_equal("Xfile2", fnamemodify(bufname('%'), ':t')) |
| 1167 | " clean up |
| 1168 | set nohidden |
| 1169 | bw! |
| 1170 | endfu |
| 1171 | |
| 1172 | func! Test_normal22_zet() |
| 1173 | " Test for ZZ |
Bram Moolenaar | 0913a10 | 2016-09-03 19:11:59 +0200 | [diff] [blame] | 1174 | " let shell = &shell |
| 1175 | " let &shell = 'sh' |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 1176 | call writefile(['1', '2'], 'Xfile') |
| 1177 | let args = ' -u NONE -N -U NONE -i NONE --noplugins -X --not-a-term' |
| 1178 | call system(v:progpath . args . ' -c "%d" -c ":norm! ZZ" Xfile') |
| 1179 | let a = readfile('Xfile') |
| 1180 | call assert_equal([], a) |
| 1181 | " Test for ZQ |
| 1182 | call writefile(['1', '2'], 'Xfile') |
| 1183 | call system(v:progpath . args . ' -c "%d" -c ":norm! ZQ" Xfile') |
| 1184 | let a = readfile('Xfile') |
| 1185 | call assert_equal(['1', '2'], a) |
| 1186 | |
| 1187 | " clean up |
| 1188 | for file in ['Xfile'] |
| 1189 | call delete(file) |
| 1190 | endfor |
Bram Moolenaar | 0913a10 | 2016-09-03 19:11:59 +0200 | [diff] [blame] | 1191 | " let &shell = shell |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 1192 | endfu |
| 1193 | |
| 1194 | func! Test_normal23_K() |
| 1195 | " Test for K command |
| 1196 | new |
| 1197 | call append(0, ['version8.txt', 'man']) |
| 1198 | let k = &keywordprg |
| 1199 | set keywordprg=:help |
| 1200 | 1 |
| 1201 | norm! VK |
| 1202 | call assert_equal('version8.txt', fnamemodify(bufname('%'), ':t')) |
| 1203 | call assert_equal('help', &ft) |
| 1204 | call assert_match('\*version8.txt\*', getline('.')) |
| 1205 | helpclose |
| 1206 | norm! 0K |
| 1207 | call assert_equal('version8.txt', fnamemodify(bufname('%'), ':t')) |
| 1208 | call assert_equal('help', &ft) |
| 1209 | call assert_match('\*version8\.0\*', getline('.')) |
| 1210 | helpclose |
| 1211 | |
Bram Moolenaar | 0913a10 | 2016-09-03 19:11:59 +0200 | [diff] [blame] | 1212 | " Only expect "man" to work on Unix |
| 1213 | if !has("unix") |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 1214 | let &keywordprg = k |
| 1215 | bw! |
| 1216 | return |
| 1217 | endif |
| 1218 | set keywordprg=man\ --pager=cat |
| 1219 | " Test for using man |
| 1220 | 2 |
| 1221 | let a = execute('unsilent norm! K') |
| 1222 | call assert_match("man --pager=cat 'man'", a) |
| 1223 | |
| 1224 | " clean up |
| 1225 | let &keywordprg = k |
| 1226 | bw! |
| 1227 | endfu |
| 1228 | |
| 1229 | func! Test_normal24_rot13() |
| 1230 | " This test uses multi byte characters |
| 1231 | if !has("multi_byte") |
| 1232 | return |
| 1233 | endif |
| 1234 | " Testing for g?? g?g? |
| 1235 | new |
| 1236 | call append(0, 'abcdefghijklmnopqrstuvwxyzäüö') |
| 1237 | 1 |
| 1238 | norm! g?? |
| 1239 | call assert_equal('nopqrstuvwxyzabcdefghijklmäüö', getline('.')) |
| 1240 | norm! g?g? |
| 1241 | call assert_equal('abcdefghijklmnopqrstuvwxyzäüö', getline('.')) |
| 1242 | |
| 1243 | " clean up |
| 1244 | bw! |
| 1245 | endfu |
| 1246 | |
| 1247 | func! Test_normal25_tag() |
| 1248 | " Testing for CTRL-] g CTRL-] g] |
| 1249 | " CTRL-W g] CTRL-W CTRL-] CTRL-W g CTRL-] |
| 1250 | h |
| 1251 | " Test for CTRL-] |
| 1252 | call search('\<x\>$') |
| 1253 | exe "norm! \<c-]>" |
| 1254 | call assert_equal("change.txt", fnamemodify(bufname('%'), ':t')) |
| 1255 | norm! yiW |
| 1256 | call assert_equal("*x*", @0) |
| 1257 | exe ":norm \<c-o>" |
| 1258 | |
| 1259 | " Test for g_CTRL-] |
| 1260 | call search('\<v_u\>$') |
| 1261 | exe "norm! g\<c-]>" |
| 1262 | call assert_equal("change.txt", fnamemodify(bufname('%'), ':t')) |
| 1263 | norm! yiW |
| 1264 | call assert_equal("*v_u*", @0) |
| 1265 | exe ":norm \<c-o>" |
| 1266 | |
| 1267 | " Test for g] |
| 1268 | call search('\<i_<Esc>$') |
| 1269 | let a = execute(":norm! g]") |
| 1270 | call assert_match('i_<Esc>.*insert.txt', a) |
| 1271 | |
| 1272 | if !empty(exepath('cscope')) && has('cscope') |
| 1273 | " setting cscopetag changes how g] works |
| 1274 | set cst |
| 1275 | exe "norm! g]" |
| 1276 | call assert_equal("insert.txt", fnamemodify(bufname('%'), ':t')) |
| 1277 | norm! yiW |
| 1278 | call assert_equal("*i_<Esc>*", @0) |
| 1279 | exe ":norm \<c-o>" |
| 1280 | " Test for CTRL-W g] |
| 1281 | exe "norm! \<C-W>g]" |
| 1282 | call assert_equal("insert.txt", fnamemodify(bufname('%'), ':t')) |
| 1283 | norm! yiW |
| 1284 | call assert_equal("*i_<Esc>*", @0) |
| 1285 | call assert_equal(3, winnr('$')) |
| 1286 | helpclose |
| 1287 | set nocst |
| 1288 | endif |
| 1289 | |
| 1290 | " Test for CTRL-W g] |
| 1291 | let a = execute("norm! \<C-W>g]") |
| 1292 | call assert_match('i_<Esc>.*insert.txt', a) |
| 1293 | |
| 1294 | " Test for CTRL-W CTRL-] |
| 1295 | exe "norm! \<C-W>\<C-]>" |
| 1296 | call assert_equal("insert.txt", fnamemodify(bufname('%'), ':t')) |
| 1297 | norm! yiW |
| 1298 | call assert_equal("*i_<Esc>*", @0) |
| 1299 | call assert_equal(3, winnr('$')) |
| 1300 | helpclose |
| 1301 | |
| 1302 | " Test for CTRL-W g CTRL-] |
| 1303 | exe "norm! \<C-W>g\<C-]>" |
| 1304 | call assert_equal("insert.txt", fnamemodify(bufname('%'), ':t')) |
| 1305 | norm! yiW |
| 1306 | call assert_equal("*i_<Esc>*", @0) |
| 1307 | call assert_equal(3, winnr('$')) |
| 1308 | helpclose |
| 1309 | |
| 1310 | " clean up |
| 1311 | helpclose |
| 1312 | endfu |
| 1313 | |
| 1314 | func! Test_normal26_put() |
| 1315 | " Test for ]p ]P [p and [P |
| 1316 | new |
| 1317 | call append(0, ['while read LINE', 'do', ' ((count++))', ' if [ $? -ne 0 ]; then', " echo 'Error writing file'", ' fi', 'done']) |
| 1318 | 1 |
| 1319 | /Error/y a |
| 1320 | 2 |
| 1321 | norm! "a]pj"a[p |
| 1322 | call assert_equal(['do', "echo 'Error writing file'", " echo 'Error writing file'", ' ((count++))'], getline(2,5)) |
| 1323 | 1 |
| 1324 | /^\s\{4}/ |
| 1325 | exe "norm! \"a]P3Eldt'" |
| 1326 | exe "norm! j\"a[P2Eldt'" |
| 1327 | call assert_equal([' if [ $? -ne 0 ]; then', " echo 'Error writing'", " echo 'Error'", " echo 'Error writing file'", ' fi'], getline(6,10)) |
| 1328 | |
| 1329 | " clean up |
| 1330 | bw! |
| 1331 | endfu |
| 1332 | |
| 1333 | func! Test_normal27_bracket() |
| 1334 | " Test for [' [` ]' ]` |
| 1335 | call Setup_NewWindow() |
| 1336 | 1,21s/.\+/ & b/ |
| 1337 | 1 |
| 1338 | norm! $ma |
| 1339 | 5 |
| 1340 | norm! $mb |
| 1341 | 10 |
| 1342 | norm! $mc |
| 1343 | 15 |
| 1344 | norm! $md |
| 1345 | 20 |
| 1346 | norm! $me |
| 1347 | |
| 1348 | " Test for [' |
| 1349 | 9 |
| 1350 | norm! 2[' |
| 1351 | call assert_equal(' 1 b', getline('.')) |
| 1352 | call assert_equal(1, line('.')) |
| 1353 | call assert_equal(3, col('.')) |
| 1354 | |
| 1355 | " Test for ]' |
| 1356 | norm! ]' |
| 1357 | call assert_equal(' 5 b', getline('.')) |
| 1358 | call assert_equal(5, line('.')) |
| 1359 | call assert_equal(3, col('.')) |
| 1360 | |
| 1361 | " No mark after line 21, cursor moves to first non blank on current line |
| 1362 | 21 |
| 1363 | norm! $]' |
| 1364 | call assert_equal(' 21 b', getline('.')) |
| 1365 | call assert_equal(21, line('.')) |
| 1366 | call assert_equal(3, col('.')) |
| 1367 | |
| 1368 | " Test for [` |
| 1369 | norm! 2[` |
| 1370 | call assert_equal(' 15 b', getline('.')) |
| 1371 | call assert_equal(15, line('.')) |
| 1372 | call assert_equal(8, col('.')) |
| 1373 | |
| 1374 | " Test for ]` |
| 1375 | norm! ]` |
| 1376 | call assert_equal(' 20 b', getline('.')) |
| 1377 | call assert_equal(20, line('.')) |
| 1378 | call assert_equal(8, col('.')) |
| 1379 | |
| 1380 | " clean up |
| 1381 | bw! |
| 1382 | endfu |
| 1383 | |
| 1384 | func! Test_normal28_parenthesis() |
| 1385 | " basic testing for ( and ) |
| 1386 | new |
| 1387 | call append(0, ['This is a test. With some sentences!', '', 'Even with a question? And one more. And no sentence here']) |
| 1388 | |
| 1389 | $ |
| 1390 | norm! d( |
| 1391 | call assert_equal(['This is a test. With some sentences!', '', 'Even with a question? And one more. ', ''], getline(1, '$')) |
| 1392 | norm! 2d( |
| 1393 | call assert_equal(['This is a test. With some sentences!', '', ' ', ''], getline(1, '$')) |
| 1394 | 1 |
| 1395 | norm! 0d) |
| 1396 | call assert_equal(['With some sentences!', '', ' ', ''], getline(1, '$')) |
| 1397 | |
| 1398 | call append('$', ['This is a long sentence', '', 'spanning', 'over several lines. ']) |
| 1399 | $ |
| 1400 | norm! $d( |
| 1401 | call assert_equal(['With some sentences!', '', ' ', '', 'This is a long sentence', ''], getline(1, '$')) |
| 1402 | |
| 1403 | " clean up |
| 1404 | bw! |
| 1405 | endfu |
| 1406 | |
| 1407 | fun! Test_normal29_brace() |
| 1408 | " basic test for { and } movements |
| 1409 | let text= ['A paragraph begins after each empty line, and also at each of a set of', |
| 1410 | \ 'paragraph macros, specified by the pairs of characters in the ''paragraphs''', |
| 1411 | \ 'option. The default is "IPLPPPQPP TPHPLIPpLpItpplpipbp", which corresponds to', |
| 1412 | \ 'the macros ".IP", ".LP", etc. (These are nroff macros, so the dot must be in', |
| 1413 | \ 'the first column). A section boundary is also a paragraph boundary.', |
| 1414 | \ 'Note that a blank line (only containing white space) is NOT a paragraph', |
| 1415 | \ 'boundary.', |
| 1416 | \ '', |
| 1417 | \ '', |
| 1418 | \ 'Also note that this does not include a ''{'' or ''}'' in the first column. When', |
| 1419 | \ 'the ''{'' flag is in ''cpoptions'' then ''{'' in the first column is used as a', |
| 1420 | \ 'paragraph boundary |posix|.', |
| 1421 | \ '{', |
| 1422 | \ 'This is no paragaraph', |
| 1423 | \ 'unless the ''{'' is set', |
| 1424 | \ 'in ''cpoptions''', |
| 1425 | \ '}', |
| 1426 | \ '.IP', |
| 1427 | \ 'The nroff macros IP seperates a paragraph', |
| 1428 | \ 'That means, it must be a ''.''', |
| 1429 | \ 'followed by IP', |
| 1430 | \ '.LPIt does not matter, if afterwards some', |
| 1431 | \ 'more characters follow.', |
| 1432 | \ '.SHAlso section boundaries from the nroff', |
| 1433 | \ 'macros terminate a paragraph. That means', |
| 1434 | \ 'a character like this:', |
| 1435 | \ '.NH', |
| 1436 | \ 'End of text here'] |
| 1437 | new |
| 1438 | call append(0, text) |
| 1439 | 1 |
| 1440 | norm! 0d2} |
| 1441 | call assert_equal(['.IP', |
| 1442 | \ 'The nroff macros IP seperates a paragraph', 'That means, it must be a ''.''', 'followed by IP', |
| 1443 | \ '.LPIt does not matter, if afterwards some', 'more characters follow.', '.SHAlso section boundaries from the nroff', |
| 1444 | \ 'macros terminate a paragraph. That means', 'a character like this:', '.NH', 'End of text here', ''], getline(1,'$')) |
| 1445 | norm! 0d} |
| 1446 | call assert_equal(['.LPIt does not matter, if afterwards some', 'more characters follow.', |
| 1447 | \ '.SHAlso section boundaries from the nroff', 'macros terminate a paragraph. That means', |
| 1448 | \ 'a character like this:', '.NH', 'End of text here', ''], getline(1, '$')) |
| 1449 | $ |
| 1450 | norm! d{ |
| 1451 | call assert_equal(['.LPIt does not matter, if afterwards some', 'more characters follow.', |
| 1452 | \ '.SHAlso section boundaries from the nroff', 'macros terminate a paragraph. That means', 'a character like this:', ''], getline(1, '$')) |
| 1453 | norm! d{ |
| 1454 | call assert_equal(['.LPIt does not matter, if afterwards some', 'more characters follow.', ''], getline(1,'$')) |
| 1455 | " Test with { in cpooptions |
| 1456 | %d |
| 1457 | call append(0, text) |
| 1458 | set cpo+={ |
| 1459 | 1 |
| 1460 | norm! 0d2} |
| 1461 | call assert_equal(['{', 'This is no paragaraph', 'unless the ''{'' is set', 'in ''cpoptions''', '}', |
| 1462 | \ '.IP', 'The nroff macros IP seperates a paragraph', 'That means, it must be a ''.''', |
| 1463 | \ 'followed by IP', '.LPIt does not matter, if afterwards some', 'more characters follow.', |
| 1464 | \ '.SHAlso section boundaries from the nroff', 'macros terminate a paragraph. That means', |
| 1465 | \ 'a character like this:', '.NH', 'End of text here', ''], getline(1,'$')) |
| 1466 | $ |
| 1467 | norm! d} |
| 1468 | call assert_equal(['{', 'This is no paragaraph', 'unless the ''{'' is set', 'in ''cpoptions''', '}', |
| 1469 | \ '.IP', 'The nroff macros IP seperates a paragraph', 'That means, it must be a ''.''', |
| 1470 | \ 'followed by IP', '.LPIt does not matter, if afterwards some', 'more characters follow.', |
| 1471 | \ '.SHAlso section boundaries from the nroff', 'macros terminate a paragraph. That means', |
| 1472 | \ 'a character like this:', '.NH', 'End of text here', ''], getline(1,'$')) |
| 1473 | norm! gg} |
| 1474 | norm! d5} |
| 1475 | call assert_equal(['{', 'This is no paragaraph', 'unless the ''{'' is set', 'in ''cpoptions''', '}', ''], getline(1,'$')) |
| 1476 | |
| 1477 | " clean up |
| 1478 | set cpo-={ |
| 1479 | bw! |
| 1480 | endfu |
| 1481 | |
| 1482 | fun! Test_normal30_changecase() |
| 1483 | " This test uses multi byte characters |
| 1484 | if !has("multi_byte") |
| 1485 | return |
| 1486 | endif |
| 1487 | new |
| 1488 | call append(0, 'This is a simple test: äüöß') |
| 1489 | norm! 1ggVu |
| 1490 | call assert_equal('this is a simple test: äüöß', getline('.')) |
| 1491 | norm! VU |
| 1492 | call assert_equal('THIS IS A SIMPLE TEST: ÄÜÖSS', getline('.')) |
| 1493 | norm! guu |
| 1494 | call assert_equal('this is a simple test: äüöss', getline('.')) |
| 1495 | norm! gUgU |
| 1496 | call assert_equal('THIS IS A SIMPLE TEST: ÄÜÖSS', getline('.')) |
| 1497 | norm! gugu |
| 1498 | call assert_equal('this is a simple test: äüöss', getline('.')) |
| 1499 | norm! gUU |
| 1500 | call assert_equal('THIS IS A SIMPLE TEST: ÄÜÖSS', getline('.')) |
| 1501 | norm! 010~ |
| 1502 | call assert_equal('this is a SIMPLE TEST: ÄÜÖSS', getline('.')) |
| 1503 | norm! V~ |
| 1504 | call assert_equal('THIS IS A simple test: äüöss', getline('.')) |
| 1505 | |
| 1506 | " clean up |
| 1507 | bw! |
| 1508 | endfu |
| 1509 | |
| 1510 | fun! Test_normal31_r_cmd() |
| 1511 | " Test for r command |
| 1512 | new |
| 1513 | call append(0, 'This is a simple test: abcd') |
| 1514 | exe "norm! 1gg$r\<cr>" |
| 1515 | call assert_equal(['This is a simple test: abc', '', ''], getline(1,'$')) |
| 1516 | exe "norm! 1gg2wlr\<cr>" |
| 1517 | call assert_equal(['This is a', 'simple test: abc', '', ''], getline(1,'$')) |
| 1518 | exe "norm! 2gg0W5r\<cr>" |
| 1519 | call assert_equal(['This is a', 'simple ', ' abc', '', ''], getline('1', '$')) |
| 1520 | set autoindent |
| 1521 | call setline(2, ['simple test: abc', '']) |
| 1522 | exe "norm! 2gg0W5r\<cr>" |
| 1523 | call assert_equal(['This is a', 'simple ', 'abc', '', '', ''], getline('1', '$')) |
| 1524 | exe "norm! 1ggVr\<cr>" |
| 1525 | call assert_equal('^M^M^M^M^M^M^M^M^M', strtrans(getline(1))) |
| 1526 | call setline(1, 'This is a') |
| 1527 | exe "norm! 1gg05rf" |
| 1528 | call assert_equal('fffffis a', getline(1)) |
| 1529 | |
| 1530 | " clean up |
| 1531 | set noautoindent |
| 1532 | bw! |
| 1533 | endfu |
| 1534 | |
| 1535 | func! Test_normal32_g_cmd1() |
| 1536 | " Test for g*, g# |
| 1537 | new |
| 1538 | call append(0, ['abc.x_foo', 'x_foobar.abc']) |
| 1539 | 1 |
| 1540 | norm! $g* |
| 1541 | call assert_equal('x_foo', @/) |
| 1542 | call assert_equal('x_foobar.abc', getline('.')) |
| 1543 | norm! $g# |
| 1544 | call assert_equal('abc', @/) |
| 1545 | call assert_equal('abc.x_foo', getline('.')) |
| 1546 | |
| 1547 | " clean up |
| 1548 | bw! |
| 1549 | endfu |
| 1550 | |
| 1551 | fun! Test_normal33_g_cmd2() |
| 1552 | if !has("jumplist") |
| 1553 | return |
| 1554 | endif |
| 1555 | " Tests for g cmds |
| 1556 | call Setup_NewWindow() |
| 1557 | " Test for g` |
| 1558 | clearjumps |
| 1559 | norm! ma10j |
| 1560 | let a=execute(':jumps') |
| 1561 | " empty jumplist |
| 1562 | call assert_equal('>', a[-1:]) |
| 1563 | norm! g`a |
| 1564 | call assert_equal('>', a[-1:]) |
| 1565 | call assert_equal(1, line('.')) |
| 1566 | call assert_equal('1', getline('.')) |
| 1567 | |
| 1568 | " Test for g; and g, |
| 1569 | norm! g; |
| 1570 | " there is only one change in the changelist |
| 1571 | " currently, when we setup the window |
| 1572 | call assert_equal(2, line('.')) |
| 1573 | call assert_fails(':norm! g;', 'E662') |
| 1574 | call assert_fails(':norm! g,', 'E663') |
| 1575 | let &ul=&ul |
| 1576 | call append('$', ['a', 'b', 'c', 'd']) |
| 1577 | let &ul=&ul |
| 1578 | call append('$', ['Z', 'Y', 'X', 'W']) |
| 1579 | let a = execute(':changes') |
| 1580 | call assert_match('2\s\+0\s\+2', a) |
| 1581 | call assert_match('101\s\+0\s\+a', a) |
| 1582 | call assert_match('105\s\+0\s\+Z', a) |
| 1583 | norm! 3g; |
| 1584 | call assert_equal(2, line('.')) |
| 1585 | norm! 2g, |
| 1586 | call assert_equal(105, line('.')) |
| 1587 | |
| 1588 | " Test for g& - global substitute |
| 1589 | %d |
| 1590 | call setline(1, range(1,10)) |
| 1591 | call append('$', ['a', 'b', 'c', 'd']) |
| 1592 | $s/\w/&&/g |
| 1593 | exe "norm! /[1-8]\<cr>" |
| 1594 | norm! g& |
| 1595 | call assert_equal(['11', '22', '33', '44', '55', '66', '77', '88', '9', '110', 'a', 'b', 'c', 'dd'], getline(1, '$')) |
| 1596 | |
| 1597 | " Test for gv |
| 1598 | %d |
| 1599 | call append('$', repeat(['abcdefgh'], 8)) |
| 1600 | exe "norm! 2gg02l\<c-v>2j2ly" |
| 1601 | call assert_equal(['cde', 'cde', 'cde'], getreg(0, 1, 1)) |
| 1602 | " in visual mode, gv swaps current and last selected region |
| 1603 | exe "norm! G0\<c-v>4k4lgvd" |
| 1604 | call assert_equal(['', 'abfgh', 'abfgh', 'abfgh', 'abcdefgh', 'abcdefgh', 'abcdefgh', 'abcdefgh', 'abcdefgh'], getline(1,'$')) |
| 1605 | exe "norm! G0\<c-v>4k4ly" |
| 1606 | exe "norm! gvood" |
| 1607 | call assert_equal(['', 'abfgh', 'abfgh', 'abfgh', 'fgh', 'fgh', 'fgh', 'fgh', 'fgh'], getline(1,'$')) |
| 1608 | |
| 1609 | " Test for gk/gj |
| 1610 | %d |
| 1611 | 15vsp |
| 1612 | set wrap listchars= sbr= |
| 1613 | let lineA='abcdefghijklmnopqrstuvwxyz' |
| 1614 | let lineB='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ' |
| 1615 | $put =lineA |
| 1616 | $put =lineB |
| 1617 | |
| 1618 | norm! 3gg0dgk |
| 1619 | call assert_equal(['', 'abcdefghijklmno', '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'], getline(1, '$')) |
| 1620 | set nu |
| 1621 | norm! 3gg0gjdgj |
| 1622 | call assert_equal(['', 'abcdefghijklmno', '0123456789AMNOPQRSTUVWXYZ'], getline(1,'$')) |
| 1623 | |
| 1624 | " Test for gJ |
| 1625 | norm! 2gggJ |
| 1626 | call assert_equal(['', 'abcdefghijklmno0123456789AMNOPQRSTUVWXYZ'], getline(1,'$')) |
| 1627 | call assert_equal(16, col('.')) |
| 1628 | " shouldn't do anything |
| 1629 | norm! 10gJ |
| 1630 | call assert_equal(1, col('.')) |
| 1631 | |
| 1632 | " Test for g0 g^ gm g$ |
| 1633 | exe "norm! 2gg0gji " |
| 1634 | call assert_equal(['', 'abcdefghijk lmno0123456789AMNOPQRSTUVWXYZ'], getline(1,'$')) |
| 1635 | norm! g0yl |
| 1636 | call assert_equal(12, col('.')) |
| 1637 | call assert_equal(' ', getreg(0)) |
| 1638 | norm! g$yl |
| 1639 | call assert_equal(22, col('.')) |
| 1640 | call assert_equal('3', getreg(0)) |
| 1641 | norm! gmyl |
| 1642 | call assert_equal(17, col('.')) |
| 1643 | call assert_equal('n', getreg(0)) |
| 1644 | norm! g^yl |
| 1645 | call assert_equal(15, col('.')) |
| 1646 | call assert_equal('l', getreg(0)) |
| 1647 | |
| 1648 | " Test for g Ctrl-G |
Bram Moolenaar | 0913a10 | 2016-09-03 19:11:59 +0200 | [diff] [blame] | 1649 | set ff=unix |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 1650 | let a=execute(":norm! g\<c-g>") |
| 1651 | call assert_match('Col 15 of 43; Line 2 of 2; Word 2 of 2; Byte 16 of 45', a) |
| 1652 | |
| 1653 | " Test for gI |
| 1654 | norm! gIfoo |
| 1655 | call assert_equal(['', 'fooabcdefghijk lmno0123456789AMNOPQRSTUVWXYZ'], getline(1,'$')) |
| 1656 | |
| 1657 | " Test for gi |
| 1658 | wincmd c |
| 1659 | %d |
| 1660 | set tw=0 |
| 1661 | call setline(1, ['foobar', 'new line']) |
| 1662 | norm! A next word |
| 1663 | $put ='third line' |
| 1664 | norm! gi another word |
| 1665 | call assert_equal(['foobar next word another word', 'new line', 'third line'], getline(1,'$')) |
| 1666 | |
| 1667 | " clean up |
| 1668 | bw! |
| 1669 | endfu |
| 1670 | |
| 1671 | fun! Test_normal34_g_cmd3() |
| 1672 | if !has("multi_byte") |
| 1673 | return |
| 1674 | endif |
| 1675 | " Test for g8 |
| 1676 | new |
| 1677 | call append(0, 'abcdefghijklmnopqrstuvwxyzäüö') |
| 1678 | let a=execute(':norm! 1gg$g8') |
| 1679 | call assert_equal('c3 b6 ', a[1:]) |
| 1680 | |
| 1681 | " Test for gp gP |
| 1682 | call append(1, range(1,10)) |
| 1683 | " clean up |
| 1684 | bw! |
| 1685 | endfu |
| 1686 | |
| 1687 | fun! Test_normal35_g_cmd4() |
| 1688 | " Test for g< |
| 1689 | " Cannot capture its output, |
| 1690 | " probably a bug, therefore, test disabled: |
Bram Moolenaar | 3184509 | 2016-09-05 22:58:31 +0200 | [diff] [blame] | 1691 | throw "Skipped: output of g< can't be tested currently" |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 1692 | echo "a\nb\nc\nd" |
| 1693 | let b=execute(':norm! g<') |
| 1694 | call assert_true(!empty(b), 'failed `execute(g<)`') |
| 1695 | endfu |
| 1696 | |
| 1697 | fun! Test_normal36_g_cmd5() |
| 1698 | new |
| 1699 | call append(0, 'abcdefghijklmnopqrstuvwxyz') |
Bram Moolenaar | 0913a10 | 2016-09-03 19:11:59 +0200 | [diff] [blame] | 1700 | set ff=unix |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 1701 | " Test for gp gP |
| 1702 | call append(1, range(1,10)) |
| 1703 | 1 |
| 1704 | norm! 1yy |
| 1705 | 3 |
| 1706 | norm! gp |
| 1707 | call assert_equal([0, 5, 1, 0, 1], getcurpos()) |
| 1708 | $ |
| 1709 | norm! gP |
| 1710 | call assert_equal([0, 14, 1, 0, 1], getcurpos()) |
| 1711 | |
| 1712 | " Test for go |
| 1713 | norm! 26go |
| 1714 | call assert_equal([0, 1, 26, 0, 26], getcurpos()) |
| 1715 | norm! 27go |
| 1716 | call assert_equal([0, 1, 26, 0, 26], getcurpos()) |
| 1717 | norm! 28go |
| 1718 | call assert_equal([0, 2, 1, 0, 1], getcurpos()) |
| 1719 | set ff=dos |
| 1720 | norm! 29go |
| 1721 | call assert_equal([0, 2, 1, 0, 1], getcurpos()) |
| 1722 | set ff=unix |
| 1723 | norm! gg0 |
| 1724 | norm! 101go |
| 1725 | call assert_equal([0, 13, 26, 0, 26], getcurpos()) |
| 1726 | norm! 103go |
| 1727 | call assert_equal([0, 14, 1, 0, 1], getcurpos()) |
| 1728 | " count > buffer content |
| 1729 | norm! 120go |
| 1730 | call assert_equal([0, 14, 1, 0, 2147483647], getcurpos()) |
| 1731 | " clean up |
| 1732 | bw! |
| 1733 | endfu |
| 1734 | |
| 1735 | fun! Test_normal37_g_cmd6() |
| 1736 | " basic test for gt and gT |
| 1737 | tabnew 1.txt |
| 1738 | tabnew 2.txt |
| 1739 | tabnew 3.txt |
| 1740 | norm! 1gt |
| 1741 | call assert_equal(1, tabpagenr()) |
| 1742 | norm! 3gt |
| 1743 | call assert_equal(3, tabpagenr()) |
| 1744 | norm! 1gT |
| 1745 | " count gT goes not to the absolute tabpagenumber |
| 1746 | " but, but goes to the count previous tabpagenumber |
| 1747 | call assert_equal(2, tabpagenr()) |
| 1748 | " wrap around |
| 1749 | norm! 3gT |
| 1750 | call assert_equal(3, tabpagenr()) |
| 1751 | " gt does not wrap around |
| 1752 | norm! 5gt |
| 1753 | call assert_equal(3, tabpagenr()) |
| 1754 | |
| 1755 | for i in range(3) |
| 1756 | tabclose |
| 1757 | endfor |
| 1758 | " clean up |
| 1759 | call assert_fails(':tabclose', 'E784') |
| 1760 | endfu |
| 1761 | |
| 1762 | fun! Test_normal38_nvhome() |
| 1763 | " Test for <Home> and <C-Home> key |
| 1764 | new |
| 1765 | call setline(1, range(10)) |
| 1766 | $ |
| 1767 | setl et sw=2 |
| 1768 | norm! V10>$ |
| 1769 | " count is ignored |
| 1770 | exe "norm! 10\<home>" |
| 1771 | call assert_equal(1, col('.')) |
| 1772 | exe "norm! \<home>" |
| 1773 | call assert_equal([0, 10, 1, 0, 1], getcurpos()) |
| 1774 | exe "norm! 5\<c-home>" |
| 1775 | call assert_equal([0, 5, 1, 0, 1], getcurpos()) |
| 1776 | exe "norm! \<c-home>" |
| 1777 | call assert_equal([0, 1, 1, 0, 1], getcurpos()) |
| 1778 | |
| 1779 | " clean up |
| 1780 | bw! |
| 1781 | endfu |
| 1782 | |
| 1783 | fun! Test_normal39_cw() |
| 1784 | " Test for cw and cW on whitespace |
| 1785 | " and cpo+=w setting |
| 1786 | new |
| 1787 | set tw=0 |
| 1788 | call append(0, 'here are some words') |
| 1789 | norm! 1gg0elcwZZZ |
| 1790 | call assert_equal('hereZZZare some words', getline('.')) |
| 1791 | norm! 1gg0elcWYYY |
| 1792 | call assert_equal('hereZZZareYYYsome words', getline('.')) |
| 1793 | set cpo+=w |
| 1794 | call setline(1, 'here are some words') |
| 1795 | norm! 1gg0elcwZZZ |
| 1796 | call assert_equal('hereZZZ are some words', getline('.')) |
| 1797 | norm! 1gg2elcWYYY |
| 1798 | call assert_equal('hereZZZ areYYY some words', getline('.')) |
| 1799 | set cpo-=w |
| 1800 | norm! 2gg0cwfoo |
| 1801 | call assert_equal('foo', getline('.')) |
| 1802 | |
| 1803 | " clean up |
| 1804 | bw! |
| 1805 | endfu |
| 1806 | |
| 1807 | fun! Test_normal40_ctrl_bsl() |
| 1808 | " Basic test for CTRL-\ commands |
| 1809 | new |
| 1810 | call append(0, 'here are some words') |
| 1811 | exe "norm! 1gg0a\<C-\>\<C-N>" |
| 1812 | call assert_equal('n', mode()) |
| 1813 | call assert_equal(1, col('.')) |
| 1814 | call assert_equal('', visualmode()) |
| 1815 | exe "norm! 1gg0viw\<C-\>\<C-N>" |
| 1816 | call assert_equal('n', mode()) |
| 1817 | call assert_equal(4, col('.')) |
| 1818 | exe "norm! 1gg0a\<C-\>\<C-G>" |
| 1819 | call assert_equal('n', mode()) |
| 1820 | call assert_equal(1, col('.')) |
| 1821 | "imap <buffer> , <c-\><c-n> |
| 1822 | set im |
| 1823 | exe ":norm! \<c-\>\<c-n>dw" |
| 1824 | set noim |
| 1825 | call assert_equal('are some words', getline(1)) |
| 1826 | call assert_false(&insertmode) |
| 1827 | |
| 1828 | " clean up |
| 1829 | bw! |
| 1830 | endfu |
| 1831 | |
| 1832 | fun! Test_normal41_insert_reg() |
| 1833 | " Test for <c-r>=, <c-r><c-r>= and <c-r><c-o>= |
| 1834 | " in insert mode |
| 1835 | new |
| 1836 | set sts=2 sw=2 ts=8 tw=0 |
| 1837 | call append(0, ["aaa\tbbb\tccc", '', '', '']) |
| 1838 | let a=getline(1) |
| 1839 | norm! 2gg0 |
| 1840 | exe "norm! a\<c-r>=a\<cr>" |
| 1841 | norm! 3gg0 |
| 1842 | exe "norm! a\<c-r>\<c-r>=a\<cr>" |
| 1843 | norm! 4gg0 |
| 1844 | exe "norm! a\<c-r>\<c-o>=a\<cr>" |
| 1845 | call assert_equal(['aaa bbb ccc', 'aaa bbb ccc', 'aaa bbb ccc', 'aaa bbb ccc', ''], getline(1, '$')) |
| 1846 | |
| 1847 | " clean up |
| 1848 | set sts=0 sw=8 ts=8 |
Bram Moolenaar | 3184509 | 2016-09-05 22:58:31 +0200 | [diff] [blame] | 1849 | bw! |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 1850 | endfu |
| 1851 | |
| 1852 | func! Test_normal42_halfpage() |
| 1853 | " basic test for Ctrl-D and Ctrl-U |
| 1854 | call Setup_NewWindow() |
| 1855 | call assert_equal(5, &scroll) |
| 1856 | exe "norm! \<c-d>" |
| 1857 | call assert_equal('6', getline('.')) |
| 1858 | exe "norm! 2\<c-d>" |
| 1859 | call assert_equal('8', getline('.')) |
| 1860 | call assert_equal(2, &scroll) |
| 1861 | set scroll=5 |
| 1862 | exe "norm! \<c-u>" |
| 1863 | call assert_equal('3', getline('.')) |
| 1864 | 1 |
| 1865 | set scrolloff=5 |
| 1866 | exe "norm! \<c-d>" |
| 1867 | call assert_equal('10', getline('.')) |
| 1868 | exe "norm! \<c-u>" |
| 1869 | call assert_equal('5', getline('.')) |
| 1870 | 1 |
| 1871 | set scrolloff=99 |
| 1872 | exe "norm! \<c-d>" |
| 1873 | call assert_equal('10', getline('.')) |
| 1874 | set scrolloff=0 |
| 1875 | 100 |
| 1876 | exe "norm! $\<c-u>" |
| 1877 | call assert_equal('95', getline('.')) |
| 1878 | call assert_equal([0, 95, 1, 0, 1], getcurpos()) |
| 1879 | 100 |
| 1880 | set nostartofline |
| 1881 | exe "norm! $\<c-u>" |
| 1882 | call assert_equal('95', getline('.')) |
| 1883 | call assert_equal([0, 95, 2, 0, 2147483647], getcurpos()) |
| 1884 | " cleanup |
| 1885 | set startofline |
| 1886 | bw! |
| 1887 | endfu |
| 1888 | |
| 1889 | fun! Test_normal43_textobject1() |
| 1890 | " basic tests for text object aw |
| 1891 | new |
| 1892 | call append(0, ['foobar,eins,foobar', 'foo,zwei,foo ']) |
| 1893 | " diw |
| 1894 | norm! 1gg0diw |
| 1895 | call assert_equal([',eins,foobar', 'foo,zwei,foo ', ''], getline(1,'$')) |
| 1896 | " daw |
| 1897 | norm! 2ggEdaw |
| 1898 | call assert_equal([',eins,foobar', 'foo,zwei,', ''], getline(1, '$')) |
| 1899 | %d |
| 1900 | call append(0, ["foo\teins\tfoobar", "foo\tzwei\tfoo "]) |
| 1901 | " diW |
| 1902 | norm! 2ggwd2iW |
| 1903 | call assert_equal(['foo eins foobar', 'foo foo ', ''], getline(1,'$')) |
| 1904 | " daW |
| 1905 | norm! 1ggd2aW |
| 1906 | call assert_equal(['foobar', 'foo foo ', ''], getline(1,'$')) |
| 1907 | |
| 1908 | %d |
| 1909 | call append(0, ["foo\teins\tfoobar", "foo\tzwei\tfoo "]) |
| 1910 | " aw in visual line mode switches to characterwise mode |
| 1911 | norm! 2gg$Vawd |
| 1912 | call assert_equal(['foo eins foobar', 'foo zwei foo'], getline(1,'$')) |
| 1913 | norm! 1gg$Viwd |
| 1914 | call assert_equal(['foo eins ', 'foo zwei foo'], getline(1,'$')) |
| 1915 | |
| 1916 | " clean up |
| 1917 | bw! |
| 1918 | endfu |
| 1919 | |
| 1920 | func! Test_normal44_textobjects2() |
| 1921 | " basic testing for is and as text objects |
| 1922 | new |
| 1923 | call append(0, ['This is a test. With some sentences!', '', 'Even with a question? And one more. And no sentence here']) |
| 1924 | " Test for dis - does not remove trailing whitespace |
| 1925 | norm! 1gg0dis |
| 1926 | call assert_equal([' With some sentences!', '', 'Even with a question? And one more. And no sentence here', ''], getline(1,'$')) |
| 1927 | " Test for das - removes leading whitespace |
| 1928 | norm! 3ggf?ldas |
| 1929 | call assert_equal([' With some sentences!', '', 'Even with a question? And no sentence here', ''], getline(1,'$')) |
| 1930 | " when used in visual mode, is made characterwise |
| 1931 | norm! 3gg$Visy |
| 1932 | call assert_equal('v', visualmode()) |
| 1933 | " reset visualmode() |
| 1934 | norm! 3ggVy |
| 1935 | norm! 3gg$Vasy |
| 1936 | call assert_equal('v', visualmode()) |
| 1937 | " basic testing for textobjects a< and at |
| 1938 | %d |
| 1939 | call setline(1, ['<div> ','<a href="foobar" class="foo">xyz</a>',' </div>', ' ']) |
| 1940 | " a< |
| 1941 | norm! 1gg0da< |
| 1942 | call assert_equal([' ', '<a href="foobar" class="foo">xyz</a>', ' </div>', ' '], getline(1,'$')) |
| 1943 | norm! 1pj |
| 1944 | call assert_equal([' <div>', '<a href="foobar" class="foo">xyz</a>', ' </div>', ' '], getline(1,'$')) |
| 1945 | " at |
| 1946 | norm! d2at |
| 1947 | call assert_equal([' '], getline(1,'$')) |
| 1948 | %d |
| 1949 | call setline(1, ['<div> ','<a href="foobar" class="foo">xyz</a>',' </div>', ' ']) |
| 1950 | " i< |
| 1951 | norm! 1gg0di< |
| 1952 | call assert_equal(['<> ', '<a href="foobar" class="foo">xyz</a>', ' </div>', ' '], getline(1,'$')) |
| 1953 | norm! 1Pj |
| 1954 | call assert_equal(['<div> ', '<a href="foobar" class="foo">xyz</a>', ' </div>', ' '], getline(1,'$')) |
| 1955 | norm! d2it |
| 1956 | call assert_equal(['<div></div>',' '], getline(1,'$')) |
| 1957 | " basic testing for a[ and i[ text object |
| 1958 | %d |
| 1959 | call setline(1, [' ', '[', 'one [two]', 'thre', ']']) |
| 1960 | norm! 3gg0di[ |
| 1961 | call assert_equal([' ', '[', ']'], getline(1,'$')) |
| 1962 | call setline(1, [' ', '[', 'one [two]', 'thre', ']']) |
| 1963 | norm! 3gg0ftd2a[ |
| 1964 | call assert_equal([' '], getline(1,'$')) |
| 1965 | %d |
| 1966 | " Test for i" when cursor is in front of a quoted object |
| 1967 | call append(0, 'foo "bar"') |
| 1968 | norm! 1gg0di" |
| 1969 | call assert_equal(['foo ""', ''], getline(1,'$')) |
| 1970 | |
| 1971 | " clean up |
| 1972 | bw! |
| 1973 | endfu |
| 1974 | |
| 1975 | func! Test_normal45_drop() |
| 1976 | if !has("dnd") |
| 1977 | return |
| 1978 | endif |
| 1979 | " basic test for :drop command |
| 1980 | " unfortunately, without a gui, we can't really test much here, |
| 1981 | " so simply test that ~p fails (which uses the drop register) |
| 1982 | new |
| 1983 | call assert_fails(':norm! "~p', 'E353') |
| 1984 | call assert_equal([], getreg('~', 1, 1)) |
| 1985 | " the ~ register is read only |
| 1986 | call assert_fails(':let @~="1"', 'E354') |
| 1987 | bw! |
| 1988 | endfu |
| 1989 | |
| 1990 | func! Test_normal46_ignore() |
| 1991 | new |
| 1992 | " How to test this? |
| 1993 | " let's just for now test, that the buffer |
| 1994 | " does not change |
| 1995 | call feedkeys("\<c-s>", 't') |
| 1996 | call assert_equal([''], getline(1,'$')) |
| 1997 | |
| 1998 | " clean up |
| 1999 | bw! |
| 2000 | endfu |