856
|
1 Test for user functions.
|
|
2 Also test an <expr> mapping calling a function.
|
3687
|
3 Also test that a builtin function cannot be replaced.
|
7
|
4
|
|
5 STARTTEST
|
|
6 :so small.vim
|
|
7 :function Table(title, ...)
|
|
8 : let ret = a:title
|
|
9 : let idx = 1
|
|
10 : while idx <= a:0
|
|
11 : exe "let ret = ret . a:" . idx
|
|
12 : let idx = idx + 1
|
|
13 : endwhile
|
|
14 : return ret
|
|
15 :endfunction
|
|
16 :function Compute(n1, n2, divname)
|
|
17 : if a:n2 == 0
|
|
18 : return "fail"
|
|
19 : endif
|
|
20 : exe "let g:" . a:divname . " = ". a:n1 / a:n2
|
|
21 : return "ok"
|
|
22 :endfunction
|
856
|
23 :func Expr1()
|
|
24 : normal! v
|
|
25 : return "111"
|
|
26 :endfunc
|
|
27 :func Expr2()
|
|
28 : call search('XX', 'b')
|
|
29 : return "222"
|
|
30 :endfunc
|
|
31 :func ListItem()
|
|
32 : let g:counter += 1
|
|
33 : return g:counter . '. '
|
|
34 :endfunc
|
|
35 :func ListReset()
|
|
36 : let g:counter = 0
|
|
37 : return ''
|
|
38 :endfunc
|
2179
|
39 :func FuncWithRef(a)
|
|
40 : unlet g:FuncRef
|
|
41 : return a:a
|
|
42 :endfunc
|
|
43 :let g:FuncRef=function("FuncWithRef")
|
856
|
44 :let counter = 0
|
|
45 :inoremap <expr> ( ListItem()
|
|
46 :inoremap <expr> [ ListReset()
|
|
47 :imap <expr> + Expr1()
|
|
48 :imap <expr> * Expr2()
|
7
|
49 :let retval = "nop"
|
|
50 /^here
|
|
51 C=Table("xxx", 4, "asdf")
|
|
52 =Compute(45, 0, "retval")
|
|
53 =retval
|
|
54 =Compute(45, 5, "retval")
|
|
55 =retval
|
2179
|
56 =g:FuncRef(333)
|
856
|
57
|
|
58 XX+-XX
|
|
59 ---*---
|
|
60 (one
|
|
61 (two
|
3687
|
62 [(one again:call append(line('$'), max([1, 2, 3]))
|
|
63 :call extend(g:, {'max': function('min')})
|
|
64 :call append(line('$'), max([1, 2, 3]))
|
|
65 :$-7,$w! test.out
|
1405
|
66 :delfunc Table
|
|
67 :delfunc Compute
|
|
68 :delfunc Expr1
|
|
69 :delfunc Expr2
|
|
70 :delfunc ListItem
|
|
71 :delfunc ListReset
|
|
72 :unlet retval counter
|
|
73 :q!
|
7
|
74 ENDTEST
|
|
75
|
|
76 here
|