]> granicus.if.org Git - vim/commitdiff
patch 8.2.0174: various commands not completely tested v8.2.0174
authorBram Moolenaar <Bram@vim.org>
Wed, 29 Jan 2020 20:57:34 +0000 (21:57 +0100)
committerBram Moolenaar <Bram@vim.org>
Wed, 29 Jan 2020 20:57:34 +0000 (21:57 +0100)
Problem:    Various commands not completely tested.
Solution:   Add more test cases. (Yegappan Lakshmanan, closes #5551)

12 files changed:
src/testdir/test_excmd.vim
src/testdir/test_fnameescape.vim
src/testdir/test_ga.vim
src/testdir/test_global.vim
src/testdir/test_move.vim
src/testdir/test_options.vim
src/testdir/test_packadd.vim
src/testdir/test_sort.vim
src/testdir/test_substitute.vim
src/testdir/test_textformat.vim
src/testdir/test_writefile.vim
src/version.c

index 992fc3de07b4f00258d6590648e481c0ed0717e8..37cc24cb4cfebefe7b4c7a3543a52930f78f06bb 100644 (file)
@@ -44,3 +44,129 @@ func Test_buffers_lastused()
   bwipeout bufb
   bwipeout bufc
 endfunc
+
+" Test for the :copy command
+func Test_copy()
+  new
+
+  call setline(1, ['L1', 'L2', 'L3', 'L4'])
+  " copy lines in a range to inside the range
+  1,3copy 2
+  call assert_equal(['L1', 'L2', 'L1', 'L2', 'L3', 'L3', 'L4'], getline(1, 7))
+
+  close!
+endfunc
+
+" Test for the :file command
+func Test_file_cmd()
+  call assert_fails('3file', 'E474:')
+  call assert_fails('0,0file', 'E474:')
+  call assert_fails('0file abc', 'E474:')
+endfunc
+
+" Test for the :drop command
+func Test_drop_cmd()
+  call writefile(['L1', 'L2'], 'Xfile')
+  enew | only
+  drop Xfile
+  call assert_equal('L2', getline(2))
+  " Test for switching to an existing window
+  below new
+  drop Xfile
+  call assert_equal(1, winnr())
+  " Test for splitting the current window
+  enew | only
+  set modified
+  drop Xfile
+  call assert_equal(2, winnr('$'))
+  " Check for setting the argument list
+  call assert_equal(['Xfile'], argv())
+  enew | only!
+  call delete('Xfile')
+endfunc
+
+" Test for the :append command
+func Test_append_cmd()
+  new
+  call setline(1, ['  L1'])
+  call feedkeys(":append\<CR>  L2\<CR>  L3\<CR>.\<CR>", 'xt')
+  call assert_equal(['  L1', '  L2', '  L3'], getline(1, '$'))
+  %delete _
+  " append after a specific line
+  call setline(1, ['  L1', '  L2', '  L3'])
+  call feedkeys(":2append\<CR>  L4\<CR>  L5\<CR>.\<CR>", 'xt')
+  call assert_equal(['  L1', '  L2', '  L4', '  L5', '  L3'], getline(1, '$'))
+  %delete _
+  " append with toggling 'autoindent'
+  call setline(1, ['  L1'])
+  call feedkeys(":append!\<CR>  L2\<CR>  L3\<CR>.\<CR>", 'xt')
+  call assert_equal(['  L1', '    L2', '      L3'], getline(1, '$'))
+  call assert_false(&autoindent)
+  %delete _
+  " append with 'autoindent' set and toggling 'autoindent'
+  set autoindent
+  call setline(1, ['  L1'])
+  call feedkeys(":append!\<CR>  L2\<CR>  L3\<CR>.\<CR>", 'xt')
+  call assert_equal(['  L1', '  L2', '  L3'], getline(1, '$'))
+  call assert_true(&autoindent)
+  set autoindent&
+  close!
+endfunc
+
+" Test for the :insert command
+func Test_insert_cmd()
+  new
+  call setline(1, ['  L1'])
+  call feedkeys(":insert\<CR>  L2\<CR>  L3\<CR>.\<CR>", 'xt')
+  call assert_equal(['  L2', '  L3', '  L1'], getline(1, '$'))
+  %delete _
+  " insert before a specific line
+  call setline(1, ['  L1', '  L2', '  L3'])
+  call feedkeys(":2insert\<CR>  L4\<CR>  L5\<CR>.\<CR>", 'xt')
+  call assert_equal(['  L1', '  L4', '  L5', '  L2', '  L3'], getline(1, '$'))
+  %delete _
+  " insert with toggling 'autoindent'
+  call setline(1, ['  L1'])
+  call feedkeys(":insert!\<CR>  L2\<CR>  L3\<CR>.\<CR>", 'xt')
+  call assert_equal(['    L2', '      L3', '  L1'], getline(1, '$'))
+  call assert_false(&autoindent)
+  %delete _
+  " insert with 'autoindent' set and toggling 'autoindent'
+  set autoindent
+  call setline(1, ['  L1'])
+  call feedkeys(":insert!\<CR>  L2\<CR>  L3\<CR>.\<CR>", 'xt')
+  call assert_equal(['  L2', '  L3', '  L1'], getline(1, '$'))
+  call assert_true(&autoindent)
+  set autoindent&
+  close!
+endfunc
+
+" Test for the :change command
+func Test_change_cmd()
+  new
+  call setline(1, ['  L1', 'L2', 'L3'])
+  call feedkeys(":change\<CR>  L4\<CR>  L5\<CR>.\<CR>", 'xt')
+  call assert_equal(['  L4', '  L5', 'L2', 'L3'], getline(1, '$'))
+  %delete _
+  " change a specific line
+  call setline(1, ['  L1', '  L2', '  L3'])
+  call feedkeys(":2change\<CR>  L4\<CR>  L5\<CR>.\<CR>", 'xt')
+  call assert_equal(['  L1', '  L4', '  L5', '  L3'], getline(1, '$'))
+  %delete _
+  " change with toggling 'autoindent'
+  call setline(1, ['  L1', 'L2', 'L3'])
+  call feedkeys(":change!\<CR>  L4\<CR>  L5\<CR>.\<CR>", 'xt')
+  call assert_equal(['    L4', '      L5', 'L2', 'L3'], getline(1, '$'))
+  call assert_false(&autoindent)
+  %delete _
+  " change with 'autoindent' set and toggling 'autoindent'
+  set autoindent
+  call setline(1, ['  L1', 'L2', 'L3'])
+  call feedkeys(":change!\<CR>  L4\<CR>  L5\<CR>.\<CR>", 'xt')
+  call assert_equal(['  L4', '  L5', 'L2', 'L3'], getline(1, '$'))
+  call assert_true(&autoindent)
+  set autoindent&
+  close!
+endfunc
+
+" vim: shiftwidth=2 sts=2 expandtab
index b0fdb3a032accd9e3d15c94aadccf956433be3eb..cdb96ba5ff0b4b082e288207149e594df6c97d3d 100644 (file)
@@ -18,4 +18,10 @@ func Test_fnameescape()
   endtry
   call assert_true(status, "ExclamationMark")
   call delete(fname)
+
+  call assert_equal('\-', fnameescape('-'))
+  call assert_equal('\+', fnameescape('+'))
+  call assert_equal('\>', fnameescape('>'))
 endfunc
+
+" vim: shiftwidth=2 sts=2 expandtab
index ea3d211aebfbee053d18d1089b6a9514e2f0a51f..22f030c9897277d67ab5b02c86bf87a7ce1466ec 100644 (file)
@@ -18,6 +18,7 @@ func Test_ga_command()
   call assert_equal("\nNUL",                             Do_ga(''))
   call assert_equal("\n<^A>  1,  Hex 01,  Oct 001, Digr SH",    Do_ga("\x01"))
   call assert_equal("\n<^I>  9,  Hex 09,  Oct 011, Digr HT",    Do_ga("\t"))
+  call assert_equal("\n<^@>  0,  Hex 00,  Octal 000",    Do_ga("\n"))
 
   call assert_equal("\n<e>  101,  Hex 65,  Octal 145",   Do_ga('e'))
 
@@ -29,5 +30,13 @@ func Test_ga_command()
   call assert_equal("\n<e>  101,  Hex 65,  Octal 145 < ́> 769, Hex 0301, Octal 1401", Do_ga("e\u0301"))
   call assert_equal("\n<e>  101,  Hex 65,  Octal 145 < ́> 769, Hex 0301, Octal 1401 < ̱> 817, Hex 0331, Octal 1461", Do_ga("e\u0301\u0331"))
   call assert_equal("\n<e>  101,  Hex 65,  Octal 145 < ́> 769, Hex 0301, Octal 1401 < ̱> 817, Hex 0331, Octal 1461 < ̸> 824, Hex 0338, Octal 1470", Do_ga("e\u0301\u0331\u0338"))
+
+  " When using Mac fileformat, CR instead of NL is used for line termination
+  enew!
+  set fileformat=mac
+  call assert_equal("\n<^J>  10,  Hex 0a,  Oct 012, Digr NU",    Do_ga("\r"))
+
   bwipe!
 endfunc
+
+" vim: shiftwidth=2 sts=2 expandtab
index bdeaf8e2cf8dbfcd45b193917e710979648bc625..044839f35477f00ff910c77c4fc59e3b4eda027a 100644 (file)
@@ -18,3 +18,11 @@ func Test_nested_global()
   call assert_equal(['nothing', '++found', 'found bad', 'bad'], getline(1, 4))
   bwipe!
 endfunc
+
+func Test_global_error()
+  call assert_fails('g\\a', 'E10:')
+  call assert_fails('g', 'E148:')
+  call assert_fails('g/\(/y', 'E476:')
+endfunc
+
+" vim: shiftwidth=2 sts=2 expandtab
index d774c93dbdb446fcba803295e8afec6eaa78158e..f666a904b0e3d2c674d05bd444cf53e5b056187f 100644 (file)
@@ -35,6 +35,11 @@ func Test_move()
 
   call assert_fails('1,2move 1', 'E134')
   call assert_fails('2,3move 2', 'E134')
+  call assert_fails("move -100", 'E16:')
+  call assert_fails("move +100", 'E16:')
+  call assert_fails('move', 'E16:')
 
   %bwipeout!
 endfunc
+
+" vim: shiftwidth=2 sts=2 expandtab
index 7a74af652acba0791085b7bb239fa0316b7df2bf..e3f2c1067ed5dbe3596226a45833c86bb3768c1f 100644 (file)
@@ -640,3 +640,24 @@ func Test_visualbell()
   set novisualbell
   set belloff=all
 endfunc
+
+" Test for the 'write' option
+func Test_write()
+  new
+  call setline(1, ['L1'])
+  set nowrite
+  call assert_fails('write Xfile', 'E142:')
+  set write
+  close!
+endfunc
+
+" Test for 'buftype' option
+func Test_buftype()
+  new
+  call setline(1, ['L1'])
+  set buftype=nowrite
+  call assert_fails('write', 'E382:')
+  close!
+endfunc
+
+" vim: shiftwidth=2 sts=2 expandtab
index 6d0565b86438f8a7f5984e708cba81d53adaceac..fcb8b8033b267bd56f1a24f2c019bb98fd53f777 100644 (file)
@@ -264,6 +264,8 @@ func Test_helptags()
   call assert_match('look-here', tags1[0])
   let tags2 = readfile(docdir2 . '/tags') 
   call assert_match('look-away', tags2[0])
+
+  call assert_fails('helptags abcxyz', 'E150:')
 endfunc
 
 func Test_colorscheme()
@@ -355,3 +357,5 @@ func Test_runtime()
   runtime! ALL extra/bar.vim
   call assert_equal('runstartopt', g:sequence)
 endfunc
+
+" vim: shiftwidth=2 sts=2 expandtab
index 7da82b0185ab7dc77dc068d1baecca2bba95c34f..4abe31d457ff31fa0be76b8e374dcd09ef856554 100644 (file)
@@ -1150,7 +1150,7 @@ func Test_sort_cmd()
        \    'input' : [
        \       '1.234',
        \       '0.88',
-       \       '123.456',
+       \       '  +  123.456',
        \       '1.15e-6',
        \       '-1.1e3',
        \       '-1.01e3',
@@ -1165,7 +1165,7 @@ func Test_sort_cmd()
        \       '1.15e-6',
        \       '0.88',
        \       '1.234',
-       \       '123.456'
+       \       '  +  123.456'
        \    ]
        \ },
        \ {
@@ -1197,6 +1197,30 @@ func Test_sort_cmd()
        \       'cc',
        \    ]
        \ },
