Bram Moolenaar | 3324d0a | 2018-03-06 19:51:13 +0100 | [diff] [blame] | 1 | " Tests for bracketed paste and other forms of pasting. |
Bram Moolenaar | 076e502 | 2017-01-24 18:58:30 +0100 | [diff] [blame] | 2 | |
Bram Moolenaar | 832615b | 2019-03-23 13:30:22 +0100 | [diff] [blame] | 3 | " Bracketed paste only works with "xterm". Not in GUI or Windows console. |
Bram Moolenaar | 8c5a278 | 2019-08-07 23:07:07 +0200 | [diff] [blame] | 4 | source check.vim |
zeertzjq | 68a573c | 2022-04-28 14:10:01 +0100 | [diff] [blame] | 5 | source term_util.vim |
Bram Moolenaar | 8c5a278 | 2019-08-07 23:07:07 +0200 | [diff] [blame] | 6 | CheckNotMSWindows |
| 7 | CheckNotGui |
| 8 | |
Bram Moolenaar | 076e502 | 2017-01-24 18:58:30 +0100 | [diff] [blame] | 9 | set term=xterm |
| 10 | |
Bram Moolenaar | a903472 | 2018-03-13 15:43:46 +0100 | [diff] [blame] | 11 | source shared.vim |
| 12 | |
Bram Moolenaar | 076e502 | 2017-01-24 18:58:30 +0100 | [diff] [blame] | 13 | func Test_paste_normal_mode() |
| 14 | new |
Bram Moolenaar | fd8983b | 2017-02-02 22:21:29 +0100 | [diff] [blame] | 15 | " In first column text is inserted |
Bram Moolenaar | 076e502 | 2017-01-24 18:58:30 +0100 | [diff] [blame] | 16 | call setline(1, ['a', 'b', 'c']) |
Bram Moolenaar | fd8983b | 2017-02-02 22:21:29 +0100 | [diff] [blame] | 17 | call cursor(2, 1) |
Bram Moolenaar | 076e502 | 2017-01-24 18:58:30 +0100 | [diff] [blame] | 18 | call feedkeys("\<Esc>[200~foo\<CR>bar\<Esc>[201~", 'xt') |
Bram Moolenaar | fd8983b | 2017-02-02 22:21:29 +0100 | [diff] [blame] | 19 | call assert_equal('foo', getline(2)) |
| 20 | call assert_equal('barb', getline(3)) |
Bram Moolenaar | 076e502 | 2017-01-24 18:58:30 +0100 | [diff] [blame] | 21 | call assert_equal('c', getline(4)) |
| 22 | |
Bram Moolenaar | fd8983b | 2017-02-02 22:21:29 +0100 | [diff] [blame] | 23 | " When repeating text is appended |
Bram Moolenaar | 076e502 | 2017-01-24 18:58:30 +0100 | [diff] [blame] | 24 | normal . |
| 25 | call assert_equal('barfoo', getline(3)) |
Bram Moolenaar | fd8983b | 2017-02-02 22:21:29 +0100 | [diff] [blame] | 26 | call assert_equal('barb', getline(4)) |
Bram Moolenaar | 076e502 | 2017-01-24 18:58:30 +0100 | [diff] [blame] | 27 | call assert_equal('c', getline(5)) |
| 28 | bwipe! |
Bram Moolenaar | fd8983b | 2017-02-02 22:21:29 +0100 | [diff] [blame] | 29 | |
| 30 | " In second column text is appended |
| 31 | call setline(1, ['a', 'bbb', 'c']) |
| 32 | call cursor(2, 2) |
| 33 | call feedkeys("\<Esc>[200~foo\<CR>bar\<Esc>[201~", 'xt') |
| 34 | call assert_equal('bbfoo', getline(2)) |
| 35 | call assert_equal('barb', getline(3)) |
| 36 | call assert_equal('c', getline(4)) |
| 37 | |
| 38 | " In last column text is appended |
| 39 | call setline(1, ['a', 'bbb', 'c']) |
| 40 | call cursor(2, 3) |
| 41 | call feedkeys("\<Esc>[200~foo\<CR>bar\<Esc>[201~", 'xt') |
| 42 | call assert_equal('bbbfoo', getline(2)) |
| 43 | call assert_equal('bar', getline(3)) |
| 44 | call assert_equal('c', getline(4)) |
Bram Moolenaar | 076e502 | 2017-01-24 18:58:30 +0100 | [diff] [blame] | 45 | endfunc |
| 46 | |
| 47 | func Test_paste_insert_mode() |
| 48 | new |
| 49 | call setline(1, ['a', 'b', 'c']) |
| 50 | 2 |
| 51 | call feedkeys("i\<Esc>[200~foo\<CR>bar\<Esc>[201~ done\<Esc>", 'xt') |
| 52 | call assert_equal('foo', getline(2)) |
| 53 | call assert_equal('bar doneb', getline(3)) |
| 54 | call assert_equal('c', getline(4)) |
| 55 | |
| 56 | normal . |
| 57 | call assert_equal('bar donfoo', getline(3)) |
| 58 | call assert_equal('bar doneeb', getline(4)) |
| 59 | call assert_equal('c', getline(5)) |
Bram Moolenaar | 9e817c8 | 2017-01-25 21:36:17 +0100 | [diff] [blame] | 60 | |
| 61 | set ai et tw=10 |
| 62 | call setline(1, ['a', ' b', 'c']) |
| 63 | 2 |
| 64 | call feedkeys("A\<Esc>[200~foo\<CR> bar bar bar\<Esc>[201~\<Esc>", 'xt') |
| 65 | call assert_equal(' bfoo', getline(2)) |
| 66 | call assert_equal(' bar bar bar', getline(3)) |
| 67 | call assert_equal('c', getline(4)) |
| 68 | |
| 69 | set ai& et& tw=0 |
Bram Moolenaar | 076e502 | 2017-01-24 18:58:30 +0100 | [diff] [blame] | 70 | bwipe! |
| 71 | endfunc |
| 72 | |
Bram Moolenaar | 3324d0a | 2018-03-06 19:51:13 +0100 | [diff] [blame] | 73 | func Test_paste_clipboard() |
Bram Moolenaar | 52992fe | 2019-08-12 14:20:33 +0200 | [diff] [blame] | 74 | CheckFeature clipboard_working |
| 75 | |
Bram Moolenaar | 3324d0a | 2018-03-06 19:51:13 +0100 | [diff] [blame] | 76 | let @+ = "nasty\<Esc>:!ls\<CR>command" |
| 77 | new |
| 78 | exe "normal i\<C-R>+\<Esc>" |
| 79 | call assert_equal("nasty\<Esc>:!ls\<CR>command", getline(1)) |
| 80 | bwipe! |
| 81 | endfunc |
| 82 | |
Bram Moolenaar | 845e0ee | 2020-06-20 16:05:32 +0200 | [diff] [blame] | 83 | " bracketed paste in command line |
Bram Moolenaar | 076e502 | 2017-01-24 18:58:30 +0100 | [diff] [blame] | 84 | func Test_paste_cmdline() |
| 85 | call feedkeys(":a\<Esc>[200~foo\<CR>bar\<Esc>[201~b\<Home>\"\<CR>", 'xt') |
| 86 | call assert_equal("\"afoo\<CR>barb", getreg(':')) |
| 87 | endfunc |
Bram Moolenaar | a189184 | 2017-02-04 21:34:31 +0100 | [diff] [blame] | 88 | |
Bram Moolenaar | 845e0ee | 2020-06-20 16:05:32 +0200 | [diff] [blame] | 89 | " bracketed paste in Ex-mode |
| 90 | func Test_paste_ex_mode() |
| 91 | unlet! foo |
| 92 | call feedkeys("Qlet foo=\"\<Esc>[200~foo\<CR>bar\<Esc>[201~\"\<CR>vi\<CR>", 'xt') |
| 93 | call assert_equal("foo\rbar", foo) |
Bram Moolenaar | 806d037 | 2022-01-25 20:45:16 +0000 | [diff] [blame] | 94 | |
| 95 | " pasting more than 40 bytes |
| 96 | exe "norm Q\<PasteStart>0000000000000000000000000000000000000000000000000000000000000000000000\<C-C>" |
Bram Moolenaar | 845e0ee | 2020-06-20 16:05:32 +0200 | [diff] [blame] | 97 | endfunc |
| 98 | |
| 99 | func Test_paste_onechar() |
| 100 | new |
| 101 | let @f='abc' |
| 102 | call feedkeys("i\<C-R>\<Esc>[200~foo\<CR>bar\<Esc>[201~", 'xt') |
| 103 | call assert_equal("abc", getline(1)) |
| 104 | close! |
| 105 | endfunc |
| 106 | |
Bram Moolenaar | a189184 | 2017-02-04 21:34:31 +0100 | [diff] [blame] | 107 | func Test_paste_visual_mode() |
| 108 | new |
| 109 | call setline(1, 'here are some words') |
| 110 | call feedkeys("0fsve\<Esc>[200~more\<Esc>[201~", 'xt') |
| 111 | call assert_equal('here are more words', getline(1)) |
| 112 | call assert_equal('some', getreg('-')) |
zeertzjq | 7a73252 | 2022-03-14 20:46:41 +0000 | [diff] [blame] | 113 | normal! u |
| 114 | call assert_equal('here are some words', getline(1)) |
| 115 | exe "normal! \<C-R>" |
| 116 | call assert_equal('here are more words', getline(1)) |
Bram Moolenaar | a189184 | 2017-02-04 21:34:31 +0100 | [diff] [blame] | 117 | |
| 118 | " include last char in the line |
| 119 | call feedkeys("0fwve\<Esc>[200~noises\<Esc>[201~", 'xt') |
| 120 | call assert_equal('here are more noises', getline(1)) |
| 121 | call assert_equal('words', getreg('-')) |
zeertzjq | 7a73252 | 2022-03-14 20:46:41 +0000 | [diff] [blame] | 122 | normal! u |
| 123 | call assert_equal('here are more words', getline(1)) |
| 124 | exe "normal! \<C-R>" |
| 125 | call assert_equal('here are more noises', getline(1)) |
Bram Moolenaar | a189184 | 2017-02-04 21:34:31 +0100 | [diff] [blame] | 126 | |
| 127 | " exclude last char in the line |
| 128 | call setline(1, 'some words!') |
| 129 | call feedkeys("0fwve\<Esc>[200~noises\<Esc>[201~", 'xt') |
| 130 | call assert_equal('some noises!', getline(1)) |
| 131 | call assert_equal('words', getreg('-')) |
zeertzjq | 7a73252 | 2022-03-14 20:46:41 +0000 | [diff] [blame] | 132 | normal! u |
| 133 | call assert_equal('some words!', getline(1)) |
| 134 | exe "normal! \<C-R>" |
| 135 | call assert_equal('some noises!', getline(1)) |
Bram Moolenaar | a189184 | 2017-02-04 21:34:31 +0100 | [diff] [blame] | 136 | |
| 137 | " multi-line selection |
| 138 | call setline(1, ['some words', 'and more']) |
| 139 | call feedkeys("0fwvj0fd\<Esc>[200~letters\<Esc>[201~", 'xt') |
| 140 | call assert_equal('some letters more', getline(1)) |
| 141 | call assert_equal("words\nand", getreg('1')) |
zeertzjq | 7a73252 | 2022-03-14 20:46:41 +0000 | [diff] [blame] | 142 | normal! u |
| 143 | call assert_equal(['some words', 'and more'], getline(1, 2)) |
| 144 | exe "normal! \<C-R>" |
| 145 | call assert_equal('some letters more', getline(1)) |
| 146 | |
| 147 | " linewise non-last line, cursor at start of line |
| 148 | call setline(1, ['some words', 'and more']) |
| 149 | call feedkeys("0V\<Esc>[200~letters\<Esc>[201~", 'xt') |
| 150 | call assert_equal('lettersand more', getline(1)) |
| 151 | call assert_equal("some words\n", getreg('1')) |
| 152 | normal! u |
| 153 | call assert_equal(['some words', 'and more'], getline(1, 2)) |
| 154 | exe "normal! \<C-R>" |
| 155 | call assert_equal('lettersand more', getline(1)) |
| 156 | |
| 157 | " linewise non-last line, cursor in the middle of line |
| 158 | call setline(1, ['some words', 'and more']) |
| 159 | call feedkeys("0fwV\<Esc>[200~letters\<Esc>[201~", 'xt') |
| 160 | call assert_equal('lettersand more', getline(1)) |
| 161 | call assert_equal("some words\n", getreg('1')) |
| 162 | normal! u |
| 163 | call assert_equal(['some words', 'and more'], getline(1, 2)) |
| 164 | exe "normal! \<C-R>" |
| 165 | call assert_equal('lettersand more', getline(1)) |
| 166 | |
| 167 | " linewise last line |
| 168 | call setline(1, ['some words', 'and more']) |
| 169 | call feedkeys("j0V\<Esc>[200~letters\<Esc>[201~", 'xt') |
| 170 | call assert_equal(['some words', 'letters'], getline(1, 2)) |
| 171 | call assert_equal("and more\n", getreg('1')) |
| 172 | normal! u |
| 173 | call assert_equal(['some words', 'and more'], getline(1, 2)) |
| 174 | exe "normal! \<C-R>" |
| 175 | call assert_equal(['some words', 'letters'], getline(1, 2)) |
Bram Moolenaar | a189184 | 2017-02-04 21:34:31 +0100 | [diff] [blame] | 176 | |
| 177 | bwipe! |
| 178 | endfunc |
Bram Moolenaar | d4aa83a | 2019-05-09 18:59:31 +0200 | [diff] [blame] | 179 | |
| 180 | func CheckCopyPaste() |
| 181 | call setline(1, ['copy this', '']) |
| 182 | normal 1G0"*y$ |
| 183 | normal j"*p |
| 184 | call assert_equal('copy this', getline(2)) |
| 185 | endfunc |
| 186 | |
| 187 | func Test_xrestore() |
Bram Moolenaar | 6d91bcb | 2020-08-12 18:50:36 +0200 | [diff] [blame] | 188 | CheckFeature xterm_clipboard |
Bram Moolenaar | f08b0eb | 2021-10-16 13:00:14 +0100 | [diff] [blame] | 189 | let g:test_is_flaky = 1 |
| 190 | |
Bram Moolenaar | d4aa83a | 2019-05-09 18:59:31 +0200 | [diff] [blame] | 191 | let display = $DISPLAY |
| 192 | new |
| 193 | call CheckCopyPaste() |
| 194 | |
| 195 | xrestore |
| 196 | call CheckCopyPaste() |
| 197 | |
| 198 | exe "xrestore " .. display |
| 199 | call CheckCopyPaste() |
| 200 | |
Bram Moolenaar | d4aa83a | 2019-05-09 18:59:31 +0200 | [diff] [blame] | 201 | bwipe! |
| 202 | endfunc |
Bram Moolenaar | 845e0ee | 2020-06-20 16:05:32 +0200 | [diff] [blame] | 203 | |
Bram Moolenaar | f4fcedc | 2021-03-15 18:36:20 +0100 | [diff] [blame] | 204 | " Test for 'pastetoggle' |
| 205 | func Test_pastetoggle() |
| 206 | new |
| 207 | set pastetoggle=<F4> |
| 208 | set nopaste |
| 209 | call feedkeys("iHello\<F4>", 'xt') |
| 210 | call assert_true(&paste) |
| 211 | call feedkeys("i\<F4>", 'xt') |
| 212 | call assert_false(&paste) |
| 213 | call assert_equal('Hello', getline(1)) |
Yegappan Lakshmanan | 2d6d718 | 2021-06-13 21:52:48 +0200 | [diff] [blame] | 214 | " command-line completion for 'pastetoggle' value |
| 215 | call feedkeys(":set pastetoggle=\<Tab>\<C-B>\"\<CR>", 'xt') |
| 216 | call assert_equal('"set pastetoggle=<F4>', @:) |
Bram Moolenaar | f4fcedc | 2021-03-15 18:36:20 +0100 | [diff] [blame] | 217 | set pastetoggle& |
| 218 | bwipe! |
| 219 | endfunc |
| 220 | |
zeertzjq | 68a573c | 2022-04-28 14:10:01 +0100 | [diff] [blame] | 221 | func Test_pastetoggle_timeout_no_typed_after_mapped() |
| 222 | CheckRunVimInTerminal |
| 223 | |
| 224 | let lines =<< trim END |
| 225 | set pastetoggle=abc |
| 226 | set ttimeoutlen=10000 |
| 227 | imap d a |
| 228 | END |
Bram Moolenaar | 145d1fd | 2022-09-30 21:57:11 +0100 | [diff] [blame] | 229 | call writefile(lines, 'Xpastetoggle_no_typed_after_mapped.vim', 'D') |
zeertzjq | 68a573c | 2022-04-28 14:10:01 +0100 | [diff] [blame] | 230 | let buf = RunVimInTerminal('-S Xpastetoggle_no_typed_after_mapped.vim', #{rows: 8}) |
| 231 | call TermWait(buf) |
| 232 | call term_sendkeys(buf, ":call feedkeys('id', 't')\<CR>") |
| 233 | call term_wait(buf, 200) |
| 234 | call term_sendkeys(buf, 'bc') |
| 235 | " 'ttimeoutlen' should NOT apply |
| 236 | call WaitForAssert({-> assert_match('^-- INSERT --', term_getline(buf, 8))}) |
| 237 | |
| 238 | call StopVimInTerminal(buf) |
zeertzjq | 68a573c | 2022-04-28 14:10:01 +0100 | [diff] [blame] | 239 | endfunc |
| 240 | |
| 241 | func Test_pastetoggle_timeout_typed_after_mapped() |
| 242 | CheckRunVimInTerminal |
| 243 | |
| 244 | let lines =<< trim END |
| 245 | set pastetoggle=abc |
| 246 | set ttimeoutlen=10000 |
| 247 | imap d a |
| 248 | END |
Bram Moolenaar | 145d1fd | 2022-09-30 21:57:11 +0100 | [diff] [blame] | 249 | call writefile(lines, 'Xpastetoggle_typed_after_mapped.vim', 'D') |
zeertzjq | 68a573c | 2022-04-28 14:10:01 +0100 | [diff] [blame] | 250 | let buf = RunVimInTerminal('-S Xpastetoggle_typed_after_mapped.vim', #{rows: 8}) |
| 251 | call TermWait(buf) |
| 252 | call term_sendkeys(buf, ":call feedkeys('idb', 't')\<CR>") |
| 253 | call term_wait(buf, 200) |
| 254 | call term_sendkeys(buf, 'c') |
| 255 | " 'ttimeoutlen' should apply |
| 256 | call WaitForAssert({-> assert_match('^-- INSERT (paste) --', term_getline(buf, 8))}) |
| 257 | |
| 258 | call StopVimInTerminal(buf) |
zeertzjq | 68a573c | 2022-04-28 14:10:01 +0100 | [diff] [blame] | 259 | endfunc |
| 260 | |
| 261 | func Test_pastetoggle_timeout_typed_after_noremap() |
| 262 | CheckRunVimInTerminal |
| 263 | |
| 264 | let lines =<< trim END |
| 265 | set pastetoggle=abc |
| 266 | set ttimeoutlen=10000 |
| 267 | inoremap d a |
| 268 | END |
Bram Moolenaar | 145d1fd | 2022-09-30 21:57:11 +0100 | [diff] [blame] | 269 | call writefile(lines, 'Xpastetoggle_typed_after_noremap.vim', 'D') |
zeertzjq | 68a573c | 2022-04-28 14:10:01 +0100 | [diff] [blame] | 270 | let buf = RunVimInTerminal('-S Xpastetoggle_typed_after_noremap.vim', #{rows: 8}) |
| 271 | call TermWait(buf) |
| 272 | call term_sendkeys(buf, ":call feedkeys('idb', 't')\<CR>") |
| 273 | call term_wait(buf, 200) |
| 274 | call term_sendkeys(buf, 'c') |
| 275 | " 'ttimeoutlen' should apply |
| 276 | call WaitForAssert({-> assert_match('^-- INSERT (paste) --', term_getline(buf, 8))}) |
| 277 | |
| 278 | call StopVimInTerminal(buf) |
zeertzjq | 68a573c | 2022-04-28 14:10:01 +0100 | [diff] [blame] | 279 | endfunc |
| 280 | |
Yegappan Lakshmanan | 2d6d718 | 2021-06-13 21:52:48 +0200 | [diff] [blame] | 281 | " Test for restoring option values when 'paste' is disabled |
| 282 | func Test_paste_opt_restore() |
| 283 | set autoindent expandtab ruler showmatch |
| 284 | if has('rightleft') |
| 285 | set revins hkmap |
| 286 | endif |
| 287 | set smarttab softtabstop=3 textwidth=27 wrapmargin=12 |
| 288 | if has('vartabs') |
| 289 | set varsofttabstop=10,20 |
| 290 | endif |
| 291 | |
| 292 | " enabling 'paste' should reset the above options |
| 293 | set paste |
| 294 | call assert_false(&autoindent) |
| 295 | call assert_false(&expandtab) |
| 296 | if has('rightleft') |
| 297 | call assert_false(&revins) |
| 298 | call assert_false(&hkmap) |
| 299 | endif |
| 300 | call assert_false(&ruler) |
| 301 | call assert_false(&showmatch) |
| 302 | call assert_false(&smarttab) |
| 303 | call assert_equal(0, &softtabstop) |
| 304 | call assert_equal(0, &textwidth) |
| 305 | call assert_equal(0, &wrapmargin) |
| 306 | if has('vartabs') |
| 307 | call assert_equal('', &varsofttabstop) |
| 308 | endif |
| 309 | |
| 310 | " disabling 'paste' should restore the option values |
| 311 | set nopaste |
| 312 | call assert_true(&autoindent) |
| 313 | call assert_true(&expandtab) |
| 314 | if has('rightleft') |
| 315 | call assert_true(&revins) |
| 316 | call assert_true(&hkmap) |
| 317 | endif |
| 318 | call assert_true(&ruler) |
| 319 | call assert_true(&showmatch) |
| 320 | call assert_true(&smarttab) |
| 321 | call assert_equal(3, &softtabstop) |
| 322 | call assert_equal(27, &textwidth) |
| 323 | call assert_equal(12, &wrapmargin) |
| 324 | if has('vartabs') |
| 325 | call assert_equal('10,20', &varsofttabstop) |
| 326 | endif |
| 327 | |
| 328 | set autoindent& expandtab& ruler& showmatch& |
| 329 | if has('rightleft') |
| 330 | set revins& hkmap& |
| 331 | endif |
| 332 | set smarttab& softtabstop& textwidth& wrapmargin& |
| 333 | if has('vartabs') |
| 334 | set varsofttabstop& |
| 335 | endif |
| 336 | endfunc |
| 337 | |
Bram Moolenaar | 845e0ee | 2020-06-20 16:05:32 +0200 | [diff] [blame] | 338 | " vim: shiftwidth=2 sts=2 expandtab |