1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
|
Test for various eval features. vim: set ft=vim :
Note: system clipboard support is not tested. I do not think anybody will thank
me for messing with clipboard.
STARTTEST
:so small.vim
:set encoding=latin1
:set noswapfile
:lang C
:fun AppendRegContents(reg)
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))))
endfun
:command -nargs=? AR :call AppendRegContents(<q-args>)
:fun SetReg(...)
call call('setreg', a:000)
call append('$', printf('{{{2 setreg(%s)', string(a:000)[1:-2]))
call AppendRegContents(a:1)
if a:1 isnot# '='
execute "silent normal! Go==\n==\e\"".a:1."P"
endif
endfun
:fun ErrExe(str)
call append('$', 'Executing '.a:str)
try
execute a:str
catch
$put =v:exception
endtry
endfun
:fun Test()
$put ='{{{1 let tests'
let @" = 'abc'
AR "
let @" = "abc\n"
AR "
let @" = "abc\<C-m>"
AR "
let @= = '"abc"'
AR =
$put ='{{{1 Basic setreg tests'
call SetReg('a', 'abcA', 'c')
call SetReg('b', 'abcB', 'v')
call SetReg('c', 'abcC', 'l')
call SetReg('d', 'abcD', 'V')
call SetReg('e', 'abcE', 'b')
call SetReg('f', 'abcF', "\<C-v>")
call SetReg('g', 'abcG', 'b10')
call SetReg('h', 'abcH', "\<C-v>10")
call SetReg('I', 'abcI')
$put ='{{{1 Appending single lines with setreg()'
call SetReg('A', 'abcAc', 'c')
call SetReg('A', 'abcAl', 'l')
call SetReg('A', 'abcAc2','c')
call SetReg('b', 'abcBc', 'ca')
call SetReg('b', 'abcBb', 'ba')
call SetReg('b', 'abcBc2','ca')
call SetReg('b', 'abcBb2','b50a')
call SetReg('C', 'abcCl', 'l')
call SetReg('C', 'abcCc', 'c')
call SetReg('D', 'abcDb', 'b')
call SetReg('E', 'abcEb', 'b')
call SetReg('E', 'abcEl', 'l')
call SetReg('F', 'abcFc', 'c')
$put ='{{{1 Appending NL with setreg()'
call setreg('a', 'abcA2', 'c')
call setreg('b', 'abcB2', 'v')
call setreg('c', 'abcC2', 'l')
call setreg('d', 'abcD2', 'V')
call setreg('e', 'abcE2', 'b')
call setreg('f', 'abcF2', "\<C-v>")
call setreg('g', 'abcG2', 'b10')
call setreg('h', 'abcH2', "\<C-v>10")
call setreg('I', 'abcI2')
call SetReg('A', "\n")
call SetReg('B', "\n", 'c')
call SetReg('C', "\n")
call SetReg('D', "\n", 'l')
call SetReg('E', "\n")
call SetReg('F', "\n", 'b')
$put ='{{{1 Setting lists with setreg()'
call SetReg('a', ['abcA3'], 'c')
call SetReg('b', ['abcB3'], 'l')
call SetReg('c', ['abcC3'], 'b')
call SetReg('d', ['abcD3'])
call SetReg('e', [1, 2, 'abc', 3])
call SetReg('f', [1, 2, 3])
$put ='{{{1 Appending lists with setreg()'
call SetReg('A', ['abcA3c'], 'c')
call SetReg('b', ['abcB3l'], 'la')
call SetReg('C', ['abcC3b'], 'lb')
call SetReg('D', ['abcD32'])
call SetReg('A', ['abcA32'])
call SetReg('B', ['abcB3c'], 'c')
call SetReg('C', ['abcC3l'], 'l')
call SetReg('D', ['abcD3b'], 'b')
$put ='{{{1 Appending lists with NL with setreg()'
call SetReg('A', ["\n", 'abcA3l2'], 'l')
call SetReg('B', ["\n", 'abcB3c2'], 'c')
call SetReg('C', ["\n", 'abcC3b2'], 'b')
call SetReg('D', ["\n", 'abcD3b50'],'b50')
$put ='{{{1 Setting lists with NLs with setreg()'
call SetReg('a', ['abcA4-0', "\n", "abcA4-2\n", "\nabcA4-3", "abcA4-4\nabcA4-4-2"])
call SetReg('b', ['abcB4c-0', "\n", "abcB4c-2\n", "\nabcB4c-3", "abcB4c-4\nabcB4c-4-2"], 'c')
call SetReg('c', ['abcC4l-0', "\n", "abcC4l-2\n", "\nabcC4l-3", "abcC4l-4\nabcC4l-4-2"], 'l')
call SetReg('d', ['abcD4b-0', "\n", "abcD4b-2\n", "\nabcD4b-3", "abcD4b-4\nabcD4b-4-2"], 'b')
call SetReg('e', ['abcE4b10-0', "\n", "abcE4b10-2\n", "\nabcE4b10-3", "abcE4b10-4\nabcE4b10-4-2"], 'b10')
$put ='{{{1 Search and expressions'
call SetReg('/', ['abc/'])
call SetReg('/', ["abc/\n"])
call SetReg('=', ['"abc/"'])
call SetReg('=', ["\"abc/\n\""])
$put ='{{{1 Errors'
call ErrExe('call setreg()')
call ErrExe('call setreg(1)')
call ErrExe('call setreg(1, 2, 3, 4)')
call ErrExe('call setreg([], 2)')
call ErrExe('call setreg(1, {})')
call ErrExe('call setreg(1, 2, [])')
call ErrExe('call setreg("/", ["1", "2"])')
call ErrExe('call setreg("=", ["1", "2"])')
call ErrExe('call setreg(1, ["", "", [], ""])')
endfun
:"
:call Test()
:"
:delfunction SetReg
:delfunction AppendRegContents
:delfunction ErrExe
:delfunction Test
:delcommand AR
:call garbagecollect(1)
:"
:" function name not starting with capital
:try
:func! g:test()
:echo "test"
:endfunc
:catch
:$put =v:exception
:endtry
:"
:" function name includes a colon
:try
:func! b:test()
:echo "test"
:endfunc
:catch
:$put =v:exception
:endtry
:"
:" function name folowed by #
:try
:func! test2() "#
:echo "test2"
:endfunc
:catch
:$put =v:exception
:endtry
:"
:" function name starting with/without "g:", buffer-local funcref.
:function! g:Foo(n)
: $put ='called Foo(' . a:n . ')'
:endfunction
:let b:my_func = function('Foo')
:call b:my_func(1)
:echo g:Foo(2)
:echo Foo(3)
:"
:" script-local function used in Funcref must exist.
:so test_eval_func.vim
:"
:" Using $ instead of '$' must give an error
:try
: call append($, 'foobar')
:catch
:$put =v:exception
:endtry
:"
:$put ='{{{1 getcurpos/setpos'
/^012345678
6l:let sp = getcurpos()
0:call setpos('.', sp)
jyl:$put
:"
:/^start:/+1,$wq! test.out
:" vim: et ts=4 isk-=\: fmr=???,???
:call getchar()
ENDTEST
012345678
012345678
start:
|