xref: /vim-8.2.3635/src/testdir/test_paste.vim (revision 8c5a278f)
1" Tests for bracketed paste and other forms of pasting.
2
3" Bracketed paste only works with "xterm".  Not in GUI or Windows console.
4source check.vim
5CheckNotMSWindows
6CheckNotGui
7
8set term=xterm
9
10source shared.vim
11
12func Test_paste_normal_mode()
13  new
14  " In first column text is inserted
15  call setline(1, ['a', 'b', 'c'])
16  call cursor(2, 1)
17  call feedkeys("\<Esc>[200~foo\<CR>bar\<Esc>[201~", 'xt')
18  call assert_equal('foo', getline(2))
19  call assert_equal('barb', getline(3))
20  call assert_equal('c', getline(4))
21
22  " When repeating text is appended
23  normal .
24  call assert_equal('barfoo', getline(3))
25  call assert_equal('barb', getline(4))
26  call assert_equal('c', getline(5))
27  bwipe!
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))
44endfunc
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))
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
69  bwipe!
70endfunc
71
72func Test_paste_clipboard()
73  if !WorkingClipboard()
74    return
75  endif
76  let @+ = "nasty\<Esc>:!ls\<CR>command"
77  new
78  exe "normal i\<C-R>+\<Esc>"
79  call assert_equal("nasty\<Esc>:!ls\<CR>command", getline(1))
80  bwipe!
81endfunc
82
83func 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(':'))
86endfunc
87
88func Test_paste_visual_mode()
89  new
90  call setline(1, 'here are some words')
91  call feedkeys("0fsve\<Esc>[200~more\<Esc>[201~", 'xt')
92  call assert_equal('here are more words', getline(1))
93  call assert_equal('some', getreg('-'))
94
95  " include last char in the line
96  call feedkeys("0fwve\<Esc>[200~noises\<Esc>[201~", 'xt')
97  call assert_equal('here are more noises', getline(1))
98  call assert_equal('words', getreg('-'))
99
100  " exclude last char in the line
101  call setline(1, 'some words!')
102  call feedkeys("0fwve\<Esc>[200~noises\<Esc>[201~", 'xt')
103  call assert_equal('some noises!', getline(1))
104  call assert_equal('words', getreg('-'))
105
106  " multi-line selection
107  call setline(1, ['some words', 'and more'])
108  call feedkeys("0fwvj0fd\<Esc>[200~letters\<Esc>[201~", 'xt')
109  call assert_equal('some letters more', getline(1))
110  call assert_equal("words\nand", getreg('1'))
111
112  bwipe!
113endfunc
114
115func CheckCopyPaste()
116  call setline(1, ['copy this', ''])
117  normal 1G0"*y$
118  normal j"*p
119  call assert_equal('copy this', getline(2))
120endfunc
121
122func Test_xrestore()
123  if !has('xterm_clipboard')
124    return
125  endif
126  let display = $DISPLAY
127  new
128  call CheckCopyPaste()
129
130  xrestore
131  call CheckCopyPaste()
132
133  exe "xrestore " .. display
134  call CheckCopyPaste()
135
136  bwipe!
137endfunc
138