5798
|
1 Test for various eval features. vim: set ft=vim :
|
|
2
|
|
3 Note: system clipboard support is not tested. I do not think anybody will thank
|
|
4 me for messing with clipboard.
|
5796
|
5
|
|
6 STARTTEST
|
|
7 :so small.vim
|
5798
|
8 :set encoding=latin1
|
|
9 :set noswapfile
|
|
10 :lang C
|
|
11 :fun AppendRegContents(reg)
|
|
12 call append('$', printf('%s: type %s; value: %s (%s), expr: %s (%s)', a:reg, getregtype(a:reg), getreg(a:reg), string(getreg(a:reg, 0, 1)), getreg(a:reg, 1), string(getreg(a:reg, 1, 1))))
|
|
13 endfun
|
|
14 :command -nargs=? AR :call AppendRegContents(<q-args>)
|
|
15 :fun SetReg(...)
|
|
16 call call('setreg', a:000)
|
|
17 call append('$', printf('{{{2 setreg(%s)', string(a:000)[1:-2]))
|
|
18 call AppendRegContents(a:1)
|
|
19 if a:1 isnot# '='
|
|
20 execute "silent normal! Go==\n==\e\"".a:1."P"
|
|
21 endif
|
|
22 endfun
|
|
23 :fun ErrExe(str)
|
|
24 call append('$', 'Executing '.a:str)
|
|
25 try
|
|
26 execute a:str
|
|
27 catch
|
|
28 $put =v:exception
|
|
29 endtry
|
|
30 endfun
|
|
31 :fun Test()
|
|
32 $put ='{{{1 let tests'
|
|
33 let @" = 'abc'
|
|
34 AR "
|
|
35 let @" = "abc\n"
|
|
36 AR "
|
|
37 let @" = "abc\<C-m>"
|
|
38 AR "
|
|
39 let @= = '"abc"'
|
|
40 AR =
|
|
41
|
|
42 $put ='{{{1 Basic setreg tests'
|
|
43 call SetReg('a', 'abcA', 'c')
|
|
44 call SetReg('b', 'abcB', 'v')
|
|
45 call SetReg('c', 'abcC', 'l')
|
|
46 call SetReg('d', 'abcD', 'V')
|
|
47 call SetReg('e', 'abcE', 'b')
|
|
48 call SetReg('f', 'abcF', "\<C-v>")
|
|
49 call SetReg('g', 'abcG', 'b10')
|
|
50 call SetReg('h', 'abcH', "\<C-v>10")
|
|
51 call SetReg('I', 'abcI')
|
|
52
|
|
53 $put ='{{{1 Appending single lines with setreg()'
|
|
54 call SetReg('A', 'abcAc', 'c')
|
|
55 call SetReg('A', 'abcAl', 'l')
|
|
56 call SetReg('A', 'abcAc2','c')
|
|
57 call SetReg('b', 'abcBc', 'ca')
|
|
58 call SetReg('b', 'abcBb', 'ba')
|
|
59 call SetReg('b', 'abcBc2','ca')
|
|
60 call SetReg('b', 'abcBb2','b50a')
|
|
61
|
|
62 call SetReg('C', 'abcCl', 'l')
|
|
63 call SetReg('C', 'abcCc', 'c')
|
|
64 call SetReg('D', 'abcDb', 'b')
|
|
65
|
|
66 call SetReg('E', 'abcEb', 'b')
|
|
67 call SetReg('E', 'abcEl', 'l')
|
|
68 call SetReg('F', 'abcFc', 'c')
|
|
69
|
|
70 $put ='{{{1 Appending NL with setreg()'
|
|
71 call setreg('a', 'abcA2', 'c')
|
|
72 call setreg('b', 'abcB2', 'v')
|
|
73 call setreg('c', 'abcC2', 'l')
|
|
74 call setreg('d', 'abcD2', 'V')
|
|
75 call setreg('e', 'abcE2', 'b')
|
|
76 call setreg('f', 'abcF2', "\<C-v>")
|
|
77 call setreg('g', 'abcG2', 'b10')
|
|
78 call setreg('h', 'abcH2', "\<C-v>10")
|
|
79 call setreg('I', 'abcI2')
|
|
80
|
|
81 call SetReg('A', "\n")
|
|
82 call SetReg('B', "\n", 'c')
|
|
83 call SetReg('C', "\n")
|
|
84 call SetReg('D', "\n", 'l')
|
|
85 call SetReg('E', "\n")
|
|
86 call SetReg('F', "\n", 'b')
|
|
87
|
|
88 $put ='{{{1 Setting lists with setreg()'
|
|
89 call SetReg('a', ['abcA3'], 'c')
|
|
90 call SetReg('b', ['abcB3'], 'l')
|
|
91 call SetReg('c', ['abcC3'], 'b')
|
|
92 call SetReg('d', ['abcD3'])
|
5810
|
93 call SetReg('e', [1, 2, 'abc', 3])
|
|
94 call SetReg('f', [1, 2, 3])
|
5798
|
95
|
|
96 $put ='{{{1 Appending lists with setreg()'
|
|
97 call SetReg('A', ['abcA3c'], 'c')
|
|
98 call SetReg('b', ['abcB3l'], 'la')
|
|
99 call SetReg('C', ['abcC3b'], 'lb')
|
|
100 call SetReg('D', ['abcD32'])
|
|
101
|
|
102 call SetReg('A', ['abcA32'])
|
|
103 call SetReg('B', ['abcB3c'], 'c')
|
|
104 call SetReg('C', ['abcC3l'], 'l')
|
|
105 call SetReg('D', ['abcD3b'], 'b')
|
|
106
|
|
107 $put ='{{{1 Appending lists with NL with setreg()'
|
|
108 call SetReg('A', ["\n", 'abcA3l2'], 'l')
|
|
109 call SetReg('B', ["\n", 'abcB3c2'], 'c')
|
|
110 call SetReg('C', ["\n", 'abcC3b2'], 'b')
|
|
111 call SetReg('D', ["\n", 'abcD3b50'],'b50')
|
|
112
|
|
113 $put ='{{{1 Setting lists with NLs with setreg()'
|
|
114 call SetReg('a', ['abcA4-0', "\n", "abcA4-2\n", "\nabcA4-3", "abcA4-4\nabcA4-4-2"])
|
|
115 call SetReg('b', ['abcB4c-0', "\n", "abcB4c-2\n", "\nabcB4c-3", "abcB4c-4\nabcB4c-4-2"], 'c')
|
|
116 call SetReg('c', ['abcC4l-0', "\n", "abcC4l-2\n", "\nabcC4l-3", "abcC4l-4\nabcC4l-4-2"], 'l')
|
|
117 call SetReg('d', ['abcD4b-0', "\n", "abcD4b-2\n", "\nabcD4b-3", "abcD4b-4\nabcD4b-4-2"], 'b')
|
|
118 call SetReg('e', ['abcE4b10-0', "\n", "abcE4b10-2\n", "\nabcE4b10-3", "abcE4b10-4\nabcE4b10-4-2"], 'b10')
|
|
119
|
|
120 $put ='{{{1 Search and expressions'
|
|
121 call SetReg('/', ['abc/'])
|
|
122 call SetReg('/', ["abc/\n"])
|
|
123 call SetReg('=', ['"abc/"'])
|
|
124 call SetReg('=', ["\"abc/\n\""])
|
|
125
|
|
126 $put ='{{{1 Errors'
|
|
127 call ErrExe('call setreg()')
|
|
128 call ErrExe('call setreg(1)')
|
|
129 call ErrExe('call setreg(1, 2, 3, 4)')
|
|
130 call ErrExe('call setreg([], 2)')
|
|
131 call ErrExe('call setreg(1, {})')
|
|
132 call ErrExe('call setreg(1, 2, [])')
|
5810
|
133 call ErrExe('call setreg("/", ["1", "2"])')
|
|
134 call ErrExe('call setreg("=", ["1", "2"])')
|
5798
|
135 call ErrExe('call setreg(1, ["", "", [], ""])')
|
|
136 endfun
|
5796
|
137 :"
|
5798
|
138 :call Test()
|
5796
|
139 :"
|
5798
|
140 :delfunction SetReg
|
|
141 :delfunction AppendRegContents
|
|
142 :delfunction ErrExe
|
|
143 :delfunction Test
|
|
144 :delcommand AR
|
|
145 :call garbagecollect(1)
|
|
146 :"
|
5842
|
147 :" function name not starting with capital
|
|
148 :try
|
|
149 :func! g:test()
|
|
150 :echo "test"
|
|
151 :endfunc
|
|
152 :catch
|
|
153 :$put =v:exception
|
|
154 :endtry
|
|
155 :"
|
5834
|
156 :" function name includes a colon
|
|
157 :try
|
5842
|
158 :func! b:test()
|
5834
|
159 :echo "test"
|
|
160 :endfunc
|
|
161 :catch
|
|
162 :$put =v:exception
|
|
163 :endtry
|
|
164 :"
|
|
165 :" function name folowed by #
|
|
166 :try
|
|
167 :func! test2() "#
|
|
168 :echo "test2"
|
|
169 :endfunc
|
|
170 :catch
|
|
171 :$put =v:exception
|
|
172 :endtry
|
|
173 :"
|
5842
|
174 :" function name starting with/without "g:", buffer-local funcref.
|
5844
|
175 :function! g:Foo(n)
|
|
176 : $put ='called Foo(' . a:n . ')'
|
5842
|
177 :endfunction
|
|
178 :let b:my_func = function('Foo')
|
5844
|
179 :call b:my_func(1)
|
|
180 :echo g:Foo(2)
|
|
181 :echo Foo(3)
|
5842
|
182 :"
|
5850
|
183 :" script-local function used in Funcref must exist.
|
|
184 :so test_eval_func.vim
|
|
185 :"
|
5858
|
186 :" Using $ instead of '$' must give an error
|
|
187 :try
|
|
188 : call append($, 'foobar')
|
|
189 :catch
|
|
190 :$put =v:exception
|
|
191 :endtry
|
|
192 :"
|
5944
|
193 :$put ='{{{1 getcurpos/setpos'
|
5938
|
194 /^012345678
|
5944
|
195 6l:let sp = getcurpos()
|
5938
|
196 0:call setpos('.', sp)
|
|
197 jyl:$put
|
|
198 :"
|
5798
|
199 :/^start:/+1,$wq! test.out
|
|
200 :" vim: et ts=4 isk-=\: fmr=???,???
|
|
201 :call getchar()
|
5796
|
202 ENDTEST
|
|
203
|
5938
|
204 012345678
|
|
205 012345678
|
|
206
|
5798
|
207 start:
|