annotate src/testdir/test_user_func.vim @ 15432:b10ce9e77128 v8.1.0724

patch 8.1.0724: build for MinGW fails commit https://github.com/vim/vim/commit/46fd6bf2b6395f5850905525fa763803a14b093d Author: Bram Moolenaar <Bram@vim.org> Date: Fri Jan 11 19:19:44 2019 +0100 patch 8.1.0724: build for MinGW fails Problem: Build for MinGW fails. Solution: Avoid specifying dependencies in included makefile.
author Bram Moolenaar <Bram@vim.org>
date Fri, 11 Jan 2019 19:30:06 +0100
parents 15f0f9f16cd9
children 1a911bd57f11
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
12662
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1 " Test for user functions.
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2 " Also test an <expr> mapping calling a function.
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3 " Also test that a builtin function cannot be replaced.
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4 " Also test for regression when calling arbitrary expression.
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6 func Table(title, ...)
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
7 let ret = a:title
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
8 let idx = 1
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
9 while idx <= a:0
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
10 exe "let ret = ret . a:" . idx
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
11 let idx = idx + 1
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
12 endwhile
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
13 return ret
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
14 endfunc
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
15
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
16 func Compute(n1, n2, divname)
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
17 if a:n2 == 0
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
18 return "fail"
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
19 endif
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
20 exe "let g:" . a:divname . " = ". a:n1 / a:n2
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
21 return "ok"
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
22 endfunc
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
23
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
24 func Expr1()
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
25 silent! normal! v
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
26 return "111"
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
27 endfunc
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
28
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
29 func Expr2()
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
30 call search('XX', 'b')
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
31 return "222"
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
32 endfunc
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
33
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
34 func ListItem()
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
35 let g:counter += 1
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
36 return g:counter . '. '
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
37 endfunc
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
38
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
39 func ListReset()
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
40 let g:counter = 0
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
41 return ''
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
42 endfunc
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
43
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
44 func FuncWithRef(a)
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
45 unlet g:FuncRef
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
46 return a:a
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
47 endfunc
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
48
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
49 func Test_user_func()
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
50 let g:FuncRef=function("FuncWithRef")
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
51 let g:counter = 0
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
52 inoremap <expr> ( ListItem()
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
53 inoremap <expr> [ ListReset()
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
54 imap <expr> + Expr1()
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
55 imap <expr> * Expr2()
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
56 let g:retval = "nop"
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
57
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
58 call assert_equal('xxx4asdf', Table("xxx", 4, "asdf"))
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
59 call assert_equal('fail', Compute(45, 0, "retval"))
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
60 call assert_equal('nop', g:retval)
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
61 call assert_equal('ok', Compute(45, 5, "retval"))
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
62 call assert_equal(9, g:retval)
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
63 call assert_equal(333, g:FuncRef(333))
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
64
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
65 enew
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
66
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
67 normal oXX+-XX
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
68 call assert_equal('XX111-XX', getline('.'))
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
69 normal o---*---
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
70 call assert_equal('---222---', getline('.'))
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
71 normal o(one
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
72 call assert_equal('1. one', getline('.'))
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
73 normal o(two
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
74 call assert_equal('2. two', getline('.'))
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
75 normal o[(one again
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
76 call assert_equal('1. one again', getline('.'))
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
77
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
78 call assert_equal(3, max([1, 2, 3]))
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
79 call assert_fails("call extend(g:, {'max': function('min')})", 'E704')
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
80 call assert_equal(3, max([1, 2, 3]))
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
81
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
82 " Regression: the first line below used to throw ?E110: Missing ')'?
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
83 " Second is here just to prove that this line is correct when not skipping
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
84 " rhs of &&.
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
85 call assert_equal(0, (0 && (function('tr'))(1, 2, 3)))
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
86 call assert_equal(1, (1 && (function('tr'))(1, 2, 3)))
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
87
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
88 delfunc Table
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
89 delfunc Compute
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
90 delfunc Expr1
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
91 delfunc Expr2
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
92 delfunc ListItem
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
93 delfunc ListReset
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
94 unlet g:retval g:counter
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
95 enew!
15f0f9f16cd9 patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
96 endfunc