]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 8.2.0197: some Ex commands not sufficiently tested v8.2.0197
authorBram Moolenaar <Bram@vim.org>
Sun, 2 Feb 2020 14:32:13 +0000 (15:32 +0100)
committerBram Moolenaar <Bram@vim.org>
Sun, 2 Feb 2020 14:32:13 +0000 (15:32 +0100)
Problem:    Some Ex commands not sufficiently tested.
Solution:   Add more tests. (Yegappan Lakshmanan, closes #5565)

src/testdir/test_global.vim
src/testdir/test_help.vim
src/testdir/test_help_tagjump.vim
src/testdir/test_options.vim
src/testdir/test_substitute.vim
src/testdir/test_textformat.vim
src/testdir/test_writefile.vim
src/version.c

index 044839f35477f00ff910c77c4fc59e3b4eda027a..8ce68531ef6eef64f6ce0bd7f319549d74909922 100644 (file)
@@ -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
index 4f46a44c90e2f3ed8f8f6ffed7ab8314f043d655..ee5ace8f74d287413975fa42a42aa4995b3c43a6 100644 (file)
@@ -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
index 46aa6a1caffd2c8d54feccaeb2cf473ba6e0fbc4..dbe0978169a5b936958b129f943c3cf9e6b238f6 100644 (file)
@@ -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\*')
index 0fcc4955f8e0ab85b60e662d187e048116d30854..f8d09fefcf12cbe550718f4fd5657873f98af891 100644 (file)
@@ -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
index abdbf687d6edddb90f700a585659b91980ab1a64..4db7b3ea4cca0059bf069493bdd78062a906ab62 100644 (file)
@@ -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
index 74d6bfeb4474485f0fda28f171bd36259ae9cd9a..fd27c7b7236af3932df90b62cc656cabda5f8b4e 100644 (file)
@@ -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
 
index db17e6f9bc19eb558b053a5b36c8b63a96523e9e..98a06eb01154cdcb452c7a2296299ec6f0289825 100644 (file)
@@ -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
index 8c5cb53dc7ea068a6367b2aa190587a771ecfed3..800d7e56971062de9ddd2b73b2294b002d337ef5 100644 (file)
@@ -742,6 +742,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    197,
 /**/
     196,
 /**/