Mercurial > vim
annotate src/testdir/test_user_func.vim @ 18983:54baf548bff9 v8.2.0052
patch 8.2.0052: more-prompt not properly tested
Commit: https://github.com/vim/vim/commit/c6d539b67181ad573452e919e58ecbfa362f4c49
Author: Bram Moolenaar <Bram@vim.org>
Date: Sat Dec 28 17:10:46 2019 +0100
patch 8.2.0052: more-prompt not properly tested
Problem: More-prompt not properly tested.
Solution: Add a test case. (Dominique Pelle, closes https://github.com/vim/vim/issues/5404)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sat, 28 Dec 2019 17:15:04 +0100 |
parents | 9ffec4eb8d33 |
children | 2a017e9dc6da |
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() |
17638
9ffec4eb8d33
patch 8.1.1816: cannot use a user defined function as a method
Bram Moolenaar <Bram@vim.org>
parents:
16615
diff
changeset
|
50 let g:FuncRef = function("FuncWithRef") |
12662
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 |
17638
9ffec4eb8d33
patch 8.1.1816: cannot use a user defined function as a method
Bram Moolenaar <Bram@vim.org>
parents:
16615
diff
changeset
|
65 let g:retval = "nop" |
9ffec4eb8d33
patch 8.1.1816: cannot use a user defined function as a method
Bram Moolenaar <Bram@vim.org>
parents:
16615
diff
changeset
|
66 call assert_equal('xxx4asdf', "xxx"->Table(4, "asdf")) |
9ffec4eb8d33
patch 8.1.1816: cannot use a user defined function as a method
Bram Moolenaar <Bram@vim.org>
parents:
16615
diff
changeset
|
67 call assert_equal('fail', 45->Compute(0, "retval")) |
9ffec4eb8d33
patch 8.1.1816: cannot use a user defined function as a method
Bram Moolenaar <Bram@vim.org>
parents:
16615
diff
changeset
|
68 call assert_equal('nop', g:retval) |
9ffec4eb8d33
patch 8.1.1816: cannot use a user defined function as a method
Bram Moolenaar <Bram@vim.org>
parents:
16615
diff
changeset
|
69 call assert_equal('ok', 45->Compute(5, "retval")) |
9ffec4eb8d33
patch 8.1.1816: cannot use a user defined function as a method
Bram Moolenaar <Bram@vim.org>
parents:
16615
diff
changeset
|
70 call assert_equal(9, g:retval) |
9ffec4eb8d33
patch 8.1.1816: cannot use a user defined function as a method
Bram Moolenaar <Bram@vim.org>
parents:
16615
diff
changeset
|
71 " call assert_equal(333, 333->g:FuncRef()) |
9ffec4eb8d33
patch 8.1.1816: cannot use a user defined function as a method
Bram Moolenaar <Bram@vim.org>
parents:
16615
diff
changeset
|
72 |
12662
15f0f9f16cd9
patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
73 enew |
15f0f9f16cd9
patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
74 |
15f0f9f16cd9
patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
75 normal oXX+-XX |
15f0f9f16cd9
patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
76 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
|
77 normal o---*--- |
15f0f9f16cd9
patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
78 call assert_equal('---222---', getline('.')) |
15f0f9f16cd9
patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
79 normal o(one |
15f0f9f16cd9
patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
80 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
|
81 normal o(two |
15f0f9f16cd9
patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
82 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
|
83 normal o[(one again |
15f0f9f16cd9
patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
84 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
|
85 |
15f0f9f16cd9
patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
86 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
|
87 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
|
88 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
|
89 |
15f0f9f16cd9
patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
90 " 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
|
91 " 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
|
92 " rhs of &&. |
15f0f9f16cd9
patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
93 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
|
94 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
|
95 |
15f0f9f16cd9
patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
96 delfunc Table |
15f0f9f16cd9
patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
97 delfunc Compute |
15f0f9f16cd9
patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
98 delfunc Expr1 |
15f0f9f16cd9
patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
99 delfunc Expr2 |
15f0f9f16cd9
patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
100 delfunc ListItem |
15f0f9f16cd9
patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
101 delfunc ListReset |
15f0f9f16cd9
patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
102 unlet g:retval g:counter |
15f0f9f16cd9
patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
103 enew! |
15f0f9f16cd9
patch 8.0.1209: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
104 endfunc |
16615
1a911bd57f11
patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents:
12662
diff
changeset
|
105 |
1a911bd57f11
patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents:
12662
diff
changeset
|
106 func Log(val, base = 10) |
1a911bd57f11
patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents:
12662
diff
changeset
|
107 return log(a:val) / log(a:base) |
1a911bd57f11
patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents:
12662
diff
changeset
|
108 endfunc |
1a911bd57f11
patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents:
12662
diff
changeset
|
109 |
1a911bd57f11
patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents:
12662
diff
changeset
|
110 func Args(mandatory, optional = v:null, ...) |
1a911bd57f11
patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents:
12662
diff
changeset
|
111 return deepcopy(a:) |
1a911bd57f11
patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents:
12662
diff
changeset
|
112 endfunc |
1a911bd57f11
patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents:
12662
diff
changeset
|
113 |
1a911bd57f11
patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents:
12662
diff
changeset
|
114 func Args2(a = 1, b = 2, c = 3) |
1a911bd57f11
patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents:
12662
diff
changeset
|
115 return deepcopy(a:) |
1a911bd57f11
patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents:
12662
diff
changeset
|
116 endfunc |
1a911bd57f11
patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents:
12662
diff
changeset
|
117 |
1a911bd57f11
patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents:
12662
diff
changeset
|
118 func MakeBadFunc() |
1a911bd57f11
patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents:
12662
diff
changeset
|
119 func s:fcn(a, b=1, c) |
1a911bd57f11
patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents:
12662
diff
changeset
|
120 endfunc |
1a911bd57f11
patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents:
12662
diff
changeset
|
121 endfunc |
1a911bd57f11
patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents:
12662
diff
changeset
|
122 |
1a911bd57f11
patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents:
12662
diff
changeset
|
123 func Test_default_arg() |
1a911bd57f11
patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents:
12662
diff
changeset
|
124 call assert_equal(1.0, Log(10)) |
1a911bd57f11
patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents:
12662
diff
changeset
|
125 call assert_equal(log(10), Log(10, exp(1))) |
1a911bd57f11
patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents:
12662
diff
changeset
|
126 call assert_fails("call Log(1,2,3)", 'E118') |
1a911bd57f11
patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents:
12662
diff
changeset
|
127 |
1a911bd57f11
patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents:
12662
diff
changeset
|
128 let res = Args(1) |
1a911bd57f11
patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents:
12662
diff
changeset
|
129 call assert_equal(res.mandatory, 1) |
1a911bd57f11
patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents:
12662
diff
changeset
|
130 call assert_equal(res.optional, v:null) |
1a911bd57f11
patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents:
12662
diff
changeset
|
131 call assert_equal(res['0'], 0) |
1a911bd57f11
patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents:
12662
diff
changeset
|
132 |
1a911bd57f11
patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents:
12662
diff
changeset
|
133 let res = Args(1,2) |
1a911bd57f11
patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents:
12662
diff
changeset
|
134 call assert_equal(res.mandatory, 1) |
1a911bd57f11
patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents:
12662
diff
changeset
|
135 call assert_equal(res.optional, 2) |
1a911bd57f11
patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents:
12662
diff
changeset
|
136 call assert_equal(res['0'], 0) |
1a911bd57f11
patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents:
12662
diff
changeset
|
137 |
1a911bd57f11
patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents:
12662
diff
changeset
|
138 let res = Args(1,2,3) |
1a911bd57f11
patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents:
12662
diff
changeset
|
139 call assert_equal(res.mandatory, 1) |
1a911bd57f11
patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents:
12662
diff
changeset
|
140 call assert_equal(res.optional, 2) |
1a911bd57f11
patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents:
12662
diff
changeset
|
141 call assert_equal(res['0'], 1) |
1a911bd57f11
patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents:
12662
diff
changeset
|
142 |
1a911bd57f11
patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents:
12662
diff
changeset
|
143 call assert_fails("call MakeBadFunc()", 'E989') |
1a911bd57f11
patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents:
12662
diff
changeset
|
144 call assert_fails("fu F(a=1 ,) | endf", 'E475') |
1a911bd57f11
patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents:
12662
diff
changeset
|
145 |
1a911bd57f11
patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents:
12662
diff
changeset
|
146 let d = Args2(7, v:none, 9) |
1a911bd57f11
patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents:
12662
diff
changeset
|
147 call assert_equal([7, 2, 9], [d.a, d.b, d.c]) |
1a911bd57f11
patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents:
12662
diff
changeset
|
148 |
1a911bd57f11
patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents:
12662
diff
changeset
|
149 call assert_equal("\n" |
1a911bd57f11
patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents:
12662
diff
changeset
|
150 \ .. " function Args2(a = 1, b = 2, c = 3)\n" |
1a911bd57f11
patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents:
12662
diff
changeset
|
151 \ .. "1 return deepcopy(a:)\n" |
1a911bd57f11
patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents:
12662
diff
changeset
|
152 \ .. " endfunction", |
1a911bd57f11
patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents:
12662
diff
changeset
|
153 \ execute('func Args2')) |
1a911bd57f11
patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents:
12662
diff
changeset
|
154 endfunc |
17638
9ffec4eb8d33
patch 8.1.1816: cannot use a user defined function as a method
Bram Moolenaar <Bram@vim.org>
parents:
16615
diff
changeset
|
155 |
9ffec4eb8d33
patch 8.1.1816: cannot use a user defined function as a method
Bram Moolenaar <Bram@vim.org>
parents:
16615
diff
changeset
|
156 func s:addFoo(lead) |
9ffec4eb8d33
patch 8.1.1816: cannot use a user defined function as a method
Bram Moolenaar <Bram@vim.org>
parents:
16615
diff
changeset
|
157 return a:lead .. 'foo' |
9ffec4eb8d33
patch 8.1.1816: cannot use a user defined function as a method
Bram Moolenaar <Bram@vim.org>
parents:
16615
diff
changeset
|
158 endfunc |
9ffec4eb8d33
patch 8.1.1816: cannot use a user defined function as a method
Bram Moolenaar <Bram@vim.org>
parents:
16615
diff
changeset
|
159 |
9ffec4eb8d33
patch 8.1.1816: cannot use a user defined function as a method
Bram Moolenaar <Bram@vim.org>
parents:
16615
diff
changeset
|
160 func Test_user_method() |
9ffec4eb8d33
patch 8.1.1816: cannot use a user defined function as a method
Bram Moolenaar <Bram@vim.org>
parents:
16615
diff
changeset
|
161 eval 'bar'->s:addFoo()->assert_equal('barfoo') |
9ffec4eb8d33
patch 8.1.1816: cannot use a user defined function as a method
Bram Moolenaar <Bram@vim.org>
parents:
16615
diff
changeset
|
162 endfunc |