blob: e1f4f6de9f2242ea7e1b47f92a1e51c9de833d28 [file] [log] [blame]
Bram Moolenaar5a50c222014-04-02 22:17:10 +02001Test for various eval features. vim: set ft=vim :
2
Bram Moolenaarfabaf752017-12-23 17:26:11 +01003NOTE: Do not add more here, use new style test test_eval_stuff.vim
4
Bram Moolenaar5c27fd12015-01-27 14:09:37 +01005Note: system clipboard is saved, changed and restored.
Bram Moolenaarb7cb42b2014-04-02 19:55:10 +02006
Bram Moolenaar4ac163a2015-01-27 22:52:15 +01007clipboard contents
8something else
9
Bram Moolenaarb7cb42b2014-04-02 19:55:10 +020010STARTTEST
11:so small.vim
Bram Moolenaar5a50c222014-04-02 22:17:10 +020012:set encoding=latin1
13:set noswapfile
14:lang C
15:fun AppendRegContents(reg)
Bram Moolenaar4ac163a2015-01-27 22:52:15 +010016 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))
Bram Moolenaar5a50c222014-04-02 22:17:10 +020020endfun
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
29endfun
30:fun ErrExe(str)
31 call append('$', 'Executing '.a:str)
32 try
33 execute a:str
34 catch
35 $put =v:exception
36 endtry
37endfun
38:fun Test()
Bram Moolenaar5a50c222014-04-02 22:17:10 +020039$put ='{{{1 Appending NL with setreg()'
40call setreg('a', 'abcA2', 'c')
41call setreg('b', 'abcB2', 'v')
42call setreg('c', 'abcC2', 'l')
43call setreg('d', 'abcD2', 'V')
44call setreg('e', 'abcE2', 'b')
45call setreg('f', 'abcF2', "\<C-v>")
46call setreg('g', 'abcG2', 'b10')
47call setreg('h', 'abcH2', "\<C-v>10")
48call setreg('I', 'abcI2')
49
50call SetReg('A', "\n")
51call SetReg('B', "\n", 'c')
52call SetReg('C', "\n")
53call SetReg('D', "\n", 'l')
54call SetReg('E', "\n")
55call SetReg('F', "\n", 'b')
56
57$put ='{{{1 Setting lists with setreg()'
58call SetReg('a', ['abcA3'], 'c')
59call SetReg('b', ['abcB3'], 'l')
60call SetReg('c', ['abcC3'], 'b')
61call SetReg('d', ['abcD3'])
Bram Moolenaar7d647822014-04-05 21:28:56 +020062call SetReg('e', [1, 2, 'abc', 3])
63call SetReg('f', [1, 2, 3])
Bram Moolenaar5a50c222014-04-02 22:17:10 +020064
65$put ='{{{1 Appending lists with setreg()'
66call SetReg('A', ['abcA3c'], 'c')
67call SetReg('b', ['abcB3l'], 'la')
68call SetReg('C', ['abcC3b'], 'lb')
69call SetReg('D', ['abcD32'])
70
71call SetReg('A', ['abcA32'])
72call SetReg('B', ['abcB3c'], 'c')
73call SetReg('C', ['abcC3l'], 'l')
74call SetReg('D', ['abcD3b'], 'b')
75
76$put ='{{{1 Appending lists with NL with setreg()'
77call SetReg('A', ["\n", 'abcA3l2'], 'l')
78call SetReg('B', ["\n", 'abcB3c2'], 'c')
79call SetReg('C', ["\n", 'abcC3b2'], 'b')
80call SetReg('D', ["\n", 'abcD3b50'],'b50')
81
82$put ='{{{1 Setting lists with NLs with setreg()'
83call SetReg('a', ['abcA4-0', "\n", "abcA4-2\n", "\nabcA4-3", "abcA4-4\nabcA4-4-2"])
84call SetReg('b', ['abcB4c-0', "\n", "abcB4c-2\n", "\nabcB4c-3", "abcB4c-4\nabcB4c-4-2"], 'c')
85call SetReg('c', ['abcC4l-0', "\n", "abcC4l-2\n", "\nabcC4l-3", "abcC4l-4\nabcC4l-4-2"], 'l')
86call SetReg('d', ['abcD4b-0', "\n", "abcD4b-2\n", "\nabcD4b-3", "abcD4b-4\nabcD4b-4-2"], 'b')
87call SetReg('e', ['abcE4b10-0', "\n", "abcE4b10-2\n", "\nabcE4b10-3", "abcE4b10-4\nabcE4b10-4-2"], 'b10')
88
89$put ='{{{1 Search and expressions'
90call SetReg('/', ['abc/'])
91call SetReg('/', ["abc/\n"])
92call SetReg('=', ['"abc/"'])
93call SetReg('=', ["\"abc/\n\""])
Bram Moolenaar5c27fd12015-01-27 14:09:37 +010094$put ='{{{1 System clipboard'
Bram Moolenaar4ac163a2015-01-27 22:52:15 +010095if has('clipboard')
Bram Moolenaar5c27fd12015-01-27 14:09:37 +010096" Save and restore system clipboard.
97" If no connection to X-Server is possible, test should succeed.
Bram Moolenaare08dd4e2015-02-03 16:07:47 +010098let _clipreg = ['*', getreg('*'), getregtype('*')]
Bram Moolenaar4ac163a2015-01-27 22:52:15 +010099let _clipopt = &cb
Bram Moolenaare08dd4e2015-02-03 16:07:47 +0100100let &cb='unnamed'
Bram Moolenaarfabaf752017-12-23 17:26:11 +01001017y
Bram Moolenaare08dd4e2015-02-03 16:07:47 +0100102AR *
Bram Moolenaar4ac163a2015-01-27 22:52:15 +0100103tabdo :windo :echo "hi"
Bram Moolenaarfabaf752017-12-23 17:26:11 +01001048y
Bram Moolenaare08dd4e2015-02-03 16:07:47 +0100105AR *
Bram Moolenaar4ac163a2015-01-27 22:52:15 +0100106let &cb=_clipopt
107call call('setreg', _clipreg)
108else
Bram Moolenaare08dd4e2015-02-03 16:07:47 +0100109 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']")
Bram Moolenaar4ac163a2015-01-27 22:52:15 +0100111endif
Bram Moolenaar5a50c222014-04-02 22:17:10 +0200112$put ='{{{1 Errors'
113call ErrExe('call setreg()')
114call ErrExe('call setreg(1)')
115call ErrExe('call setreg(1, 2, 3, 4)')
116call ErrExe('call setreg([], 2)')
117call ErrExe('call setreg(1, {})')
118call ErrExe('call setreg(1, 2, [])')
Bram Moolenaar7d647822014-04-05 21:28:56 +0200119call ErrExe('call setreg("/", ["1", "2"])')
120call ErrExe('call setreg("=", ["1", "2"])')
Bram Moolenaar5a50c222014-04-02 22:17:10 +0200121call ErrExe('call setreg(1, ["", "", [], ""])')
122endfun
Bram Moolenaarb7cb42b2014-04-02 19:55:10 +0200123:"
Bram Moolenaar5a50c222014-04-02 22:17:10 +0200124:call Test()
Bram Moolenaarb7cb42b2014-04-02 19:55:10 +0200125:"
Bram Moolenaar5a50c222014-04-02 22:17:10 +0200126:delfunction SetReg
127:delfunction AppendRegContents
128:delfunction ErrExe
129:delfunction Test
130:delcommand AR
131:call garbagecollect(1)
132:"
Bram Moolenaareccb7fc2014-04-23 20:43:41 +0200133:" function name not starting with capital
Bram Moolenaar9bdfb002014-04-23 17:43:42 +0200134:try
135:func! g:test()
136:echo "test"
137:endfunc
138:catch
139:$put =v:exception
140:endtry
141:"
Bram Moolenaareccb7fc2014-04-23 20:43:41 +0200142:" function name includes a colon
143:try
144:func! b:test()
145:echo "test"
146:endfunc
147:catch
148:$put =v:exception
149:endtry
150:"
Bram Moolenaar9bdfb002014-04-23 17:43:42 +0200151:" function name folowed by #
152:try
153:func! test2() "#
154:echo "test2"
155:endfunc
156:catch
157:$put =v:exception
158:endtry
159:"
Bram Moolenaareccb7fc2014-04-23 20:43:41 +0200160:" function name starting with/without "g:", buffer-local funcref.
Bram Moolenaara4f317d2014-04-24 17:12:33 +0200161:function! g:Foo(n)
162: $put ='called Foo(' . a:n . ')'
Bram Moolenaareccb7fc2014-04-23 20:43:41 +0200163:endfunction
164:let b:my_func = function('Foo')
Bram Moolenaara4f317d2014-04-24 17:12:33 +0200165:call b:my_func(1)
166:echo g:Foo(2)
167:echo Foo(3)
Bram Moolenaareccb7fc2014-04-23 20:43:41 +0200168:"
Bram Moolenaar355a95a2014-04-29 14:03:02 +0200169:" script-local function used in Funcref must exist.
170:so test_eval_func.vim
171:"
Bram Moolenaare512c8c2014-04-29 17:41:22 +0200172:" Using $ instead of '$' must give an error
173:try
174: call append($, 'foobar')
175:catch
176:$put =v:exception
177:endtry
178:"
Bram Moolenaar6f6c0f82014-05-28 20:31:42 +0200179:$put ='{{{1 getcurpos/setpos'
Bram Moolenaar493c1782014-05-28 14:34:46 +0200180/^012345678
Bram Moolenaar6f6c0f82014-05-28 20:31:42 +02001816l:let sp = getcurpos()
Bram Moolenaar493c1782014-05-28 14:34:46 +02001820:call setpos('.', sp)
183jyl:$put
184:"
Bram Moolenaar9bbf63d2016-01-16 16:49:28 +0100185:" substring and variable name
186:let str = 'abcdef'
187:let n = 3
188:$put =str[n:]
189:$put =str[:n]
190:$put =str[n:n]
191:unlet n
192:let nn = 3
193:$put =str[nn:]
194:$put =str[:nn]
195:$put =str[nn:nn]
196:unlet nn
197:let b:nn = 4
198:$put =str[b:nn:]
199:$put =str[:b:nn]
200:$put =str[b:nn:b:nn]
201:unlet b:nn
202:"
Bram Moolenaar5a50c222014-04-02 22:17:10 +0200203:/^start:/+1,$wq! test.out
204:" vim: et ts=4 isk-=\: fmr=???,???
205:call getchar()
Bram Moolenaarb7cb42b2014-04-02 19:55:10 +0200206ENDTEST
207
Bram Moolenaar493c1782014-05-28 14:34:46 +0200208012345678
209012345678
210
Bram Moolenaar5a50c222014-04-02 22:17:10 +0200211start: