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