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 | b0f94c1 | 2019-06-13 22:19:53 +0200 | [diff] [blame] | 4 | if has('win32') |
Bram Moolenaar | b46fecd | 2019-06-15 17:58:09 +0200 | [diff] [blame] | 5 | throw 'Skipped: does not work on MS-Windows' |
Bram Moolenaar | b0f94c1 | 2019-06-13 22:19:53 +0200 | [diff] [blame] | 6 | endif |
| 7 | if has('gui_running') |
Bram Moolenaar | b46fecd | 2019-06-15 17:58:09 +0200 | [diff] [blame] | 8 | throw 'Skipped: does not work in the GUI' |
Bram Moolenaar | bff6ad1 | 2017-01-24 19:18:13 +0100 | [diff] [blame] | 9 | endif |
Bram Moolenaar | 076e502 | 2017-01-24 18:58:30 +0100 | [diff] [blame] | 10 | set term=xterm |
| 11 | |
Bram Moolenaar | a903472 | 2018-03-13 15:43:46 +0100 | [diff] [blame] | 12 | source shared.vim |
| 13 | |
Bram Moolenaar | 076e502 | 2017-01-24 18:58:30 +0100 | [diff] [blame] | 14 | func Test_paste_normal_mode() |
| 15 | new |
Bram Moolenaar | fd8983b | 2017-02-02 22:21:29 +0100 | [diff] [blame] | 16 | " In first column text is inserted |
Bram Moolenaar | 076e502 | 2017-01-24 18:58:30 +0100 | [diff] [blame] | 17 | call setline(1, ['a', 'b', 'c']) |
Bram Moolenaar | fd8983b | 2017-02-02 22:21:29 +0100 | [diff] [blame] | 18 | call cursor(2, 1) |
Bram Moolenaar | 076e502 | 2017-01-24 18:58:30 +0100 | [diff] [blame] | 19 | call feedkeys("\<Esc>[200~foo\<CR>bar\<Esc>[201~", 'xt') |
Bram Moolenaar | fd8983b | 2017-02-02 22:21:29 +0100 | [diff] [blame] | 20 | call assert_equal('foo', getline(2)) |
| 21 | call assert_equal('barb', getline(3)) |
Bram Moolenaar | 076e502 | 2017-01-24 18:58:30 +0100 | [diff] [blame] | 22 | call assert_equal('c', getline(4)) |
| 23 | |
Bram Moolenaar | fd8983b | 2017-02-02 22:21:29 +0100 | [diff] [blame] | 24 | " When repeating text is appended |
Bram Moolenaar | 076e502 | 2017-01-24 18:58:30 +0100 | [diff] [blame] | 25 | normal . |
| 26 | call assert_equal('barfoo', getline(3)) |
Bram Moolenaar | fd8983b | 2017-02-02 22:21:29 +0100 | [diff] [blame] | 27 | call assert_equal('barb', getline(4)) |
Bram Moolenaar | 076e502 | 2017-01-24 18:58:30 +0100 | [diff] [blame] | 28 | call assert_equal('c', getline(5)) |
| 29 | bwipe! |
Bram Moolenaar | fd8983b | 2017-02-02 22:21:29 +0100 | [diff] [blame] | 30 | |
| 31 | " In second column text is appended |
| 32 | call setline(1, ['a', 'bbb', 'c']) |
| 33 | call cursor(2, 2) |
| 34 | call feedkeys("\<Esc>[200~foo\<CR>bar\<Esc>[201~", 'xt') |
| 35 | call assert_equal('bbfoo', getline(2)) |
| 36 | call assert_equal('barb', getline(3)) |
| 37 | call assert_equal('c', getline(4)) |
| 38 | |
| 39 | " In last column text is appended |
| 40 | call setline(1, ['a', 'bbb', 'c']) |
| 41 | call cursor(2, 3) |
| 42 | call feedkeys("\<Esc>[200~foo\<CR>bar\<Esc>[201~", 'xt') |
| 43 | call assert_equal('bbbfoo', getline(2)) |
| 44 | call assert_equal('bar', getline(3)) |
| 45 | call assert_equal('c', getline(4)) |
Bram Moolenaar | 076e502 | 2017-01-24 18:58:30 +0100 | [diff] [blame] | 46 | endfunc |
| 47 | |
| 48 | func Test_paste_insert_mode() |
| 49 | new |
| 50 | call setline(1, ['a', 'b', 'c']) |
| 51 | 2 |
| 52 | call feedkeys("i\<Esc>[200~foo\<CR>bar\<Esc>[201~ done\<Esc>", 'xt') |
| 53 | call assert_equal('foo', getline(2)) |
| 54 | call assert_equal('bar doneb', getline(3)) |
| 55 | call assert_equal('c', getline(4)) |
| 56 | |
| 57 | normal . |
| 58 | call assert_equal('bar donfoo', getline(3)) |
| 59 | call assert_equal('bar doneeb', getline(4)) |
| 60 | call assert_equal('c', getline(5)) |
Bram Moolenaar | 9e817c8 | 2017-01-25 21:36:17 +0100 | [diff] [blame] | 61 | |
| 62 | set ai et tw=10 |
| 63 | call setline(1, ['a', ' b', 'c']) |
| 64 | 2 |
| 65 | call feedkeys("A\<Esc>[200~foo\<CR> bar bar bar\<Esc>[201~\<Esc>", 'xt') |
| 66 | call assert_equal(' bfoo', getline(2)) |
| 67 | call assert_equal(' bar bar bar', getline(3)) |
| 68 | call assert_equal('c', getline(4)) |
| 69 | |
| 70 | set ai& et& tw=0 |
Bram Moolenaar | 076e502 | 2017-01-24 18:58:30 +0100 | [diff] [blame] | 71 | bwipe! |
| 72 | endfunc |
| 73 | |
Bram Moolenaar | 3324d0a | 2018-03-06 19:51:13 +0100 | [diff] [blame] | 74 | func Test_paste_clipboard() |
Bram Moolenaar | a903472 | 2018-03-13 15:43:46 +0100 | [diff] [blame] | 75 | if !WorkingClipboard() |
Bram Moolenaar | 3324d0a | 2018-03-06 19:51:13 +0100 | [diff] [blame] | 76 | return |
| 77 | endif |
| 78 | let @+ = "nasty\<Esc>:!ls\<CR>command" |
| 79 | new |
| 80 | exe "normal i\<C-R>+\<Esc>" |
| 81 | call assert_equal("nasty\<Esc>:!ls\<CR>command", getline(1)) |
| 82 | bwipe! |
| 83 | endfunc |
| 84 | |
Bram Moolenaar | 076e502 | 2017-01-24 18:58:30 +0100 | [diff] [blame] | 85 | func Test_paste_cmdline() |
| 86 | call feedkeys(":a\<Esc>[200~foo\<CR>bar\<Esc>[201~b\<Home>\"\<CR>", 'xt') |
| 87 | call assert_equal("\"afoo\<CR>barb", getreg(':')) |
| 88 | endfunc |
Bram Moolenaar | a189184 | 2017-02-04 21:34:31 +0100 | [diff] [blame] | 89 | |
| 90 | func Test_paste_visual_mode() |
| 91 | new |
| 92 | call setline(1, 'here are some words') |
| 93 | call feedkeys("0fsve\<Esc>[200~more\<Esc>[201~", 'xt') |
| 94 | call assert_equal('here are more words', getline(1)) |
| 95 | call assert_equal('some', getreg('-')) |
| 96 | |
| 97 | " include last char in the line |
| 98 | call feedkeys("0fwve\<Esc>[200~noises\<Esc>[201~", 'xt') |
| 99 | call assert_equal('here are more noises', getline(1)) |
| 100 | call assert_equal('words', getreg('-')) |
| 101 | |
| 102 | " exclude last char in the line |
| 103 | call setline(1, 'some words!') |
| 104 | call feedkeys("0fwve\<Esc>[200~noises\<Esc>[201~", 'xt') |
| 105 | call assert_equal('some noises!', getline(1)) |
| 106 | call assert_equal('words', getreg('-')) |
| 107 | |
| 108 | " multi-line selection |
| 109 | call setline(1, ['some words', 'and more']) |
| 110 | call feedkeys("0fwvj0fd\<Esc>[200~letters\<Esc>[201~", 'xt') |
| 111 | call assert_equal('some letters more', getline(1)) |
| 112 | call assert_equal("words\nand", getreg('1')) |
| 113 | |
| 114 | bwipe! |
| 115 | endfunc |
Bram Moolenaar | d4aa83a | 2019-05-09 18:59:31 +0200 | [diff] [blame] | 116 | |
| 117 | func CheckCopyPaste() |
| 118 | call setline(1, ['copy this', '']) |
| 119 | normal 1G0"*y$ |
| 120 | normal j"*p |
| 121 | call assert_equal('copy this', getline(2)) |
| 122 | endfunc |
| 123 | |
| 124 | func Test_xrestore() |
| 125 | if !has('xterm_clipboard') |
| 126 | return |
| 127 | endif |
Bram Moolenaar | d4aa83a | 2019-05-09 18:59:31 +0200 | [diff] [blame] | 128 | let display = $DISPLAY |
| 129 | new |
| 130 | call CheckCopyPaste() |
| 131 | |
| 132 | xrestore |
| 133 | call CheckCopyPaste() |
| 134 | |
| 135 | exe "xrestore " .. display |
| 136 | call CheckCopyPaste() |
| 137 | |
Bram Moolenaar | d4aa83a | 2019-05-09 18:59:31 +0200 | [diff] [blame] | 138 | bwipe! |
| 139 | endfunc |