Mercurial > vim
annotate src/testdir/test_partial.vim @ 8583:537bbbd4e987 v7.4.1581
commit https://github.com/vim/vim/commit/65639032bb7b17996cd255d1508a1df4ad528a1f
Author: Bram Moolenaar <Bram@vim.org>
Date: Wed Mar 16 21:40:30 2016 +0100
patch 7.4.1581
Problem: Using ":call dict.func()" where the function is a partial does
not work. Using "dict.func()" where the function does not take a
Dictionary does not work.
Solution: Handle partial properly in ":call". (Yasuhiro Matsumoto)
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Wed, 16 Mar 2016 21:45:04 +0100 |
parents | fd454847836d |
children | ce37bbedcb65 |
rev | line source |
---|---|
8538
c337c813c64d
commit https://github.com/vim/vim/commit/1735bc988c546cc962c5f94792815b4d7cb79710
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1 " Test binding arguments to a Funcref. |
c337c813c64d
commit https://github.com/vim/vim/commit/1735bc988c546cc962c5f94792815b4d7cb79710
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2 |
c337c813c64d
commit https://github.com/vim/vim/commit/1735bc988c546cc962c5f94792815b4d7cb79710
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3 func MyFunc(arg1, arg2, arg3) |
c337c813c64d
commit https://github.com/vim/vim/commit/1735bc988c546cc962c5f94792815b4d7cb79710
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4 return a:arg1 . '/' . a:arg2 . '/' . a:arg3 |
c337c813c64d
commit https://github.com/vim/vim/commit/1735bc988c546cc962c5f94792815b4d7cb79710
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5 endfunc |
c337c813c64d
commit https://github.com/vim/vim/commit/1735bc988c546cc962c5f94792815b4d7cb79710
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6 |
c337c813c64d
commit https://github.com/vim/vim/commit/1735bc988c546cc962c5f94792815b4d7cb79710
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
7 func MySort(up, one, two) |
c337c813c64d
commit https://github.com/vim/vim/commit/1735bc988c546cc962c5f94792815b4d7cb79710
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
8 if a:one == a:two |
c337c813c64d
commit https://github.com/vim/vim/commit/1735bc988c546cc962c5f94792815b4d7cb79710
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
9 return 0 |
c337c813c64d
commit https://github.com/vim/vim/commit/1735bc988c546cc962c5f94792815b4d7cb79710
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
10 endif |
c337c813c64d
commit https://github.com/vim/vim/commit/1735bc988c546cc962c5f94792815b4d7cb79710
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
11 if a:up |
8546
996109e24f02
commit https://github.com/vim/vim/commit/790500a8e65bee295ef51a59dfa67ecbaab8ea17
Christian Brabandt <cb@256bit.org>
parents:
8538
diff
changeset
|
12 return a:one > a:two ? 1 : -1 |
8538
c337c813c64d
commit https://github.com/vim/vim/commit/1735bc988c546cc962c5f94792815b4d7cb79710
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
13 endif |
8546
996109e24f02
commit https://github.com/vim/vim/commit/790500a8e65bee295ef51a59dfa67ecbaab8ea17
Christian Brabandt <cb@256bit.org>
parents:
8538
diff
changeset
|
14 return a:one < a:two ? 1 : -1 |
8538
c337c813c64d
commit https://github.com/vim/vim/commit/1735bc988c546cc962c5f94792815b4d7cb79710
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
15 endfunc |
c337c813c64d
commit https://github.com/vim/vim/commit/1735bc988c546cc962c5f94792815b4d7cb79710
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
16 |
c337c813c64d
commit https://github.com/vim/vim/commit/1735bc988c546cc962c5f94792815b4d7cb79710
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
17 func Test_partial_args() |
c337c813c64d
commit https://github.com/vim/vim/commit/1735bc988c546cc962c5f94792815b4d7cb79710
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
18 let Cb = function('MyFunc', ["foo", "bar"]) |
8583
537bbbd4e987
commit https://github.com/vim/vim/commit/65639032bb7b17996cd255d1508a1df4ad528a1f
Christian Brabandt <cb@256bit.org>
parents:
8581
diff
changeset
|
19 |
537bbbd4e987
commit https://github.com/vim/vim/commit/65639032bb7b17996cd255d1508a1df4ad528a1f
Christian Brabandt <cb@256bit.org>
parents:
8581
diff
changeset
|
20 call Cb("zzz") |
8538
c337c813c64d
commit https://github.com/vim/vim/commit/1735bc988c546cc962c5f94792815b4d7cb79710
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
21 call assert_equal("foo/bar/xxx", Cb("xxx")) |
c337c813c64d
commit https://github.com/vim/vim/commit/1735bc988c546cc962c5f94792815b4d7cb79710
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
22 call assert_equal("foo/bar/yyy", call(Cb, ["yyy"])) |
c337c813c64d
commit https://github.com/vim/vim/commit/1735bc988c546cc962c5f94792815b4d7cb79710
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
23 |
8548
24db3583c496
commit https://github.com/vim/vim/commit/346418c624f1bc7c04c98907134a2b284e6452dd
Christian Brabandt <cb@256bit.org>
parents:
8546
diff
changeset
|
24 let Cb = function('MyFunc', []) |
24db3583c496
commit https://github.com/vim/vim/commit/346418c624f1bc7c04c98907134a2b284e6452dd
Christian Brabandt <cb@256bit.org>
parents:
8546
diff
changeset
|
25 call assert_equal("a/b/c", Cb("a", "b", "c")) |
24db3583c496
commit https://github.com/vim/vim/commit/346418c624f1bc7c04c98907134a2b284e6452dd
Christian Brabandt <cb@256bit.org>
parents:
8546
diff
changeset
|
26 |
8538
c337c813c64d
commit https://github.com/vim/vim/commit/1735bc988c546cc962c5f94792815b4d7cb79710
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
27 let Sort = function('MySort', [1]) |
c337c813c64d
commit https://github.com/vim/vim/commit/1735bc988c546cc962c5f94792815b4d7cb79710
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
28 call assert_equal([1, 2, 3], sort([3, 1, 2], Sort)) |
c337c813c64d
commit https://github.com/vim/vim/commit/1735bc988c546cc962c5f94792815b4d7cb79710
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
29 let Sort = function('MySort', [0]) |
c337c813c64d
commit https://github.com/vim/vim/commit/1735bc988c546cc962c5f94792815b4d7cb79710
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
30 call assert_equal([3, 2, 1], sort([3, 1, 2], Sort)) |
c337c813c64d
commit https://github.com/vim/vim/commit/1735bc988c546cc962c5f94792815b4d7cb79710
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
31 endfunc |
c337c813c64d
commit https://github.com/vim/vim/commit/1735bc988c546cc962c5f94792815b4d7cb79710
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
32 |
c337c813c64d
commit https://github.com/vim/vim/commit/1735bc988c546cc962c5f94792815b4d7cb79710
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
33 func MyDictFunc(arg1, arg2) dict |
c337c813c64d
commit https://github.com/vim/vim/commit/1735bc988c546cc962c5f94792815b4d7cb79710
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
34 return self.name . '/' . a:arg1 . '/' . a:arg2 |
c337c813c64d
commit https://github.com/vim/vim/commit/1735bc988c546cc962c5f94792815b4d7cb79710
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
35 endfunc |
c337c813c64d
commit https://github.com/vim/vim/commit/1735bc988c546cc962c5f94792815b4d7cb79710
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
36 |
c337c813c64d
commit https://github.com/vim/vim/commit/1735bc988c546cc962c5f94792815b4d7cb79710
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
37 func Test_partial_dict() |
c337c813c64d
commit https://github.com/vim/vim/commit/1735bc988c546cc962c5f94792815b4d7cb79710
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
38 let dict = {'name': 'hello'} |
c337c813c64d
commit https://github.com/vim/vim/commit/1735bc988c546cc962c5f94792815b4d7cb79710
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
39 let Cb = function('MyDictFunc', ["foo", "bar"], dict) |
c337c813c64d
commit https://github.com/vim/vim/commit/1735bc988c546cc962c5f94792815b4d7cb79710
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
40 call assert_equal("hello/foo/bar", Cb()) |
c337c813c64d
commit https://github.com/vim/vim/commit/1735bc988c546cc962c5f94792815b4d7cb79710
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
41 call assert_fails('Cb("xxx")', 'E492:') |
8548
24db3583c496
commit https://github.com/vim/vim/commit/346418c624f1bc7c04c98907134a2b284e6452dd
Christian Brabandt <cb@256bit.org>
parents:
8546
diff
changeset
|
42 |
8538
c337c813c64d
commit https://github.com/vim/vim/commit/1735bc988c546cc962c5f94792815b4d7cb79710
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
43 let Cb = function('MyDictFunc', ["foo"], dict) |
c337c813c64d
commit https://github.com/vim/vim/commit/1735bc988c546cc962c5f94792815b4d7cb79710
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
44 call assert_equal("hello/foo/xxx", Cb("xxx")) |
c337c813c64d
commit https://github.com/vim/vim/commit/1735bc988c546cc962c5f94792815b4d7cb79710
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
45 call assert_fails('Cb()', 'E492:') |
8548
24db3583c496
commit https://github.com/vim/vim/commit/346418c624f1bc7c04c98907134a2b284e6452dd
Christian Brabandt <cb@256bit.org>
parents:
8546
diff
changeset
|
46 |
24db3583c496
commit https://github.com/vim/vim/commit/346418c624f1bc7c04c98907134a2b284e6452dd
Christian Brabandt <cb@256bit.org>
parents:
8546
diff
changeset
|
47 let Cb = function('MyDictFunc', [], dict) |
24db3583c496
commit https://github.com/vim/vim/commit/346418c624f1bc7c04c98907134a2b284e6452dd
Christian Brabandt <cb@256bit.org>
parents:
8546
diff
changeset
|
48 call assert_equal("hello/ttt/xxx", Cb("ttt", "xxx")) |
24db3583c496
commit https://github.com/vim/vim/commit/346418c624f1bc7c04c98907134a2b284e6452dd
Christian Brabandt <cb@256bit.org>
parents:
8546
diff
changeset
|
49 call assert_fails('Cb("yyy")', 'E492:') |
24db3583c496
commit https://github.com/vim/vim/commit/346418c624f1bc7c04c98907134a2b284e6452dd
Christian Brabandt <cb@256bit.org>
parents:
8546
diff
changeset
|
50 |
8538
c337c813c64d
commit https://github.com/vim/vim/commit/1735bc988c546cc962c5f94792815b4d7cb79710
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
51 let Cb = function('MyDictFunc', dict) |
c337c813c64d
commit https://github.com/vim/vim/commit/1735bc988c546cc962c5f94792815b4d7cb79710
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
52 call assert_equal("hello/xxx/yyy", Cb("xxx", "yyy")) |
8548
24db3583c496
commit https://github.com/vim/vim/commit/346418c624f1bc7c04c98907134a2b284e6452dd
Christian Brabandt <cb@256bit.org>
parents:
8546
diff
changeset
|
53 call assert_fails('Cb("fff")', 'E492:') |
8583
537bbbd4e987
commit https://github.com/vim/vim/commit/65639032bb7b17996cd255d1508a1df4ad528a1f
Christian Brabandt <cb@256bit.org>
parents:
8581
diff
changeset
|
54 |
537bbbd4e987
commit https://github.com/vim/vim/commit/65639032bb7b17996cd255d1508a1df4ad528a1f
Christian Brabandt <cb@256bit.org>
parents:
8581
diff
changeset
|
55 let dict = {"tr": function('tr', ['hello', 'h', 'H'])} |
537bbbd4e987
commit https://github.com/vim/vim/commit/65639032bb7b17996cd255d1508a1df4ad528a1f
Christian Brabandt <cb@256bit.org>
parents:
8581
diff
changeset
|
56 call assert_equal("Hello", dict.tr()) |
8538
c337c813c64d
commit https://github.com/vim/vim/commit/1735bc988c546cc962c5f94792815b4d7cb79710
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
57 endfunc |
8575
b5209a4e5baf
commit https://github.com/vim/vim/commit/ab1fa3955f25dfdb7e329c3bd76e175c93c8cb5e
Christian Brabandt <cb@256bit.org>
parents:
8548
diff
changeset
|
58 |
b5209a4e5baf
commit https://github.com/vim/vim/commit/ab1fa3955f25dfdb7e329c3bd76e175c93c8cb5e
Christian Brabandt <cb@256bit.org>
parents:
8548
diff
changeset
|
59 func Test_partial_implicit() |
b5209a4e5baf
commit https://github.com/vim/vim/commit/ab1fa3955f25dfdb7e329c3bd76e175c93c8cb5e
Christian Brabandt <cb@256bit.org>
parents:
8548
diff
changeset
|
60 let dict = {'name': 'foo'} |
b5209a4e5baf
commit https://github.com/vim/vim/commit/ab1fa3955f25dfdb7e329c3bd76e175c93c8cb5e
Christian Brabandt <cb@256bit.org>
parents:
8548
diff
changeset
|
61 func dict.MyFunc(arg) dict |
b5209a4e5baf
commit https://github.com/vim/vim/commit/ab1fa3955f25dfdb7e329c3bd76e175c93c8cb5e
Christian Brabandt <cb@256bit.org>
parents:
8548
diff
changeset
|
62 return self.name . '/' . a:arg |
b5209a4e5baf
commit https://github.com/vim/vim/commit/ab1fa3955f25dfdb7e329c3bd76e175c93c8cb5e
Christian Brabandt <cb@256bit.org>
parents:
8548
diff
changeset
|
63 endfunc |
b5209a4e5baf
commit https://github.com/vim/vim/commit/ab1fa3955f25dfdb7e329c3bd76e175c93c8cb5e
Christian Brabandt <cb@256bit.org>
parents:
8548
diff
changeset
|
64 |
b5209a4e5baf
commit https://github.com/vim/vim/commit/ab1fa3955f25dfdb7e329c3bd76e175c93c8cb5e
Christian Brabandt <cb@256bit.org>
parents:
8548
diff
changeset
|
65 call assert_equal('foo/bar', dict.MyFunc('bar')) |
b5209a4e5baf
commit https://github.com/vim/vim/commit/ab1fa3955f25dfdb7e329c3bd76e175c93c8cb5e
Christian Brabandt <cb@256bit.org>
parents:
8548
diff
changeset
|
66 |
b5209a4e5baf
commit https://github.com/vim/vim/commit/ab1fa3955f25dfdb7e329c3bd76e175c93c8cb5e
Christian Brabandt <cb@256bit.org>
parents:
8548
diff
changeset
|
67 call assert_fails('let func = dict.MyFunc', 'E704:') |
b5209a4e5baf
commit https://github.com/vim/vim/commit/ab1fa3955f25dfdb7e329c3bd76e175c93c8cb5e
Christian Brabandt <cb@256bit.org>
parents:
8548
diff
changeset
|
68 let Func = dict.MyFunc |
b5209a4e5baf
commit https://github.com/vim/vim/commit/ab1fa3955f25dfdb7e329c3bd76e175c93c8cb5e
Christian Brabandt <cb@256bit.org>
parents:
8548
diff
changeset
|
69 call assert_equal('foo/aaa', Func('aaa')) |
b5209a4e5baf
commit https://github.com/vim/vim/commit/ab1fa3955f25dfdb7e329c3bd76e175c93c8cb5e
Christian Brabandt <cb@256bit.org>
parents:
8548
diff
changeset
|
70 |
b5209a4e5baf
commit https://github.com/vim/vim/commit/ab1fa3955f25dfdb7e329c3bd76e175c93c8cb5e
Christian Brabandt <cb@256bit.org>
parents:
8548
diff
changeset
|
71 let Func = function(dict.MyFunc, ['bbb']) |
b5209a4e5baf
commit https://github.com/vim/vim/commit/ab1fa3955f25dfdb7e329c3bd76e175c93c8cb5e
Christian Brabandt <cb@256bit.org>
parents:
8548
diff
changeset
|
72 call assert_equal('foo/bbb', Func()) |
b5209a4e5baf
commit https://github.com/vim/vim/commit/ab1fa3955f25dfdb7e329c3bd76e175c93c8cb5e
Christian Brabandt <cb@256bit.org>
parents:
8548
diff
changeset
|
73 |
b5209a4e5baf
commit https://github.com/vim/vim/commit/ab1fa3955f25dfdb7e329c3bd76e175c93c8cb5e
Christian Brabandt <cb@256bit.org>
parents:
8548
diff
changeset
|
74 call assert_fails('call function(dict.MyFunc, ["bbb"], dict)', 'E924:') |
b5209a4e5baf
commit https://github.com/vim/vim/commit/ab1fa3955f25dfdb7e329c3bd76e175c93c8cb5e
Christian Brabandt <cb@256bit.org>
parents:
8548
diff
changeset
|
75 endfunc |
8581
fd454847836d
commit https://github.com/vim/vim/commit/7a5c46a9df7ef01a4f6a620861c35400d5ad28d9
Christian Brabandt <cb@256bit.org>
parents:
8575
diff
changeset
|
76 |
fd454847836d
commit https://github.com/vim/vim/commit/7a5c46a9df7ef01a4f6a620861c35400d5ad28d9
Christian Brabandt <cb@256bit.org>
parents:
8575
diff
changeset
|
77 fun InnerCall(funcref) |
fd454847836d
commit https://github.com/vim/vim/commit/7a5c46a9df7ef01a4f6a620861c35400d5ad28d9
Christian Brabandt <cb@256bit.org>
parents:
8575
diff
changeset
|
78 return a:funcref |
fd454847836d
commit https://github.com/vim/vim/commit/7a5c46a9df7ef01a4f6a620861c35400d5ad28d9
Christian Brabandt <cb@256bit.org>
parents:
8575
diff
changeset
|
79 endfu |
fd454847836d
commit https://github.com/vim/vim/commit/7a5c46a9df7ef01a4f6a620861c35400d5ad28d9
Christian Brabandt <cb@256bit.org>
parents:
8575
diff
changeset
|
80 |
fd454847836d
commit https://github.com/vim/vim/commit/7a5c46a9df7ef01a4f6a620861c35400d5ad28d9
Christian Brabandt <cb@256bit.org>
parents:
8575
diff
changeset
|
81 fun OuterCall() |
fd454847836d
commit https://github.com/vim/vim/commit/7a5c46a9df7ef01a4f6a620861c35400d5ad28d9
Christian Brabandt <cb@256bit.org>
parents:
8575
diff
changeset
|
82 let opt = { 'func' : function('sin') } |
fd454847836d
commit https://github.com/vim/vim/commit/7a5c46a9df7ef01a4f6a620861c35400d5ad28d9
Christian Brabandt <cb@256bit.org>
parents:
8575
diff
changeset
|
83 call InnerCall(opt.func) |
fd454847836d
commit https://github.com/vim/vim/commit/7a5c46a9df7ef01a4f6a620861c35400d5ad28d9
Christian Brabandt <cb@256bit.org>
parents:
8575
diff
changeset
|
84 endfu |
fd454847836d
commit https://github.com/vim/vim/commit/7a5c46a9df7ef01a4f6a620861c35400d5ad28d9
Christian Brabandt <cb@256bit.org>
parents:
8575
diff
changeset
|
85 |
fd454847836d
commit https://github.com/vim/vim/commit/7a5c46a9df7ef01a4f6a620861c35400d5ad28d9
Christian Brabandt <cb@256bit.org>
parents:
8575
diff
changeset
|
86 func Test_function_in_dict() |
fd454847836d
commit https://github.com/vim/vim/commit/7a5c46a9df7ef01a4f6a620861c35400d5ad28d9
Christian Brabandt <cb@256bit.org>
parents:
8575
diff
changeset
|
87 call OuterCall() |
fd454847836d
commit https://github.com/vim/vim/commit/7a5c46a9df7ef01a4f6a620861c35400d5ad28d9
Christian Brabandt <cb@256bit.org>
parents:
8575
diff
changeset
|
88 endfunc |
fd454847836d
commit https://github.com/vim/vim/commit/7a5c46a9df7ef01a4f6a620861c35400d5ad28d9
Christian Brabandt <cb@256bit.org>
parents:
8575
diff
changeset
|
89 |