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.
|
5473
|
4 Also test for regression when calling arbitrary expression.
|
7
|
5
|
|
6 STARTTEST
|
|
7 :so small.vim
|
|
8 :function Table(title, ...)
|
|
9 : let ret = a:title
|
|
10 : let idx = 1
|
|
11 : while idx <= a:0
|
|
12 : exe "let ret = ret . a:" . idx
|
|
13 : let idx = idx + 1
|
|
14 : endwhile
|
|
15 : return ret
|
|
16 :endfunction
|
|
17 :function Compute(n1, n2, divname)
|
|
18 : if a:n2 == 0
|
|
19 : return "fail"
|
|
20 : endif
|
|
21 : exe "let g:" . a:divname . " = ". a:n1 / a:n2
|
|
22 : return "ok"
|
|
23 :endfunction
|
856
|
24 :func Expr1()
|
|
25 : normal! v
|
|
26 : return "111"
|
|
27 :endfunc
|
|
28 :func Expr2()
|
|
29 : call search('XX', 'b')
|
|
30 : return "222"
|
|
31 :endfunc
|
|
32 :func ListItem()
|
|
33 : let g:counter += 1
|
|
34 : return g:counter . '. '
|
|
35 :endfunc
|
|
36 :func ListReset()
|
|
37 : let g:counter = 0
|
|
38 : return ''
|
|
39 :endfunc
|
2179
|
40 :func FuncWithRef(a)
|
|
41 : unlet g:FuncRef
|
|
42 : return a:a
|
|
43 :endfunc
|
|
44 :let g:FuncRef=function("FuncWithRef")
|
856
|
45 :let counter = 0
|
|
46 :inoremap <expr> ( ListItem()
|
|
47 :inoremap <expr> [ ListReset()
|
|
48 :imap <expr> + Expr1()
|
|
49 :imap <expr> * Expr2()
|
7
|
50 :let retval = "nop"
|
|
51 /^here
|
|
52 C=Table("xxx", 4, "asdf")
|
|
53 =Compute(45, 0, "retval")
|
|
54 =retval
|
|
55 =Compute(45, 5, "retval")
|
|
56 =retval
|
2179
|
57 =g:FuncRef(333)
|
856
|
58
|
|
59 XX+-XX
|
|
60 ---*---
|
|
61 (one
|
|
62 (two
|
3687
|
63 [(one again:call append(line('$'), max([1, 2, 3]))
|
|
64 :call extend(g:, {'max': function('min')})
|
|
65 :call append(line('$'), max([1, 2, 3]))
|
5473
|
66 :try
|
|
67 : " Regression: the first line below used to throw ?E110: Missing ')'?
|
|
68 : " Second is here just to prove that this line is correct when not skipping
|
|
69 : " rhs of &&.
|
|
70 : $put =(0&&(function('tr'))(1, 2, 3))
|
|
71 : $put =(1&&(function('tr'))(1, 2, 3))
|
|
72 :catch
|
|
73 : $put ='!!! Unexpected exception:'
|
|
74 : $put =v:exception
|
|
75 :endtry
|
|
76 :$-9,$w! test.out
|
1405
|
77 :delfunc Table
|
|
78 :delfunc Compute
|
|
79 :delfunc Expr1
|
|
80 :delfunc Expr2
|
|
81 :delfunc ListItem
|
|
82 :delfunc ListReset
|
|
83 :unlet retval counter
|
|
84 :q!
|
7
|
85 ENDTEST
|
|
86
|
|
87 here
|