blob: 087e6099ac70aa6820fd10d24b35b958df4e1fb5 [file] [log] [blame]
Bram Moolenaar5a50c222014-04-02 22:17:10 +02001Test for various eval features. vim: set ft=vim :
2
Bram Moolenaar5c27fd12015-01-27 14:09:37 +01003Note: system clipboard is saved, changed and restored.
Bram Moolenaarb7cb42b2014-04-02 19:55:10 +02004
Bram Moolenaar4ac163a2015-01-27 22:52:15 +01005clipboard contents
6something else
7
Bram Moolenaarb7cb42b2014-04-02 19:55:10 +02008STARTTEST
9:so small.vim
Bram Moolenaar5a50c222014-04-02 22:17:10 +020010:set encoding=latin1
11:set noswapfile
12:lang C
13:fun AppendRegContents(reg)
Bram Moolenaar4ac163a2015-01-27 22:52:15 +010014 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))
Bram Moolenaar5a50c222014-04-02 22:17:10 +020018endfun
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
27endfun
28:fun ErrExe(str)
29 call append('$', 'Executing '.a:str)
30 try
31 execute a:str
32 catch
33 $put =v:exception
34 endtry
35endfun
36:fun Test()
37$put ='{{{1 let tests'
38let @" = 'abc'
39AR "
40let @" = "abc\n"
41AR "
42let @" = "abc\<C-m>"
43AR "
44let @= = '"abc"'
45AR =
46
47$put ='{{{1 Basic setreg tests'
48call SetReg('a', 'abcA', 'c')
49call SetReg('b', 'abcB', 'v')
50call SetReg('c', 'abcC', 'l')
51call SetReg('d', 'abcD', 'V')
52call SetReg('e', 'abcE', 'b')
53call SetReg('f', 'abcF', "\<C-v>")
54call SetReg('g', 'abcG', 'b10')
55call SetReg('h', 'abcH', "\<C-v>10")
56call SetReg('I', 'abcI')
57
58$put ='{{{1 Appending single lines with setreg()'
59call SetReg('A', 'abcAc', 'c')
60call SetReg('A', 'abcAl', 'l')
61call SetReg('A', 'abcAc2','c')
62call SetReg('b', 'abcBc', 'ca')
63call SetReg('b', 'abcBb', 'ba')
64call SetReg('b', 'abcBc2','ca')
65call SetReg('b', 'abcBb2','b50a')
66
67call SetReg('C', 'abcCl', 'l')
68call SetReg('C', 'abcCc', 'c')
69call SetReg('D', 'abcDb', 'b')
70
71call SetReg('E', 'abcEb', 'b')
72call SetReg('E', 'abcEl', 'l')
73call SetReg('F', 'abcFc', 'c')
74
75$put ='{{{1 Appending NL with setreg()'
76call setreg('a', 'abcA2', 'c')
77call setreg('b', 'abcB2', 'v')
78call setreg('c', 'abcC2', 'l')
79call setreg('d', 'abcD2', 'V')
80call setreg('e', 'abcE2', 'b')
81call setreg('f', 'abcF2', "\<C-v>")
82call setreg('g', 'abcG2', 'b10')
83call setreg('h', 'abcH2', "\<C-v>10")
84call setreg('I', 'abcI2')
85
86call SetReg('A', "\n")
87call SetReg('B', "\n", 'c')
88call SetReg('C', "\n")
89call SetReg('D', "\n", 'l')
90call SetReg('E', "\n")
91call SetReg('F', "\n", 'b')
92
93$put ='{{{1 Setting lists with setreg()'
94call SetReg('a', ['abcA3'], 'c')
95call SetReg('b', ['abcB3'], 'l')
96call SetReg('c', ['abcC3'], 'b')
97call SetReg('d', ['abcD3'])
Bram Moolenaar7d647822014-04-05 21:28:56 +020098call SetReg('e', [1, 2, 'abc', 3])
99call SetReg('f', [1, 2, 3])
Bram Moolenaar5a50c222014-04-02 22:17:10 +0200100
101$put ='{{{1 Appending lists with setreg()'
102call SetReg('A', ['abcA3c'], 'c')
103call SetReg('b', ['abcB3l'], 'la')
104call SetReg('C', ['abcC3b'], 'lb')
105call SetReg('D', ['abcD32'])
106
107call SetReg('A', ['abcA32'])
108call SetReg('B', ['abcB3c'], 'c')
109call SetReg('C', ['abcC3l'], 'l')
110call SetReg('D', ['abcD3b'], 'b')
111
112$put ='{{{1 Appending lists with NL with setreg()'
113call SetReg('A', ["\n", 'abcA3l2'], 'l')
114call SetReg('B', ["\n", 'abcB3c2'], 'c')
115call SetReg('C', ["\n", 'abcC3b2'], 'b')
116call SetReg('D', ["\n", 'abcD3b50'],'b50')
117
118$put ='{{{1 Setting lists with NLs with setreg()'
119call SetReg('a', ['abcA4-0', "\n", "abcA4-2\n", "\nabcA4-3", "abcA4-4\nabcA4-4-2"])
120call SetReg('b', ['abcB4c-0', "\n", "abcB4c-2\n", "\nabcB4c-3", "abcB4c-4\nabcB4c-4-2"], 'c')
121call SetReg('c', ['abcC4l-0', "\n", "abcC4l-2\n", "\nabcC4l-3", "abcC4l-4\nabcC4l-4-2"], 'l')
122call SetReg('d', ['abcD4b-0', "\n", "abcD4b-2\n", "\nabcD4b-3", "abcD4b-4\nabcD4b-4-2"], 'b')
123call SetReg('e', ['abcE4b10-0', "\n", "abcE4b10-2\n", "\nabcE4b10-3", "abcE4b10-4\nabcE4b10-4-2"], 'b10')
124
125$put ='{{{1 Search and expressions'
126call SetReg('/', ['abc/'])
127call SetReg('/', ["abc/\n"])
128call SetReg('=', ['"abc/"'])
129call SetReg('=', ["\"abc/\n\""])
Bram Moolenaar5c27fd12015-01-27 14:09:37 +0100130$put ='{{{1 System clipboard'
Bram Moolenaar4ac163a2015-01-27 22:52:15 +0100131if has('clipboard')
Bram Moolenaar5c27fd12015-01-27 14:09:37 +0100132" Save and restore system clipboard.
133" If no connection to X-Server is possible, test should succeed.
Bram Moolenaare08dd4e2015-02-03 16:07:47 +0100134let _clipreg = ['*', getreg('*'), getregtype('*')]
Bram Moolenaar4ac163a2015-01-27 22:52:15 +0100135let _clipopt = &cb
Bram Moolenaare08dd4e2015-02-03 16:07:47 +0100136let &cb='unnamed'
Bram Moolenaar4ac163a2015-01-27 22:52:15 +01001375y
Bram Moolenaare08dd4e2015-02-03 16:07:47 +0100138AR *
Bram Moolenaar4ac163a2015-01-27 22:52:15 +0100139tabdo :windo :echo "hi"
1406y
Bram Moolenaare08dd4e2015-02-03 16:07:47 +0100141AR *
Bram Moolenaar4ac163a2015-01-27 22:52:15 +0100142let &cb=_clipopt
143call call('setreg', _clipreg)
144else
Bram Moolenaare08dd4e2015-02-03 16:07:47 +0100145 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']")
Bram Moolenaar4ac163a2015-01-27 22:52:15 +0100147endif
Bram Moolenaar5a50c222014-04-02 22:17:10 +0200148$put ='{{{1 Errors'
149call ErrExe('call setreg()')
150call ErrExe('call setreg(1)')
151call ErrExe('call setreg(1, 2, 3, 4)')
152call ErrExe('call setreg([], 2)')
153call ErrExe('call setreg(1, {})')
154call ErrExe('call setreg(1, 2, [])')
Bram Moolenaar7d647822014-04-05 21:28:56 +0200155call ErrExe('call setreg("/", ["1", "2"])')
156call ErrExe('call setreg("=", ["1", "2"])')
Bram Moolenaar5a50c222014-04-02 22:17:10 +0200157call ErrExe('call setreg(1, ["", "", [], ""])')
158endfun
Bram Moolenaarb7cb42b2014-04-02 19:55:10 +0200159:"
Bram Moolenaar5a50c222014-04-02 22:17:10 +0200160:call Test()
Bram Moolenaarb7cb42b2014-04-02 19:55:10 +0200161:"
Bram Moolenaar5a50c222014-04-02 22:17:10 +0200162:delfunction SetReg
163:delfunction AppendRegContents
164:delfunction ErrExe
165:delfunction Test
166:delcommand AR
167:call garbagecollect(1)
168:"
Bram Moolenaareccb7fc2014-04-23 20:43:41 +0200169:" function name not starting with capital
Bram Moolenaar9bdfb002014-04-23 17:43:42 +0200170:try
171:func! g:test()
172:echo "test"
173:endfunc
174:catch
175:$put =v:exception
176:endtry
177:"
Bram Moolenaareccb7fc2014-04-23 20:43:41 +0200178:" function name includes a colon
179:try
180:func! b:test()
181:echo "test"
182:endfunc
183:catch
184:$put =v:exception
185:endtry
186:"
Bram Moolenaar9bdfb002014-04-23 17:43:42 +0200187:" function name folowed by #
188:try
189:func! test2() "#
190:echo "test2"
191:endfunc
192:catch
193:$put =v:exception
194:endtry
195:"
Bram Moolenaareccb7fc2014-04-23 20:43:41 +0200196:" function name starting with/without "g:", buffer-local funcref.
Bram Moolenaara4f317d2014-04-24 17:12:33 +0200197:function! g:Foo(n)
198: $put ='called Foo(' . a:n . ')'
Bram Moolenaareccb7fc2014-04-23 20:43:41 +0200199:endfunction
200:let b:my_func = function('Foo')
Bram Moolenaara4f317d2014-04-24 17:12:33 +0200201:call b:my_func(1)
202:echo g:Foo(2)
203:echo Foo(3)
Bram Moolenaareccb7fc2014-04-23 20:43:41 +0200204:"
Bram Moolenaar355a95a2014-04-29 14:03:02 +0200205:" script-local function used in Funcref must exist.
206:so test_eval_func.vim
207:"
Bram Moolenaare512c8c2014-04-29 17:41:22 +0200208:" Using $ instead of '$' must give an error
209:try
210: call append($, 'foobar')
211:catch
212:$put =v:exception
213:endtry
214:"
Bram Moolenaar6f6c0f82014-05-28 20:31:42 +0200215:$put ='{{{1 getcurpos/setpos'
Bram Moolenaar493c1782014-05-28 14:34:46 +0200216/^012345678
Bram Moolenaar6f6c0f82014-05-28 20:31:42 +02002176l:let sp = getcurpos()
Bram Moolenaar493c1782014-05-28 14:34:46 +02002180:call setpos('.', sp)
219jyl:$put
220:"
Bram Moolenaar5a50c222014-04-02 22:17:10 +0200221:/^start:/+1,$wq! test.out
222:" vim: et ts=4 isk-=\: fmr=???,???
223:call getchar()
Bram Moolenaarb7cb42b2014-04-02 19:55:10 +0200224ENDTEST
225
Bram Moolenaar493c1782014-05-28 14:34:46 +0200226012345678
227012345678
228
Bram Moolenaar5a50c222014-04-02 22:17:10 +0200229start: