Mercurial > vim
annotate src/testdir/test_eval.in @ 9640:bc0a6d9a9a07 v7.4.2097
commit https://github.com/vim/vim/commit/d4f31dc45482e8db527ca044b9c3436b1e750006
Author: Bram Moolenaar <Bram@vim.org>
Date: Sat Jul 23 17:28:22 2016 +0200
patch 7.4.2097
Problem: Warning from 64 bit compiler.
Solution: use size_t instead of int. (Mike Williams)
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Sat, 23 Jul 2016 17:30:06 +0200 |
parents | 9c420b8db435 |
children | 30f9a62f5f51 |
rev | line source |
---|---|
5798 | 1 Test for various eval features. vim: set ft=vim : |
2 | |
6543 | 3 Note: system clipboard is saved, changed and restored. |
5796 | 4 |
6563 | 5 clipboard contents |
6 something else | |
7 | |
5796 | 8 STARTTEST |
9 :so small.vim | |
5798 | 10 :set encoding=latin1 |
11 :set noswapfile | |
12 :lang C | |
13 :fun AppendRegContents(reg) | |
6563 | 14 call AppendRegParts(a:reg, getregtype(a:reg), getreg(a:reg), string(getreg(a:reg, 0, 1)), getreg(a:reg, 1), string(getreg(a:reg, 1, 1))) |
15 :endfun | |
16 :fun AppendRegParts(reg, type, cont, strcont, cont1, strcont1) | |
17 call append('$', printf('%s: type %s; value: %s (%s), expr: %s (%s)', a:reg, a:type, a:cont, a:strcont, a:cont1, a:strcont1)) | |
5798 | 18 endfun |
19 :command -nargs=? AR :call AppendRegContents(<q-args>) | |
20 :fun SetReg(...) | |
21 call call('setreg', a:000) | |
22 call append('$', printf('{{{2 setreg(%s)', string(a:000)[1:-2])) | |
23 call AppendRegContents(a:1) | |
24 if a:1 isnot# '=' | |
25 execute "silent normal! Go==\n==\e\"".a:1."P" | |
26 endif | |
27 endfun | |
28 :fun ErrExe(str) | |
29 call append('$', 'Executing '.a:str) | |
30 try | |
31 execute a:str | |
32 catch | |
33 $put =v:exception | |
34 endtry | |
35 endfun | |
36 :fun Test() | |
37 $put ='{{{1 let tests' | |
38 let @" = 'abc' | |
39 AR " | |
40 let @" = "abc\n" | |
41 AR " | |
42 let @" = "abc\<C-m>" | |
43 AR " | |
44 let @= = '"abc"' | |
45 AR = | |
46 | |
47 $put ='{{{1 Basic setreg tests' | |
48 call SetReg('a', 'abcA', 'c') | |
49 call SetReg('b', 'abcB', 'v') | |
50 call SetReg('c', 'abcC', 'l') | |
51 call SetReg('d', 'abcD', 'V') | |
52 call SetReg('e', 'abcE', 'b') | |
53 call SetReg('f', 'abcF', "\<C-v>") | |
54 call SetReg('g', 'abcG', 'b10') | |
55 call SetReg('h', 'abcH', "\<C-v>10") | |
56 call SetReg('I', 'abcI') | |
57 | |
58 $put ='{{{1 Appending single lines with setreg()' | |
59 call SetReg('A', 'abcAc', 'c') | |
60 call SetReg('A', 'abcAl', 'l') | |
61 call SetReg('A', 'abcAc2','c') | |
62 call SetReg('b', 'abcBc', 'ca') | |
63 call SetReg('b', 'abcBb', 'ba') | |
64 call SetReg('b', 'abcBc2','ca') | |
65 call SetReg('b', 'abcBb2','b50a') | |
66 | |
67 call SetReg('C', 'abcCl', 'l') | |
68 call SetReg('C', 'abcCc', 'c') | |
69 call SetReg('D', 'abcDb', 'b') | |
70 | |
71 call SetReg('E', 'abcEb', 'b') | |
72 call SetReg('E', 'abcEl', 'l') | |
73 call SetReg('F', 'abcFc', 'c') | |
74 | |
75 $put ='{{{1 Appending NL with setreg()' | |
76 call setreg('a', 'abcA2', 'c') | |
77 call setreg('b', 'abcB2', 'v') | |
78 call setreg('c', 'abcC2', 'l') | |
79 call setreg('d', 'abcD2', 'V') | |
80 call setreg('e', 'abcE2', 'b') | |
81 call setreg('f', 'abcF2', "\<C-v>") | |
82 call setreg('g', 'abcG2', 'b10') | |
83 call setreg('h', 'abcH2', "\<C-v>10") | |
84 call setreg('I', 'abcI2') | |
85 | |
86 call SetReg('A', "\n") | |
87 call SetReg('B', "\n", 'c') | |
88 call SetReg('C', "\n") | |
89 call SetReg('D', "\n", 'l') | |
90 call SetReg('E', "\n") | |
91 call SetReg('F', "\n", 'b') | |
92 | |
93 $put ='{{{1 Setting lists with setreg()' | |
94 call SetReg('a', ['abcA3'], 'c') | |
95 call SetReg('b', ['abcB3'], 'l') | |
96 call SetReg('c', ['abcC3'], 'b') | |
97 call SetReg('d', ['abcD3']) | |
5810 | 98 call SetReg('e', [1, 2, 'abc', 3]) |
99 call SetReg('f', [1, 2, 3]) | |
5798 | 100 |
101 $put ='{{{1 Appending lists with setreg()' | |
102 call SetReg('A', ['abcA3c'], 'c') | |
103 call SetReg('b', ['abcB3l'], 'la') | |
104 call SetReg('C', ['abcC3b'], 'lb') | |
105 call SetReg('D', ['abcD32']) | |
106 | |
107 call SetReg('A', ['abcA32']) | |
108 call SetReg('B', ['abcB3c'], 'c') | |
109 call SetReg('C', ['abcC3l'], 'l') | |
110 call SetReg('D', ['abcD3b'], 'b') | |
111 | |
112 $put ='{{{1 Appending lists with NL with setreg()' | |
113 call SetReg('A', ["\n", 'abcA3l2'], 'l') | |
114 call SetReg('B', ["\n", 'abcB3c2'], 'c') | |
115 call SetReg('C', ["\n", 'abcC3b2'], 'b') | |
116 call SetReg('D', ["\n", 'abcD3b50'],'b50') | |
117 | |
118 $put ='{{{1 Setting lists with NLs with setreg()' | |
119 call SetReg('a', ['abcA4-0', "\n", "abcA4-2\n", "\nabcA4-3", "abcA4-4\nabcA4-4-2"]) | |
120 call SetReg('b', ['abcB4c-0', "\n", "abcB4c-2\n", "\nabcB4c-3", "abcB4c-4\nabcB4c-4-2"], 'c') | |
121 call SetReg('c', ['abcC4l-0', "\n", "abcC4l-2\n", "\nabcC4l-3", "abcC4l-4\nabcC4l-4-2"], 'l') | |
122 call SetReg('d', ['abcD4b-0', "\n", "abcD4b-2\n", "\nabcD4b-3", "abcD4b-4\nabcD4b-4-2"], 'b') | |
123 call SetReg('e', ['abcE4b10-0', "\n", "abcE4b10-2\n", "\nabcE4b10-3", "abcE4b10-4\nabcE4b10-4-2"], 'b10') | |
124 | |
125 $put ='{{{1 Search and expressions' | |
126 call SetReg('/', ['abc/']) | |
127 call SetReg('/', ["abc/\n"]) | |
128 call SetReg('=', ['"abc/"']) | |
129 call SetReg('=', ["\"abc/\n\""]) | |
6543 | 130 $put ='{{{1 System clipboard' |
6563 | 131 if has('clipboard') |
6543 | 132 " Save and restore system clipboard. |
133 " If no connection to X-Server is possible, test should succeed. | |
6571 | 134 let _clipreg = ['*', getreg('*'), getregtype('*')] |
6563 | 135 let _clipopt = &cb |
6571 | 136 let &cb='unnamed' |
6563 | 137 5y |
6571 | 138 AR * |
6563 | 139 tabdo :windo :echo "hi" |
140 6y | |
6571 | 141 AR * |
6563 | 142 let &cb=_clipopt |
143 call call('setreg', _clipreg) | |
144 else | |
6571 | 145 call AppendRegParts('*', 'V', "clipboard contents\n", "['clipboard contents']", "clipboard contents\n", "['clipboard contents']") |
146 call AppendRegParts('*', 'V', "something else\n", "['something else']", "something else\n", "['something else']") | |
6563 | 147 endif |
5798 | 148 $put ='{{{1 Errors' |
149 call ErrExe('call setreg()') | |
150 call ErrExe('call setreg(1)') | |
151 call ErrExe('call setreg(1, 2, 3, 4)') | |
152 call ErrExe('call setreg([], 2)') | |
153 call ErrExe('call setreg(1, {})') | |
154 call ErrExe('call setreg(1, 2, [])') | |
5810 | 155 call ErrExe('call setreg("/", ["1", "2"])') |
156 call ErrExe('call setreg("=", ["1", "2"])') | |
5798 | 157 call ErrExe('call setreg(1, ["", "", [], ""])') |
158 endfun | |
5796 | 159 :" |
5798 | 160 :call Test() |
5796 | 161 :" |
5798 | 162 :delfunction SetReg |
163 :delfunction AppendRegContents | |
164 :delfunction ErrExe | |
165 :delfunction Test | |
166 :delcommand AR | |
167 :call garbagecollect(1) | |
168 :" | |
5842 | 169 :" function name not starting with capital |
170 :try | |
171 :func! g:test() | |
172 :echo "test" | |
173 :endfunc | |
174 :catch | |
175 :$put =v:exception | |
176 :endtry | |
177 :" | |
5834 | 178 :" function name includes a colon |
179 :try | |
5842 | 180 :func! b:test() |
5834 | 181 :echo "test" |
182 :endfunc | |
183 :catch | |
184 :$put =v:exception | |
185 :endtry | |
186 :" | |
187 :" function name folowed by # | |
188 :try | |
189 :func! test2() "# | |
190 :echo "test2" | |
191 :endfunc | |
192 :catch | |
193 :$put =v:exception | |
194 :endtry | |
195 :" | |
5842 | 196 :" function name starting with/without "g:", buffer-local funcref. |
5844 | 197 :function! g:Foo(n) |
198 : $put ='called Foo(' . a:n . ')' | |
5842 | 199 :endfunction |
200 :let b:my_func = function('Foo') | |
5844 | 201 :call b:my_func(1) |
202 :echo g:Foo(2) | |
203 :echo Foo(3) | |
5842 | 204 :" |
5850 | 205 :" script-local function used in Funcref must exist. |
206 :so test_eval_func.vim | |
207 :" | |
5858 | 208 :" Using $ instead of '$' must give an error |
209 :try | |
210 : call append($, 'foobar') | |
211 :catch | |
212 :$put =v:exception | |
213 :endtry | |
214 :" | |
5944 | 215 :$put ='{{{1 getcurpos/setpos' |
5938 | 216 /^012345678 |
5944 | 217 6l:let sp = getcurpos() |
5938 | 218 0:call setpos('.', sp) |
219 jyl:$put | |
220 :" | |
7611
9c420b8db435
commit https://github.com/vim/vim/commit/9bbf63dbf8286fadc0cd6b3428010abb67b1b64d
Christian Brabandt <cb@256bit.org>
parents:
6571
diff
changeset
|
221 :" substring and variable name |
9c420b8db435
commit https://github.com/vim/vim/commit/9bbf63dbf8286fadc0cd6b3428010abb67b1b64d
Christian Brabandt <cb@256bit.org>
parents:
6571
diff
changeset
|
222 :let str = 'abcdef' |
9c420b8db435
commit https://github.com/vim/vim/commit/9bbf63dbf8286fadc0cd6b3428010abb67b1b64d
Christian Brabandt <cb@256bit.org>
parents:
6571
diff
changeset
|
223 :let n = 3 |
9c420b8db435
commit https://github.com/vim/vim/commit/9bbf63dbf8286fadc0cd6b3428010abb67b1b64d
Christian Brabandt <cb@256bit.org>
parents:
6571
diff
changeset
|
224 :$put =str[n:] |
9c420b8db435
commit https://github.com/vim/vim/commit/9bbf63dbf8286fadc0cd6b3428010abb67b1b64d
Christian Brabandt <cb@256bit.org>
parents:
6571
diff
changeset
|
225 :$put =str[:n] |
9c420b8db435
commit https://github.com/vim/vim/commit/9bbf63dbf8286fadc0cd6b3428010abb67b1b64d
Christian Brabandt <cb@256bit.org>
parents:
6571
diff
changeset
|
226 :$put =str[n:n] |
9c420b8db435
commit https://github.com/vim/vim/commit/9bbf63dbf8286fadc0cd6b3428010abb67b1b64d
Christian Brabandt <cb@256bit.org>
parents:
6571
diff
changeset
|
227 :unlet n |
9c420b8db435
commit https://github.com/vim/vim/commit/9bbf63dbf8286fadc0cd6b3428010abb67b1b64d
Christian Brabandt <cb@256bit.org>
parents:
6571
diff
changeset
|
228 :let nn = 3 |
9c420b8db435
commit https://github.com/vim/vim/commit/9bbf63dbf8286fadc0cd6b3428010abb67b1b64d
Christian Brabandt <cb@256bit.org>
parents:
6571
diff
changeset
|
229 :$put =str[nn:] |
9c420b8db435
commit https://github.com/vim/vim/commit/9bbf63dbf8286fadc0cd6b3428010abb67b1b64d
Christian Brabandt <cb@256bit.org>
parents:
6571
diff
changeset
|
230 :$put =str[:nn] |
9c420b8db435
commit https://github.com/vim/vim/commit/9bbf63dbf8286fadc0cd6b3428010abb67b1b64d
Christian Brabandt <cb@256bit.org>
parents:
6571
diff
changeset
|
231 :$put =str[nn:nn] |
9c420b8db435
commit https://github.com/vim/vim/commit/9bbf63dbf8286fadc0cd6b3428010abb67b1b64d
Christian Brabandt <cb@256bit.org>
parents:
6571
diff
changeset
|
232 :unlet nn |
9c420b8db435
commit https://github.com/vim/vim/commit/9bbf63dbf8286fadc0cd6b3428010abb67b1b64d
Christian Brabandt <cb@256bit.org>
parents:
6571
diff
changeset
|
233 :let b:nn = 4 |
9c420b8db435
commit https://github.com/vim/vim/commit/9bbf63dbf8286fadc0cd6b3428010abb67b1b64d
Christian Brabandt <cb@256bit.org>
parents:
6571
diff
changeset
|
234 :$put =str[b:nn:] |
9c420b8db435
commit https://github.com/vim/vim/commit/9bbf63dbf8286fadc0cd6b3428010abb67b1b64d
Christian Brabandt <cb@256bit.org>
parents:
6571
diff
changeset
|
235 :$put =str[:b:nn] |
9c420b8db435
commit https://github.com/vim/vim/commit/9bbf63dbf8286fadc0cd6b3428010abb67b1b64d
Christian Brabandt <cb@256bit.org>
parents:
6571
diff
changeset
|
236 :$put =str[b:nn:b:nn] |
9c420b8db435
commit https://github.com/vim/vim/commit/9bbf63dbf8286fadc0cd6b3428010abb67b1b64d
Christian Brabandt <cb@256bit.org>
parents:
6571
diff
changeset
|
237 :unlet b:nn |
9c420b8db435
commit https://github.com/vim/vim/commit/9bbf63dbf8286fadc0cd6b3428010abb67b1b64d
Christian Brabandt <cb@256bit.org>
parents:
6571
diff
changeset
|
238 :" |
5798 | 239 :/^start:/+1,$wq! test.out |
240 :" vim: et ts=4 isk-=\: fmr=???,??? | |
241 :call getchar() | |
5796 | 242 ENDTEST |
243 | |
5938 | 244 012345678 |
245 012345678 | |
246 | |
5798 | 247 start: |