+       \ {
+       \    'name' : 'sort one line buffer',
+       \    'cmd' : 'sort',
+       \    'input' : [
+       \       'single line'
+       \    ],
+       \    'expected' : [
+       \       'single line'
+       \    ]
+       \ },
+       \ {
+       \    'name' : 'sort ignoring case',
+       \    'cmd' : '%sort i',
+       \    'input' : [
+       \       'BB',
+       \       'Cc',
+       \       'aa'
+       \    ],
+       \    'expected' : [
+       \       'aa',
+       \       'BB',
+       \       'Cc'
+       \    ]
+       \ },
        \ ]
 
   for t in tests
@@ -1217,7 +1241,11 @@ func Test_sort_cmd()
     endif
   endfor
 
-  call assert_fails('sort no', 'E474')
+  " Needs atleast two lines for this test
+  call setline(1, ['line1', 'line2'])
+  call assert_fails('sort no', 'E474:')
+  call assert_fails('sort c', 'E475:')
+  call assert_fails('sort #pat%', 'E682:')
 
   enew!
 endfunc
@@ -1321,4 +1349,46 @@ func Test_sort_cmd_report()
     " the output comes from the :g command, not from the :sort
     call assert_match("6 fewer lines", res)
     enew!
-  endfunc
+endfunc
+
+" Test for a :sort command followed by another command
+func Test_sort_followed_by_cmd()
+  new
+  let var = ''
+  call setline(1, ['cc', 'aa', 'bb'])
+  %sort | let var = "sortcmdtest"
+  call assert_equal(var, "sortcmdtest")
+  call assert_equal(['aa', 'bb', 'cc'], getline(1, '$'))
+  " Test for :sort followed by a comment
+  call setline(1, ['3b', '1c', '2a'])
+  %sort /\d\+/ " sort alphabetically
+  call assert_equal(['2a', '3b', '1c'], getline(1, '$'))
+  close!
+endfunc
+
+" Test for :sort using last search pattern
+func Test_sort_last_search_pat()
+  new
+  let @/ = '\d\+'
+  call setline(1, ['3b', '1c', '2a'])
+  sort //
+  call assert_equal(['2a', '3b', '1c'], getline(1, '$'))
+  close!
+endfunc
+
+" Test for retaining marks across a :sort
+func Test_sort_with_marks()
+  new
+  call setline(1, ['cc', 'aa', 'bb'])
+  call setpos("'c", [0, 1, 0, 0])
+  call setpos("'a", [0, 2, 0, 0])
+  call setpos("'b", [0, 3, 0, 0])
+  %sort
+  call assert_equal(['aa', 'bb', 'cc'], getline(1, '$'))
+  call assert_equal(2, line("'a"))
+  call assert_equal(3, line("'b"))
+  call assert_equal(1, line("'c"))
+  close!
+endfunc
+
+" vim: shiftwidth=2 sts=2 expandtab
index c7532fbb4bd7467a444a9f745f755c135d226091..abdbf687d6edddb90f700a585659b91980ab1a64 100644 (file)
@@ -218,6 +218,8 @@ func Test_substitute_errors()
   call assert_fails('s/FOO/bar/', 'E486:')
   call assert_fails('s/foo/bar/@', 'E488:')
   call assert_fails('s/\(/bar/', 'E476:')
