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