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