Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 1 | " Test for edit functions |
Bram Moolenaar | 215ba3b | 2019-11-06 15:07:07 +0100 | [diff] [blame] | 2 | |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 3 | if exists("+t_kD") |
| 4 | let &t_kD="[3;*~" |
| 5 | endif |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 6 | |
Bram Moolenaar | 215ba3b | 2019-11-06 15:07:07 +0100 | [diff] [blame] | 7 | source check.vim |
| 8 | |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 9 | " Needed for testing basic rightleft: Test_edit_rightleft |
| 10 | source view_util.vim |
| 11 | |
| 12 | " Needs to come first until the bug in getchar() is |
| 13 | " fixed: https://groups.google.com/d/msg/vim_dev/fXL9yme4H4c/bOR-U6_bAQAJ |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 14 | func Test_edit_00b() |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 15 | new |
| 16 | call setline(1, ['abc ']) |
| 17 | inoreabbr <buffer> h here some more |
| 18 | call cursor(1, 4) |
| 19 | " <c-l> expands the abbreviation and ends insertmode |
| 20 | call feedkeys(":set im\<cr> h\<c-l>:set noim\<cr>", 'tix') |
| 21 | call assert_equal(['abc here some more '], getline(1,'$')) |
| 22 | iunabbr <buffer> h |
| 23 | bw! |
| 24 | endfunc |
| 25 | |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 26 | func Test_edit_01() |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 27 | " set for Travis CI? |
| 28 | " set nocp noesckeys |
| 29 | new |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 30 | " 1) empty buffer |
| 31 | call assert_equal([''], getline(1,'$')) |
| 32 | " 2) delete in an empty line |
| 33 | call feedkeys("i\<del>\<esc>", 'tnix') |
| 34 | call assert_equal([''], getline(1,'$')) |
| 35 | %d |
| 36 | " 3) delete one character |
| 37 | call setline(1, 'a') |
| 38 | call feedkeys("i\<del>\<esc>", 'tnix') |
| 39 | call assert_equal([''], getline(1,'$')) |
| 40 | %d |
| 41 | " 4) delete a multibyte character |
Bram Moolenaar | 30276f2 | 2019-01-24 17:59:39 +0100 | [diff] [blame] | 42 | call setline(1, "\u0401") |
| 43 | call feedkeys("i\<del>\<esc>", 'tnix') |
| 44 | call assert_equal([''], getline(1,'$')) |
| 45 | %d |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 46 | " 5.1) delete linebreak with 'bs' option containing eol |
| 47 | let _bs=&bs |
| 48 | set bs=eol |
| 49 | call setline(1, ["abc def", "ghi jkl"]) |
| 50 | call cursor(1, 1) |
| 51 | call feedkeys("A\<del>\<esc>", 'tnix') |
| 52 | call assert_equal(['abc defghi jkl'], getline(1, 2)) |
| 53 | %d |
| 54 | " 5.2) delete linebreak with backspace option w/out eol |
| 55 | set bs= |
| 56 | call setline(1, ["abc def", "ghi jkl"]) |
| 57 | call cursor(1, 1) |
| 58 | call feedkeys("A\<del>\<esc>", 'tnix') |
| 59 | call assert_equal(["abc def", "ghi jkl"], getline(1, 2)) |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 60 | let &bs=_bs |
| 61 | bw! |
| 62 | endfunc |
| 63 | |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 64 | func Test_edit_02() |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 65 | " Change cursor position in InsertCharPre command |
| 66 | new |
| 67 | call setline(1, 'abc') |
| 68 | call cursor(1, 1) |
| 69 | fu! DoIt(...) |
| 70 | call cursor(1, 4) |
| 71 | if len(a:000) |
| 72 | let v:char=a:1 |
| 73 | endif |
| 74 | endfu |
| 75 | au InsertCharPre <buffer> :call DoIt('y') |
| 76 | call feedkeys("ix\<esc>", 'tnix') |
| 77 | call assert_equal(['abcy'], getline(1, '$')) |
| 78 | " Setting <Enter> in InsertCharPre |
| 79 | au! InsertCharPre <buffer> :call DoIt("\n") |
| 80 | call setline(1, 'abc') |
| 81 | call cursor(1, 1) |
| 82 | call feedkeys("ix\<esc>", 'tnix') |
| 83 | call assert_equal(['abc', ''], getline(1, '$')) |
| 84 | %d |
| 85 | au! InsertCharPre |
| 86 | " Change cursor position in InsertEnter command |
| 87 | " 1) when setting v:char, keeps changed cursor position |
| 88 | au! InsertEnter <buffer> :call DoIt('y') |
| 89 | call setline(1, 'abc') |
| 90 | call cursor(1, 1) |
| 91 | call feedkeys("ix\<esc>", 'tnix') |
| 92 | call assert_equal(['abxc'], getline(1, '$')) |
| 93 | " 2) when not setting v:char, restores changed cursor position |
| 94 | au! InsertEnter <buffer> :call DoIt() |
| 95 | call setline(1, 'abc') |
| 96 | call cursor(1, 1) |
| 97 | call feedkeys("ix\<esc>", 'tnix') |
| 98 | call assert_equal(['xabc'], getline(1, '$')) |
| 99 | au! InsertEnter |
| 100 | delfu DoIt |
| 101 | bw! |
| 102 | endfunc |
| 103 | |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 104 | func Test_edit_03() |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 105 | " Change cursor after <c-o> command to end of line |
| 106 | new |
| 107 | call setline(1, 'abc') |
| 108 | call cursor(1, 1) |
| 109 | call feedkeys("i\<c-o>$y\<esc>", 'tnix') |
| 110 | call assert_equal(['abcy'], getline(1, '$')) |
| 111 | %d |
| 112 | call setline(1, 'abc') |
| 113 | call cursor(1, 1) |
| 114 | call feedkeys("i\<c-o>80|y\<esc>", 'tnix') |
| 115 | call assert_equal(['abcy'], getline(1, '$')) |
| 116 | %d |
| 117 | call setline(1, 'abc') |
| 118 | call feedkeys("Ad\<c-o>:s/$/efg/\<cr>hij", 'tnix') |
| 119 | call assert_equal(['hijabcdefg'], getline(1, '$')) |
| 120 | bw! |
| 121 | endfunc |
| 122 | |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 123 | func Test_edit_04() |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 124 | " test for :stopinsert |
| 125 | new |
| 126 | call setline(1, 'abc') |
| 127 | call cursor(1, 1) |
| 128 | call feedkeys("i\<c-o>:stopinsert\<cr>$", 'tnix') |
| 129 | call feedkeys("aX\<esc>", 'tnix') |
| 130 | call assert_equal(['abcX'], getline(1, '$')) |
| 131 | %d |
| 132 | bw! |
| 133 | endfunc |
| 134 | |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 135 | func Test_edit_05() |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 136 | " test for folds being opened |
| 137 | new |
| 138 | call setline(1, ['abcX', 'abcX', 'zzzZ']) |
| 139 | call cursor(1, 1) |
| 140 | set foldmethod=manual foldopen+=insert |
| 141 | " create fold for those two lines |
| 142 | norm! Vjzf |
| 143 | call feedkeys("$ay\<esc>", 'tnix') |
| 144 | call assert_equal(['abcXy', 'abcX', 'zzzZ'], getline(1, '$')) |
| 145 | %d |
| 146 | call setline(1, ['abcX', 'abcX', 'zzzZ']) |
| 147 | call cursor(1, 1) |
| 148 | set foldmethod=manual foldopen-=insert |
| 149 | " create fold for those two lines |
| 150 | norm! Vjzf |
| 151 | call feedkeys("$ay\<esc>", 'tnix') |
| 152 | call assert_equal(['abcXy', 'abcX', 'zzzZ'], getline(1, '$')) |
| 153 | %d |
| 154 | bw! |
| 155 | endfunc |
| 156 | |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 157 | func Test_edit_06() |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 158 | " Test in diff mode |
Bram Moolenaar | 6d91bcb | 2020-08-12 18:50:36 +0200 | [diff] [blame] | 159 | CheckFeature diff |
| 160 | CheckExecutable diff |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 161 | new |
| 162 | call setline(1, ['abc', 'xxx', 'yyy']) |
| 163 | vnew |
| 164 | call setline(1, ['abc', 'zzz', 'xxx', 'yyy']) |
| 165 | wincmd p |
| 166 | diffthis |
| 167 | wincmd p |
| 168 | diffthis |
| 169 | wincmd p |
| 170 | call cursor(2, 1) |
| 171 | norm! zt |
| 172 | call feedkeys("Ozzz\<esc>", 'tnix') |
| 173 | call assert_equal(['abc', 'zzz', 'xxx', 'yyy'], getline(1,'$')) |
| 174 | bw! |
| 175 | bw! |
| 176 | endfunc |
| 177 | |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 178 | func Test_edit_07() |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 179 | " 1) Test with completion <c-l> when popupmenu is visible |
| 180 | new |
| 181 | call setline(1, 'J') |
| 182 | |
| 183 | func! ListMonths() |
| 184 | call complete(col('.')-1, ['January', 'February', 'March', |
| 185 | \ 'April', 'May', 'June', 'July', 'August', 'September', |
| 186 | \ 'October', 'November', 'December']) |
| 187 | return '' |
| 188 | endfunc |
| 189 | inoremap <buffer> <F5> <C-R>=ListMonths()<CR> |
| 190 | |
| 191 | call feedkeys("A\<f5>\<c-p>". repeat("\<down>", 6)."\<c-l>\<down>\<c-l>\<cr>", 'tx') |
| 192 | call assert_equal(['July'], getline(1,'$')) |
| 193 | " 1) Test completion when InsertCharPre kicks in |
| 194 | %d |
| 195 | call setline(1, 'J') |
| 196 | fu! DoIt() |
| 197 | if v:char=='u' |
| 198 | let v:char='an' |
| 199 | endif |
| 200 | endfu |
| 201 | au InsertCharPre <buffer> :call DoIt() |
| 202 | call feedkeys("A\<f5>\<c-p>u\<cr>\<c-l>\<cr>", 'tx') |
Bram Moolenaar | 4c313b1 | 2019-08-24 22:58:31 +0200 | [diff] [blame] | 203 | call assert_equal(["Jan\<c-l>",''], 1->getline('$')) |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 204 | %d |
| 205 | call setline(1, 'J') |
| 206 | call feedkeys("A\<f5>\<c-p>u\<down>\<c-l>\<cr>", 'tx') |
Bram Moolenaar | 4c313b1 | 2019-08-24 22:58:31 +0200 | [diff] [blame] | 207 | call assert_equal(["January"], 1->getline('$')) |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 208 | |
| 209 | delfu ListMonths |
| 210 | delfu DoIt |
| 211 | iunmap <buffer> <f5> |
| 212 | bw! |
| 213 | endfunc |
| 214 | |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 215 | func Test_edit_08() |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 216 | " reset insertmode from i_ctrl-r_= |
Bram Moolenaar | 2a45d64 | 2017-10-27 01:35:00 +0200 | [diff] [blame] | 217 | let g:bufnr = bufnr('%') |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 218 | new |
| 219 | call setline(1, ['abc']) |
| 220 | call cursor(1, 4) |
Bram Moolenaar | 2a45d64 | 2017-10-27 01:35:00 +0200 | [diff] [blame] | 221 | call feedkeys(":set im\<cr>ZZZ\<c-r>=setbufvar(g:bufnr,'&im', 0)\<cr>",'tnix') |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 222 | call assert_equal(['abZZZc'], getline(1,'$')) |
| 223 | call assert_equal([0, 1, 1, 0], getpos('.')) |
| 224 | call assert_false(0, '&im') |
| 225 | bw! |
Bram Moolenaar | 2a45d64 | 2017-10-27 01:35:00 +0200 | [diff] [blame] | 226 | unlet g:bufnr |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 227 | endfunc |
| 228 | |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 229 | func Test_edit_09() |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 230 | " test i_CTRL-\ combinations |
| 231 | new |
| 232 | call setline(1, ['abc', 'def', 'ghi']) |
| 233 | call cursor(1, 1) |
| 234 | " 1) CTRL-\ CTLR-N |
| 235 | call feedkeys(":set im\<cr>\<c-\>\<c-n>ccABC\<c-l>", 'txin') |
| 236 | call assert_equal(['ABC', 'def', 'ghi'], getline(1,'$')) |
| 237 | call setline(1, ['ABC', 'def', 'ghi']) |
| 238 | " 2) CTRL-\ CTLR-G |
| 239 | call feedkeys("j0\<c-\>\<c-g>ZZZ\<cr>\<c-l>", 'txin') |
| 240 | call assert_equal(['ABC', 'ZZZ', 'def', 'ghi'], getline(1,'$')) |
| 241 | call feedkeys("I\<c-\>\<c-g>YYY\<c-l>", 'txin') |
| 242 | call assert_equal(['ABC', 'ZZZ', 'YYYdef', 'ghi'], getline(1,'$')) |
| 243 | set noinsertmode |
| 244 | " 3) CTRL-\ CTRL-O |
| 245 | call setline(1, ['ABC', 'ZZZ', 'def', 'ghi']) |
| 246 | call cursor(1, 1) |
| 247 | call feedkeys("A\<c-o>ix", 'txin') |
| 248 | call assert_equal(['ABxC', 'ZZZ', 'def', 'ghi'], getline(1,'$')) |
| 249 | call feedkeys("A\<c-\>\<c-o>ix", 'txin') |
| 250 | call assert_equal(['ABxCx', 'ZZZ', 'def', 'ghi'], getline(1,'$')) |
| 251 | " 4) CTRL-\ a (should be inserted literally, not special after <c-\> |
| 252 | call setline(1, ['ABC', 'ZZZ', 'def', 'ghi']) |
| 253 | call cursor(1, 1) |
| 254 | call feedkeys("A\<c-\>a", 'txin') |
| 255 | call assert_equal(["ABC\<c-\>a", 'ZZZ', 'def', 'ghi'], getline(1, '$')) |
| 256 | bw! |
| 257 | endfunc |
| 258 | |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 259 | func Test_edit_11() |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 260 | " Test that indenting kicks in |
| 261 | new |
| 262 | set cindent |
| 263 | call setline(1, ['{', '', '']) |
| 264 | call cursor(2, 1) |
| 265 | call feedkeys("i\<c-f>int c;\<esc>", 'tnix') |
| 266 | call cursor(3, 1) |
Bram Moolenaar | 1671f44 | 2020-03-10 07:48:13 +0100 | [diff] [blame] | 267 | call feedkeys("\<Insert>/* comment */", 'tnix') |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 268 | call assert_equal(['{', "\<tab>int c;", "/* comment */"], getline(1, '$')) |
| 269 | " added changed cindentkeys slightly |
| 270 | set cindent cinkeys+=*/ |
| 271 | call setline(1, ['{', '', '']) |
| 272 | call cursor(2, 1) |
| 273 | call feedkeys("i\<c-f>int c;\<esc>", 'tnix') |
| 274 | call cursor(3, 1) |
| 275 | call feedkeys("i/* comment */", 'tnix') |
| 276 | call assert_equal(['{', "\<tab>int c;", "\<tab>/* comment */"], getline(1, '$')) |
| 277 | set cindent cinkeys+==end |
| 278 | call feedkeys("oend\<cr>\<esc>", 'tnix') |
| 279 | call assert_equal(['{', "\<tab>int c;", "\<tab>/* comment */", "\tend", ''], getline(1, '$')) |
| 280 | set cinkeys-==end |
| 281 | %d |
| 282 | " Use indentexpr instead of cindenting |
| 283 | func! Do_Indent() |
| 284 | if v:lnum == 3 |
| 285 | return 3*shiftwidth() |
| 286 | else |
| 287 | return 2*shiftwidth() |
| 288 | endif |
| 289 | endfunc |
| 290 | setl indentexpr=Do_Indent() indentkeys+=*/ |
| 291 | call setline(1, ['{', '', '']) |
| 292 | call cursor(2, 1) |
| 293 | call feedkeys("i\<c-f>int c;\<esc>", 'tnix') |
| 294 | call cursor(3, 1) |
| 295 | call feedkeys("i/* comment */", 'tnix') |
| 296 | call assert_equal(['{', "\<tab>\<tab>int c;", "\<tab>\<tab>\<tab>/* comment */"], getline(1, '$')) |
| 297 | set cinkeys&vim indentkeys&vim |
| 298 | set nocindent indentexpr= |
| 299 | delfu Do_Indent |
| 300 | bw! |
| 301 | endfunc |
| 302 | |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 303 | func Test_edit_11_indentexpr() |
Bram Moolenaar | 1b38344 | 2017-09-26 20:04:54 +0200 | [diff] [blame] | 304 | " Test that indenting kicks in |
| 305 | new |
| 306 | " Use indentexpr instead of cindenting |
| 307 | func! Do_Indent() |
| 308 | let pline=prevnonblank(v:lnum) |
| 309 | if empty(getline(v:lnum)) |
| 310 | if getline(pline) =~ 'if\|then' |
| 311 | return shiftwidth() |
| 312 | else |
| 313 | return 0 |
| 314 | endif |
| 315 | else |
| 316 | return 0 |
| 317 | endif |
| 318 | endfunc |
| 319 | setl indentexpr=Do_Indent() indentkeys+=0=then,0=fi |
| 320 | call setline(1, ['if [ $this ]']) |
| 321 | call cursor(1, 1) |
| 322 | call feedkeys("othen\<cr>that\<cr>fi", 'tnix') |
| 323 | call assert_equal(['if [ $this ]', "then", "\<tab>that", "fi"], getline(1, '$')) |
| 324 | set cinkeys&vim indentkeys&vim |
| 325 | set nocindent indentexpr= |
| 326 | delfu Do_Indent |
| 327 | bw! |
| 328 | endfunc |
| 329 | |
Bram Moolenaar | f9ab52e | 2020-05-05 19:57:18 +0200 | [diff] [blame] | 330 | " Test changing indent in replace mode |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 331 | func Test_edit_12() |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 332 | new |
| 333 | call setline(1, ["\tabc", "\tdef"]) |
| 334 | call cursor(2, 4) |
| 335 | call feedkeys("R^\<c-d>", 'tnix') |
| 336 | call assert_equal(["\tabc", "def"], getline(1, '$')) |
Bram Moolenaar | 4c313b1 | 2019-08-24 22:58:31 +0200 | [diff] [blame] | 337 | call assert_equal([0, 2, 2, 0], '.'->getpos()) |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 338 | %d |
| 339 | call setline(1, ["\tabc", "\t\tdef"]) |
| 340 | call cursor(2, 2) |
| 341 | call feedkeys("R^\<c-d>", 'tnix') |
| 342 | call assert_equal(["\tabc", "def"], getline(1, '$')) |
| 343 | call assert_equal([0, 2, 1, 0], getpos('.')) |
| 344 | %d |
| 345 | call setline(1, ["\tabc", "\t\tdef"]) |
| 346 | call cursor(2, 2) |
| 347 | call feedkeys("R\<c-t>", 'tnix') |
| 348 | call assert_equal(["\tabc", "\t\t\tdef"], getline(1, '$')) |
| 349 | call assert_equal([0, 2, 2, 0], getpos('.')) |
| 350 | bw! |
| 351 | 10vnew |
| 352 | call setline(1, ["\tabc", "\t\tdef"]) |
| 353 | call cursor(2, 2) |
| 354 | call feedkeys("R\<c-t>", 'tnix') |
| 355 | call assert_equal(["\tabc", "\t\t\tdef"], getline(1, '$')) |
| 356 | call assert_equal([0, 2, 2, 0], getpos('.')) |
| 357 | %d |
| 358 | set sw=4 |
| 359 | call setline(1, ["\tabc", "\t\tdef"]) |
| 360 | call cursor(2, 2) |
| 361 | call feedkeys("R\<c-t>\<c-t>", 'tnix') |
| 362 | call assert_equal(["\tabc", "\t\t\tdef"], getline(1, '$')) |
| 363 | call assert_equal([0, 2, 2, 0], getpos('.')) |
| 364 | %d |
| 365 | call setline(1, ["\tabc", "\t\tdef"]) |
| 366 | call cursor(2, 2) |
| 367 | call feedkeys("R\<c-t>\<c-t>", 'tnix') |
| 368 | call assert_equal(["\tabc", "\t\t\tdef"], getline(1, '$')) |
| 369 | call assert_equal([0, 2, 2, 0], getpos('.')) |
Bram Moolenaar | f9ab52e | 2020-05-05 19:57:18 +0200 | [diff] [blame] | 370 | set sw& |
| 371 | |
| 372 | " In replace mode, after hitting enter in a line with tab characters, |
| 373 | " pressing backspace should restore the tab characters. |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 374 | %d |
Bram Moolenaar | f9ab52e | 2020-05-05 19:57:18 +0200 | [diff] [blame] | 375 | setlocal autoindent backspace=2 |
| 376 | call setline(1, "\tone\t\ttwo") |
| 377 | exe "normal ggRred\<CR>six" .. repeat("\<BS>", 8) |
| 378 | call assert_equal(["\tone\t\ttwo"], getline(1, '$')) |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 379 | bw! |
| 380 | endfunc |
| 381 | |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 382 | func Test_edit_13() |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 383 | " Test smartindenting |
| 384 | if exists("+smartindent") |
| 385 | new |
| 386 | set smartindent autoindent |
| 387 | call setline(1, ["\tabc"]) |
| 388 | call feedkeys("A {\<cr>more\<cr>}\<esc>", 'tnix') |
| 389 | call assert_equal(["\tabc {", "\t\tmore", "\t}"], getline(1, '$')) |
| 390 | set smartindent& autoindent& |
Bram Moolenaar | 2ba4238 | 2019-03-16 18:11:07 +0100 | [diff] [blame] | 391 | bwipe! |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 392 | endif |
Bram Moolenaar | 2ba4238 | 2019-03-16 18:11:07 +0100 | [diff] [blame] | 393 | |
| 394 | " Test autoindent removing indent of blank line. |
| 395 | new |
| 396 | call setline(1, ' foo bar baz') |
| 397 | set autoindent |
| 398 | exe "normal 0eea\<CR>\<CR>\<Esc>" |
| 399 | call assert_equal(" foo bar", getline(1)) |
| 400 | call assert_equal("", getline(2)) |
| 401 | call assert_equal(" baz", getline(3)) |
| 402 | set autoindent& |
Bram Moolenaar | 845e0ee | 2020-06-20 16:05:32 +0200 | [diff] [blame] | 403 | |
| 404 | " pressing <C-U> to erase line should keep the indent with 'autoindent' |
| 405 | set backspace=2 autoindent |
| 406 | %d |
| 407 | exe "normal i\tone\<CR>three\<C-U>two" |
| 408 | call assert_equal(["\tone", "\ttwo"], getline(1, '$')) |
| 409 | set backspace& autoindent& |
| 410 | |
Bram Moolenaar | 2ba4238 | 2019-03-16 18:11:07 +0100 | [diff] [blame] | 411 | bwipe! |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 412 | endfunc |
| 413 | |
Bram Moolenaar | 1f448d9 | 2021-03-22 19:37:06 +0100 | [diff] [blame] | 414 | " Test for autoindent removing indent when insert mode is stopped. Some parts |
| 415 | " of the code is exercised only when interactive mode is used. So use Vim in a |
| 416 | " terminal. |
| 417 | func Test_autoindent_remove_indent() |
| 418 | CheckRunVimInTerminal |
| 419 | let buf = RunVimInTerminal('-N Xfile', {'rows': 6, 'cols' : 20}) |
| 420 | call TermWait(buf) |
| 421 | call term_sendkeys(buf, ":set autoindent\n") |
| 422 | " leaving insert mode in a new line with indent added by autoindent, should |
| 423 | " remove the indent. |
| 424 | call term_sendkeys(buf, "i\<Tab>foo\<CR>\<Esc>") |
Dominique Pelle | 923dce2 | 2021-11-21 11:36:04 +0000 | [diff] [blame] | 425 | " Need to delay for some time, otherwise the code in getchar.c will not be |
Bram Moolenaar | 1f448d9 | 2021-03-22 19:37:06 +0100 | [diff] [blame] | 426 | " exercised. |
| 427 | call TermWait(buf, 50) |
| 428 | " when a line is wrapped and the cursor is at the start of the second line, |
| 429 | " leaving insert mode, should move the cursor back to the first line. |
| 430 | call term_sendkeys(buf, "o" .. repeat('x', 20) .. "\<Esc>") |
Dominique Pelle | 923dce2 | 2021-11-21 11:36:04 +0000 | [diff] [blame] | 431 | " Need to delay for some time, otherwise the code in getchar.c will not be |
Bram Moolenaar | 1f448d9 | 2021-03-22 19:37:06 +0100 | [diff] [blame] | 432 | " exercised. |
| 433 | call TermWait(buf, 50) |
| 434 | call term_sendkeys(buf, ":w\n") |
| 435 | call TermWait(buf) |
| 436 | call StopVimInTerminal(buf) |
| 437 | call assert_equal(["\tfoo", '', repeat('x', 20)], readfile('Xfile')) |
| 438 | call delete('Xfile') |
| 439 | endfunc |
| 440 | |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 441 | func Test_edit_CR() |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 442 | " Test for <CR> in insert mode |
Dominique Pelle | 923dce2 | 2021-11-21 11:36:04 +0000 | [diff] [blame] | 443 | " basically only in quickfix mode it's tested, the rest |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 444 | " has been taken care of by other tests |
Bram Moolenaar | 6d91bcb | 2020-08-12 18:50:36 +0200 | [diff] [blame] | 445 | CheckFeature quickfix |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 446 | botright new |
| 447 | call writefile(range(1, 10), 'Xqflist.txt') |
| 448 | call setqflist([{'filename': 'Xqflist.txt', 'lnum': 2}]) |
| 449 | copen |
| 450 | set modifiable |
| 451 | call feedkeys("A\<cr>", 'tnix') |
| 452 | call assert_equal('Xqflist.txt', bufname('')) |
| 453 | call assert_equal(2, line('.')) |
| 454 | cclose |
| 455 | botright new |
| 456 | call setloclist(0, [{'filename': 'Xqflist.txt', 'lnum': 10}]) |
| 457 | lopen |
| 458 | set modifiable |
| 459 | call feedkeys("A\<cr>", 'tnix') |
| 460 | call assert_equal('Xqflist.txt', bufname('')) |
| 461 | call assert_equal(10, line('.')) |
| 462 | call feedkeys("A\<Enter>", 'tnix') |
| 463 | call feedkeys("A\<kEnter>", 'tnix') |
| 464 | call feedkeys("A\n", 'tnix') |
| 465 | call feedkeys("A\r", 'tnix') |
| 466 | call assert_equal(map(range(1, 10), 'string(v:val)') + ['', '', '', ''], getline(1, '$')) |
| 467 | bw! |
| 468 | lclose |
| 469 | call delete('Xqflist.txt') |
| 470 | endfunc |
| 471 | |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 472 | func Test_edit_CTRL_() |
Bram Moolenaar | 6d91bcb | 2020-08-12 18:50:36 +0200 | [diff] [blame] | 473 | CheckFeature rightleft |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 474 | " disabled for Windows builds, why? |
Bram Moolenaar | 6d91bcb | 2020-08-12 18:50:36 +0200 | [diff] [blame] | 475 | CheckNotMSWindows |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 476 | let _encoding=&encoding |
| 477 | set encoding=utf-8 |
| 478 | " Test for CTRL-_ |
| 479 | new |
| 480 | call setline(1, ['abc']) |
| 481 | call cursor(1, 1) |
| 482 | call feedkeys("i\<c-_>xyz\<esc>", 'tnix') |
| 483 | call assert_equal(["\<C-_>xyzabc"], getline(1, '$')) |
| 484 | call assert_false(&revins) |
| 485 | set ari |
| 486 | call setline(1, ['abc']) |
| 487 | call cursor(1, 1) |
| 488 | call feedkeys("i\<c-_>xyz\<esc>", 'tnix') |
| 489 | call assert_equal(["æèñabc"], getline(1, '$')) |
| 490 | call assert_true(&revins) |
| 491 | call setline(1, ['abc']) |
| 492 | call cursor(1, 1) |
| 493 | call feedkeys("i\<c-_>xyz\<esc>", 'tnix') |
| 494 | call assert_equal(["xyzabc"], getline(1, '$')) |
| 495 | call assert_false(&revins) |
| 496 | set noari |
| 497 | let &encoding=_encoding |
| 498 | bw! |
| 499 | endfunc |
| 500 | |
| 501 | " needs to come first, to have the @. register empty |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 502 | func Test_edit_00a_CTRL_A() |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 503 | " Test pressing CTRL-A |
| 504 | new |
| 505 | call setline(1, repeat([''], 5)) |
| 506 | call cursor(1, 1) |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 507 | try |
| 508 | call feedkeys("A\<NUL>", 'tnix') |
| 509 | catch /^Vim\%((\a\+)\)\=:E29/ |
| 510 | call assert_true(1, 'E29 error caught') |
| 511 | endtry |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 512 | call cursor(1, 1) |
| 513 | call feedkeys("Afoobar \<esc>", 'tnix') |
| 514 | call cursor(2, 1) |
| 515 | call feedkeys("A\<c-a>more\<esc>", 'tnix') |
| 516 | call cursor(3, 1) |
| 517 | call feedkeys("A\<NUL>and more\<esc>", 'tnix') |
| 518 | call assert_equal(['foobar ', 'foobar more', 'foobar morend more', '', ''], getline(1, '$')) |
| 519 | bw! |
| 520 | endfunc |
| 521 | |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 522 | func Test_edit_CTRL_EY() |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 523 | " Ctrl-E/ Ctrl-Y in insert mode completion to scroll |
| 524 | 10new |
| 525 | call setline(1, range(1, 100)) |
| 526 | call cursor(30, 1) |
| 527 | norm! z. |
| 528 | call feedkeys("A\<c-x>\<c-e>\<c-e>\<c-e>\<c-e>\<c-e>", 'tnix') |
| 529 | call assert_equal(30, winsaveview()['topline']) |
| 530 | call assert_equal([0, 30, 2, 0], getpos('.')) |
| 531 | call feedkeys("A\<c-x>\<c-e>\<c-e>\<c-e>\<c-e>\<c-e>", 'tnix') |
| 532 | call feedkeys("A\<c-x>".repeat("\<c-y>", 10), 'tnix') |
| 533 | call assert_equal(21, winsaveview()['topline']) |
| 534 | call assert_equal([0, 30, 2, 0], getpos('.')) |
| 535 | bw! |
| 536 | endfunc |
| 537 | |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 538 | func Test_edit_CTRL_G() |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 539 | new |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 540 | call setline(1, ['foobar', 'foobar', 'foobar']) |
| 541 | call cursor(2, 4) |
| 542 | call feedkeys("ioooooooo\<c-g>k\<c-r>.\<esc>", 'tnix') |
| 543 | call assert_equal(['foooooooooobar', 'foooooooooobar', 'foobar'], getline(1, '$')) |
| 544 | call assert_equal([0, 1, 11, 0], getpos('.')) |
| 545 | call feedkeys("i\<c-g>k\<esc>", 'tnix') |
| 546 | call assert_equal([0, 1, 10, 0], getpos('.')) |
| 547 | call cursor(2, 4) |
| 548 | call feedkeys("i\<c-g>jzzzz\<esc>", 'tnix') |
| 549 | call assert_equal(['foooooooooobar', 'foooooooooobar', 'foozzzzbar'], getline(1, '$')) |
| 550 | call assert_equal([0, 3, 7, 0], getpos('.')) |
| 551 | call feedkeys("i\<c-g>j\<esc>", 'tnix') |
| 552 | call assert_equal([0, 3, 6, 0], getpos('.')) |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 553 | bw! |
| 554 | endfunc |
| 555 | |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 556 | func Test_edit_CTRL_I() |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 557 | " Tab in completion mode |
| 558 | let path=expand("%:p:h") |
| 559 | new |
Bram Moolenaar | ca85159 | 2018-06-06 21:04:07 +0200 | [diff] [blame] | 560 | call setline(1, [path. "/", '']) |
Bram Moolenaar | c537947 | 2017-03-16 22:38:00 +0100 | [diff] [blame] | 561 | call feedkeys("Arunt\<c-x>\<c-f>\<tab>\<cr>\<esc>", 'tnix') |
| 562 | call assert_match('runtest\.vim', getline(1)) |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 563 | %d |
| 564 | call writefile(['one', 'two', 'three'], 'Xinclude.txt') |
| 565 | let include='#include Xinclude.txt' |
| 566 | call setline(1, [include, '']) |
| 567 | call cursor(2, 1) |
| 568 | call feedkeys("A\<c-x>\<tab>\<cr>\<esc>", 'tnix') |
| 569 | call assert_equal([include, 'one', ''], getline(1, '$')) |
| 570 | call feedkeys("2ggC\<c-x>\<tab>\<down>\<cr>\<esc>", 'tnix') |
| 571 | call assert_equal([include, 'two', ''], getline(1, '$')) |
| 572 | call feedkeys("2ggC\<c-x>\<tab>\<down>\<down>\<cr>\<esc>", 'tnix') |
| 573 | call assert_equal([include, 'three', ''], getline(1, '$')) |
| 574 | call feedkeys("2ggC\<c-x>\<tab>\<down>\<down>\<down>\<cr>\<esc>", 'tnix') |
| 575 | call assert_equal([include, '', ''], getline(1, '$')) |
| 576 | call delete("Xinclude.txt") |
| 577 | bw! |
| 578 | endfunc |
| 579 | |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 580 | func Test_edit_CTRL_K() |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 581 | " Test pressing CTRL-K (basically only dictionary completion and digraphs |
| 582 | " the rest is already covered |
| 583 | call writefile(['A', 'AA', 'AAA', 'AAAA'], 'Xdictionary.txt') |
| 584 | set dictionary=Xdictionary.txt |
| 585 | new |
| 586 | call setline(1, 'A') |
| 587 | call cursor(1, 1) |
| 588 | call feedkeys("A\<c-x>\<c-k>\<cr>\<esc>", 'tnix') |
| 589 | call assert_equal(['AA', ''], getline(1, '$')) |
| 590 | %d |
| 591 | call setline(1, 'A') |
| 592 | call cursor(1, 1) |
| 593 | call feedkeys("A\<c-x>\<c-k>\<down>\<cr>\<esc>", 'tnix') |
| 594 | call assert_equal(['AAA'], getline(1, '$')) |
| 595 | %d |
| 596 | call setline(1, 'A') |
| 597 | call cursor(1, 1) |
| 598 | call feedkeys("A\<c-x>\<c-k>\<down>\<down>\<cr>\<esc>", 'tnix') |
| 599 | call assert_equal(['AAAA'], getline(1, '$')) |
| 600 | %d |
| 601 | call setline(1, 'A') |
| 602 | call cursor(1, 1) |
| 603 | call feedkeys("A\<c-x>\<c-k>\<down>\<down>\<down>\<cr>\<esc>", 'tnix') |
| 604 | call assert_equal(['A'], getline(1, '$')) |
| 605 | %d |
| 606 | call setline(1, 'A') |
| 607 | call cursor(1, 1) |
| 608 | call feedkeys("A\<c-x>\<c-k>\<down>\<down>\<down>\<down>\<cr>\<esc>", 'tnix') |
| 609 | call assert_equal(['AA'], getline(1, '$')) |
| 610 | |
Bram Moolenaar | 4b96df5 | 2020-01-26 22:00:26 +0100 | [diff] [blame] | 611 | " press an unexpected key after dictionary completion |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 612 | %d |
| 613 | call setline(1, 'A') |
| 614 | call cursor(1, 1) |
| 615 | call feedkeys("A\<c-x>\<c-k>\<c-]>\<cr>\<esc>", 'tnix') |
| 616 | call assert_equal(['AA', ''], getline(1, '$')) |
| 617 | %d |
| 618 | call setline(1, 'A') |
| 619 | call cursor(1, 1) |
| 620 | call feedkeys("A\<c-x>\<c-k>\<c-s>\<cr>\<esc>", 'tnix') |
| 621 | call assert_equal(["AA\<c-s>", ''], getline(1, '$')) |
| 622 | %d |
| 623 | call setline(1, 'A') |
| 624 | call cursor(1, 1) |
| 625 | call feedkeys("A\<c-x>\<c-k>\<c-f>\<cr>\<esc>", 'tnix') |
| 626 | call assert_equal(["AA\<c-f>", ''], getline(1, '$')) |
| 627 | |
| 628 | set dictionary= |
| 629 | %d |
| 630 | call setline(1, 'A') |
| 631 | call cursor(1, 1) |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 632 | let v:testing = 1 |
| 633 | try |
| 634 | call feedkeys("A\<c-x>\<c-k>\<esc>", 'tnix') |
| 635 | catch |
| 636 | " error sleeps 2 seconds, when v:testing is not set |
| 637 | let v:testing = 0 |
| 638 | endtry |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 639 | call delete('Xdictionary.txt') |
| 640 | |
Bram Moolenaar | 30276f2 | 2019-01-24 17:59:39 +0100 | [diff] [blame] | 641 | call test_override("char_avail", 1) |
| 642 | set showcmd |
| 643 | %d |
| 644 | call feedkeys("A\<c-k>a:\<esc>", 'tnix') |
| 645 | call assert_equal(['ä'], getline(1, '$')) |
| 646 | call test_override("char_avail", 0) |
| 647 | set noshowcmd |
| 648 | |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 649 | bw! |
| 650 | endfunc |
| 651 | |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 652 | func Test_edit_CTRL_L() |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 653 | " Test Ctrl-X Ctrl-L (line completion) |
| 654 | new |
| 655 | set complete=. |
| 656 | call setline(1, ['one', 'two', 'three', '', '', '', '']) |
| 657 | call cursor(4, 1) |
| 658 | call feedkeys("A\<c-x>\<c-l>\<esc>", 'tnix') |
| 659 | call assert_equal(['one', 'two', 'three', 'three', '', '', ''], getline(1, '$')) |
| 660 | call feedkeys("cct\<c-x>\<c-l>\<c-n>\<esc>", 'tnix') |
| 661 | call assert_equal(['one', 'two', 'three', 't', '', '', ''], getline(1, '$')) |
| 662 | call feedkeys("cct\<c-x>\<c-l>\<c-n>\<c-n>\<esc>", 'tnix') |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 663 | call assert_equal(['one', 'two', 'three', 'two', '', '', ''], getline(1, '$')) |
Bram Moolenaar | 02ae9b4 | 2018-02-09 15:06:02 +0100 | [diff] [blame] | 664 | call feedkeys("cct\<c-x>\<c-l>\<c-n>\<c-n>\<c-n>\<esc>", 'tnix') |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 665 | call assert_equal(['one', 'two', 'three', 'three', '', '', ''], getline(1, '$')) |
Bram Moolenaar | 02ae9b4 | 2018-02-09 15:06:02 +0100 | [diff] [blame] | 666 | call feedkeys("cct\<c-x>\<c-l>\<c-n>\<c-n>\<c-n>\<c-n>\<esc>", 'tnix') |
| 667 | call assert_equal(['one', 'two', 'three', 't', '', '', ''], getline(1, '$')) |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 668 | call feedkeys("cct\<c-x>\<c-l>\<c-p>\<esc>", 'tnix') |
| 669 | call assert_equal(['one', 'two', 'three', 'two', '', '', ''], getline(1, '$')) |
| 670 | call feedkeys("cct\<c-x>\<c-l>\<c-p>\<c-p>\<esc>", 'tnix') |
| 671 | call assert_equal(['one', 'two', 'three', 't', '', '', ''], getline(1, '$')) |
| 672 | call feedkeys("cct\<c-x>\<c-l>\<c-p>\<c-p>\<c-p>\<esc>", 'tnix') |
| 673 | call assert_equal(['one', 'two', 'three', 'three', '', '', ''], getline(1, '$')) |
| 674 | set complete= |
| 675 | call cursor(5, 1) |
| 676 | call feedkeys("A\<c-x>\<c-l>\<c-p>\<c-n>\<esc>", 'tnix') |
| 677 | call assert_equal(['one', 'two', 'three', 'three', "\<c-l>\<c-p>\<c-n>", '', ''], getline(1, '$')) |
| 678 | set complete& |
| 679 | %d |
| 680 | if has("conceal") && has("syntax") |
| 681 | call setline(1, ['foo', 'bar', 'foobar']) |
| 682 | call test_override("char_avail", 1) |
| 683 | set conceallevel=2 concealcursor=n |
| 684 | syn on |
| 685 | syn match ErrorMsg "^bar" |
| 686 | call matchadd("Conceal", 'oo', 10, -1, {'conceal': 'X'}) |
| 687 | func! DoIt() |
| 688 | let g:change=1 |
| 689 | endfunc |
| 690 | au! TextChangedI <buffer> :call DoIt() |
| 691 | |
| 692 | call cursor(2, 1) |
| 693 | call assert_false(exists("g:change")) |
| 694 | call feedkeys("A \<esc>", 'tnix') |
| 695 | call assert_equal(['foo', 'bar ', 'foobar'], getline(1, '$')) |
| 696 | call assert_equal(1, g:change) |
| 697 | |
| 698 | call test_override("char_avail", 0) |
| 699 | call clearmatches() |
| 700 | syn off |
| 701 | au! TextChangedI |
| 702 | delfu DoIt |
| 703 | unlet! g:change |
| 704 | endif |
| 705 | bw! |
| 706 | endfunc |
| 707 | |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 708 | func Test_edit_CTRL_N() |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 709 | " Check keyword completion |
Bram Moolenaar | a1070ea | 2021-02-20 19:21:36 +0100 | [diff] [blame] | 710 | for e in ['latin1', 'utf-8'] |
| 711 | exe 'set encoding=' .. e |
| 712 | new |
| 713 | set complete=. |
| 714 | call setline(1, ['INFER', 'loWER', '', '', ]) |
| 715 | call cursor(3, 1) |
| 716 | call feedkeys("Ai\<c-n>\<cr>\<esc>", "tnix") |
| 717 | call feedkeys("ILO\<c-n>\<cr>\<esc>", 'tnix') |
| 718 | call assert_equal(['INFER', 'loWER', 'i', 'LO', '', ''], getline(1, '$'), e) |
| 719 | %d |
| 720 | call setline(1, ['INFER', 'loWER', '', '', ]) |
| 721 | call cursor(3, 1) |
| 722 | set ignorecase infercase |
| 723 | call feedkeys("Ii\<c-n>\<cr>\<esc>", "tnix") |
| 724 | call feedkeys("ILO\<c-n>\<cr>\<esc>", 'tnix') |
| 725 | call assert_equal(['INFER', 'loWER', 'infer', 'LOWER', '', ''], getline(1, '$'), e) |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 726 | |
Bram Moolenaar | a1070ea | 2021-02-20 19:21:36 +0100 | [diff] [blame] | 727 | set noignorecase noinfercase complete& |
| 728 | bw! |
| 729 | endfor |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 730 | endfunc |
| 731 | |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 732 | func Test_edit_CTRL_O() |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 733 | " Check for CTRL-O in insert mode |
| 734 | new |
| 735 | inoreabbr <buffer> h here some more |
| 736 | call setline(1, ['abc', 'def']) |
| 737 | call cursor(1, 1) |
| 738 | " Ctrl-O after an abbreviation |
| 739 | exe "norm A h\<c-o>:set nu\<cr> text" |
| 740 | call assert_equal(['abc here some more text', 'def'], getline(1, '$')) |
| 741 | call assert_true(&nu) |
| 742 | set nonu |
| 743 | iunabbr <buffer> h |
| 744 | " Ctrl-O at end of line with 've'=onemore |
| 745 | call cursor(1, 1) |
| 746 | call feedkeys("A\<c-o>:let g:a=getpos('.')\<cr>\<esc>", 'tnix') |
| 747 | call assert_equal([0, 1, 23, 0], g:a) |
| 748 | call cursor(1, 1) |
| 749 | set ve=onemore |
| 750 | call feedkeys("A\<c-o>:let g:a=getpos('.')\<cr>\<esc>", 'tnix') |
| 751 | call assert_equal([0, 1, 24, 0], g:a) |
| 752 | set ve= |
| 753 | unlet! g:a |
| 754 | bw! |
| 755 | endfunc |
| 756 | |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 757 | func Test_edit_CTRL_R() |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 758 | " Insert Register |
| 759 | new |
| 760 | call test_override("ALL", 1) |
| 761 | set showcmd |
| 762 | call feedkeys("AFOOBAR eins zwei\<esc>", 'tnix') |
| 763 | call feedkeys("O\<c-r>.", 'tnix') |
| 764 | call feedkeys("O\<c-r>=10*500\<cr>\<esc>", 'tnix') |
| 765 | call feedkeys("O\<c-r>=getreg('=', 1)\<cr>\<esc>", 'tnix') |
| 766 | call assert_equal(["getreg('=', 1)", '5000', "FOOBAR eins zwei", "FOOBAR eins zwei"], getline(1, '$')) |
| 767 | call test_override("ALL", 0) |
| 768 | set noshowcmd |
| 769 | bw! |
| 770 | endfunc |
| 771 | |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 772 | func Test_edit_CTRL_S() |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 773 | " Test pressing CTRL-S (basically only spellfile completion) |
| 774 | " the rest is already covered |
| 775 | new |
| 776 | if !has("spell") |
| 777 | call setline(1, 'vim') |
| 778 | call feedkeys("A\<c-x>ss\<cr>\<esc>", 'tnix') |
| 779 | call assert_equal(['vims', ''], getline(1, '$')) |
| 780 | bw! |
| 781 | return |
| 782 | endif |
| 783 | call setline(1, 'vim') |
| 784 | " spell option not yet set |
| 785 | try |
| 786 | call feedkeys("A\<c-x>\<c-s>\<cr>\<esc>", 'tnix') |
| 787 | catch /^Vim\%((\a\+)\)\=:E756/ |
| 788 | call assert_true(1, 'error caught') |
| 789 | endtry |
| 790 | call assert_equal(['vim', ''], getline(1, '$')) |
| 791 | %d |
| 792 | setl spell spelllang=en |
| 793 | call setline(1, 'vim') |
| 794 | call cursor(1, 1) |
| 795 | call feedkeys("A\<c-x>\<c-s>\<cr>\<esc>", 'tnix') |
| 796 | call assert_equal(['Vim', ''], getline(1, '$')) |
| 797 | %d |
| 798 | call setline(1, 'vim') |
| 799 | call cursor(1, 1) |
| 800 | call feedkeys("A\<c-x>\<c-s>\<down>\<cr>\<esc>", 'tnix') |
| 801 | call assert_equal(['Aim'], getline(1, '$')) |
| 802 | %d |
| 803 | call setline(1, 'vim') |
| 804 | call cursor(1, 1) |
| 805 | call feedkeys("A\<c-x>\<c-s>\<c-p>\<cr>\<esc>", 'tnix') |
| 806 | call assert_equal(['vim', ''], getline(1, '$')) |
| 807 | %d |
| 808 | " empty buffer |
| 809 | call cursor(1, 1) |
| 810 | call feedkeys("A\<c-x>\<c-s>\<c-p>\<cr>\<esc>", 'tnix') |
| 811 | call assert_equal(['', ''], getline(1, '$')) |
| 812 | setl nospell |
| 813 | bw! |
| 814 | endfunc |
| 815 | |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 816 | func Test_edit_CTRL_T() |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 817 | " Check for CTRL-T and CTRL-X CTRL-T in insert mode |
| 818 | " 1) increase indent |
| 819 | new |
| 820 | call setline(1, "abc") |
| 821 | call cursor(1, 1) |
| 822 | call feedkeys("A\<c-t>xyz", 'tnix') |
| 823 | call assert_equal(["\<tab>abcxyz"], getline(1, '$')) |
| 824 | " 2) also when paste option is set |
| 825 | set paste |
| 826 | call setline(1, "abc") |
| 827 | call cursor(1, 1) |
| 828 | call feedkeys("A\<c-t>xyz", 'tnix') |
| 829 | call assert_equal(["\<tab>abcxyz"], getline(1, '$')) |
| 830 | set nopaste |
| 831 | " CTRL-X CTRL-T (thesaurus complete) |
| 832 | call writefile(['angry furious mad enraged'], 'Xthesaurus') |
| 833 | set thesaurus=Xthesaurus |
| 834 | call setline(1, 'mad') |
| 835 | call cursor(1, 1) |
| 836 | call feedkeys("A\<c-x>\<c-t>\<cr>\<esc>", 'tnix') |
| 837 | call assert_equal(['mad', ''], getline(1, '$')) |
| 838 | %d |
| 839 | call setline(1, 'mad') |
| 840 | call cursor(1, 1) |
| 841 | call feedkeys("A\<c-x>\<c-t>\<c-n>\<cr>\<esc>", 'tnix') |
| 842 | call assert_equal(['angry', ''], getline(1, '$')) |
| 843 | %d |
| 844 | call setline(1, 'mad') |
| 845 | call cursor(1, 1) |
| 846 | call feedkeys("A\<c-x>\<c-t>\<c-n>\<c-n>\<cr>\<esc>", 'tnix') |
| 847 | call assert_equal(['furious', ''], getline(1, '$')) |
| 848 | %d |
| 849 | call setline(1, 'mad') |
| 850 | call cursor(1, 1) |
| 851 | call feedkeys("A\<c-x>\<c-t>\<c-n>\<c-n>\<c-n>\<cr>\<esc>", 'tnix') |
| 852 | call assert_equal(['enraged', ''], getline(1, '$')) |
| 853 | %d |
| 854 | call setline(1, 'mad') |
| 855 | call cursor(1, 1) |
| 856 | call feedkeys("A\<c-x>\<c-t>\<c-n>\<c-n>\<c-n>\<c-n>\<cr>\<esc>", 'tnix') |
| 857 | call assert_equal(['mad', ''], getline(1, '$')) |
| 858 | %d |
| 859 | call setline(1, 'mad') |
| 860 | call cursor(1, 1) |
| 861 | call feedkeys("A\<c-x>\<c-t>\<c-n>\<c-n>\<c-n>\<c-n>\<c-n>\<cr>\<esc>", 'tnix') |
| 862 | call assert_equal(['mad', ''], getline(1, '$')) |
| 863 | " Using <c-p> <c-n> when 'complete' is empty |
| 864 | set complete= |
| 865 | %d |
| 866 | call setline(1, 'mad') |
| 867 | call cursor(1, 1) |
| 868 | call feedkeys("A\<c-x>\<c-t>\<c-n>\<cr>\<esc>", 'tnix') |
| 869 | call assert_equal(['angry', ''], getline(1, '$')) |
| 870 | %d |
| 871 | call setline(1, 'mad') |
| 872 | call cursor(1, 1) |
| 873 | call feedkeys("A\<c-x>\<c-t>\<c-p>\<cr>\<esc>", 'tnix') |
| 874 | call assert_equal(['mad', ''], getline(1, '$')) |
| 875 | set complete& |
| 876 | |
| 877 | set thesaurus= |
| 878 | %d |
| 879 | call setline(1, 'mad') |
| 880 | call cursor(1, 1) |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 881 | let v:testing = 1 |
| 882 | try |
| 883 | call feedkeys("A\<c-x>\<c-t>\<esc>", 'tnix') |
| 884 | catch |
| 885 | " error sleeps 2 seconds, when v:testing is not set |
| 886 | let v:testing = 0 |
| 887 | endtry |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 888 | call assert_equal(['mad'], getline(1, '$')) |
| 889 | call delete('Xthesaurus') |
| 890 | bw! |
| 891 | endfunc |
| 892 | |
Yegappan Lakshmanan | 160e994 | 2021-10-16 15:41:29 +0100 | [diff] [blame] | 893 | " Test 'thesaurusfunc' |
| 894 | func MyThesaurus(findstart, base) |
| 895 | let mythesaurus = [ |
| 896 | \ #{word: "happy", |
| 897 | \ synonyms: "cheerful,blissful,flying high,looking good,peppy"}, |
| 898 | \ #{word: "kind", |
| 899 | \ synonyms: "amiable,bleeding-heart,heart in right place"}] |
| 900 | if a:findstart |
| 901 | " locate the start of the word |
| 902 | let line = getline('.') |
| 903 | let start = col('.') - 1 |
| 904 | while start > 0 && line[start - 1] =~ '\a' |
| 905 | let start -= 1 |
| 906 | endwhile |
| 907 | return start |
| 908 | else |
| 909 | " find strings matching with "a:base" |
| 910 | let res = [] |
| 911 | for w in mythesaurus |
| 912 | if w.word =~ '^' . a:base |
| 913 | call add(res, w.word) |
| 914 | call extend(res, split(w.synonyms, ",")) |
| 915 | endif |
| 916 | endfor |
| 917 | return res |
| 918 | endif |
| 919 | endfunc |
| 920 | |
| 921 | func Test_thesaurus_func() |
| 922 | new |
Bram Moolenaar | f4d8b76 | 2021-10-17 14:13:09 +0100 | [diff] [blame] | 923 | set thesaurus=notused |
| 924 | set thesaurusfunc=NotUsed |
| 925 | setlocal thesaurusfunc=MyThesaurus |
Yegappan Lakshmanan | 160e994 | 2021-10-16 15:41:29 +0100 | [diff] [blame] | 926 | call setline(1, "an ki") |
| 927 | call cursor(1, 1) |
| 928 | call feedkeys("A\<c-x>\<c-t>\<c-n>\<cr>\<esc>", 'tnix') |
| 929 | call assert_equal(['an amiable', ''], getline(1, '$')) |
Bram Moolenaar | f4d8b76 | 2021-10-17 14:13:09 +0100 | [diff] [blame] | 930 | |
| 931 | setlocal thesaurusfunc=NonExistingFunc |
| 932 | call assert_fails("normal $a\<C-X>\<C-T>", 'E117:') |
| 933 | |
| 934 | setlocal thesaurusfunc= |
Yegappan Lakshmanan | 160e994 | 2021-10-16 15:41:29 +0100 | [diff] [blame] | 935 | set thesaurusfunc=NonExistingFunc |
| 936 | call assert_fails("normal $a\<C-X>\<C-T>", 'E117:') |
Yegappan Lakshmanan | 160e994 | 2021-10-16 15:41:29 +0100 | [diff] [blame] | 937 | %bw! |
Bram Moolenaar | f4d8b76 | 2021-10-17 14:13:09 +0100 | [diff] [blame] | 938 | |
| 939 | set thesaurusfunc= |
| 940 | set thesaurus= |
Yegappan Lakshmanan | 160e994 | 2021-10-16 15:41:29 +0100 | [diff] [blame] | 941 | endfunc |
| 942 | |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 943 | func Test_edit_CTRL_U() |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 944 | " Test 'completefunc' |
| 945 | new |
| 946 | " -1, -2 and -3 are special return values |
| 947 | let g:special=0 |
| 948 | fun! CompleteMonths(findstart, base) |
| 949 | if a:findstart |
| 950 | " locate the start of the word |
| 951 | return g:special |
| 952 | else |
| 953 | " find months matching with "a:base" |
| 954 | let res = [] |
| 955 | for m in split("Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec") |
| 956 | if m =~ '^\c'.a:base |
| 957 | call add(res, {'word': m, 'abbr': m.' Month', 'icase': 0}) |
| 958 | endif |
| 959 | endfor |
| 960 | return {'words': res, 'refresh': 'always'} |
| 961 | endif |
| 962 | endfun |
| 963 | set completefunc=CompleteMonths |
| 964 | call setline(1, ['', '']) |
| 965 | call cursor(1, 1) |
| 966 | call feedkeys("AX\<c-x>\<c-u>\<cr>\<esc>", 'tnix') |
| 967 | call assert_equal(['X', '', ''], getline(1, '$')) |
| 968 | %d |
| 969 | let g:special=-1 |
| 970 | call feedkeys("AX\<c-x>\<c-u>\<cr>\<esc>", 'tnix') |
| 971 | call assert_equal(['XJan', ''], getline(1, '$')) |
| 972 | %d |
| 973 | let g:special=-2 |
| 974 | call feedkeys("AX\<c-x>\<c-u>\<cr>\<esc>", 'tnix') |
| 975 | call assert_equal(['X', ''], getline(1, '$')) |
| 976 | %d |
| 977 | let g:special=-3 |
| 978 | call feedkeys("AX\<c-x>\<c-u>\<cr>\<esc>", 'tnix') |
| 979 | call assert_equal(['X', ''], getline(1, '$')) |
| 980 | %d |
| 981 | let g:special=0 |
| 982 | call feedkeys("AM\<c-x>\<c-u>\<cr>\<esc>", 'tnix') |
| 983 | call assert_equal(['Mar', ''], getline(1, '$')) |
| 984 | %d |
| 985 | call feedkeys("AM\<c-x>\<c-u>\<c-n>\<cr>\<esc>", 'tnix') |
| 986 | call assert_equal(['May', ''], getline(1, '$')) |
| 987 | %d |
| 988 | call feedkeys("AM\<c-x>\<c-u>\<c-n>\<c-n>\<cr>\<esc>", 'tnix') |
| 989 | call assert_equal(['M', ''], getline(1, '$')) |
| 990 | delfu CompleteMonths |
| 991 | %d |
| 992 | try |
| 993 | call feedkeys("A\<c-x>\<c-u>", 'tnix') |
| 994 | call assert_fails(1, 'unknown completion function') |
| 995 | catch /^Vim\%((\a\+)\)\=:E117/ |
| 996 | call assert_true(1, 'E117 error caught') |
| 997 | endtry |
| 998 | set completefunc= |
| 999 | bw! |
| 1000 | endfunc |
| 1001 | |
Bram Moolenaar | ff06f28 | 2020-04-21 22:01:14 +0200 | [diff] [blame] | 1002 | func Test_edit_completefunc_delete() |
| 1003 | func CompleteFunc(findstart, base) |
| 1004 | if a:findstart == 1 |
| 1005 | return col('.') - 1 |
| 1006 | endif |
| 1007 | normal dd |
| 1008 | return ['a', 'b'] |
| 1009 | endfunc |
| 1010 | new |
| 1011 | set completefunc=CompleteFunc |
| 1012 | call setline(1, ['', 'abcd', '']) |
| 1013 | 2d |
Bram Moolenaar | 6adb9ea | 2020-04-30 22:31:18 +0200 | [diff] [blame] | 1014 | call assert_fails("normal 2G$a\<C-X>\<C-U>", 'E578:') |
Bram Moolenaar | ff06f28 | 2020-04-21 22:01:14 +0200 | [diff] [blame] | 1015 | bwipe! |
| 1016 | endfunc |
| 1017 | |
| 1018 | |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 1019 | func Test_edit_CTRL_Z() |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 1020 | " Ctrl-Z when insertmode is not set inserts it literally |
| 1021 | new |
| 1022 | call setline(1, 'abc') |
| 1023 | call feedkeys("A\<c-z>\<esc>", 'tnix') |
| 1024 | call assert_equal(["abc\<c-z>"], getline(1,'$')) |
| 1025 | bw! |
| 1026 | " TODO: How to Test Ctrl-Z in insert mode, e.g. suspend? |
| 1027 | endfunc |
| 1028 | |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 1029 | func Test_edit_DROP() |
Bram Moolenaar | 6d91bcb | 2020-08-12 18:50:36 +0200 | [diff] [blame] | 1030 | CheckFeature dnd |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 1031 | new |
| 1032 | call setline(1, ['abc def ghi']) |
| 1033 | call cursor(1, 1) |
| 1034 | try |
| 1035 | call feedkeys("i\<Drop>\<Esc>", 'tnix') |
| 1036 | call assert_fails(1, 'Invalid register name') |
| 1037 | catch /^Vim\%((\a\+)\)\=:E353/ |
| 1038 | call assert_true(1, 'error caught') |
| 1039 | endtry |
| 1040 | bw! |
| 1041 | endfunc |
| 1042 | |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 1043 | func Test_edit_CTRL_V() |
Bram Moolenaar | 6d91bcb | 2020-08-12 18:50:36 +0200 | [diff] [blame] | 1044 | CheckFeature ebcdic |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 1045 | new |
| 1046 | call setline(1, ['abc']) |
| 1047 | call cursor(2, 1) |
| 1048 | " force some redraws |
| 1049 | set showmode showcmd |
| 1050 | "call test_override_char_avail(1) |
| 1051 | call test_override('ALL', 1) |
| 1052 | call feedkeys("A\<c-v>\<c-n>\<c-v>\<c-l>\<c-v>\<c-b>\<esc>", 'tnix') |
| 1053 | call assert_equal(["abc\x0e\x0c\x02"], getline(1, '$')) |
| 1054 | |
| 1055 | if has("rightleft") && exists("+rl") |
| 1056 | set rl |
| 1057 | call setline(1, ['abc']) |
| 1058 | call cursor(2, 1) |
| 1059 | call feedkeys("A\<c-v>\<c-n>\<c-v>\<c-l>\<c-v>\<c-b>\<esc>", 'tnix') |
| 1060 | call assert_equal(["abc\x0e\x0c\x02"], getline(1, '$')) |
| 1061 | set norl |
| 1062 | endif |
| 1063 | |
| 1064 | call test_override('ALL', 0) |
| 1065 | set noshowmode showcmd |
| 1066 | bw! |
| 1067 | endfunc |
| 1068 | |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 1069 | func Test_edit_F1() |
Bram Moolenaar | 5a4c308 | 2019-12-01 15:23:11 +0100 | [diff] [blame] | 1070 | CheckFeature quickfix |
| 1071 | |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 1072 | " Pressing <f1> |
| 1073 | new |
| 1074 | call feedkeys(":set im\<cr>\<f1>\<c-l>", 'tnix') |
| 1075 | set noinsertmode |
| 1076 | call assert_equal('help', &buftype) |
| 1077 | bw |
| 1078 | bw |
| 1079 | endfunc |
| 1080 | |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 1081 | func Test_edit_F21() |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 1082 | " Pressing <f21> |
| 1083 | " sends a netbeans command |
Bram Moolenaar | 6d91bcb | 2020-08-12 18:50:36 +0200 | [diff] [blame] | 1084 | CheckFeature netbeans_intg |
| 1085 | new |
| 1086 | " I have no idea what this is supposed to do :) |
| 1087 | call feedkeys("A\<F21>\<F1>\<esc>", 'tnix') |
| 1088 | bw |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 1089 | endfunc |
| 1090 | |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 1091 | func Test_edit_HOME_END() |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 1092 | " Test Home/End Keys |
| 1093 | new |
| 1094 | set foldopen+=hor |
| 1095 | call setline(1, ['abc', 'def']) |
| 1096 | call cursor(1, 1) |
| 1097 | call feedkeys("AX\<Home>Y\<esc>", 'tnix') |
| 1098 | call cursor(2, 1) |
| 1099 | call feedkeys("iZ\<End>Y\<esc>", 'tnix') |
| 1100 | call assert_equal(['YabcX', 'ZdefY'], getline(1, '$')) |
| 1101 | |
| 1102 | set foldopen-=hor |
| 1103 | bw! |
| 1104 | endfunc |
| 1105 | |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 1106 | func Test_edit_INS() |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 1107 | " Test for Pressing <Insert> |
| 1108 | new |
| 1109 | call setline(1, ['abc', 'def']) |
| 1110 | call cursor(1, 1) |
| 1111 | call feedkeys("i\<Insert>ZYX>", 'tnix') |
| 1112 | call assert_equal(['ZYX>', 'def'], getline(1, '$')) |
| 1113 | call setline(1, ['abc', 'def']) |
| 1114 | call cursor(1, 1) |
| 1115 | call feedkeys("i\<Insert>Z\<Insert>YX>", 'tnix') |
| 1116 | call assert_equal(['ZYX>bc', 'def'], getline(1, '$')) |
| 1117 | bw! |
| 1118 | endfunc |
| 1119 | |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 1120 | func Test_edit_LEFT_RIGHT() |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 1121 | " Left, Shift-Left, Right, Shift-Right |
| 1122 | new |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 1123 | call setline(1, ['abc def ghi', 'ABC DEF GHI', 'ZZZ YYY XXX']) |
| 1124 | let _ww=&ww |
| 1125 | set ww= |
| 1126 | call cursor(2, 1) |
| 1127 | call feedkeys("i\<left>\<esc>", 'tnix') |
| 1128 | call assert_equal([0, 2, 1, 0], getpos('.')) |
| 1129 | " Is this a bug, <s-left> does not respect whichwrap option |
| 1130 | call feedkeys("i\<s-left>\<esc>", 'tnix') |
| 1131 | call assert_equal([0, 1, 8, 0], getpos('.')) |
| 1132 | call feedkeys("i". repeat("\<s-left>", 3). "\<esc>", 'tnix') |
| 1133 | call assert_equal([0, 1, 1, 0], getpos('.')) |
| 1134 | call feedkeys("i\<right>\<esc>", 'tnix') |
| 1135 | call assert_equal([0, 1, 1, 0], getpos('.')) |
| 1136 | call feedkeys("i\<right>\<right>\<esc>", 'tnix') |
| 1137 | call assert_equal([0, 1, 2, 0], getpos('.')) |
| 1138 | call feedkeys("A\<right>\<esc>", 'tnix') |
| 1139 | call assert_equal([0, 1, 11, 0], getpos('.')) |
| 1140 | call feedkeys("A\<s-right>\<esc>", 'tnix') |
| 1141 | call assert_equal([0, 2, 1, 0], getpos('.')) |
| 1142 | call feedkeys("i\<s-right>\<esc>", 'tnix') |
| 1143 | call assert_equal([0, 2, 4, 0], getpos('.')) |
| 1144 | call cursor(3, 11) |
| 1145 | call feedkeys("A\<right>\<esc>", 'tnix') |
| 1146 | call feedkeys("A\<s-right>\<esc>", 'tnix') |
| 1147 | call assert_equal([0, 3, 11, 0], getpos('.')) |
| 1148 | call cursor(2, 11) |
| 1149 | " <S-Right> does not respect 'whichwrap' option |
| 1150 | call feedkeys("A\<s-right>\<esc>", 'tnix') |
| 1151 | call assert_equal([0, 3, 1, 0], getpos('.')) |
| 1152 | " Check motion when 'whichwrap' contains cursor keys for insert mode |
| 1153 | set ww+=[,] |
| 1154 | call cursor(2, 1) |
| 1155 | call feedkeys("i\<left>\<esc>", 'tnix') |
| 1156 | call assert_equal([0, 1, 11, 0], getpos('.')) |
| 1157 | call cursor(2, 11) |
| 1158 | call feedkeys("A\<right>\<esc>", 'tnix') |
| 1159 | call assert_equal([0, 3, 1, 0], getpos('.')) |
| 1160 | call cursor(2, 11) |
| 1161 | call feedkeys("A\<s-right>\<esc>", 'tnix') |
| 1162 | call assert_equal([0, 3, 1, 0], getpos('.')) |
| 1163 | let &ww = _ww |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 1164 | bw! |
| 1165 | endfunc |
| 1166 | |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 1167 | func Test_edit_MOUSE() |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 1168 | " This is a simple test, since we not really using the mouse here |
Bram Moolenaar | 6d91bcb | 2020-08-12 18:50:36 +0200 | [diff] [blame] | 1169 | CheckFeature mouse |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 1170 | 10new |
| 1171 | call setline(1, range(1, 100)) |
| 1172 | call cursor(1, 1) |
| 1173 | set mouse=a |
| 1174 | call feedkeys("A\<ScrollWheelDown>\<esc>", 'tnix') |
| 1175 | call assert_equal([0, 4, 1, 0], getpos('.')) |
| 1176 | " This should move by one pageDown, but only moves |
| 1177 | " by one line when the test is run... |
| 1178 | call feedkeys("A\<S-ScrollWheelDown>\<esc>", 'tnix') |
| 1179 | call assert_equal([0, 5, 1, 0], getpos('.')) |
| 1180 | set nostartofline |
| 1181 | call feedkeys("A\<C-ScrollWheelDown>\<esc>", 'tnix') |
| 1182 | call assert_equal([0, 6, 1, 0], getpos('.')) |
| 1183 | call feedkeys("A\<LeftMouse>\<esc>", 'tnix') |
| 1184 | call assert_equal([0, 6, 1, 0], getpos('.')) |
| 1185 | call feedkeys("A\<RightMouse>\<esc>", 'tnix') |
| 1186 | call assert_equal([0, 6, 1, 0], getpos('.')) |
| 1187 | call cursor(1, 100) |
| 1188 | norm! zt |
| 1189 | " this should move by a screen up, but when the test |
| 1190 | " is run, it moves up to the top of the buffer... |
| 1191 | call feedkeys("A\<ScrollWheelUp>\<esc>", 'tnix') |
| 1192 | call assert_equal([0, 1, 1, 0], getpos('.')) |
| 1193 | call cursor(1, 30) |
| 1194 | norm! zt |
| 1195 | call feedkeys("A\<S-ScrollWheelUp>\<esc>", 'tnix') |
| 1196 | call assert_equal([0, 1, 1, 0], getpos('.')) |
| 1197 | call cursor(1, 30) |
| 1198 | norm! zt |
| 1199 | call feedkeys("A\<C-ScrollWheelUp>\<esc>", 'tnix') |
| 1200 | call assert_equal([0, 1, 1, 0], getpos('.')) |
| 1201 | %d |
| 1202 | call setline(1, repeat(["12345678901234567890"], 100)) |
| 1203 | call cursor(2, 1) |
| 1204 | call feedkeys("A\<ScrollWheelRight>\<esc>", 'tnix') |
| 1205 | call assert_equal([0, 2, 20, 0], getpos('.')) |
| 1206 | call feedkeys("A\<ScrollWheelLeft>\<esc>", 'tnix') |
| 1207 | call assert_equal([0, 2, 20, 0], getpos('.')) |
| 1208 | call feedkeys("A\<S-ScrollWheelRight>\<esc>", 'tnix') |
| 1209 | call assert_equal([0, 2, 20, 0], getpos('.')) |
| 1210 | call feedkeys("A\<S-ScrollWheelLeft>\<esc>", 'tnix') |
| 1211 | call assert_equal([0, 2, 20, 0], getpos('.')) |
| 1212 | call feedkeys("A\<C-ScrollWheelRight>\<esc>", 'tnix') |
| 1213 | call assert_equal([0, 2, 20, 0], getpos('.')) |
| 1214 | call feedkeys("A\<C-ScrollWheelLeft>\<esc>", 'tnix') |
| 1215 | call assert_equal([0, 2, 20, 0], getpos('.')) |
| 1216 | set mouse& startofline |
| 1217 | bw! |
| 1218 | endfunc |
| 1219 | |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 1220 | func Test_edit_PAGEUP_PAGEDOWN() |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 1221 | 10new |
| 1222 | call setline(1, repeat(['abc def ghi'], 30)) |
| 1223 | call cursor(1, 1) |
| 1224 | call feedkeys("i\<PageDown>\<esc>", 'tnix') |
| 1225 | call assert_equal([0, 9, 1, 0], getpos('.')) |
| 1226 | call feedkeys("i\<PageDown>\<esc>", 'tnix') |
| 1227 | call assert_equal([0, 17, 1, 0], getpos('.')) |
| 1228 | call feedkeys("i\<PageDown>\<esc>", 'tnix') |
| 1229 | call assert_equal([0, 25, 1, 0], getpos('.')) |
| 1230 | call feedkeys("i\<PageDown>\<esc>", 'tnix') |
| 1231 | call assert_equal([0, 30, 1, 0], getpos('.')) |
| 1232 | call feedkeys("i\<PageDown>\<esc>", 'tnix') |
| 1233 | call assert_equal([0, 30, 1, 0], getpos('.')) |
| 1234 | call feedkeys("A\<PageUp>\<esc>", 'tnix') |
| 1235 | call assert_equal([0, 29, 1, 0], getpos('.')) |
| 1236 | call feedkeys("A\<PageUp>\<esc>", 'tnix') |
| 1237 | call assert_equal([0, 21, 1, 0], getpos('.')) |
| 1238 | call feedkeys("A\<PageUp>\<esc>", 'tnix') |
| 1239 | call assert_equal([0, 13, 1, 0], getpos('.')) |
| 1240 | call feedkeys("A\<PageUp>\<esc>", 'tnix') |
| 1241 | call assert_equal([0, 5, 1, 0], getpos('.')) |
| 1242 | call feedkeys("A\<PageUp>\<esc>", 'tnix') |
| 1243 | call assert_equal([0, 5, 11, 0], getpos('.')) |
| 1244 | " <S-Up> is the same as <PageUp> |
| 1245 | " <S-Down> is the same as <PageDown> |
| 1246 | call cursor(1, 1) |
| 1247 | call feedkeys("i\<S-Down>\<esc>", 'tnix') |
| 1248 | call assert_equal([0, 9, 1, 0], getpos('.')) |
| 1249 | call feedkeys("i\<S-Down>\<esc>", 'tnix') |
| 1250 | call assert_equal([0, 17, 1, 0], getpos('.')) |
| 1251 | call feedkeys("i\<S-Down>\<esc>", 'tnix') |
| 1252 | call assert_equal([0, 25, 1, 0], getpos('.')) |
| 1253 | call feedkeys("i\<S-Down>\<esc>", 'tnix') |
| 1254 | call assert_equal([0, 30, 1, 0], getpos('.')) |
| 1255 | call feedkeys("i\<S-Down>\<esc>", 'tnix') |
| 1256 | call assert_equal([0, 30, 1, 0], getpos('.')) |
| 1257 | call feedkeys("A\<S-Up>\<esc>", 'tnix') |
| 1258 | call assert_equal([0, 29, 1, 0], getpos('.')) |
| 1259 | call feedkeys("A\<S-Up>\<esc>", 'tnix') |
| 1260 | call assert_equal([0, 21, 1, 0], getpos('.')) |
| 1261 | call feedkeys("A\<S-Up>\<esc>", 'tnix') |
| 1262 | call assert_equal([0, 13, 1, 0], getpos('.')) |
| 1263 | call feedkeys("A\<S-Up>\<esc>", 'tnix') |
| 1264 | call assert_equal([0, 5, 1, 0], getpos('.')) |
| 1265 | call feedkeys("A\<S-Up>\<esc>", 'tnix') |
| 1266 | call assert_equal([0, 5, 11, 0], getpos('.')) |
| 1267 | set nostartofline |
| 1268 | call cursor(30, 11) |
| 1269 | norm! zt |
| 1270 | call feedkeys("A\<PageUp>\<esc>", 'tnix') |
| 1271 | call assert_equal([0, 29, 11, 0], getpos('.')) |
| 1272 | call feedkeys("A\<PageUp>\<esc>", 'tnix') |
| 1273 | call assert_equal([0, 21, 11, 0], getpos('.')) |
| 1274 | call feedkeys("A\<PageUp>\<esc>", 'tnix') |
| 1275 | call assert_equal([0, 13, 11, 0], getpos('.')) |
| 1276 | call feedkeys("A\<PageUp>\<esc>", 'tnix') |
| 1277 | call assert_equal([0, 5, 11, 0], getpos('.')) |
| 1278 | call feedkeys("A\<PageUp>\<esc>", 'tnix') |
| 1279 | call assert_equal([0, 5, 11, 0], getpos('.')) |
| 1280 | call cursor(1, 1) |
| 1281 | call feedkeys("A\<PageDown>\<esc>", 'tnix') |
| 1282 | call assert_equal([0, 9, 11, 0], getpos('.')) |
| 1283 | call feedkeys("A\<PageDown>\<esc>", 'tnix') |
| 1284 | call assert_equal([0, 17, 11, 0], getpos('.')) |
| 1285 | call feedkeys("A\<PageDown>\<esc>", 'tnix') |
| 1286 | call assert_equal([0, 25, 11, 0], getpos('.')) |
| 1287 | call feedkeys("A\<PageDown>\<esc>", 'tnix') |
| 1288 | call assert_equal([0, 30, 11, 0], getpos('.')) |
| 1289 | call feedkeys("A\<PageDown>\<esc>", 'tnix') |
| 1290 | call assert_equal([0, 30, 11, 0], getpos('.')) |
| 1291 | " <S-Up> is the same as <PageUp> |
| 1292 | " <S-Down> is the same as <PageDown> |
| 1293 | call cursor(30, 11) |
| 1294 | norm! zt |
| 1295 | call feedkeys("A\<S-Up>\<esc>", 'tnix') |
| 1296 | call assert_equal([0, 29, 11, 0], getpos('.')) |
| 1297 | call feedkeys("A\<S-Up>\<esc>", 'tnix') |
| 1298 | call assert_equal([0, 21, 11, 0], getpos('.')) |
| 1299 | call feedkeys("A\<S-Up>\<esc>", 'tnix') |
| 1300 | call assert_equal([0, 13, 11, 0], getpos('.')) |
| 1301 | call feedkeys("A\<S-Up>\<esc>", 'tnix') |
| 1302 | call assert_equal([0, 5, 11, 0], getpos('.')) |
| 1303 | call feedkeys("A\<S-Up>\<esc>", 'tnix') |
| 1304 | call assert_equal([0, 5, 11, 0], getpos('.')) |
| 1305 | call cursor(1, 1) |
| 1306 | call feedkeys("A\<S-Down>\<esc>", 'tnix') |
| 1307 | call assert_equal([0, 9, 11, 0], getpos('.')) |
| 1308 | call feedkeys("A\<S-Down>\<esc>", 'tnix') |
| 1309 | call assert_equal([0, 17, 11, 0], getpos('.')) |
| 1310 | call feedkeys("A\<S-Down>\<esc>", 'tnix') |
| 1311 | call assert_equal([0, 25, 11, 0], getpos('.')) |
| 1312 | call feedkeys("A\<S-Down>\<esc>", 'tnix') |
| 1313 | call assert_equal([0, 30, 11, 0], getpos('.')) |
| 1314 | call feedkeys("A\<S-Down>\<esc>", 'tnix') |
| 1315 | call assert_equal([0, 30, 11, 0], getpos('.')) |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 1316 | bw! |
| 1317 | endfunc |
| 1318 | |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 1319 | func Test_edit_forbidden() |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 1320 | new |
| 1321 | " 1) edit in the sandbox is not allowed |
| 1322 | call setline(1, 'a') |
| 1323 | com! Sandbox :sandbox call feedkeys("i\<del>\<esc>", 'tnix') |
| 1324 | call assert_fails(':Sandbox', 'E48:') |
| 1325 | com! Sandbox :sandbox exe "norm! i\<del>" |
| 1326 | call assert_fails(':Sandbox', 'E48:') |
| 1327 | delcom Sandbox |
| 1328 | call assert_equal(['a'], getline(1,'$')) |
Bram Moolenaar | 52797ba | 2021-12-16 14:45:13 +0000 | [diff] [blame] | 1329 | |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 1330 | " 2) edit with textlock set |
| 1331 | fu! DoIt() |
| 1332 | call feedkeys("i\<del>\<esc>", 'tnix') |
| 1333 | endfu |
| 1334 | au InsertCharPre <buffer> :call DoIt() |
| 1335 | try |
| 1336 | call feedkeys("ix\<esc>", 'tnix') |
| 1337 | call assert_fails(1, 'textlock') |
Bram Moolenaar | ff06f28 | 2020-04-21 22:01:14 +0200 | [diff] [blame] | 1338 | catch /^Vim\%((\a\+)\)\=:E565/ " catch E565: not allowed here |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 1339 | endtry |
| 1340 | " TODO: Might be a bug: should x really be inserted here |
| 1341 | call assert_equal(['xa'], getline(1, '$')) |
| 1342 | delfu DoIt |
| 1343 | try |
| 1344 | call feedkeys("ix\<esc>", 'tnix') |
| 1345 | call assert_fails(1, 'unknown function') |
| 1346 | catch /^Vim\%((\a\+)\)\=:E117/ " catch E117: unknown function |
| 1347 | endtry |
| 1348 | au! InsertCharPre |
Bram Moolenaar | 52797ba | 2021-12-16 14:45:13 +0000 | [diff] [blame] | 1349 | |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 1350 | " 3) edit when completion is shown |
| 1351 | fun! Complete(findstart, base) |
| 1352 | if a:findstart |
| 1353 | return col('.') |
| 1354 | else |
| 1355 | call feedkeys("i\<del>\<esc>", 'tnix') |
| 1356 | return [] |
| 1357 | endif |
| 1358 | endfun |
| 1359 | set completefunc=Complete |
| 1360 | try |
| 1361 | call feedkeys("i\<c-x>\<c-u>\<esc>", 'tnix') |
| 1362 | call assert_fails(1, 'change in complete function') |
Bram Moolenaar | ff06f28 | 2020-04-21 22:01:14 +0200 | [diff] [blame] | 1363 | catch /^Vim\%((\a\+)\)\=:E565/ " catch E565 |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 1364 | endtry |
| 1365 | delfu Complete |
| 1366 | set completefunc= |
Bram Moolenaar | 52797ba | 2021-12-16 14:45:13 +0000 | [diff] [blame] | 1367 | |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 1368 | if has("rightleft") && exists("+fkmap") |
| 1369 | " 4) 'R' when 'fkmap' and 'revins' is set. |
| 1370 | set revins fkmap |
| 1371 | try |
| 1372 | normal Ri |
| 1373 | call assert_fails(1, "R with 'fkmap' and 'ri' set") |
| 1374 | catch |
| 1375 | finally |
| 1376 | set norevins nofkmap |
| 1377 | endtry |
| 1378 | endif |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 1379 | bw! |
| 1380 | endfunc |
| 1381 | |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 1382 | func Test_edit_rightleft() |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 1383 | " Cursor in rightleft mode moves differently |
Bram Moolenaar | 845e0ee | 2020-06-20 16:05:32 +0200 | [diff] [blame] | 1384 | CheckFeature rightleft |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 1385 | call NewWindow(10, 20) |
| 1386 | call setline(1, ['abc', 'def', 'ghi']) |
| 1387 | call cursor(1, 2) |
| 1388 | set rightleft |
| 1389 | " Screen looks as expected |
| 1390 | let lines = ScreenLines([1, 4], winwidth(0)) |
| 1391 | let expect = [ |
| 1392 | \" cba", |
| 1393 | \" fed", |
| 1394 | \" ihg", |
| 1395 | \" ~"] |
| 1396 | call assert_equal(join(expect, "\n"), join(lines, "\n")) |
| 1397 | " 2) right moves to the left |
| 1398 | call feedkeys("i\<right>\<esc>x", 'txin') |
| 1399 | call assert_equal(['bc', 'def', 'ghi'], getline(1,'$')) |
| 1400 | call cursor(1, 2) |
| 1401 | call feedkeys("i\<s-right>\<esc>", 'txin') |
| 1402 | call cursor(1, 2) |
| 1403 | call feedkeys("i\<c-right>\<esc>", 'txin') |
| 1404 | " Screen looks as expected |
| 1405 | let lines = ScreenLines([1, 4], winwidth(0)) |
| 1406 | let expect = [ |
| 1407 | \" cb", |
| 1408 | \" fed", |
| 1409 | \" ihg", |
| 1410 | \" ~"] |
| 1411 | call assert_equal(join(expect, "\n"), join(lines, "\n")) |
| 1412 | " 2) left moves to the right |
| 1413 | call setline(1, ['abc', 'def', 'ghi']) |
| 1414 | call cursor(1, 2) |
| 1415 | call feedkeys("i\<left>\<esc>x", 'txin') |
| 1416 | call assert_equal(['ac', 'def', 'ghi'], getline(1,'$')) |
| 1417 | call cursor(1, 2) |
| 1418 | call feedkeys("i\<s-left>\<esc>", 'txin') |
| 1419 | call cursor(1, 2) |
| 1420 | call feedkeys("i\<c-left>\<esc>", 'txin') |
| 1421 | " Screen looks as expected |
| 1422 | let lines = ScreenLines([1, 4], winwidth(0)) |
| 1423 | let expect = [ |
| 1424 | \" ca", |
| 1425 | \" fed", |
| 1426 | \" ihg", |
| 1427 | \" ~"] |
| 1428 | call assert_equal(join(expect, "\n"), join(lines, "\n")) |
Bram Moolenaar | 845e0ee | 2020-06-20 16:05:32 +0200 | [diff] [blame] | 1429 | %d _ |
| 1430 | call test_override('redraw_flag', 1) |
| 1431 | call test_override('char_avail', 1) |
| 1432 | call feedkeys("a\<C-V>x41", "xt") |
| 1433 | redraw! |
| 1434 | call assert_equal(repeat(' ', 19) .. 'A', Screenline(1)) |
| 1435 | call test_override('ALL', 0) |
Bram Moolenaar | eb992cb | 2017-03-09 18:20:16 +0100 | [diff] [blame] | 1436 | set norightleft |
| 1437 | bw! |
| 1438 | endfunc |
Bram Moolenaar | 658a3a2 | 2017-03-31 22:27:12 +0200 | [diff] [blame] | 1439 | |
| 1440 | func Test_edit_complete_very_long_name() |
Bram Moolenaar | 6d91bcb | 2020-08-12 18:50:36 +0200 | [diff] [blame] | 1441 | " Long directory names only work on Unix. |
| 1442 | CheckUnix |
Bram Moolenaar | 15ecbd6 | 2017-04-07 14:10:48 +0200 | [diff] [blame] | 1443 | |
| 1444 | let dirname = getcwd() . "/Xdir" |
| 1445 | let longdirname = dirname . repeat('/' . repeat('d', 255), 4) |
| 1446 | try |
| 1447 | call mkdir(longdirname, 'p') |
| 1448 | catch /E739:/ |
| 1449 | " Long directory name probably not supported. |
| 1450 | call delete(dirname, 'rf') |
| 1451 | return |
| 1452 | endtry |
| 1453 | |
Bram Moolenaar | f8191c5 | 2019-05-18 17:22:54 +0200 | [diff] [blame] | 1454 | " Try to get the Vim window position before setting 'columns', so that we can |
| 1455 | " move the window back to where it was. |
Bram Moolenaar | ba6ec18 | 2017-04-04 22:41:10 +0200 | [diff] [blame] | 1456 | let winposx = getwinposx() |
| 1457 | let winposy = getwinposy() |
Bram Moolenaar | f8191c5 | 2019-05-18 17:22:54 +0200 | [diff] [blame] | 1458 | |
| 1459 | if winposx >= 0 && winposy >= 0 && !has('gui_running') |
| 1460 | " We did get the window position, but xterm may report the wrong numbers. |
| 1461 | " Move the window to the reported position and compute any offset. |
| 1462 | exe 'winpos ' . winposx . ' ' . winposy |
| 1463 | sleep 100m |
| 1464 | let x = getwinposx() |
| 1465 | if x >= 0 |
| 1466 | let winposx += winposx - x |
| 1467 | endif |
| 1468 | let y = getwinposy() |
| 1469 | if y >= 0 |
| 1470 | let winposy += winposy - y |
| 1471 | endif |
| 1472 | endif |
| 1473 | |
Bram Moolenaar | 658a3a2 | 2017-03-31 22:27:12 +0200 | [diff] [blame] | 1474 | let save_columns = &columns |
Bram Moolenaar | 15ecbd6 | 2017-04-07 14:10:48 +0200 | [diff] [blame] | 1475 | " Need at least about 1100 columns to reproduce the problem. |
Bram Moolenaar | ba6ec18 | 2017-04-04 22:41:10 +0200 | [diff] [blame] | 1476 | set columns=2000 |
Bram Moolenaar | 658a3a2 | 2017-03-31 22:27:12 +0200 | [diff] [blame] | 1477 | set noswapfile |
Bram Moolenaar | ba6ec18 | 2017-04-04 22:41:10 +0200 | [diff] [blame] | 1478 | |
Bram Moolenaar | 658a3a2 | 2017-03-31 22:27:12 +0200 | [diff] [blame] | 1479 | let longfilename = longdirname . '/' . repeat('a', 255) |
Bram Moolenaar | 658a3a2 | 2017-03-31 22:27:12 +0200 | [diff] [blame] | 1480 | call writefile(['Totum', 'Table'], longfilename) |
| 1481 | new |
| 1482 | exe "next Xfile " . longfilename |
| 1483 | exe "normal iT\<C-N>" |
| 1484 | |
| 1485 | bwipe! |
| 1486 | exe 'bwipe! ' . longfilename |
| 1487 | call delete(dirname, 'rf') |
| 1488 | let &columns = save_columns |
Bram Moolenaar | ba6ec18 | 2017-04-04 22:41:10 +0200 | [diff] [blame] | 1489 | if winposx >= 0 && winposy >= 0 |
| 1490 | exe 'winpos ' . winposx . ' ' . winposy |
| 1491 | endif |
Bram Moolenaar | 658a3a2 | 2017-03-31 22:27:12 +0200 | [diff] [blame] | 1492 | set swapfile& |
| 1493 | endfunc |
Bram Moolenaar | ff930ca | 2017-10-19 17:12:10 +0200 | [diff] [blame] | 1494 | |
Bram Moolenaar | 2c8c681 | 2018-07-28 17:07:52 +0200 | [diff] [blame] | 1495 | func Test_edit_backtick() |
| 1496 | next a\`b c |
| 1497 | call assert_equal('a`b', expand('%')) |
| 1498 | next |
| 1499 | call assert_equal('c', expand('%')) |
| 1500 | call assert_equal('a\`b c', expand('##')) |
| 1501 | endfunc |
| 1502 | |
Bram Moolenaar | ff930ca | 2017-10-19 17:12:10 +0200 | [diff] [blame] | 1503 | func Test_edit_quit() |
| 1504 | edit foo.txt |
| 1505 | split |
| 1506 | new |
| 1507 | call setline(1, 'hello') |
| 1508 | 3wincmd w |
| 1509 | redraw! |
| 1510 | call assert_fails('1q', 'E37:') |
| 1511 | bwipe! foo.txt |
| 1512 | only |
| 1513 | endfunc |
| 1514 | |
Bram Moolenaar | adb8fbe | 2018-06-04 20:34:23 +0200 | [diff] [blame] | 1515 | func Test_edit_alt() |
| 1516 | " Keeping the cursor line didn't happen when the first line has indent. |
| 1517 | new |
| 1518 | call setline(1, [' one', 'two', 'three']) |
| 1519 | w XAltFile |
| 1520 | $ |
| 1521 | call assert_equal(3, line('.')) |
| 1522 | e Xother |
| 1523 | e # |
| 1524 | call assert_equal(3, line('.')) |
| 1525 | |
| 1526 | bwipe XAltFile |
| 1527 | call delete('XAltFile') |
| 1528 | endfunc |
Bram Moolenaar | 4dbc262 | 2018-11-02 11:59:15 +0100 | [diff] [blame] | 1529 | |
Bram Moolenaar | db93495 | 2020-04-27 20:18:31 +0200 | [diff] [blame] | 1530 | func Test_edit_InsertLeave() |
Bram Moolenaar | 4dbc262 | 2018-11-02 11:59:15 +0100 | [diff] [blame] | 1531 | new |
Bram Moolenaar | b53e13a | 2020-10-21 12:19:53 +0200 | [diff] [blame] | 1532 | au InsertLeavePre * let g:did_au_pre = 1 |
Bram Moolenaar | 4dbc262 | 2018-11-02 11:59:15 +0100 | [diff] [blame] | 1533 | au InsertLeave * let g:did_au = 1 |
Bram Moolenaar | b53e13a | 2020-10-21 12:19:53 +0200 | [diff] [blame] | 1534 | let g:did_au_pre = 0 |
Bram Moolenaar | 4dbc262 | 2018-11-02 11:59:15 +0100 | [diff] [blame] | 1535 | let g:did_au = 0 |
| 1536 | call feedkeys("afoo\<Esc>", 'tx') |
Bram Moolenaar | b53e13a | 2020-10-21 12:19:53 +0200 | [diff] [blame] | 1537 | call assert_equal(1, g:did_au_pre) |
Bram Moolenaar | 4dbc262 | 2018-11-02 11:59:15 +0100 | [diff] [blame] | 1538 | call assert_equal(1, g:did_au) |
| 1539 | call assert_equal('foo', getline(1)) |
| 1540 | |
Bram Moolenaar | b53e13a | 2020-10-21 12:19:53 +0200 | [diff] [blame] | 1541 | let g:did_au_pre = 0 |
Bram Moolenaar | 4dbc262 | 2018-11-02 11:59:15 +0100 | [diff] [blame] | 1542 | let g:did_au = 0 |
| 1543 | call feedkeys("Sbar\<C-C>", 'tx') |
Bram Moolenaar | b53e13a | 2020-10-21 12:19:53 +0200 | [diff] [blame] | 1544 | call assert_equal(1, g:did_au_pre) |
Bram Moolenaar | 4dbc262 | 2018-11-02 11:59:15 +0100 | [diff] [blame] | 1545 | call assert_equal(0, g:did_au) |
| 1546 | call assert_equal('bar', getline(1)) |
| 1547 | |
| 1548 | inoremap x xx<Esc> |
Bram Moolenaar | b53e13a | 2020-10-21 12:19:53 +0200 | [diff] [blame] | 1549 | let g:did_au_pre = 0 |
Bram Moolenaar | 4dbc262 | 2018-11-02 11:59:15 +0100 | [diff] [blame] | 1550 | let g:did_au = 0 |
| 1551 | call feedkeys("Saax", 'tx') |
Bram Moolenaar | b53e13a | 2020-10-21 12:19:53 +0200 | [diff] [blame] | 1552 | call assert_equal(1, g:did_au_pre) |
Bram Moolenaar | 4dbc262 | 2018-11-02 11:59:15 +0100 | [diff] [blame] | 1553 | call assert_equal(1, g:did_au) |
| 1554 | call assert_equal('aaxx', getline(1)) |
| 1555 | |
| 1556 | inoremap x xx<C-C> |
Bram Moolenaar | b53e13a | 2020-10-21 12:19:53 +0200 | [diff] [blame] | 1557 | let g:did_au_pre = 0 |
Bram Moolenaar | 4dbc262 | 2018-11-02 11:59:15 +0100 | [diff] [blame] | 1558 | let g:did_au = 0 |
| 1559 | call feedkeys("Sbbx", 'tx') |
Bram Moolenaar | b53e13a | 2020-10-21 12:19:53 +0200 | [diff] [blame] | 1560 | call assert_equal(1, g:did_au_pre) |
Bram Moolenaar | 4dbc262 | 2018-11-02 11:59:15 +0100 | [diff] [blame] | 1561 | call assert_equal(0, g:did_au) |
| 1562 | call assert_equal('bbxx', getline(1)) |
| 1563 | |
| 1564 | bwipe! |
Bram Moolenaar | b53e13a | 2020-10-21 12:19:53 +0200 | [diff] [blame] | 1565 | au! InsertLeave InsertLeavePre |
Bram Moolenaar | 4dbc262 | 2018-11-02 11:59:15 +0100 | [diff] [blame] | 1566 | iunmap x |
| 1567 | endfunc |
Bram Moolenaar | c6b37db | 2019-04-27 18:00:34 +0200 | [diff] [blame] | 1568 | |
Bram Moolenaar | db93495 | 2020-04-27 20:18:31 +0200 | [diff] [blame] | 1569 | func Test_edit_InsertLeave_undo() |
| 1570 | new XtestUndo |
| 1571 | set undofile |
| 1572 | au InsertLeave * wall |
| 1573 | exe "normal ofoo\<Esc>" |
| 1574 | call assert_equal(2, line('$')) |
| 1575 | normal u |
| 1576 | call assert_equal(1, line('$')) |
| 1577 | |
| 1578 | bwipe! |
| 1579 | au! InsertLeave |
| 1580 | call delete('XtestUndo') |
Bram Moolenaar | b340bae | 2020-06-15 19:51:56 +0200 | [diff] [blame] | 1581 | call delete(undofile('XtestUndo')) |
Bram Moolenaar | db93495 | 2020-04-27 20:18:31 +0200 | [diff] [blame] | 1582 | set undofile& |
| 1583 | endfunc |
| 1584 | |
Bram Moolenaar | c6b37db | 2019-04-27 18:00:34 +0200 | [diff] [blame] | 1585 | " Test for inserting characters using CTRL-V followed by a number. |
| 1586 | func Test_edit_special_chars() |
| 1587 | new |
| 1588 | |
| 1589 | if has("ebcdic") |
| 1590 | let t = "o\<C-V>193\<C-V>xc2\<C-V>o303 \<C-V>90a\<C-V>xfg\<C-V>o578\<Esc>" |
| 1591 | else |
| 1592 | let t = "o\<C-V>65\<C-V>x42\<C-V>o103 \<C-V>33a\<C-V>xfg\<C-V>o78\<Esc>" |
| 1593 | endif |
| 1594 | |
| 1595 | exe "normal " . t |
| 1596 | call assert_equal("ABC !a\<C-O>g\<C-G>8", getline(2)) |
| 1597 | |
| 1598 | close! |
| 1599 | endfunc |
Bram Moolenaar | 8d3b510 | 2019-09-05 21:29:01 +0200 | [diff] [blame] | 1600 | |
| 1601 | func Test_edit_startinsert() |
| 1602 | new |
| 1603 | set backspace+=start |
| 1604 | call setline(1, 'foobar') |
| 1605 | call feedkeys("A\<C-U>\<Esc>", 'xt') |
| 1606 | call assert_equal('', getline(1)) |
| 1607 | |
| 1608 | call setline(1, 'foobar') |
| 1609 | call feedkeys(":startinsert!\<CR>\<C-U>\<Esc>", 'xt') |
| 1610 | call assert_equal('', getline(1)) |
| 1611 | |
| 1612 | set backspace& |
| 1613 | bwipe! |
| 1614 | endfunc |
Bram Moolenaar | 177c9f2 | 2019-11-06 13:59:16 +0100 | [diff] [blame] | 1615 | |
Bram Moolenaar | bc2b71d | 2020-02-17 21:33:30 +0100 | [diff] [blame] | 1616 | " Test for :startreplace and :startgreplace |
| 1617 | func Test_edit_startreplace() |
| 1618 | new |
| 1619 | call setline(1, 'abc') |
| 1620 | call feedkeys("l:startreplace\<CR>xyz\e", 'xt') |
| 1621 | call assert_equal('axyz', getline(1)) |
| 1622 | call feedkeys("0:startreplace!\<CR>abc\e", 'xt') |
| 1623 | call assert_equal('axyzabc', getline(1)) |
| 1624 | call setline(1, "a\tb") |
| 1625 | call feedkeys("0l:startgreplace\<CR>xyz\e", 'xt') |
| 1626 | call assert_equal("axyz\tb", getline(1)) |
| 1627 | call feedkeys("0i\<C-R>=execute('startreplace')\<CR>12\e", 'xt') |
| 1628 | call assert_equal("12axyz\tb", getline(1)) |
| 1629 | close! |
| 1630 | endfunc |
| 1631 | |
Bram Moolenaar | 177c9f2 | 2019-11-06 13:59:16 +0100 | [diff] [blame] | 1632 | func Test_edit_noesckeys() |
Bram Moolenaar | 215ba3b | 2019-11-06 15:07:07 +0100 | [diff] [blame] | 1633 | CheckNotGui |
Bram Moolenaar | 177c9f2 | 2019-11-06 13:59:16 +0100 | [diff] [blame] | 1634 | new |
| 1635 | |
| 1636 | " <Left> moves cursor when 'esckeys' is set |
| 1637 | exe "set t_kl=\<Esc>OD" |
| 1638 | set esckeys |
| 1639 | call feedkeys("axyz\<Esc>ODX", "xt") |
| 1640 | call assert_equal("xyXz", getline(1)) |
| 1641 | |
| 1642 | " <Left> exits Insert mode when 'esckeys' is off |
| 1643 | set noesckeys |
| 1644 | call setline(1, '') |
| 1645 | call feedkeys("axyz\<Esc>ODX", "xt") |
| 1646 | call assert_equal(["DX", "xyz"], getline(1, 2)) |
| 1647 | |
| 1648 | bwipe! |
| 1649 | set esckeys |
| 1650 | endfunc |
Bram Moolenaar | bc2b71d | 2020-02-17 21:33:30 +0100 | [diff] [blame] | 1651 | |
Bram Moolenaar | 1671f44 | 2020-03-10 07:48:13 +0100 | [diff] [blame] | 1652 | " Test for running an invalid ex command in insert mode using CTRL-O |
Bram Moolenaar | 1671f44 | 2020-03-10 07:48:13 +0100 | [diff] [blame] | 1653 | func Test_edit_ctrl_o_invalid_cmd() |
| 1654 | new |
| 1655 | set showmode showcmd |
Bram Moolenaar | b340bae | 2020-06-15 19:51:56 +0200 | [diff] [blame] | 1656 | " Avoid a sleep of 3 seconds. Zero might have side effects. |
| 1657 | call test_override('ui_delay', 50) |
Bram Moolenaar | 1671f44 | 2020-03-10 07:48:13 +0100 | [diff] [blame] | 1658 | let caught_e492 = 0 |
| 1659 | try |
| 1660 | call feedkeys("i\<C-O>:invalid\<CR>abc\<Esc>", "xt") |
| 1661 | catch /E492:/ |
| 1662 | let caught_e492 = 1 |
| 1663 | endtry |
| 1664 | call assert_equal(1, caught_e492) |
| 1665 | call assert_equal('abc', getline(1)) |
| 1666 | set showmode& showcmd& |
Bram Moolenaar | b340bae | 2020-06-15 19:51:56 +0200 | [diff] [blame] | 1667 | call test_override('ui_delay', 0) |
Bram Moolenaar | 1671f44 | 2020-03-10 07:48:13 +0100 | [diff] [blame] | 1668 | close! |
| 1669 | endfunc |
| 1670 | |
Bram Moolenaar | b340bae | 2020-06-15 19:51:56 +0200 | [diff] [blame] | 1671 | " Test for editing a file with a very long name |
| 1672 | func Test_edit_illegal_filename() |
| 1673 | CheckEnglish |
| 1674 | new |
| 1675 | redir => msg |
| 1676 | exe 'edit ' . repeat('f', 5000) |
| 1677 | redir END |
| 1678 | call assert_match("Illegal file name$", split(msg, "\n")[0]) |
| 1679 | close! |
| 1680 | endfunc |
| 1681 | |
Bram Moolenaar | c8fe645 | 2020-10-03 17:04:37 +0200 | [diff] [blame] | 1682 | " Test for editing a directory |
| 1683 | func Test_edit_is_a_directory() |
| 1684 | CheckEnglish |
| 1685 | let dirname = getcwd() . "/Xdir" |
| 1686 | call mkdir(dirname, 'p') |
| 1687 | |
| 1688 | new |
| 1689 | redir => msg |
| 1690 | exe 'edit' dirname |
| 1691 | redir END |
| 1692 | call assert_match("is a directory$", split(msg, "\n")[0]) |
| 1693 | bwipe! |
| 1694 | |
| 1695 | let dirname .= '/' |
| 1696 | |
| 1697 | new |
| 1698 | redir => msg |
| 1699 | exe 'edit' dirname |
| 1700 | redir END |
| 1701 | call assert_match("is a directory$", split(msg, "\n")[0]) |
| 1702 | bwipe! |
| 1703 | |
| 1704 | call delete(dirname, 'rf') |
| 1705 | endfunc |
| 1706 | |
Bram Moolenaar | b340bae | 2020-06-15 19:51:56 +0200 | [diff] [blame] | 1707 | " Test for editing a file using invalid file encoding |
| 1708 | func Test_edit_invalid_encoding() |
| 1709 | CheckEnglish |
| 1710 | call writefile([], 'Xfile') |
| 1711 | redir => msg |
| 1712 | new ++enc=axbyc Xfile |
| 1713 | redir END |
| 1714 | call assert_match('\[NOT converted\]', msg) |
| 1715 | call delete('Xfile') |
| 1716 | close! |
| 1717 | endfunc |
| 1718 | |
| 1719 | " Test for the "charconvert" option |
| 1720 | func Test_edit_charconvert() |
| 1721 | CheckEnglish |
| 1722 | call writefile(['one', 'two'], 'Xfile') |
| 1723 | |
| 1724 | " set 'charconvert' to a non-existing function |
| 1725 | set charconvert=NonExitingFunc() |
| 1726 | new |
| 1727 | let caught_e117 = v:false |
| 1728 | try |
| 1729 | redir => msg |
| 1730 | edit ++enc=axbyc Xfile |
| 1731 | catch /E117:/ |
| 1732 | let caught_e117 = v:true |
| 1733 | finally |
| 1734 | redir END |
| 1735 | endtry |
| 1736 | call assert_true(caught_e117) |
| 1737 | call assert_equal(['one', 'two'], getline(1, '$')) |
| 1738 | call assert_match("Conversion with 'charconvert' failed", msg) |
| 1739 | close! |
| 1740 | set charconvert& |
| 1741 | |
| 1742 | " 'charconvert' function doesn't create a output file |
| 1743 | func Cconv1() |
| 1744 | endfunc |
| 1745 | set charconvert=Cconv1() |
| 1746 | new |
| 1747 | redir => msg |
| 1748 | edit ++enc=axbyc Xfile |
| 1749 | redir END |
| 1750 | call assert_equal(['one', 'two'], getline(1, '$')) |
| 1751 | call assert_match("can't read output of 'charconvert'", msg) |
| 1752 | close! |
| 1753 | delfunc Cconv1 |
| 1754 | set charconvert& |
| 1755 | |
| 1756 | " 'charconvert' function to convert to upper case |
| 1757 | func Cconv2() |
| 1758 | let data = readfile(v:fname_in) |
| 1759 | call map(data, 'toupper(v:val)') |
| 1760 | call writefile(data, v:fname_out) |
| 1761 | endfunc |
| 1762 | set charconvert=Cconv2() |
| 1763 | new Xfile |
| 1764 | write ++enc=ucase Xfile1 |
| 1765 | call assert_equal(['ONE', 'TWO'], readfile('Xfile1')) |
| 1766 | call delete('Xfile1') |
| 1767 | close! |
| 1768 | delfunc Cconv2 |
| 1769 | set charconvert& |
| 1770 | |
| 1771 | " 'charconvert' function removes the input file |
| 1772 | func Cconv3() |
| 1773 | call delete(v:fname_in) |
| 1774 | endfunc |
| 1775 | set charconvert=Cconv3() |
| 1776 | new |
| 1777 | call assert_fails('edit ++enc=lcase Xfile', 'E202:') |
| 1778 | call assert_equal([''], getline(1, '$')) |
| 1779 | close! |
| 1780 | delfunc Cconv3 |
| 1781 | set charconvert& |
| 1782 | |
| 1783 | call delete('Xfile') |
| 1784 | endfunc |
| 1785 | |
| 1786 | " Test for editing a file without read permission |
| 1787 | func Test_edit_file_no_read_perm() |
| 1788 | CheckUnix |
Bram Moolenaar | 17709e2 | 2021-03-19 14:38:12 +0100 | [diff] [blame] | 1789 | CheckNotRoot |
| 1790 | |
Bram Moolenaar | b340bae | 2020-06-15 19:51:56 +0200 | [diff] [blame] | 1791 | call writefile(['one', 'two'], 'Xfile') |
| 1792 | call setfperm('Xfile', '-w-------') |
| 1793 | new |
| 1794 | redir => msg |
| 1795 | edit Xfile |
| 1796 | redir END |
| 1797 | call assert_equal(1, &readonly) |
| 1798 | call assert_equal([''], getline(1, '$')) |
| 1799 | call assert_match('\[Permission Denied\]', msg) |
| 1800 | close! |
| 1801 | call delete('Xfile') |
| 1802 | endfunc |
| 1803 | |
Bram Moolenaar | 845e0ee | 2020-06-20 16:05:32 +0200 | [diff] [blame] | 1804 | " Pressing escape in 'insertmode' should beep |
| 1805 | func Test_edit_insertmode_esc_beeps() |
| 1806 | new |
| 1807 | set insertmode |
| 1808 | call assert_beeps("call feedkeys(\"one\<Esc>\", 'xt')") |
| 1809 | set insertmode& |
| 1810 | " unsupported CTRL-G command should beep in insert mode. |
| 1811 | call assert_beeps("normal i\<C-G>l") |
| 1812 | close! |
| 1813 | endfunc |
| 1814 | |
| 1815 | " Test for 'hkmap' and 'hkmapp' |
| 1816 | func Test_edit_hkmap() |
| 1817 | CheckFeature rightleft |
| 1818 | if has('win32') && !has('gui') |
Bram Moolenaar | 6d91bcb | 2020-08-12 18:50:36 +0200 | [diff] [blame] | 1819 | throw 'Skipped: fails on the MS-Windows terminal version' |
Bram Moolenaar | 845e0ee | 2020-06-20 16:05:32 +0200 | [diff] [blame] | 1820 | endif |
| 1821 | new |
| 1822 | |
| 1823 | set revins hkmap |
| 1824 | let str = 'abcdefghijklmnopqrstuvwxyz' |
| 1825 | let str ..= 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' |
| 1826 | let str ..= '`/'',.;' |
| 1827 | call feedkeys('i' .. str, 'xt') |
| 1828 | let expected = "óõú,.;" |
| 1829 | let expected ..= "ZYXWVUTSRQPONMLKJIHGFEDCBA" |
| 1830 | let expected ..= "æèñ'äåà ãø/ôÃîöêìçïéòë÷âáðù" |
| 1831 | call assert_equal(expected, getline(1)) |
| 1832 | |
| 1833 | %d |
| 1834 | set revins hkmap hkmapp |
| 1835 | let str = 'abcdefghijklmnopqrstuvwxyz' |
| 1836 | let str ..= 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' |
| 1837 | call feedkeys('i' .. str, 'xt') |
| 1838 | let expected = "õYXWVUTSRQóOïÃLKJIHGFEDêBA" |
| 1839 | let expected ..= "öòXùåèúæø'ôñðîì÷çéäâóǟãëáà " |
| 1840 | call assert_equal(expected, getline(1)) |
| 1841 | |
| 1842 | set revins& hkmap& hkmapp& |
| 1843 | close! |
| 1844 | endfunc |
| 1845 | |
| 1846 | " Test for 'allowrevins' and using CTRL-_ in insert mode |
| 1847 | func Test_edit_allowrevins() |
| 1848 | CheckFeature rightleft |
| 1849 | new |
| 1850 | set allowrevins |
| 1851 | call feedkeys("iABC\<C-_>DEF\<C-_>GHI", 'xt') |
| 1852 | call assert_equal('ABCFEDGHI', getline(1)) |
| 1853 | set allowrevins& |
| 1854 | close! |
| 1855 | endfunc |
| 1856 | |
| 1857 | " Test for inserting a register in insert mode using CTRL-R |
| 1858 | func Test_edit_insert_reg() |
| 1859 | new |
| 1860 | let g:Line = '' |
| 1861 | func SaveFirstLine() |
| 1862 | let g:Line = Screenline(1) |
| 1863 | return 'r' |
| 1864 | endfunc |
| 1865 | inoremap <expr> <buffer> <F2> SaveFirstLine() |
| 1866 | call test_override('redraw_flag', 1) |
| 1867 | call test_override('char_avail', 1) |
| 1868 | let @r = 'sample' |
| 1869 | call feedkeys("a\<C-R>=SaveFirstLine()\<CR>", "xt") |
| 1870 | call assert_equal('"', g:Line) |
| 1871 | call test_override('ALL', 0) |
| 1872 | close! |
| 1873 | endfunc |
| 1874 | |
| 1875 | " When a character is inserted at the last position of the last line in a |
| 1876 | " window, the window contents should be scrolled one line up. If the top line |
| 1877 | " is part of a fold, then the entire fold should be scrolled up. |
| 1878 | func Test_edit_lastline_scroll() |
| 1879 | new |
| 1880 | let h = winheight(0) |
| 1881 | let lines = ['one', 'two', 'three'] |
| 1882 | let lines += repeat(['vim'], h - 4) |
| 1883 | call setline(1, lines) |
| 1884 | call setline(h, repeat('x', winwidth(0) - 1)) |
| 1885 | call feedkeys("GAx", 'xt') |
| 1886 | redraw! |
| 1887 | call assert_equal(h - 1, winline()) |
| 1888 | call assert_equal(2, line('w0')) |
| 1889 | |
| 1890 | " scroll with a fold |
| 1891 | 1,2fold |
| 1892 | normal gg |
| 1893 | call setline(h + 1, repeat('x', winwidth(0) - 1)) |
| 1894 | call feedkeys("GAx", 'xt') |
| 1895 | redraw! |
| 1896 | call assert_equal(h - 1, winline()) |
| 1897 | call assert_equal(3, line('w0')) |
| 1898 | |
| 1899 | close! |
| 1900 | endfunc |
| 1901 | |
Bram Moolenaar | 21cbe17 | 2020-10-13 19:08:24 +0200 | [diff] [blame] | 1902 | func Test_edit_browse() |
| 1903 | " in the GUI this opens a file picker, we only test the terminal behavior |
| 1904 | CheckNotGui |
| 1905 | |
| 1906 | " ":browse xxx" checks for the FileExplorer augroup and assumes editing "." |
| 1907 | " works then. |
| 1908 | augroup FileExplorer |
| 1909 | au! |
| 1910 | augroup END |
| 1911 | |
| 1912 | " When the USE_FNAME_CASE is defined this used to cause a crash. |
| 1913 | browse enew |
| 1914 | bwipe! |
| 1915 | |
| 1916 | browse split |
| 1917 | bwipe! |
| 1918 | endfunc |
| 1919 | |
Bram Moolenaar | caf73dc | 2020-10-26 21:39:13 +0100 | [diff] [blame] | 1920 | func Test_read_invalid() |
| 1921 | set encoding=latin1 |
| 1922 | " This was not properly checking for going past the end. |
| 1923 | call assert_fails('r`=', 'E484') |
| 1924 | set encoding=utf-8 |
| 1925 | endfunc |
| 1926 | |
Yegappan Lakshmanan | 5958549 | 2021-06-12 13:46:41 +0200 | [diff] [blame] | 1927 | " Test for the 'revins' option |
| 1928 | func Test_edit_revins() |
| 1929 | CheckFeature rightleft |
| 1930 | new |
| 1931 | set revins |
| 1932 | exe "normal! ione\ttwo three" |
| 1933 | call assert_equal("eerht owt\teno", getline(1)) |
| 1934 | call setline(1, "one\ttwo three") |
| 1935 | normal! gg$bi a |
| 1936 | call assert_equal("one\ttwo a three", getline(1)) |
| 1937 | exe "normal! $bi\<BS>\<BS>" |
| 1938 | call assert_equal("one\ttwo a ree", getline(1)) |
| 1939 | exe "normal! 0wi\<C-W>" |
| 1940 | call assert_equal("one\t a ree", getline(1)) |
| 1941 | exe "normal! 0wi\<C-U>" |
| 1942 | call assert_equal("one\t ", getline(1)) |
| 1943 | " newline in insert mode starts at the end of the line |
| 1944 | call setline(1, 'one two three') |
| 1945 | exe "normal! wi\nfour" |
| 1946 | call assert_equal(['one two three', 'ruof'], getline(1, '$')) |
| 1947 | set revins& |
| 1948 | bw! |
| 1949 | endfunc |
| 1950 | |
Bram Moolenaar | 35a9a00 | 2021-09-11 21:14:20 +0200 | [diff] [blame] | 1951 | " Test for getting the character of the line below after "p" |
| 1952 | func Test_edit_put_CTRL_E() |
| 1953 | set encoding=latin1 |
| 1954 | new |
| 1955 | let @" = '' |
| 1956 | sil! norm orggRx |
| 1957 | sil! norm pr |
| 1958 | call assert_equal(['r', 'r'], getline(1, 2)) |
| 1959 | bwipe! |
| 1960 | set encoding=utf-8 |
| 1961 | endfunc |
| 1962 | |
=?UTF-8?q?Magnus=20Gro=C3=9F?= | f1e8876 | 2021-09-12 13:39:55 +0200 | [diff] [blame] | 1963 | " Test for ModeChanged pattern |
| 1964 | func Test_mode_changes() |
=?UTF-8?q?Magnus=20Gro=C3=9F?= | f1e8876 | 2021-09-12 13:39:55 +0200 | [diff] [blame] | 1965 | let g:index = 0 |
=?UTF-8?q?Magnus=20Gro=C3=9F?= | 25def2c | 2021-10-22 18:56:39 +0100 | [diff] [blame] | 1966 | let g:mode_seq = ['n', 'i', 'n', 'v', 'V', 'i', 'ix', 'i', 'ic', 'i', 'n', 'no', 'n', 'V', 'v', 's', 'n'] |
=?UTF-8?q?Magnus=20Gro=C3=9F?= | f1e8876 | 2021-09-12 13:39:55 +0200 | [diff] [blame] | 1967 | func! TestMode() |
| 1968 | call assert_equal(g:mode_seq[g:index], get(v:event, "old_mode")) |
| 1969 | call assert_equal(g:mode_seq[g:index + 1], get(v:event, "new_mode")) |
Bram Moolenaar | d85931e | 2021-10-02 16:55:39 +0100 | [diff] [blame] | 1970 | call assert_equal(mode(1), get(v:event, "new_mode")) |
=?UTF-8?q?Magnus=20Gro=C3=9F?= | f1e8876 | 2021-09-12 13:39:55 +0200 | [diff] [blame] | 1971 | let g:index += 1 |
| 1972 | endfunc |
| 1973 | |
| 1974 | au ModeChanged * :call TestMode() |
=?UTF-8?q?Magnus=20Gro=C3=9F?= | 25def2c | 2021-10-22 18:56:39 +0100 | [diff] [blame] | 1975 | let g:n_to_any = 0 |
| 1976 | au ModeChanged n:* let g:n_to_any += 1 |
| 1977 | call feedkeys("i\<esc>vVca\<CR>\<C-X>\<C-L>\<esc>ggdG", 'tnix') |
=?UTF-8?q?Magnus=20Gro=C3=9F?= | f1e8876 | 2021-09-12 13:39:55 +0200 | [diff] [blame] | 1978 | |
=?UTF-8?q?Magnus=20Gro=C3=9F?= | 25def2c | 2021-10-22 18:56:39 +0100 | [diff] [blame] | 1979 | let g:V_to_v = 0 |
| 1980 | au ModeChanged V:v let g:V_to_v += 1 |
| 1981 | call feedkeys("Vv\<C-G>\<esc>", 'tnix') |
| 1982 | call assert_equal(len(filter(g:mode_seq[1:], {idx, val -> val == 'n'})), g:n_to_any) |
| 1983 | call assert_equal(1, g:V_to_v) |
Bram Moolenaar | d85931e | 2021-10-02 16:55:39 +0100 | [diff] [blame] | 1984 | call assert_equal(len(g:mode_seq) - 1, g:index) |
=?UTF-8?q?Magnus=20Gro=C3=9F?= | f1e8876 | 2021-09-12 13:39:55 +0200 | [diff] [blame] | 1985 | |
Bram Moolenaar | 72d2fa6 | 2021-10-02 21:48:15 +0100 | [diff] [blame] | 1986 | let g:n_to_i = 0 |
| 1987 | au ModeChanged n:i let g:n_to_i += 1 |
| 1988 | let g:n_to_niI = 0 |
| 1989 | au ModeChanged i:niI let g:n_to_niI += 1 |
| 1990 | let g:niI_to_i = 0 |
| 1991 | au ModeChanged niI:i let g:niI_to_i += 1 |
| 1992 | let g:nany_to_i = 0 |
| 1993 | au ModeChanged n*:i let g:nany_to_i += 1 |
| 1994 | let g:i_to_n = 0 |
| 1995 | au ModeChanged i:n let g:i_to_n += 1 |
| 1996 | let g:nori_to_any = 0 |
| 1997 | au ModeChanged [ni]:* let g:nori_to_any += 1 |
| 1998 | let g:i_to_any = 0 |
| 1999 | au ModeChanged i:* let g:i_to_any += 1 |
Bram Moolenaar | d85931e | 2021-10-02 16:55:39 +0100 | [diff] [blame] | 2000 | let g:index = 0 |
| 2001 | let g:mode_seq = ['n', 'i', 'niI', 'i', 'n'] |
| 2002 | call feedkeys("a\<C-O>l\<esc>", 'tnix') |
=?UTF-8?q?Magnus=20Gro=C3=9F?= | f1e8876 | 2021-09-12 13:39:55 +0200 | [diff] [blame] | 2003 | call assert_equal(len(g:mode_seq) - 1, g:index) |
Bram Moolenaar | 72d2fa6 | 2021-10-02 21:48:15 +0100 | [diff] [blame] | 2004 | call assert_equal(1, g:n_to_i) |
| 2005 | call assert_equal(1, g:n_to_niI) |
| 2006 | call assert_equal(1, g:niI_to_i) |
| 2007 | call assert_equal(2, g:nany_to_i) |
| 2008 | call assert_equal(1, g:i_to_n) |
| 2009 | call assert_equal(2, g:i_to_any) |
| 2010 | call assert_equal(3, g:nori_to_any) |
=?UTF-8?q?Magnus=20Gro=C3=9F?= | f1e8876 | 2021-09-12 13:39:55 +0200 | [diff] [blame] | 2011 | |
=?UTF-8?q?Magnus=20Gro=C3=9F?= | 25def2c | 2021-10-22 18:56:39 +0100 | [diff] [blame] | 2012 | if has('terminal') |
| 2013 | let g:mode_seq += ['c', 'n', 't', 'nt', 'c', 'nt', 'n'] |
| 2014 | call feedkeys(":term\<CR>\<C-W>N:bd!\<CR>", 'tnix') |
| 2015 | call assert_equal(len(g:mode_seq) - 1, g:index) |
| 2016 | call assert_equal(1, g:n_to_i) |
| 2017 | call assert_equal(1, g:n_to_niI) |
| 2018 | call assert_equal(1, g:niI_to_i) |
| 2019 | call assert_equal(2, g:nany_to_i) |
| 2020 | call assert_equal(1, g:i_to_n) |
| 2021 | call assert_equal(2, g:i_to_any) |
| 2022 | call assert_equal(5, g:nori_to_any) |
| 2023 | endif |
| 2024 | |
=?UTF-8?q?Magnus=20Gro=C3=9F?= | f1e8876 | 2021-09-12 13:39:55 +0200 | [diff] [blame] | 2025 | au! ModeChanged |
| 2026 | delfunc TestMode |
| 2027 | unlet! g:mode_seq |
| 2028 | unlet! g:index |
=?UTF-8?q?Magnus=20Gro=C3=9F?= | 25def2c | 2021-10-22 18:56:39 +0100 | [diff] [blame] | 2029 | unlet! g:n_to_any |
| 2030 | unlet! g:V_to_v |
| 2031 | unlet! g:n_to_i |
| 2032 | unlet! g:n_to_niI |
| 2033 | unlet! g:niI_to_i |
| 2034 | unlet! g:nany_to_i |
| 2035 | unlet! g:i_to_n |
| 2036 | unlet! g:nori_to_any |
| 2037 | unlet! g:i_to_any |
=?UTF-8?q?Magnus=20Gro=C3=9F?= | f1e8876 | 2021-09-12 13:39:55 +0200 | [diff] [blame] | 2038 | endfunc |
| 2039 | |
Bram Moolenaar | 3075a45 | 2021-11-17 15:51:52 +0000 | [diff] [blame] | 2040 | func Test_recursive_ModeChanged() |
| 2041 | au! ModeChanged * norm 0u |
| 2042 | sil! norm |
Bram Moolenaar | a062006 | 2021-11-17 16:52:40 +0000 | [diff] [blame] | 2043 | au! ModeChanged |
| 2044 | endfunc |
| 2045 | |
| 2046 | func Test_ModeChanged_starts_visual() |
| 2047 | " This was triggering ModeChanged before setting VIsual, causing a crash. |
| 2048 | au! ModeChanged * norm 0u |
| 2049 | sil! norm |
| 2050 | |
| 2051 | au! ModeChanged |
Bram Moolenaar | 3075a45 | 2021-11-17 15:51:52 +0000 | [diff] [blame] | 2052 | endfunc |
| 2053 | |
Dominique Pelle | 9cd063e | 2021-10-28 21:06:05 +0100 | [diff] [blame] | 2054 | " Test toggling of input method. See :help i_CTRL-^ |
| 2055 | func Test_edit_CTRL_hat() |
| 2056 | CheckFeature xim |
Dominique Pelle | 8753c1d | 2021-10-31 20:19:17 +0000 | [diff] [blame] | 2057 | |
| 2058 | " FIXME: test fails with Athena and Motif GUI. |
| 2059 | " test also fails when running in the GUI. |
| 2060 | CheckFeature gui_gtk |
| 2061 | CheckNotGui |
Dominique Pelle | 9cd063e | 2021-10-28 21:06:05 +0100 | [diff] [blame] | 2062 | |
| 2063 | new |
| 2064 | |
| 2065 | call assert_equal(0, &iminsert) |
| 2066 | call feedkeys("i\<C-^>", 'xt') |
| 2067 | call assert_equal(2, &iminsert) |
| 2068 | call feedkeys("i\<C-^>", 'xt') |
| 2069 | call assert_equal(0, &iminsert) |
| 2070 | |
| 2071 | bwipe! |
| 2072 | endfunc |
| 2073 | |
| 2074 | |
Bram Moolenaar | bc2b71d | 2020-02-17 21:33:30 +0100 | [diff] [blame] | 2075 | " vim: shiftwidth=2 sts=2 expandtab |