blob: a22e8e505ee3acc495b86cd150c79cded798005f [file] [log] [blame]
Bram Moolenaar3324d0a2018-03-06 19:51:13 +01001" Tests for bracketed paste and other forms of pasting.
Bram Moolenaar076e5022017-01-24 18:58:30 +01002
Bram Moolenaar832615b2019-03-23 13:30:22 +01003" Bracketed paste only works with "xterm". Not in GUI or Windows console.
Bram Moolenaarb0f94c12019-06-13 22:19:53 +02004if has('win32')
Bram Moolenaarb46fecd2019-06-15 17:58:09 +02005 throw 'Skipped: does not work on MS-Windows'
Bram Moolenaarb0f94c12019-06-13 22:19:53 +02006endif
7if has('gui_running')
Bram Moolenaarb46fecd2019-06-15 17:58:09 +02008 throw 'Skipped: does not work in the GUI'
Bram Moolenaarbff6ad12017-01-24 19:18:13 +01009endif
Bram Moolenaar076e5022017-01-24 18:58:30 +010010set term=xterm
11
Bram Moolenaara9034722018-03-13 15:43:46 +010012source shared.vim
13
Bram Moolenaar076e5022017-01-24 18:58:30 +010014func Test_paste_normal_mode()
15 new
Bram Moolenaarfd8983b2017-02-02 22:21:29 +010016 " In first column text is inserted
Bram Moolenaar076e5022017-01-24 18:58:30 +010017 call setline(1, ['a', 'b', 'c'])
Bram Moolenaarfd8983b2017-02-02 22:21:29 +010018 call cursor(2, 1)
Bram Moolenaar076e5022017-01-24 18:58:30 +010019 call feedkeys("\<Esc>[200~foo\<CR>bar\<Esc>[201~", 'xt')
Bram Moolenaarfd8983b2017-02-02 22:21:29 +010020 call assert_equal('foo', getline(2))
21 call assert_equal('barb', getline(3))
Bram Moolenaar076e5022017-01-24 18:58:30 +010022 call assert_equal('c', getline(4))
23
Bram Moolenaarfd8983b2017-02-02 22:21:29 +010024 " When repeating text is appended
Bram Moolenaar076e5022017-01-24 18:58:30 +010025 normal .
26 call assert_equal('barfoo', getline(3))
Bram Moolenaarfd8983b2017-02-02 22:21:29 +010027 call assert_equal('barb', getline(4))
Bram Moolenaar076e5022017-01-24 18:58:30 +010028 call assert_equal('c', getline(5))
29 bwipe!
Bram Moolenaarfd8983b2017-02-02 22:21:29 +010030
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 Moolenaar076e5022017-01-24 18:58:30 +010046endfunc
47
48func 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 Moolenaar9e817c82017-01-25 21:36:17 +010061
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 Moolenaar076e5022017-01-24 18:58:30 +010071 bwipe!
72endfunc
73
Bram Moolenaar3324d0a2018-03-06 19:51:13 +010074func Test_paste_clipboard()
Bram Moolenaara9034722018-03-13 15:43:46 +010075 if !WorkingClipboard()
Bram Moolenaar3324d0a2018-03-06 19:51:13 +010076 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!
83endfunc
84
Bram Moolenaar076e5022017-01-24 18:58:30 +010085func 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(':'))
88endfunc
Bram Moolenaara1891842017-02-04 21:34:31 +010089
90func 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!
115endfunc
Bram Moolenaard4aa83a2019-05-09 18:59:31 +0200116
117func CheckCopyPaste()
118 call setline(1, ['copy this', ''])
119 normal 1G0"*y$
120 normal j"*p
121 call assert_equal('copy this', getline(2))
122endfunc
123
124func Test_xrestore()
125 if !has('xterm_clipboard')
126 return
127 endif
Bram Moolenaard4aa83a2019-05-09 18:59:31 +0200128 let display = $DISPLAY
129 new
130 call CheckCopyPaste()
131
132 xrestore
133 call CheckCopyPaste()
134
135 exe "xrestore " .. display
136 call CheckCopyPaste()
137
Bram Moolenaard4aa83a2019-05-09 18:59:31 +0200138 bwipe!
139endfunc