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