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! $ |
Bram Moolenaar | 65f0847 | 2017-09-10 18:16:20 +0200 | [diff] [blame] | 391 | call assert_equal('cbar', expand('<cword>')) |
| 392 | call assert_equal('ifooar,,cbar', expand('<cWORD>')) |
| 393 | |
| 394 | call setline(1, ['prx = list[idx];']) |
| 395 | 1 |
| 396 | let expected = ['', 'prx', 'prx', 'prx', |
| 397 | \ 'list', 'list', 'list', 'list', 'list', 'list', 'list', |
| 398 | \ 'idx', 'idx', 'idx', 'idx', |
| 399 | \ 'list[idx]', |
| 400 | \ '];', |
| 401 | \ ] |
| 402 | for i in range(1, 16) |
| 403 | exe 'norm ' . i . '|' |
| 404 | call assert_equal(expected[i], expand('<cexpr>'), 'i == ' . i) |
| 405 | endfor |
| 406 | |
Bram Moolenaar | ae6f865 | 2017-12-20 22:32:20 +0100 | [diff] [blame] | 407 | if executable('echo') |
| 408 | " Test expand(`...`) i.e. backticks command expansion. |
| 409 | " MS-Windows has a trailing space. |
| 410 | call assert_match('^abcde *$', expand('`echo abcde`')) |
| 411 | endif |
| 412 | |
| 413 | " Test expand(`=...`) i.e. backticks expression expansion |
| 414 | call assert_equal('5', expand('`=2+3`')) |
| 415 | |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 416 | " clean up |
| 417 | bw! |
Bram Moolenaar | 2931f2a | 2016-09-09 16:59:08 +0200 | [diff] [blame] | 418 | endfunc |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 419 | |
| 420 | func! Test_normal11_showcmd() |
| 421 | " test for 'showcmd' |
| 422 | 10new |
| 423 | exe "norm! ofoobar\<esc>" |
| 424 | call assert_equal(2, line('$')) |
| 425 | set showcmd |
| 426 | exe "norm! ofoobar2\<esc>" |
| 427 | call assert_equal(3, line('$')) |
| 428 | exe "norm! VAfoobar3\<esc>" |
| 429 | call assert_equal(3, line('$')) |
| 430 | exe "norm! 0d3\<del>2l" |
| 431 | call assert_equal('obar2foobar3', getline('.')) |
| 432 | bw! |
Bram Moolenaar | 2931f2a | 2016-09-09 16:59:08 +0200 | [diff] [blame] | 433 | endfunc |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 434 | |
| 435 | func! Test_normal12_nv_error() |
| 436 | " Test for nv_error |
| 437 | 10new |
| 438 | call setline(1, range(1,5)) |
| 439 | " should not do anything, just beep |
| 440 | exe "norm! <c-k>" |
| 441 | call assert_equal(map(range(1,5), 'string(v:val)'), getline(1,'$')) |
| 442 | bw! |
Bram Moolenaar | 2931f2a | 2016-09-09 16:59:08 +0200 | [diff] [blame] | 443 | endfunc |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 444 | |
| 445 | func! Test_normal13_help() |
| 446 | " Test for F1 |
| 447 | call assert_equal(1, winnr()) |
| 448 | call feedkeys("\<f1>", 'txi') |
| 449 | call assert_match('help\.txt', bufname('%')) |
| 450 | call assert_equal(2, winnr('$')) |
| 451 | bw! |
Bram Moolenaar | 2931f2a | 2016-09-09 16:59:08 +0200 | [diff] [blame] | 452 | endfunc |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 453 | |
| 454 | func! Test_normal14_page() |
| 455 | " basic test for Ctrl-F and Ctrl-B |
| 456 | call Setup_NewWindow() |
| 457 | exe "norm! \<c-f>" |
| 458 | call assert_equal('9', getline('.')) |
| 459 | exe "norm! 2\<c-f>" |
| 460 | call assert_equal('25', getline('.')) |
| 461 | exe "norm! 2\<c-b>" |
| 462 | call assert_equal('18', getline('.')) |
| 463 | 1 |
| 464 | set scrolloff=5 |
| 465 | exe "norm! 2\<c-f>" |
| 466 | call assert_equal('21', getline('.')) |
| 467 | exe "norm! \<c-b>" |
| 468 | call assert_equal('13', getline('.')) |
| 469 | 1 |
| 470 | set scrolloff=99 |
| 471 | exe "norm! \<c-f>" |
| 472 | call assert_equal('13', getline('.')) |
| 473 | set scrolloff=0 |
| 474 | 100 |
| 475 | exe "norm! $\<c-b>" |
| 476 | call assert_equal('92', getline('.')) |
| 477 | call assert_equal([0, 92, 1, 0, 1], getcurpos()) |
| 478 | 100 |
| 479 | set nostartofline |
| 480 | exe "norm! $\<c-b>" |
| 481 | call assert_equal('92', getline('.')) |
| 482 | call assert_equal([0, 92, 2, 0, 2147483647], getcurpos()) |
| 483 | " cleanup |
| 484 | set startofline |
| 485 | bw! |
Bram Moolenaar | 2931f2a | 2016-09-09 16:59:08 +0200 | [diff] [blame] | 486 | endfunc |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 487 | |
Bram Moolenaar | bc54f3f | 2016-09-04 14:34:28 +0200 | [diff] [blame] | 488 | func! Test_normal14_page_eol() |
| 489 | 10new |
| 490 | norm oxxxxxxx |
| 491 | exe "norm 2\<c-f>" |
| 492 | " check with valgrind that cursor is put back in column 1 |
| 493 | exe "norm 2\<c-b>" |
| 494 | bw! |
| 495 | endfunc |
| 496 | |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 497 | func! Test_normal15_z_scroll_vert() |
| 498 | " basic test for z commands that scroll the window |
| 499 | call Setup_NewWindow() |
| 500 | 100 |
| 501 | norm! >> |
| 502 | " Test for z<cr> |
| 503 | exe "norm! z\<cr>" |
| 504 | call assert_equal(' 100', getline('.')) |
| 505 | call assert_equal(100, winsaveview()['topline']) |
| 506 | call assert_equal([0, 100, 2, 0, 9], getcurpos()) |
| 507 | |
| 508 | " Test for zt |
| 509 | 21 |
| 510 | norm! >>0zt |
| 511 | call assert_equal(' 21', getline('.')) |
| 512 | call assert_equal(21, winsaveview()['topline']) |
| 513 | call assert_equal([0, 21, 1, 0, 8], getcurpos()) |
| 514 | |
| 515 | " Test for zb |
| 516 | 30 |
| 517 | norm! >>$ztzb |
| 518 | call assert_equal(' 30', getline('.')) |
| 519 | call assert_equal(30, winsaveview()['topline']+winheight(0)-1) |
| 520 | call assert_equal([0, 30, 3, 0, 2147483647], getcurpos()) |
| 521 | |
| 522 | " Test for z- |
| 523 | 1 |
| 524 | 30 |
| 525 | norm! 0z- |
| 526 | call assert_equal(' 30', getline('.')) |
| 527 | call assert_equal(30, winsaveview()['topline']+winheight(0)-1) |
| 528 | call assert_equal([0, 30, 2, 0, 9], getcurpos()) |
| 529 | |
| 530 | " Test for z{height}<cr> |
| 531 | call assert_equal(10, winheight(0)) |
| 532 | exe "norm! z12\<cr>" |
| 533 | call assert_equal(12, winheight(0)) |
| 534 | exe "norm! z10\<cr>" |
| 535 | call assert_equal(10, winheight(0)) |
| 536 | |
| 537 | " Test for z. |
| 538 | 1 |
| 539 | 21 |
| 540 | norm! 0z. |
| 541 | call assert_equal(' 21', getline('.')) |
| 542 | call assert_equal(17, winsaveview()['topline']) |
| 543 | call assert_equal([0, 21, 2, 0, 9], getcurpos()) |
| 544 | |
| 545 | " Test for zz |
| 546 | 1 |
| 547 | 21 |
| 548 | norm! 0zz |
| 549 | call assert_equal(' 21', getline('.')) |
| 550 | call assert_equal(17, winsaveview()['topline']) |
| 551 | call assert_equal([0, 21, 1, 0, 8], getcurpos()) |
| 552 | |
| 553 | " Test for z+ |
| 554 | 11 |
| 555 | norm! zt |
| 556 | norm! z+ |
| 557 | call assert_equal(' 21', getline('.')) |
| 558 | call assert_equal(21, winsaveview()['topline']) |
| 559 | call assert_equal([0, 21, 2, 0, 9], getcurpos()) |
| 560 | |
| 561 | " Test for [count]z+ |
| 562 | 1 |
| 563 | norm! 21z+ |
| 564 | call assert_equal(' 21', getline('.')) |
| 565 | call assert_equal(21, winsaveview()['topline']) |
| 566 | call assert_equal([0, 21, 2, 0, 9], getcurpos()) |
| 567 | |
| 568 | " Test for z^ |
| 569 | norm! 22z+0 |
| 570 | norm! z^ |
| 571 | call assert_equal(' 21', getline('.')) |
| 572 | call assert_equal(12, winsaveview()['topline']) |
| 573 | call assert_equal([0, 21, 2, 0, 9], getcurpos()) |
| 574 | |
| 575 | " Test for [count]z^ |
| 576 | 1 |
| 577 | norm! 30z^ |
| 578 | call assert_equal(' 21', getline('.')) |
| 579 | call assert_equal(12, winsaveview()['topline']) |
| 580 | call assert_equal([0, 21, 2, 0, 9], getcurpos()) |
| 581 | |
| 582 | " cleanup |
| 583 | bw! |
Bram Moolenaar | 2931f2a | 2016-09-09 16:59:08 +0200 | [diff] [blame] | 584 | endfunc |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 585 | |
| 586 | func! Test_normal16_z_scroll_hor() |
| 587 | " basic test for z commands that scroll the window |
| 588 | 10new |
| 589 | 15vsp |
| 590 | set nowrap listchars= |
| 591 | let lineA='abcdefghijklmnopqrstuvwxyz' |
| 592 | let lineB='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ' |
| 593 | $put =lineA |
| 594 | $put =lineB |
| 595 | 1d |
| 596 | |
| 597 | " Test for zl |
| 598 | 1 |
| 599 | norm! 5zl |
| 600 | call assert_equal(lineA, getline('.')) |
| 601 | call assert_equal(6, col('.')) |
| 602 | call assert_equal(5, winsaveview()['leftcol']) |
| 603 | norm! yl |
| 604 | call assert_equal('f', @0) |
| 605 | |
| 606 | " Test for zh |
| 607 | norm! 2zh |
| 608 | call assert_equal(lineA, getline('.')) |
| 609 | call assert_equal(6, col('.')) |
| 610 | norm! yl |
| 611 | call assert_equal('f', @0) |
| 612 | call assert_equal(3, winsaveview()['leftcol']) |
| 613 | |
| 614 | " Test for zL |
| 615 | norm! zL |
| 616 | call assert_equal(11, col('.')) |
| 617 | norm! yl |
| 618 | call assert_equal('k', @0) |
| 619 | call assert_equal(10, winsaveview()['leftcol']) |
| 620 | norm! 2zL |
| 621 | call assert_equal(25, col('.')) |
| 622 | norm! yl |
| 623 | call assert_equal('y', @0) |
| 624 | call assert_equal(24, winsaveview()['leftcol']) |
| 625 | |
| 626 | " Test for zH |
| 627 | norm! 2zH |
| 628 | call assert_equal(25, col('.')) |
| 629 | call assert_equal(10, winsaveview()['leftcol']) |
| 630 | norm! yl |
| 631 | call assert_equal('y', @0) |
| 632 | |
| 633 | " Test for zs |
| 634 | norm! $zs |
| 635 | call assert_equal(26, col('.')) |
| 636 | call assert_equal(25, winsaveview()['leftcol']) |
| 637 | norm! yl |
| 638 | call assert_equal('z', @0) |
| 639 | |
| 640 | " Test for ze |
| 641 | norm! ze |
| 642 | call assert_equal(26, col('.')) |
| 643 | call assert_equal(11, winsaveview()['leftcol']) |
| 644 | norm! yl |
| 645 | call assert_equal('z', @0) |
| 646 | |
| 647 | " cleanup |
| 648 | set wrap listchars=eol:$ |
| 649 | bw! |
Bram Moolenaar | 2931f2a | 2016-09-09 16:59:08 +0200 | [diff] [blame] | 650 | endfunc |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 651 | |
| 652 | func! Test_normal17_z_scroll_hor2() |
| 653 | " basic test for z commands that scroll the window |
| 654 | " using 'sidescrolloff' setting |
| 655 | 10new |
| 656 | 20vsp |
| 657 | set nowrap listchars= sidescrolloff=5 |
| 658 | let lineA='abcdefghijklmnopqrstuvwxyz' |
| 659 | let lineB='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ' |
| 660 | $put =lineA |
| 661 | $put =lineB |
| 662 | 1d |
| 663 | |
| 664 | " Test for zl |
| 665 | 1 |
| 666 | norm! 5zl |
| 667 | call assert_equal(lineA, getline('.')) |
| 668 | call assert_equal(11, col('.')) |
| 669 | call assert_equal(5, winsaveview()['leftcol']) |
| 670 | norm! yl |
| 671 | call assert_equal('k', @0) |
| 672 | |
| 673 | " Test for zh |
| 674 | norm! 2zh |
| 675 | call assert_equal(lineA, getline('.')) |
| 676 | call assert_equal(11, col('.')) |
| 677 | norm! yl |
| 678 | call assert_equal('k', @0) |
| 679 | call assert_equal(3, winsaveview()['leftcol']) |
| 680 | |
| 681 | " Test for zL |
| 682 | norm! 0zL |
| 683 | call assert_equal(16, col('.')) |
| 684 | norm! yl |
| 685 | call assert_equal('p', @0) |
| 686 | call assert_equal(10, winsaveview()['leftcol']) |
| 687 | norm! 2zL |
| 688 | call assert_equal(26, col('.')) |
| 689 | norm! yl |
| 690 | call assert_equal('z', @0) |
| 691 | call assert_equal(15, winsaveview()['leftcol']) |
| 692 | |
| 693 | " Test for zH |
| 694 | norm! 2zH |
| 695 | call assert_equal(15, col('.')) |
| 696 | call assert_equal(0, winsaveview()['leftcol']) |
| 697 | norm! yl |
| 698 | call assert_equal('o', @0) |
| 699 | |
| 700 | " Test for zs |
| 701 | norm! $zs |
| 702 | call assert_equal(26, col('.')) |
| 703 | call assert_equal(20, winsaveview()['leftcol']) |
| 704 | norm! yl |
| 705 | call assert_equal('z', @0) |
| 706 | |
| 707 | " Test for ze |
| 708 | norm! ze |
| 709 | call assert_equal(26, col('.')) |
| 710 | call assert_equal(11, winsaveview()['leftcol']) |
| 711 | norm! yl |
| 712 | call assert_equal('z', @0) |
| 713 | |
| 714 | " cleanup |
| 715 | set wrap listchars=eol:$ sidescrolloff=0 |
| 716 | bw! |
Bram Moolenaar | 2931f2a | 2016-09-09 16:59:08 +0200 | [diff] [blame] | 717 | endfunc |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 718 | |
| 719 | func! Test_normal18_z_fold() |
| 720 | " basic tests for foldopen/folddelete |
| 721 | if !has("folding") |
| 722 | return |
| 723 | endif |
| 724 | call Setup_NewWindow() |
| 725 | 50 |
| 726 | setl foldenable fdm=marker foldlevel=5 |
| 727 | |
| 728 | " Test for zF |
| 729 | " First fold |
| 730 | norm! 4zF |
| 731 | " check that folds have been created |
| 732 | call assert_equal(['50/*{{{*/', '51', '52', '53/*}}}*/'], getline(50,53)) |
| 733 | |
| 734 | " Test for zd |
| 735 | 51 |
| 736 | norm! 2zF |
| 737 | call assert_equal(2, foldlevel('.')) |
| 738 | norm! kzd |
| 739 | call assert_equal(['50', '51/*{{{*/', '52/*}}}*/', '53'], getline(50,53)) |
| 740 | norm! j |
| 741 | call assert_equal(1, foldlevel('.')) |
| 742 | |
| 743 | " Test for zD |
| 744 | " also deletes partially selected folds recursively |
| 745 | 51 |
| 746 | norm! zF |
| 747 | call assert_equal(2, foldlevel('.')) |
| 748 | norm! kV2jzD |
| 749 | call assert_equal(['50', '51', '52', '53'], getline(50,53)) |
| 750 | |
| 751 | " Test for zE |
| 752 | 85 |
| 753 | norm! 4zF |
| 754 | 86 |
| 755 | norm! 2zF |
| 756 | 90 |
| 757 | norm! 4zF |
| 758 | call assert_equal(['85/*{{{*/', '86/*{{{*/', '87/*}}}*/', '88/*}}}*/', '89', '90/*{{{*/', '91', '92', '93/*}}}*/'], getline(85,93)) |
| 759 | norm! zE |
| 760 | call assert_equal(['85', '86', '87', '88', '89', '90', '91', '92', '93'], getline(85,93)) |
| 761 | |
| 762 | " Test for zn |
| 763 | 50 |
| 764 | set foldlevel=0 |
| 765 | norm! 2zF |
| 766 | norm! zn |
| 767 | norm! k |
| 768 | call assert_equal('49', getline('.')) |
| 769 | norm! j |
| 770 | call assert_equal('50/*{{{*/', getline('.')) |
| 771 | norm! j |
| 772 | call assert_equal('51/*}}}*/', getline('.')) |
| 773 | norm! j |
| 774 | call assert_equal('52', getline('.')) |
| 775 | call assert_equal(0, &foldenable) |
| 776 | |
| 777 | " Test for zN |
| 778 | 49 |
| 779 | norm! zN |
| 780 | call assert_equal('49', getline('.')) |
| 781 | norm! j |
| 782 | call assert_equal('50/*{{{*/', getline('.')) |
| 783 | norm! j |
| 784 | call assert_equal('52', getline('.')) |
| 785 | call assert_equal(1, &foldenable) |
| 786 | |
| 787 | " Test for zi |
| 788 | norm! zi |
| 789 | call assert_equal(0, &foldenable) |
| 790 | norm! zi |
| 791 | call assert_equal(1, &foldenable) |
| 792 | norm! zi |
| 793 | call assert_equal(0, &foldenable) |
| 794 | norm! zi |
| 795 | call assert_equal(1, &foldenable) |
| 796 | |
| 797 | " Test for za |
| 798 | 50 |
| 799 | norm! za |
| 800 | norm! k |
| 801 | call assert_equal('49', getline('.')) |
| 802 | norm! j |
| 803 | call assert_equal('50/*{{{*/', getline('.')) |
| 804 | norm! j |
| 805 | call assert_equal('51/*}}}*/', getline('.')) |
| 806 | norm! j |
| 807 | call assert_equal('52', getline('.')) |
| 808 | 50 |
| 809 | norm! za |
| 810 | norm! k |
| 811 | call assert_equal('49', getline('.')) |
| 812 | norm! j |
| 813 | call assert_equal('50/*{{{*/', getline('.')) |
| 814 | norm! j |
| 815 | call assert_equal('52', getline('.')) |
| 816 | |
| 817 | 49 |
| 818 | norm! 5zF |
| 819 | norm! k |
| 820 | call assert_equal('48', getline('.')) |
| 821 | norm! j |
| 822 | call assert_equal('49/*{{{*/', getline('.')) |
| 823 | norm! j |
| 824 | call assert_equal('55', getline('.')) |
| 825 | 49 |
| 826 | norm! za |
| 827 | call assert_equal('49/*{{{*/', getline('.')) |
| 828 | norm! j |
| 829 | call assert_equal('50/*{{{*/', getline('.')) |
| 830 | norm! j |
| 831 | call assert_equal('52', getline('.')) |
| 832 | set nofoldenable |
| 833 | " close fold and set foldenable |
| 834 | norm! za |
| 835 | call assert_equal(1, &foldenable) |
| 836 | |
| 837 | 50 |
| 838 | " have to use {count}za to open all folds and make the cursor visible |
| 839 | norm! 2za |
| 840 | norm! 2k |
| 841 | call assert_equal('48', getline('.')) |
| 842 | norm! j |
| 843 | call assert_equal('49/*{{{*/', getline('.')) |
| 844 | norm! j |
| 845 | call assert_equal('50/*{{{*/', getline('.')) |
| 846 | norm! j |
| 847 | call assert_equal('51/*}}}*/', getline('.')) |
| 848 | norm! j |
| 849 | call assert_equal('52', getline('.')) |
| 850 | |
| 851 | " Test for zA |
| 852 | 49 |
| 853 | set foldlevel=0 |
| 854 | 50 |
| 855 | norm! zA |
| 856 | norm! 2k |
| 857 | call assert_equal('48', getline('.')) |
| 858 | norm! j |
| 859 | call assert_equal('49/*{{{*/', getline('.')) |
| 860 | norm! j |
| 861 | call assert_equal('50/*{{{*/', getline('.')) |
| 862 | norm! j |
| 863 | call assert_equal('51/*}}}*/', getline('.')) |
| 864 | norm! j |
| 865 | call assert_equal('52', getline('.')) |
| 866 | |
Bram Moolenaar | 395b6ba | 2017-04-07 20:09:51 +0200 | [diff] [blame] | 867 | " zA on a opened fold when foldenable is not set |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 868 | 50 |
| 869 | set nofoldenable |
| 870 | norm! zA |
| 871 | call assert_equal(1, &foldenable) |
| 872 | norm! k |
| 873 | call assert_equal('48', getline('.')) |
| 874 | norm! j |
| 875 | call assert_equal('49/*{{{*/', getline('.')) |
| 876 | norm! j |
| 877 | call assert_equal('55', getline('.')) |
| 878 | |
| 879 | " Test for zc |
| 880 | norm! zE |
| 881 | 50 |
| 882 | norm! 2zF |
| 883 | 49 |
| 884 | norm! 5zF |
| 885 | set nofoldenable |
| 886 | 50 |
| 887 | " There most likely is a bug somewhere: |
| 888 | " https://groups.google.com/d/msg/vim_dev/v2EkfJ_KQjI/u-Cvv94uCAAJ |
| 889 | " TODO: Should this only close the inner most fold or both folds? |
| 890 | norm! zc |
| 891 | call assert_equal(1, &foldenable) |
| 892 | norm! k |
| 893 | call assert_equal('48', getline('.')) |
| 894 | norm! j |
| 895 | call assert_equal('49/*{{{*/', getline('.')) |
| 896 | norm! j |
| 897 | call assert_equal('55', getline('.')) |
| 898 | set nofoldenable |
| 899 | 50 |
| 900 | norm! Vjzc |
| 901 | norm! k |
| 902 | call assert_equal('48', getline('.')) |
| 903 | norm! j |
| 904 | call assert_equal('49/*{{{*/', getline('.')) |
| 905 | norm! j |
| 906 | call assert_equal('55', getline('.')) |
| 907 | |
| 908 | " Test for zC |
| 909 | set nofoldenable |
| 910 | 50 |
| 911 | norm! zCk |
| 912 | call assert_equal('48', getline('.')) |
| 913 | norm! j |
| 914 | call assert_equal('49/*{{{*/', getline('.')) |
| 915 | norm! j |
| 916 | call assert_equal('55', getline('.')) |
| 917 | |
| 918 | " Test for zx |
| 919 | " 1) close folds at line 49-54 |
| 920 | set nofoldenable |
| 921 | 48 |
| 922 | norm! zx |
| 923 | call assert_equal(1, &foldenable) |
| 924 | norm! j |
| 925 | call assert_equal('49/*{{{*/', getline('.')) |
| 926 | norm! j |
| 927 | call assert_equal('55', getline('.')) |
| 928 | |
Bram Moolenaar | 395b6ba | 2017-04-07 20:09:51 +0200 | [diff] [blame] | 929 | " 2) do not close fold under cursor |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 930 | 51 |
| 931 | set nofoldenable |
| 932 | norm! zx |
| 933 | call assert_equal(1, &foldenable) |
| 934 | norm! 3k |
| 935 | call assert_equal('48', getline('.')) |
| 936 | norm! j |
| 937 | call assert_equal('49/*{{{*/', getline('.')) |
| 938 | norm! j |
| 939 | call assert_equal('50/*{{{*/', getline('.')) |
| 940 | norm! j |
| 941 | call assert_equal('51/*}}}*/', getline('.')) |
| 942 | norm! j |
| 943 | call assert_equal('52', getline('.')) |
| 944 | norm! j |
| 945 | call assert_equal('53', getline('.')) |
| 946 | norm! j |
| 947 | call assert_equal('54/*}}}*/', getline('.')) |
| 948 | norm! j |
| 949 | call assert_equal('55', getline('.')) |
| 950 | |
| 951 | " 3) close one level of folds |
| 952 | 48 |
| 953 | set nofoldenable |
| 954 | set foldlevel=1 |
| 955 | norm! zx |
| 956 | call assert_equal(1, &foldenable) |
| 957 | call assert_equal('48', getline('.')) |
| 958 | norm! j |
| 959 | call assert_equal('49/*{{{*/', getline('.')) |
| 960 | norm! j |
| 961 | call assert_equal('50/*{{{*/', getline('.')) |
| 962 | norm! j |
| 963 | call assert_equal('52', getline('.')) |
| 964 | norm! j |
| 965 | call assert_equal('53', getline('.')) |
| 966 | norm! j |
| 967 | call assert_equal('54/*}}}*/', getline('.')) |
| 968 | norm! j |
| 969 | call assert_equal('55', getline('.')) |
| 970 | |
| 971 | " Test for zX |
| 972 | " Close all folds |
| 973 | set foldlevel=0 nofoldenable |
| 974 | 50 |
| 975 | norm! zX |
| 976 | call assert_equal(1, &foldenable) |
| 977 | norm! k |
| 978 | call assert_equal('48', getline('.')) |
| 979 | norm! j |
| 980 | call assert_equal('49/*{{{*/', getline('.')) |
| 981 | norm! j |
| 982 | call assert_equal('55', getline('.')) |
| 983 | |
| 984 | " Test for zm |
| 985 | 50 |
| 986 | set nofoldenable foldlevel=2 |
| 987 | norm! zm |
| 988 | call assert_equal(1, &foldenable) |
| 989 | call assert_equal(1, &foldlevel) |
| 990 | norm! zm |
| 991 | call assert_equal(0, &foldlevel) |
| 992 | norm! zm |
| 993 | call assert_equal(0, &foldlevel) |
| 994 | norm! k |
| 995 | call assert_equal('48', getline('.')) |
| 996 | norm! j |
| 997 | call assert_equal('49/*{{{*/', getline('.')) |
| 998 | norm! j |
| 999 | call assert_equal('55', getline('.')) |
| 1000 | |
| 1001 | " Test for zM |
| 1002 | 48 |
| 1003 | set nofoldenable foldlevel=99 |
| 1004 | norm! zM |
| 1005 | call assert_equal(1, &foldenable) |
| 1006 | call assert_equal(0, &foldlevel) |
| 1007 | call assert_equal('48', getline('.')) |
| 1008 | norm! j |
| 1009 | call assert_equal('49/*{{{*/', getline('.')) |
| 1010 | norm! j |
| 1011 | call assert_equal('55', getline('.')) |
| 1012 | |
| 1013 | " Test for zr |
| 1014 | 48 |
| 1015 | set nofoldenable foldlevel=0 |
| 1016 | norm! zr |
| 1017 | call assert_equal(0, &foldenable) |
| 1018 | call assert_equal(1, &foldlevel) |
| 1019 | set foldlevel=0 foldenable |
| 1020 | norm! zr |
| 1021 | call assert_equal(1, &foldenable) |
| 1022 | call assert_equal(1, &foldlevel) |
| 1023 | norm! zr |
| 1024 | call assert_equal(2, &foldlevel) |
| 1025 | call assert_equal('48', getline('.')) |
| 1026 | norm! j |
| 1027 | call assert_equal('49/*{{{*/', getline('.')) |
| 1028 | norm! j |
| 1029 | call assert_equal('50/*{{{*/', getline('.')) |
| 1030 | norm! j |
| 1031 | call assert_equal('51/*}}}*/', getline('.')) |
| 1032 | norm! j |
| 1033 | call assert_equal('52', getline('.')) |
| 1034 | |
| 1035 | " Test for zR |
| 1036 | 48 |
| 1037 | set nofoldenable foldlevel=0 |
| 1038 | norm! zR |
| 1039 | call assert_equal(0, &foldenable) |
| 1040 | call assert_equal(2, &foldlevel) |
| 1041 | set foldenable foldlevel=0 |
| 1042 | norm! zR |
| 1043 | call assert_equal(1, &foldenable) |
| 1044 | call assert_equal(2, &foldlevel) |
| 1045 | call assert_equal('48', getline('.')) |
| 1046 | norm! j |
| 1047 | call assert_equal('49/*{{{*/', getline('.')) |
| 1048 | norm! j |
| 1049 | call assert_equal('50/*{{{*/', getline('.')) |
| 1050 | norm! j |
| 1051 | call assert_equal('51/*}}}*/', getline('.')) |
| 1052 | norm! j |
| 1053 | call assert_equal('52', getline('.')) |
| 1054 | call append(50, ['a /*{{{*/', 'b /*}}}*/']) |
| 1055 | 48 |
| 1056 | call assert_equal('48', getline('.')) |
| 1057 | norm! j |
| 1058 | call assert_equal('49/*{{{*/', getline('.')) |
| 1059 | norm! j |
| 1060 | call assert_equal('50/*{{{*/', getline('.')) |
| 1061 | norm! j |
| 1062 | call assert_equal('a /*{{{*/', getline('.')) |
| 1063 | norm! j |
| 1064 | call assert_equal('51/*}}}*/', getline('.')) |
| 1065 | norm! j |
| 1066 | call assert_equal('52', getline('.')) |
| 1067 | 48 |
| 1068 | norm! zR |
| 1069 | call assert_equal(1, &foldenable) |
| 1070 | call assert_equal(3, &foldlevel) |
| 1071 | call assert_equal('48', getline('.')) |
| 1072 | norm! j |
| 1073 | call assert_equal('49/*{{{*/', getline('.')) |
| 1074 | norm! j |
| 1075 | call assert_equal('50/*{{{*/', getline('.')) |
| 1076 | norm! j |
| 1077 | call assert_equal('a /*{{{*/', getline('.')) |
| 1078 | norm! j |
| 1079 | call assert_equal('b /*}}}*/', getline('.')) |
| 1080 | norm! j |
| 1081 | call assert_equal('51/*}}}*/', getline('.')) |
| 1082 | norm! j |
| 1083 | call assert_equal('52', getline('.')) |
| 1084 | |
| 1085 | " clean up |
| 1086 | setl nofoldenable fdm=marker foldlevel=0 |
| 1087 | bw! |
Bram Moolenaar | 2931f2a | 2016-09-09 16:59:08 +0200 | [diff] [blame] | 1088 | endfunc |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 1089 | |
| 1090 | func! Test_normal19_z_spell() |
| 1091 | if !has("spell") || !has('syntax') |
| 1092 | return |
| 1093 | endif |
| 1094 | new |
| 1095 | call append(0, ['1 good', '2 goood', '3 goood']) |
| 1096 | set spell spellfile=./Xspellfile.add spelllang=en |
| 1097 | let oldlang=v:lang |
| 1098 | lang C |
| 1099 | |
| 1100 | " Test for zg |
| 1101 | 1 |
| 1102 | norm! ]s |
| 1103 | call assert_equal('2 goood', getline('.')) |
| 1104 | norm! zg |
| 1105 | 1 |
| 1106 | let a=execute('unsilent :norm! ]s') |
| 1107 | call assert_equal('1 good', getline('.')) |
| 1108 | call assert_equal('search hit BOTTOM, continuing at TOP', a[1:]) |
| 1109 | let cnt=readfile('./Xspellfile.add') |
| 1110 | call assert_equal('goood', cnt[0]) |
| 1111 | |
| 1112 | " Test for zw |
| 1113 | 2 |
| 1114 | norm! $zw |
| 1115 | 1 |
| 1116 | norm! ]s |
| 1117 | call assert_equal('2 goood', getline('.')) |
| 1118 | let cnt=readfile('./Xspellfile.add') |
| 1119 | call assert_equal('#oood', cnt[0]) |
| 1120 | call assert_equal('goood/!', cnt[1]) |
| 1121 | |
| 1122 | " Test for zg in visual mode |
| 1123 | let a=execute('unsilent :norm! V$zg') |
| 1124 | call assert_equal("Word '2 goood' added to ./Xspellfile.add", a[1:]) |
| 1125 | 1 |
| 1126 | norm! ]s |
| 1127 | call assert_equal('3 goood', getline('.')) |
| 1128 | let cnt=readfile('./Xspellfile.add') |
| 1129 | call assert_equal('2 goood', cnt[2]) |
| 1130 | " Remove "2 good" from spellfile |
| 1131 | 2 |
| 1132 | let a=execute('unsilent norm! V$zw') |
| 1133 | call assert_equal("Word '2 goood' added to ./Xspellfile.add", a[1:]) |
| 1134 | let cnt=readfile('./Xspellfile.add') |
| 1135 | call assert_equal('2 goood/!', cnt[3]) |
| 1136 | |
| 1137 | " Test for zG |
| 1138 | let a=execute('unsilent norm! V$zG') |
| 1139 | call assert_match("Word '2 goood' added to .*", a) |
| 1140 | let fname=matchstr(a, 'to\s\+\zs\f\+$') |
| 1141 | let cnt=readfile(fname) |
| 1142 | call assert_equal('2 goood', cnt[0]) |
| 1143 | |
| 1144 | " Test for zW |
| 1145 | let a=execute('unsilent norm! V$zW') |
| 1146 | call assert_match("Word '2 goood' added to .*", a) |
| 1147 | let cnt=readfile(fname) |
| 1148 | call assert_equal('# goood', cnt[0]) |
| 1149 | call assert_equal('2 goood/!', cnt[1]) |
| 1150 | |
| 1151 | " Test for zuW |
| 1152 | let a=execute('unsilent norm! V$zuW') |
| 1153 | call assert_match("Word '2 goood' removed from .*", a) |
| 1154 | let cnt=readfile(fname) |
| 1155 | call assert_equal('# goood', cnt[0]) |
| 1156 | call assert_equal('# goood/!', cnt[1]) |
| 1157 | |
| 1158 | " Test for zuG |
| 1159 | let a=execute('unsilent norm! $zG') |
| 1160 | call assert_match("Word 'goood' added to .*", a) |
| 1161 | let cnt=readfile(fname) |
| 1162 | call assert_equal('# goood', cnt[0]) |
| 1163 | call assert_equal('# goood/!', cnt[1]) |
| 1164 | call assert_equal('goood', cnt[2]) |
| 1165 | let a=execute('unsilent norm! $zuG') |
| 1166 | let cnt=readfile(fname) |
| 1167 | call assert_match("Word 'goood' removed from .*", a) |
| 1168 | call assert_equal('# goood', cnt[0]) |
| 1169 | call assert_equal('# goood/!', cnt[1]) |
| 1170 | call assert_equal('#oood', cnt[2]) |
| 1171 | " word not found in wordlist |
| 1172 | let a=execute('unsilent norm! V$zuG') |
| 1173 | let cnt=readfile(fname) |
| 1174 | call assert_match("", a) |
| 1175 | call assert_equal('# goood', cnt[0]) |
| 1176 | call assert_equal('# goood/!', cnt[1]) |
| 1177 | call assert_equal('#oood', cnt[2]) |
| 1178 | |
| 1179 | " Test for zug |
| 1180 | call delete('./Xspellfile.add') |
| 1181 | 2 |
| 1182 | let a=execute('unsilent norm! $zg') |
| 1183 | let cnt=readfile('./Xspellfile.add') |
| 1184 | call assert_equal('goood', cnt[0]) |
| 1185 | let a=execute('unsilent norm! $zug') |
| 1186 | call assert_match("Word 'goood' removed from \./Xspellfile.add", a) |
| 1187 | let cnt=readfile('./Xspellfile.add') |
| 1188 | call assert_equal('#oood', cnt[0]) |
| 1189 | " word not in wordlist |
| 1190 | let a=execute('unsilent norm! V$zug') |
| 1191 | call assert_match('', a) |
| 1192 | let cnt=readfile('./Xspellfile.add') |
| 1193 | call assert_equal('#oood', cnt[0]) |
| 1194 | |
| 1195 | " Test for zuw |
| 1196 | call delete('./Xspellfile.add') |
| 1197 | 2 |
| 1198 | let a=execute('unsilent norm! Vzw') |
| 1199 | let cnt=readfile('./Xspellfile.add') |
| 1200 | call assert_equal('2 goood/!', cnt[0]) |
| 1201 | let a=execute('unsilent norm! Vzuw') |
| 1202 | call assert_match("Word '2 goood' removed from \./Xspellfile.add", a) |
| 1203 | let cnt=readfile('./Xspellfile.add') |
| 1204 | call assert_equal('# goood/!', cnt[0]) |
| 1205 | " word not in wordlist |
| 1206 | let a=execute('unsilent norm! $zug') |
| 1207 | call assert_match('', a) |
| 1208 | let cnt=readfile('./Xspellfile.add') |
| 1209 | call assert_equal('# goood/!', cnt[0]) |
| 1210 | |
| 1211 | " add second entry to spellfile setting |
| 1212 | set spellfile=./Xspellfile.add,./Xspellfile2.add |
| 1213 | call delete('./Xspellfile.add') |
| 1214 | 2 |
| 1215 | let a=execute('unsilent norm! $2zg') |
| 1216 | let cnt=readfile('./Xspellfile2.add') |
| 1217 | call assert_match("Word 'goood' added to ./Xspellfile2.add", a) |
| 1218 | call assert_equal('goood', cnt[0]) |
| 1219 | |
Bram Moolenaar | f45938c | 2017-11-02 15:59:57 +0100 | [diff] [blame] | 1220 | " Test for :spellgood! |
| 1221 | let temp = execute(':spe!0/0') |
| 1222 | call assert_match('Invalid region', temp) |
| 1223 | let spellfile = matchstr(temp, 'Invalid region nr in \zs.*\ze line \d: 0') |
| 1224 | call assert_equal(['# goood', '# goood/!', '#oood', '0/0'], readfile(spellfile)) |
| 1225 | call delete(spellfile) |
| 1226 | |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 1227 | " clean up |
| 1228 | exe "lang" oldlang |
| 1229 | call delete("./Xspellfile.add") |
| 1230 | call delete("./Xspellfile2.add") |
Bram Moolenaar | df0db16 | 2016-09-06 20:37:41 +0200 | [diff] [blame] | 1231 | call delete("./Xspellfile.add.spl") |
| 1232 | call delete("./Xspellfile2.add.spl") |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 1233 | |
| 1234 | " zux -> no-op |
| 1235 | 2 |
| 1236 | norm! $zux |
| 1237 | call assert_equal([], glob('Xspellfile.add',0,1)) |
| 1238 | call assert_equal([], glob('Xspellfile2.add',0,1)) |
| 1239 | |
| 1240 | set spellfile= |
| 1241 | bw! |
Bram Moolenaar | 2931f2a | 2016-09-09 16:59:08 +0200 | [diff] [blame] | 1242 | endfunc |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 1243 | |
| 1244 | func! Test_normal20_exmode() |
Bram Moolenaar | 0913a10 | 2016-09-03 19:11:59 +0200 | [diff] [blame] | 1245 | if !has("unix") |
| 1246 | " Reading from redirected file doesn't work on MS-Windows |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 1247 | return |
| 1248 | endif |
| 1249 | call writefile(['1a', 'foo', 'bar', '.', 'w! Xfile2', 'q!'], 'Xscript') |
| 1250 | call writefile(['1', '2'], 'Xfile') |
| 1251 | call system(v:progpath .' -e -s < Xscript Xfile') |
| 1252 | let a=readfile('Xfile2') |
| 1253 | call assert_equal(['1', 'foo', 'bar', '2'], a) |
| 1254 | |
| 1255 | " clean up |
| 1256 | for file in ['Xfile', 'Xfile2', 'Xscript'] |
| 1257 | call delete(file) |
| 1258 | endfor |
| 1259 | bw! |
Bram Moolenaar | 2931f2a | 2016-09-09 16:59:08 +0200 | [diff] [blame] | 1260 | endfunc |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 1261 | |
| 1262 | func! Test_normal21_nv_hat() |
| 1263 | set hidden |
Bram Moolenaar | 2931f2a | 2016-09-09 16:59:08 +0200 | [diff] [blame] | 1264 | new |
| 1265 | " to many buffers opened already, will not work |
| 1266 | "call assert_fails(":b#", 'E23') |
| 1267 | "call assert_equal('', @#) |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 1268 | e Xfoobar |
| 1269 | e Xfile2 |
| 1270 | call feedkeys("\<c-^>", 't') |
| 1271 | call assert_equal("Xfile2", fnamemodify(bufname('%'), ':t')) |
| 1272 | call feedkeys("f\<c-^>", 't') |
| 1273 | call assert_equal("Xfile2", fnamemodify(bufname('%'), ':t')) |
| 1274 | " clean up |
| 1275 | set nohidden |
| 1276 | bw! |
Bram Moolenaar | 2931f2a | 2016-09-09 16:59:08 +0200 | [diff] [blame] | 1277 | endfunc |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 1278 | |
| 1279 | func! Test_normal22_zet() |
| 1280 | " Test for ZZ |
Bram Moolenaar | 0913a10 | 2016-09-03 19:11:59 +0200 | [diff] [blame] | 1281 | " let shell = &shell |
| 1282 | " let &shell = 'sh' |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 1283 | call writefile(['1', '2'], 'Xfile') |
| 1284 | let args = ' -u NONE -N -U NONE -i NONE --noplugins -X --not-a-term' |
| 1285 | call system(v:progpath . args . ' -c "%d" -c ":norm! ZZ" Xfile') |
| 1286 | let a = readfile('Xfile') |
| 1287 | call assert_equal([], a) |
| 1288 | " Test for ZQ |
| 1289 | call writefile(['1', '2'], 'Xfile') |
| 1290 | call system(v:progpath . args . ' -c "%d" -c ":norm! ZQ" Xfile') |
| 1291 | let a = readfile('Xfile') |
| 1292 | call assert_equal(['1', '2'], a) |
| 1293 | |
| 1294 | " clean up |
| 1295 | for file in ['Xfile'] |
| 1296 | call delete(file) |
| 1297 | endfor |
Bram Moolenaar | 0913a10 | 2016-09-03 19:11:59 +0200 | [diff] [blame] | 1298 | " let &shell = shell |
Bram Moolenaar | 2931f2a | 2016-09-09 16:59:08 +0200 | [diff] [blame] | 1299 | endfunc |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 1300 | |
| 1301 | func! Test_normal23_K() |
| 1302 | " Test for K command |
| 1303 | new |
Bram Moolenaar | 426f375 | 2016-11-04 21:22:37 +0100 | [diff] [blame] | 1304 | call append(0, ['version8.txt', 'man', 'aa%bb', 'cc|dd']) |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 1305 | let k = &keywordprg |
| 1306 | set keywordprg=:help |
| 1307 | 1 |
| 1308 | norm! VK |
| 1309 | call assert_equal('version8.txt', fnamemodify(bufname('%'), ':t')) |
| 1310 | call assert_equal('help', &ft) |
| 1311 | call assert_match('\*version8.txt\*', getline('.')) |
| 1312 | helpclose |
| 1313 | norm! 0K |
| 1314 | call assert_equal('version8.txt', fnamemodify(bufname('%'), ':t')) |
| 1315 | call assert_equal('help', &ft) |
Bram Moolenaar | b1c9198 | 2018-05-17 17:04:55 +0200 | [diff] [blame] | 1316 | call assert_match('\*version8\.\d\*', getline('.')) |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 1317 | helpclose |
| 1318 | |
Bram Moolenaar | 426f375 | 2016-11-04 21:22:37 +0100 | [diff] [blame] | 1319 | set keywordprg=:new |
| 1320 | set iskeyword+=% |
| 1321 | set iskeyword+=\| |
| 1322 | 2 |
| 1323 | norm! K |
| 1324 | call assert_equal('man', fnamemodify(bufname('%'), ':t')) |
| 1325 | bwipe! |
| 1326 | 3 |
| 1327 | norm! K |
| 1328 | call assert_equal('aa%bb', fnamemodify(bufname('%'), ':t')) |
| 1329 | bwipe! |
Bram Moolenaar | eb828d0 | 2016-11-05 19:54:01 +0100 | [diff] [blame] | 1330 | if !has('win32') |
| 1331 | 4 |
| 1332 | norm! K |
| 1333 | call assert_equal('cc|dd', fnamemodify(bufname('%'), ':t')) |
| 1334 | bwipe! |
| 1335 | endif |
Bram Moolenaar | 426f375 | 2016-11-04 21:22:37 +0100 | [diff] [blame] | 1336 | set iskeyword-=% |
| 1337 | set iskeyword-=\| |
| 1338 | |
Bram Moolenaar | 0913a10 | 2016-09-03 19:11:59 +0200 | [diff] [blame] | 1339 | " Only expect "man" to work on Unix |
| 1340 | if !has("unix") |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 1341 | let &keywordprg = k |
| 1342 | bw! |
| 1343 | return |
| 1344 | endif |
| 1345 | set keywordprg=man\ --pager=cat |
| 1346 | " Test for using man |
| 1347 | 2 |
| 1348 | let a = execute('unsilent norm! K') |
| 1349 | call assert_match("man --pager=cat 'man'", a) |
| 1350 | |
| 1351 | " clean up |
| 1352 | let &keywordprg = k |
| 1353 | bw! |
Bram Moolenaar | 2931f2a | 2016-09-09 16:59:08 +0200 | [diff] [blame] | 1354 | endfunc |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 1355 | |
| 1356 | func! Test_normal24_rot13() |
| 1357 | " This test uses multi byte characters |
| 1358 | if !has("multi_byte") |
| 1359 | return |
| 1360 | endif |
| 1361 | " Testing for g?? g?g? |
| 1362 | new |
| 1363 | call append(0, 'abcdefghijklmnopqrstuvwxyzäüö') |
| 1364 | 1 |
| 1365 | norm! g?? |
| 1366 | call assert_equal('nopqrstuvwxyzabcdefghijklmäüö', getline('.')) |
| 1367 | norm! g?g? |
| 1368 | call assert_equal('abcdefghijklmnopqrstuvwxyzäüö', getline('.')) |
| 1369 | |
| 1370 | " clean up |
| 1371 | bw! |
Bram Moolenaar | 2931f2a | 2016-09-09 16:59:08 +0200 | [diff] [blame] | 1372 | endfunc |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 1373 | |
| 1374 | func! Test_normal25_tag() |
| 1375 | " Testing for CTRL-] g CTRL-] g] |
| 1376 | " CTRL-W g] CTRL-W CTRL-] CTRL-W g CTRL-] |
| 1377 | h |
| 1378 | " Test for CTRL-] |
| 1379 | call search('\<x\>$') |
| 1380 | exe "norm! \<c-]>" |
| 1381 | call assert_equal("change.txt", fnamemodify(bufname('%'), ':t')) |
| 1382 | norm! yiW |
| 1383 | call assert_equal("*x*", @0) |
| 1384 | exe ":norm \<c-o>" |
| 1385 | |
| 1386 | " Test for g_CTRL-] |
| 1387 | call search('\<v_u\>$') |
| 1388 | exe "norm! g\<c-]>" |
| 1389 | call assert_equal("change.txt", fnamemodify(bufname('%'), ':t')) |
| 1390 | norm! yiW |
| 1391 | call assert_equal("*v_u*", @0) |
| 1392 | exe ":norm \<c-o>" |
| 1393 | |
| 1394 | " Test for g] |
| 1395 | call search('\<i_<Esc>$') |
| 1396 | let a = execute(":norm! g]") |
| 1397 | call assert_match('i_<Esc>.*insert.txt', a) |
| 1398 | |
| 1399 | if !empty(exepath('cscope')) && has('cscope') |
| 1400 | " setting cscopetag changes how g] works |
| 1401 | set cst |
| 1402 | exe "norm! g]" |
| 1403 | call assert_equal("insert.txt", fnamemodify(bufname('%'), ':t')) |
| 1404 | norm! yiW |
| 1405 | call assert_equal("*i_<Esc>*", @0) |
| 1406 | exe ":norm \<c-o>" |
| 1407 | " Test for CTRL-W g] |
| 1408 | exe "norm! \<C-W>g]" |
| 1409 | call assert_equal("insert.txt", fnamemodify(bufname('%'), ':t')) |
| 1410 | norm! yiW |
| 1411 | call assert_equal("*i_<Esc>*", @0) |
| 1412 | call assert_equal(3, winnr('$')) |
| 1413 | helpclose |
| 1414 | set nocst |
| 1415 | endif |
| 1416 | |
| 1417 | " Test for CTRL-W g] |
| 1418 | let a = execute("norm! \<C-W>g]") |
| 1419 | call assert_match('i_<Esc>.*insert.txt', a) |
| 1420 | |
| 1421 | " Test for CTRL-W CTRL-] |
| 1422 | exe "norm! \<C-W>\<C-]>" |
| 1423 | call assert_equal("insert.txt", fnamemodify(bufname('%'), ':t')) |
| 1424 | norm! yiW |
| 1425 | call assert_equal("*i_<Esc>*", @0) |
| 1426 | call assert_equal(3, winnr('$')) |
| 1427 | helpclose |
| 1428 | |
| 1429 | " Test for CTRL-W g CTRL-] |
| 1430 | exe "norm! \<C-W>g\<C-]>" |
| 1431 | call assert_equal("insert.txt", fnamemodify(bufname('%'), ':t')) |
| 1432 | norm! yiW |
| 1433 | call assert_equal("*i_<Esc>*", @0) |
| 1434 | call assert_equal(3, winnr('$')) |
| 1435 | helpclose |
| 1436 | |
| 1437 | " clean up |
| 1438 | helpclose |
Bram Moolenaar | 2931f2a | 2016-09-09 16:59:08 +0200 | [diff] [blame] | 1439 | endfunc |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 1440 | |
| 1441 | func! Test_normal26_put() |
| 1442 | " Test for ]p ]P [p and [P |
| 1443 | new |
| 1444 | call append(0, ['while read LINE', 'do', ' ((count++))', ' if [ $? -ne 0 ]; then', " echo 'Error writing file'", ' fi', 'done']) |
| 1445 | 1 |
| 1446 | /Error/y a |
| 1447 | 2 |
| 1448 | norm! "a]pj"a[p |
| 1449 | call assert_equal(['do', "echo 'Error writing file'", " echo 'Error writing file'", ' ((count++))'], getline(2,5)) |
| 1450 | 1 |
| 1451 | /^\s\{4}/ |
| 1452 | exe "norm! \"a]P3Eldt'" |
| 1453 | exe "norm! j\"a[P2Eldt'" |
| 1454 | call assert_equal([' if [ $? -ne 0 ]; then', " echo 'Error writing'", " echo 'Error'", " echo 'Error writing file'", ' fi'], getline(6,10)) |
| 1455 | |
| 1456 | " clean up |
| 1457 | bw! |
Bram Moolenaar | 2931f2a | 2016-09-09 16:59:08 +0200 | [diff] [blame] | 1458 | endfunc |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 1459 | |
| 1460 | func! Test_normal27_bracket() |
| 1461 | " Test for [' [` ]' ]` |
| 1462 | call Setup_NewWindow() |
| 1463 | 1,21s/.\+/ & b/ |
| 1464 | 1 |
| 1465 | norm! $ma |
| 1466 | 5 |
| 1467 | norm! $mb |
| 1468 | 10 |
| 1469 | norm! $mc |
| 1470 | 15 |
| 1471 | norm! $md |
| 1472 | 20 |
| 1473 | norm! $me |
| 1474 | |
| 1475 | " Test for [' |
| 1476 | 9 |
| 1477 | norm! 2[' |
| 1478 | call assert_equal(' 1 b', getline('.')) |
| 1479 | call assert_equal(1, line('.')) |
| 1480 | call assert_equal(3, col('.')) |
| 1481 | |
| 1482 | " Test for ]' |
| 1483 | norm! ]' |
| 1484 | call assert_equal(' 5 b', getline('.')) |
| 1485 | call assert_equal(5, line('.')) |
| 1486 | call assert_equal(3, col('.')) |
| 1487 | |
| 1488 | " No mark after line 21, cursor moves to first non blank on current line |
| 1489 | 21 |
| 1490 | norm! $]' |
| 1491 | call assert_equal(' 21 b', getline('.')) |
| 1492 | call assert_equal(21, line('.')) |
| 1493 | call assert_equal(3, col('.')) |
| 1494 | |
| 1495 | " Test for [` |
| 1496 | norm! 2[` |
| 1497 | call assert_equal(' 15 b', getline('.')) |
| 1498 | call assert_equal(15, line('.')) |
| 1499 | call assert_equal(8, col('.')) |
| 1500 | |
| 1501 | " Test for ]` |
| 1502 | norm! ]` |
| 1503 | call assert_equal(' 20 b', getline('.')) |
| 1504 | call assert_equal(20, line('.')) |
| 1505 | call assert_equal(8, col('.')) |
| 1506 | |
| 1507 | " clean up |
| 1508 | bw! |
Bram Moolenaar | 2931f2a | 2016-09-09 16:59:08 +0200 | [diff] [blame] | 1509 | endfunc |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 1510 | |
| 1511 | func! Test_normal28_parenthesis() |
| 1512 | " basic testing for ( and ) |
| 1513 | new |
| 1514 | call append(0, ['This is a test. With some sentences!', '', 'Even with a question? And one more. And no sentence here']) |
| 1515 | |
| 1516 | $ |
| 1517 | norm! d( |
| 1518 | call assert_equal(['This is a test. With some sentences!', '', 'Even with a question? And one more. ', ''], getline(1, '$')) |
| 1519 | norm! 2d( |
| 1520 | call assert_equal(['This is a test. With some sentences!', '', ' ', ''], getline(1, '$')) |
| 1521 | 1 |
| 1522 | norm! 0d) |
| 1523 | call assert_equal(['With some sentences!', '', ' ', ''], getline(1, '$')) |
| 1524 | |
| 1525 | call append('$', ['This is a long sentence', '', 'spanning', 'over several lines. ']) |
| 1526 | $ |
| 1527 | norm! $d( |
| 1528 | call assert_equal(['With some sentences!', '', ' ', '', 'This is a long sentence', ''], getline(1, '$')) |
| 1529 | |
| 1530 | " clean up |
| 1531 | bw! |
Bram Moolenaar | 2931f2a | 2016-09-09 16:59:08 +0200 | [diff] [blame] | 1532 | endfunc |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 1533 | |
| 1534 | fun! Test_normal29_brace() |
| 1535 | " basic test for { and } movements |
| 1536 | let text= ['A paragraph begins after each empty line, and also at each of a set of', |
| 1537 | \ 'paragraph macros, specified by the pairs of characters in the ''paragraphs''', |
| 1538 | \ 'option. The default is "IPLPPPQPP TPHPLIPpLpItpplpipbp", which corresponds to', |
| 1539 | \ 'the macros ".IP", ".LP", etc. (These are nroff macros, so the dot must be in', |
| 1540 | \ 'the first column). A section boundary is also a paragraph boundary.', |
| 1541 | \ 'Note that a blank line (only containing white space) is NOT a paragraph', |
| 1542 | \ 'boundary.', |
| 1543 | \ '', |
| 1544 | \ '', |
| 1545 | \ 'Also note that this does not include a ''{'' or ''}'' in the first column. When', |
| 1546 | \ 'the ''{'' flag is in ''cpoptions'' then ''{'' in the first column is used as a', |
| 1547 | \ 'paragraph boundary |posix|.', |
| 1548 | \ '{', |
Bram Moolenaar | ae6f865 | 2017-12-20 22:32:20 +0100 | [diff] [blame] | 1549 | \ 'This is no paragraph', |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 1550 | \ 'unless the ''{'' is set', |
| 1551 | \ 'in ''cpoptions''', |
| 1552 | \ '}', |
| 1553 | \ '.IP', |
Bram Moolenaar | ae6f865 | 2017-12-20 22:32:20 +0100 | [diff] [blame] | 1554 | \ 'The nroff macros IP separates a paragraph', |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 1555 | \ 'That means, it must be a ''.''', |
| 1556 | \ 'followed by IP', |
| 1557 | \ '.LPIt does not matter, if afterwards some', |
| 1558 | \ 'more characters follow.', |
| 1559 | \ '.SHAlso section boundaries from the nroff', |
| 1560 | \ 'macros terminate a paragraph. That means', |
| 1561 | \ 'a character like this:', |
| 1562 | \ '.NH', |
| 1563 | \ 'End of text here'] |
| 1564 | new |
| 1565 | call append(0, text) |
| 1566 | 1 |
| 1567 | norm! 0d2} |
| 1568 | call assert_equal(['.IP', |
Bram Moolenaar | ae6f865 | 2017-12-20 22:32:20 +0100 | [diff] [blame] | 1569 | \ 'The nroff macros IP separates a paragraph', 'That means, it must be a ''.''', 'followed by IP', |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 1570 | \ '.LPIt does not matter, if afterwards some', 'more characters follow.', '.SHAlso section boundaries from the nroff', |
| 1571 | \ 'macros terminate a paragraph. That means', 'a character like this:', '.NH', 'End of text here', ''], getline(1,'$')) |
| 1572 | norm! 0d} |
| 1573 | call assert_equal(['.LPIt does not matter, if afterwards some', 'more characters follow.', |
| 1574 | \ '.SHAlso section boundaries from the nroff', 'macros terminate a paragraph. That means', |
| 1575 | \ 'a character like this:', '.NH', 'End of text here', ''], getline(1, '$')) |
| 1576 | $ |
| 1577 | norm! d{ |
| 1578 | call assert_equal(['.LPIt does not matter, if afterwards some', 'more characters follow.', |
| 1579 | \ '.SHAlso section boundaries from the nroff', 'macros terminate a paragraph. That means', 'a character like this:', ''], getline(1, '$')) |
| 1580 | norm! d{ |
| 1581 | call assert_equal(['.LPIt does not matter, if afterwards some', 'more characters follow.', ''], getline(1,'$')) |
| 1582 | " Test with { in cpooptions |
| 1583 | %d |
| 1584 | call append(0, text) |
| 1585 | set cpo+={ |
| 1586 | 1 |
| 1587 | norm! 0d2} |
Bram Moolenaar | ae6f865 | 2017-12-20 22:32:20 +0100 | [diff] [blame] | 1588 | call assert_equal(['{', 'This is no paragraph', 'unless the ''{'' is set', 'in ''cpoptions''', '}', |
| 1589 | \ '.IP', 'The nroff macros IP separates a paragraph', 'That means, it must be a ''.''', |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 1590 | \ 'followed by IP', '.LPIt does not matter, if afterwards some', 'more characters follow.', |
| 1591 | \ '.SHAlso section boundaries from the nroff', 'macros terminate a paragraph. That means', |
| 1592 | \ 'a character like this:', '.NH', 'End of text here', ''], getline(1,'$')) |
| 1593 | $ |
| 1594 | norm! d} |
Bram Moolenaar | ae6f865 | 2017-12-20 22:32:20 +0100 | [diff] [blame] | 1595 | call assert_equal(['{', 'This is no paragraph', 'unless the ''{'' is set', 'in ''cpoptions''', '}', |
| 1596 | \ '.IP', 'The nroff macros IP separates a paragraph', 'That means, it must be a ''.''', |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 1597 | \ 'followed by IP', '.LPIt does not matter, if afterwards some', 'more characters follow.', |
| 1598 | \ '.SHAlso section boundaries from the nroff', 'macros terminate a paragraph. That means', |
| 1599 | \ 'a character like this:', '.NH', 'End of text here', ''], getline(1,'$')) |
| 1600 | norm! gg} |
| 1601 | norm! d5} |
Bram Moolenaar | ae6f865 | 2017-12-20 22:32:20 +0100 | [diff] [blame] | 1602 | call assert_equal(['{', 'This is no paragraph', 'unless the ''{'' is set', 'in ''cpoptions''', '}', ''], getline(1,'$')) |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 1603 | |
| 1604 | " clean up |
| 1605 | set cpo-={ |
| 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_normal30_changecase() |
| 1610 | " This test uses multi byte characters |
| 1611 | if !has("multi_byte") |
| 1612 | return |
| 1613 | endif |
| 1614 | new |
| 1615 | call append(0, 'This is a simple test: äüöß') |
| 1616 | norm! 1ggVu |
| 1617 | call assert_equal('this is a simple test: äüöß', getline('.')) |
| 1618 | norm! VU |
| 1619 | call assert_equal('THIS IS A SIMPLE TEST: ÄÜÖSS', getline('.')) |
| 1620 | norm! guu |
| 1621 | call assert_equal('this is a simple test: äüöss', getline('.')) |
| 1622 | norm! gUgU |
| 1623 | call assert_equal('THIS IS A SIMPLE TEST: ÄÜÖSS', getline('.')) |
| 1624 | norm! gugu |
| 1625 | call assert_equal('this is a simple test: äüöss', getline('.')) |
| 1626 | norm! gUU |
| 1627 | call assert_equal('THIS IS A SIMPLE TEST: ÄÜÖSS', getline('.')) |
| 1628 | norm! 010~ |
| 1629 | call assert_equal('this is a SIMPLE TEST: ÄÜÖSS', getline('.')) |
| 1630 | norm! V~ |
| 1631 | call assert_equal('THIS IS A simple test: äüöss', getline('.')) |
| 1632 | |
Bram Moolenaar | f1c118b | 2018-09-03 22:08:10 +0200 | [diff] [blame^] | 1633 | " Turkish ASCII turns to multi-byte. On some systems Turkish locale |
| 1634 | " is available but toupper()/tolower() don't do the right thing. |
| 1635 | try |
| 1636 | lang tr_TR.UTF-8 |
| 1637 | set casemap= |
| 1638 | let iupper = toupper('i') |
| 1639 | if iupper == "\u0130" |
Bram Moolenaar | 9f4de1f | 2017-04-08 19:39:43 +0200 | [diff] [blame] | 1640 | call setline(1, 'iI') |
| 1641 | 1normal gUU |
| 1642 | call assert_equal("\u0130I", getline(1)) |
| 1643 | call assert_equal("\u0130I", toupper("iI")) |
Bram Moolenaar | 3317d5e | 2017-04-08 19:12:06 +0200 | [diff] [blame] | 1644 | |
Bram Moolenaar | 9f4de1f | 2017-04-08 19:39:43 +0200 | [diff] [blame] | 1645 | call setline(1, 'iI') |
| 1646 | 1normal guu |
| 1647 | call assert_equal("i\u0131", getline(1)) |
| 1648 | call assert_equal("i\u0131", tolower("iI")) |
Bram Moolenaar | f1c118b | 2018-09-03 22:08:10 +0200 | [diff] [blame^] | 1649 | elseif iupper == "I" |
Bram Moolenaar | 1cc4820 | 2017-04-09 13:41:59 +0200 | [diff] [blame] | 1650 | call setline(1, 'iI') |
| 1651 | 1normal gUU |
| 1652 | call assert_equal("II", getline(1)) |
| 1653 | call assert_equal("II", toupper("iI")) |
| 1654 | |
| 1655 | call setline(1, 'iI') |
| 1656 | 1normal guu |
| 1657 | call assert_equal("ii", getline(1)) |
| 1658 | call assert_equal("ii", tolower("iI")) |
Bram Moolenaar | f1c118b | 2018-09-03 22:08:10 +0200 | [diff] [blame^] | 1659 | else |
| 1660 | call assert_true(false, "expected toupper('i') to be either 'I' or '\u0130'") |
| 1661 | endif |
| 1662 | set casemap& |
| 1663 | call setline(1, 'iI') |
| 1664 | 1normal gUU |
| 1665 | call assert_equal("II", getline(1)) |
| 1666 | call assert_equal("II", toupper("iI")) |
Bram Moolenaar | 1cc4820 | 2017-04-09 13:41:59 +0200 | [diff] [blame] | 1667 | |
Bram Moolenaar | f1c118b | 2018-09-03 22:08:10 +0200 | [diff] [blame^] | 1668 | call setline(1, 'iI') |
| 1669 | 1normal guu |
| 1670 | call assert_equal("ii", getline(1)) |
| 1671 | call assert_equal("ii", tolower("iI")) |
| 1672 | |
| 1673 | lang en_US.UTF-8 |
| 1674 | catch /E197:/ |
| 1675 | " can't use Turkish locale |
| 1676 | throw 'Skipped: Turkish locale not available' |
| 1677 | endtry |
Bram Moolenaar | 3317d5e | 2017-04-08 19:12:06 +0200 | [diff] [blame] | 1678 | |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 1679 | " clean up |
| 1680 | bw! |
Bram Moolenaar | 2931f2a | 2016-09-09 16:59:08 +0200 | [diff] [blame] | 1681 | endfunc |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 1682 | |
| 1683 | fun! Test_normal31_r_cmd() |
| 1684 | " Test for r command |
| 1685 | new |
| 1686 | call append(0, 'This is a simple test: abcd') |
| 1687 | exe "norm! 1gg$r\<cr>" |
| 1688 | call assert_equal(['This is a simple test: abc', '', ''], getline(1,'$')) |
| 1689 | exe "norm! 1gg2wlr\<cr>" |
| 1690 | call assert_equal(['This is a', 'simple test: abc', '', ''], getline(1,'$')) |
| 1691 | exe "norm! 2gg0W5r\<cr>" |
| 1692 | call assert_equal(['This is a', 'simple ', ' abc', '', ''], getline('1', '$')) |
| 1693 | set autoindent |
| 1694 | call setline(2, ['simple test: abc', '']) |
| 1695 | exe "norm! 2gg0W5r\<cr>" |
| 1696 | call assert_equal(['This is a', 'simple ', 'abc', '', '', ''], getline('1', '$')) |
| 1697 | exe "norm! 1ggVr\<cr>" |
| 1698 | call assert_equal('^M^M^M^M^M^M^M^M^M', strtrans(getline(1))) |
| 1699 | call setline(1, 'This is a') |
| 1700 | exe "norm! 1gg05rf" |
| 1701 | call assert_equal('fffffis a', getline(1)) |
| 1702 | |
| 1703 | " clean up |
| 1704 | set noautoindent |
| 1705 | bw! |
Bram Moolenaar | 2931f2a | 2016-09-09 16:59:08 +0200 | [diff] [blame] | 1706 | endfunc |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 1707 | |
| 1708 | func! Test_normal32_g_cmd1() |
| 1709 | " Test for g*, g# |
| 1710 | new |
| 1711 | call append(0, ['abc.x_foo', 'x_foobar.abc']) |
| 1712 | 1 |
| 1713 | norm! $g* |
| 1714 | call assert_equal('x_foo', @/) |
| 1715 | call assert_equal('x_foobar.abc', getline('.')) |
| 1716 | norm! $g# |
| 1717 | call assert_equal('abc', @/) |
| 1718 | call assert_equal('abc.x_foo', getline('.')) |
| 1719 | |
| 1720 | " clean up |
| 1721 | bw! |
Bram Moolenaar | 2931f2a | 2016-09-09 16:59:08 +0200 | [diff] [blame] | 1722 | endfunc |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 1723 | |
| 1724 | fun! Test_normal33_g_cmd2() |
| 1725 | if !has("jumplist") |
| 1726 | return |
| 1727 | endif |
| 1728 | " Tests for g cmds |
| 1729 | call Setup_NewWindow() |
| 1730 | " Test for g` |
| 1731 | clearjumps |
| 1732 | norm! ma10j |
| 1733 | let a=execute(':jumps') |
| 1734 | " empty jumplist |
| 1735 | call assert_equal('>', a[-1:]) |
| 1736 | norm! g`a |
| 1737 | call assert_equal('>', a[-1:]) |
| 1738 | call assert_equal(1, line('.')) |
| 1739 | call assert_equal('1', getline('.')) |
| 1740 | |
| 1741 | " Test for g; and g, |
| 1742 | norm! g; |
| 1743 | " there is only one change in the changelist |
| 1744 | " currently, when we setup the window |
| 1745 | call assert_equal(2, line('.')) |
| 1746 | call assert_fails(':norm! g;', 'E662') |
| 1747 | call assert_fails(':norm! g,', 'E663') |
| 1748 | let &ul=&ul |
| 1749 | call append('$', ['a', 'b', 'c', 'd']) |
| 1750 | let &ul=&ul |
| 1751 | call append('$', ['Z', 'Y', 'X', 'W']) |
| 1752 | let a = execute(':changes') |
| 1753 | call assert_match('2\s\+0\s\+2', a) |
| 1754 | call assert_match('101\s\+0\s\+a', a) |
| 1755 | call assert_match('105\s\+0\s\+Z', a) |
| 1756 | norm! 3g; |
| 1757 | call assert_equal(2, line('.')) |
| 1758 | norm! 2g, |
| 1759 | call assert_equal(105, line('.')) |
| 1760 | |
| 1761 | " Test for g& - global substitute |
| 1762 | %d |
| 1763 | call setline(1, range(1,10)) |
| 1764 | call append('$', ['a', 'b', 'c', 'd']) |
| 1765 | $s/\w/&&/g |
| 1766 | exe "norm! /[1-8]\<cr>" |
| 1767 | norm! g& |
| 1768 | call assert_equal(['11', '22', '33', '44', '55', '66', '77', '88', '9', '110', 'a', 'b', 'c', 'dd'], getline(1, '$')) |
| 1769 | |
| 1770 | " Test for gv |
| 1771 | %d |
| 1772 | call append('$', repeat(['abcdefgh'], 8)) |
| 1773 | exe "norm! 2gg02l\<c-v>2j2ly" |
| 1774 | call assert_equal(['cde', 'cde', 'cde'], getreg(0, 1, 1)) |
| 1775 | " in visual mode, gv swaps current and last selected region |
| 1776 | exe "norm! G0\<c-v>4k4lgvd" |
| 1777 | call assert_equal(['', 'abfgh', 'abfgh', 'abfgh', 'abcdefgh', 'abcdefgh', 'abcdefgh', 'abcdefgh', 'abcdefgh'], getline(1,'$')) |
| 1778 | exe "norm! G0\<c-v>4k4ly" |
| 1779 | exe "norm! gvood" |
| 1780 | call assert_equal(['', 'abfgh', 'abfgh', 'abfgh', 'fgh', 'fgh', 'fgh', 'fgh', 'fgh'], getline(1,'$')) |
| 1781 | |
| 1782 | " Test for gk/gj |
| 1783 | %d |
| 1784 | 15vsp |
| 1785 | set wrap listchars= sbr= |
| 1786 | let lineA='abcdefghijklmnopqrstuvwxyz' |
| 1787 | let lineB='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ' |
| 1788 | $put =lineA |
| 1789 | $put =lineB |
| 1790 | |
| 1791 | norm! 3gg0dgk |
| 1792 | call assert_equal(['', 'abcdefghijklmno', '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'], getline(1, '$')) |
| 1793 | set nu |
| 1794 | norm! 3gg0gjdgj |
| 1795 | call assert_equal(['', 'abcdefghijklmno', '0123456789AMNOPQRSTUVWXYZ'], getline(1,'$')) |
| 1796 | |
| 1797 | " Test for gJ |
| 1798 | norm! 2gggJ |
| 1799 | call assert_equal(['', 'abcdefghijklmno0123456789AMNOPQRSTUVWXYZ'], getline(1,'$')) |
| 1800 | call assert_equal(16, col('.')) |
| 1801 | " shouldn't do anything |
| 1802 | norm! 10gJ |
| 1803 | call assert_equal(1, col('.')) |
| 1804 | |
| 1805 | " Test for g0 g^ gm g$ |
| 1806 | exe "norm! 2gg0gji " |
| 1807 | call assert_equal(['', 'abcdefghijk lmno0123456789AMNOPQRSTUVWXYZ'], getline(1,'$')) |
| 1808 | norm! g0yl |
| 1809 | call assert_equal(12, col('.')) |
| 1810 | call assert_equal(' ', getreg(0)) |
| 1811 | norm! g$yl |
| 1812 | call assert_equal(22, col('.')) |
| 1813 | call assert_equal('3', getreg(0)) |
| 1814 | norm! gmyl |
| 1815 | call assert_equal(17, col('.')) |
| 1816 | call assert_equal('n', getreg(0)) |
| 1817 | norm! g^yl |
| 1818 | call assert_equal(15, col('.')) |
| 1819 | call assert_equal('l', getreg(0)) |
| 1820 | |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 1821 | " Test for gI |
| 1822 | norm! gIfoo |
| 1823 | call assert_equal(['', 'fooabcdefghijk lmno0123456789AMNOPQRSTUVWXYZ'], getline(1,'$')) |
| 1824 | |
| 1825 | " Test for gi |
| 1826 | wincmd c |
| 1827 | %d |
| 1828 | set tw=0 |
| 1829 | call setline(1, ['foobar', 'new line']) |
| 1830 | norm! A next word |
| 1831 | $put ='third line' |
| 1832 | norm! gi another word |
| 1833 | call assert_equal(['foobar next word another word', 'new line', 'third line'], getline(1,'$')) |
| 1834 | |
| 1835 | " clean up |
| 1836 | bw! |
Bram Moolenaar | 2931f2a | 2016-09-09 16:59:08 +0200 | [diff] [blame] | 1837 | endfunc |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 1838 | |
Bram Moolenaar | 0529583 | 2018-08-24 22:07:58 +0200 | [diff] [blame] | 1839 | func! Test_g_ctrl_g() |
| 1840 | new |
| 1841 | |
| 1842 | let a = execute(":norm! g\<c-g>") |
| 1843 | call assert_equal("\n--No lines in buffer--", a) |
| 1844 | |
| 1845 | call setline(1, ['first line', 'second line']) |
| 1846 | |
| 1847 | " Test g CTRL-g with dos, mac and unix file type. |
| 1848 | norm! gojll |
| 1849 | set ff=dos |
| 1850 | let a = execute(":norm! g\<c-g>") |
| 1851 | call assert_equal("\nCol 3 of 11; Line 2 of 2; Word 3 of 4; Byte 15 of 25", a) |
| 1852 | |
| 1853 | set ff=mac |
| 1854 | let a = execute(":norm! g\<c-g>") |
| 1855 | call assert_equal("\nCol 3 of 11; Line 2 of 2; Word 3 of 4; Byte 14 of 23", a) |
| 1856 | |
| 1857 | set ff=unix |
| 1858 | let a = execute(":norm! g\<c-g>") |
| 1859 | call assert_equal("\nCol 3 of 11; Line 2 of 2; Word 3 of 4; Byte 14 of 23", a) |
| 1860 | |
| 1861 | " Test g CTRL-g in visual mode (v) |
| 1862 | let a = execute(":norm! gojllvlg\<c-g>") |
| 1863 | call assert_equal("\nSelected 1 of 2 Lines; 1 of 4 Words; 2 of 23 Bytes", a) |
| 1864 | |
| 1865 | " Test g CTRL-g in visual mode (CTRL-V) with end col > start col |
| 1866 | let a = execute(":norm! \<Esc>gojll\<C-V>kllg\<c-g>") |
| 1867 | call assert_equal("\nSelected 3 Cols; 2 of 2 Lines; 2 of 4 Words; 6 of 23 Bytes", a) |
| 1868 | |
| 1869 | " Test g_CTRL-g in visual mode (CTRL-V) with end col < start col |
| 1870 | let a = execute(":norm! \<Esc>goll\<C-V>jhhg\<c-g>") |
| 1871 | call assert_equal("\nSelected 3 Cols; 2 of 2 Lines; 2 of 4 Words; 6 of 23 Bytes", a) |
| 1872 | |
| 1873 | " Test g CTRL-g in visual mode (CTRL-V) with end_vcol being MAXCOL |
| 1874 | let a = execute(":norm! \<Esc>gojll\<C-V>k$g\<c-g>") |
| 1875 | call assert_equal("\nSelected 2 of 2 Lines; 4 of 4 Words; 17 of 23 Bytes", a) |
| 1876 | |
| 1877 | " There should be one byte less with noeol |
| 1878 | set bin noeol |
| 1879 | let a = execute(":norm! \<Esc>gog\<c-g>") |
| 1880 | call assert_equal("\nCol 1 of 10; Line 1 of 2; Word 1 of 4; Char 1 of 23; Byte 1 of 22", a) |
| 1881 | set bin & eol& |
| 1882 | |
| 1883 | if has('multi_byte') |
| 1884 | call setline(1, ['Français', '日本語']) |
| 1885 | |
| 1886 | let a = execute(":norm! \<Esc>gojlg\<c-g>") |
| 1887 | call assert_equal("\nCol 4-3 of 9-6; Line 2 of 2; Word 2 of 2; Char 11 of 13; Byte 16 of 20", a) |
| 1888 | |
| 1889 | let a = execute(":norm! \<Esc>gojvlg\<c-g>") |
| 1890 | call assert_equal("\nSelected 1 of 2 Lines; 1 of 2 Words; 2 of 13 Chars; 6 of 20 Bytes", a) |
| 1891 | |
| 1892 | let a = execute(":norm! \<Esc>goll\<c-v>jlg\<c-g>") |
| 1893 | call assert_equal("\nSelected 4 Cols; 2 of 2 Lines; 2 of 2 Words; 6 of 13 Chars; 11 of 20 Bytes", a) |
| 1894 | |
| 1895 | set fenc=utf8 bomb |
| 1896 | let a = execute(":norm! \<Esc>gojlg\<c-g>") |
| 1897 | call assert_equal("\nCol 4-3 of 9-6; Line 2 of 2; Word 2 of 2; Char 11 of 13; Byte 16 of 20(+3 for BOM)", a) |
| 1898 | |
| 1899 | set fenc=utf16 bomb |
| 1900 | let a = execute(":norm! g\<c-g>") |
| 1901 | call assert_equal("\nCol 4-3 of 9-6; Line 2 of 2; Word 2 of 2; Char 11 of 13; Byte 16 of 20(+2 for BOM)", a) |
| 1902 | |
| 1903 | set fenc=utf32 bomb |
| 1904 | let a = execute(":norm! g\<c-g>") |
| 1905 | call assert_equal("\nCol 4-3 of 9-6; Line 2 of 2; Word 2 of 2; Char 11 of 13; Byte 16 of 20(+4 for BOM)", a) |
| 1906 | |
| 1907 | set fenc& bomb& |
| 1908 | endif |
| 1909 | |
| 1910 | set ff& |
| 1911 | bwipe! |
| 1912 | endfunc |
| 1913 | |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 1914 | fun! Test_normal34_g_cmd3() |
| 1915 | if !has("multi_byte") |
| 1916 | return |
| 1917 | endif |
Bram Moolenaar | 395b6ba | 2017-04-07 20:09:51 +0200 | [diff] [blame] | 1918 | |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 1919 | " Test for g8 |
| 1920 | new |
Bram Moolenaar | 395b6ba | 2017-04-07 20:09:51 +0200 | [diff] [blame] | 1921 | let a=execute(':norm! 1G0g8') |
| 1922 | call assert_equal("\nNUL", a) |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 1923 | |
Bram Moolenaar | 395b6ba | 2017-04-07 20:09:51 +0200 | [diff] [blame] | 1924 | call setline(1, 'abcdefghijklmnopqrstuvwxyzäüö') |
| 1925 | let a=execute(':norm! 1G$g8') |
| 1926 | call assert_equal("\nc3 b6 ", a) |
| 1927 | |
| 1928 | call setline(1, "a\u0302") |
| 1929 | let a=execute(':norm! 1G0g8') |
| 1930 | call assert_equal("\n61 + cc 82 ", a) |
| 1931 | |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 1932 | " clean up |
| 1933 | bw! |
Bram Moolenaar | 2931f2a | 2016-09-09 16:59:08 +0200 | [diff] [blame] | 1934 | endfunc |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 1935 | |
Bram Moolenaar | 395b6ba | 2017-04-07 20:09:51 +0200 | [diff] [blame] | 1936 | func Test_normal_8g8() |
| 1937 | if !has("multi_byte") |
| 1938 | return |
| 1939 | endif |
| 1940 | new |
| 1941 | |
| 1942 | " Test 8g8 which finds invalid utf8 at or after the cursor. |
| 1943 | |
| 1944 | " With invalid byte. |
| 1945 | call setline(1, "___\xff___") |
| 1946 | norm! 1G08g8g |
| 1947 | call assert_equal([0, 1, 4, 0, 1], getcurpos()) |
| 1948 | |
| 1949 | " With invalid byte before the cursor. |
| 1950 | call setline(1, "___\xff___") |
| 1951 | norm! 1G$h8g8g |
| 1952 | call assert_equal([0, 1, 6, 0, 9], getcurpos()) |
| 1953 | |
| 1954 | " With truncated sequence. |
| 1955 | call setline(1, "___\xE2\x82___") |
| 1956 | norm! 1G08g8g |
| 1957 | call assert_equal([0, 1, 4, 0, 1], getcurpos()) |
| 1958 | |
| 1959 | " With overlong sequence. |
| 1960 | call setline(1, "___\xF0\x82\x82\xAC___") |
| 1961 | norm! 1G08g8g |
| 1962 | call assert_equal([0, 1, 4, 0, 1], getcurpos()) |
| 1963 | |
| 1964 | " With valid utf8. |
| 1965 | call setline(1, "café") |
| 1966 | norm! 1G08g8 |
| 1967 | call assert_equal([0, 1, 1, 0, 1], getcurpos()) |
| 1968 | |
| 1969 | bw! |
| 1970 | endfunc |
| 1971 | |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 1972 | fun! Test_normal35_g_cmd4() |
| 1973 | " Test for g< |
| 1974 | " Cannot capture its output, |
| 1975 | " probably a bug, therefore, test disabled: |
Bram Moolenaar | 3184509 | 2016-09-05 22:58:31 +0200 | [diff] [blame] | 1976 | throw "Skipped: output of g< can't be tested currently" |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 1977 | echo "a\nb\nc\nd" |
| 1978 | let b=execute(':norm! g<') |
| 1979 | call assert_true(!empty(b), 'failed `execute(g<)`') |
Bram Moolenaar | 2931f2a | 2016-09-09 16:59:08 +0200 | [diff] [blame] | 1980 | endfunc |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 1981 | |
| 1982 | fun! Test_normal36_g_cmd5() |
| 1983 | new |
| 1984 | call append(0, 'abcdefghijklmnopqrstuvwxyz') |
Bram Moolenaar | 0913a10 | 2016-09-03 19:11:59 +0200 | [diff] [blame] | 1985 | set ff=unix |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 1986 | " Test for gp gP |
| 1987 | call append(1, range(1,10)) |
| 1988 | 1 |
| 1989 | norm! 1yy |
| 1990 | 3 |
| 1991 | norm! gp |
| 1992 | call assert_equal([0, 5, 1, 0, 1], getcurpos()) |
| 1993 | $ |
| 1994 | norm! gP |
| 1995 | call assert_equal([0, 14, 1, 0, 1], getcurpos()) |
| 1996 | |
| 1997 | " Test for go |
| 1998 | norm! 26go |
| 1999 | call assert_equal([0, 1, 26, 0, 26], getcurpos()) |
| 2000 | norm! 27go |
| 2001 | call assert_equal([0, 1, 26, 0, 26], getcurpos()) |
| 2002 | norm! 28go |
| 2003 | call assert_equal([0, 2, 1, 0, 1], getcurpos()) |
| 2004 | set ff=dos |
| 2005 | norm! 29go |
| 2006 | call assert_equal([0, 2, 1, 0, 1], getcurpos()) |
| 2007 | set ff=unix |
| 2008 | norm! gg0 |
| 2009 | norm! 101go |
| 2010 | call assert_equal([0, 13, 26, 0, 26], getcurpos()) |
| 2011 | norm! 103go |
| 2012 | call assert_equal([0, 14, 1, 0, 1], getcurpos()) |
| 2013 | " count > buffer content |
| 2014 | norm! 120go |
| 2015 | call assert_equal([0, 14, 1, 0, 2147483647], getcurpos()) |
| 2016 | " clean up |
| 2017 | bw! |
Bram Moolenaar | 2931f2a | 2016-09-09 16:59:08 +0200 | [diff] [blame] | 2018 | endfunc |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 2019 | |
| 2020 | fun! Test_normal37_g_cmd6() |
| 2021 | " basic test for gt and gT |
| 2022 | tabnew 1.txt |
| 2023 | tabnew 2.txt |
| 2024 | tabnew 3.txt |
| 2025 | norm! 1gt |
| 2026 | call assert_equal(1, tabpagenr()) |
| 2027 | norm! 3gt |
| 2028 | call assert_equal(3, tabpagenr()) |
| 2029 | norm! 1gT |
| 2030 | " count gT goes not to the absolute tabpagenumber |
| 2031 | " but, but goes to the count previous tabpagenumber |
| 2032 | call assert_equal(2, tabpagenr()) |
| 2033 | " wrap around |
| 2034 | norm! 3gT |
| 2035 | call assert_equal(3, tabpagenr()) |
| 2036 | " gt does not wrap around |
| 2037 | norm! 5gt |
| 2038 | call assert_equal(3, tabpagenr()) |
| 2039 | |
| 2040 | for i in range(3) |
| 2041 | tabclose |
| 2042 | endfor |
| 2043 | " clean up |
| 2044 | call assert_fails(':tabclose', 'E784') |
Bram Moolenaar | 2931f2a | 2016-09-09 16:59:08 +0200 | [diff] [blame] | 2045 | endfunc |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 2046 | |
| 2047 | fun! Test_normal38_nvhome() |
| 2048 | " Test for <Home> and <C-Home> key |
| 2049 | new |
| 2050 | call setline(1, range(10)) |
| 2051 | $ |
| 2052 | setl et sw=2 |
| 2053 | norm! V10>$ |
| 2054 | " count is ignored |
| 2055 | exe "norm! 10\<home>" |
| 2056 | call assert_equal(1, col('.')) |
| 2057 | exe "norm! \<home>" |
| 2058 | call assert_equal([0, 10, 1, 0, 1], getcurpos()) |
| 2059 | exe "norm! 5\<c-home>" |
| 2060 | call assert_equal([0, 5, 1, 0, 1], getcurpos()) |
| 2061 | exe "norm! \<c-home>" |
| 2062 | call assert_equal([0, 1, 1, 0, 1], getcurpos()) |
| 2063 | |
| 2064 | " clean up |
| 2065 | bw! |
Bram Moolenaar | 2931f2a | 2016-09-09 16:59:08 +0200 | [diff] [blame] | 2066 | endfunc |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 2067 | |
| 2068 | fun! Test_normal39_cw() |
| 2069 | " Test for cw and cW on whitespace |
| 2070 | " and cpo+=w setting |
| 2071 | new |
| 2072 | set tw=0 |
| 2073 | call append(0, 'here are some words') |
| 2074 | norm! 1gg0elcwZZZ |
| 2075 | call assert_equal('hereZZZare some words', getline('.')) |
| 2076 | norm! 1gg0elcWYYY |
| 2077 | call assert_equal('hereZZZareYYYsome words', getline('.')) |
| 2078 | set cpo+=w |
| 2079 | call setline(1, 'here are some words') |
| 2080 | norm! 1gg0elcwZZZ |
| 2081 | call assert_equal('hereZZZ are some words', getline('.')) |
| 2082 | norm! 1gg2elcWYYY |
| 2083 | call assert_equal('hereZZZ areYYY some words', getline('.')) |
| 2084 | set cpo-=w |
| 2085 | norm! 2gg0cwfoo |
| 2086 | call assert_equal('foo', getline('.')) |
| 2087 | |
| 2088 | " clean up |
| 2089 | bw! |
Bram Moolenaar | 2931f2a | 2016-09-09 16:59:08 +0200 | [diff] [blame] | 2090 | endfunc |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 2091 | |
| 2092 | fun! Test_normal40_ctrl_bsl() |
| 2093 | " Basic test for CTRL-\ commands |
| 2094 | new |
| 2095 | call append(0, 'here are some words') |
| 2096 | exe "norm! 1gg0a\<C-\>\<C-N>" |
| 2097 | call assert_equal('n', mode()) |
| 2098 | call assert_equal(1, col('.')) |
| 2099 | call assert_equal('', visualmode()) |
| 2100 | exe "norm! 1gg0viw\<C-\>\<C-N>" |
| 2101 | call assert_equal('n', mode()) |
| 2102 | call assert_equal(4, col('.')) |
| 2103 | exe "norm! 1gg0a\<C-\>\<C-G>" |
| 2104 | call assert_equal('n', mode()) |
| 2105 | call assert_equal(1, col('.')) |
| 2106 | "imap <buffer> , <c-\><c-n> |
| 2107 | set im |
| 2108 | exe ":norm! \<c-\>\<c-n>dw" |
| 2109 | set noim |
| 2110 | call assert_equal('are some words', getline(1)) |
| 2111 | call assert_false(&insertmode) |
| 2112 | |
| 2113 | " clean up |
| 2114 | bw! |
Bram Moolenaar | 2931f2a | 2016-09-09 16:59:08 +0200 | [diff] [blame] | 2115 | endfunc |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 2116 | |
| 2117 | fun! Test_normal41_insert_reg() |
| 2118 | " Test for <c-r>=, <c-r><c-r>= and <c-r><c-o>= |
| 2119 | " in insert mode |
| 2120 | new |
| 2121 | set sts=2 sw=2 ts=8 tw=0 |
| 2122 | call append(0, ["aaa\tbbb\tccc", '', '', '']) |
| 2123 | let a=getline(1) |
| 2124 | norm! 2gg0 |
| 2125 | exe "norm! a\<c-r>=a\<cr>" |
| 2126 | norm! 3gg0 |
| 2127 | exe "norm! a\<c-r>\<c-r>=a\<cr>" |
| 2128 | norm! 4gg0 |
| 2129 | exe "norm! a\<c-r>\<c-o>=a\<cr>" |
| 2130 | call assert_equal(['aaa bbb ccc', 'aaa bbb ccc', 'aaa bbb ccc', 'aaa bbb ccc', ''], getline(1, '$')) |
| 2131 | |
| 2132 | " clean up |
| 2133 | set sts=0 sw=8 ts=8 |
Bram Moolenaar | 3184509 | 2016-09-05 22:58:31 +0200 | [diff] [blame] | 2134 | bw! |
Bram Moolenaar | 2931f2a | 2016-09-09 16:59:08 +0200 | [diff] [blame] | 2135 | endfunc |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 2136 | |
| 2137 | func! Test_normal42_halfpage() |
| 2138 | " basic test for Ctrl-D and Ctrl-U |
| 2139 | call Setup_NewWindow() |
| 2140 | call assert_equal(5, &scroll) |
| 2141 | exe "norm! \<c-d>" |
| 2142 | call assert_equal('6', getline('.')) |
| 2143 | exe "norm! 2\<c-d>" |
| 2144 | call assert_equal('8', getline('.')) |
| 2145 | call assert_equal(2, &scroll) |
| 2146 | set scroll=5 |
| 2147 | exe "norm! \<c-u>" |
| 2148 | call assert_equal('3', getline('.')) |
| 2149 | 1 |
| 2150 | set scrolloff=5 |
| 2151 | exe "norm! \<c-d>" |
| 2152 | call assert_equal('10', getline('.')) |
| 2153 | exe "norm! \<c-u>" |
| 2154 | call assert_equal('5', getline('.')) |
| 2155 | 1 |
| 2156 | set scrolloff=99 |
| 2157 | exe "norm! \<c-d>" |
| 2158 | call assert_equal('10', getline('.')) |
| 2159 | set scrolloff=0 |
| 2160 | 100 |
| 2161 | exe "norm! $\<c-u>" |
| 2162 | call assert_equal('95', getline('.')) |
| 2163 | call assert_equal([0, 95, 1, 0, 1], getcurpos()) |
| 2164 | 100 |
| 2165 | set nostartofline |
| 2166 | exe "norm! $\<c-u>" |
| 2167 | call assert_equal('95', getline('.')) |
| 2168 | call assert_equal([0, 95, 2, 0, 2147483647], getcurpos()) |
| 2169 | " cleanup |
| 2170 | set startofline |
| 2171 | bw! |
Bram Moolenaar | 2931f2a | 2016-09-09 16:59:08 +0200 | [diff] [blame] | 2172 | endfunc |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 2173 | |
| 2174 | fun! Test_normal43_textobject1() |
| 2175 | " basic tests for text object aw |
| 2176 | new |
| 2177 | call append(0, ['foobar,eins,foobar', 'foo,zwei,foo ']) |
| 2178 | " diw |
| 2179 | norm! 1gg0diw |
| 2180 | call assert_equal([',eins,foobar', 'foo,zwei,foo ', ''], getline(1,'$')) |
| 2181 | " daw |
| 2182 | norm! 2ggEdaw |
| 2183 | call assert_equal([',eins,foobar', 'foo,zwei,', ''], getline(1, '$')) |
| 2184 | %d |
| 2185 | call append(0, ["foo\teins\tfoobar", "foo\tzwei\tfoo "]) |
| 2186 | " diW |
| 2187 | norm! 2ggwd2iW |
| 2188 | call assert_equal(['foo eins foobar', 'foo foo ', ''], getline(1,'$')) |
| 2189 | " daW |
| 2190 | norm! 1ggd2aW |
| 2191 | call assert_equal(['foobar', 'foo foo ', ''], getline(1,'$')) |
| 2192 | |
| 2193 | %d |
| 2194 | call append(0, ["foo\teins\tfoobar", "foo\tzwei\tfoo "]) |
| 2195 | " aw in visual line mode switches to characterwise mode |
| 2196 | norm! 2gg$Vawd |
| 2197 | call assert_equal(['foo eins foobar', 'foo zwei foo'], getline(1,'$')) |
| 2198 | norm! 1gg$Viwd |
| 2199 | call assert_equal(['foo eins ', 'foo zwei foo'], getline(1,'$')) |
| 2200 | |
| 2201 | " clean up |
| 2202 | bw! |
Bram Moolenaar | 2931f2a | 2016-09-09 16:59:08 +0200 | [diff] [blame] | 2203 | endfunc |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 2204 | |
| 2205 | func! Test_normal44_textobjects2() |
| 2206 | " basic testing for is and as text objects |
| 2207 | new |
| 2208 | call append(0, ['This is a test. With some sentences!', '', 'Even with a question? And one more. And no sentence here']) |
| 2209 | " Test for dis - does not remove trailing whitespace |
| 2210 | norm! 1gg0dis |
| 2211 | call assert_equal([' With some sentences!', '', 'Even with a question? And one more. And no sentence here', ''], getline(1,'$')) |
| 2212 | " Test for das - removes leading whitespace |
| 2213 | norm! 3ggf?ldas |
| 2214 | call assert_equal([' With some sentences!', '', 'Even with a question? And no sentence here', ''], getline(1,'$')) |
| 2215 | " when used in visual mode, is made characterwise |
| 2216 | norm! 3gg$Visy |
| 2217 | call assert_equal('v', visualmode()) |
| 2218 | " reset visualmode() |
| 2219 | norm! 3ggVy |
| 2220 | norm! 3gg$Vasy |
| 2221 | call assert_equal('v', visualmode()) |
| 2222 | " basic testing for textobjects a< and at |
| 2223 | %d |
| 2224 | call setline(1, ['<div> ','<a href="foobar" class="foo">xyz</a>',' </div>', ' ']) |
| 2225 | " a< |
| 2226 | norm! 1gg0da< |
| 2227 | call assert_equal([' ', '<a href="foobar" class="foo">xyz</a>', ' </div>', ' '], getline(1,'$')) |
| 2228 | norm! 1pj |
| 2229 | call assert_equal([' <div>', '<a href="foobar" class="foo">xyz</a>', ' </div>', ' '], getline(1,'$')) |
| 2230 | " at |
| 2231 | norm! d2at |
| 2232 | call assert_equal([' '], getline(1,'$')) |
| 2233 | %d |
| 2234 | call setline(1, ['<div> ','<a href="foobar" class="foo">xyz</a>',' </div>', ' ']) |
| 2235 | " i< |
| 2236 | norm! 1gg0di< |
| 2237 | call assert_equal(['<> ', '<a href="foobar" class="foo">xyz</a>', ' </div>', ' '], getline(1,'$')) |
| 2238 | norm! 1Pj |
| 2239 | call assert_equal(['<div> ', '<a href="foobar" class="foo">xyz</a>', ' </div>', ' '], getline(1,'$')) |
| 2240 | norm! d2it |
| 2241 | call assert_equal(['<div></div>',' '], getline(1,'$')) |
| 2242 | " basic testing for a[ and i[ text object |
| 2243 | %d |
| 2244 | call setline(1, [' ', '[', 'one [two]', 'thre', ']']) |
| 2245 | norm! 3gg0di[ |
| 2246 | call assert_equal([' ', '[', ']'], getline(1,'$')) |
| 2247 | call setline(1, [' ', '[', 'one [two]', 'thre', ']']) |
| 2248 | norm! 3gg0ftd2a[ |
| 2249 | call assert_equal([' '], getline(1,'$')) |
| 2250 | %d |
| 2251 | " Test for i" when cursor is in front of a quoted object |
| 2252 | call append(0, 'foo "bar"') |
| 2253 | norm! 1gg0di" |
| 2254 | call assert_equal(['foo ""', ''], getline(1,'$')) |
| 2255 | |
| 2256 | " clean up |
| 2257 | bw! |
Bram Moolenaar | 2931f2a | 2016-09-09 16:59:08 +0200 | [diff] [blame] | 2258 | endfunc |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 2259 | |
| 2260 | func! Test_normal45_drop() |
Bram Moolenaar | 2949595 | 2018-02-12 22:49:00 +0100 | [diff] [blame] | 2261 | if !has('dnd') |
Bram Moolenaar | b48e96f | 2018-02-13 12:26:14 +0100 | [diff] [blame] | 2262 | " The ~ register does not exist |
| 2263 | call assert_beeps('norm! "~') |
Bram Moolenaar | 2949595 | 2018-02-12 22:49:00 +0100 | [diff] [blame] | 2264 | return |
| 2265 | endif |
| 2266 | |
| 2267 | " basic test for drag-n-drop |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 2268 | " unfortunately, without a gui, we can't really test much here, |
| 2269 | " so simply test that ~p fails (which uses the drop register) |
| 2270 | new |
| 2271 | call assert_fails(':norm! "~p', 'E353') |
| 2272 | call assert_equal([], getreg('~', 1, 1)) |
| 2273 | " the ~ register is read only |
| 2274 | call assert_fails(':let @~="1"', 'E354') |
| 2275 | bw! |
Bram Moolenaar | 2931f2a | 2016-09-09 16:59:08 +0200 | [diff] [blame] | 2276 | endfunc |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 2277 | |
| 2278 | func! Test_normal46_ignore() |
Bram Moolenaar | 2931f2a | 2016-09-09 16:59:08 +0200 | [diff] [blame] | 2279 | " This test uses multi byte characters |
| 2280 | if !has("multi_byte") |
| 2281 | return |
| 2282 | endif |
| 2283 | |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 2284 | new |
| 2285 | " How to test this? |
| 2286 | " let's just for now test, that the buffer |
| 2287 | " does not change |
| 2288 | call feedkeys("\<c-s>", 't') |
| 2289 | call assert_equal([''], getline(1,'$')) |
| 2290 | |
Bram Moolenaar | 2931f2a | 2016-09-09 16:59:08 +0200 | [diff] [blame] | 2291 | " no valid commands |
| 2292 | exe "norm! \<char-0x100>" |
| 2293 | call assert_equal([''], getline(1,'$')) |
| 2294 | |
| 2295 | exe "norm! ä" |
| 2296 | call assert_equal([''], getline(1,'$')) |
| 2297 | |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 2298 | " clean up |
| 2299 | bw! |
Bram Moolenaar | 2931f2a | 2016-09-09 16:59:08 +0200 | [diff] [blame] | 2300 | endfunc |
Bram Moolenaar | c4a908e | 2016-09-08 23:35:30 +0200 | [diff] [blame] | 2301 | |
| 2302 | func! Test_normal47_visual_buf_wipe() |
| 2303 | " This was causing a crash or ml_get error. |
| 2304 | enew! |
| 2305 | call setline(1,'xxx') |
| 2306 | normal $ |
| 2307 | new |
| 2308 | call setline(1, range(1,2)) |
| 2309 | 2 |
| 2310 | exe "norm \<C-V>$" |
| 2311 | bw! |
| 2312 | norm yp |
| 2313 | set nomodified |
Bram Moolenaar | 2931f2a | 2016-09-09 16:59:08 +0200 | [diff] [blame] | 2314 | endfunc |
| 2315 | |
| 2316 | func! Test_normal47_autocmd() |
| 2317 | " disabled, does not seem to be possible currently |
| 2318 | throw "Skipped: not possible to test cursorhold autocmd while waiting for input in normal_cmd" |
| 2319 | new |
| 2320 | call append(0, repeat('-',20)) |
| 2321 | au CursorHold * call feedkeys('2l', '') |
| 2322 | 1 |
| 2323 | set updatetime=20 |
| 2324 | " should delete 12 chars (d12l) |
| 2325 | call feedkeys('d1', '!') |
| 2326 | call assert_equal('--------', getline(1)) |
| 2327 | |
| 2328 | " clean up |
| 2329 | au! CursorHold |
| 2330 | set updatetime=4000 |
| 2331 | bw! |
| 2332 | endfunc |
| 2333 | |
| 2334 | func! Test_normal48_wincmd() |
| 2335 | new |
| 2336 | exe "norm! \<c-w>c" |
| 2337 | call assert_equal(1, winnr('$')) |
| 2338 | call assert_fails(":norm! \<c-w>c", "E444") |
| 2339 | endfunc |
| 2340 | |
| 2341 | func! Test_normal49_counts() |
| 2342 | new |
| 2343 | call setline(1, 'one two three four five six seven eight nine ten') |
| 2344 | 1 |
| 2345 | norm! 3d2w |
| 2346 | call assert_equal('seven eight nine ten', getline(1)) |
| 2347 | bw! |
| 2348 | endfunc |
| 2349 | |
| 2350 | func! Test_normal50_commandline() |
Bram Moolenaar | 4033c55 | 2017-09-16 20:54:51 +0200 | [diff] [blame] | 2351 | if !has("timers") || !has("cmdline_hist") |
Bram Moolenaar | 2931f2a | 2016-09-09 16:59:08 +0200 | [diff] [blame] | 2352 | return |
| 2353 | endif |
| 2354 | func! DoTimerWork(id) |
| 2355 | call assert_equal('[Command Line]', bufname('')) |
| 2356 | " should fail, with E11, but does fail with E23? |
| 2357 | "call feedkeys("\<c-^>", 'tm') |
| 2358 | |
| 2359 | " should also fail with E11 |
| 2360 | call assert_fails(":wincmd p", 'E11') |
| 2361 | " return from commandline window |
| 2362 | call feedkeys("\<cr>") |
| 2363 | endfunc |
| 2364 | |
| 2365 | let oldlang=v:lang |
| 2366 | lang C |
| 2367 | set updatetime=20 |
| 2368 | call timer_start(100, 'DoTimerWork') |
| 2369 | try |
| 2370 | " throws E23, for whatever reason... |
| 2371 | call feedkeys('q:', 'x!') |
| 2372 | catch /E23/ |
| 2373 | " no-op |
| 2374 | endtry |
| 2375 | " clean up |
| 2376 | set updatetime=4000 |
| 2377 | exe "lang" oldlang |
| 2378 | bw! |
| 2379 | endfunc |
| 2380 | |
| 2381 | func! Test_normal51_FileChangedRO() |
| 2382 | if !has("autocmd") |
| 2383 | return |
| 2384 | endif |
Bram Moolenaar | e5f2a07 | 2017-02-01 22:31:49 +0100 | [diff] [blame] | 2385 | " Don't sleep after the warning message. |
| 2386 | call test_settime(1) |
Bram Moolenaar | 2931f2a | 2016-09-09 16:59:08 +0200 | [diff] [blame] | 2387 | call writefile(['foo'], 'Xreadonly.log') |
| 2388 | new Xreadonly.log |
| 2389 | setl ro |
| 2390 | au FileChangedRO <buffer> :call feedkeys("\<c-^>", 'tix') |
| 2391 | call assert_fails(":norm! Af", 'E788') |
| 2392 | call assert_equal(['foo'], getline(1,'$')) |
| 2393 | call assert_equal('Xreadonly.log', bufname('')) |
| 2394 | |
| 2395 | " cleanup |
Bram Moolenaar | e5f2a07 | 2017-02-01 22:31:49 +0100 | [diff] [blame] | 2396 | call test_settime(0) |
Bram Moolenaar | 2931f2a | 2016-09-09 16:59:08 +0200 | [diff] [blame] | 2397 | bw! |
| 2398 | call delete("Xreadonly.log") |
| 2399 | endfunc |
| 2400 | |
| 2401 | func! Test_normal52_rl() |
| 2402 | if !has("rightleft") |
| 2403 | return |
| 2404 | endif |
| 2405 | new |
| 2406 | call setline(1, 'abcde fghij klmnopq') |
| 2407 | norm! 1gg$ |
| 2408 | set rl |
| 2409 | call assert_equal(19, col('.')) |
| 2410 | call feedkeys('l', 'tx') |
| 2411 | call assert_equal(18, col('.')) |
| 2412 | call feedkeys('h', 'tx') |
| 2413 | call assert_equal(19, col('.')) |
| 2414 | call feedkeys("\<right>", 'tx') |
| 2415 | call assert_equal(18, col('.')) |
| 2416 | call feedkeys("\<s-right>", 'tx') |
| 2417 | call assert_equal(13, col('.')) |
| 2418 | call feedkeys("\<c-right>", 'tx') |
| 2419 | call assert_equal(7, col('.')) |
| 2420 | call feedkeys("\<c-left>", 'tx') |
| 2421 | call assert_equal(13, col('.')) |
| 2422 | call feedkeys("\<s-left>", 'tx') |
| 2423 | call assert_equal(19, col('.')) |
| 2424 | call feedkeys("<<", 'tx') |
| 2425 | call assert_equal(' abcde fghij klmnopq',getline(1)) |
| 2426 | call feedkeys(">>", 'tx') |
| 2427 | call assert_equal('abcde fghij klmnopq',getline(1)) |
| 2428 | |
| 2429 | " cleanup |
| 2430 | set norl |
| 2431 | bw! |
| 2432 | endfunc |
| 2433 | |
| 2434 | func! Test_normal53_digraph() |
| 2435 | if !has('digraphs') |
| 2436 | return |
| 2437 | endif |
| 2438 | new |
| 2439 | call setline(1, 'abcdefgh|') |
| 2440 | exe "norm! 1gg0f\<c-k>!!" |
| 2441 | call assert_equal(9, col('.')) |
| 2442 | set cpo+=D |
| 2443 | exe "norm! 1gg0f\<c-k>!!" |
| 2444 | call assert_equal(1, col('.')) |
| 2445 | |
| 2446 | set cpo-=D |
| 2447 | bw! |
| 2448 | endfunc |
| 2449 | |
Bram Moolenaar | b1e04fc | 2017-03-29 13:08:35 +0200 | [diff] [blame] | 2450 | func Test_normal54_Ctrl_bsl() |
| 2451 | new |
| 2452 | call setline(1, 'abcdefghijklmn') |
| 2453 | exe "norm! df\<c-\>\<c-n>" |
| 2454 | call assert_equal(['abcdefghijklmn'], getline(1,'$')) |
| 2455 | exe "norm! df\<c-\>\<c-g>" |
| 2456 | call assert_equal(['abcdefghijklmn'], getline(1,'$')) |
| 2457 | exe "norm! df\<c-\>m" |
| 2458 | call assert_equal(['abcdefghijklmn'], getline(1,'$')) |
Bram Moolenaar | 2931f2a | 2016-09-09 16:59:08 +0200 | [diff] [blame] | 2459 | if !has("multi_byte") |
| 2460 | return |
| 2461 | endif |
Bram Moolenaar | b1e04fc | 2017-03-29 13:08:35 +0200 | [diff] [blame] | 2462 | call setline(2, 'abcdefghijklmnāf') |
| 2463 | norm! 2gg0 |
| 2464 | exe "norm! df\<Char-0x101>" |
| 2465 | call assert_equal(['abcdefghijklmn', 'f'], getline(1,'$')) |
| 2466 | norm! 1gg0 |
| 2467 | exe "norm! df\<esc>" |
| 2468 | call assert_equal(['abcdefghijklmn', 'f'], getline(1,'$')) |
Bram Moolenaar | 2931f2a | 2016-09-09 16:59:08 +0200 | [diff] [blame] | 2469 | |
Bram Moolenaar | b1e04fc | 2017-03-29 13:08:35 +0200 | [diff] [blame] | 2470 | " clean up |
| 2471 | bw! |
| 2472 | endfunc |
| 2473 | |
| 2474 | func Test_normal_large_count() |
| 2475 | " This may fail with 32bit long, how do we detect that? |
| 2476 | new |
| 2477 | normal o |
| 2478 | normal 6666666666dL |
| 2479 | bwipe! |
Bram Moolenaar | 2931f2a | 2016-09-09 16:59:08 +0200 | [diff] [blame] | 2480 | endfunc |
Bram Moolenaar | bf3d580 | 2017-03-29 19:48:11 +0200 | [diff] [blame] | 2481 | |
| 2482 | func Test_delete_until_paragraph() |
| 2483 | if !has('multi_byte') |
| 2484 | return |
| 2485 | endif |
| 2486 | new |
| 2487 | normal grádv} |
| 2488 | call assert_equal('á', getline(1)) |
| 2489 | normal grád} |
| 2490 | call assert_equal('', getline(1)) |
| 2491 | bwipe! |
| 2492 | endfunc |
Bram Moolenaar | fb094e1 | 2017-11-05 20:59:28 +0100 | [diff] [blame] | 2493 | |
| 2494 | " Test for the gr (virtual replace) command |
| 2495 | " Test for the bug fixed by 7.4.387 |
| 2496 | func Test_gr_command() |
| 2497 | enew! |
| 2498 | let save_cpo = &cpo |
| 2499 | call append(0, ['First line', 'Second line', 'Third line']) |
| 2500 | exe "normal i\<C-G>u" |
| 2501 | call cursor(2, 1) |
| 2502 | set cpo-=X |
| 2503 | normal 4gro |
| 2504 | call assert_equal('oooond line', getline(2)) |
| 2505 | undo |
| 2506 | set cpo+=X |
| 2507 | normal 4gro |
| 2508 | call assert_equal('ooooecond line', getline(2)) |
| 2509 | let &cpo = save_cpo |
| 2510 | enew! |
| 2511 | endfunc |
| 2512 | |
| 2513 | " When splitting a window the changelist position is wrong. |
| 2514 | " Test the changelist position after splitting a window. |
| 2515 | " Test for the bug fixed by 7.4.386 |
| 2516 | func Test_changelist() |
| 2517 | let save_ul = &ul |
| 2518 | enew! |
| 2519 | call append('$', ['1', '2']) |
| 2520 | exe "normal i\<C-G>u" |
| 2521 | exe "normal Gkylpa\<C-G>u" |
| 2522 | set ul=100 |
| 2523 | exe "normal Gylpa\<C-G>u" |
| 2524 | set ul=100 |
| 2525 | normal gg |
| 2526 | vsplit |
| 2527 | normal g; |
| 2528 | call assert_equal([3, 2], [line('.'), col('.')]) |
| 2529 | normal g; |
| 2530 | call assert_equal([2, 2], [line('.'), col('.')]) |
| 2531 | call assert_fails('normal g;', 'E662:') |
| 2532 | %bwipe! |
| 2533 | let &ul = save_ul |
| 2534 | endfunc |