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 |
| 5 | CheckNotMSWindows |
| 6 | CheckNotGui |
| 7 | |
Bram Moolenaar | 076e502 | 2017-01-24 18:58:30 +0100 | [diff] [blame] | 8 | set term=xterm |
| 9 | |
Bram Moolenaar | a903472 | 2018-03-13 15:43:46 +0100 | [diff] [blame] | 10 | source shared.vim |
| 11 | |
Bram Moolenaar | 076e502 | 2017-01-24 18:58:30 +0100 | [diff] [blame] | 12 | func Test_paste_normal_mode() |
| 13 | new |
Bram Moolenaar | fd8983b | 2017-02-02 22:21:29 +0100 | [diff] [blame] | 14 | " In first column text is inserted |
Bram Moolenaar | 076e502 | 2017-01-24 18:58:30 +0100 | [diff] [blame] | 15 | call setline(1, ['a', 'b', 'c']) |
Bram Moolenaar | fd8983b | 2017-02-02 22:21:29 +0100 | [diff] [blame] | 16 | call cursor(2, 1) |
Bram Moolenaar | 076e502 | 2017-01-24 18:58:30 +0100 | [diff] [blame] | 17 | call feedkeys("\<Esc>[200~foo\<CR>bar\<Esc>[201~", 'xt') |
Bram Moolenaar | fd8983b | 2017-02-02 22:21:29 +0100 | [diff] [blame] | 18 | call assert_equal('foo', getline(2)) |
| 19 | call assert_equal('barb', getline(3)) |
Bram Moolenaar | 076e502 | 2017-01-24 18:58:30 +0100 | [diff] [blame] | 20 | call assert_equal('c', getline(4)) |
| 21 | |
Bram Moolenaar | fd8983b | 2017-02-02 22:21:29 +0100 | [diff] [blame] | 22 | " When repeating text is appended |
Bram Moolenaar | 076e502 | 2017-01-24 18:58:30 +0100 | [diff] [blame] | 23 | normal . |
| 24 | call assert_equal('barfoo', getline(3)) |
Bram Moolenaar | fd8983b | 2017-02-02 22:21:29 +0100 | [diff] [blame] | 25 | call assert_equal('barb', getline(4)) |
Bram Moolenaar | 076e502 | 2017-01-24 18:58:30 +0100 | [diff] [blame] | 26 | call assert_equal('c', getline(5)) |
| 27 | bwipe! |
Bram Moolenaar | fd8983b | 2017-02-02 22:21:29 +0100 | [diff] [blame] | 28 | |
| 29 | " In second column text is appended |
| 30 | call setline(1, ['a', 'bbb', 'c']) |
| 31 | call cursor(2, 2) |
| 32 | call feedkeys("\<Esc>[200~foo\<CR>bar\<Esc>[201~", 'xt') |
| 33 | call assert_equal('bbfoo', getline(2)) |
| 34 | call assert_equal('barb', getline(3)) |
| 35 | call assert_equal('c', getline(4)) |
| 36 | |
| 37 | " In last column text is appended |
| 38 | call setline(1, ['a', 'bbb', 'c']) |
| 39 | call cursor(2, 3) |
| 40 | call feedkeys("\<Esc>[200~foo\<CR>bar\<Esc>[201~", 'xt') |
| 41 | call assert_equal('bbbfoo', getline(2)) |
| 42 | call assert_equal('bar', getline(3)) |
| 43 | call assert_equal('c', getline(4)) |
Bram Moolenaar | 076e502 | 2017-01-24 18:58:30 +0100 | [diff] [blame] | 44 | endfunc |
| 45 | |
| 46 | func Test_paste_insert_mode() |
| 47 | new |
| 48 | call setline(1, ['a', 'b', 'c']) |
| 49 | 2 |
| 50 | call feedkeys("i\<Esc>[200~foo\<CR>bar\<Esc>[201~ done\<Esc>", 'xt') |
| 51 | call assert_equal('foo', getline(2)) |
| 52 | call assert_equal('bar doneb', getline(3)) |
| 53 | call assert_equal('c', getline(4)) |
| 54 | |
| 55 | normal . |
| 56 | call assert_equal('bar donfoo', getline(3)) |
| 57 | call assert_equal('bar doneeb', getline(4)) |
| 58 | call assert_equal('c', getline(5)) |
Bram Moolenaar | 9e817c8 | 2017-01-25 21:36:17 +0100 | [diff] [blame] | 59 | |
| 60 | set ai et tw=10 |
| 61 | call setline(1, ['a', ' b', 'c']) |
| 62 | 2 |
| 63 | call feedkeys("A\<Esc>[200~foo\<CR> bar bar bar\<Esc>[201~\<Esc>", 'xt') |
| 64 | call assert_equal(' bfoo', getline(2)) |
| 65 | call assert_equal(' bar bar bar', getline(3)) |
| 66 | call assert_equal('c', getline(4)) |
| 67 | |
| 68 | set ai& et& tw=0 |
Bram Moolenaar | 076e502 | 2017-01-24 18:58:30 +0100 | [diff] [blame] | 69 | bwipe! |
| 70 | endfunc |
| 71 | |
Bram Moolenaar | 3324d0a | 2018-03-06 19:51:13 +0100 | [diff] [blame] | 72 | func Test_paste_clipboard() |
Bram Moolenaar | 52992fe | 2019-08-12 14:20:33 +0200 | [diff] [blame] | 73 | CheckFeature clipboard_working |
| 74 | |
Bram Moolenaar | 3324d0a | 2018-03-06 19:51:13 +0100 | [diff] [blame] | 75 | let @+ = "nasty\<Esc>:!ls\<CR>command" |
| 76 | new |
| 77 | exe "normal i\<C-R>+\<Esc>" |
| 78 | call assert_equal("nasty\<Esc>:!ls\<CR>command", getline(1)) |
| 79 | bwipe! |
| 80 | endfunc |
| 81 | |
Bram Moolenaar | 845e0ee | 2020-06-20 16:05:32 +0200 | [diff] [blame] | 82 | " bracketed paste in command line |
Bram Moolenaar | 076e502 | 2017-01-24 18:58:30 +0100 | [diff] [blame] | 83 | func Test_paste_cmdline() |
| 84 | call feedkeys(":a\<Esc>[200~foo\<CR>bar\<Esc>[201~b\<Home>\"\<CR>", 'xt') |
| 85 | call assert_equal("\"afoo\<CR>barb", getreg(':')) |
| 86 | endfunc |
Bram Moolenaar | a189184 | 2017-02-04 21:34:31 +0100 | [diff] [blame] | 87 | |
Bram Moolenaar | 845e0ee | 2020-06-20 16:05:32 +0200 | [diff] [blame] | 88 | " bracketed paste in Ex-mode |
| 89 | func Test_paste_ex_mode() |
| 90 | unlet! foo |
| 91 | call feedkeys("Qlet foo=\"\<Esc>[200~foo\<CR>bar\<Esc>[201~\"\<CR>vi\<CR>", 'xt') |
| 92 | call assert_equal("foo\rbar", foo) |
| 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('-')) |
| 109 | |
| 110 | " include last char in the line |
| 111 | call feedkeys("0fwve\<Esc>[200~noises\<Esc>[201~", 'xt') |
| 112 | call assert_equal('here are more noises', getline(1)) |
| 113 | call assert_equal('words', getreg('-')) |
| 114 | |
| 115 | " exclude last char in the line |
| 116 | call setline(1, 'some words!') |
| 117 | call feedkeys("0fwve\<Esc>[200~noises\<Esc>[201~", 'xt') |
| 118 | call assert_equal('some noises!', getline(1)) |
| 119 | call assert_equal('words', getreg('-')) |
| 120 | |
| 121 | " multi-line selection |
| 122 | call setline(1, ['some words', 'and more']) |
| 123 | call feedkeys("0fwvj0fd\<Esc>[200~letters\<Esc>[201~", 'xt') |
| 124 | call assert_equal('some letters more', getline(1)) |
| 125 | call assert_equal("words\nand", getreg('1')) |
| 126 | |
| 127 | bwipe! |
| 128 | endfunc |
Bram Moolenaar | d4aa83a | 2019-05-09 18:59:31 +0200 | [diff] [blame] | 129 | |
| 130 | func CheckCopyPaste() |
| 131 | call setline(1, ['copy this', '']) |
| 132 | normal 1G0"*y$ |
| 133 | normal j"*p |
| 134 | call assert_equal('copy this', getline(2)) |
| 135 | endfunc |
| 136 | |
| 137 | func Test_xrestore() |
Bram Moolenaar | 6d91bcb | 2020-08-12 18:50:36 +0200 | [diff] [blame] | 138 | CheckFeature xterm_clipboard |
Bram Moolenaar | d4aa83a | 2019-05-09 18:59:31 +0200 | [diff] [blame] | 139 | let display = $DISPLAY |
| 140 | new |
| 141 | call CheckCopyPaste() |
| 142 | |
| 143 | xrestore |
| 144 | call CheckCopyPaste() |
| 145 | |
| 146 | exe "xrestore " .. display |
| 147 | call CheckCopyPaste() |
| 148 | |
Bram Moolenaar | d4aa83a | 2019-05-09 18:59:31 +0200 | [diff] [blame] | 149 | bwipe! |
| 150 | endfunc |
Bram Moolenaar | 845e0ee | 2020-06-20 16:05:32 +0200 | [diff] [blame] | 151 | |
Bram Moolenaar | f4fcedc | 2021-03-15 18:36:20 +0100 | [diff] [blame] | 152 | " Test for 'pastetoggle' |
| 153 | func Test_pastetoggle() |
| 154 | new |
| 155 | set pastetoggle=<F4> |
| 156 | set nopaste |
| 157 | call feedkeys("iHello\<F4>", 'xt') |
| 158 | call assert_true(&paste) |
| 159 | call feedkeys("i\<F4>", 'xt') |
| 160 | call assert_false(&paste) |
| 161 | call assert_equal('Hello', getline(1)) |
Yegappan Lakshmanan | 2d6d718 | 2021-06-13 21:52:48 +0200 | [diff] [blame] | 162 | " command-line completion for 'pastetoggle' value |
| 163 | call feedkeys(":set pastetoggle=\<Tab>\<C-B>\"\<CR>", 'xt') |
| 164 | call assert_equal('"set pastetoggle=<F4>', @:) |
Bram Moolenaar | f4fcedc | 2021-03-15 18:36:20 +0100 | [diff] [blame] | 165 | set pastetoggle& |
| 166 | bwipe! |
| 167 | endfunc |
| 168 | |
Yegappan Lakshmanan | 2d6d718 | 2021-06-13 21:52:48 +0200 | [diff] [blame] | 169 | " Test for restoring option values when 'paste' is disabled |
| 170 | func Test_paste_opt_restore() |
| 171 | set autoindent expandtab ruler showmatch |
| 172 | if has('rightleft') |
| 173 | set revins hkmap |
| 174 | endif |
| 175 | set smarttab softtabstop=3 textwidth=27 wrapmargin=12 |
| 176 | if has('vartabs') |
| 177 | set varsofttabstop=10,20 |
| 178 | endif |
| 179 | |
| 180 | " enabling 'paste' should reset the above options |
| 181 | set paste |
| 182 | call assert_false(&autoindent) |
| 183 | call assert_false(&expandtab) |
| 184 | if has('rightleft') |
| 185 | call assert_false(&revins) |
| 186 | call assert_false(&hkmap) |
| 187 | endif |
| 188 | call assert_false(&ruler) |
| 189 | call assert_false(&showmatch) |
| 190 | call assert_false(&smarttab) |
| 191 | call assert_equal(0, &softtabstop) |
| 192 | call assert_equal(0, &textwidth) |
| 193 | call assert_equal(0, &wrapmargin) |
| 194 | if has('vartabs') |
| 195 | call assert_equal('', &varsofttabstop) |
| 196 | endif |
| 197 | |
| 198 | " disabling 'paste' should restore the option values |
| 199 | set nopaste |
| 200 | call assert_true(&autoindent) |
| 201 | call assert_true(&expandtab) |
| 202 | if has('rightleft') |
| 203 | call assert_true(&revins) |
| 204 | call assert_true(&hkmap) |
| 205 | endif |
| 206 | call assert_true(&ruler) |
| 207 | call assert_true(&showmatch) |
| 208 | call assert_true(&smarttab) |
| 209 | call assert_equal(3, &softtabstop) |
| 210 | call assert_equal(27, &textwidth) |
| 211 | call assert_equal(12, &wrapmargin) |
| 212 | if has('vartabs') |
| 213 | call assert_equal('10,20', &varsofttabstop) |
| 214 | endif |
| 215 | |
| 216 | set autoindent& expandtab& ruler& showmatch& |
| 217 | if has('rightleft') |
| 218 | set revins& hkmap& |
| 219 | endif |
| 220 | set smarttab& softtabstop& textwidth& wrapmargin& |
| 221 | if has('vartabs') |
| 222 | set varsofttabstop& |
| 223 | endif |
| 224 | endfunc |
| 225 | |
Bram Moolenaar | 845e0ee | 2020-06-20 16:05:32 +0200 | [diff] [blame] | 226 | " vim: shiftwidth=2 sts=2 expandtab |