blob: c30140f4397bd4a4a4c4a925f7bc80027687981c [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 Moolenaar8c5a2782019-08-07 23:07:07 +02004source check.vim
5CheckNotMSWindows
6CheckNotGui
7
Bram Moolenaar076e5022017-01-24 18:58:30 +01008set term=xterm
9
Bram Moolenaara9034722018-03-13 15:43:46 +010010source shared.vim
11
Bram Moolenaar076e5022017-01-24 18:58:30 +010012func Test_paste_normal_mode()
13 new
Bram Moolenaarfd8983b2017-02-02 22:21:29 +010014 " In first column text is inserted
Bram Moolenaar076e5022017-01-24 18:58:30 +010015 call setline(1, ['a', 'b', 'c'])
Bram Moolenaarfd8983b2017-02-02 22:21:29 +010016 call cursor(2, 1)
Bram Moolenaar076e5022017-01-24 18:58:30 +010017 call feedkeys("\<Esc>[200~foo\<CR>bar\<Esc>[201~", 'xt')
Bram Moolenaarfd8983b2017-02-02 22:21:29 +010018 call assert_equal('foo', getline(2))
19 call assert_equal('barb', getline(3))
Bram Moolenaar076e5022017-01-24 18:58:30 +010020 call assert_equal('c', getline(4))
21
Bram Moolenaarfd8983b2017-02-02 22:21:29 +010022 " When repeating text is appended
Bram Moolenaar076e5022017-01-24 18:58:30 +010023 normal .
24 call assert_equal('barfoo', getline(3))
Bram Moolenaarfd8983b2017-02-02 22:21:29 +010025 call assert_equal('barb', getline(4))
Bram Moolenaar076e5022017-01-24 18:58:30 +010026 call assert_equal('c', getline(5))
27 bwipe!
Bram Moolenaarfd8983b2017-02-02 22:21:29 +010028
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 Moolenaar076e5022017-01-24 18:58:30 +010044endfunc
45
46func 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 Moolenaar9e817c82017-01-25 21:36:17 +010059
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 Moolenaar076e5022017-01-24 18:58:30 +010069 bwipe!
70endfunc
71
Bram Moolenaar3324d0a2018-03-06 19:51:13 +010072func Test_paste_clipboard()
Bram Moolenaar52992fe2019-08-12 14:20:33 +020073 CheckFeature clipboard_working
74
Bram Moolenaar3324d0a2018-03-06 19:51:13 +010075 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!
80endfunc
81
Bram Moolenaar076e5022017-01-24 18:58:30 +010082func Test_paste_cmdline()
83 call feedkeys(":a\<Esc>[200~foo\<CR>bar\<Esc>[201~b\<Home>\"\<CR>", 'xt')
84 call assert_equal("\"afoo\<CR>barb", getreg(':'))
85endfunc
Bram Moolenaara1891842017-02-04 21:34:31 +010086
87func Test_paste_visual_mode()
88 new
89 call setline(1, 'here are some words')
90 call feedkeys("0fsve\<Esc>[200~more\<Esc>[201~", 'xt')
91 call assert_equal('here are more words', getline(1))
92 call assert_equal('some', getreg('-'))
93
94 " include last char in the line
95 call feedkeys("0fwve\<Esc>[200~noises\<Esc>[201~", 'xt')
96 call assert_equal('here are more noises', getline(1))
97 call assert_equal('words', getreg('-'))
98
99 " exclude last char in the line
100 call setline(1, 'some words!')
101 call feedkeys("0fwve\<Esc>[200~noises\<Esc>[201~", 'xt')
102 call assert_equal('some noises!', getline(1))
103 call assert_equal('words', getreg('-'))
104
105 " multi-line selection
106 call setline(1, ['some words', 'and more'])
107 call feedkeys("0fwvj0fd\<Esc>[200~letters\<Esc>[201~", 'xt')
108 call assert_equal('some letters more', getline(1))
109 call assert_equal("words\nand", getreg('1'))
110
111 bwipe!
112endfunc
Bram Moolenaard4aa83a2019-05-09 18:59:31 +0200113
114func CheckCopyPaste()
115 call setline(1, ['copy this', ''])
116 normal 1G0"*y$
117 normal j"*p
118 call assert_equal('copy this', getline(2))
119endfunc
120
121func Test_xrestore()
122 if !has('xterm_clipboard')
123 return
124 endif
Bram Moolenaard4aa83a2019-05-09 18:59:31 +0200125 let display = $DISPLAY
126 new
127 call CheckCopyPaste()
128
129 xrestore
130 call CheckCopyPaste()
131
132 exe "xrestore " .. display
133 call CheckCopyPaste()
134
Bram Moolenaard4aa83a2019-05-09 18:59:31 +0200135 bwipe!
136endfunc