+  call assert_fails('s afooabara', 'E146:')
+  call assert_fails('s\\a', 'E10:')
 
   setl nomodifiable
   call assert_fails('s/foo/bar/', 'E21:')
@@ -745,3 +747,5 @@ func Test_sub_beyond_end()
   call assert_equal('#', getline(1))
   bwipe!
 endfunc
+
+" vim: shiftwidth=2 sts=2 expandtab
index 2223be952c793178d98ee98afcdbbaa774c5774b..a49ef5c64ce133863eb5fb5a9152941a7068ecc3 100644 (file)
@@ -424,6 +424,14 @@ func Test_format_align()
              \ ], getline(1, '$'))
   enew!
 
+  " align text with 'wrapmargin'
+  call setline(1, ['Vim'])
+  set textwidth=0
+  set wrapmargin=60
+  right
+  call assert_equal("\t\t Vim", getline(1))
+  set wrapmargin&
+
   set tw&
 endfunc
 
index 8eb2e7809f7cfc7c57a28189b83028be332dbc7d..db17e6f9bc19eb558b053a5b36c8b63a96523e9e 100644 (file)
@@ -179,3 +179,68 @@ func Test_writefile_autowrite_nowrite()
   bwipe!
   set noautowrite
 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
+  new
+  call setline(1, ['L1', 'L2', 'L3', 'L4'])
+  2,3w !cat > Xfile
+  call assert_equal(['L2', 'L3'], readfile('Xfile'))
+  close!
+  call delete('Xfile')
+endfunc
+
+" Test for :saveas
+func Test_saveas()
+  call assert_fails('saveas', 'E471:')
+  call writefile(['L1'], 'Xfile')
+  new Xfile
+  new
+  call setline(1, ['L1'])
+  call assert_fails('saveas Xfile', 'E139:')
+  close!
+  enew | only
+  call delete('Xfile')
+endfunc
+
+func Test_write_errors()
+  " Test for writing partial buffer
+  call writefile(['L1', 'L2', 'L3'], 'Xfile')
+  new Xfile
+  call assert_fails('1,2write', 'E140:')
+  close!
+
+  " Try to overwrite a directory
+  if has('unix')
+    call mkdir('Xdir1')
+    call assert_fails('write Xdir1', 'E17:')
+    call delete('Xdir1', 'd')
+  endif
+
+  " Test for :wall for a buffer with no name
+  enew | only
+  call setline(1, ['L1'])
+  call assert_fails('wall', 'E141:')
+  enew!
+
+  " Test for writing a 'readonly' file
+  new Xfile
+  set readonly
+  call assert_fails('write', 'E45:')
+  close
+
+  " Test for writing to a read-only file
+  new Xfile
+  call setfperm('Xfile', 'r--r--r--')
+  call assert_fails('write', 'E505:')
+  call setfperm('Xfile', 'rw-rw-rw-')
+  close
+
+  call delete('Xfile')
+endfunc
+
+" vim: shiftwidth=2 sts=2 expandtab
index 33fe21c2c318b10d8eb9aa5a774212bc17ac3273..df1fe0d045ecfcf2d8a810a681b19cf660db8d47 100644 (file)
@@ -742,6 +742,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    174,
 /**/
     173,
 /**/