Mercurial > vim
diff src/testdir/test_substitute.vim @ 30281:d3cfd12839ef v9.0.0476
patch 9.0.0476: varargs does not work for replacement function of substitute()
Commit: https://github.com/vim/vim/commit/48db5dafecacced4a9e42de3f92838b2d59beb4c
Author: zeertzjq <zeertzjq@outlook.com>
Date: Fri Sep 16 12:10:03 2022 +0100
patch 9.0.0476: varargs does not work for replacement function of substitute()
Problem: Varargs does not work for replacement function of substitute().
Solution: Check the varargs flag of the function. (closes https://github.com/vim/vim/issues/11142)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Fri, 16 Sep 2022 13:15:05 +0200 |
parents | b57d52934160 |
children | 085406413994 |
line wrap: on
line diff
--- a/src/testdir/test_substitute.vim +++ b/src/testdir/test_substitute.vim @@ -439,20 +439,24 @@ endfunc func SubReplacer(text, submatches) return a:text .. a:submatches[0] .. a:text endfunc +func SubReplacerVar(text, ...) + return a:text .. a:1[0] .. a:text +endfunc func SubReplacer20(t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, submatches) return a:t3 .. a:submatches[0] .. a:t11 endfunc func Test_substitute_partial() - call assert_equal('1foo2foo3', substitute('123', '2', function('SubReplacer', ['foo']), 'g')) + call assert_equal('1foo2foo3', substitute('123', '2', function('SubReplacer', ['foo']), 'g')) + call assert_equal('1foo2foo3', substitute('123', '2', function('SubReplacerVar', ['foo']), 'g')) - " 19 arguments plus one is just OK - let Replacer = function('SubReplacer20', repeat(['foo'], 19)) - call assert_equal('1foo2foo3', substitute('123', '2', Replacer, 'g')) + " 19 arguments plus one is just OK + let Replacer = function('SubReplacer20', repeat(['foo'], 19)) + call assert_equal('1foo2foo3', substitute('123', '2', Replacer, 'g')) - " 20 arguments plus one is too many - let Replacer = function('SubReplacer20', repeat(['foo'], 20)) - call assert_fails("call substitute('123', '2', Replacer, 'g')", 'E118:') + " 20 arguments plus one is too many + let Replacer = function('SubReplacer20', repeat(['foo'], 20)) + call assert_fails("call substitute('123', '2', Replacer, 'g')", 'E118:') endfunc func Test_substitute_float()