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