From fc46efd3f2d95920bf50832848515b14b12c0723 Mon Sep 17 00:00:00 2001 From: Michael Ennen Date: Thu, 15 Dec 2016 13:53:14 -0700 Subject: vim-patch:7.4.2072 Problem: substitute() does not support a Funcref argument. Solution: Support a Funcref like it supports a string starting with "\=". https://github.com/vim/vim/commit/72ab729c3dcdea0fba44d8e676602c847e841bcd --- src/nvim/testdir/test_expr.vim | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'src/nvim/testdir/test_expr.vim') diff --git a/src/nvim/testdir/test_expr.vim b/src/nvim/testdir/test_expr.vim index 39dcacb55f..0e409009e0 100644 --- a/src/nvim/testdir/test_expr.vim +++ b/src/nvim/testdir/test_expr.vim @@ -106,3 +106,21 @@ func Test_setmatches() call setmatches(set) call assert_equal(exp, getmatches()) endfunc + +func Test_substitute_expr() + let g:val = 'XXX' + call assert_equal('XXX', substitute('yyy', 'y*', '\=g:val', '')) + call assert_equal('XXX', substitute('yyy', 'y*', {-> g:val}, '')) + call assert_equal("-\u1b \uf2-", substitute("-%1b %f2-", '%\(\x\x\)', + \ '\=nr2char("0x" . submatch(1))', 'g')) + call assert_equal("-\u1b \uf2-", substitute("-%1b %f2-", '%\(\x\x\)', + \ {-> nr2char("0x" . submatch(1))}, 'g')) + + call assert_equal('231', substitute('123', '\(.\)\(.\)\(.\)', + \ {-> submatch(2) . submatch(3) . submatch(1)}, '')) + + func Recurse() + return substitute('yyy', 'y*', {-> g:val}, '') + endfunc + call assert_equal('--', substitute('xxx', 'x*', {-> '-' . Recurse() . '-'}, '')) +endfunc -- cgit From 7f4848aff47b7b2a85be5f83007846934ef9fd90 Mon Sep 17 00:00:00 2001 From: Michael Ennen Date: Thu, 15 Dec 2016 13:27:32 -0700 Subject: vim-patch:7.4.2090 Problem: Using submatch() in a lambda passed to substitute() is verbose. Solution: Use a static list and pass it as an optional argument to the function. Fix memory leak. https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311 --- src/nvim/testdir/test_expr.vim | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'src/nvim/testdir/test_expr.vim') diff --git a/src/nvim/testdir/test_expr.vim b/src/nvim/testdir/test_expr.vim index 0e409009e0..0c4a91298c 100644 --- a/src/nvim/testdir/test_expr.vim +++ b/src/nvim/testdir/test_expr.vim @@ -124,3 +124,22 @@ func Test_substitute_expr() endfunc call assert_equal('--', substitute('xxx', 'x*', {-> '-' . Recurse() . '-'}, '')) endfunc + +func Test_substitute_expr_arg() + call assert_equal('123456789-123456789=', substitute('123456789', + \ '\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)', + \ {m -> m[0] . '-' . m[1] . m[2] . m[3] . m[4] . m[5] . m[6] . m[7] . m[8] . m[9] . '='}, '')) + + call assert_equal('123456-123456=789', substitute('123456789', + \ '\(.\)\(.\)\(.\)\(a*\)\(n*\)\(.\)\(.\)\(.\)\(x*\)', + \ {m -> m[0] . '-' . m[1] . m[2] . m[3] . m[4] . m[5] . m[6] . m[7] . m[8] . m[9] . '='}, '')) + + call assert_equal('123456789-123456789x=', substitute('123456789', + \ '\(.\)\(.\)\(.*\)', + \ {m -> m[0] . '-' . m[1] . m[2] . m[3] . 'x' . m[4] . m[5] . m[6] . m[7] . m[8] . m[9] . '='}, '')) + + call assert_fails("call substitute('xxx', '.', {m -> string(add(m, 'x'))}, '')", 'E742:') + call assert_fails("call substitute('xxx', '.', {m -> string(insert(m, 'x'))}, '')", 'E742:') + call assert_fails("call substitute('xxx', '.', {m -> string(extend(m, ['x']))}, '')", 'E742:') + call assert_fails("call substitute('xxx', '.', {m -> string(remove(m, 1))}, '')", 'E742:') +endfunc -- cgit From 1e3c0efa0f3d41563f91097d04b3616848d5eb62 Mon Sep 17 00:00:00 2001 From: Michael Ennen Date: Sat, 17 Dec 2016 18:01:24 -0700 Subject: vim-patch:7.4.2134 Problem: No error for using function() badly. Solution: Check for passing wrong function name. (Ken Takata) https://github.com/vim/vim/commit/b54c3ff3174dbb5dfbfcabdf95200b047beaa644 --- src/nvim/testdir/test_expr.vim | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src/nvim/testdir/test_expr.vim') diff --git a/src/nvim/testdir/test_expr.vim b/src/nvim/testdir/test_expr.vim index 0c4a91298c..7e43af9ebd 100644 --- a/src/nvim/testdir/test_expr.vim +++ b/src/nvim/testdir/test_expr.vim @@ -143,3 +143,10 @@ func Test_substitute_expr_arg() call assert_fails("call substitute('xxx', '.', {m -> string(extend(m, ['x']))}, '')", 'E742:') call assert_fails("call substitute('xxx', '.', {m -> string(remove(m, 1))}, '')", 'E742:') endfunc + +func Test_function_with_funcref() + let s:f = function('type') + let s:fref = function(s:f) + call assert_equal(v:t_string, s:fref('x')) + call assert_fails("call function('s:f')", 'E700:') +endfunc -- cgit From 53fad45115d3ee438dfb537d99ccf3b021ebc6b7 Mon Sep 17 00:00:00 2001 From: Michael Ennen Date: Fri, 16 Dec 2016 14:51:49 -0700 Subject: vim-patch:7.4.2137 Problem: Using function() with a name will find another function when it is redefined. Solution: Add funcref(). Refer to lambda using a partial. Fix several reference counting issues. https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c --- src/nvim/testdir/test_expr.vim | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'src/nvim/testdir/test_expr.vim') diff --git a/src/nvim/testdir/test_expr.vim b/src/nvim/testdir/test_expr.vim index 7e43af9ebd..419d539b42 100644 --- a/src/nvim/testdir/test_expr.vim +++ b/src/nvim/testdir/test_expr.vim @@ -150,3 +150,18 @@ func Test_function_with_funcref() call assert_equal(v:t_string, s:fref('x')) call assert_fails("call function('s:f')", 'E700:') endfunc + +func Test_funcref() + func! One() + return 1 + endfunc + let OneByName = function('One') + let OneByRef = funcref('One') + func! One() + return 2 + endfunc + call assert_equal(2, OneByName()) + call assert_equal(1, OneByRef()) + let OneByRef = funcref('One') + call assert_equal(2, OneByRef()) +endfunc -- cgit From effe760b134589f8024d6a5f1cb2c7b979054937 Mon Sep 17 00:00:00 2001 From: Michael Ennen Date: Mon, 19 Dec 2016 17:21:50 -0700 Subject: vim-patch:7.4.2233 Problem: Crash when using funcref() with invalid name. (Dominique Pelle) Solution: Check for NULL translated name. https://github.com/vim/vim/commit/843b884461de1c79a1d2748549776fb13fc94360 --- src/nvim/testdir/test_expr.vim | 1 + 1 file changed, 1 insertion(+) (limited to 'src/nvim/testdir/test_expr.vim') diff --git a/src/nvim/testdir/test_expr.vim b/src/nvim/testdir/test_expr.vim index 419d539b42..3b87c4b087 100644 --- a/src/nvim/testdir/test_expr.vim +++ b/src/nvim/testdir/test_expr.vim @@ -164,4 +164,5 @@ func Test_funcref() call assert_equal(1, OneByRef()) let OneByRef = funcref('One') call assert_equal(2, OneByRef()) + call assert_fails('echo funcref("{")', 'E475:') endfunc -- cgit From bae8a19c63381c3f6c860bae75af3580d68bf3b3 Mon Sep 17 00:00:00 2001 From: Michael Ennen Date: Mon, 19 Dec 2016 17:24:21 -0700 Subject: vim-patch:7.4.2235 Problem: submatch() does not check for a valid argument. Solution: Give an error if the argument is out of range. (Dominique Pelle) https://github.com/vim/vim/commit/989f592f7ffcbafdc4ec35cee4dc65bd053e2077 --- src/nvim/testdir/test_expr.vim | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src/nvim/testdir/test_expr.vim') diff --git a/src/nvim/testdir/test_expr.vim b/src/nvim/testdir/test_expr.vim index 3b87c4b087..7ceef2834f 100644 --- a/src/nvim/testdir/test_expr.vim +++ b/src/nvim/testdir/test_expr.vim @@ -125,6 +125,11 @@ func Test_substitute_expr() call assert_equal('--', substitute('xxx', 'x*', {-> '-' . Recurse() . '-'}, '')) endfunc +func Test_invalid_submatch() + " This was causing invalid memory access in Vim-7.4.2232 and older + call assert_fails("call substitute('x', '.', {-> submatch(10)}, '')", 'E935:') +endfunc + func Test_substitute_expr_arg() call assert_equal('123456789-123456789=', substitute('123456789', \ '\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)', -- cgit