From 521e45f2a8c0619335288accdda0f0aaa1fc6513 Mon Sep 17 00:00:00 2001 From: Michael Ennen Date: Mon, 24 Oct 2016 23:53:07 -0700 Subject: vim-patch:7.4.1559 Problem: Passing cookie to a callback is clumsy. Solution: Change function() to take arguments and return a partial. https://github.com/vim/vim/commit/1735bc988c546cc962c5f94792815b4d7cb79710 --- src/nvim/testdir/test_alot.vim | 1 + src/nvim/testdir/test_partial.vim | 43 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 src/nvim/testdir/test_partial.vim (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_alot.vim b/src/nvim/testdir/test_alot.vim index c79d9380d4..5da122c45d 100644 --- a/src/nvim/testdir/test_alot.vim +++ b/src/nvim/testdir/test_alot.vim @@ -14,6 +14,7 @@ source test_matchadd_conceal_utf8.vim source test_menu.vim source test_messages.vim source test_options.vim +source test_partial.vim source test_popup.vim source test_regexp_utf8.vim source test_statusline.vim diff --git a/src/nvim/testdir/test_partial.vim b/src/nvim/testdir/test_partial.vim new file mode 100644 index 0000000000..061f839668 --- /dev/null +++ b/src/nvim/testdir/test_partial.vim @@ -0,0 +1,43 @@ +" Test binding arguments to a Funcref. + +func MyFunc(arg1, arg2, arg3) + return a:arg1 . '/' . a:arg2 . '/' . a:arg3 +endfunc + +func MySort(up, one, two) + if a:one == a:two + return 0 + endif + if a:up + return a:one > a:two + endif + return a:one < a:two +endfunc + +func Test_partial_args() + let Cb = function('MyFunc', ["foo", "bar"]) + call assert_equal("foo/bar/xxx", Cb("xxx")) + call assert_equal("foo/bar/yyy", call(Cb, ["yyy"])) + + let Sort = function('MySort', [1]) + call assert_equal([1, 2, 3], sort([3, 1, 2], Sort)) + let Sort = function('MySort', [0]) + call assert_equal([3, 2, 1], sort([3, 1, 2], Sort)) +endfunc + +func MyDictFunc(arg1, arg2) dict + return self.name . '/' . a:arg1 . '/' . a:arg2 +endfunc + +func Test_partial_dict() + let dict = {'name': 'hello'} + let Cb = function('MyDictFunc', ["foo", "bar"], dict) + call assert_equal("hello/foo/bar", Cb()) + call assert_fails('Cb("xxx")', 'E492:') + let Cb = function('MyDictFunc', ["foo"], dict) + call assert_equal("hello/foo/xxx", Cb("xxx")) + call assert_fails('Cb()', 'E492:') + let Cb = function('MyDictFunc', dict) + call assert_equal("hello/xxx/yyy", Cb("xxx", "yyy")) + call assert_fails('Cb()', 'E492:') +endfunc -- cgit From 66922d89cce6ee381244d37f7c0c324cae815b45 Mon Sep 17 00:00:00 2001 From: Michael Ennen Date: Tue, 25 Oct 2016 22:48:08 -0700 Subject: vim-patch:7.4.1563 Problem: Partial test fails on windows. Solution: Return 1 or -1 from compare function. https://github.com/vim/vim/commit/790500a8e65bee295ef51a59dfa67ecbaab8ea17 --- src/nvim/testdir/test_partial.vim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_partial.vim b/src/nvim/testdir/test_partial.vim index 061f839668..998b232206 100644 --- a/src/nvim/testdir/test_partial.vim +++ b/src/nvim/testdir/test_partial.vim @@ -9,9 +9,9 @@ func MySort(up, one, two) return 0 endif if a:up - return a:one > a:two + return a:one > a:two ? 1 : -1 endif - return a:one < a:two + return a:one < a:two ? 1 : -1 endfunc func Test_partial_args() -- cgit From f90551b0e67c1389cb91dfedbe9a111c677e67e2 Mon Sep 17 00:00:00 2001 From: Michael Ennen Date: Tue, 25 Oct 2016 23:03:04 -0700 Subject: vim-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. https://github.com/vim/vim/commit/346418c624f1bc7c04c98907134a2b284e6452dd --- src/nvim/testdir/test_partial.vim | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_partial.vim b/src/nvim/testdir/test_partial.vim index 998b232206..abb655841b 100644 --- a/src/nvim/testdir/test_partial.vim +++ b/src/nvim/testdir/test_partial.vim @@ -19,6 +19,9 @@ func Test_partial_args() call assert_equal("foo/bar/xxx", Cb("xxx")) call assert_equal("foo/bar/yyy", call(Cb, ["yyy"])) + let Cb = function('MyFunc', []) + call assert_equal("a/b/c", Cb("a", "b", "c")) + let Sort = function('MySort', [1]) call assert_equal([1, 2, 3], sort([3, 1, 2], Sort)) let Sort = function('MySort', [0]) @@ -34,10 +37,15 @@ func Test_partial_dict() let Cb = function('MyDictFunc', ["foo", "bar"], dict) call assert_equal("hello/foo/bar", Cb()) call assert_fails('Cb("xxx")', 'E492:') + + let Cb = function('MyDictFunc', [], dict) + call assert_equal("hello/ttt/xxx", Cb("ttt", "xxx")) + call assert_fails('Cb("yyy")', 'E492:') + let Cb = function('MyDictFunc', ["foo"], dict) call assert_equal("hello/foo/xxx", Cb("xxx")) call assert_fails('Cb()', 'E492:') let Cb = function('MyDictFunc', dict) call assert_equal("hello/xxx/yyy", Cb("xxx", "yyy")) - call assert_fails('Cb()', 'E492:') + call assert_fails('Cb("fff")', 'E492:') endfunc -- cgit From 529482d6844474f6eab9feed5162008b652fd931 Mon Sep 17 00:00:00 2001 From: Michael Ennen Date: Wed, 26 Oct 2016 12:23:49 -0700 Subject: vim-patch:7.4.1577 Problem: Cannot pass "dict.Myfunc" around as a partial. Solution: Create a partial when expected. https://github.com/vim/vim/commit/ab1fa3955f25dfdb7e329c3bd76e175c93c8cb5e --- src/nvim/testdir/test_partial.vim | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_partial.vim b/src/nvim/testdir/test_partial.vim index abb655841b..caae1a8cb1 100644 --- a/src/nvim/testdir/test_partial.vim +++ b/src/nvim/testdir/test_partial.vim @@ -49,3 +49,21 @@ func Test_partial_dict() call assert_equal("hello/xxx/yyy", Cb("xxx", "yyy")) call assert_fails('Cb("fff")', 'E492:') endfunc + +func Test_partial_implicit() + let dict = {'name': 'foo'} + func dict.MyFunc(arg) dict + return self.name . '/' . a:arg + endfunc + + call assert_equal('foo/bar', dict.MyFunc('bar')) + + call assert_fails('let func = dict.MyFunc', 'E704:') + let Func = dict.MyFunc + call assert_equal('foo/aaa', Func('aaa')) + + let Func = function(dict.MyFunc, ['bbb']) + call assert_equal('foo/bbb', Func()) + + call assert_fails('call function(dict.MyFunc, ["bbb"], dict)', 'E924:') +endfunc -- cgit From 2c1b4c7f3c13b61dab70d6ad3507b90c7a60e4aa Mon Sep 17 00:00:00 2001 From: Michael Ennen Date: Wed, 26 Oct 2016 12:26:06 -0700 Subject: vim-patch:7.4.1580 Problem: Crash when using function reference. (Luchr) Solution: Set initial refcount. (Ken Takata) https://github.com/vim/vim/commit/7a5c46a9df7ef01a4f6a620861c35400d5ad28d9 --- src/nvim/testdir/test_partial.vim | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_partial.vim b/src/nvim/testdir/test_partial.vim index caae1a8cb1..f6f6b87a29 100644 --- a/src/nvim/testdir/test_partial.vim +++ b/src/nvim/testdir/test_partial.vim @@ -67,3 +67,17 @@ func Test_partial_implicit() call assert_fails('call function(dict.MyFunc, ["bbb"], dict)', 'E924:') endfunc + +fun InnerCall(funcref) + return a:funcref +endfu + +fun OuterCall() + let opt = { 'func' : function('sin') } + call InnerCall(opt.func) +endfu + +func Test_function_in_dict() + call OuterCall() +endfunc + -- cgit From 5cf0c99755581f789973a4fa4bb3d95a61a01341 Mon Sep 17 00:00:00 2001 From: Michael Ennen Date: Wed, 26 Oct 2016 12:42:15 -0700 Subject: vim-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) https://github.com/vim/vim/commit/65639032bb7b17996cd255d1508a1df4ad528a1f --- src/nvim/testdir/test_partial.vim | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_partial.vim b/src/nvim/testdir/test_partial.vim index f6f6b87a29..cb853f9335 100644 --- a/src/nvim/testdir/test_partial.vim +++ b/src/nvim/testdir/test_partial.vim @@ -16,6 +16,8 @@ endfunc func Test_partial_args() let Cb = function('MyFunc', ["foo", "bar"]) + + call Cb("zzz") call assert_equal("foo/bar/xxx", Cb("xxx")) call assert_equal("foo/bar/yyy", call(Cb, ["yyy"])) @@ -48,6 +50,9 @@ func Test_partial_dict() let Cb = function('MyDictFunc', dict) call assert_equal("hello/xxx/yyy", Cb("xxx", "yyy")) call assert_fails('Cb("fff")', 'E492:') + + let dict = {"tr": function('tr', ['hello', 'h', 'H'])} + call assert_equal("Hello", dict.tr()) endfunc func Test_partial_implicit() -- cgit From e2258598cacebf3c90bbb8e13789194c417d8dad Mon Sep 17 00:00:00 2001 From: Michael Ennen Date: Wed, 26 Oct 2016 21:40:40 -0700 Subject: vim-patch:7.4.1582 Problem: Get E923 when using function(dict.func, [], dict). (Kent Sibilev) Storing a function with a dict in a variable drops the dict if the function is script-local. Solution: Translate the function name. Use dict arg if present. https://github.com/vim/vim/commit/6f2e4b36c9d9908e1cace2b1b96e2c154a837bc2 --- src/nvim/testdir/test_partial.vim | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_partial.vim b/src/nvim/testdir/test_partial.vim index cb853f9335..7941ec01c2 100644 --- a/src/nvim/testdir/test_partial.vim +++ b/src/nvim/testdir/test_partial.vim @@ -69,8 +69,6 @@ func Test_partial_implicit() let Func = function(dict.MyFunc, ['bbb']) call assert_equal('foo/bbb', Func()) - - call assert_fails('call function(dict.MyFunc, ["bbb"], dict)', 'E924:') endfunc fun InnerCall(funcref) @@ -86,3 +84,24 @@ func Test_function_in_dict() call OuterCall() endfunc +function! s:cache_clear() dict + return self.name +endfunction + +func Test_script_function_in_dict() + let s:obj = {'name': 'foo'} + let s:obj2 = {'name': 'bar'} + + let s:obj['clear'] = function('s:cache_clear') + + call assert_equal('foo', s:obj.clear()) + let F = s:obj.clear + call assert_equal('foo', F()) + call assert_equal('foo', call(s:obj.clear, [], s:obj)) + call assert_equal('bar', call(s:obj.clear, [], s:obj2)) + + let s:obj2['clear'] = function('s:cache_clear') + call assert_equal('bar', s:obj2.clear()) + let B = s:obj2.clear + call assert_equal('bar', B()) +endfunc -- cgit From 27b2fb944a4b9bce0f06e7c1f2267949c8edab06 Mon Sep 17 00:00:00 2001 From: Michael Ennen Date: Wed, 26 Oct 2016 21:44:57 -0700 Subject: vim-patch:7.4.1585 Problem: Partial is not recognized everywhere. Solution: Check for partial in trans_function_name(). (Yasuhiro Matsumoto) Add a test. https://github.com/vim/vim/commit/d22a18928ebcb465393da1418bb88204b97badb1 --- src/nvim/testdir/test_partial.vim | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_partial.vim b/src/nvim/testdir/test_partial.vim index 7941ec01c2..75cbfe2f25 100644 --- a/src/nvim/testdir/test_partial.vim +++ b/src/nvim/testdir/test_partial.vim @@ -105,3 +105,15 @@ func Test_script_function_in_dict() let B = s:obj2.clear call assert_equal('bar', B()) endfunc + +func Test_partial_exists() + let F = function('MyFunc') + call assert_true(exists('*F')) + let lF = [F] + call assert_true(exists('*lF[0]')) + + let F = function('MyFunc', ['arg']) + call assert_true(exists('*F')) + let lF = [F] + call assert_true(exists('*lF[0]')) +endfunc -- cgit From cf2701b269a0fd1490da4296774b9fe426100640 Mon Sep 17 00:00:00 2001 From: Michael Ennen Date: Wed, 26 Oct 2016 21:56:02 -0700 Subject: vim-patch:7.4.1586 Problem: Nesting partials doesn't work. Solution: Append arguments. (Ken Takata) https://github.com/vim/vim/commit/8a1bb046378f4bc68d6a04af2eab80fb3ce04da6 --- src/nvim/testdir/test_partial.vim | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_partial.vim b/src/nvim/testdir/test_partial.vim index 75cbfe2f25..ae4f74cf5b 100644 --- a/src/nvim/testdir/test_partial.vim +++ b/src/nvim/testdir/test_partial.vim @@ -20,9 +20,17 @@ func Test_partial_args() call Cb("zzz") call assert_equal("foo/bar/xxx", Cb("xxx")) call assert_equal("foo/bar/yyy", call(Cb, ["yyy"])) + let Cb2 = function(Cb) + call assert_equal("foo/bar/zzz", Cb2("zzz")) + let Cb3 = function(Cb, ["www"]) + call assert_equal("foo/bar/www", Cb3()) let Cb = function('MyFunc', []) call assert_equal("a/b/c", Cb("a", "b", "c")) + let Cb2 = function(Cb, []) + call assert_equal("a/b/d", Cb2("a", "b", "d")) + let Cb3 = function(Cb, ["a", "b"]) + call assert_equal("a/b/e", Cb3("e")) let Sort = function('MySort', [1]) call assert_equal([1, 2, 3], sort([3, 1, 2], Sort)) -- cgit From 531249a4acdef36ed44e8bbf1355f2a80a5792a5 Mon Sep 17 00:00:00 2001 From: Michael Ennen Date: Thu, 27 Oct 2016 13:48:32 -0700 Subject: vim-patch:7.4.1589 Problem: Combining dict and args with partial doesn't always work. Solution: Use the arguments from the partial. https://github.com/vim/vim/commit/9e63f61cb01c70fd71652f54b2d01ee27b2a3534 --- src/nvim/testdir/test_partial.vim | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_partial.vim b/src/nvim/testdir/test_partial.vim index ae4f74cf5b..2b6b56c358 100644 --- a/src/nvim/testdir/test_partial.vim +++ b/src/nvim/testdir/test_partial.vim @@ -114,6 +114,36 @@ func Test_script_function_in_dict() call assert_equal('bar', B()) endfunc +function! s:cache_arg(arg) dict + let s:result = self.name . '/' . a:arg + return s:result +endfunction + +func Test_script_function_in_dict_arg() + let s:obj = {'name': 'foo'} + let s:obj['clear'] = function('s:cache_arg') + + call assert_equal('foo/bar', s:obj.clear('bar')) + let F = s:obj.clear + let s:result = '' + call assert_equal('foo/bar', F('bar')) + call assert_equal('foo/bar', s:result) + + let s:obj['clear'] = function('s:cache_arg', ['bar']) + call assert_equal('foo/bar', s:obj.clear()) + let s:result = '' + call s:obj.clear() + call assert_equal('foo/bar', s:result) + + let F = s:obj.clear + call assert_equal('foo/bar', F()) + let s:result = '' + call F() + call assert_equal('foo/bar', s:result) + + call assert_equal('foo/bar', call(s:obj.clear, [], s:obj)) +endfunc + func Test_partial_exists() let F = function('MyFunc') call assert_true(exists('*F')) -- cgit From 5241ca7d7a8c3a08af8bbfbf7cca3381241a915b Mon Sep 17 00:00:00 2001 From: Michael Ennen Date: Thu, 27 Oct 2016 13:53:53 -0700 Subject: vim-patch:7.4.1606 Problem: Having type() handle a Funcref that is or isn't a partial differently causes problems for existing scripts. Solution: Make type() return the same value. (Thinca) https://github.com/vim/vim/commit/953cc7fb139dc2ba8590f8b03a095b63f4e1208f --- src/nvim/testdir/test_viml.vim | 1 + 1 file changed, 1 insertion(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_viml.vim b/src/nvim/testdir/test_viml.vim index a11d62f5cf..2f9a72d618 100644 --- a/src/nvim/testdir/test_viml.vim +++ b/src/nvim/testdir/test_viml.vim @@ -943,6 +943,7 @@ func Test_type() call assert_equal(0, type(0)) call assert_equal(1, type("")) call assert_equal(2, type(function("tr"))) + call assert_equal(2, type(function("tr", [8]))) call assert_equal(3, type([])) call assert_equal(4, type({})) call assert_equal(5, type(0.0)) -- cgit From 3213b28c01313c7f0e7e0e01f72a0fbfef85fa3e Mon Sep 17 00:00:00 2001 From: Michael Ennen Date: Thu, 27 Oct 2016 14:05:27 -0700 Subject: vim-patch:7.4.1607 Problem: Comparing a function that exists on two dicts is not backwards compatible. (Thinca) Solution: Only compare the function, not what the partial adds. https://github.com/vim/vim/commit/f0e86a0dbddc18568910e9e4aaae0cd88ca8087a --- src/nvim/testdir/test_expr.vim | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_expr.vim b/src/nvim/testdir/test_expr.vim index 66a10b05e1..cc5e9587ed 100644 --- a/src/nvim/testdir/test_expr.vim +++ b/src/nvim/testdir/test_expr.vim @@ -15,6 +15,28 @@ func Test_version() call assert_false(has('patch-9.9.1')) endfunc +func Test_equal() + let base = {} + func base.method() + return 1 + endfunc + func base.other() dict + return 1 + endfunc + let instance = copy(base) + call assert_true(base.method == instance.method) + call assert_true([base.method] == [instance.method]) + call assert_true(base.other == instance.other) + call assert_true([base.other] == [instance.other]) + + call assert_false(base.method == base.other) + call assert_false([base.method] == [base.other]) + call assert_false(base.method == instance.other) + call assert_false([base.method] == [instance.other]) + + call assert_fails('echo base.method > instance.method') +endfunc + func Test_strgetchar() call assert_equal(char2nr('a'), strgetchar('axb', 0)) call assert_equal(char2nr('x'), strgetchar('axb', 1)) -- cgit From bae31b764a5607fad5d914f271e93e10c2d0bfbe Mon Sep 17 00:00:00 2001 From: Michael Ennen Date: Fri, 28 Oct 2016 22:44:42 -0700 Subject: vim-patch:7.4.1608 Problem: string() doesn't handle a partial. Solution: Make a string from a partial. https://github.com/vim/vim/commit/5c29154b521e9948190be653cfda666ecbb63b5b --- src/nvim/testdir/test_partial.vim | 86 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_partial.vim b/src/nvim/testdir/test_partial.vim index 2b6b56c358..b5909910c7 100644 --- a/src/nvim/testdir/test_partial.vim +++ b/src/nvim/testdir/test_partial.vim @@ -155,3 +155,89 @@ func Test_partial_exists() let lF = [F] call assert_true(exists('*lF[0]')) endfunc + +func Test_partial_string() + let F = function('MyFunc') + call assert_equal("function('MyFunc')", string(F)) + let F = function('MyFunc', ['foo']) + call assert_equal("function('MyFunc', ['foo'])", string(F)) + let F = function('MyFunc', ['foo', 'bar']) + call assert_equal("function('MyFunc', ['foo', 'bar'])", string(F)) + let d = {'one': 1} + let F = function('MyFunc', d) + call assert_equal("function('MyFunc', {'one': 1})", string(F)) + let F = function('MyFunc', ['foo'], d) + call assert_equal("function('MyFunc', ['foo'], {'one': 1})", string(F)) +endfunc + +func Test_func_unref() + let obj = {} + function! obj.func() abort + endfunction + let funcnumber = matchstr(string(obj.func), '^function(''\zs.\{-}\ze''') + call assert_true(exists('*{' . funcnumber . '}')) + unlet obj + call assert_false(exists('*{' . funcnumber . '}')) +endfunc + +func Test_redefine_dict_func() + let d = {} + function d.test4() + endfunction + let d.test4 = d.test4 + try + function! d.test4(name) + endfunction + catch + call assert_true(v:errmsg, v:exception) + endtry +endfunc + +" This causes double free on exit if EXITFREE is defined. +func Test_cyclic_list_arg() + let l = [] + let Pt = function('string', [l]) + call add(l, Pt) + unlet l + unlet Pt +endfunc + +" This causes double free on exit if EXITFREE is defined. +func Test_cyclic_dict_arg() + let d = {} + let Pt = function('string', [d]) + let d.Pt = Pt + unlet d + unlet Pt +endfunc + +func Test_auto_partial_rebind() + let dict1 = {'name': 'dict1'} + func! dict1.f1() + return self.name + endfunc + let dict1.f2 = function(dict1.f1, dict1) + + call assert_equal('dict1', dict1.f1()) + call assert_equal('dict1', dict1['f1']()) + call assert_equal('dict1', dict1.f2()) + call assert_equal('dict1', dict1['f2']()) + + let dict2 = {'name': 'dict2'} + let dict2.f1 = dict1.f1 + let dict2.f2 = dict1.f2 + + call assert_equal('dict2', dict2.f1()) + call assert_equal('dict2', dict2['f1']()) + call assert_equal('dict1', dict2.f2()) + call assert_equal('dict1', dict2['f2']()) +endfunc + +func Test_get_partial_items() + let dict = {'name': 'hello'} + let Cb = function('MyDictFunc', ["foo", "bar"], dict) + call assert_equal('MyDictFunc', get(Cb, 'func')) + call assert_equal(["foo", "bar"], get(Cb, 'args')) + call assert_equal(dict, get(Cb, 'dict')) + call assert_fails('call get(Cb, "xxx")', 'E475:') +endfunc -- cgit From 25438f149fda66375ed54a735e4477f3f4d87338 Mon Sep 17 00:00:00 2001 From: Michael Ennen Date: Sun, 30 Oct 2016 15:10:11 -0700 Subject: vim-patch:7.4.1719 Problem: Leaking memory when there is a cycle involving a job and a partial. Solution: Add a copyID to job and channel. Set references in items referred by them. Go through all jobs and channels to find unreferenced items. Also, decrement reference counts when garbage collecting. https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5 --- src/nvim/testdir/test_partial.vim | 19 +++++++++++++++++-- src/nvim/testdir/test_timers.vim | 13 +++++++++++++ 2 files changed, 30 insertions(+), 2 deletions(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_partial.vim b/src/nvim/testdir/test_partial.vim index b5909910c7..7562c7fd2a 100644 --- a/src/nvim/testdir/test_partial.vim +++ b/src/nvim/testdir/test_partial.vim @@ -193,7 +193,7 @@ func Test_redefine_dict_func() endtry endfunc -" This causes double free on exit if EXITFREE is defined. +" This caused double free on exit if EXITFREE is defined. func Test_cyclic_list_arg() let l = [] let Pt = function('string', [l]) @@ -202,7 +202,7 @@ func Test_cyclic_list_arg() unlet Pt endfunc -" This causes double free on exit if EXITFREE is defined. +" This caused double free on exit if EXITFREE is defined. func Test_cyclic_dict_arg() let d = {} let Pt = function('string', [d]) @@ -211,6 +211,21 @@ func Test_cyclic_dict_arg() unlet Pt endfunc +func Ignored(job1, job2, status) +endfunc + +" func Test_cycle_partial_job() +" let job = job_start('echo') +" call job_setoptions(job, {'exit_cb': function('Ignored', [job])}) +" unlet job +" endfunc + +" func Test_ref_job_partial_dict() +" let g:ref_job = job_start('echo') +" let d = {'a': 'b'} +" call job_setoptions(g:ref_job, {'exit_cb': function('string', [], d)}) +" endfunc + func Test_auto_partial_rebind() let dict1 = {'name': 'dict1'} func! dict1.f1() diff --git a/src/nvim/testdir/test_timers.vim b/src/nvim/testdir/test_timers.vim index 9f58a35909..abf4e43ec3 100644 --- a/src/nvim/testdir/test_timers.vim +++ b/src/nvim/testdir/test_timers.vim @@ -30,3 +30,16 @@ func Test_repeat_many() call assert_true(s:val > 1) call assert_true(s:val < 5) endfunc + +" func Test_with_partial_callback() +" let s:val = 0 +" let s:meow = {} +" function s:meow.bite(...) +" let s:val += 1 +" endfunction + +" call timer_start(50, s:meow.bite) +" sleep 200m +" call assert_equal(1, s:val) +" endfunc +" vim: ts=2 sw=0 et -- cgit From c52856af2c5f3b12b89671d91c35689fb2f84a70 Mon Sep 17 00:00:00 2001 From: Michael Ennen Date: Fri, 28 Oct 2016 22:58:11 -0700 Subject: vim-patch:7.4.1842 Problem: get() works for Partial but not for Funcref. Solution: Accept Funcref. Also return the function itself. (Nikolai Pavlov) https://github.com/vim/vim/commit/03e19a04ac2ca55643663b97b6ab94043233dcbd --- src/nvim/testdir/test_partial.vim | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_partial.vim b/src/nvim/testdir/test_partial.vim index 7562c7fd2a..f97d283022 100644 --- a/src/nvim/testdir/test_partial.vim +++ b/src/nvim/testdir/test_partial.vim @@ -250,9 +250,18 @@ endfunc func Test_get_partial_items() let dict = {'name': 'hello'} - let Cb = function('MyDictFunc', ["foo", "bar"], dict) - call assert_equal('MyDictFunc', get(Cb, 'func')) - call assert_equal(["foo", "bar"], get(Cb, 'args')) + let args = ["foo", "bar"] + let Func = function('MyDictFunc') + let Cb = function('MyDictFunc', args, dict) + + call assert_equal(Func, get(Cb, 'func')) + call assert_equal('MyDictFunc', get(Cb, 'name')) + call assert_equal(args, get(Cb, 'args')) call assert_equal(dict, get(Cb, 'dict')) call assert_fails('call get(Cb, "xxx")', 'E475:') + + call assert_equal(Func, get(Func, 'func')) + call assert_equal('MyDictFunc', get(Func, 'name')) + call assert_equal([], get(Func, 'args')) + call assert_true(empty( get(Func, 'dict'))) endfunc -- cgit From 537cee4883a00bc3dd8ac3524c8f704a372bdcc8 Mon Sep 17 00:00:00 2001 From: Michael Ennen Date: Wed, 2 Nov 2016 22:11:25 -0700 Subject: vim-patch:7.4.1860 Problem: Using a partial for timer_start() may cause a crash. Solution: Set the copyID in timer objects. (Ozaki Kiichi) https://github.com/vim/vim/commit/e3188e261569ae512fb1ae2653b57fdd9e259ca3 --- src/nvim/testdir/test_timers.vim | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_timers.vim b/src/nvim/testdir/test_timers.vim index abf4e43ec3..136f32a80e 100644 --- a/src/nvim/testdir/test_timers.vim +++ b/src/nvim/testdir/test_timers.vim @@ -8,6 +8,10 @@ func MyHandler(timer) let s:val += 1 endfunc +func MyHandlerWithLists(lists, timer) + let x = string(a:lists) +endfunc + func Test_oneshot() let s:val = 0 let timer = timer_start(50, 'MyHandler') @@ -31,15 +35,20 @@ func Test_repeat_many() call assert_true(s:val < 5) endfunc -" func Test_with_partial_callback() -" let s:val = 0 -" let s:meow = {} -" function s:meow.bite(...) -" let s:val += 1 -" endfunction - -" call timer_start(50, s:meow.bite) -" sleep 200m -" call assert_equal(1, s:val) -" endfunc +func Test_with_partial_callback() + let s:val = 0 + let s:meow = {} + function s:meow.bite(...) + let s:val += 1 + endfunction + call timer_start(50, s:meow.bite) + sleep 200m + call assert_equal(1, s:val) +endfunc + +func Test_retain_partial() + call timer_start(100, function('MyHandlerWithLists', [['a']])) + call garbagecollect() + sleep 200m +endfunc " vim: ts=2 sw=0 et -- cgit From b42347da45933a2d1ed54e9ca65db37f50d3e8be Mon Sep 17 00:00:00 2001 From: Michael Ennen Date: Tue, 6 Dec 2016 22:47:40 -0700 Subject: vim-patch:7.4.1862 Mark as NA --- src/nvim/testdir/test_viml.vim | 80 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_viml.vim b/src/nvim/testdir/test_viml.vim index 2f9a72d618..a2997b6d4d 100644 --- a/src/nvim/testdir/test_viml.vim +++ b/src/nvim/testdir/test_viml.vim @@ -984,6 +984,86 @@ func Test_skip() endfunc +"------------------------------------------------------------------------------- +" Test 93: :echo and string() {{{1 +"------------------------------------------------------------------------------- + +func Test_echo_and_string() + " String + let a = 'foo bar' + redir => result + echo a + echo string(a) + redir END + let l = split(result, "\n") + call assert_equal(["foo bar", + \ "'foo bar'"], l) + + " Float + if has('float') + let a = -1.2e0 + redir => result + echo a + echo string(a) + redir END + let l = split(result, "\n") + call assert_equal(["-1.2", + \ "-1.2"], l) + endif + + " Funcref + redir => result + echo function('string') + echo string(function('string')) + redir END + let l = split(result, "\n") + call assert_equal(["string", + \ "function('string')"], l) + + " Empty dictionaries in a list + let a = {} + redir => result + echo [a, a, a] + echo string([a, a, a]) + redir END + let l = split(result, "\n") + call assert_equal(["[{}, {}, {}]", + \ "[{}, {}, {}]"], l) + + " Empty dictionaries in a dictionary + let a = {} + let b = {"a": a, "b": a} + redir => result + echo b + echo string(b) + redir END + let l = split(result, "\n") + call assert_equal(["{'a': {}, 'b': {}}", + \ "{'a': {}, 'b': {}}"], l) + + " Empty lists in a list + let a = [] + redir => result + echo [a, a, a] + echo string([a, a, a]) + redir END + let l = split(result, "\n") + call assert_equal(["[[], [], []]", + \ "[[], [], []]"], l) + + " Empty lists in a dictionary + let a = [] + let b = {"a": a, "b": a} + redir => result + echo b + echo string(b) + redir END + let l = split(result, "\n") + call assert_equal(["{'a': [], 'b': []}", + \ "{'a': [], 'b': []}"], l) + +endfunc + "------------------------------------------------------------------------------- " Modelines {{{1 " vim: ts=8 sw=4 tw=80 fdm=marker -- cgit From 6c5dd6827f5d1347cdf90f8a2f76d6a732e93931 Mon Sep 17 00:00:00 2001 From: Michael Ennen Date: Sat, 29 Oct 2016 12:02:58 -0700 Subject: vim-patch:7.4.1875 Problem: Comparing functions and partials doesn't work well. Solution: Add tests. (Nikolai Pavlov) Compare the dict and arguments in the partial. https://github.com/vim/vim/commit/8e759ba8651428995b338b66c615367259f79766 --- src/nvim/testdir/test_partial.vim | 63 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_partial.vim b/src/nvim/testdir/test_partial.vim index f97d283022..3a6e162453 100644 --- a/src/nvim/testdir/test_partial.vim +++ b/src/nvim/testdir/test_partial.vim @@ -265,3 +265,66 @@ func Test_get_partial_items() call assert_equal([], get(Func, 'args')) call assert_true(empty( get(Func, 'dict'))) endfunc + +func Test_compare_partials() + let d1 = {} + let d2 = {} + + function d1.f1() dict + endfunction + + function d1.f2() dict + endfunction + + let F1 = get(d1, 'f1') + let F2 = get(d1, 'f2') + + let F1d1 = function(F1, d1) + let F2d1 = function(F2, d2) + let F1d1a1 = function(F1d1, [1]) + let F1d1a12 = function(F1d1, [1, 2]) + let F1a1 = function(F1, [1]) + let F1a2 = function(F1, [2]) + let F1d2 = function(F1, d2) + let d3 = {'f1': F1, 'f2': F2} + let F1d3 = function(F1, d3) + let F1ad1 = function(F1, [d1]) + let F1ad3 = function(F1, [d3]) + + call assert_match('^function(''\d\+'')$', string(F1)) " Not a partial + call assert_match('^function(''\d\+'')$', string(F2)) " Not a partial + call assert_match('^function(''\d\+'', {.*})$', string(F1d1)) " A partial + call assert_match('^function(''\d\+'', {.*})$', string(F2d1)) " A partial + call assert_match('^function(''\d\+'', \[.*\])$', string(F1a1)) " No dict + + " != + let X = F1 + call assert_false(F1 != X) " same function + let X = F1d1 + call assert_false(F1d1 != X) " same partial + let X = F1d1a1 + call assert_false(F1d1a1 != X) " same partial + let X = F1a1 + call assert_false(F1a1 != X) " same partial + + call assert_true(F1 != F2) " Different functions + call assert_true(F1 != F1d1) " Partial /= non-partial + call assert_true(F1d1a1 != F1d1a12) " Different number of arguments + call assert_true(F1a1 != F1d1a12) " One has no dict + call assert_true(F1a1 != F1a2) " Different arguments + call assert_true(F1d2 != F1d1) " Different dictionaries + call assert_false(F1d1 != F1d3) " Equal dictionaries, even though d1 isnot d3 + + " isnot, option 1 + call assert_true(F1 isnot# F2) " Different functions + call assert_true(F1 isnot# F1d1) " Partial /= non-partial + call assert_true(F1d1 isnot# F1d3) " d1 isnot d3, even though d1 == d3 + call assert_true(F1a1 isnot# F1d1a12) " One has no dict + call assert_true(F1a1 isnot# F1a2) " Different number of arguments + call assert_true(F1ad1 isnot# F1ad3) " In arguments d1 isnot d3 + + " isnot, option 2 + call assert_true(F1 isnot# F2) " Different functions + call assert_true(F1 isnot# F1d1) " Partial /= non-partial + call assert_true(d1.f1 isnot# d1.f1) " handle_subscript creates new partial each time +endfunc -- cgit From 0f681c80e1e9c9060394365dae12f8ebd5736176 Mon Sep 17 00:00:00 2001 From: Björn Linse Date: Tue, 1 Nov 2016 10:54:32 +0100 Subject: Make partials work with jobs, timers, and dictwatchers. --- src/nvim/testdir/test_timers.vim | 1 + 1 file changed, 1 insertion(+) (limited to 'src/nvim/testdir') diff --git a/src/nvim/testdir/test_timers.vim b/src/nvim/testdir/test_timers.vim index 136f32a80e..d92cbe6897 100644 --- a/src/nvim/testdir/test_timers.vim +++ b/src/nvim/testdir/test_timers.vim @@ -41,6 +41,7 @@ func Test_with_partial_callback() function s:meow.bite(...) let s:val += 1 endfunction + call timer_start(50, s:meow.bite) sleep 200m call assert_equal(1, s:val) -- cgit