forked from aniani/vim
patch 8.2.4628: not enough testing for 2/3 letter substitute commands
Problem: Not enough testing for 2/3 letter substitute commands. Solution: Add more tests. (Yegappan Lakshmanan, closes #10019)
This commit is contained in:
committed by
Bram Moolenaar
parent
acf7d73a7f
commit
5e877baf87
@@ -3284,4 +3284,17 @@ func Test_cmdline_complete_scriptnames()
|
||||
set wildmenu&
|
||||
endfunc
|
||||
|
||||
" Test for expanding 2-letter and 3-letter :substitute command arguments.
|
||||
" These commands don't accept an argument.
|
||||
func Test_cmdline_complete_substitute_short()
|
||||
for cmd in ['sc', 'sce', 'scg', 'sci', 'scI', 'scn', 'scp', 'scl',
|
||||
\ 'sgc', 'sge', 'sg', 'sgi', 'sgI', 'sgn', 'sgp', 'sgl', 'sgr',
|
||||
\ 'sic', 'sie', 'si', 'siI', 'sin', 'sip', 'sir',
|
||||
\ 'sIc', 'sIe', 'sIg', 'sIi', 'sI', 'sIn', 'sIp', 'sIl', 'sIr',
|
||||
\ 'src', 'srg', 'sri', 'srI', 'srn', 'srp', 'srl', 'sr']
|
||||
call feedkeys(':' .. cmd .. " \<Tab>\<C-B>\"\<CR>", 'tx')
|
||||
call assert_equal('"' .. cmd .. " \<Tab>", @:)
|
||||
endfor
|
||||
endfunc
|
||||
|
||||
" vim: shiftwidth=2 sts=2 expandtab
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
" Tests for multi-line regexps with ":s".
|
||||
" Tests for the substitute (:s) command
|
||||
|
||||
source shared.vim
|
||||
source check.vim
|
||||
@@ -1000,5 +1000,287 @@ func Test_using_old_sub()
|
||||
set nocompatible
|
||||
endfunc
|
||||
|
||||
" Test for the 2-letter and 3-letter :substitute commands
|
||||
func Test_substitute_short_cmd()
|
||||
new
|
||||
call setline(1, ['one', 'one one one'])
|
||||
s/one/two
|
||||
call cursor(2, 1)
|
||||
|
||||
" :sc
|
||||
call feedkeys(":sc\<CR>y", 'xt')
|
||||
call assert_equal('two one one', getline(2))
|
||||
|
||||
" :scg
|
||||
call setline(2, 'one one one')
|
||||
call feedkeys(":scg\<CR>nyq", 'xt')
|
||||
call assert_equal('one two one', getline(2))
|
||||
|
||||
" :sci
|
||||
call setline(2, 'ONE One onE')
|
||||
call feedkeys(":sci\<CR>y", 'xt')
|
||||
call assert_equal('two One onE', getline(2))
|
||||
|
||||
" :scI
|
||||
set ignorecase
|
||||
call setline(2, 'ONE One one')
|
||||
call feedkeys(":scI\<CR>y", 'xt')
|
||||
call assert_equal('ONE One two', getline(2))
|
||||
set ignorecase&
|
||||
|
||||
" :scn
|
||||
call setline(2, 'one one one')
|
||||
let t = execute('scn')->split("\n")
|
||||
call assert_equal(['1 match on 1 line'], t)
|
||||
call assert_equal('one one one', getline(2))
|
||||
|
||||
" :scp
|
||||
call setline(2, "\tone one one")
|
||||
redir => output
|
||||
call feedkeys(":scp\<CR>y", 'xt')
|
||||
redir END
|
||||
call assert_equal(' two one one', output->split("\n")[-1])
|
||||
call assert_equal("\ttwo one one", getline(2))
|
||||
|
||||
" :scl
|
||||
call setline(2, "\tone one one")
|
||||
redir => output
|
||||
call feedkeys(":scl\<CR>y", 'xt')
|
||||
redir END
|
||||
call assert_equal("^Itwo one one$", output->split("\n")[-1])
|
||||
call assert_equal("\ttwo one one", getline(2))
|
||||
|
||||
" :sgc
|
||||
call setline(2, 'one one one one one')
|
||||
call feedkeys(":sgc\<CR>nyyq", 'xt')
|
||||
call assert_equal('one two two one one', getline(2))
|
||||
|
||||
" :sg
|
||||
call setline(2, 'one one one')
|
||||
sg
|
||||
call assert_equal('two two two', getline(2))
|
||||
|
||||
" :sgi
|
||||
call setline(2, 'ONE One onE')
|
||||
sgi
|
||||
call assert_equal('two two two', getline(2))
|
||||
|
||||
" :sgI
|
||||
set ignorecase
|
||||
call setline(2, 'ONE One one')
|
||||
sgI
|
||||
call assert_equal('ONE One two', getline(2))
|
||||
set ignorecase&
|
||||
|
||||
" :sgn
|
||||
call setline(2, 'one one one')
|
||||
let t = execute('sgn')->split("\n")
|
||||
call assert_equal(['3 matches on 1 line'], t)
|
||||
call assert_equal('one one one', getline(2))
|
||||
|
||||
" :sgp
|
||||
call setline(2, "\tone one one")
|
||||
redir => output
|
||||
sgp
|
||||
redir END
|
||||
call assert_equal(' two two two', output->split("\n")[-1])
|
||||
call assert_equal("\ttwo two two", getline(2))
|
||||
|
||||
" :sgl
|
||||
call setline(2, "\tone one one")
|
||||
redir => output
|
||||
sgl
|
||||
redir END
|
||||
call assert_equal("^Itwo two two$", output->split("\n")[-1])
|
||||
call assert_equal("\ttwo two two", getline(2))
|
||||
|
||||
" :sgr
|
||||
call setline(2, "one one one")
|
||||
call cursor(2, 1)
|
||||
s/abc/xyz/e
|
||||
let @/ = 'one'
|
||||
sgr
|
||||
call assert_equal('xyz xyz xyz', getline(2))
|
||||
|
||||
" :sic
|
||||
call cursor(1, 1)
|
||||
s/one/two/e
|
||||
call setline(2, "ONE One one")
|
||||
call cursor(2, 1)
|
||||
call feedkeys(":sic\<CR>y", 'xt')
|
||||
call assert_equal('two One one', getline(2))
|
||||
|
||||
" :si
|
||||
call setline(2, "ONE One one")
|
||||
si
|
||||
call assert_equal('two One one', getline(2))
|
||||
|
||||
" :siI
|
||||
call setline(2, "ONE One one")
|
||||
siI
|
||||
call assert_equal('ONE One two', getline(2))
|
||||
|
||||
" :sin
|
||||
call setline(2, 'ONE One onE')
|
||||
let t = execute('sin')->split("\n")
|
||||
call assert_equal(['1 match on 1 line'], t)
|
||||
call assert_equal('ONE One onE', getline(2))
|
||||
|
||||
" :sip
|
||||
call setline(2, "\tONE One onE")
|
||||
redir => output
|
||||
sip
|
||||
redir END
|
||||
call assert_equal(' two One onE', output->split("\n")[-1])
|
||||
call assert_equal("\ttwo One onE", getline(2))
|
||||
|
||||
" :sir
|
||||
call setline(2, "ONE One onE")
|
||||
call cursor(2, 1)
|
||||
s/abc/xyz/e
|
||||
let @/ = 'one'
|
||||
sir
|
||||
call assert_equal('xyz One onE', getline(2))
|
||||
|
||||
" :sIc
|
||||
call cursor(1, 1)
|
||||
s/one/two/e
|
||||
call setline(2, "ONE One one")
|
||||
call cursor(2, 1)
|
||||
call feedkeys(":sIc\<CR>y", 'xt')
|
||||
call assert_equal('ONE One two', getline(2))
|
||||
|
||||
" :sIg
|
||||
call setline(2, "ONE one onE one")
|
||||
sIg
|
||||
call assert_equal('ONE two onE two', getline(2))
|
||||
|
||||
" :sIi
|
||||
call setline(2, "ONE One one")
|
||||
sIi
|
||||
call assert_equal('two One one', getline(2))
|
||||
|
||||
" :sI
|
||||
call setline(2, "ONE One one")
|
||||
sI
|
||||
call assert_equal('ONE One two', getline(2))
|
||||
|
||||
" :sIn
|
||||
call setline(2, 'ONE One one')
|
||||
let t = execute('sIn')->split("\n")
|
||||
call assert_equal(['1 match on 1 line'], t)
|
||||
call assert_equal('ONE One one', getline(2))
|
||||
|
||||
" :sIp
|
||||
call setline(2, "\tONE One one")
|
||||
redir => output
|
||||
sIp
|
||||
redir END
|
||||
call assert_equal(' ONE One two', output->split("\n")[-1])
|
||||
call assert_equal("\tONE One two", getline(2))
|
||||
|
||||
" :sIl
|
||||
call setline(2, "\tONE onE one")
|
||||
redir => output
|
||||
sIl
|
||||
redir END
|
||||
call assert_equal("^IONE onE two$", output->split("\n")[-1])
|
||||
call assert_equal("\tONE onE two", getline(2))
|
||||
|
||||
" :sIr
|
||||
call setline(2, "ONE one onE")
|
||||
call cursor(2, 1)
|
||||
s/abc/xyz/e
|
||||
let @/ = 'one'
|
||||
sIr
|
||||
call assert_equal('ONE xyz onE', getline(2))
|
||||
|
||||
" :src
|
||||
call setline(2, "ONE one one")
|
||||
call cursor(2, 1)
|
||||
s/abc/xyz/e
|
||||
let @/ = 'one'
|
||||
call feedkeys(":src\<CR>y", 'xt')
|
||||
call assert_equal('ONE xyz one', getline(2))
|
||||
|
||||
" :srg
|
||||
call setline(2, "one one one")
|
||||
call cursor(2, 1)
|
||||
s/abc/xyz/e
|
||||
let @/ = 'one'
|
||||
srg
|
||||
call assert_equal('xyz xyz xyz', getline(2))
|
||||
|
||||
" :sri
|
||||
call setline(2, "ONE one onE")
|
||||
call cursor(2, 1)
|
||||
s/abc/xyz/e
|
||||
let @/ = 'one'
|
||||
sri
|
||||
call assert_equal('xyz one onE', getline(2))
|
||||
|
||||
" :srI
|
||||
call setline(2, "ONE one onE")
|
||||
call cursor(2, 1)
|
||||
s/abc/xyz/e
|
||||
let @/ = 'one'
|
||||
srI
|
||||
call assert_equal('ONE xyz onE', getline(2))
|
||||
|
||||
" :srn
|
||||
call setline(2, "ONE one onE")
|
||||
call cursor(2, 1)
|
||||
s/abc/xyz/e
|
||||
let @/ = 'one'
|
||||
let t = execute('srn')->split("\n")
|
||||
call assert_equal(['1 match on 1 line'], t)
|
||||
call assert_equal('ONE one onE', getline(2))
|
||||
|
||||
" :srp
|
||||
call setline(2, "\tONE one onE")
|
||||
call cursor(2, 1)
|
||||
s/abc/xyz/e
|
||||
let @/ = 'one'
|
||||
redir => output
|
||||
srp
|
||||
redir END
|
||||
call assert_equal(' ONE xyz onE', output->split("\n")[-1])
|
||||
call assert_equal("\tONE xyz onE", getline(2))
|
||||
|
||||
" :srl
|
||||
call setline(2, "\tONE one onE")
|
||||
call cursor(2, 1)
|
||||
s/abc/xyz/e
|
||||
let @/ = 'one'
|
||||
redir => output
|
||||
srl
|
||||
redir END
|
||||
call assert_equal("^IONE xyz onE$", output->split("\n")[-1])
|
||||
call assert_equal("\tONE xyz onE", getline(2))
|
||||
|
||||
" :sr
|
||||
call setline(2, "ONE one onE")
|
||||
call cursor(2, 1)
|
||||
s/abc/xyz/e
|
||||
let @/ = 'one'
|
||||
sr
|
||||
call assert_equal('ONE xyz onE', getline(2))
|
||||
|
||||
" :sce
|
||||
s/abc/xyz/e
|
||||
call assert_fails("sc", 'E486:')
|
||||
sce
|
||||
" :sge
|
||||
call assert_fails("sg", 'E486:')
|
||||
sge
|
||||
" :sie
|
||||
call assert_fails("si", 'E486:')
|
||||
sie
|
||||
" :sIe
|
||||
call assert_fails("sI", 'E486:')
|
||||
sIe
|
||||
|
||||
bw!
|
||||
endfunc
|
||||
|
||||
" vim: shiftwidth=2 sts=2 expandtab
|
||||
|
||||
@@ -750,6 +750,8 @@ static char *(features[]) =
|
||||
|
||||
static int included_patches[] =
|
||||
{ /* Add new patch number below this line */
|
||||
/**/
|
||||
4628,
|
||||
/**/
|
||||
4627,
|
||||
/**/
|
||||
|
||||
Reference in New Issue
Block a user