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