mirror of
https://github.com/inkarkat/vim-ingo-library.git
synced 2026-10-12 22:49:23 +02:00
Since Vim 8.0.20, the regexp engine is reentrant, and the built-in substitute() handles recursive invocations.
19 lines
1.3 KiB
VimL
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()
|