aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2022-06-24 06:22:22 +0800
committerzeertzjq <zeertzjq@outlook.com>2022-06-24 07:26:06 +0800
commit764dc7c383235950c153a133d399523e2bbffed4 (patch)
treeec7007e2fdac3e35304ed2feccfccd6e3b2d20e3
parenta9cb0b8a5a22fe0488f38ad67818111c7765f9d7 (diff)
downloadrneovim-764dc7c383235950c153a133d399523e2bbffed4.tar.gz
rneovim-764dc7c383235950c153a133d399523e2bbffed4.tar.bz2
rneovim-764dc7c383235950c153a133d399523e2bbffed4.zip
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 vim/vim#10019) https://github.com/vim/vim/commit/5e877baf87530d5c4fe4da2c5a6269cf19526c27
-rw-r--r--src/nvim/testdir/test_cmdline.vim13
-rw-r--r--src/nvim/testdir/test_substitute.vim284
2 files changed, 296 insertions, 1 deletions
diff --git a/src/nvim/testdir/test_cmdline.vim b/src/nvim/testdir/test_cmdline.vim
index d26c80077d..4630ddd6e7 100644
--- a/src/nvim/testdir/test_cmdline.vim
+++ b/src/nvim/testdir/test_cmdline.vim
@@ -1220,6 +1220,19 @@ func Test_recalling_cmdline()
cunmap <Plug>(save-cmdline)
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
+
func Check_completion()
call assert_equal('let a', getcmdline())
call assert_equal(6, getcmdpos())
diff --git a/src/nvim/testdir/test_substitute.vim b/src/nvim/testdir/test_substitute.vim
index 979c4a70bc..c45f1e7ec6 100644
--- a/src/nvim/testdir/test_substitute.vim
+++ b/src/nvim/testdir/test_substitute.vim
@@ -1,4 +1,4 @@
-" Tests for multi-line regexps with ":s".
+" Tests for the substitute (:s) command
func Test_multiline_subst()
enew!
@@ -838,5 +838,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