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