Mercurial > vim
diff src/testdir/test_expr.vim @ 9589:bf204ab1ce7d v7.4.2072
commit https://github.com/vim/vim/commit/72ab729c3dcdea0fba44d8e676602c847e841bcd
Author: Bram Moolenaar <Bram@vim.org>
Date: Tue Jul 19 19:10:51 2016 +0200
patch 7.4.2072
Problem: substitute() does not support a Funcref argument.
Solution: Support a Funcref like it supports a string starting with "\=".
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Tue, 19 Jul 2016 19:15:06 +0200 |
parents | d18d71ae21e5 |
children | 172131507c85 |
line wrap: on
line diff
--- a/src/testdir/test_expr.vim +++ b/src/testdir/test_expr.vim @@ -135,3 +135,21 @@ function Test_printf_64bit() call assert_equal("123456789012345", printf('%d', 123456789012345)) endif 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