Files
vim-ingo-library-mirror/tests/compat/substitution/t1000-RecursiveSubstitutionExpression.vim
Ingo Karkat ae5443aa73 - Deprecated: ingo#subst#expr#emulation#Substitute() is now available as a compat function ingo#compat#substitution#RecursiveSubstitutionExpression()
Since Vim 8.0.20, the regexp engine is reentrant, and the built-in substitute() handles recursive invocations.
2020-10-20 21:34:11 +02:00

19 lines
1.3 KiB
VimL

" Test recursive invocation of sub-replace-expression.
let g:IngoLibrary_CompatFor = 'RecursiveSubstitutionExpression'
call vimtest#StartTap()
call vimtap#Plan(5)
call vimtap#Is(ingo#compat#substitution#RecursiveSubstitutionExpression('foobor', 'o\+', 'X', 'g'), 'fXbXr', 'plain substitution')
call vimtap#Is(ingo#compat#substitution#RecursiveSubstitutionExpression('foobor', 'o\+', '\=repeat(submatch(0), 2)', 'g'), 'fooooboor', 'non-recursive expression substitution')
call vimtap#Is(substitute('foobor', '.o\+', '\=ingo#compat#substitution#RecursiveSubstitutionExpression(submatch(0), "^.", "\\=toupper(submatch(0))", "")', 'g'), 'FooBor', 'recursive expression substitution with inner compat function')
call vimtap#Is(ingo#compat#substitution#RecursiveSubstitutionExpression('foobor', '.o\+', '\=ingo#compat#substitution#RecursiveSubstitutionExpression(submatch(0), "^.", "\\=toupper(submatch(0))", "")', 'g'), 'FooBor', 'recursive expression substitution both using compat function')
function! Recurse() abort
return ingo#compat#substitution#RecursiveSubstitutionExpression('yyy', '.\(.\).', '\=submatch(1) . submatch(1)', '')
endfunction
call vimtap#Is(substitute('foobor', 'o\+', '\=Recurse() . submatch(0)', 'g'), 'fyyoobyyor', 'recursive expression substitution through function')
call vimtest#Quit()