blob: 11bc7e8e676f39e815119bc6e67f03b7239f9872 [file] [log] [blame]
Bram Moolenaar5a50c222014-04-02 22:17:10 +02001Test for various eval features. vim: set ft=vim :
2
3Note: system clipboard support is not tested. I do not think anybody will thank
4me for messing with clipboard.
Bram Moolenaarb7cb42b2014-04-02 19:55:10 +02005
6STARTTEST
7:so small.vim
Bram Moolenaar5a50c222014-04-02 22:17:10 +02008: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))))
13endfun
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
22endfun
23:fun ErrExe(str)
24 call append('$', 'Executing '.a:str)
25 try
26 execute a:str
27 catch
28 $put =v:exception
29 endtry
30endfun
31:fun Test()
32$put ='{{{1 let tests'
33let @" = 'abc'
34AR "
35let @" = "abc\n"
36AR "
37let @" = "abc\<C-m>"
38AR "
39let @= = '"abc"'
40AR =
41
42$put ='{{{1 Basic setreg tests'
43call SetReg('a', 'abcA', 'c')
44call SetReg('b', 'abcB', 'v')
45call SetReg('c', 'abcC', 'l')
46call SetReg('d', 'abcD', 'V')
47call SetReg('e', 'abcE', 'b')
48call SetReg('f', 'abcF', "\<C-v>")
49call SetReg('g', 'abcG', 'b10')
50call SetReg('h', 'abcH', "\<C-v>10")
51call SetReg('I', 'abcI')
52
53$put ='{{{1 Appending single lines with setreg()'
54call SetReg('A', 'abcAc', 'c')
55call SetReg('A', 'abcAl', 'l')
56call SetReg('A', 'abcAc2','c')
57call SetReg('b', 'abcBc', 'ca')
58call SetReg('b', 'abcBb', 'ba')
59call SetReg('b', 'abcBc2','ca')
60call SetReg('b', 'abcBb2','b50a')
61
62call SetReg('C', 'abcCl', 'l')
63call SetReg('C', 'abcCc', 'c')
64call SetReg('D', 'abcDb', 'b')
65
66call SetReg('E', 'abcEb', 'b')
67call SetReg('E', 'abcEl', 'l')
68call SetReg('F', 'abcFc', 'c')
69
70$put ='{{{1 Appending NL with setreg()'
71call setreg('a', 'abcA2', 'c')
72call setreg('b', 'abcB2', 'v')
73call setreg('c', 'abcC2', 'l')
74call setreg('d', 'abcD2', 'V')
75call setreg('e', 'abcE2', 'b')
76call setreg('f', 'abcF2', "\<C-v>")
77call setreg('g', 'abcG2', 'b10')
78call setreg('h', 'abcH2', "\<C-v>10")
79call setreg('I', 'abcI2')
80
81call SetReg('A', "\n")
82call SetReg('B', "\n", 'c')
83call SetReg('C', "\n")
84call SetReg('D', "\n", 'l')
85call SetReg('E', "\n")
86call SetReg('F', "\n", 'b')
87
88$put ='{{{1 Setting lists with setreg()'
89call SetReg('a', ['abcA3'], 'c')
90call SetReg('b', ['abcB3'], 'l')
91call SetReg('c', ['abcC3'], 'b')
92call SetReg('d', ['abcD3'])
Bram Moolenaar7d647822014-04-05 21:28:56 +020093call SetReg('e', [1, 2, 'abc', 3])
94call SetReg('f', [1, 2, 3])
Bram Moolenaar5a50c222014-04-02 22:17:10 +020095
96$put ='{{{1 Appending lists with setreg()'
97call SetReg('A', ['abcA3c'], 'c')
98call SetReg('b', ['abcB3l'], 'la')
99call SetReg('C', ['abcC3b'], 'lb')
100call SetReg('D', ['abcD32'])
101
102call SetReg('A', ['abcA32'])
103call SetReg('B', ['abcB3c'], 'c')
104call SetReg('C', ['abcC3l'], 'l')
105call SetReg('D', ['abcD3b'], 'b')
106
107$put ='{{{1 Appending lists with NL with setreg()'
108call SetReg('A', ["\n", 'abcA3l2'], 'l')
109call SetReg('B', ["\n", 'abcB3c2'], 'c')
110call SetReg('C', ["\n", 'abcC3b2'], 'b')
111call SetReg('D', ["\n", 'abcD3b50'],'b50')
112
113$put ='{{{1 Setting lists with NLs with setreg()'
114call SetReg('a', ['abcA4-0', "\n", "abcA4-2\n", "\nabcA4-3", "abcA4-4\nabcA4-4-2"])
115call SetReg('b', ['abcB4c-0', "\n", "abcB4c-2\n", "\nabcB4c-3", "abcB4c-4\nabcB4c-4-2"], 'c')
116call SetReg('c', ['abcC4l-0', "\n", "abcC4l-2\n", "\nabcC4l-3", "abcC4l-4\nabcC4l-4-2"], 'l')
117call SetReg('d', ['abcD4b-0', "\n", "abcD4b-2\n", "\nabcD4b-3", "abcD4b-4\nabcD4b-4-2"], 'b')
118call SetReg('e', ['abcE4b10-0', "\n", "abcE4b10-2\n", "\nabcE4b10-3", "abcE4b10-4\nabcE4b10-4-2"], 'b10')
119
120$put ='{{{1 Search and expressions'
121call SetReg('/', ['abc/'])
122call SetReg('/', ["abc/\n"])
123call SetReg('=', ['"abc/"'])
124call SetReg('=', ["\"abc/\n\""])
125
126$put ='{{{1 Errors'
127call ErrExe('call setreg()')
128call ErrExe('call setreg(1)')
129call ErrExe('call setreg(1, 2, 3, 4)')
130call ErrExe('call setreg([], 2)')
131call ErrExe('call setreg(1, {})')
132call ErrExe('call setreg(1, 2, [])')
Bram Moolenaar7d647822014-04-05 21:28:56 +0200133call ErrExe('call setreg("/", ["1", "2"])')
134call ErrExe('call setreg("=", ["1", "2"])')
Bram Moolenaar5a50c222014-04-02 22:17:10 +0200135call ErrExe('call setreg(1, ["", "", [], ""])')
136endfun
Bram Moolenaarb7cb42b2014-04-02 19:55:10 +0200137:"
Bram Moolenaar5a50c222014-04-02 22:17:10 +0200138:call Test()
Bram Moolenaarb7cb42b2014-04-02 19:55:10 +0200139:"
Bram Moolenaar5a50c222014-04-02 22:17:10 +0200140:delfunction SetReg
141:delfunction AppendRegContents
142:delfunction ErrExe
143:delfunction Test
144:delcommand AR
145:call garbagecollect(1)
146:"
Bram Moolenaareccb7fc2014-04-23 20:43:41 +0200147:" function name not starting with capital
Bram Moolenaar9bdfb002014-04-23 17:43:42 +0200148:try
149:func! g:test()
150:echo "test"
151:endfunc
152:catch
153:$put =v:exception
154:endtry
155:"
Bram Moolenaareccb7fc2014-04-23 20:43:41 +0200156:" function name includes a colon
157:try
158:func! b:test()
159:echo "test"
160:endfunc
161:catch
162:$put =v:exception
163:endtry
164:"
Bram Moolenaar9bdfb002014-04-23 17:43:42 +0200165:" function name folowed by #
166:try
167:func! test2() "#
168:echo "test2"
169:endfunc
170:catch
171:$put =v:exception
172:endtry
173:"
Bram Moolenaareccb7fc2014-04-23 20:43:41 +0200174:" function name starting with/without "g:", buffer-local funcref.
Bram Moolenaara4f317d2014-04-24 17:12:33 +0200175:function! g:Foo(n)
176: $put ='called Foo(' . a:n . ')'
Bram Moolenaareccb7fc2014-04-23 20:43:41 +0200177:endfunction
178:let b:my_func = function('Foo')
Bram Moolenaara4f317d2014-04-24 17:12:33 +0200179:call b:my_func(1)
180:echo g:Foo(2)
181:echo Foo(3)
Bram Moolenaareccb7fc2014-04-23 20:43:41 +0200182:"
Bram Moolenaar355a95a2014-04-29 14:03:02 +0200183:" script-local function used in Funcref must exist.
184:so test_eval_func.vim
185:"
Bram Moolenaare512c8c2014-04-29 17:41:22 +0200186:" Using $ instead of '$' must give an error
187:try
188: call append($, 'foobar')
189:catch
190:$put =v:exception
191:endtry
192:"
Bram Moolenaar5a50c222014-04-02 22:17:10 +0200193:/^start:/+1,$wq! test.out
194:" vim: et ts=4 isk-=\: fmr=???,???
195:call getchar()
Bram Moolenaarb7cb42b2014-04-02 19:55:10 +0200196ENDTEST
197
Bram Moolenaar5a50c222014-04-02 22:17:10 +0200198start: