annotate src/testdir/test_partial.vim @ 8548:24db3583c496 v7.4.1564

commit https://github.com/vim/vim/commit/346418c624f1bc7c04c98907134a2b284e6452dd Author: Bram Moolenaar <Bram@vim.org> Date: Tue Mar 15 12:36:08 2016 +0100 patch 7.4.1564 Problem: An empty list in function() causes an error. Solution: Handle an empty list like there is no list of arguments.
author Christian Brabandt <cb@256bit.org>
date Tue, 15 Mar 2016 12:45:05 +0100
parents 996109e24f02
children b5209a4e5baf
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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"])
c337c813c64d commit https://github.com/vim/vim/commit/1735bc988c546cc962c5f94792815b4d7cb79710
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
19 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
20 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
21
8548
24db3583c496 commit https://github.com/vim/vim/commit/346418c624f1bc7c04c98907134a2b284e6452dd
Christian Brabandt <cb@256bit.org>
parents: 8546
diff changeset
22 let Cb = function('MyFunc', [])
24db3583c496 commit https://github.com/vim/vim/commit/346418c624f1bc7c04c98907134a2b284e6452dd
Christian Brabandt <cb@256bit.org>
parents: 8546
diff changeset
23 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
24
8538
c337c813c64d commit https://github.com/vim/vim/commit/1735bc988c546cc962c5f94792815b4d7cb79710
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
25 let Sort = function('MySort', [1])
c337c813c64d commit https://github.com/vim/vim/commit/1735bc988c546cc962c5f94792815b4d7cb79710
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
26 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
27 let Sort = function('MySort', [0])
c337c813c64d commit https://github.com/vim/vim/commit/1735bc988c546cc962c5f94792815b4d7cb79710
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
28 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
29 endfunc
c337c813c64d commit https://github.com/vim/vim/commit/1735bc988c546cc962c5f94792815b4d7cb79710
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
30
c337c813c64d commit https://github.com/vim/vim/commit/1735bc988c546cc962c5f94792815b4d7cb79710
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
31 func MyDictFunc(arg1, arg2) dict
c337c813c64d commit https://github.com/vim/vim/commit/1735bc988c546cc962c5f94792815b4d7cb79710
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
32 return self.name . '/' . a:arg1 . '/' . a:arg2
c337c813c64d commit https://github.com/vim/vim/commit/1735bc988c546cc962c5f94792815b4d7cb79710
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
33 endfunc
c337c813c64d commit https://github.com/vim/vim/commit/1735bc988c546cc962c5f94792815b4d7cb79710
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
34
c337c813c64d commit https://github.com/vim/vim/commit/1735bc988c546cc962c5f94792815b4d7cb79710
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
35 func Test_partial_dict()
c337c813c64d commit https://github.com/vim/vim/commit/1735bc988c546cc962c5f94792815b4d7cb79710
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
36 let dict = {'name': 'hello'}
c337c813c64d commit https://github.com/vim/vim/commit/1735bc988c546cc962c5f94792815b4d7cb79710
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
37 let Cb = function('MyDictFunc', ["foo", "bar"], dict)
c337c813c64d commit https://github.com/vim/vim/commit/1735bc988c546cc962c5f94792815b4d7cb79710
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
38 call assert_equal("hello/foo/bar", Cb())
c337c813c64d commit https://github.com/vim/vim/commit/1735bc988c546cc962c5f94792815b4d7cb79710
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
39 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
40
8538
c337c813c64d commit https://github.com/vim/vim/commit/1735bc988c546cc962c5f94792815b4d7cb79710
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
41 let Cb = function('MyDictFunc', ["foo"], dict)
c337c813c64d commit https://github.com/vim/vim/commit/1735bc988c546cc962c5f94792815b4d7cb79710
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
42 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
43 call assert_fails('Cb()', 'E492:')
8548
24db3583c496 commit https://github.com/vim/vim/commit/346418c624f1bc7c04c98907134a2b284e6452dd
Christian Brabandt <cb@256bit.org>
parents: 8546
diff changeset
44
24db3583c496 commit https://github.com/vim/vim/commit/346418c624f1bc7c04c98907134a2b284e6452dd
Christian Brabandt <cb@256bit.org>
parents: 8546
diff changeset
45 let Cb = function('MyDictFunc', [], dict)
24db3583c496 commit https://github.com/vim/vim/commit/346418c624f1bc7c04c98907134a2b284e6452dd
Christian Brabandt <cb@256bit.org>
parents: 8546
diff changeset
46 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
47 call assert_fails('Cb("yyy")', 'E492:')
24db3583c496 commit https://github.com/vim/vim/commit/346418c624f1bc7c04c98907134a2b284e6452dd
Christian Brabandt <cb@256bit.org>
parents: 8546
diff changeset
48
8538
c337c813c64d commit https://github.com/vim/vim/commit/1735bc988c546cc962c5f94792815b4d7cb79710
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
49 let Cb = function('MyDictFunc', dict)
c337c813c64d commit https://github.com/vim/vim/commit/1735bc988c546cc962c5f94792815b4d7cb79710
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
50 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
51 call assert_fails('Cb("fff")', 'E492:')
8538
c337c813c64d commit https://github.com/vim/vim/commit/1735bc988c546cc962c5f94792815b4d7cb79710
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
52 endfunc