forked from aniani/vim
patch 8.2.0197: some Ex commands not sufficiently tested
Problem: Some Ex commands not sufficiently tested. Solution: Add more tests. (Yegappan Lakshmanan, closes #5565)
This commit is contained in:
@@ -25,4 +25,34 @@ func Test_global_error()
|
||||
call assert_fails('g/\(/y', 'E476:')
|
||||
endfunc
|
||||
|
||||
" Test for printing lines using :g with different search patterns
|
||||
func Test_global_print()
|
||||
new
|
||||
call setline(1, ['foo', 'bar', 'foo', 'foo'])
|
||||
let @/ = 'foo'
|
||||
let t = execute("g/")->trim()->split("\n")
|
||||
call assert_equal(['foo', 'foo', 'foo'], t)
|
||||
|
||||
" Test for Vi compatible patterns
|
||||
let @/ = 'bar'
|
||||
let t = execute('g\/')->trim()->split("\n")
|
||||
call assert_equal(['bar'], t)
|
||||
|
||||
normal gg
|
||||
s/foo/foo/
|
||||
let t = execute('g\&')->trim()->split("\n")
|
||||
call assert_equal(['foo', 'foo', 'foo'], t)
|
||||
|
||||
let @/ = 'bar'
|
||||
let t = execute('g?')->trim()->split("\n")
|
||||
call assert_equal(['bar'], t)
|
||||
|
||||
" Test for the 'Pattern found in every line' message
|
||||
let v:statusmsg = ''
|
||||
v/foo\|bar/p
|
||||
call assert_notequal('', v:statusmsg)
|
||||
|
||||
close!
|
||||
endfunc
|
||||
|
||||
" vim: shiftwidth=2 sts=2 expandtab
|
||||
|
@@ -12,6 +12,18 @@ endfunc
|
||||
func Test_help_errors()
|
||||
call assert_fails('help doesnotexist', 'E149:')
|
||||
call assert_fails('help!', 'E478:')
|
||||
if has('multi_lang')
|
||||
call assert_fails('help help@xy', 'E661:')
|
||||
endif
|
||||
|
||||
let save_hf = &helpfile
|
||||
set helpfile=help_missing
|
||||
help
|
||||
call assert_equal(1, winnr('$'))
|
||||
call assert_notequal('help', &buftype)
|
||||
let &helpfile = save_hf
|
||||
|
||||
call assert_fails('help ' . repeat('a', 1048), 'E149:')
|
||||
|
||||
new
|
||||
set keywordprg=:help
|
||||
|
@@ -11,6 +11,11 @@ func Test_help_tagjump()
|
||||
call assert_true(getline('.') =~ '\*bar\*')
|
||||
helpclose
|
||||
|
||||
help "
|
||||
call assert_equal("help", &filetype)
|
||||
call assert_true(getline('.') =~ '\*quote\*')
|
||||
helpclose
|
||||
|
||||
help "*
|
||||
call assert_equal("help", &filetype)
|
||||
call assert_true(getline('.') =~ '\*quotestar\*')
|
||||
@@ -74,11 +79,40 @@ func Test_help_tagjump()
|
||||
call assert_true(getline('.') =~ '\*i_^_CTRL-D\*')
|
||||
helpclose
|
||||
|
||||
help i^x^y
|
||||
call assert_equal("help", &filetype)
|
||||
call assert_true(getline('.') =~ '\*i_CTRL-X_CTRL-Y\*')
|
||||
helpclose
|
||||
|
||||
exe "help i\<C-\>\<C-G>"
|
||||
call assert_equal("help", &filetype)
|
||||
call assert_true(getline('.') =~ '\*i_CTRL-\\_CTRL-G\*')
|
||||
helpclose
|
||||
|
||||
exec "help \<C-V>"
|
||||
call assert_equal("help", &filetype)
|
||||
call assert_true(getline('.') =~ '\*CTRL-V\*')
|
||||
helpclose
|
||||
|
||||
help /\|
|
||||
call assert_equal("help", &filetype)
|
||||
call assert_true(getline('.') =~ '\*/\\bar\*')
|
||||
helpclose
|
||||
|
||||
help CTRL-\_CTRL-N
|
||||
call assert_equal("help", &filetype)
|
||||
call assert_true(getline('.') =~ '\*CTRL-\\_CTRL-N\*')
|
||||
helpclose
|
||||
|
||||
help `:pwd`,
|
||||
call assert_equal("help", &filetype)
|
||||
call assert_true(getline('.') =~ '\*:pwd\*')
|
||||
helpclose
|
||||
|
||||
help `:ls`.
|
||||
call assert_equal("help", &filetype)
|
||||
call assert_true(getline('.') =~ '\*:ls\*')
|
||||
helpclose
|
||||
|
||||
exec "help! ('textwidth'"
|
||||
call assert_equal("help", &filetype)
|
||||
@@ -110,6 +144,15 @@ func Test_help_tagjump()
|
||||
call assert_true(getline('.') =~ '\*{address}\*')
|
||||
helpclose
|
||||
|
||||
" Use special patterns in the help tag
|
||||
for h in ['/\w', '/\%^', '/\%(', '/\zs', '/\@<=', '/\_$', '[++opt]', '/\{']
|
||||
exec "help! " . h
|
||||
call assert_equal("help", &filetype)
|
||||
let pat = '\*' . escape(h, '\$[') . '\*'
|
||||
call assert_true(getline('.') =~ pat, pat)
|
||||
helpclose
|
||||
endfor
|
||||
|
||||
exusage
|
||||
call assert_equal("help", &filetype)
|
||||
call assert_true(getline('.') =~ '\*:index\*')
|
||||
|
@@ -659,4 +659,17 @@ func Test_buftype()
|
||||
close!
|
||||
endfunc
|
||||
|
||||
" Test for the 'shellquote' option
|
||||
func Test_shellquote()
|
||||
CheckUnix
|
||||
set shellquote=#
|
||||
set verbose=20
|
||||
redir => v
|
||||
silent! !echo Hello
|
||||
redir END
|
||||
set verbose&
|
||||
set shellquote&
|
||||
call assert_match(': "#echo Hello#"', v)
|
||||
endfunc
|
||||
|
||||
" vim: shiftwidth=2 sts=2 expandtab
|
||||
|
@@ -51,10 +51,12 @@ func Test_substitute_variants()
|
||||
\ { 'cmd': ':s/t/r/cg', 'exp': 'Tesring srring', 'prompt': 'a' },
|
||||
\ { 'cmd': ':s/t/r/ci', 'exp': 'resting string', 'prompt': 'y' },
|
||||
\ { 'cmd': ':s/t/r/cI', 'exp': 'Tesring string', 'prompt': 'y' },
|
||||
\ { 'cmd': ':s/t/r/c', 'exp': 'Testing string', 'prompt': 'n' },
|
||||
\ { 'cmd': ':s/t/r/cn', 'exp': ln },
|
||||
\ { 'cmd': ':s/t/r/cp', 'exp': 'Tesring string', 'prompt': 'y' },
|
||||
\ { 'cmd': ':s/t/r/cl', 'exp': 'Tesring string', 'prompt': 'y' },
|
||||
\ { 'cmd': ':s/t/r/gc', 'exp': 'Tesring srring', 'prompt': 'a' },
|
||||
\ { 'cmd': ':s/i/I/gc', 'exp': 'TestIng string', 'prompt': 'l' },
|
||||
\ { 'cmd': ':s/foo/bar/ge', 'exp': ln },
|
||||
\ { 'cmd': ':s/t/r/g', 'exp': 'Tesring srring' },
|
||||
\ { 'cmd': ':s/t/r/gi', 'exp': 'resring srring' },
|
||||
@@ -86,6 +88,7 @@ func Test_substitute_variants()
|
||||
\ { 'cmd': ':s//r/rp', 'exp': 'Testr string' },
|
||||
\ { 'cmd': ':s//r/rl', 'exp': 'Testr string' },
|
||||
\ { 'cmd': ':s//r/r', 'exp': 'Testr string' },
|
||||
\ { 'cmd': ':s/i/I/gc', 'exp': 'Testing string', 'prompt': 'q' },
|
||||
\]
|
||||
|
||||
for var in variants
|
||||
@@ -176,6 +179,10 @@ func Test_substitute_join()
|
||||
call assert_equal(["foo\tbarbar\<C-H>foo"], getline(1, '$'))
|
||||
call assert_equal('\n', histget("search", -1))
|
||||
|
||||
call setline(1, ['foo', 'bar', 'baz', 'qux'])
|
||||
call execute('1,2s/\n//')
|
||||
call assert_equal(['foobarbaz', 'qux'], getline(1, '$'))
|
||||
|
||||
bwipe!
|
||||
endfunc
|
||||
|
||||
@@ -190,6 +197,11 @@ func Test_substitute_count()
|
||||
|
||||
call assert_fails('s/foo/bar/0', 'E939:')
|
||||
|
||||
call setline(1, ['foo foo', 'foo foo', 'foo foo', 'foo foo', 'foo foo'])
|
||||
2,4s/foo/bar/ 10
|
||||
call assert_equal(['foo foo', 'foo foo', 'foo foo', 'bar foo', 'bar foo'],
|
||||
\ getline(1, '$'))
|
||||
|
||||
bwipe!
|
||||
endfunc
|
||||
|
||||
@@ -208,6 +220,10 @@ func Test_substitute_flag_n()
|
||||
" No substitution should have been done.
|
||||
call assert_equal(lines, getline(1, '$'))
|
||||
|
||||
%delete _
|
||||
call setline(1, ['A', 'Bar', 'Baz'])
|
||||
call assert_equal("\n1 match on 1 line", execute('s/\nB\@=//gn'))
|
||||
|
||||
bwipe!
|
||||
endfunc
|
||||
|
||||
@@ -748,4 +764,43 @@ func Test_sub_beyond_end()
|
||||
bwipe!
|
||||
endfunc
|
||||
|
||||
" Test for repeating last substitution using :~ and :&r
|
||||
func Test_repeat_last_sub()
|
||||
new
|
||||
call setline(1, ['blue green yellow orange white'])
|
||||
s/blue/red/
|
||||
let @/ = 'yellow'
|
||||
~
|
||||
let @/ = 'white'
|
||||
:&r
|
||||
let @/ = 'green'
|
||||
s//gray
|
||||
call assert_equal('red gray red orange red', getline(1))
|
||||
close!
|
||||
endfunc
|
||||
|
||||
" Test for Vi compatible substitution:
|
||||
" \/{string}/, \?{string}? and \&{string}&
|
||||
func Test_sub_vi_compatibility()
|
||||
new
|
||||
call setline(1, ['blue green yellow orange blue'])
|
||||
let @/ = 'orange'
|
||||
s\/white/
|
||||
let @/ = 'blue'
|
||||
s\?amber?
|
||||
let @/ = 'white'
|
||||
s\&green&
|
||||
call assert_equal('amber green yellow white green', getline(1))
|
||||
close!
|
||||
endfunc
|
||||
|
||||
" Test for substitute with the new text longer than the original text
|
||||
func Test_sub_expand_text()
|
||||
new
|
||||
call setline(1, 'abcabcabcabcabcabcabcabc')
|
||||
s/b/\=repeat('B', 10)/g
|
||||
call assert_equal(repeat('aBBBBBBBBBBc', 8), getline(1))
|
||||
close!
|
||||
endfunc
|
||||
|
||||
" vim: shiftwidth=2 sts=2 expandtab
|
||||
|
@@ -433,6 +433,21 @@ func Test_format_align()
|
||||
call assert_equal("\t\t Vim", getline(1))
|
||||
q!
|
||||
|
||||
" align text with 'rightleft'
|
||||
if has('rightleft')
|
||||
new
|
||||
call setline(1, 'Vim')
|
||||
setlocal rightleft
|
||||
left 20
|
||||
setlocal norightleft
|
||||
call assert_equal("\t\t Vim", getline(1))
|
||||
setlocal rightleft
|
||||
right
|
||||
setlocal norightleft
|
||||
call assert_equal("Vim", getline(1))
|
||||
close!
|
||||
endif
|
||||
|
||||
set tw&
|
||||
endfunc
|
||||
|
||||
|
@@ -1,5 +1,7 @@
|
||||
" Tests for the writefile() function and some :write commands.
|
||||
|
||||
source check.vim
|
||||
|
||||
func Test_writefile()
|
||||
let f = tempname()
|
||||
call writefile(["over","written"], f, "b")
|
||||
@@ -183,9 +185,7 @@ endfunc
|
||||
" Test for ':w !<cmd>' to pipe lines from the current buffer to an external
|
||||
" command.
|
||||
func Test_write_pipe_to_cmd()
|
||||
if !has('unix')
|
||||
return
|
||||
endif
|
||||
CheckUnix
|
||||
new
|
||||
call setline(1, ['L1', 'L2', 'L3', 'L4'])
|
||||
2,3w !cat > Xfile
|
||||
|
@@ -742,6 +742,8 @@ static char *(features[]) =
|
||||
|
||||
static int included_patches[] =
|
||||
{ /* Add new patch number below this line */
|
||||
/**/
|
||||
197,
|
||||
/**/
|
||||
196,
|
||||
/**/
|
||||
|
Reference in New Issue
Block a user