Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 1 | " Test for various Normal mode commands |
| 2 | |
Bram Moolenaar | a84a3dd | 2019-03-25 22:21:24 +0100 | [diff] [blame] | 3 | source shared.vim |
Bram Moolenaar | 5a4c308 | 2019-12-01 15:23:11 +0100 | [diff] [blame] | 4 | source check.vim |
Bram Moolenaar | ca68ae1 | 2020-03-30 19:32:53 +0200 | [diff] [blame^] | 5 | source view_util.vim |
Bram Moolenaar | a84a3dd | 2019-03-25 22:21:24 +0100 | [diff] [blame] | 6 | |
Bram Moolenaar | 1bbb619 | 2018-11-10 16:02:01 +0100 | [diff] [blame] | 7 | func Setup_NewWindow() |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 8 | 10new |
| 9 | call setline(1, range(1,100)) |
| 10 | endfunc |
| 11 | |
Bram Moolenaar | 1bbb619 | 2018-11-10 16:02:01 +0100 | [diff] [blame] | 12 | func MyFormatExpr() |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 13 | " Adds '->$' at lines having numbers followed by trailing whitespace |
| 14 | for ln in range(v:lnum, v:lnum+v:count-1) |
| 15 | let line = getline(ln) |
| 16 | if getline(ln) =~# '\d\s\+$' |
| 17 | call setline(ln, substitute(line, '\s\+$', '', '') . '->$') |
| 18 | endif |
| 19 | endfor |
Bram Moolenaar | 2931f2a | 2016-09-09 16:59:08 +0200 | [diff] [blame] | 20 | endfunc |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 21 | |
Bram Moolenaar | 1bbb619 | 2018-11-10 16:02:01 +0100 | [diff] [blame] | 22 | func CountSpaces(type, ...) |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 23 | " for testing operatorfunc |
| 24 | " will count the number of spaces |
| 25 | " and return the result in g:a |
| 26 | let sel_save = &selection |
| 27 | let &selection = "inclusive" |
| 28 | let reg_save = @@ |
| 29 | |
| 30 | if a:0 " Invoked from Visual mode, use gv command. |
| 31 | silent exe "normal! gvy" |
| 32 | elseif a:type == 'line' |
| 33 | silent exe "normal! '[V']y" |
| 34 | else |
| 35 | silent exe "normal! `[v`]y" |
| 36 | endif |
| 37 | let g:a=strlen(substitute(@@, '[^ ]', '', 'g')) |
| 38 | let &selection = sel_save |
| 39 | let @@ = reg_save |
Bram Moolenaar | 2931f2a | 2016-09-09 16:59:08 +0200 | [diff] [blame] | 40 | endfunc |
| 41 | |
Bram Moolenaar | 1bbb619 | 2018-11-10 16:02:01 +0100 | [diff] [blame] | 42 | func OpfuncDummy(type, ...) |
Bram Moolenaar | 4a08b0d | 2016-11-05 21:55:13 +0100 | [diff] [blame] | 43 | " for testing operatorfunc |
| 44 | let g:opt=&linebreak |
| 45 | |
| 46 | if a:0 " Invoked from Visual mode, use gv command. |
| 47 | silent exe "normal! gvy" |
| 48 | elseif a:type == 'line' |
| 49 | silent exe "normal! '[V']y" |
| 50 | else |
| 51 | silent exe "normal! `[v`]y" |
| 52 | endif |
| 53 | " Create a new dummy window |
| 54 | new |
| 55 | let g:bufnr=bufnr('%') |
Bram Moolenaar | 2931f2a | 2016-09-09 16:59:08 +0200 | [diff] [blame] | 56 | endfunc |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 57 | |
Bram Moolenaar | 1671f44 | 2020-03-10 07:48:13 +0100 | [diff] [blame] | 58 | func Test_normal00_optrans() |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 59 | new |
| 60 | call append(0, ['1 This is a simple test: abcd', '2 This is the second line', '3 this is the third line']) |
| 61 | 1 |
| 62 | exe "norm! Sfoobar\<esc>" |
| 63 | call assert_equal(['foobar', '2 This is the second line', '3 this is the third line', ''], getline(1,'$')) |
| 64 | 2 |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 65 | exe "norm! $vbsone" |
| 66 | 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] | 67 | norm! VS Second line here |
| 68 | call assert_equal(['foobar', ' Second line here', '3 this is the third line', ''], getline(1, '$')) |
| 69 | %d |
| 70 | call append(0, ['4 This is a simple test: abcd', '5 This is the second line', '6 this is the third line']) |
| 71 | call append(0, ['1 This is a simple test: abcd', '2 This is the second line', '3 this is the third line']) |
| 72 | |
| 73 | 1 |
| 74 | norm! 2D |
| 75 | 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,'$')) |
| 76 | set cpo+=# |
| 77 | norm! 4D |
| 78 | call assert_equal(['', '4 This is a simple test: abcd', '5 This is the second line', '6 this is the third line', ''], getline(1,'$')) |
| 79 | |
| 80 | " clean up |
| 81 | set cpo-=# |
| 82 | bw! |
Bram Moolenaar | 2931f2a | 2016-09-09 16:59:08 +0200 | [diff] [blame] | 83 | endfunc |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 84 | |
Bram Moolenaar | 1bbb619 | 2018-11-10 16:02:01 +0100 | [diff] [blame] | 85 | func Test_normal01_keymodel() |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 86 | call Setup_NewWindow() |
| 87 | " Test 1: depending on 'keymodel' <s-down> does something different |
Bram Moolenaar | 2931f2a | 2016-09-09 16:59:08 +0200 | [diff] [blame] | 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(['47', '48', '49', '50'], getline("'<", "'>")) |
Bram Moolenaar | 2931f2a | 2016-09-09 16:59:08 +0200 | [diff] [blame] | 91 | set keymodel=startsel |
| 92 | 50 |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 93 | call feedkeys("V\<S-Up>y", 'tx') |
| 94 | call assert_equal(['49', '50'], getline("'<", "'>")) |
| 95 | " Start visual mode when keymodel = startsel |
Bram Moolenaar | 2931f2a | 2016-09-09 16:59:08 +0200 | [diff] [blame] | 96 | 50 |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 97 | call feedkeys("\<S-Up>y", 'tx') |
| 98 | call assert_equal(['49', '5'], getreg(0, 0, 1)) |
Bram Moolenaar | 1671f44 | 2020-03-10 07:48:13 +0100 | [diff] [blame] | 99 | " Use the different Shift special keys |
| 100 | 50 |
| 101 | call feedkeys("\<S-Right>\<S-Left>\<S-Up>\<S-Down>\<S-Home>\<S-End>y", 'tx') |
| 102 | call assert_equal(['50'], getline("'<", "'>")) |
| 103 | call assert_equal(['50', ''], getreg(0, 0, 1)) |
| 104 | |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 105 | " Do not start visual mode when keymodel= |
Bram Moolenaar | 2931f2a | 2016-09-09 16:59:08 +0200 | [diff] [blame] | 106 | set keymodel= |
| 107 | 50 |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 108 | call feedkeys("\<S-Up>y$", 'tx') |
| 109 | call assert_equal(['42'], getreg(0, 0, 1)) |
Bram Moolenaar | 2931f2a | 2016-09-09 16:59:08 +0200 | [diff] [blame] | 110 | " Stop visual mode when keymodel=stopsel |
| 111 | set keymodel=stopsel |
| 112 | 50 |
| 113 | call feedkeys("Vkk\<Up>yy", 'tx') |
| 114 | call assert_equal(['47'], getreg(0, 0, 1)) |
| 115 | |
| 116 | set keymodel= |
| 117 | 50 |
| 118 | call feedkeys("Vkk\<Up>yy", 'tx') |
| 119 | call assert_equal(['47', '48', '49', '50'], getreg(0, 0, 1)) |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 120 | |
| 121 | " clean up |
| 122 | bw! |
| 123 | endfunc |
| 124 | |
Bram Moolenaar | 1bbb619 | 2018-11-10 16:02:01 +0100 | [diff] [blame] | 125 | func Test_normal03_join() |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 126 | " basic join test |
| 127 | call Setup_NewWindow() |
| 128 | 50 |
| 129 | norm! VJ |
| 130 | call assert_equal('50 51', getline('.')) |
| 131 | $ |
| 132 | norm! J |
| 133 | call assert_equal('100', getline('.')) |
| 134 | $ |
| 135 | norm! V9-gJ |
| 136 | call assert_equal('919293949596979899100', getline('.')) |
| 137 | call setline(1, range(1,100)) |
| 138 | $ |
| 139 | :j 10 |
| 140 | call assert_equal('100', getline('.')) |
| 141 | " clean up |
| 142 | bw! |
Bram Moolenaar | 2931f2a | 2016-09-09 16:59:08 +0200 | [diff] [blame] | 143 | endfunc |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 144 | |
Bram Moolenaar | 1bbb619 | 2018-11-10 16:02:01 +0100 | [diff] [blame] | 145 | func Test_normal04_filter() |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 146 | " basic filter test |
| 147 | " only test on non windows platform |
Bram Moolenaar | 4a08b0d | 2016-11-05 21:55:13 +0100 | [diff] [blame] | 148 | if has('win32') |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 149 | return |
| 150 | endif |
| 151 | call Setup_NewWindow() |
| 152 | 1 |
| 153 | call feedkeys("!!sed -e 's/^/| /'\n", 'tx') |
| 154 | call assert_equal('| 1', getline('.')) |
| 155 | 90 |
| 156 | :sil :!echo one |
| 157 | call feedkeys('.', 'tx') |
| 158 | call assert_equal('| 90', getline('.')) |
| 159 | 95 |
| 160 | set cpo+=! |
| 161 | " 2 <CR>, 1: for executing the command, |
| 162 | " 2: clear hit-enter-prompt |
| 163 | call feedkeys("!!\n", 'tx') |
| 164 | call feedkeys(":!echo one\n\n", 'tx') |
| 165 | call feedkeys(".", 'tx') |
| 166 | call assert_equal('one', getline('.')) |
| 167 | set cpo-=! |
| 168 | bw! |
Bram Moolenaar | 2931f2a | 2016-09-09 16:59:08 +0200 | [diff] [blame] | 169 | endfunc |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 170 | |
Bram Moolenaar | 1bbb619 | 2018-11-10 16:02:01 +0100 | [diff] [blame] | 171 | func Test_normal05_formatexpr() |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 172 | " basic formatexpr test |
| 173 | call Setup_NewWindow() |
| 174 | %d_ |
| 175 | call setline(1, ['here: 1 ', '2', 'here: 3 ', '4', 'not here: ']) |
| 176 | 1 |
| 177 | set formatexpr=MyFormatExpr() |
| 178 | norm! gqG |
| 179 | call assert_equal(['here: 1->$', '2', 'here: 3->$', '4', 'not here: '], getline(1,'$')) |
| 180 | set formatexpr= |
| 181 | bw! |
Bram Moolenaar | 2931f2a | 2016-09-09 16:59:08 +0200 | [diff] [blame] | 182 | endfunc |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 183 | |
Bram Moolenaar | d77f9d5 | 2016-09-04 15:13:39 +0200 | [diff] [blame] | 184 | func Test_normal05_formatexpr_newbuf() |
| 185 | " Edit another buffer in the 'formatexpr' function |
| 186 | new |
| 187 | func! Format() |
| 188 | edit another |
| 189 | endfunc |
| 190 | set formatexpr=Format() |
| 191 | norm gqG |
| 192 | bw! |
| 193 | set formatexpr= |
| 194 | endfunc |
| 195 | |
| 196 | func Test_normal05_formatexpr_setopt() |
| 197 | " Change the 'formatexpr' value in the function |
| 198 | new |
| 199 | func! Format() |
| 200 | set formatexpr= |
| 201 | endfunc |
| 202 | set formatexpr=Format() |
| 203 | norm gqG |
| 204 | bw! |
| 205 | set formatexpr= |
| 206 | endfunc |
| 207 | |
Bram Moolenaar | 1bbb619 | 2018-11-10 16:02:01 +0100 | [diff] [blame] | 208 | func Test_normal06_formatprg() |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 209 | " basic test for formatprg |
| 210 | " only test on non windows platform |
Bram Moolenaar | 4a08b0d | 2016-11-05 21:55:13 +0100 | [diff] [blame] | 211 | if has('win32') |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 212 | return |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 213 | endif |
Bram Moolenaar | 9be7c04 | 2017-01-14 14:28:30 +0100 | [diff] [blame] | 214 | |
| 215 | " uses sed to number non-empty lines |
| 216 | call writefile(['#!/bin/sh', 'sed ''/./=''|sed ''/./{', 'N', 's/\n/ /', '}'''], 'Xsed_format.sh') |
| 217 | call system('chmod +x ./Xsed_format.sh') |
| 218 | let text = ['a', '', 'c', '', ' ', 'd', 'e'] |
| 219 | let expected = ['1 a', '', '3 c', '', '5 ', '6 d', '7 e'] |
| 220 | |
| 221 | 10new |
| 222 | call setline(1, text) |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 223 | set formatprg=./Xsed_format.sh |
| 224 | norm! gggqG |
Bram Moolenaar | 9be7c04 | 2017-01-14 14:28:30 +0100 | [diff] [blame] | 225 | call assert_equal(expected, getline(1, '$')) |
| 226 | bw! |
| 227 | |
| 228 | 10new |
| 229 | call setline(1, text) |
| 230 | set formatprg=donothing |
| 231 | setlocal formatprg=./Xsed_format.sh |
| 232 | norm! gggqG |
| 233 | call assert_equal(expected, getline(1, '$')) |
| 234 | bw! |
| 235 | |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 236 | " clean up |
| 237 | set formatprg= |
Bram Moolenaar | 9be7c04 | 2017-01-14 14:28:30 +0100 | [diff] [blame] | 238 | setlocal formatprg= |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 239 | call delete('Xsed_format.sh') |
Bram Moolenaar | 2931f2a | 2016-09-09 16:59:08 +0200 | [diff] [blame] | 240 | endfunc |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 241 | |
Bram Moolenaar | 1bbb619 | 2018-11-10 16:02:01 +0100 | [diff] [blame] | 242 | func Test_normal07_internalfmt() |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 243 | " basic test for internal formmatter to textwidth of 12 |
| 244 | let list=range(1,11) |
| 245 | call map(list, 'v:val." "') |
| 246 | 10new |
| 247 | call setline(1, list) |
| 248 | set tw=12 |
| 249 | norm! gggqG |
| 250 | call assert_equal(['1 2 3', '4 5 6', '7 8 9', '10 11 '], getline(1, '$')) |
| 251 | " clean up |
Bram Moolenaar | 9be7c04 | 2017-01-14 14:28:30 +0100 | [diff] [blame] | 252 | set tw=0 |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 253 | bw! |
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 | |
Bram Moolenaar | 1bbb619 | 2018-11-10 16:02:01 +0100 | [diff] [blame] | 256 | func Test_normal08_fold() |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 257 | " basic tests for foldopen/folddelete |
| 258 | if !has("folding") |
| 259 | return |
| 260 | endif |
| 261 | call Setup_NewWindow() |
| 262 | 50 |
| 263 | setl foldenable fdm=marker |
| 264 | " First fold |
| 265 | norm! V4jzf |
| 266 | " check that folds have been created |
| 267 | call assert_equal(['50/*{{{*/', '51', '52', '53', '54/*}}}*/'], getline(50,54)) |
| 268 | " Second fold |
| 269 | 46 |
| 270 | norm! V10jzf |
| 271 | " check that folds have been created |
| 272 | call assert_equal('46/*{{{*/', getline(46)) |
| 273 | call assert_equal('60/*}}}*/', getline(60)) |
| 274 | norm! k |
| 275 | call assert_equal('45', getline('.')) |
| 276 | norm! j |
| 277 | call assert_equal('46/*{{{*/', getline('.')) |
| 278 | norm! j |
| 279 | call assert_equal('61', getline('.')) |
| 280 | norm! k |
| 281 | " open a fold |
| 282 | norm! Vzo |
| 283 | norm! k |
| 284 | call assert_equal('45', getline('.')) |
| 285 | norm! j |
| 286 | call assert_equal('46/*{{{*/', getline('.')) |
| 287 | norm! j |
| 288 | call assert_equal('47', getline('.')) |
| 289 | norm! k |
| 290 | norm! zcVzO |
| 291 | call assert_equal('46/*{{{*/', getline('.')) |
| 292 | norm! j |
| 293 | call assert_equal('47', getline('.')) |
| 294 | norm! j |
| 295 | call assert_equal('48', getline('.')) |
| 296 | norm! j |
| 297 | call assert_equal('49', getline('.')) |
| 298 | norm! j |
| 299 | call assert_equal('50/*{{{*/', getline('.')) |
| 300 | norm! j |
| 301 | call assert_equal('51', getline('.')) |
| 302 | " delete folds |
| 303 | :46 |
| 304 | " collapse fold |
| 305 | norm! V14jzC |
| 306 | " delete all folds recursively |
| 307 | norm! VzD |
| 308 | call assert_equal(['46', '47', '48', '49', '50', '51', '52', '53', '54', '55', '56', '57', '58', '59', '60'], getline(46,60)) |
| 309 | |
| 310 | " clean up |
| 311 | setl nofoldenable fdm=marker |
| 312 | bw! |
Bram Moolenaar | 2931f2a | 2016-09-09 16:59:08 +0200 | [diff] [blame] | 313 | endfunc |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 314 | |
Bram Moolenaar | 1bbb619 | 2018-11-10 16:02:01 +0100 | [diff] [blame] | 315 | func Test_normal09_operatorfunc() |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 316 | " Test operatorfunc |
| 317 | call Setup_NewWindow() |
| 318 | " Add some spaces for counting |
| 319 | 50,60s/$/ / |
| 320 | unlet! g:a |
| 321 | let g:a=0 |
| 322 | nmap <buffer><silent> ,, :set opfunc=CountSpaces<CR>g@ |
| 323 | vmap <buffer><silent> ,, :<C-U>call CountSpaces(visualmode(), 1)<CR> |
| 324 | 50 |
| 325 | norm V2j,, |
| 326 | call assert_equal(6, g:a) |
| 327 | norm V,, |
| 328 | call assert_equal(2, g:a) |
| 329 | norm ,,l |
| 330 | call assert_equal(0, g:a) |
| 331 | 50 |
| 332 | exe "norm 0\<c-v>10j2l,," |
| 333 | call assert_equal(11, g:a) |
| 334 | 50 |
| 335 | norm V10j,, |
| 336 | call assert_equal(22, g:a) |
| 337 | |
| 338 | " clean up |
| 339 | unmap <buffer> ,, |
| 340 | set opfunc= |
Bram Moolenaar | 4a08b0d | 2016-11-05 21:55:13 +0100 | [diff] [blame] | 341 | unlet! g:a |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 342 | bw! |
Bram Moolenaar | 2931f2a | 2016-09-09 16:59:08 +0200 | [diff] [blame] | 343 | endfunc |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 344 | |
Bram Moolenaar | 1bbb619 | 2018-11-10 16:02:01 +0100 | [diff] [blame] | 345 | func Test_normal09a_operatorfunc() |
Bram Moolenaar | 4a08b0d | 2016-11-05 21:55:13 +0100 | [diff] [blame] | 346 | " Test operatorfunc |
| 347 | call Setup_NewWindow() |
| 348 | " Add some spaces for counting |
| 349 | 50,60s/$/ / |
| 350 | unlet! g:opt |
| 351 | set linebreak |
| 352 | nmap <buffer><silent> ,, :set opfunc=OpfuncDummy<CR>g@ |
| 353 | 50 |
| 354 | norm ,,j |
| 355 | exe "bd!" g:bufnr |
| 356 | call assert_true(&linebreak) |
| 357 | call assert_equal(g:opt, &linebreak) |
| 358 | set nolinebreak |
| 359 | norm ,,j |
| 360 | exe "bd!" g:bufnr |
| 361 | call assert_false(&linebreak) |
| 362 | call assert_equal(g:opt, &linebreak) |
| 363 | |
| 364 | " clean up |
| 365 | unmap <buffer> ,, |
| 366 | set opfunc= |
| 367 | bw! |
| 368 | unlet! g:opt |
| 369 | endfunc |
| 370 | |
Bram Moolenaar | 1bbb619 | 2018-11-10 16:02:01 +0100 | [diff] [blame] | 371 | func Test_normal10_expand() |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 372 | " Test for expand() |
| 373 | 10new |
| 374 | call setline(1, ['1', 'ifooar,,cbar']) |
| 375 | 2 |
| 376 | norm! $ |
Bram Moolenaar | 65f0847 | 2017-09-10 18:16:20 +0200 | [diff] [blame] | 377 | call assert_equal('cbar', expand('<cword>')) |
| 378 | call assert_equal('ifooar,,cbar', expand('<cWORD>')) |
| 379 | |
| 380 | call setline(1, ['prx = list[idx];']) |
| 381 | 1 |
| 382 | let expected = ['', 'prx', 'prx', 'prx', |
| 383 | \ 'list', 'list', 'list', 'list', 'list', 'list', 'list', |
| 384 | \ 'idx', 'idx', 'idx', 'idx', |
| 385 | \ 'list[idx]', |
| 386 | \ '];', |
| 387 | \ ] |
| 388 | for i in range(1, 16) |
| 389 | exe 'norm ' . i . '|' |
| 390 | call assert_equal(expected[i], expand('<cexpr>'), 'i == ' . i) |
| 391 | endfor |
| 392 | |
Bram Moolenaar | ae6f865 | 2017-12-20 22:32:20 +0100 | [diff] [blame] | 393 | if executable('echo') |
| 394 | " Test expand(`...`) i.e. backticks command expansion. |
Bram Moolenaar | 077ff43 | 2019-10-28 00:42:21 +0100 | [diff] [blame] | 395 | call assert_equal('abcde', expand('`echo abcde`')) |
Bram Moolenaar | ae6f865 | 2017-12-20 22:32:20 +0100 | [diff] [blame] | 396 | endif |
| 397 | |
| 398 | " Test expand(`=...`) i.e. backticks expression expansion |
| 399 | call assert_equal('5', expand('`=2+3`')) |
Bram Moolenaar | 8b63313 | 2020-03-20 18:20:51 +0100 | [diff] [blame] | 400 | call assert_equal('3.14', expand('`=3.14`')) |
Bram Moolenaar | ae6f865 | 2017-12-20 22:32:20 +0100 | [diff] [blame] | 401 | |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 402 | " clean up |
| 403 | bw! |
Bram Moolenaar | 2931f2a | 2016-09-09 16:59:08 +0200 | [diff] [blame] | 404 | endfunc |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 405 | |
Bram Moolenaar | 1bbb619 | 2018-11-10 16:02:01 +0100 | [diff] [blame] | 406 | func Test_normal11_showcmd() |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 407 | " test for 'showcmd' |
| 408 | 10new |
| 409 | exe "norm! ofoobar\<esc>" |
| 410 | call assert_equal(2, line('$')) |
| 411 | set showcmd |
| 412 | exe "norm! ofoobar2\<esc>" |
| 413 | call assert_equal(3, line('$')) |
| 414 | exe "norm! VAfoobar3\<esc>" |
| 415 | call assert_equal(3, line('$')) |
| 416 | exe "norm! 0d3\<del>2l" |
| 417 | call assert_equal('obar2foobar3', getline('.')) |
| 418 | bw! |
Bram Moolenaar | 2931f2a | 2016-09-09 16:59:08 +0200 | [diff] [blame] | 419 | endfunc |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 420 | |
Bram Moolenaar | 1671f44 | 2020-03-10 07:48:13 +0100 | [diff] [blame] | 421 | " Test for nv_error and normal command errors |
Bram Moolenaar | 1bbb619 | 2018-11-10 16:02:01 +0100 | [diff] [blame] | 422 | func Test_normal12_nv_error() |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 423 | 10new |
| 424 | call setline(1, range(1,5)) |
| 425 | " should not do anything, just beep |
Bram Moolenaar | f5f1e10 | 2020-03-08 05:13:15 +0100 | [diff] [blame] | 426 | call assert_beeps('exe "norm! <c-k>"') |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 427 | call assert_equal(map(range(1,5), 'string(v:val)'), getline(1,'$')) |
Bram Moolenaar | f5f1e10 | 2020-03-08 05:13:15 +0100 | [diff] [blame] | 428 | call assert_beeps('normal! G2dd') |
| 429 | call assert_beeps("normal! g\<C-A>") |
| 430 | call assert_beeps("normal! g\<C-X>") |
| 431 | call assert_beeps("normal! g\<C-B>") |
Bram Moolenaar | 1671f44 | 2020-03-10 07:48:13 +0100 | [diff] [blame] | 432 | call assert_beeps("normal! vQ\<Esc>") |
| 433 | call assert_beeps("normal! 2[[") |
| 434 | call assert_beeps("normal! 2]]") |
| 435 | call assert_beeps("normal! 2[]") |
| 436 | call assert_beeps("normal! 2][") |
| 437 | call assert_beeps("normal! 4[z") |
| 438 | call assert_beeps("normal! 4]z") |
| 439 | call assert_beeps("normal! 4[c") |
| 440 | call assert_beeps("normal! 4]c") |
| 441 | call assert_beeps("normal! 200%") |
| 442 | call assert_beeps("normal! %") |
| 443 | call assert_beeps("normal! 2{") |
| 444 | call assert_beeps("normal! 2}") |
| 445 | call assert_beeps("normal! r\<Right>") |
| 446 | call assert_beeps("normal! 8ry") |
| 447 | call assert_beeps('normal! "@') |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 448 | bw! |
Bram Moolenaar | 2931f2a | 2016-09-09 16:59:08 +0200 | [diff] [blame] | 449 | endfunc |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 450 | |
Bram Moolenaar | 1bbb619 | 2018-11-10 16:02:01 +0100 | [diff] [blame] | 451 | func Test_normal13_help() |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 452 | " Test for F1 |
| 453 | call assert_equal(1, winnr()) |
| 454 | call feedkeys("\<f1>", 'txi') |
| 455 | call assert_match('help\.txt', bufname('%')) |
| 456 | call assert_equal(2, winnr('$')) |
| 457 | bw! |
Bram Moolenaar | 2931f2a | 2016-09-09 16:59:08 +0200 | [diff] [blame] | 458 | endfunc |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 459 | |
Bram Moolenaar | 1bbb619 | 2018-11-10 16:02:01 +0100 | [diff] [blame] | 460 | func Test_normal14_page() |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 461 | " basic test for Ctrl-F and Ctrl-B |
| 462 | call Setup_NewWindow() |
| 463 | exe "norm! \<c-f>" |
| 464 | call assert_equal('9', getline('.')) |
| 465 | exe "norm! 2\<c-f>" |
| 466 | call assert_equal('25', getline('.')) |
| 467 | exe "norm! 2\<c-b>" |
| 468 | call assert_equal('18', getline('.')) |
| 469 | 1 |
| 470 | set scrolloff=5 |
| 471 | exe "norm! 2\<c-f>" |
| 472 | call assert_equal('21', getline('.')) |
| 473 | exe "norm! \<c-b>" |
| 474 | call assert_equal('13', getline('.')) |
| 475 | 1 |
| 476 | set scrolloff=99 |
| 477 | exe "norm! \<c-f>" |
| 478 | call assert_equal('13', getline('.')) |
| 479 | set scrolloff=0 |
| 480 | 100 |
| 481 | exe "norm! $\<c-b>" |
| 482 | call assert_equal('92', getline('.')) |
| 483 | call assert_equal([0, 92, 1, 0, 1], getcurpos()) |
| 484 | 100 |
| 485 | set nostartofline |
| 486 | exe "norm! $\<c-b>" |
| 487 | call assert_equal('92', getline('.')) |
| 488 | call assert_equal([0, 92, 2, 0, 2147483647], getcurpos()) |
| 489 | " cleanup |
| 490 | set startofline |
| 491 | bw! |
Bram Moolenaar | 2931f2a | 2016-09-09 16:59:08 +0200 | [diff] [blame] | 492 | endfunc |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 493 | |
Bram Moolenaar | 1bbb619 | 2018-11-10 16:02:01 +0100 | [diff] [blame] | 494 | func Test_normal14_page_eol() |
Bram Moolenaar | bc54f3f | 2016-09-04 14:34:28 +0200 | [diff] [blame] | 495 | 10new |
| 496 | norm oxxxxxxx |
| 497 | exe "norm 2\<c-f>" |
| 498 | " check with valgrind that cursor is put back in column 1 |
| 499 | exe "norm 2\<c-b>" |
| 500 | bw! |
| 501 | endfunc |
| 502 | |
Bram Moolenaar | 1671f44 | 2020-03-10 07:48:13 +0100 | [diff] [blame] | 503 | " Test for errors with z command |
| 504 | func Test_normal_z_error() |
| 505 | call assert_beeps('normal! z2p') |
| 506 | call assert_beeps('normal! zp') |
| 507 | endfunc |
| 508 | |
Bram Moolenaar | 1bbb619 | 2018-11-10 16:02:01 +0100 | [diff] [blame] | 509 | func Test_normal15_z_scroll_vert() |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 510 | " basic test for z commands that scroll the window |
| 511 | call Setup_NewWindow() |
| 512 | 100 |
| 513 | norm! >> |
| 514 | " Test for z<cr> |
| 515 | exe "norm! z\<cr>" |
| 516 | call assert_equal(' 100', getline('.')) |
| 517 | call assert_equal(100, winsaveview()['topline']) |
| 518 | call assert_equal([0, 100, 2, 0, 9], getcurpos()) |
| 519 | |
| 520 | " Test for zt |
| 521 | 21 |
| 522 | norm! >>0zt |
| 523 | call assert_equal(' 21', getline('.')) |
| 524 | call assert_equal(21, winsaveview()['topline']) |
| 525 | call assert_equal([0, 21, 1, 0, 8], getcurpos()) |
| 526 | |
| 527 | " Test for zb |
| 528 | 30 |
| 529 | norm! >>$ztzb |
| 530 | call assert_equal(' 30', getline('.')) |
| 531 | call assert_equal(30, winsaveview()['topline']+winheight(0)-1) |
| 532 | call assert_equal([0, 30, 3, 0, 2147483647], getcurpos()) |
| 533 | |
| 534 | " Test for z- |
| 535 | 1 |
| 536 | 30 |
| 537 | norm! 0z- |
| 538 | call assert_equal(' 30', getline('.')) |
| 539 | call assert_equal(30, winsaveview()['topline']+winheight(0)-1) |
| 540 | call assert_equal([0, 30, 2, 0, 9], getcurpos()) |
| 541 | |
| 542 | " Test for z{height}<cr> |
| 543 | call assert_equal(10, winheight(0)) |
| 544 | exe "norm! z12\<cr>" |
| 545 | call assert_equal(12, winheight(0)) |
| 546 | exe "norm! z10\<cr>" |
| 547 | call assert_equal(10, winheight(0)) |
| 548 | |
| 549 | " Test for z. |
| 550 | 1 |
| 551 | 21 |
| 552 | norm! 0z. |
| 553 | call assert_equal(' 21', getline('.')) |
| 554 | call assert_equal(17, winsaveview()['topline']) |
| 555 | call assert_equal([0, 21, 2, 0, 9], getcurpos()) |
| 556 | |
| 557 | " Test for zz |
| 558 | 1 |
| 559 | 21 |
| 560 | norm! 0zz |
| 561 | call assert_equal(' 21', getline('.')) |
| 562 | call assert_equal(17, winsaveview()['topline']) |
| 563 | call assert_equal([0, 21, 1, 0, 8], getcurpos()) |
| 564 | |
| 565 | " Test for z+ |
| 566 | 11 |
| 567 | norm! zt |
| 568 | norm! z+ |
| 569 | call assert_equal(' 21', getline('.')) |
| 570 | call assert_equal(21, winsaveview()['topline']) |
| 571 | call assert_equal([0, 21, 2, 0, 9], getcurpos()) |
| 572 | |
| 573 | " Test for [count]z+ |
| 574 | 1 |
| 575 | norm! 21z+ |
| 576 | call assert_equal(' 21', getline('.')) |
| 577 | call assert_equal(21, winsaveview()['topline']) |
| 578 | call assert_equal([0, 21, 2, 0, 9], getcurpos()) |
| 579 | |
| 580 | " Test for z^ |
| 581 | norm! 22z+0 |
| 582 | norm! z^ |
| 583 | call assert_equal(' 21', getline('.')) |
| 584 | call assert_equal(12, winsaveview()['topline']) |
| 585 | call assert_equal([0, 21, 2, 0, 9], getcurpos()) |
| 586 | |
| 587 | " Test for [count]z^ |
| 588 | 1 |
| 589 | norm! 30z^ |
| 590 | call assert_equal(' 21', getline('.')) |
| 591 | call assert_equal(12, winsaveview()['topline']) |
| 592 | call assert_equal([0, 21, 2, 0, 9], getcurpos()) |
| 593 | |
| 594 | " cleanup |
| 595 | bw! |
Bram Moolenaar | 2931f2a | 2016-09-09 16:59:08 +0200 | [diff] [blame] | 596 | endfunc |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 597 | |
Bram Moolenaar | 1bbb619 | 2018-11-10 16:02:01 +0100 | [diff] [blame] | 598 | func Test_normal16_z_scroll_hor() |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 599 | " basic test for z commands that scroll the window |
| 600 | 10new |
| 601 | 15vsp |
| 602 | set nowrap listchars= |
| 603 | let lineA='abcdefghijklmnopqrstuvwxyz' |
| 604 | let lineB='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ' |
| 605 | $put =lineA |
| 606 | $put =lineB |
| 607 | 1d |
| 608 | |
Bram Moolenaar | 1671f44 | 2020-03-10 07:48:13 +0100 | [diff] [blame] | 609 | " Test for zl and zh with a count |
| 610 | norm! 0z10l |
| 611 | call assert_equal([11, 1], [col('.'), wincol()]) |
| 612 | norm! z4h |
| 613 | call assert_equal([11, 5], [col('.'), wincol()]) |
| 614 | normal! 2gg |
| 615 | |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 616 | " Test for zl |
| 617 | 1 |
| 618 | norm! 5zl |
| 619 | call assert_equal(lineA, getline('.')) |
| 620 | call assert_equal(6, col('.')) |
| 621 | call assert_equal(5, winsaveview()['leftcol']) |
| 622 | norm! yl |
| 623 | call assert_equal('f', @0) |
| 624 | |
| 625 | " Test for zh |
| 626 | norm! 2zh |
| 627 | call assert_equal(lineA, getline('.')) |
| 628 | call assert_equal(6, col('.')) |
| 629 | norm! yl |
| 630 | call assert_equal('f', @0) |
| 631 | call assert_equal(3, winsaveview()['leftcol']) |
| 632 | |
| 633 | " Test for zL |
| 634 | norm! zL |
| 635 | call assert_equal(11, col('.')) |
| 636 | norm! yl |
| 637 | call assert_equal('k', @0) |
| 638 | call assert_equal(10, winsaveview()['leftcol']) |
| 639 | norm! 2zL |
| 640 | call assert_equal(25, col('.')) |
| 641 | norm! yl |
| 642 | call assert_equal('y', @0) |
| 643 | call assert_equal(24, winsaveview()['leftcol']) |
| 644 | |
| 645 | " Test for zH |
| 646 | norm! 2zH |
| 647 | call assert_equal(25, col('.')) |
| 648 | call assert_equal(10, winsaveview()['leftcol']) |
| 649 | norm! yl |
| 650 | call assert_equal('y', @0) |
| 651 | |
| 652 | " Test for zs |
| 653 | norm! $zs |
| 654 | call assert_equal(26, col('.')) |
| 655 | call assert_equal(25, winsaveview()['leftcol']) |
| 656 | norm! yl |
| 657 | call assert_equal('z', @0) |
| 658 | |
| 659 | " Test for ze |
| 660 | norm! ze |
| 661 | call assert_equal(26, col('.')) |
| 662 | call assert_equal(11, winsaveview()['leftcol']) |
| 663 | norm! yl |
| 664 | call assert_equal('z', @0) |
| 665 | |
| 666 | " cleanup |
| 667 | set wrap listchars=eol:$ |
| 668 | bw! |
Bram Moolenaar | 2931f2a | 2016-09-09 16:59:08 +0200 | [diff] [blame] | 669 | endfunc |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 670 | |
Bram Moolenaar | 1bbb619 | 2018-11-10 16:02:01 +0100 | [diff] [blame] | 671 | func Test_normal17_z_scroll_hor2() |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 672 | " basic test for z commands that scroll the window |
| 673 | " using 'sidescrolloff' setting |
| 674 | 10new |
| 675 | 20vsp |
| 676 | set nowrap listchars= sidescrolloff=5 |
| 677 | let lineA='abcdefghijklmnopqrstuvwxyz' |
| 678 | let lineB='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ' |
| 679 | $put =lineA |
| 680 | $put =lineB |
| 681 | 1d |
| 682 | |
| 683 | " Test for zl |
| 684 | 1 |
| 685 | norm! 5zl |
| 686 | call assert_equal(lineA, getline('.')) |
| 687 | call assert_equal(11, col('.')) |
| 688 | call assert_equal(5, winsaveview()['leftcol']) |
| 689 | norm! yl |
| 690 | call assert_equal('k', @0) |
| 691 | |
| 692 | " Test for zh |
| 693 | norm! 2zh |
| 694 | call assert_equal(lineA, getline('.')) |
| 695 | call assert_equal(11, col('.')) |
| 696 | norm! yl |
| 697 | call assert_equal('k', @0) |
| 698 | call assert_equal(3, winsaveview()['leftcol']) |
| 699 | |
| 700 | " Test for zL |
| 701 | norm! 0zL |
| 702 | call assert_equal(16, col('.')) |
| 703 | norm! yl |
| 704 | call assert_equal('p', @0) |
| 705 | call assert_equal(10, winsaveview()['leftcol']) |
| 706 | norm! 2zL |
| 707 | call assert_equal(26, col('.')) |
| 708 | norm! yl |
| 709 | call assert_equal('z', @0) |
| 710 | call assert_equal(15, winsaveview()['leftcol']) |
| 711 | |
| 712 | " Test for zH |
| 713 | norm! 2zH |
| 714 | call assert_equal(15, col('.')) |
| 715 | call assert_equal(0, winsaveview()['leftcol']) |
| 716 | norm! yl |
| 717 | call assert_equal('o', @0) |
| 718 | |
| 719 | " Test for zs |
| 720 | norm! $zs |
| 721 | call assert_equal(26, col('.')) |
| 722 | call assert_equal(20, winsaveview()['leftcol']) |
| 723 | norm! yl |
| 724 | call assert_equal('z', @0) |
| 725 | |
| 726 | " Test for ze |
| 727 | norm! ze |
| 728 | call assert_equal(26, col('.')) |
| 729 | call assert_equal(11, winsaveview()['leftcol']) |
| 730 | norm! yl |
| 731 | call assert_equal('z', @0) |
| 732 | |
| 733 | " cleanup |
| 734 | set wrap listchars=eol:$ sidescrolloff=0 |
| 735 | bw! |
Bram Moolenaar | 2931f2a | 2016-09-09 16:59:08 +0200 | [diff] [blame] | 736 | endfunc |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 737 | |
Bram Moolenaar | 1671f44 | 2020-03-10 07:48:13 +0100 | [diff] [blame] | 738 | " Test for H, M and L commands with folds |
| 739 | func Test_scroll_cmds() |
| 740 | 15new |
| 741 | call setline(1, range(1, 100)) |
| 742 | exe "normal! 30ggz\<CR>" |
| 743 | set foldenable |
| 744 | 33,36fold |
| 745 | 40,43fold |
| 746 | 46,49fold |
| 747 | let h = winheight(0) |
| 748 | " Top of the screen = 30 |
| 749 | " Folded lines = 9 |
| 750 | " Bottom of the screen = 30 + h + 9 - 1 |
| 751 | normal! 4L |
| 752 | call assert_equal(35 + h, line('.')) |
| 753 | normal! 4H |
| 754 | call assert_equal(33, line('.')) |
| 755 | set foldenable& |
| 756 | close! |
| 757 | endfunc |
| 758 | |
Bram Moolenaar | 1bbb619 | 2018-11-10 16:02:01 +0100 | [diff] [blame] | 759 | func Test_normal18_z_fold() |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 760 | " basic tests for foldopen/folddelete |
| 761 | if !has("folding") |
| 762 | return |
| 763 | endif |
| 764 | call Setup_NewWindow() |
| 765 | 50 |
| 766 | setl foldenable fdm=marker foldlevel=5 |
| 767 | |
Bram Moolenaar | 1671f44 | 2020-03-10 07:48:13 +0100 | [diff] [blame] | 768 | call assert_beeps('normal! zj') |
| 769 | call assert_beeps('normal! zk') |
| 770 | |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 771 | " Test for zF |
| 772 | " First fold |
| 773 | norm! 4zF |
| 774 | " check that folds have been created |
| 775 | call assert_equal(['50/*{{{*/', '51', '52', '53/*}}}*/'], getline(50,53)) |
| 776 | |
| 777 | " Test for zd |
| 778 | 51 |
| 779 | norm! 2zF |
| 780 | call assert_equal(2, foldlevel('.')) |
| 781 | norm! kzd |
| 782 | call assert_equal(['50', '51/*{{{*/', '52/*}}}*/', '53'], getline(50,53)) |
| 783 | norm! j |
| 784 | call assert_equal(1, foldlevel('.')) |
| 785 | |
| 786 | " Test for zD |
| 787 | " also deletes partially selected folds recursively |
| 788 | 51 |
| 789 | norm! zF |
| 790 | call assert_equal(2, foldlevel('.')) |
| 791 | norm! kV2jzD |
| 792 | call assert_equal(['50', '51', '52', '53'], getline(50,53)) |
| 793 | |
| 794 | " Test for zE |
| 795 | 85 |
| 796 | norm! 4zF |
| 797 | 86 |
| 798 | norm! 2zF |
| 799 | 90 |
| 800 | norm! 4zF |
| 801 | call assert_equal(['85/*{{{*/', '86/*{{{*/', '87/*}}}*/', '88/*}}}*/', '89', '90/*{{{*/', '91', '92', '93/*}}}*/'], getline(85,93)) |
| 802 | norm! zE |
| 803 | call assert_equal(['85', '86', '87', '88', '89', '90', '91', '92', '93'], getline(85,93)) |
| 804 | |
| 805 | " Test for zn |
| 806 | 50 |
| 807 | set foldlevel=0 |
| 808 | norm! 2zF |
| 809 | norm! zn |
| 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('51/*}}}*/', getline('.')) |
| 816 | norm! j |
| 817 | call assert_equal('52', getline('.')) |
| 818 | call assert_equal(0, &foldenable) |
| 819 | |
| 820 | " Test for zN |
| 821 | 49 |
| 822 | norm! zN |
| 823 | call assert_equal('49', getline('.')) |
| 824 | norm! j |
| 825 | call assert_equal('50/*{{{*/', getline('.')) |
| 826 | norm! j |
| 827 | call assert_equal('52', getline('.')) |
| 828 | call assert_equal(1, &foldenable) |
| 829 | |
| 830 | " Test for zi |
| 831 | norm! zi |
| 832 | call assert_equal(0, &foldenable) |
| 833 | norm! zi |
| 834 | call assert_equal(1, &foldenable) |
| 835 | norm! zi |
| 836 | call assert_equal(0, &foldenable) |
| 837 | norm! zi |
| 838 | call assert_equal(1, &foldenable) |
| 839 | |
| 840 | " Test for za |
| 841 | 50 |
| 842 | norm! za |
| 843 | norm! k |
| 844 | call assert_equal('49', getline('.')) |
| 845 | norm! j |
| 846 | call assert_equal('50/*{{{*/', getline('.')) |
| 847 | norm! j |
| 848 | call assert_equal('51/*}}}*/', getline('.')) |
| 849 | norm! j |
| 850 | call assert_equal('52', getline('.')) |
| 851 | 50 |
| 852 | norm! za |
| 853 | norm! k |
| 854 | call assert_equal('49', getline('.')) |
| 855 | norm! j |
| 856 | call assert_equal('50/*{{{*/', getline('.')) |
| 857 | norm! j |
| 858 | call assert_equal('52', getline('.')) |
| 859 | |
| 860 | 49 |
| 861 | norm! 5zF |
| 862 | norm! k |
| 863 | call assert_equal('48', getline('.')) |
| 864 | norm! j |
| 865 | call assert_equal('49/*{{{*/', getline('.')) |
| 866 | norm! j |
| 867 | call assert_equal('55', getline('.')) |
| 868 | 49 |
| 869 | norm! za |
| 870 | call assert_equal('49/*{{{*/', getline('.')) |
| 871 | norm! j |
| 872 | call assert_equal('50/*{{{*/', getline('.')) |
| 873 | norm! j |
| 874 | call assert_equal('52', getline('.')) |
| 875 | set nofoldenable |
| 876 | " close fold and set foldenable |
| 877 | norm! za |
| 878 | call assert_equal(1, &foldenable) |
| 879 | |
| 880 | 50 |
| 881 | " have to use {count}za to open all folds and make the cursor visible |
| 882 | norm! 2za |
| 883 | norm! 2k |
| 884 | call assert_equal('48', getline('.')) |
| 885 | norm! j |
| 886 | call assert_equal('49/*{{{*/', getline('.')) |
| 887 | norm! j |
| 888 | call assert_equal('50/*{{{*/', getline('.')) |
| 889 | norm! j |
| 890 | call assert_equal('51/*}}}*/', getline('.')) |
| 891 | norm! j |
| 892 | call assert_equal('52', getline('.')) |
| 893 | |
| 894 | " Test for zA |
| 895 | 49 |
| 896 | set foldlevel=0 |
| 897 | 50 |
| 898 | norm! zA |
| 899 | norm! 2k |
| 900 | call assert_equal('48', getline('.')) |
| 901 | norm! j |
| 902 | call assert_equal('49/*{{{*/', getline('.')) |
| 903 | norm! j |
| 904 | call assert_equal('50/*{{{*/', getline('.')) |
| 905 | norm! j |
| 906 | call assert_equal('51/*}}}*/', getline('.')) |
| 907 | norm! j |
| 908 | call assert_equal('52', getline('.')) |
| 909 | |
Bram Moolenaar | 395b6ba | 2017-04-07 20:09:51 +0200 | [diff] [blame] | 910 | " zA on a opened fold when foldenable is not set |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 911 | 50 |
| 912 | set nofoldenable |
| 913 | norm! zA |
| 914 | call assert_equal(1, &foldenable) |
| 915 | norm! k |
| 916 | call assert_equal('48', getline('.')) |
| 917 | norm! j |
| 918 | call assert_equal('49/*{{{*/', getline('.')) |
| 919 | norm! j |
| 920 | call assert_equal('55', getline('.')) |
| 921 | |
| 922 | " Test for zc |
| 923 | norm! zE |
| 924 | 50 |
| 925 | norm! 2zF |
| 926 | 49 |
| 927 | norm! 5zF |
| 928 | set nofoldenable |
| 929 | 50 |
| 930 | " There most likely is a bug somewhere: |
| 931 | " https://groups.google.com/d/msg/vim_dev/v2EkfJ_KQjI/u-Cvv94uCAAJ |
| 932 | " TODO: Should this only close the inner most fold or both folds? |
| 933 | norm! zc |
| 934 | call assert_equal(1, &foldenable) |
| 935 | norm! k |
| 936 | call assert_equal('48', getline('.')) |
| 937 | norm! j |
| 938 | call assert_equal('49/*{{{*/', getline('.')) |
| 939 | norm! j |
| 940 | call assert_equal('55', getline('.')) |
| 941 | set nofoldenable |
| 942 | 50 |
| 943 | norm! Vjzc |
| 944 | norm! k |
| 945 | call assert_equal('48', getline('.')) |
| 946 | norm! j |
| 947 | call assert_equal('49/*{{{*/', getline('.')) |
| 948 | norm! j |
| 949 | call assert_equal('55', getline('.')) |
| 950 | |
| 951 | " Test for zC |
| 952 | set nofoldenable |
| 953 | 50 |
| 954 | norm! zCk |
| 955 | call assert_equal('48', getline('.')) |
| 956 | norm! j |
| 957 | call assert_equal('49/*{{{*/', getline('.')) |
| 958 | norm! j |
| 959 | call assert_equal('55', getline('.')) |
| 960 | |
| 961 | " Test for zx |
| 962 | " 1) close folds at line 49-54 |
| 963 | set nofoldenable |
| 964 | 48 |
| 965 | norm! zx |
| 966 | call assert_equal(1, &foldenable) |
| 967 | norm! j |
| 968 | call assert_equal('49/*{{{*/', getline('.')) |
| 969 | norm! j |
| 970 | call assert_equal('55', getline('.')) |
| 971 | |
Bram Moolenaar | 395b6ba | 2017-04-07 20:09:51 +0200 | [diff] [blame] | 972 | " 2) do not close fold under cursor |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 973 | 51 |
| 974 | set nofoldenable |
| 975 | norm! zx |
| 976 | call assert_equal(1, &foldenable) |
| 977 | norm! 3k |
| 978 | call assert_equal('48', getline('.')) |
| 979 | norm! j |
| 980 | call assert_equal('49/*{{{*/', getline('.')) |
| 981 | norm! j |
| 982 | call assert_equal('50/*{{{*/', getline('.')) |
| 983 | norm! j |
| 984 | call assert_equal('51/*}}}*/', getline('.')) |
| 985 | norm! j |
| 986 | call assert_equal('52', getline('.')) |
| 987 | norm! j |
| 988 | call assert_equal('53', getline('.')) |
| 989 | norm! j |
| 990 | call assert_equal('54/*}}}*/', getline('.')) |
| 991 | norm! j |
| 992 | call assert_equal('55', getline('.')) |
| 993 | |
| 994 | " 3) close one level of folds |
| 995 | 48 |
| 996 | set nofoldenable |
| 997 | set foldlevel=1 |
| 998 | norm! zx |
| 999 | call assert_equal(1, &foldenable) |
| 1000 | call assert_equal('48', getline('.')) |
| 1001 | norm! j |
| 1002 | call assert_equal('49/*{{{*/', getline('.')) |
| 1003 | norm! j |
| 1004 | call assert_equal('50/*{{{*/', getline('.')) |
| 1005 | norm! j |
| 1006 | call assert_equal('52', getline('.')) |
| 1007 | norm! j |
| 1008 | call assert_equal('53', getline('.')) |
| 1009 | norm! j |
| 1010 | call assert_equal('54/*}}}*/', getline('.')) |
| 1011 | norm! j |
| 1012 | call assert_equal('55', getline('.')) |
| 1013 | |
| 1014 | " Test for zX |
| 1015 | " Close all folds |
| 1016 | set foldlevel=0 nofoldenable |
| 1017 | 50 |
| 1018 | norm! zX |
| 1019 | call assert_equal(1, &foldenable) |
| 1020 | norm! k |
| 1021 | call assert_equal('48', getline('.')) |
| 1022 | norm! j |
| 1023 | call assert_equal('49/*{{{*/', getline('.')) |
| 1024 | norm! j |
| 1025 | call assert_equal('55', getline('.')) |
| 1026 | |
| 1027 | " Test for zm |
| 1028 | 50 |
| 1029 | set nofoldenable foldlevel=2 |
| 1030 | norm! zm |
| 1031 | call assert_equal(1, &foldenable) |
| 1032 | call assert_equal(1, &foldlevel) |
| 1033 | norm! zm |
| 1034 | call assert_equal(0, &foldlevel) |
| 1035 | norm! zm |
| 1036 | call assert_equal(0, &foldlevel) |
| 1037 | norm! k |
| 1038 | call assert_equal('48', getline('.')) |
| 1039 | norm! j |
| 1040 | call assert_equal('49/*{{{*/', getline('.')) |
| 1041 | norm! j |
| 1042 | call assert_equal('55', getline('.')) |
| 1043 | |
| 1044 | " Test for zM |
| 1045 | 48 |
| 1046 | set nofoldenable foldlevel=99 |
| 1047 | norm! zM |
| 1048 | call assert_equal(1, &foldenable) |
| 1049 | call assert_equal(0, &foldlevel) |
| 1050 | call assert_equal('48', getline('.')) |
| 1051 | norm! j |
| 1052 | call assert_equal('49/*{{{*/', getline('.')) |
| 1053 | norm! j |
| 1054 | call assert_equal('55', getline('.')) |
| 1055 | |
| 1056 | " Test for zr |
| 1057 | 48 |
| 1058 | set nofoldenable foldlevel=0 |
| 1059 | norm! zr |
| 1060 | call assert_equal(0, &foldenable) |
| 1061 | call assert_equal(1, &foldlevel) |
| 1062 | set foldlevel=0 foldenable |
| 1063 | norm! zr |
| 1064 | call assert_equal(1, &foldenable) |
| 1065 | call assert_equal(1, &foldlevel) |
| 1066 | norm! zr |
| 1067 | call assert_equal(2, &foldlevel) |
| 1068 | call assert_equal('48', getline('.')) |
| 1069 | norm! j |
| 1070 | call assert_equal('49/*{{{*/', getline('.')) |
| 1071 | norm! j |
| 1072 | call assert_equal('50/*{{{*/', getline('.')) |
| 1073 | norm! j |
| 1074 | call assert_equal('51/*}}}*/', getline('.')) |
| 1075 | norm! j |
| 1076 | call assert_equal('52', getline('.')) |
| 1077 | |
| 1078 | " Test for zR |
| 1079 | 48 |
| 1080 | set nofoldenable foldlevel=0 |
| 1081 | norm! zR |
| 1082 | call assert_equal(0, &foldenable) |
| 1083 | call assert_equal(2, &foldlevel) |
| 1084 | set foldenable foldlevel=0 |
| 1085 | norm! zR |
| 1086 | call assert_equal(1, &foldenable) |
| 1087 | call assert_equal(2, &foldlevel) |
| 1088 | call assert_equal('48', getline('.')) |
| 1089 | norm! j |
| 1090 | call assert_equal('49/*{{{*/', getline('.')) |
| 1091 | norm! j |
| 1092 | call assert_equal('50/*{{{*/', getline('.')) |
| 1093 | norm! j |
| 1094 | call assert_equal('51/*}}}*/', getline('.')) |
| 1095 | norm! j |
| 1096 | call assert_equal('52', getline('.')) |
| 1097 | call append(50, ['a /*{{{*/', 'b /*}}}*/']) |
| 1098 | 48 |
| 1099 | call assert_equal('48', getline('.')) |
| 1100 | norm! j |
| 1101 | call assert_equal('49/*{{{*/', getline('.')) |
| 1102 | norm! j |
| 1103 | call assert_equal('50/*{{{*/', getline('.')) |
| 1104 | norm! j |
| 1105 | call assert_equal('a /*{{{*/', getline('.')) |
| 1106 | norm! j |
| 1107 | call assert_equal('51/*}}}*/', getline('.')) |
| 1108 | norm! j |
| 1109 | call assert_equal('52', getline('.')) |
| 1110 | 48 |
| 1111 | norm! zR |
| 1112 | call assert_equal(1, &foldenable) |
| 1113 | call assert_equal(3, &foldlevel) |
| 1114 | call assert_equal('48', getline('.')) |
| 1115 | norm! j |
| 1116 | call assert_equal('49/*{{{*/', getline('.')) |
| 1117 | norm! j |
| 1118 | call assert_equal('50/*{{{*/', getline('.')) |
| 1119 | norm! j |
| 1120 | call assert_equal('a /*{{{*/', getline('.')) |
| 1121 | norm! j |
| 1122 | call assert_equal('b /*}}}*/', getline('.')) |
| 1123 | norm! j |
| 1124 | call assert_equal('51/*}}}*/', getline('.')) |
| 1125 | norm! j |
| 1126 | call assert_equal('52', getline('.')) |
| 1127 | |
| 1128 | " clean up |
| 1129 | setl nofoldenable fdm=marker foldlevel=0 |
| 1130 | bw! |
Bram Moolenaar | 2931f2a | 2016-09-09 16:59:08 +0200 | [diff] [blame] | 1131 | endfunc |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 1132 | |
Bram Moolenaar | 1bbb619 | 2018-11-10 16:02:01 +0100 | [diff] [blame] | 1133 | func Test_normal20_exmode() |
Bram Moolenaar | 0913a10 | 2016-09-03 19:11:59 +0200 | [diff] [blame] | 1134 | if !has("unix") |
| 1135 | " Reading from redirected file doesn't work on MS-Windows |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 1136 | return |
| 1137 | endif |
| 1138 | call writefile(['1a', 'foo', 'bar', '.', 'w! Xfile2', 'q!'], 'Xscript') |
| 1139 | call writefile(['1', '2'], 'Xfile') |
Bram Moolenaar | 93344c2 | 2019-08-14 21:12:05 +0200 | [diff] [blame] | 1140 | call system(GetVimCommand() .. ' -e -s < Xscript Xfile') |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 1141 | let a=readfile('Xfile2') |
| 1142 | call assert_equal(['1', 'foo', 'bar', '2'], a) |
| 1143 | |
| 1144 | " clean up |
| 1145 | for file in ['Xfile', 'Xfile2', 'Xscript'] |
| 1146 | call delete(file) |
| 1147 | endfor |
| 1148 | bw! |
Bram Moolenaar | 2931f2a | 2016-09-09 16:59:08 +0200 | [diff] [blame] | 1149 | endfunc |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 1150 | |
Bram Moolenaar | 1bbb619 | 2018-11-10 16:02:01 +0100 | [diff] [blame] | 1151 | func Test_normal21_nv_hat() |
| 1152 | |
| 1153 | " Edit a fresh file and wipe the buffer list so that there is no alternate |
| 1154 | " file present. Next, check for the expected command failures. |
| 1155 | edit Xfoo | %bw |
| 1156 | call assert_fails(':buffer #', 'E86') |
| 1157 | call assert_fails(':execute "normal! \<C-^>"', 'E23') |
| 1158 | |
| 1159 | " Test for the expected behavior when switching between two named buffers. |
| 1160 | edit Xfoo | edit Xbar |
| 1161 | call feedkeys("\<C-^>", 'tx') |
| 1162 | call assert_equal('Xfoo', fnamemodify(bufname('%'), ':t')) |
| 1163 | call feedkeys("\<C-^>", 'tx') |
| 1164 | call assert_equal('Xbar', fnamemodify(bufname('%'), ':t')) |
| 1165 | |
| 1166 | " Test for the expected behavior when only one buffer is named. |
| 1167 | enew | let l:nr = bufnr('%') |
| 1168 | call feedkeys("\<C-^>", 'tx') |
| 1169 | call assert_equal('Xbar', fnamemodify(bufname('%'), ':t')) |
| 1170 | call feedkeys("\<C-^>", 'tx') |
| 1171 | call assert_equal('', bufname('%')) |
| 1172 | call assert_equal(l:nr, bufnr('%')) |
| 1173 | |
| 1174 | " Test that no action is taken by "<C-^>" when an operator is pending. |
| 1175 | edit Xfoo |
| 1176 | call feedkeys("ci\<C-^>", 'tx') |
| 1177 | call assert_equal('Xfoo', fnamemodify(bufname('%'), ':t')) |
| 1178 | |
| 1179 | %bw! |
Bram Moolenaar | 2931f2a | 2016-09-09 16:59:08 +0200 | [diff] [blame] | 1180 | endfunc |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 1181 | |
Bram Moolenaar | 1bbb619 | 2018-11-10 16:02:01 +0100 | [diff] [blame] | 1182 | func Test_normal22_zet() |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 1183 | " Test for ZZ |
Bram Moolenaar | 0913a10 | 2016-09-03 19:11:59 +0200 | [diff] [blame] | 1184 | " let shell = &shell |
| 1185 | " let &shell = 'sh' |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 1186 | call writefile(['1', '2'], 'Xfile') |
Bram Moolenaar | 93344c2 | 2019-08-14 21:12:05 +0200 | [diff] [blame] | 1187 | let args = ' -N -i NONE --noplugins -X --not-a-term' |
| 1188 | call system(GetVimCommand() .. args .. ' -c "%d" -c ":norm! ZZ" Xfile') |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 1189 | let a = readfile('Xfile') |
| 1190 | call assert_equal([], a) |
| 1191 | " Test for ZQ |
| 1192 | call writefile(['1', '2'], 'Xfile') |
Bram Moolenaar | 93344c2 | 2019-08-14 21:12:05 +0200 | [diff] [blame] | 1193 | call system(GetVimCommand() . args . ' -c "%d" -c ":norm! ZQ" Xfile') |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 1194 | let a = readfile('Xfile') |
| 1195 | call assert_equal(['1', '2'], a) |
| 1196 | |
Bram Moolenaar | 1671f44 | 2020-03-10 07:48:13 +0100 | [diff] [blame] | 1197 | " Unsupported Z command |
| 1198 | call assert_beeps('normal! ZW') |
| 1199 | |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 1200 | " clean up |
| 1201 | for file in ['Xfile'] |
| 1202 | call delete(file) |
| 1203 | endfor |
Bram Moolenaar | 0913a10 | 2016-09-03 19:11:59 +0200 | [diff] [blame] | 1204 | " let &shell = shell |
Bram Moolenaar | 2931f2a | 2016-09-09 16:59:08 +0200 | [diff] [blame] | 1205 | endfunc |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 1206 | |
Bram Moolenaar | 1bbb619 | 2018-11-10 16:02:01 +0100 | [diff] [blame] | 1207 | func Test_normal23_K() |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 1208 | " Test for K command |
| 1209 | new |
Bram Moolenaar | 426f375 | 2016-11-04 21:22:37 +0100 | [diff] [blame] | 1210 | call append(0, ['version8.txt', 'man', 'aa%bb', 'cc|dd']) |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 1211 | let k = &keywordprg |
| 1212 | set keywordprg=:help |
| 1213 | 1 |
| 1214 | norm! VK |
| 1215 | call assert_equal('version8.txt', fnamemodify(bufname('%'), ':t')) |
| 1216 | call assert_equal('help', &ft) |
| 1217 | call assert_match('\*version8.txt\*', getline('.')) |
| 1218 | helpclose |
| 1219 | norm! 0K |
| 1220 | call assert_equal('version8.txt', fnamemodify(bufname('%'), ':t')) |
| 1221 | call assert_equal('help', &ft) |
Bram Moolenaar | b1c9198 | 2018-05-17 17:04:55 +0200 | [diff] [blame] | 1222 | call assert_match('\*version8\.\d\*', getline('.')) |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 1223 | helpclose |
| 1224 | |
Bram Moolenaar | 426f375 | 2016-11-04 21:22:37 +0100 | [diff] [blame] | 1225 | set keywordprg=:new |
| 1226 | set iskeyword+=% |
| 1227 | set iskeyword+=\| |
| 1228 | 2 |
| 1229 | norm! K |
| 1230 | call assert_equal('man', fnamemodify(bufname('%'), ':t')) |
| 1231 | bwipe! |
| 1232 | 3 |
| 1233 | norm! K |
| 1234 | call assert_equal('aa%bb', fnamemodify(bufname('%'), ':t')) |
| 1235 | bwipe! |
Bram Moolenaar | eb828d0 | 2016-11-05 19:54:01 +0100 | [diff] [blame] | 1236 | if !has('win32') |
| 1237 | 4 |
| 1238 | norm! K |
| 1239 | call assert_equal('cc|dd', fnamemodify(bufname('%'), ':t')) |
| 1240 | bwipe! |
| 1241 | endif |
Bram Moolenaar | 426f375 | 2016-11-04 21:22:37 +0100 | [diff] [blame] | 1242 | set iskeyword-=% |
| 1243 | set iskeyword-=\| |
| 1244 | |
Bram Moolenaar | 0913a10 | 2016-09-03 19:11:59 +0200 | [diff] [blame] | 1245 | " Only expect "man" to work on Unix |
| 1246 | if !has("unix") |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 1247 | let &keywordprg = k |
| 1248 | bw! |
| 1249 | return |
| 1250 | endif |
Bram Moolenaar | c6b37db | 2019-04-27 18:00:34 +0200 | [diff] [blame] | 1251 | |
Bram Moolenaar | 9134f1e | 2019-11-29 20:26:13 +0100 | [diff] [blame] | 1252 | let not_gnu_man = has('mac') || has('bsd') |
| 1253 | if not_gnu_man |
Bram Moolenaar | c7d2a57 | 2019-11-28 21:16:06 +0100 | [diff] [blame] | 1254 | " In MacOS and BSD, the option for specifying a pager is different |
Bram Moolenaar | c6b37db | 2019-04-27 18:00:34 +0200 | [diff] [blame] | 1255 | set keywordprg=man\ -P\ cat |
| 1256 | else |
| 1257 | set keywordprg=man\ --pager=cat |
| 1258 | endif |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 1259 | " Test for using man |
| 1260 | 2 |
| 1261 | let a = execute('unsilent norm! K') |
Bram Moolenaar | 9134f1e | 2019-11-29 20:26:13 +0100 | [diff] [blame] | 1262 | if not_gnu_man |
Bram Moolenaar | c6b37db | 2019-04-27 18:00:34 +0200 | [diff] [blame] | 1263 | call assert_match("man -P cat 'man'", a) |
| 1264 | else |
| 1265 | call assert_match("man --pager=cat 'man'", a) |
| 1266 | endif |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 1267 | |
Bram Moolenaar | 1671f44 | 2020-03-10 07:48:13 +0100 | [diff] [blame] | 1268 | " Error cases |
| 1269 | call setline(1, '#$#') |
| 1270 | call assert_fails('normal! ggK', 'E349:') |
| 1271 | call setline(1, '---') |
| 1272 | call assert_fails('normal! ggv2lK', 'E349:') |
| 1273 | call setline(1, ['abc', 'xyz']) |
| 1274 | call assert_fails("normal! gg2lv2h\<C-]>", 'E426:') |
| 1275 | call assert_beeps("normal! ggVjK") |
| 1276 | |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 1277 | " clean up |
| 1278 | let &keywordprg = k |
| 1279 | bw! |
Bram Moolenaar | 2931f2a | 2016-09-09 16:59:08 +0200 | [diff] [blame] | 1280 | endfunc |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 1281 | |
Bram Moolenaar | 1bbb619 | 2018-11-10 16:02:01 +0100 | [diff] [blame] | 1282 | func Test_normal24_rot13() |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 1283 | " Testing for g?? g?g? |
| 1284 | new |
| 1285 | call append(0, 'abcdefghijklmnopqrstuvwxyzäüö') |
| 1286 | 1 |
| 1287 | norm! g?? |
| 1288 | call assert_equal('nopqrstuvwxyzabcdefghijklmäüö', getline('.')) |
| 1289 | norm! g?g? |
| 1290 | call assert_equal('abcdefghijklmnopqrstuvwxyzäüö', getline('.')) |
| 1291 | |
| 1292 | " clean up |
| 1293 | bw! |
Bram Moolenaar | 2931f2a | 2016-09-09 16:59:08 +0200 | [diff] [blame] | 1294 | endfunc |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 1295 | |
Bram Moolenaar | 1bbb619 | 2018-11-10 16:02:01 +0100 | [diff] [blame] | 1296 | func Test_normal25_tag() |
Bram Moolenaar | 5a4c308 | 2019-12-01 15:23:11 +0100 | [diff] [blame] | 1297 | CheckFeature quickfix |
| 1298 | |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 1299 | " Testing for CTRL-] g CTRL-] g] |
| 1300 | " CTRL-W g] CTRL-W CTRL-] CTRL-W g CTRL-] |
| 1301 | h |
| 1302 | " Test for CTRL-] |
| 1303 | call search('\<x\>$') |
| 1304 | exe "norm! \<c-]>" |
| 1305 | call assert_equal("change.txt", fnamemodify(bufname('%'), ':t')) |
| 1306 | norm! yiW |
| 1307 | call assert_equal("*x*", @0) |
| 1308 | exe ":norm \<c-o>" |
| 1309 | |
| 1310 | " Test for g_CTRL-] |
| 1311 | call search('\<v_u\>$') |
| 1312 | exe "norm! g\<c-]>" |
| 1313 | call assert_equal("change.txt", fnamemodify(bufname('%'), ':t')) |
| 1314 | norm! yiW |
| 1315 | call assert_equal("*v_u*", @0) |
| 1316 | exe ":norm \<c-o>" |
| 1317 | |
| 1318 | " Test for g] |
| 1319 | call search('\<i_<Esc>$') |
| 1320 | let a = execute(":norm! g]") |
| 1321 | call assert_match('i_<Esc>.*insert.txt', a) |
| 1322 | |
| 1323 | if !empty(exepath('cscope')) && has('cscope') |
| 1324 | " setting cscopetag changes how g] works |
| 1325 | set cst |
| 1326 | exe "norm! g]" |
| 1327 | call assert_equal("insert.txt", fnamemodify(bufname('%'), ':t')) |
| 1328 | norm! yiW |
| 1329 | call assert_equal("*i_<Esc>*", @0) |
| 1330 | exe ":norm \<c-o>" |
| 1331 | " Test for CTRL-W g] |
| 1332 | exe "norm! \<C-W>g]" |
| 1333 | call assert_equal("insert.txt", fnamemodify(bufname('%'), ':t')) |
| 1334 | norm! yiW |
| 1335 | call assert_equal("*i_<Esc>*", @0) |
| 1336 | call assert_equal(3, winnr('$')) |
| 1337 | helpclose |
| 1338 | set nocst |
| 1339 | endif |
| 1340 | |
| 1341 | " Test for CTRL-W g] |
| 1342 | let a = execute("norm! \<C-W>g]") |
| 1343 | call assert_match('i_<Esc>.*insert.txt', a) |
| 1344 | |
| 1345 | " Test for CTRL-W CTRL-] |
| 1346 | exe "norm! \<C-W>\<C-]>" |
| 1347 | call assert_equal("insert.txt", fnamemodify(bufname('%'), ':t')) |
| 1348 | norm! yiW |
| 1349 | call assert_equal("*i_<Esc>*", @0) |
| 1350 | call assert_equal(3, winnr('$')) |
| 1351 | helpclose |
| 1352 | |
| 1353 | " Test for CTRL-W g CTRL-] |
| 1354 | exe "norm! \<C-W>g\<C-]>" |
| 1355 | call assert_equal("insert.txt", fnamemodify(bufname('%'), ':t')) |
| 1356 | norm! yiW |
| 1357 | call assert_equal("*i_<Esc>*", @0) |
| 1358 | call assert_equal(3, winnr('$')) |
| 1359 | helpclose |
| 1360 | |
| 1361 | " clean up |
| 1362 | helpclose |
Bram Moolenaar | 2931f2a | 2016-09-09 16:59:08 +0200 | [diff] [blame] | 1363 | endfunc |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 1364 | |
Bram Moolenaar | 1bbb619 | 2018-11-10 16:02:01 +0100 | [diff] [blame] | 1365 | func Test_normal26_put() |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 1366 | " Test for ]p ]P [p and [P |
| 1367 | new |
| 1368 | call append(0, ['while read LINE', 'do', ' ((count++))', ' if [ $? -ne 0 ]; then', " echo 'Error writing file'", ' fi', 'done']) |
| 1369 | 1 |
| 1370 | /Error/y a |
| 1371 | 2 |
| 1372 | norm! "a]pj"a[p |
| 1373 | call assert_equal(['do', "echo 'Error writing file'", " echo 'Error writing file'", ' ((count++))'], getline(2,5)) |
| 1374 | 1 |
| 1375 | /^\s\{4}/ |
| 1376 | exe "norm! \"a]P3Eldt'" |
| 1377 | exe "norm! j\"a[P2Eldt'" |
| 1378 | call assert_equal([' if [ $? -ne 0 ]; then', " echo 'Error writing'", " echo 'Error'", " echo 'Error writing file'", ' fi'], getline(6,10)) |
| 1379 | |
| 1380 | " clean up |
| 1381 | bw! |
Bram Moolenaar | 2931f2a | 2016-09-09 16:59:08 +0200 | [diff] [blame] | 1382 | endfunc |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 1383 | |
Bram Moolenaar | 1bbb619 | 2018-11-10 16:02:01 +0100 | [diff] [blame] | 1384 | func Test_normal27_bracket() |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 1385 | " Test for [' [` ]' ]` |
| 1386 | call Setup_NewWindow() |
| 1387 | 1,21s/.\+/ & b/ |
| 1388 | 1 |
| 1389 | norm! $ma |
| 1390 | 5 |
| 1391 | norm! $mb |
| 1392 | 10 |
| 1393 | norm! $mc |
| 1394 | 15 |
| 1395 | norm! $md |
| 1396 | 20 |
| 1397 | norm! $me |
| 1398 | |
| 1399 | " Test for [' |
| 1400 | 9 |
| 1401 | norm! 2[' |
| 1402 | call assert_equal(' 1 b', getline('.')) |
| 1403 | call assert_equal(1, line('.')) |
| 1404 | call assert_equal(3, col('.')) |
| 1405 | |
| 1406 | " Test for ]' |
| 1407 | norm! ]' |
| 1408 | call assert_equal(' 5 b', getline('.')) |
| 1409 | call assert_equal(5, line('.')) |
| 1410 | call assert_equal(3, col('.')) |
| 1411 | |
| 1412 | " No mark after line 21, cursor moves to first non blank on current line |
| 1413 | 21 |
| 1414 | norm! $]' |
| 1415 | call assert_equal(' 21 b', getline('.')) |
| 1416 | call assert_equal(21, line('.')) |
| 1417 | call assert_equal(3, col('.')) |
| 1418 | |
| 1419 | " Test for [` |
| 1420 | norm! 2[` |
| 1421 | call assert_equal(' 15 b', getline('.')) |
| 1422 | call assert_equal(15, line('.')) |
| 1423 | call assert_equal(8, col('.')) |
| 1424 | |
| 1425 | " Test for ]` |
| 1426 | norm! ]` |
| 1427 | call assert_equal(' 20 b', getline('.')) |
| 1428 | call assert_equal(20, line('.')) |
| 1429 | call assert_equal(8, col('.')) |
| 1430 | |
| 1431 | " clean up |
| 1432 | bw! |
Bram Moolenaar | 2931f2a | 2016-09-09 16:59:08 +0200 | [diff] [blame] | 1433 | endfunc |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 1434 | |
Bram Moolenaar | 1671f44 | 2020-03-10 07:48:13 +0100 | [diff] [blame] | 1435 | " Test for ( and ) sentence movements |
Bram Moolenaar | 1bbb619 | 2018-11-10 16:02:01 +0100 | [diff] [blame] | 1436 | func Test_normal28_parenthesis() |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 1437 | new |
| 1438 | call append(0, ['This is a test. With some sentences!', '', 'Even with a question? And one more. And no sentence here']) |
| 1439 | |
| 1440 | $ |
| 1441 | norm! d( |
| 1442 | call assert_equal(['This is a test. With some sentences!', '', 'Even with a question? And one more. ', ''], getline(1, '$')) |
| 1443 | norm! 2d( |
| 1444 | call assert_equal(['This is a test. With some sentences!', '', ' ', ''], getline(1, '$')) |
| 1445 | 1 |
| 1446 | norm! 0d) |
| 1447 | call assert_equal(['With some sentences!', '', ' ', ''], getline(1, '$')) |
| 1448 | |
| 1449 | call append('$', ['This is a long sentence', '', 'spanning', 'over several lines. ']) |
| 1450 | $ |
| 1451 | norm! $d( |
| 1452 | call assert_equal(['With some sentences!', '', ' ', '', 'This is a long sentence', ''], getline(1, '$')) |
| 1453 | |
Bram Moolenaar | 1671f44 | 2020-03-10 07:48:13 +0100 | [diff] [blame] | 1454 | " It is an error if a next sentence is not found |
| 1455 | %d |
| 1456 | call setline(1, '.SH') |
| 1457 | call assert_beeps('normal )') |
| 1458 | |
| 1459 | " Jumping to a fold should open the fold |
| 1460 | call setline(1, ['', '', 'one', 'two', 'three']) |
| 1461 | set foldenable |
| 1462 | 2,$fold |
| 1463 | call feedkeys(')', 'xt') |
| 1464 | call assert_equal(3, line('.')) |
| 1465 | call assert_equal(1, foldlevel('.')) |
| 1466 | call assert_equal(-1, foldclosed('.')) |
| 1467 | set foldenable& |
| 1468 | |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 1469 | " clean up |
| 1470 | bw! |
Bram Moolenaar | 2931f2a | 2016-09-09 16:59:08 +0200 | [diff] [blame] | 1471 | endfunc |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 1472 | |
Bram Moolenaar | 1671f44 | 2020-03-10 07:48:13 +0100 | [diff] [blame] | 1473 | " Test for { and } paragraph movements |
| 1474 | func Test_normal29_brace() |
Bram Moolenaar | c79745a | 2019-05-20 22:12:34 +0200 | [diff] [blame] | 1475 | let text =<< trim [DATA] |
Bram Moolenaar | e7eb927 | 2019-06-24 00:58:07 +0200 | [diff] [blame] | 1476 | A paragraph begins after each empty line, and also at each of a set of |
| 1477 | paragraph macros, specified by the pairs of characters in the 'paragraphs' |
| 1478 | option. The default is "IPLPPPQPP TPHPLIPpLpItpplpipbp", which corresponds to |
| 1479 | the macros ".IP", ".LP", etc. (These are nroff macros, so the dot must be in |
| 1480 | the first column). A section boundary is also a paragraph boundary. |
| 1481 | Note that a blank line (only containing white space) is NOT a paragraph |
| 1482 | boundary. |
Bram Moolenaar | c79745a | 2019-05-20 22:12:34 +0200 | [diff] [blame] | 1483 | |
| 1484 | |
Bram Moolenaar | e7eb927 | 2019-06-24 00:58:07 +0200 | [diff] [blame] | 1485 | Also note that this does not include a '{' or '}' in the first column. When |
| 1486 | the '{' flag is in 'cpoptions' then '{' in the first column is used as a |
| 1487 | paragraph boundary |posix|. |
| 1488 | { |
| 1489 | This is no paragraph |
| 1490 | unless the '{' is set |
| 1491 | in 'cpoptions' |
| 1492 | } |
| 1493 | .IP |
| 1494 | The nroff macros IP separates a paragraph |
| 1495 | That means, it must be a '.' |
| 1496 | followed by IP |
| 1497 | .LPIt does not matter, if afterwards some |
| 1498 | more characters follow. |
| 1499 | .SHAlso section boundaries from the nroff |
| 1500 | macros terminate a paragraph. That means |
| 1501 | a character like this: |
| 1502 | .NH |
| 1503 | End of text here |
Bram Moolenaar | c79745a | 2019-05-20 22:12:34 +0200 | [diff] [blame] | 1504 | [DATA] |
| 1505 | |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 1506 | new |
| 1507 | call append(0, text) |
| 1508 | 1 |
| 1509 | norm! 0d2} |
Bram Moolenaar | c79745a | 2019-05-20 22:12:34 +0200 | [diff] [blame] | 1510 | |
| 1511 | let expected =<< trim [DATA] |
Bram Moolenaar | e7eb927 | 2019-06-24 00:58:07 +0200 | [diff] [blame] | 1512 | .IP |
| 1513 | The nroff macros IP separates a paragraph |
| 1514 | That means, it must be a '.' |
| 1515 | followed by IP |
| 1516 | .LPIt does not matter, if afterwards some |
| 1517 | more characters follow. |
| 1518 | .SHAlso section boundaries from the nroff |
| 1519 | macros terminate a paragraph. That means |
| 1520 | a character like this: |
| 1521 | .NH |
| 1522 | End of text here |
Bram Moolenaar | c79745a | 2019-05-20 22:12:34 +0200 | [diff] [blame] | 1523 | |
| 1524 | [DATA] |
| 1525 | call assert_equal(expected, getline(1, '$')) |
| 1526 | |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 1527 | norm! 0d} |
Bram Moolenaar | c79745a | 2019-05-20 22:12:34 +0200 | [diff] [blame] | 1528 | |
| 1529 | let expected =<< trim [DATA] |
Bram Moolenaar | e7eb927 | 2019-06-24 00:58:07 +0200 | [diff] [blame] | 1530 | .LPIt does not matter, if afterwards some |
| 1531 | more characters follow. |
| 1532 | .SHAlso section boundaries from the nroff |
| 1533 | macros terminate a paragraph. That means |
| 1534 | a character like this: |
| 1535 | .NH |
| 1536 | End of text here |
| 1537 | |
Bram Moolenaar | c79745a | 2019-05-20 22:12:34 +0200 | [diff] [blame] | 1538 | [DATA] |
| 1539 | call assert_equal(expected, getline(1, '$')) |
| 1540 | |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 1541 | $ |
| 1542 | norm! d{ |
Bram Moolenaar | c79745a | 2019-05-20 22:12:34 +0200 | [diff] [blame] | 1543 | |
| 1544 | let expected =<< trim [DATA] |
Bram Moolenaar | e7eb927 | 2019-06-24 00:58:07 +0200 | [diff] [blame] | 1545 | .LPIt does not matter, if afterwards some |
| 1546 | more characters follow. |
| 1547 | .SHAlso section boundaries from the nroff |
| 1548 | macros terminate a paragraph. That means |
| 1549 | a character like this: |
Bram Moolenaar | c79745a | 2019-05-20 22:12:34 +0200 | [diff] [blame] | 1550 | |
| 1551 | [DATA] |
| 1552 | call assert_equal(expected, getline(1, '$')) |
| 1553 | |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 1554 | norm! d{ |
Bram Moolenaar | c79745a | 2019-05-20 22:12:34 +0200 | [diff] [blame] | 1555 | |
| 1556 | let expected =<< trim [DATA] |
Bram Moolenaar | e7eb927 | 2019-06-24 00:58:07 +0200 | [diff] [blame] | 1557 | .LPIt does not matter, if afterwards some |
| 1558 | more characters follow. |
Bram Moolenaar | c79745a | 2019-05-20 22:12:34 +0200 | [diff] [blame] | 1559 | |
| 1560 | [DATA] |
| 1561 | call assert_equal(expected, getline(1, '$')) |
| 1562 | |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 1563 | " Test with { in cpooptions |
| 1564 | %d |
| 1565 | call append(0, text) |
| 1566 | set cpo+={ |
| 1567 | 1 |
| 1568 | norm! 0d2} |
Bram Moolenaar | c79745a | 2019-05-20 22:12:34 +0200 | [diff] [blame] | 1569 | |
| 1570 | let expected =<< trim [DATA] |
Bram Moolenaar | e7eb927 | 2019-06-24 00:58:07 +0200 | [diff] [blame] | 1571 | { |
| 1572 | This is no paragraph |
| 1573 | unless the '{' is set |
| 1574 | in 'cpoptions' |
| 1575 | } |
| 1576 | .IP |
| 1577 | The nroff macros IP separates a paragraph |
| 1578 | That means, it must be a '.' |
| 1579 | followed by IP |
| 1580 | .LPIt does not matter, if afterwards some |
| 1581 | more characters follow. |
| 1582 | .SHAlso section boundaries from the nroff |
| 1583 | macros terminate a paragraph. That means |
| 1584 | a character like this: |
| 1585 | .NH |
| 1586 | End of text here |
Bram Moolenaar | c79745a | 2019-05-20 22:12:34 +0200 | [diff] [blame] | 1587 | |
| 1588 | [DATA] |
| 1589 | call assert_equal(expected, getline(1, '$')) |
| 1590 | |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 1591 | $ |
| 1592 | norm! d} |
Bram Moolenaar | c79745a | 2019-05-20 22:12:34 +0200 | [diff] [blame] | 1593 | |
| 1594 | let expected =<< trim [DATA] |
Bram Moolenaar | e7eb927 | 2019-06-24 00:58:07 +0200 | [diff] [blame] | 1595 | { |
| 1596 | This is no paragraph |
| 1597 | unless the '{' is set |
| 1598 | in 'cpoptions' |
| 1599 | } |
| 1600 | .IP |
| 1601 | The nroff macros IP separates a paragraph |
| 1602 | That means, it must be a '.' |
| 1603 | followed by IP |
| 1604 | .LPIt does not matter, if afterwards some |
| 1605 | more characters follow. |
| 1606 | .SHAlso section boundaries from the nroff |
| 1607 | macros terminate a paragraph. That means |
| 1608 | a character like this: |
| 1609 | .NH |
| 1610 | End of text here |
Bram Moolenaar | c79745a | 2019-05-20 22:12:34 +0200 | [diff] [blame] | 1611 | |
| 1612 | [DATA] |
| 1613 | call assert_equal(expected, getline(1, '$')) |
| 1614 | |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 1615 | norm! gg} |
| 1616 | norm! d5} |
Bram Moolenaar | c79745a | 2019-05-20 22:12:34 +0200 | [diff] [blame] | 1617 | |
| 1618 | let expected =<< trim [DATA] |
Bram Moolenaar | e7eb927 | 2019-06-24 00:58:07 +0200 | [diff] [blame] | 1619 | { |
| 1620 | This is no paragraph |
| 1621 | unless the '{' is set |
| 1622 | in 'cpoptions' |
| 1623 | } |
Bram Moolenaar | c79745a | 2019-05-20 22:12:34 +0200 | [diff] [blame] | 1624 | |
| 1625 | [DATA] |
| 1626 | call assert_equal(expected, getline(1, '$')) |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 1627 | |
Bram Moolenaar | 1671f44 | 2020-03-10 07:48:13 +0100 | [diff] [blame] | 1628 | " Jumping to a fold should open the fold |
| 1629 | %d |
| 1630 | call setline(1, ['', 'one', 'two', '']) |
| 1631 | set foldenable |
| 1632 | 2,$fold |
| 1633 | call feedkeys('}', 'xt') |
| 1634 | call assert_equal(4, line('.')) |
| 1635 | call assert_equal(1, foldlevel('.')) |
| 1636 | call assert_equal(-1, foldclosed('.')) |
| 1637 | set foldenable& |
| 1638 | |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 1639 | " clean up |
| 1640 | set cpo-={ |
| 1641 | bw! |
Bram Moolenaar | 2931f2a | 2016-09-09 16:59:08 +0200 | [diff] [blame] | 1642 | endfunc |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 1643 | |
Bram Moolenaar | 1671f44 | 2020-03-10 07:48:13 +0100 | [diff] [blame] | 1644 | " Test for ~ command |
| 1645 | func Test_normal30_changecase() |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 1646 | new |
| 1647 | call append(0, 'This is a simple test: äüöß') |
| 1648 | norm! 1ggVu |
| 1649 | call assert_equal('this is a simple test: äüöß', getline('.')) |
| 1650 | norm! VU |
| 1651 | call assert_equal('THIS IS A SIMPLE TEST: ÄÜÖSS', getline('.')) |
| 1652 | norm! guu |
| 1653 | call assert_equal('this is a simple test: äüöss', getline('.')) |
| 1654 | norm! gUgU |
| 1655 | call assert_equal('THIS IS A SIMPLE TEST: ÄÜÖSS', getline('.')) |
| 1656 | norm! gugu |
| 1657 | call assert_equal('this is a simple test: äüöss', getline('.')) |
| 1658 | norm! gUU |
| 1659 | call assert_equal('THIS IS A SIMPLE TEST: ÄÜÖSS', getline('.')) |
| 1660 | norm! 010~ |
| 1661 | call assert_equal('this is a SIMPLE TEST: ÄÜÖSS', getline('.')) |
| 1662 | norm! V~ |
| 1663 | call assert_equal('THIS IS A simple test: äüöss', getline('.')) |
| 1664 | |
Bram Moolenaar | 1671f44 | 2020-03-10 07:48:13 +0100 | [diff] [blame] | 1665 | " Test for changing case across lines using 'whichwrap' |
| 1666 | call setline(1, ['aaaaaa', 'aaaaaa']) |
| 1667 | normal! gg10~ |
| 1668 | call assert_equal(['AAAAAA', 'aaaaaa'], getline(1, 2)) |
| 1669 | set whichwrap+=~ |
| 1670 | normal! gg10~ |
| 1671 | call assert_equal(['aaaaaa', 'AAAAaa'], getline(1, 2)) |
| 1672 | set whichwrap& |
| 1673 | |
| 1674 | " clean up |
| 1675 | bw! |
| 1676 | endfunc |
| 1677 | |
| 1678 | " Turkish ASCII turns to multi-byte. On some systems Turkish locale |
| 1679 | " is available but toupper()/tolower() don't do the right thing. |
| 1680 | func Test_normal_changecase_turkish() |
| 1681 | new |
Bram Moolenaar | f1c118b | 2018-09-03 22:08:10 +0200 | [diff] [blame] | 1682 | try |
| 1683 | lang tr_TR.UTF-8 |
| 1684 | set casemap= |
| 1685 | let iupper = toupper('i') |
| 1686 | if iupper == "\u0130" |
Bram Moolenaar | 9f4de1f | 2017-04-08 19:39:43 +0200 | [diff] [blame] | 1687 | call setline(1, 'iI') |
| 1688 | 1normal gUU |
| 1689 | call assert_equal("\u0130I", getline(1)) |
| 1690 | call assert_equal("\u0130I", toupper("iI")) |
Bram Moolenaar | 3317d5e | 2017-04-08 19:12:06 +0200 | [diff] [blame] | 1691 | |
Bram Moolenaar | 9f4de1f | 2017-04-08 19:39:43 +0200 | [diff] [blame] | 1692 | call setline(1, 'iI') |
| 1693 | 1normal guu |
| 1694 | call assert_equal("i\u0131", getline(1)) |
| 1695 | call assert_equal("i\u0131", tolower("iI")) |
Bram Moolenaar | f1c118b | 2018-09-03 22:08:10 +0200 | [diff] [blame] | 1696 | elseif iupper == "I" |
Bram Moolenaar | 1cc4820 | 2017-04-09 13:41:59 +0200 | [diff] [blame] | 1697 | call setline(1, 'iI') |
| 1698 | 1normal gUU |
| 1699 | call assert_equal("II", getline(1)) |
| 1700 | call assert_equal("II", toupper("iI")) |
| 1701 | |
| 1702 | call setline(1, 'iI') |
| 1703 | 1normal guu |
| 1704 | call assert_equal("ii", getline(1)) |
| 1705 | call assert_equal("ii", tolower("iI")) |
Bram Moolenaar | f1c118b | 2018-09-03 22:08:10 +0200 | [diff] [blame] | 1706 | else |
| 1707 | call assert_true(false, "expected toupper('i') to be either 'I' or '\u0130'") |
| 1708 | endif |
| 1709 | set casemap& |
| 1710 | call setline(1, 'iI') |
| 1711 | 1normal gUU |
| 1712 | call assert_equal("II", getline(1)) |
| 1713 | call assert_equal("II", toupper("iI")) |
Bram Moolenaar | 1cc4820 | 2017-04-09 13:41:59 +0200 | [diff] [blame] | 1714 | |
Bram Moolenaar | f1c118b | 2018-09-03 22:08:10 +0200 | [diff] [blame] | 1715 | call setline(1, 'iI') |
| 1716 | 1normal guu |
| 1717 | call assert_equal("ii", getline(1)) |
| 1718 | call assert_equal("ii", tolower("iI")) |
| 1719 | |
| 1720 | lang en_US.UTF-8 |
| 1721 | catch /E197:/ |
| 1722 | " can't use Turkish locale |
| 1723 | throw 'Skipped: Turkish locale not available' |
| 1724 | endtry |
Bram Moolenaar | 1671f44 | 2020-03-10 07:48:13 +0100 | [diff] [blame] | 1725 | close! |
Bram Moolenaar | 2931f2a | 2016-09-09 16:59:08 +0200 | [diff] [blame] | 1726 | endfunc |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 1727 | |
Bram Moolenaar | 1671f44 | 2020-03-10 07:48:13 +0100 | [diff] [blame] | 1728 | " Test for r (replace) command |
| 1729 | func Test_normal31_r_cmd() |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 1730 | new |
| 1731 | call append(0, 'This is a simple test: abcd') |
| 1732 | exe "norm! 1gg$r\<cr>" |
| 1733 | call assert_equal(['This is a simple test: abc', '', ''], getline(1,'$')) |
| 1734 | exe "norm! 1gg2wlr\<cr>" |
| 1735 | call assert_equal(['This is a', 'simple test: abc', '', ''], getline(1,'$')) |
| 1736 | exe "norm! 2gg0W5r\<cr>" |
| 1737 | call assert_equal(['This is a', 'simple ', ' abc', '', ''], getline('1', '$')) |
| 1738 | set autoindent |
| 1739 | call setline(2, ['simple test: abc', '']) |
| 1740 | exe "norm! 2gg0W5r\<cr>" |
| 1741 | call assert_equal(['This is a', 'simple ', 'abc', '', '', ''], getline('1', '$')) |
| 1742 | exe "norm! 1ggVr\<cr>" |
| 1743 | call assert_equal('^M^M^M^M^M^M^M^M^M', strtrans(getline(1))) |
| 1744 | call setline(1, 'This is a') |
| 1745 | exe "norm! 1gg05rf" |
| 1746 | call assert_equal('fffffis a', getline(1)) |
| 1747 | |
Bram Moolenaar | 1671f44 | 2020-03-10 07:48:13 +0100 | [diff] [blame] | 1748 | " When replacing characters, copy characters from above and below lines |
| 1749 | " using CTRL-Y and CTRL-E. |
| 1750 | " Different code paths are used for utf-8 and latin1 encodings |
| 1751 | set showmatch |
| 1752 | for enc in ['latin1', 'utf-8'] |
| 1753 | enew! |
| 1754 | let &encoding = enc |
| 1755 | call setline(1, [' {a}', 'xxxxxxxxxx', ' [b]']) |
| 1756 | exe "norm! 2gg5r\<C-Y>l5r\<C-E>" |
| 1757 | call assert_equal(' {a}x [b]x', getline(2)) |
| 1758 | endfor |
| 1759 | set showmatch& |
| 1760 | |
| 1761 | " r command should fail in operator pending mode |
| 1762 | call assert_beeps('normal! cr') |
| 1763 | |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 1764 | " clean up |
| 1765 | set noautoindent |
| 1766 | bw! |
Bram Moolenaar | 2931f2a | 2016-09-09 16:59:08 +0200 | [diff] [blame] | 1767 | endfunc |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 1768 | |
Bram Moolenaar | f5f1e10 | 2020-03-08 05:13:15 +0100 | [diff] [blame] | 1769 | " Test for g*, g# |
Bram Moolenaar | 1bbb619 | 2018-11-10 16:02:01 +0100 | [diff] [blame] | 1770 | func Test_normal32_g_cmd1() |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 1771 | new |
| 1772 | call append(0, ['abc.x_foo', 'x_foobar.abc']) |
| 1773 | 1 |
| 1774 | norm! $g* |
| 1775 | call assert_equal('x_foo', @/) |
| 1776 | call assert_equal('x_foobar.abc', getline('.')) |
| 1777 | norm! $g# |
| 1778 | call assert_equal('abc', @/) |
| 1779 | call assert_equal('abc.x_foo', getline('.')) |
| 1780 | |
| 1781 | " clean up |
| 1782 | bw! |
Bram Moolenaar | 2931f2a | 2016-09-09 16:59:08 +0200 | [diff] [blame] | 1783 | endfunc |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 1784 | |
Bram Moolenaar | f5f1e10 | 2020-03-08 05:13:15 +0100 | [diff] [blame] | 1785 | " Test for g`, g;, g,, g&, gv, gk, gj, gJ, g0, g^, g_, gm, g$, gM, g CTRL-G, |
| 1786 | " gi and gI commands |
Bram Moolenaar | 1671f44 | 2020-03-10 07:48:13 +0100 | [diff] [blame] | 1787 | func Test_normal33_g_cmd2() |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 1788 | if !has("jumplist") |
| 1789 | return |
| 1790 | endif |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 1791 | call Setup_NewWindow() |
| 1792 | " Test for g` |
| 1793 | clearjumps |
| 1794 | norm! ma10j |
| 1795 | let a=execute(':jumps') |
| 1796 | " empty jumplist |
| 1797 | call assert_equal('>', a[-1:]) |
| 1798 | norm! g`a |
| 1799 | call assert_equal('>', a[-1:]) |
| 1800 | call assert_equal(1, line('.')) |
| 1801 | call assert_equal('1', getline('.')) |
Bram Moolenaar | f5f1e10 | 2020-03-08 05:13:15 +0100 | [diff] [blame] | 1802 | call cursor(10, 1) |
| 1803 | norm! g'a |
| 1804 | call assert_equal('>', a[-1:]) |
| 1805 | call assert_equal(1, line('.')) |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 1806 | |
| 1807 | " Test for g; and g, |
| 1808 | norm! g; |
| 1809 | " there is only one change in the changelist |
| 1810 | " currently, when we setup the window |
| 1811 | call assert_equal(2, line('.')) |
| 1812 | call assert_fails(':norm! g;', 'E662') |
| 1813 | call assert_fails(':norm! g,', 'E663') |
| 1814 | let &ul=&ul |
| 1815 | call append('$', ['a', 'b', 'c', 'd']) |
| 1816 | let &ul=&ul |
| 1817 | call append('$', ['Z', 'Y', 'X', 'W']) |
| 1818 | let a = execute(':changes') |
| 1819 | call assert_match('2\s\+0\s\+2', a) |
| 1820 | call assert_match('101\s\+0\s\+a', a) |
| 1821 | call assert_match('105\s\+0\s\+Z', a) |
| 1822 | norm! 3g; |
| 1823 | call assert_equal(2, line('.')) |
| 1824 | norm! 2g, |
| 1825 | call assert_equal(105, line('.')) |
| 1826 | |
| 1827 | " Test for g& - global substitute |
| 1828 | %d |
| 1829 | call setline(1, range(1,10)) |
| 1830 | call append('$', ['a', 'b', 'c', 'd']) |
| 1831 | $s/\w/&&/g |
| 1832 | exe "norm! /[1-8]\<cr>" |
| 1833 | norm! g& |
| 1834 | call assert_equal(['11', '22', '33', '44', '55', '66', '77', '88', '9', '110', 'a', 'b', 'c', 'dd'], getline(1, '$')) |
| 1835 | |
Bram Moolenaar | 1671f44 | 2020-03-10 07:48:13 +0100 | [diff] [blame] | 1836 | " Jumping to a fold using gg should open the fold |
| 1837 | set foldenable |
| 1838 | set foldopen+=jump |
| 1839 | 5,8fold |
| 1840 | call feedkeys('6gg', 'xt') |
| 1841 | call assert_equal(1, foldlevel('.')) |
| 1842 | call assert_equal(-1, foldclosed('.')) |
| 1843 | set foldopen-=jump |
| 1844 | set foldenable& |
| 1845 | |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 1846 | " Test for gv |
| 1847 | %d |
| 1848 | call append('$', repeat(['abcdefgh'], 8)) |
| 1849 | exe "norm! 2gg02l\<c-v>2j2ly" |
| 1850 | call assert_equal(['cde', 'cde', 'cde'], getreg(0, 1, 1)) |
| 1851 | " in visual mode, gv swaps current and last selected region |
| 1852 | exe "norm! G0\<c-v>4k4lgvd" |
| 1853 | call assert_equal(['', 'abfgh', 'abfgh', 'abfgh', 'abcdefgh', 'abcdefgh', 'abcdefgh', 'abcdefgh', 'abcdefgh'], getline(1,'$')) |
| 1854 | exe "norm! G0\<c-v>4k4ly" |
| 1855 | exe "norm! gvood" |
| 1856 | call assert_equal(['', 'abfgh', 'abfgh', 'abfgh', 'fgh', 'fgh', 'fgh', 'fgh', 'fgh'], getline(1,'$')) |
Bram Moolenaar | f5f1e10 | 2020-03-08 05:13:15 +0100 | [diff] [blame] | 1857 | " gv cannot be used in operator pending mode |
| 1858 | call assert_beeps('normal! cgv') |
| 1859 | " gv should beep without a previously selected visual area |
| 1860 | new |
| 1861 | call assert_beeps('normal! gv') |
| 1862 | close |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 1863 | |
| 1864 | " Test for gk/gj |
| 1865 | %d |
| 1866 | 15vsp |
| 1867 | set wrap listchars= sbr= |
| 1868 | let lineA='abcdefghijklmnopqrstuvwxyz' |
| 1869 | let lineB='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ' |
Bram Moolenaar | 8b530c1 | 2019-10-28 02:13:05 +0100 | [diff] [blame] | 1870 | let lineC='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz01234567890123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789' |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 1871 | $put =lineA |
| 1872 | $put =lineB |
| 1873 | |
| 1874 | norm! 3gg0dgk |
| 1875 | call assert_equal(['', 'abcdefghijklmno', '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'], getline(1, '$')) |
| 1876 | set nu |
| 1877 | norm! 3gg0gjdgj |
| 1878 | call assert_equal(['', 'abcdefghijklmno', '0123456789AMNOPQRSTUVWXYZ'], getline(1,'$')) |
| 1879 | |
| 1880 | " Test for gJ |
| 1881 | norm! 2gggJ |
| 1882 | call assert_equal(['', 'abcdefghijklmno0123456789AMNOPQRSTUVWXYZ'], getline(1,'$')) |
| 1883 | call assert_equal(16, col('.')) |
| 1884 | " shouldn't do anything |
| 1885 | norm! 10gJ |
| 1886 | call assert_equal(1, col('.')) |
| 1887 | |
| 1888 | " Test for g0 g^ gm g$ |
| 1889 | exe "norm! 2gg0gji " |
| 1890 | call assert_equal(['', 'abcdefghijk lmno0123456789AMNOPQRSTUVWXYZ'], getline(1,'$')) |
| 1891 | norm! g0yl |
| 1892 | call assert_equal(12, col('.')) |
| 1893 | call assert_equal(' ', getreg(0)) |
| 1894 | norm! g$yl |
| 1895 | call assert_equal(22, col('.')) |
| 1896 | call assert_equal('3', getreg(0)) |
| 1897 | norm! gmyl |
| 1898 | call assert_equal(17, col('.')) |
| 1899 | call assert_equal('n', getreg(0)) |
| 1900 | norm! g^yl |
| 1901 | call assert_equal(15, col('.')) |
| 1902 | call assert_equal('l', getreg(0)) |
Bram Moolenaar | f5f1e10 | 2020-03-08 05:13:15 +0100 | [diff] [blame] | 1903 | call assert_beeps('normal 5g$') |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 1904 | |
Bram Moolenaar | f5f1e10 | 2020-03-08 05:13:15 +0100 | [diff] [blame] | 1905 | " Test for g_ |
| 1906 | call assert_beeps('normal! 100g_') |
| 1907 | call setline(2, [' foo ', ' foobar ']) |
| 1908 | normal! 2ggg_ |
| 1909 | call assert_equal(5, col('.')) |
| 1910 | normal! 2g_ |
| 1911 | call assert_equal(8, col('.')) |
| 1912 | |
| 1913 | norm! 2ggdG |
Bram Moolenaar | 8b530c1 | 2019-10-28 02:13:05 +0100 | [diff] [blame] | 1914 | $put =lineC |
| 1915 | |
| 1916 | " Test for gM |
| 1917 | norm! gMyl |
| 1918 | call assert_equal(73, col('.')) |
| 1919 | call assert_equal('0', getreg(0)) |
| 1920 | " Test for 20gM |
| 1921 | norm! 20gMyl |
| 1922 | call assert_equal(29, col('.')) |
| 1923 | call assert_equal('S', getreg(0)) |
| 1924 | " Test for 60gM |
| 1925 | norm! 60gMyl |
| 1926 | call assert_equal(87, col('.')) |
| 1927 | call assert_equal('E', getreg(0)) |
| 1928 | |
| 1929 | " Test for g Ctrl-G |
| 1930 | set ff=unix |
| 1931 | let a=execute(":norm! g\<c-g>") |
| 1932 | call assert_match('Col 87 of 144; Line 2 of 2; Word 1 of 1; Byte 88 of 146', a) |
| 1933 | |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 1934 | " Test for gI |
| 1935 | norm! gIfoo |
Bram Moolenaar | 8b530c1 | 2019-10-28 02:13:05 +0100 | [diff] [blame] | 1936 | call assert_equal(['', 'foo0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz01234567890123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'], getline(1,'$')) |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 1937 | |
| 1938 | " Test for gi |
| 1939 | wincmd c |
| 1940 | %d |
| 1941 | set tw=0 |
| 1942 | call setline(1, ['foobar', 'new line']) |
| 1943 | norm! A next word |
| 1944 | $put ='third line' |
| 1945 | norm! gi another word |
| 1946 | call assert_equal(['foobar next word another word', 'new line', 'third line'], getline(1,'$')) |
Bram Moolenaar | f5f1e10 | 2020-03-08 05:13:15 +0100 | [diff] [blame] | 1947 | call setline(1, 'foobar') |
| 1948 | normal! Ggifirst line |
| 1949 | call assert_equal('foobarfirst line', getline(1)) |
| 1950 | " Test gi in 'virtualedit' mode with cursor after the end of the line |
| 1951 | set virtualedit=all |
| 1952 | call setline(1, 'foo') |
| 1953 | exe "normal! Abar\<Right>\<Right>\<Right>\<Right>" |
| 1954 | call setline(1, 'foo') |
| 1955 | normal! Ggifirst line |
| 1956 | call assert_equal('foo first line', getline(1)) |
| 1957 | set virtualedit& |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 1958 | |
Bram Moolenaar | 1671f44 | 2020-03-10 07:48:13 +0100 | [diff] [blame] | 1959 | " Test for aboring a g command using CTRL-\ CTRL-G |
| 1960 | exe "normal! g\<C-\>\<C-G>" |
| 1961 | call assert_equal('foo first line', getline('.')) |
| 1962 | |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 1963 | " clean up |
| 1964 | bw! |
Bram Moolenaar | 2931f2a | 2016-09-09 16:59:08 +0200 | [diff] [blame] | 1965 | endfunc |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 1966 | |
Bram Moolenaar | f5f1e10 | 2020-03-08 05:13:15 +0100 | [diff] [blame] | 1967 | " Test for g CTRL-G |
Bram Moolenaar | 1bbb619 | 2018-11-10 16:02:01 +0100 | [diff] [blame] | 1968 | func Test_g_ctrl_g() |
Bram Moolenaar | 0529583 | 2018-08-24 22:07:58 +0200 | [diff] [blame] | 1969 | new |
| 1970 | |
| 1971 | let a = execute(":norm! g\<c-g>") |
| 1972 | call assert_equal("\n--No lines in buffer--", a) |
| 1973 | |
Bram Moolenaar | 1671f44 | 2020-03-10 07:48:13 +0100 | [diff] [blame] | 1974 | " Test for CTRL-G (same as :file) |
| 1975 | let a = execute(":norm! \<c-g>") |
| 1976 | call assert_equal("\n\n\"[No Name]\" --No lines in buffer--", a) |
| 1977 | |
Bram Moolenaar | 0529583 | 2018-08-24 22:07:58 +0200 | [diff] [blame] | 1978 | call setline(1, ['first line', 'second line']) |
| 1979 | |
| 1980 | " Test g CTRL-g with dos, mac and unix file type. |
| 1981 | norm! gojll |
| 1982 | set ff=dos |
| 1983 | let a = execute(":norm! g\<c-g>") |
| 1984 | call assert_equal("\nCol 3 of 11; Line 2 of 2; Word 3 of 4; Byte 15 of 25", a) |
| 1985 | |
| 1986 | set ff=mac |
| 1987 | let a = execute(":norm! g\<c-g>") |
| 1988 | call assert_equal("\nCol 3 of 11; Line 2 of 2; Word 3 of 4; Byte 14 of 23", a) |
| 1989 | |
| 1990 | set ff=unix |
| 1991 | let a = execute(":norm! g\<c-g>") |
| 1992 | call assert_equal("\nCol 3 of 11; Line 2 of 2; Word 3 of 4; Byte 14 of 23", a) |
| 1993 | |
| 1994 | " Test g CTRL-g in visual mode (v) |
| 1995 | let a = execute(":norm! gojllvlg\<c-g>") |
| 1996 | call assert_equal("\nSelected 1 of 2 Lines; 1 of 4 Words; 2 of 23 Bytes", a) |
| 1997 | |
| 1998 | " Test g CTRL-g in visual mode (CTRL-V) with end col > start col |
| 1999 | let a = execute(":norm! \<Esc>gojll\<C-V>kllg\<c-g>") |
| 2000 | call assert_equal("\nSelected 3 Cols; 2 of 2 Lines; 2 of 4 Words; 6 of 23 Bytes", a) |
| 2001 | |
| 2002 | " Test g_CTRL-g in visual mode (CTRL-V) with end col < start col |
| 2003 | let a = execute(":norm! \<Esc>goll\<C-V>jhhg\<c-g>") |
| 2004 | call assert_equal("\nSelected 3 Cols; 2 of 2 Lines; 2 of 4 Words; 6 of 23 Bytes", a) |
| 2005 | |
| 2006 | " Test g CTRL-g in visual mode (CTRL-V) with end_vcol being MAXCOL |
| 2007 | let a = execute(":norm! \<Esc>gojll\<C-V>k$g\<c-g>") |
| 2008 | call assert_equal("\nSelected 2 of 2 Lines; 4 of 4 Words; 17 of 23 Bytes", a) |
| 2009 | |
| 2010 | " There should be one byte less with noeol |
| 2011 | set bin noeol |
| 2012 | let a = execute(":norm! \<Esc>gog\<c-g>") |
| 2013 | call assert_equal("\nCol 1 of 10; Line 1 of 2; Word 1 of 4; Char 1 of 23; Byte 1 of 22", a) |
| 2014 | set bin & eol& |
| 2015 | |
Bram Moolenaar | 30276f2 | 2019-01-24 17:59:39 +0100 | [diff] [blame] | 2016 | call setline(1, ['Français', '日本語']) |
Bram Moolenaar | 0529583 | 2018-08-24 22:07:58 +0200 | [diff] [blame] | 2017 | |
Bram Moolenaar | 30276f2 | 2019-01-24 17:59:39 +0100 | [diff] [blame] | 2018 | let a = execute(":norm! \<Esc>gojlg\<c-g>") |
| 2019 | call assert_equal("\nCol 4-3 of 9-6; Line 2 of 2; Word 2 of 2; Char 11 of 13; Byte 16 of 20", a) |
Bram Moolenaar | 0529583 | 2018-08-24 22:07:58 +0200 | [diff] [blame] | 2020 | |
Bram Moolenaar | 30276f2 | 2019-01-24 17:59:39 +0100 | [diff] [blame] | 2021 | let a = execute(":norm! \<Esc>gojvlg\<c-g>") |
| 2022 | call assert_equal("\nSelected 1 of 2 Lines; 1 of 2 Words; 2 of 13 Chars; 6 of 20 Bytes", a) |
Bram Moolenaar | 0529583 | 2018-08-24 22:07:58 +0200 | [diff] [blame] | 2023 | |
Bram Moolenaar | 30276f2 | 2019-01-24 17:59:39 +0100 | [diff] [blame] | 2024 | let a = execute(":norm! \<Esc>goll\<c-v>jlg\<c-g>") |
| 2025 | call assert_equal("\nSelected 4 Cols; 2 of 2 Lines; 2 of 2 Words; 6 of 13 Chars; 11 of 20 Bytes", a) |
Bram Moolenaar | 0529583 | 2018-08-24 22:07:58 +0200 | [diff] [blame] | 2026 | |
Bram Moolenaar | 30276f2 | 2019-01-24 17:59:39 +0100 | [diff] [blame] | 2027 | set fenc=utf8 bomb |
| 2028 | let a = execute(":norm! \<Esc>gojlg\<c-g>") |
| 2029 | call assert_equal("\nCol 4-3 of 9-6; Line 2 of 2; Word 2 of 2; Char 11 of 13; Byte 16 of 20(+3 for BOM)", a) |
Bram Moolenaar | 0529583 | 2018-08-24 22:07:58 +0200 | [diff] [blame] | 2030 | |
Bram Moolenaar | 30276f2 | 2019-01-24 17:59:39 +0100 | [diff] [blame] | 2031 | set fenc=utf16 bomb |
| 2032 | let a = execute(":norm! g\<c-g>") |
| 2033 | call assert_equal("\nCol 4-3 of 9-6; Line 2 of 2; Word 2 of 2; Char 11 of 13; Byte 16 of 20(+2 for BOM)", a) |
Bram Moolenaar | 0529583 | 2018-08-24 22:07:58 +0200 | [diff] [blame] | 2034 | |
Bram Moolenaar | 30276f2 | 2019-01-24 17:59:39 +0100 | [diff] [blame] | 2035 | set fenc=utf32 bomb |
| 2036 | let a = execute(":norm! g\<c-g>") |
| 2037 | call assert_equal("\nCol 4-3 of 9-6; Line 2 of 2; Word 2 of 2; Char 11 of 13; Byte 16 of 20(+4 for BOM)", a) |
Bram Moolenaar | 0529583 | 2018-08-24 22:07:58 +0200 | [diff] [blame] | 2038 | |
Bram Moolenaar | 30276f2 | 2019-01-24 17:59:39 +0100 | [diff] [blame] | 2039 | set fenc& bomb& |
Bram Moolenaar | 0529583 | 2018-08-24 22:07:58 +0200 | [diff] [blame] | 2040 | |
| 2041 | set ff& |
| 2042 | bwipe! |
| 2043 | endfunc |
| 2044 | |
Bram Moolenaar | f5f1e10 | 2020-03-08 05:13:15 +0100 | [diff] [blame] | 2045 | " Test for g8 |
Bram Moolenaar | 1671f44 | 2020-03-10 07:48:13 +0100 | [diff] [blame] | 2046 | func Test_normal34_g_cmd3() |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 2047 | new |
Bram Moolenaar | 395b6ba | 2017-04-07 20:09:51 +0200 | [diff] [blame] | 2048 | let a=execute(':norm! 1G0g8') |
| 2049 | call assert_equal("\nNUL", a) |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 2050 | |
Bram Moolenaar | 395b6ba | 2017-04-07 20:09:51 +0200 | [diff] [blame] | 2051 | call setline(1, 'abcdefghijklmnopqrstuvwxyzäüö') |
| 2052 | let a=execute(':norm! 1G$g8') |
| 2053 | call assert_equal("\nc3 b6 ", a) |
| 2054 | |
| 2055 | call setline(1, "a\u0302") |
| 2056 | let a=execute(':norm! 1G0g8') |
| 2057 | call assert_equal("\n61 + cc 82 ", a) |
| 2058 | |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 2059 | " clean up |
| 2060 | bw! |
Bram Moolenaar | 2931f2a | 2016-09-09 16:59:08 +0200 | [diff] [blame] | 2061 | endfunc |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 2062 | |
Bram Moolenaar | f5f1e10 | 2020-03-08 05:13:15 +0100 | [diff] [blame] | 2063 | " Test 8g8 which finds invalid utf8 at or after the cursor. |
Bram Moolenaar | 395b6ba | 2017-04-07 20:09:51 +0200 | [diff] [blame] | 2064 | func Test_normal_8g8() |
Bram Moolenaar | 395b6ba | 2017-04-07 20:09:51 +0200 | [diff] [blame] | 2065 | new |
| 2066 | |
Bram Moolenaar | 395b6ba | 2017-04-07 20:09:51 +0200 | [diff] [blame] | 2067 | " With invalid byte. |
| 2068 | call setline(1, "___\xff___") |
| 2069 | norm! 1G08g8g |
| 2070 | call assert_equal([0, 1, 4, 0, 1], getcurpos()) |
| 2071 | |
| 2072 | " With invalid byte before the cursor. |
| 2073 | call setline(1, "___\xff___") |
| 2074 | norm! 1G$h8g8g |
| 2075 | call assert_equal([0, 1, 6, 0, 9], getcurpos()) |
| 2076 | |
| 2077 | " With truncated sequence. |
| 2078 | call setline(1, "___\xE2\x82___") |
| 2079 | norm! 1G08g8g |
| 2080 | call assert_equal([0, 1, 4, 0, 1], getcurpos()) |
| 2081 | |
| 2082 | " With overlong sequence. |
| 2083 | call setline(1, "___\xF0\x82\x82\xAC___") |
| 2084 | norm! 1G08g8g |
| 2085 | call assert_equal([0, 1, 4, 0, 1], getcurpos()) |
| 2086 | |
| 2087 | " With valid utf8. |
| 2088 | call setline(1, "café") |
| 2089 | norm! 1G08g8 |
| 2090 | call assert_equal([0, 1, 1, 0, 1], getcurpos()) |
| 2091 | |
| 2092 | bw! |
| 2093 | endfunc |
| 2094 | |
Bram Moolenaar | f5f1e10 | 2020-03-08 05:13:15 +0100 | [diff] [blame] | 2095 | " Test for g< |
Bram Moolenaar | 1671f44 | 2020-03-10 07:48:13 +0100 | [diff] [blame] | 2096 | func Test_normal35_g_cmd4() |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 2097 | " Cannot capture its output, |
| 2098 | " probably a bug, therefore, test disabled: |
Bram Moolenaar | 3184509 | 2016-09-05 22:58:31 +0200 | [diff] [blame] | 2099 | throw "Skipped: output of g< can't be tested currently" |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 2100 | echo "a\nb\nc\nd" |
| 2101 | let b=execute(':norm! g<') |
| 2102 | call assert_true(!empty(b), 'failed `execute(g<)`') |
Bram Moolenaar | 2931f2a | 2016-09-09 16:59:08 +0200 | [diff] [blame] | 2103 | endfunc |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 2104 | |
Bram Moolenaar | f5f1e10 | 2020-03-08 05:13:15 +0100 | [diff] [blame] | 2105 | " Test for gp gP go |
Bram Moolenaar | 1671f44 | 2020-03-10 07:48:13 +0100 | [diff] [blame] | 2106 | func Test_normal36_g_cmd5() |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 2107 | new |
| 2108 | call append(0, 'abcdefghijklmnopqrstuvwxyz') |
Bram Moolenaar | 0913a10 | 2016-09-03 19:11:59 +0200 | [diff] [blame] | 2109 | set ff=unix |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 2110 | " Test for gp gP |
| 2111 | call append(1, range(1,10)) |
| 2112 | 1 |
| 2113 | norm! 1yy |
| 2114 | 3 |
| 2115 | norm! gp |
| 2116 | call assert_equal([0, 5, 1, 0, 1], getcurpos()) |
| 2117 | $ |
| 2118 | norm! gP |
| 2119 | call assert_equal([0, 14, 1, 0, 1], getcurpos()) |
| 2120 | |
| 2121 | " Test for go |
| 2122 | norm! 26go |
| 2123 | call assert_equal([0, 1, 26, 0, 26], getcurpos()) |
| 2124 | norm! 27go |
| 2125 | call assert_equal([0, 1, 26, 0, 26], getcurpos()) |
| 2126 | norm! 28go |
| 2127 | call assert_equal([0, 2, 1, 0, 1], getcurpos()) |
| 2128 | set ff=dos |
| 2129 | norm! 29go |
| 2130 | call assert_equal([0, 2, 1, 0, 1], getcurpos()) |
| 2131 | set ff=unix |
| 2132 | norm! gg0 |
| 2133 | norm! 101go |
| 2134 | call assert_equal([0, 13, 26, 0, 26], getcurpos()) |
| 2135 | norm! 103go |
| 2136 | call assert_equal([0, 14, 1, 0, 1], getcurpos()) |
| 2137 | " count > buffer content |
| 2138 | norm! 120go |
| 2139 | call assert_equal([0, 14, 1, 0, 2147483647], getcurpos()) |
| 2140 | " clean up |
| 2141 | bw! |
Bram Moolenaar | 2931f2a | 2016-09-09 16:59:08 +0200 | [diff] [blame] | 2142 | endfunc |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 2143 | |
Bram Moolenaar | f5f1e10 | 2020-03-08 05:13:15 +0100 | [diff] [blame] | 2144 | " Test for gt and gT |
Bram Moolenaar | 1671f44 | 2020-03-10 07:48:13 +0100 | [diff] [blame] | 2145 | func Test_normal37_g_cmd6() |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 2146 | tabnew 1.txt |
| 2147 | tabnew 2.txt |
| 2148 | tabnew 3.txt |
| 2149 | norm! 1gt |
| 2150 | call assert_equal(1, tabpagenr()) |
| 2151 | norm! 3gt |
| 2152 | call assert_equal(3, tabpagenr()) |
| 2153 | norm! 1gT |
| 2154 | " count gT goes not to the absolute tabpagenumber |
| 2155 | " but, but goes to the count previous tabpagenumber |
| 2156 | call assert_equal(2, tabpagenr()) |
| 2157 | " wrap around |
| 2158 | norm! 3gT |
| 2159 | call assert_equal(3, tabpagenr()) |
| 2160 | " gt does not wrap around |
| 2161 | norm! 5gt |
| 2162 | call assert_equal(3, tabpagenr()) |
| 2163 | |
| 2164 | for i in range(3) |
| 2165 | tabclose |
| 2166 | endfor |
| 2167 | " clean up |
Bram Moolenaar | bc2b71d | 2020-02-17 21:33:30 +0100 | [diff] [blame] | 2168 | call assert_fails(':tabclose', 'E784:') |
Bram Moolenaar | 2931f2a | 2016-09-09 16:59:08 +0200 | [diff] [blame] | 2169 | endfunc |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 2170 | |
Bram Moolenaar | f5f1e10 | 2020-03-08 05:13:15 +0100 | [diff] [blame] | 2171 | " Test for <Home> and <C-Home> key |
Bram Moolenaar | 1671f44 | 2020-03-10 07:48:13 +0100 | [diff] [blame] | 2172 | func Test_normal38_nvhome() |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 2173 | new |
| 2174 | call setline(1, range(10)) |
| 2175 | $ |
| 2176 | setl et sw=2 |
| 2177 | norm! V10>$ |
| 2178 | " count is ignored |
| 2179 | exe "norm! 10\<home>" |
| 2180 | call assert_equal(1, col('.')) |
| 2181 | exe "norm! \<home>" |
| 2182 | call assert_equal([0, 10, 1, 0, 1], getcurpos()) |
| 2183 | exe "norm! 5\<c-home>" |
| 2184 | call assert_equal([0, 5, 1, 0, 1], getcurpos()) |
| 2185 | exe "norm! \<c-home>" |
| 2186 | call assert_equal([0, 1, 1, 0, 1], getcurpos()) |
Bram Moolenaar | f5f1e10 | 2020-03-08 05:13:15 +0100 | [diff] [blame] | 2187 | exe "norm! G\<c-kHome>" |
| 2188 | call assert_equal([0, 1, 1, 0, 1], getcurpos()) |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 2189 | |
| 2190 | " clean up |
| 2191 | bw! |
Bram Moolenaar | 2931f2a | 2016-09-09 16:59:08 +0200 | [diff] [blame] | 2192 | endfunc |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 2193 | |
Bram Moolenaar | 1671f44 | 2020-03-10 07:48:13 +0100 | [diff] [blame] | 2194 | " Test for <End> and <C-End> keys |
| 2195 | func Test_normal_nvend() |
| 2196 | new |
| 2197 | call setline(1, map(range(1, 10), '"line" .. v:val')) |
| 2198 | exe "normal! \<End>" |
| 2199 | call assert_equal(5, col('.')) |
| 2200 | exe "normal! 4\<End>" |
| 2201 | call assert_equal([4, 5], [line('.'), col('.')]) |
| 2202 | exe "normal! \<C-End>" |
| 2203 | call assert_equal([10, 6], [line('.'), col('.')]) |
| 2204 | close! |
| 2205 | endfunc |
| 2206 | |
Bram Moolenaar | f5f1e10 | 2020-03-08 05:13:15 +0100 | [diff] [blame] | 2207 | " Test for cw cW ce |
Bram Moolenaar | 1671f44 | 2020-03-10 07:48:13 +0100 | [diff] [blame] | 2208 | func Test_normal39_cw() |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 2209 | " Test for cw and cW on whitespace |
| 2210 | " and cpo+=w setting |
| 2211 | new |
| 2212 | set tw=0 |
| 2213 | call append(0, 'here are some words') |
| 2214 | norm! 1gg0elcwZZZ |
| 2215 | call assert_equal('hereZZZare some words', getline('.')) |
| 2216 | norm! 1gg0elcWYYY |
| 2217 | call assert_equal('hereZZZareYYYsome words', getline('.')) |
| 2218 | set cpo+=w |
| 2219 | call setline(1, 'here are some words') |
| 2220 | norm! 1gg0elcwZZZ |
| 2221 | call assert_equal('hereZZZ are some words', getline('.')) |
| 2222 | norm! 1gg2elcWYYY |
| 2223 | call assert_equal('hereZZZ areYYY some words', getline('.')) |
| 2224 | set cpo-=w |
| 2225 | norm! 2gg0cwfoo |
| 2226 | call assert_equal('foo', getline('.')) |
| 2227 | |
Bram Moolenaar | f5f1e10 | 2020-03-08 05:13:15 +0100 | [diff] [blame] | 2228 | call setline(1, 'one; two') |
| 2229 | call cursor(1, 1) |
| 2230 | call feedkeys('cwvim', 'xt') |
| 2231 | call assert_equal('vim; two', getline(1)) |
| 2232 | call feedkeys('0cWone', 'xt') |
| 2233 | call assert_equal('one two', getline(1)) |
| 2234 | "When cursor is at the end of a word 'ce' will change until the end of the |
| 2235 | "next word, but 'cw' will change only one character |
| 2236 | call setline(1, 'one two') |
| 2237 | call feedkeys('0ecwce', 'xt') |
| 2238 | call assert_equal('once two', getline(1)) |
| 2239 | call setline(1, 'one two') |
| 2240 | call feedkeys('0ecely', 'xt') |
| 2241 | call assert_equal('only', getline(1)) |
| 2242 | |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 2243 | " clean up |
| 2244 | bw! |
Bram Moolenaar | 2931f2a | 2016-09-09 16:59:08 +0200 | [diff] [blame] | 2245 | endfunc |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 2246 | |
Bram Moolenaar | f5f1e10 | 2020-03-08 05:13:15 +0100 | [diff] [blame] | 2247 | " Test for CTRL-\ commands |
Bram Moolenaar | 1671f44 | 2020-03-10 07:48:13 +0100 | [diff] [blame] | 2248 | func Test_normal40_ctrl_bsl() |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 2249 | new |
| 2250 | call append(0, 'here are some words') |
| 2251 | exe "norm! 1gg0a\<C-\>\<C-N>" |
| 2252 | call assert_equal('n', mode()) |
| 2253 | call assert_equal(1, col('.')) |
| 2254 | call assert_equal('', visualmode()) |
| 2255 | exe "norm! 1gg0viw\<C-\>\<C-N>" |
| 2256 | call assert_equal('n', mode()) |
| 2257 | call assert_equal(4, col('.')) |
| 2258 | exe "norm! 1gg0a\<C-\>\<C-G>" |
| 2259 | call assert_equal('n', mode()) |
| 2260 | call assert_equal(1, col('.')) |
| 2261 | "imap <buffer> , <c-\><c-n> |
| 2262 | set im |
| 2263 | exe ":norm! \<c-\>\<c-n>dw" |
| 2264 | set noim |
| 2265 | call assert_equal('are some words', getline(1)) |
| 2266 | call assert_false(&insertmode) |
Bram Moolenaar | 1671f44 | 2020-03-10 07:48:13 +0100 | [diff] [blame] | 2267 | call assert_beeps("normal! \<C-\>\<C-A>", 'xt') |
| 2268 | |
| 2269 | " Using CTRL-\ CTRL-N in cmd window should close the window |
| 2270 | call feedkeys("q:\<C-\>\<C-N>", 'xt') |
| 2271 | call assert_equal('', getcmdwintype()) |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 2272 | |
| 2273 | " clean up |
| 2274 | bw! |
Bram Moolenaar | 2931f2a | 2016-09-09 16:59:08 +0200 | [diff] [blame] | 2275 | endfunc |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 2276 | |
Bram Moolenaar | f5f1e10 | 2020-03-08 05:13:15 +0100 | [diff] [blame] | 2277 | " Test for <c-r>=, <c-r><c-r>= and <c-r><c-o>= in insert mode |
Bram Moolenaar | 1671f44 | 2020-03-10 07:48:13 +0100 | [diff] [blame] | 2278 | func Test_normal41_insert_reg() |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 2279 | new |
| 2280 | set sts=2 sw=2 ts=8 tw=0 |
| 2281 | call append(0, ["aaa\tbbb\tccc", '', '', '']) |
| 2282 | let a=getline(1) |
| 2283 | norm! 2gg0 |
| 2284 | exe "norm! a\<c-r>=a\<cr>" |
| 2285 | norm! 3gg0 |
| 2286 | exe "norm! a\<c-r>\<c-r>=a\<cr>" |
| 2287 | norm! 4gg0 |
| 2288 | exe "norm! a\<c-r>\<c-o>=a\<cr>" |
| 2289 | call assert_equal(['aaa bbb ccc', 'aaa bbb ccc', 'aaa bbb ccc', 'aaa bbb ccc', ''], getline(1, '$')) |
| 2290 | |
| 2291 | " clean up |
| 2292 | set sts=0 sw=8 ts=8 |
Bram Moolenaar | 3184509 | 2016-09-05 22:58:31 +0200 | [diff] [blame] | 2293 | bw! |
Bram Moolenaar | 2931f2a | 2016-09-09 16:59:08 +0200 | [diff] [blame] | 2294 | endfunc |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 2295 | |
Bram Moolenaar | f5f1e10 | 2020-03-08 05:13:15 +0100 | [diff] [blame] | 2296 | " Test for Ctrl-D and Ctrl-U |
Bram Moolenaar | 1bbb619 | 2018-11-10 16:02:01 +0100 | [diff] [blame] | 2297 | func Test_normal42_halfpage() |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 2298 | call Setup_NewWindow() |
| 2299 | call assert_equal(5, &scroll) |
| 2300 | exe "norm! \<c-d>" |
| 2301 | call assert_equal('6', getline('.')) |
| 2302 | exe "norm! 2\<c-d>" |
| 2303 | call assert_equal('8', getline('.')) |
| 2304 | call assert_equal(2, &scroll) |
| 2305 | set scroll=5 |
| 2306 | exe "norm! \<c-u>" |
| 2307 | call assert_equal('3', getline('.')) |
| 2308 | 1 |
| 2309 | set scrolloff=5 |
| 2310 | exe "norm! \<c-d>" |
| 2311 | call assert_equal('10', getline('.')) |
| 2312 | exe "norm! \<c-u>" |
| 2313 | call assert_equal('5', getline('.')) |
| 2314 | 1 |
| 2315 | set scrolloff=99 |
| 2316 | exe "norm! \<c-d>" |
| 2317 | call assert_equal('10', getline('.')) |
| 2318 | set scrolloff=0 |
| 2319 | 100 |
| 2320 | exe "norm! $\<c-u>" |
| 2321 | call assert_equal('95', getline('.')) |
| 2322 | call assert_equal([0, 95, 1, 0, 1], getcurpos()) |
| 2323 | 100 |
| 2324 | set nostartofline |
| 2325 | exe "norm! $\<c-u>" |
| 2326 | call assert_equal('95', getline('.')) |
| 2327 | call assert_equal([0, 95, 2, 0, 2147483647], getcurpos()) |
| 2328 | " cleanup |
| 2329 | set startofline |
| 2330 | bw! |
Bram Moolenaar | 2931f2a | 2016-09-09 16:59:08 +0200 | [diff] [blame] | 2331 | endfunc |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 2332 | |
Bram Moolenaar | f5f1e10 | 2020-03-08 05:13:15 +0100 | [diff] [blame] | 2333 | " Tests for text object aw |
Bram Moolenaar | 1671f44 | 2020-03-10 07:48:13 +0100 | [diff] [blame] | 2334 | func Test_normal43_textobject1() |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 2335 | new |
| 2336 | call append(0, ['foobar,eins,foobar', 'foo,zwei,foo ']) |
| 2337 | " diw |
| 2338 | norm! 1gg0diw |
| 2339 | call assert_equal([',eins,foobar', 'foo,zwei,foo ', ''], getline(1,'$')) |
| 2340 | " daw |
| 2341 | norm! 2ggEdaw |
| 2342 | call assert_equal([',eins,foobar', 'foo,zwei,', ''], getline(1, '$')) |
| 2343 | %d |
| 2344 | call append(0, ["foo\teins\tfoobar", "foo\tzwei\tfoo "]) |
| 2345 | " diW |
| 2346 | norm! 2ggwd2iW |
| 2347 | call assert_equal(['foo eins foobar', 'foo foo ', ''], getline(1,'$')) |
| 2348 | " daW |
| 2349 | norm! 1ggd2aW |
| 2350 | call assert_equal(['foobar', 'foo foo ', ''], getline(1,'$')) |
| 2351 | |
| 2352 | %d |
| 2353 | call append(0, ["foo\teins\tfoobar", "foo\tzwei\tfoo "]) |
| 2354 | " aw in visual line mode switches to characterwise mode |
| 2355 | norm! 2gg$Vawd |
| 2356 | call assert_equal(['foo eins foobar', 'foo zwei foo'], getline(1,'$')) |
| 2357 | norm! 1gg$Viwd |
| 2358 | call assert_equal(['foo eins ', 'foo zwei foo'], getline(1,'$')) |
| 2359 | |
| 2360 | " clean up |
| 2361 | bw! |
Bram Moolenaar | 2931f2a | 2016-09-09 16:59:08 +0200 | [diff] [blame] | 2362 | endfunc |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 2363 | |
Bram Moolenaar | f5f1e10 | 2020-03-08 05:13:15 +0100 | [diff] [blame] | 2364 | " Test for is and as text objects |
Bram Moolenaar | 1bbb619 | 2018-11-10 16:02:01 +0100 | [diff] [blame] | 2365 | func Test_normal44_textobjects2() |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 2366 | new |
| 2367 | call append(0, ['This is a test. With some sentences!', '', 'Even with a question? And one more. And no sentence here']) |
| 2368 | " Test for dis - does not remove trailing whitespace |
| 2369 | norm! 1gg0dis |
| 2370 | call assert_equal([' With some sentences!', '', 'Even with a question? And one more. And no sentence here', ''], getline(1,'$')) |
| 2371 | " Test for das - removes leading whitespace |
| 2372 | norm! 3ggf?ldas |
| 2373 | call assert_equal([' With some sentences!', '', 'Even with a question? And no sentence here', ''], getline(1,'$')) |
| 2374 | " when used in visual mode, is made characterwise |
| 2375 | norm! 3gg$Visy |
| 2376 | call assert_equal('v', visualmode()) |
| 2377 | " reset visualmode() |
| 2378 | norm! 3ggVy |
| 2379 | norm! 3gg$Vasy |
| 2380 | call assert_equal('v', visualmode()) |
| 2381 | " basic testing for textobjects a< and at |
| 2382 | %d |
| 2383 | call setline(1, ['<div> ','<a href="foobar" class="foo">xyz</a>',' </div>', ' ']) |
| 2384 | " a< |
| 2385 | norm! 1gg0da< |
| 2386 | call assert_equal([' ', '<a href="foobar" class="foo">xyz</a>', ' </div>', ' '], getline(1,'$')) |
| 2387 | norm! 1pj |
| 2388 | call assert_equal([' <div>', '<a href="foobar" class="foo">xyz</a>', ' </div>', ' '], getline(1,'$')) |
| 2389 | " at |
| 2390 | norm! d2at |
| 2391 | call assert_equal([' '], getline(1,'$')) |
| 2392 | %d |
| 2393 | call setline(1, ['<div> ','<a href="foobar" class="foo">xyz</a>',' </div>', ' ']) |
| 2394 | " i< |
| 2395 | norm! 1gg0di< |
| 2396 | call assert_equal(['<> ', '<a href="foobar" class="foo">xyz</a>', ' </div>', ' '], getline(1,'$')) |
| 2397 | norm! 1Pj |
| 2398 | call assert_equal(['<div> ', '<a href="foobar" class="foo">xyz</a>', ' </div>', ' '], getline(1,'$')) |
| 2399 | norm! d2it |
| 2400 | call assert_equal(['<div></div>',' '], getline(1,'$')) |
| 2401 | " basic testing for a[ and i[ text object |
| 2402 | %d |
| 2403 | call setline(1, [' ', '[', 'one [two]', 'thre', ']']) |
| 2404 | norm! 3gg0di[ |
| 2405 | call assert_equal([' ', '[', ']'], getline(1,'$')) |
| 2406 | call setline(1, [' ', '[', 'one [two]', 'thre', ']']) |
| 2407 | norm! 3gg0ftd2a[ |
| 2408 | call assert_equal([' '], getline(1,'$')) |
| 2409 | %d |
| 2410 | " Test for i" when cursor is in front of a quoted object |
| 2411 | call append(0, 'foo "bar"') |
| 2412 | norm! 1gg0di" |
| 2413 | call assert_equal(['foo ""', ''], getline(1,'$')) |
| 2414 | |
| 2415 | " clean up |
| 2416 | bw! |
Bram Moolenaar | 2931f2a | 2016-09-09 16:59:08 +0200 | [diff] [blame] | 2417 | endfunc |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 2418 | |
Bram Moolenaar | 1bbb619 | 2018-11-10 16:02:01 +0100 | [diff] [blame] | 2419 | func Test_normal45_drop() |
Bram Moolenaar | 2949595 | 2018-02-12 22:49:00 +0100 | [diff] [blame] | 2420 | if !has('dnd') |
Bram Moolenaar | b48e96f | 2018-02-13 12:26:14 +0100 | [diff] [blame] | 2421 | " The ~ register does not exist |
| 2422 | call assert_beeps('norm! "~') |
Bram Moolenaar | 2949595 | 2018-02-12 22:49:00 +0100 | [diff] [blame] | 2423 | return |
| 2424 | endif |
| 2425 | |
| 2426 | " basic test for drag-n-drop |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 2427 | " unfortunately, without a gui, we can't really test much here, |
| 2428 | " so simply test that ~p fails (which uses the drop register) |
| 2429 | new |
| 2430 | call assert_fails(':norm! "~p', 'E353') |
| 2431 | call assert_equal([], getreg('~', 1, 1)) |
| 2432 | " the ~ register is read only |
| 2433 | call assert_fails(':let @~="1"', 'E354') |
| 2434 | bw! |
Bram Moolenaar | 2931f2a | 2016-09-09 16:59:08 +0200 | [diff] [blame] | 2435 | endfunc |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 2436 | |
Bram Moolenaar | 1bbb619 | 2018-11-10 16:02:01 +0100 | [diff] [blame] | 2437 | func Test_normal46_ignore() |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 2438 | new |
| 2439 | " How to test this? |
| 2440 | " let's just for now test, that the buffer |
| 2441 | " does not change |
| 2442 | call feedkeys("\<c-s>", 't') |
| 2443 | call assert_equal([''], getline(1,'$')) |
| 2444 | |
Bram Moolenaar | 2931f2a | 2016-09-09 16:59:08 +0200 | [diff] [blame] | 2445 | " no valid commands |
| 2446 | exe "norm! \<char-0x100>" |
| 2447 | call assert_equal([''], getline(1,'$')) |
| 2448 | |
| 2449 | exe "norm! ä" |
| 2450 | call assert_equal([''], getline(1,'$')) |
| 2451 | |
Bram Moolenaar | 87bc3f7 | 2016-09-03 17:33:54 +0200 | [diff] [blame] | 2452 | " clean up |
| 2453 | bw! |
Bram Moolenaar | 2931f2a | 2016-09-09 16:59:08 +0200 | [diff] [blame] | 2454 | endfunc |
Bram Moolenaar | c4a908e | 2016-09-08 23:35:30 +0200 | [diff] [blame] | 2455 | |
Bram Moolenaar | 1bbb619 | 2018-11-10 16:02:01 +0100 | [diff] [blame] | 2456 | func Test_normal47_visual_buf_wipe() |
Bram Moolenaar | c4a908e | 2016-09-08 23:35:30 +0200 | [diff] [blame] | 2457 | " This was causing a crash or ml_get error. |
| 2458 | enew! |
| 2459 | call setline(1,'xxx') |
| 2460 | normal $ |
| 2461 | new |
| 2462 | call setline(1, range(1,2)) |
| 2463 | 2 |
| 2464 | exe "norm \<C-V>$" |
| 2465 | bw! |
| 2466 | norm yp |
| 2467 | set nomodified |
Bram Moolenaar | 2931f2a | 2016-09-09 16:59:08 +0200 | [diff] [blame] | 2468 | endfunc |
| 2469 | |
Bram Moolenaar | 1bbb619 | 2018-11-10 16:02:01 +0100 | [diff] [blame] | 2470 | func Test_normal47_autocmd() |
Bram Moolenaar | 2931f2a | 2016-09-09 16:59:08 +0200 | [diff] [blame] | 2471 | " disabled, does not seem to be possible currently |
| 2472 | throw "Skipped: not possible to test cursorhold autocmd while waiting for input in normal_cmd" |
| 2473 | new |
| 2474 | call append(0, repeat('-',20)) |
| 2475 | au CursorHold * call feedkeys('2l', '') |
| 2476 | 1 |
| 2477 | set updatetime=20 |
| 2478 | " should delete 12 chars (d12l) |
| 2479 | call feedkeys('d1', '!') |
| 2480 | call assert_equal('--------', getline(1)) |
| 2481 | |
| 2482 | " clean up |
| 2483 | au! CursorHold |
| 2484 | set updatetime=4000 |
| 2485 | bw! |
| 2486 | endfunc |
| 2487 | |
Bram Moolenaar | 1bbb619 | 2018-11-10 16:02:01 +0100 | [diff] [blame] | 2488 | func Test_normal48_wincmd() |
Bram Moolenaar | 2931f2a | 2016-09-09 16:59:08 +0200 | [diff] [blame] | 2489 | new |
| 2490 | exe "norm! \<c-w>c" |
| 2491 | call assert_equal(1, winnr('$')) |
| 2492 | call assert_fails(":norm! \<c-w>c", "E444") |
| 2493 | endfunc |
| 2494 | |
Bram Moolenaar | 1bbb619 | 2018-11-10 16:02:01 +0100 | [diff] [blame] | 2495 | func Test_normal49_counts() |
Bram Moolenaar | 2931f2a | 2016-09-09 16:59:08 +0200 | [diff] [blame] | 2496 | new |
| 2497 | call setline(1, 'one two three four five six seven eight nine ten') |
| 2498 | 1 |
| 2499 | norm! 3d2w |
| 2500 | call assert_equal('seven eight nine ten', getline(1)) |
| 2501 | bw! |
| 2502 | endfunc |
| 2503 | |
Bram Moolenaar | 1bbb619 | 2018-11-10 16:02:01 +0100 | [diff] [blame] | 2504 | func Test_normal50_commandline() |
Bram Moolenaar | 4033c55 | 2017-09-16 20:54:51 +0200 | [diff] [blame] | 2505 | if !has("timers") || !has("cmdline_hist") |
Bram Moolenaar | 2931f2a | 2016-09-09 16:59:08 +0200 | [diff] [blame] | 2506 | return |
| 2507 | endif |
| 2508 | func! DoTimerWork(id) |
| 2509 | call assert_equal('[Command Line]', bufname('')) |
| 2510 | " should fail, with E11, but does fail with E23? |
| 2511 | "call feedkeys("\<c-^>", 'tm') |
| 2512 | |
| 2513 | " should also fail with E11 |
| 2514 | call assert_fails(":wincmd p", 'E11') |
| 2515 | " return from commandline window |
| 2516 | call feedkeys("\<cr>") |
| 2517 | endfunc |
| 2518 | |
| 2519 | let oldlang=v:lang |
| 2520 | lang C |
| 2521 | set updatetime=20 |
| 2522 | call timer_start(100, 'DoTimerWork') |
| 2523 | try |
| 2524 | " throws E23, for whatever reason... |
| 2525 | call feedkeys('q:', 'x!') |
| 2526 | catch /E23/ |
| 2527 | " no-op |
| 2528 | endtry |
| 2529 | " clean up |
| 2530 | set updatetime=4000 |
| 2531 | exe "lang" oldlang |
| 2532 | bw! |
| 2533 | endfunc |
| 2534 | |
Bram Moolenaar | 1bbb619 | 2018-11-10 16:02:01 +0100 | [diff] [blame] | 2535 | func Test_normal51_FileChangedRO() |
Bram Moolenaar | 2931f2a | 2016-09-09 16:59:08 +0200 | [diff] [blame] | 2536 | if !has("autocmd") |
| 2537 | return |
| 2538 | endif |
Bram Moolenaar | e5f2a07 | 2017-02-01 22:31:49 +0100 | [diff] [blame] | 2539 | " Don't sleep after the warning message. |
| 2540 | call test_settime(1) |
Bram Moolenaar | 2931f2a | 2016-09-09 16:59:08 +0200 | [diff] [blame] | 2541 | call writefile(['foo'], 'Xreadonly.log') |
| 2542 | new Xreadonly.log |
| 2543 | setl ro |
| 2544 | au FileChangedRO <buffer> :call feedkeys("\<c-^>", 'tix') |
| 2545 | call assert_fails(":norm! Af", 'E788') |
| 2546 | call assert_equal(['foo'], getline(1,'$')) |
| 2547 | call assert_equal('Xreadonly.log', bufname('')) |
| 2548 | |
| 2549 | " cleanup |
Bram Moolenaar | e5f2a07 | 2017-02-01 22:31:49 +0100 | [diff] [blame] | 2550 | call test_settime(0) |
Bram Moolenaar | 2931f2a | 2016-09-09 16:59:08 +0200 | [diff] [blame] | 2551 | bw! |
| 2552 | call delete("Xreadonly.log") |
| 2553 | endfunc |
| 2554 | |
Bram Moolenaar | 1bbb619 | 2018-11-10 16:02:01 +0100 | [diff] [blame] | 2555 | func Test_normal52_rl() |
Bram Moolenaar | 2931f2a | 2016-09-09 16:59:08 +0200 | [diff] [blame] | 2556 | if !has("rightleft") |
| 2557 | return |
| 2558 | endif |
| 2559 | new |
| 2560 | call setline(1, 'abcde fghij klmnopq') |
| 2561 | norm! 1gg$ |
| 2562 | set rl |
| 2563 | call assert_equal(19, col('.')) |
| 2564 | call feedkeys('l', 'tx') |
| 2565 | call assert_equal(18, col('.')) |
| 2566 | call feedkeys('h', 'tx') |
| 2567 | call assert_equal(19, col('.')) |
| 2568 | call feedkeys("\<right>", 'tx') |
| 2569 | call assert_equal(18, col('.')) |
Bram Moolenaar | 1671f44 | 2020-03-10 07:48:13 +0100 | [diff] [blame] | 2570 | call feedkeys("\<left>", 'tx') |
| 2571 | call assert_equal(19, col('.')) |
Bram Moolenaar | 2931f2a | 2016-09-09 16:59:08 +0200 | [diff] [blame] | 2572 | call feedkeys("\<s-right>", 'tx') |
| 2573 | call assert_equal(13, col('.')) |
| 2574 | call feedkeys("\<c-right>", 'tx') |
| 2575 | call assert_equal(7, col('.')) |
| 2576 | call feedkeys("\<c-left>", 'tx') |
| 2577 | call assert_equal(13, col('.')) |
| 2578 | call feedkeys("\<s-left>", 'tx') |
| 2579 | call assert_equal(19, col('.')) |
| 2580 | call feedkeys("<<", 'tx') |
| 2581 | call assert_equal(' abcde fghij klmnopq',getline(1)) |
| 2582 | call feedkeys(">>", 'tx') |
| 2583 | call assert_equal('abcde fghij klmnopq',getline(1)) |
| 2584 | |
| 2585 | " cleanup |
| 2586 | set norl |
| 2587 | bw! |
| 2588 | endfunc |
| 2589 | |
Bram Moolenaar | 1bbb619 | 2018-11-10 16:02:01 +0100 | [diff] [blame] | 2590 | func Test_normal53_digraph() |
Bram Moolenaar | 2931f2a | 2016-09-09 16:59:08 +0200 | [diff] [blame] | 2591 | if !has('digraphs') |
| 2592 | return |
| 2593 | endif |
| 2594 | new |
| 2595 | call setline(1, 'abcdefgh|') |
| 2596 | exe "norm! 1gg0f\<c-k>!!" |
| 2597 | call assert_equal(9, col('.')) |
| 2598 | set cpo+=D |
| 2599 | exe "norm! 1gg0f\<c-k>!!" |
| 2600 | call assert_equal(1, col('.')) |
| 2601 | |
| 2602 | set cpo-=D |
| 2603 | bw! |
| 2604 | endfunc |
| 2605 | |
Bram Moolenaar | b1e04fc | 2017-03-29 13:08:35 +0200 | [diff] [blame] | 2606 | func Test_normal54_Ctrl_bsl() |
| 2607 | new |
| 2608 | call setline(1, 'abcdefghijklmn') |
| 2609 | exe "norm! df\<c-\>\<c-n>" |
| 2610 | call assert_equal(['abcdefghijklmn'], getline(1,'$')) |
| 2611 | exe "norm! df\<c-\>\<c-g>" |
| 2612 | call assert_equal(['abcdefghijklmn'], getline(1,'$')) |
| 2613 | exe "norm! df\<c-\>m" |
| 2614 | call assert_equal(['abcdefghijklmn'], getline(1,'$')) |
Bram Moolenaar | 30276f2 | 2019-01-24 17:59:39 +0100 | [diff] [blame] | 2615 | |
Bram Moolenaar | b1e04fc | 2017-03-29 13:08:35 +0200 | [diff] [blame] | 2616 | call setline(2, 'abcdefghijklmnāf') |
| 2617 | norm! 2gg0 |
| 2618 | exe "norm! df\<Char-0x101>" |
| 2619 | call assert_equal(['abcdefghijklmn', 'f'], getline(1,'$')) |
| 2620 | norm! 1gg0 |
| 2621 | exe "norm! df\<esc>" |
| 2622 | call assert_equal(['abcdefghijklmn', 'f'], getline(1,'$')) |
Bram Moolenaar | 2931f2a | 2016-09-09 16:59:08 +0200 | [diff] [blame] | 2623 | |
Bram Moolenaar | b1e04fc | 2017-03-29 13:08:35 +0200 | [diff] [blame] | 2624 | " clean up |
| 2625 | bw! |
| 2626 | endfunc |
| 2627 | |
| 2628 | func Test_normal_large_count() |
| 2629 | " This may fail with 32bit long, how do we detect that? |
| 2630 | new |
| 2631 | normal o |
| 2632 | normal 6666666666dL |
| 2633 | bwipe! |
Bram Moolenaar | 2931f2a | 2016-09-09 16:59:08 +0200 | [diff] [blame] | 2634 | endfunc |
Bram Moolenaar | bf3d580 | 2017-03-29 19:48:11 +0200 | [diff] [blame] | 2635 | |
| 2636 | func Test_delete_until_paragraph() |
Bram Moolenaar | bf3d580 | 2017-03-29 19:48:11 +0200 | [diff] [blame] | 2637 | new |
| 2638 | normal grádv} |
| 2639 | call assert_equal('á', getline(1)) |
| 2640 | normal grád} |
| 2641 | call assert_equal('', getline(1)) |
| 2642 | bwipe! |
| 2643 | endfunc |
Bram Moolenaar | fb094e1 | 2017-11-05 20:59:28 +0100 | [diff] [blame] | 2644 | |
| 2645 | " Test for the gr (virtual replace) command |
| 2646 | " Test for the bug fixed by 7.4.387 |
| 2647 | func Test_gr_command() |
| 2648 | enew! |
| 2649 | let save_cpo = &cpo |
| 2650 | call append(0, ['First line', 'Second line', 'Third line']) |
| 2651 | exe "normal i\<C-G>u" |
| 2652 | call cursor(2, 1) |
| 2653 | set cpo-=X |
| 2654 | normal 4gro |
| 2655 | call assert_equal('oooond line', getline(2)) |
| 2656 | undo |
| 2657 | set cpo+=X |
| 2658 | normal 4gro |
| 2659 | call assert_equal('ooooecond line', getline(2)) |
| 2660 | let &cpo = save_cpo |
Bram Moolenaar | f5f1e10 | 2020-03-08 05:13:15 +0100 | [diff] [blame] | 2661 | normal! ggvegrx |
| 2662 | call assert_equal('xxxxx line', getline(1)) |
| 2663 | exe "normal! gggr\<C-V>122" |
| 2664 | call assert_equal('zxxxx line', getline(1)) |
| 2665 | set virtualedit=all |
| 2666 | normal! 15|grl |
| 2667 | call assert_equal('zxxxx line l', getline(1)) |
| 2668 | set virtualedit& |
| 2669 | set nomodifiable |
| 2670 | call assert_fails('normal! grx', 'E21:') |
| 2671 | call assert_fails('normal! gRx', 'E21:') |
| 2672 | set modifiable& |
Bram Moolenaar | fb094e1 | 2017-11-05 20:59:28 +0100 | [diff] [blame] | 2673 | enew! |
| 2674 | endfunc |
| 2675 | |
| 2676 | " When splitting a window the changelist position is wrong. |
| 2677 | " Test the changelist position after splitting a window. |
| 2678 | " Test for the bug fixed by 7.4.386 |
| 2679 | func Test_changelist() |
| 2680 | let save_ul = &ul |
| 2681 | enew! |
| 2682 | call append('$', ['1', '2']) |
| 2683 | exe "normal i\<C-G>u" |
| 2684 | exe "normal Gkylpa\<C-G>u" |
| 2685 | set ul=100 |
| 2686 | exe "normal Gylpa\<C-G>u" |
| 2687 | set ul=100 |
| 2688 | normal gg |
| 2689 | vsplit |
| 2690 | normal g; |
| 2691 | call assert_equal([3, 2], [line('.'), col('.')]) |
| 2692 | normal g; |
| 2693 | call assert_equal([2, 2], [line('.'), col('.')]) |
| 2694 | call assert_fails('normal g;', 'E662:') |
Bram Moolenaar | 1671f44 | 2020-03-10 07:48:13 +0100 | [diff] [blame] | 2695 | new |
| 2696 | call assert_fails('normal g;', 'E664:') |
Bram Moolenaar | fb094e1 | 2017-11-05 20:59:28 +0100 | [diff] [blame] | 2697 | %bwipe! |
| 2698 | let &ul = save_ul |
| 2699 | endfunc |
Bram Moolenaar | 1bbb619 | 2018-11-10 16:02:01 +0100 | [diff] [blame] | 2700 | |
| 2701 | func Test_nv_hat_count() |
| 2702 | %bwipeout! |
| 2703 | let l:nr = bufnr('%') + 1 |
| 2704 | call assert_fails(':execute "normal! ' . l:nr . '\<C-^>"', 'E92') |
| 2705 | |
| 2706 | edit Xfoo |
| 2707 | let l:foo_nr = bufnr('Xfoo') |
| 2708 | |
| 2709 | edit Xbar |
| 2710 | let l:bar_nr = bufnr('Xbar') |
| 2711 | |
| 2712 | " Make sure we are not just using the alternate file. |
| 2713 | edit Xbaz |
| 2714 | |
| 2715 | call feedkeys(l:foo_nr . "\<C-^>", 'tx') |
| 2716 | call assert_equal('Xfoo', fnamemodify(bufname('%'), ':t')) |
| 2717 | |
| 2718 | call feedkeys(l:bar_nr . "\<C-^>", 'tx') |
| 2719 | call assert_equal('Xbar', fnamemodify(bufname('%'), ':t')) |
| 2720 | |
| 2721 | %bwipeout! |
| 2722 | endfunc |
Bram Moolenaar | a84a3dd | 2019-03-25 22:21:24 +0100 | [diff] [blame] | 2723 | |
| 2724 | func Test_message_when_using_ctrl_c() |
Bram Moolenaar | 553e5a5 | 2019-03-25 23:16:34 +0100 | [diff] [blame] | 2725 | " Make sure no buffers are changed. |
| 2726 | %bwipe! |
| 2727 | |
Bram Moolenaar | a84a3dd | 2019-03-25 22:21:24 +0100 | [diff] [blame] | 2728 | exe "normal \<C-C>" |
| 2729 | call assert_match("Type :qa and press <Enter> to exit Vim", Screenline(&lines)) |
Bram Moolenaar | 553e5a5 | 2019-03-25 23:16:34 +0100 | [diff] [blame] | 2730 | |
Bram Moolenaar | a84a3dd | 2019-03-25 22:21:24 +0100 | [diff] [blame] | 2731 | new |
| 2732 | cal setline(1, 'hi!') |
| 2733 | exe "normal \<C-C>" |
| 2734 | call assert_match("Type :qa! and press <Enter> to abandon all changes and exit Vim", Screenline(&lines)) |
Bram Moolenaar | 553e5a5 | 2019-03-25 23:16:34 +0100 | [diff] [blame] | 2735 | |
Bram Moolenaar | a84a3dd | 2019-03-25 22:21:24 +0100 | [diff] [blame] | 2736 | bwipe! |
| 2737 | endfunc |
Bram Moolenaar | c6b37db | 2019-04-27 18:00:34 +0200 | [diff] [blame] | 2738 | |
| 2739 | " Test for '[m', ']m', '[M' and ']M' |
| 2740 | " Jumping to beginning and end of methods in Java-like languages |
| 2741 | func Test_java_motion() |
| 2742 | new |
Bram Moolenaar | 1671f44 | 2020-03-10 07:48:13 +0100 | [diff] [blame] | 2743 | call assert_beeps('normal! [m') |
| 2744 | call assert_beeps('normal! ]m') |
| 2745 | call assert_beeps('normal! [M') |
| 2746 | call assert_beeps('normal! ]M') |
Bram Moolenaar | c6b37db | 2019-04-27 18:00:34 +0200 | [diff] [blame] | 2747 | a |
| 2748 | Piece of Java |
| 2749 | { |
| 2750 | tt m1 { |
| 2751 | t1; |
| 2752 | } e1 |
| 2753 | |
| 2754 | tt m2 { |
| 2755 | t2; |
| 2756 | } e2 |
| 2757 | |
| 2758 | tt m3 { |
| 2759 | if (x) |
| 2760 | { |
| 2761 | t3; |
| 2762 | } |
| 2763 | } e3 |
| 2764 | } |
| 2765 | . |
| 2766 | |
| 2767 | normal gg |
| 2768 | |
| 2769 | normal 2]maA |
| 2770 | call assert_equal("\ttt m1 {A", getline('.')) |
| 2771 | call assert_equal([3, 9, 16], [line('.'), col('.'), virtcol('.')]) |
| 2772 | |
| 2773 | normal j]maB |
| 2774 | call assert_equal("\ttt m2 {B", getline('.')) |
| 2775 | call assert_equal([7, 9, 16], [line('.'), col('.'), virtcol('.')]) |
| 2776 | |
| 2777 | normal ]maC |
| 2778 | call assert_equal("\ttt m3 {C", getline('.')) |
| 2779 | call assert_equal([11, 9, 16], [line('.'), col('.'), virtcol('.')]) |
| 2780 | |
| 2781 | normal [maD |
| 2782 | call assert_equal("\ttt m3 {DC", getline('.')) |
| 2783 | call assert_equal([11, 9, 16], [line('.'), col('.'), virtcol('.')]) |
| 2784 | |
| 2785 | normal k2[maE |
| 2786 | call assert_equal("\ttt m1 {EA", getline('.')) |
| 2787 | call assert_equal([3, 9, 16], [line('.'), col('.'), virtcol('.')]) |
| 2788 | |
| 2789 | normal 3[maF |
| 2790 | call assert_equal("{F", getline('.')) |
| 2791 | call assert_equal([2, 2, 2], [line('.'), col('.'), virtcol('.')]) |
| 2792 | |
| 2793 | normal ]MaG |
| 2794 | call assert_equal("\t}G e1", getline('.')) |
| 2795 | call assert_equal([5, 3, 10], [line('.'), col('.'), virtcol('.')]) |
| 2796 | |
| 2797 | normal j2]MaH |
| 2798 | call assert_equal("\t}H e3", getline('.')) |
| 2799 | call assert_equal([16, 3, 10], [line('.'), col('.'), virtcol('.')]) |
| 2800 | |
| 2801 | normal ]M]M |
| 2802 | normal aI |
| 2803 | call assert_equal("}I", getline('.')) |
| 2804 | call assert_equal([17, 2, 2], [line('.'), col('.'), virtcol('.')]) |
| 2805 | |
| 2806 | normal 2[MaJ |
| 2807 | call assert_equal("\t}JH e3", getline('.')) |
| 2808 | call assert_equal([16, 3, 10], [line('.'), col('.'), virtcol('.')]) |
| 2809 | |
| 2810 | normal k[MaK |
| 2811 | call assert_equal("\t}K e2", getline('.')) |
| 2812 | call assert_equal([9, 3, 10], [line('.'), col('.'), virtcol('.')]) |
| 2813 | |
| 2814 | normal 3[MaL |
| 2815 | call assert_equal("{LF", getline('.')) |
| 2816 | call assert_equal([2, 2, 2], [line('.'), col('.'), virtcol('.')]) |
| 2817 | |
| 2818 | close! |
| 2819 | endfunc |
Bram Moolenaar | d5c8234 | 2019-07-27 18:44:57 +0200 | [diff] [blame] | 2820 | |
Bram Moolenaar | 1671f44 | 2020-03-10 07:48:13 +0100 | [diff] [blame] | 2821 | func Test_normal_gdollar_cmd() |
Bram Moolenaar | d5c8234 | 2019-07-27 18:44:57 +0200 | [diff] [blame] | 2822 | if !has("jumplist") |
| 2823 | return |
| 2824 | endif |
| 2825 | " Tests for g cmds |
| 2826 | call Setup_NewWindow() |
| 2827 | " Make long lines that will wrap |
| 2828 | %s/$/\=repeat(' foobar', 10)/ |
| 2829 | 20vsp |
| 2830 | set wrap |
| 2831 | " Test for g$ with count |
| 2832 | norm! gg |
| 2833 | norm! 0vg$y |
| 2834 | call assert_equal(20, col("'>")) |
| 2835 | call assert_equal('1 foobar foobar foob', getreg(0)) |
| 2836 | norm! gg |
| 2837 | norm! 0v4g$y |
| 2838 | call assert_equal(72, col("'>")) |
| 2839 | call assert_equal('1 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar'.."\n", getreg(0)) |
| 2840 | norm! gg |
| 2841 | norm! 0v6g$y |
| 2842 | call assert_equal(40, col("'>")) |
| 2843 | call assert_equal('1 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar'.. "\n".. |
| 2844 | \ '2 foobar foobar foobar foobar foobar foo', getreg(0)) |
| 2845 | set nowrap |
| 2846 | " clean up |
| 2847 | norm! gg |
| 2848 | norm! 0vg$y |
| 2849 | call assert_equal(20, col("'>")) |
| 2850 | call assert_equal('1 foobar foobar foob', getreg(0)) |
| 2851 | norm! gg |
| 2852 | norm! 0v4g$y |
| 2853 | call assert_equal(20, col("'>")) |
| 2854 | call assert_equal('1 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar'.. "\n".. |
| 2855 | \ '2 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar'.. "\n".. |
| 2856 | \ '3 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar'.. "\n".. |
| 2857 | \ '4 foobar foobar foob', getreg(0)) |
| 2858 | norm! gg |
| 2859 | norm! 0v6g$y |
| 2860 | call assert_equal(20, col("'>")) |
| 2861 | call assert_equal('1 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar'.. "\n".. |
| 2862 | \ '2 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar'.. "\n".. |
| 2863 | \ '3 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar'.. "\n".. |
| 2864 | \ '4 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar'.. "\n".. |
| 2865 | \ '5 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar'.. "\n".. |
| 2866 | \ '6 foobar foobar foob', getreg(0)) |
| 2867 | " Move to last line, also down movement is not possible, should still move |
| 2868 | " the cursor to the last visible char |
| 2869 | norm! G |
| 2870 | norm! 0v6g$y |
| 2871 | call assert_equal(20, col("'>")) |
| 2872 | call assert_equal('100 foobar foobar fo', getreg(0)) |
| 2873 | bw! |
| 2874 | endfunc |
Bram Moolenaar | 03ac52f | 2019-09-24 22:47:46 +0200 | [diff] [blame] | 2875 | |
Bram Moolenaar | f5f1e10 | 2020-03-08 05:13:15 +0100 | [diff] [blame] | 2876 | func Test_normal_gk_gj() |
Bram Moolenaar | 03ac52f | 2019-09-24 22:47:46 +0200 | [diff] [blame] | 2877 | " needs 80 column new window |
| 2878 | new |
| 2879 | vert 80new |
Bram Moolenaar | f5f1e10 | 2020-03-08 05:13:15 +0100 | [diff] [blame] | 2880 | call assert_beeps('normal gk') |
Bram Moolenaar | 03ac52f | 2019-09-24 22:47:46 +0200 | [diff] [blame] | 2881 | put =[repeat('x',90)..' {{{1', 'x {{{1'] |
| 2882 | norm! gk |
| 2883 | " In a 80 column wide terminal the window will be only 78 char |
| 2884 | " (because Vim will leave space for the other window), |
| 2885 | " but if the terminal is larger, it will be 80 chars, so verify the |
| 2886 | " cursor column correctly. |
| 2887 | call assert_equal(winwidth(0)+1, col('.')) |
| 2888 | call assert_equal(winwidth(0)+1, virtcol('.')) |
| 2889 | norm! j |
| 2890 | call assert_equal(6, col('.')) |
| 2891 | call assert_equal(6, virtcol('.')) |
| 2892 | norm! gk |
| 2893 | call assert_equal(95, col('.')) |
| 2894 | call assert_equal(95, virtcol('.')) |
Bram Moolenaar | f5f1e10 | 2020-03-08 05:13:15 +0100 | [diff] [blame] | 2895 | %bw! |
Bram Moolenaar | ceba3dd | 2019-10-12 16:12:54 +0200 | [diff] [blame] | 2896 | |
| 2897 | " needs 80 column new window |
| 2898 | new |
| 2899 | vert 80new |
Bram Moolenaar | f5f1e10 | 2020-03-08 05:13:15 +0100 | [diff] [blame] | 2900 | call assert_beeps('normal gj') |
Bram Moolenaar | ceba3dd | 2019-10-12 16:12:54 +0200 | [diff] [blame] | 2901 | set number |
| 2902 | set numberwidth=10 |
| 2903 | set cpoptions+=n |
| 2904 | put =[repeat('0',90), repeat('1',90)] |
| 2905 | norm! 075l |
| 2906 | call assert_equal(76, col('.')) |
| 2907 | norm! gk |
| 2908 | call assert_equal(1, col('.')) |
| 2909 | norm! gk |
| 2910 | call assert_equal(76, col('.')) |
| 2911 | norm! gk |
| 2912 | call assert_equal(1, col('.')) |
| 2913 | norm! gj |
| 2914 | call assert_equal(76, col('.')) |
| 2915 | norm! gj |
| 2916 | call assert_equal(1, col('.')) |
| 2917 | norm! gj |
| 2918 | call assert_equal(76, col('.')) |
Bram Moolenaar | f5f1e10 | 2020-03-08 05:13:15 +0100 | [diff] [blame] | 2919 | " When 'nowrap' is set, gk and gj behave like k and j |
| 2920 | set nowrap |
| 2921 | normal! gk |
| 2922 | call assert_equal([2, 76], [line('.'), col('.')]) |
| 2923 | normal! gj |
| 2924 | call assert_equal([3, 76], [line('.'), col('.')]) |
| 2925 | %bw! |
| 2926 | set cpoptions& number& numberwidth& wrap& |
Bram Moolenaar | 03ac52f | 2019-09-24 22:47:46 +0200 | [diff] [blame] | 2927 | endfunc |
Bram Moolenaar | f0cee19 | 2020-02-16 13:33:56 +0100 | [diff] [blame] | 2928 | |
| 2929 | " Test for cursor movement with '-' in 'cpoptions' |
| 2930 | func Test_normal_cpo_minus() |
| 2931 | new |
| 2932 | call setline(1, ['foo', 'bar', 'baz']) |
| 2933 | let save_cpo = &cpo |
| 2934 | set cpo+=- |
| 2935 | call assert_beeps('normal 10j') |
| 2936 | call assert_equal(1, line('.')) |
| 2937 | normal G |
| 2938 | call assert_beeps('normal 10k') |
| 2939 | call assert_equal(3, line('.')) |
| 2940 | call assert_fails(10, 'E16:') |
| 2941 | let &cpo = save_cpo |
| 2942 | close! |
| 2943 | endfunc |
Bram Moolenaar | 818fc9a | 2020-02-21 17:54:45 +0100 | [diff] [blame] | 2944 | |
Bram Moolenaar | ca68ae1 | 2020-03-30 19:32:53 +0200 | [diff] [blame^] | 2945 | " Test for displaying dollar when changing text ('$' flag in 'cpoptions') |
| 2946 | func Test_normal_cpo_dollar() |
| 2947 | new |
| 2948 | let g:Line = '' |
| 2949 | func SaveFirstLine() |
| 2950 | let g:Line = Screenline(1) |
| 2951 | return '' |
| 2952 | endfunc |
| 2953 | inoremap <expr> <buffer> <F2> SaveFirstLine() |
| 2954 | call test_override('redraw_flag', 1) |
| 2955 | set cpo+=$ |
| 2956 | call setline(1, 'one two three') |
| 2957 | redraw! |
| 2958 | exe "normal c2w\<F2>vim" |
| 2959 | call assert_equal('one tw$ three', g:Line) |
| 2960 | call assert_equal('vim three', getline(1)) |
| 2961 | set cpo-=$ |
| 2962 | call test_override('ALL', 0) |
| 2963 | delfunc SaveFirstLine |
| 2964 | %bw! |
| 2965 | endfunc |
| 2966 | |
Bram Moolenaar | 818fc9a | 2020-02-21 17:54:45 +0100 | [diff] [blame] | 2967 | " Test for using : to run a multi-line Ex command in operator pending mode |
| 2968 | func Test_normal_yank_with_excmd() |
| 2969 | new |
| 2970 | call setline(1, ['foo', 'bar', 'baz']) |
| 2971 | let @a = '' |
| 2972 | call feedkeys("\"ay:if v:true\<CR>normal l\<CR>endif\<CR>", 'xt') |
| 2973 | call assert_equal('f', @a) |
| 2974 | close! |
| 2975 | endfunc |
Bram Moolenaar | f5f1e10 | 2020-03-08 05:13:15 +0100 | [diff] [blame] | 2976 | |
| 2977 | " Test for supplying a count to a normal-mode command across a cursorhold call |
| 2978 | func Test_normal_cursorhold_with_count() |
| 2979 | func s:cHold() |
| 2980 | let g:cHold_Called += 1 |
| 2981 | endfunc |
| 2982 | new |
| 2983 | augroup normalcHoldTest |
| 2984 | au! |
| 2985 | au CursorHold <buffer> call s:cHold() |
| 2986 | augroup END |
| 2987 | let g:cHold_Called = 0 |
| 2988 | call feedkeys("3\<CursorHold>2ix", 'xt') |
| 2989 | call assert_equal(1, g:cHold_Called) |
| 2990 | call assert_equal(repeat('x', 32), getline(1)) |
| 2991 | augroup normalcHoldTest |
| 2992 | au! |
| 2993 | augroup END |
| 2994 | au! normalcHoldTest |
| 2995 | close! |
| 2996 | delfunc s:cHold |
| 2997 | endfunc |
| 2998 | |
| 2999 | " Test for using a count and a command with CTRL-W |
| 3000 | func Test_wincmd_with_count() |
| 3001 | call feedkeys("\<C-W>12n", 'xt') |
| 3002 | call assert_equal(12, winheight(0)) |
| 3003 | endfunc |
| 3004 | |
| 3005 | " Test for 'b', 'B' 'ge' and 'gE' commands |
Bram Moolenaar | 1671f44 | 2020-03-10 07:48:13 +0100 | [diff] [blame] | 3006 | func Test_horiz_motion() |
| 3007 | new |
Bram Moolenaar | f5f1e10 | 2020-03-08 05:13:15 +0100 | [diff] [blame] | 3008 | normal! gg |
| 3009 | call assert_beeps('normal! b') |
| 3010 | call assert_beeps('normal! B') |
| 3011 | call assert_beeps('normal! gE') |
| 3012 | call assert_beeps('normal! ge') |
Bram Moolenaar | 1671f44 | 2020-03-10 07:48:13 +0100 | [diff] [blame] | 3013 | " <S-Backspace> moves one word left and <C-Backspace> moves one WORD left |
| 3014 | call setline(1, 'one ,two ,three') |
| 3015 | exe "normal! $\<S-BS>" |
| 3016 | call assert_equal(11, col('.')) |
| 3017 | exe "normal! $\<C-BS>" |
| 3018 | call assert_equal(10, col('.')) |
| 3019 | close! |
| 3020 | endfunc |
| 3021 | |
| 3022 | " Test for using a : command in operator pending mode |
| 3023 | func Test_normal_colon_op() |
| 3024 | new |
| 3025 | call setline(1, ['one', 'two']) |
| 3026 | call assert_beeps("normal! Gc:d\<CR>") |
| 3027 | close! |
Bram Moolenaar | f5f1e10 | 2020-03-08 05:13:15 +0100 | [diff] [blame] | 3028 | endfunc |
| 3029 | |
| 3030 | " vim: shiftwidth=2 sts=2 expandtab |