@@ -31,7 +31,8 @@ func s:setup_commands(cchar)
3131 command ! -nargs =* - bang Xnfile <mods> cnfile <bang> <args>
3232 command ! -nargs =* - bang Xpfile <mods> cpfile <bang> <args>
3333 command ! -nargs =* Xexpr <mods> cexpr <args>
34- command ! -nargs =* Xvimgrep <mods> vimgrep <args>
34+ command ! - range -nargs =* Xvimgrep <mods><count> vimgrep <args>
35+ command ! -nargs =* Xvimgrepadd <mods> vimgrepadd <args>
3536 command ! -nargs =* Xgrep <mods> grep <args>
3637 command ! -nargs =* Xgrepadd <mods> grepadd <args>
3738 command ! -nargs =* Xhelpgrep helpgrep <args>
@@ -61,7 +62,8 @@ func s:setup_commands(cchar)
6162 command ! -nargs =* - bang Xnfile <mods> lnfile <bang> <args>
6263 command ! -nargs =* - bang Xpfile <mods> lpfile <bang> <args>
6364 command ! -nargs =* Xexpr <mods> lexpr <args>
64- command ! -nargs =* Xvimgrep <mods> lvimgrep <args>
65+ command ! - range -nargs =* Xvimgrep <mods><count> lvimgrep <args>
66+ command ! -nargs =* Xvimgrepadd <mods> lvimgrepadd <args>
6567 command ! -nargs =* Xgrep <mods> lgrep <args>
6668 command ! -nargs =* Xgrepadd <mods> lgrepadd <args>
6769 command ! -nargs =* Xhelpgrep lhelpgrep <args>
@@ -85,57 +87,52 @@ func XlistTests(cchar)
8587 \ ' non-error 3' , ' Xtestfile3:3:1:Line3' ]
8688
8789 " List only valid entries
88- redir = > result
89- Xlist
90- redir END
91- let l = split (result, " \n " )
90+ let l = split (execute (' Xlist' , ' ' ), " \n " )
9291 call assert_equal ([' 2 Xtestfile1:1 col 3: Line1' ,
9392 \ ' 4 Xtestfile2:2 col 2: Line2' ,
9493 \ ' 6 Xtestfile3:3 col 1: Line3' ], l )
9594
9695 " List all the entries
97- redir = > result
98- Xlist!
99- redir END
100- let l = split (result, " \n " )
96+ let l = split (execute (' Xlist!' , ' ' ), " \n " )
10197 call assert_equal ([' 1: non-error 1' , ' 2 Xtestfile1:1 col 3: Line1' ,
10298 \ ' 3: non-error 2' , ' 4 Xtestfile2:2 col 2: Line2' ,
10399 \ ' 5: non-error 3' , ' 6 Xtestfile3:3 col 1: Line3' ], l )
104100
105101 " List a range of errors
106- redir = > result
107- Xlist 3 ,6
108- redir END
109- let l = split (result, " \n " )
102+ let l = split (execute (' Xlist 3,6' , ' ' ), " \n " )
110103 call assert_equal ([' 4 Xtestfile2:2 col 2: Line2' ,
111104 \ ' 6 Xtestfile3:3 col 1: Line3' ], l )
112105
113- redir = > result
114- Xlist! 3 ,4
115- redir END
116- let l = split (result, " \n " )
106+ let l = split (execute (' Xlist! 3,4' , ' ' ), " \n " )
117107 call assert_equal ([' 3: non-error 2' , ' 4 Xtestfile2:2 col 2: Line2' ], l )
118108
119- redir = > result
120- Xlist -6 ,-4
121- redir END
122- let l = split (result, " \n " )
109+ let l = split (execute (' Xlist -6,-4' , ' ' ), " \n " )
123110 call assert_equal ([' 2 Xtestfile1:1 col 3: Line1' ], l )
124111
125- redir = > result
126- Xlist! -5 ,-3
127- redir END
128- let l = split (result, " \n " )
112+ let l = split (execute (' Xlist! -5,-3' , ' ' ), " \n " )
129113 call assert_equal ([' 2 Xtestfile1:1 col 3: Line1' ,
130114 \ ' 3: non-error 2' , ' 4 Xtestfile2:2 col 2: Line2' ], l )
131115
132116 " Test for '+'
133- redir = > result
134- Xlist! + 2
135- redir END
136- let l = split (result, " \n " )
117+ let l = split (execute (' Xlist! +2' , ' ' ), " \n " )
137118 call assert_equal ([' 2 Xtestfile1:1 col 3: Line1' ,
138119 \ ' 3: non-error 2' , ' 4 Xtestfile2:2 col 2: Line2' ], l )
120+
121+ " Different types of errors
122+ call g: Xsetlist ([{' lnum' :10 ,' col' :5 ,' type' :' W' , ' text' :' Warning' ,' nr' :11 },
123+ \ {' lnum' :20 ,' col' :10 ,' type' :' e' ,' text' :' Error' ,' nr' :22 },
124+ \ {' lnum' :30 ,' col' :15 ,' type' :' i' ,' text' :' Info' ,' nr' :33 },
125+ \ {' lnum' :40 ,' col' :20 ,' type' :' x' , ' text' :' Other' ,' nr' :44 },
126+ \ {' lnum' :50 ,' col' :25 ,' type' :" \<C-A> " ,' text' :' one' ,' nr' :55 }])
127+ let l = split (execute (' Xlist' , " " ), " \n " )
128+ call assert_equal ([' 1:10 col 5 warning 11: Warning' ,
129+ \ ' 2:20 col 10 error 22: Error' ,
130+ \ ' 3:30 col 15 info 33: Info' ,
131+ \ ' 4:40 col 20 x 44: Other' ,
132+ \ ' 5:50 col 25 55: one' ], l )
133+
134+ " Error cases
135+ call assert_fails (' Xlist abc' , ' E488:' )
139136endfunc
140137
141138func Test_clist ()
@@ -324,6 +321,23 @@ func XbufferTests(cchar)
324321 \ l [3 ].lnum == 750 && l [3 ].col == 25 && l [3 ].text == # ' Line 750' )
325322 enew !
326323
324+ " Check for invalid buffer
325+ call assert_fails (' Xbuffer 199' , ' E474:' )
326+
327+ " Check for unloaded buffer
328+ edit Xtestfile1
329+ let bnr = bufnr (' %' )
330+ enew !
331+ call assert_fails (' Xbuffer ' . bnr, ' E681:' )
332+
333+ " Check for invalid range
334+ " Using Xbuffer will not run the range check in the cbuffer/lbuffer
335+ " commands. So directly call the commands.
336+ if (a: cchar == ' c' )
337+ call assert_fails (' 900,999cbuffer' , ' E16:' )
338+ else
339+ call assert_fails (' 900,999lbuffer' , ' E16:' )
340+ endif
327341endfunc
328342
329343func Test_cbuffer ()
@@ -372,6 +386,9 @@ func Xtest_browse(cchar)
372386 call assert_equal (' Xqftestfile1' , bufname (' %' ))
373387 call assert_equal (5 , line (' .' ))
374388
389+ Xexpr " "
390+ call assert_fails (' Xnext' , ' E42:' )
391+
375392 call delete (' Xqftestfile1' )
376393 call delete (' Xqftestfile2' )
377394endfunc
@@ -411,6 +428,9 @@ func s:test_xhelpgrep(cchar)
411428 call assert_true (w: quickfix_title = ~ title_text, w: quickfix_title )
412429 " This wipes out the buffer, make sure that doesn't cause trouble.
413430 Xclose
431+
432+ " Search for non existing help string
433+ call assert_fails (' Xhelpgrep a1b2c3' , ' E480:' )
414434endfunc
415435
416436func Test_helpgrep ()
@@ -604,7 +624,7 @@ func Test_locationlist()
604624 wincmd n | only
605625
606626 augroup ! testgroup
607- endfunc
627+ endfunc
608628
609629func Test_locationlist_curwin_was_closed ()
610630 augroup testgroup
@@ -623,7 +643,7 @@ func Test_locationlist_curwin_was_closed()
623643 call assert_fails (' lrewind' , ' E924:' )
624644
625645 augroup ! testgroup
626- endfunc
646+ endfunc
627647
628648func Test_locationlist_cross_tab_jump ()
629649 call writefile ([' loclistfoo' ], ' loclistfoo' )
@@ -760,7 +780,7 @@ func Test_efm1()
760780 call delete (' Xerrorfile1' )
761781 call delete (' Xerrorfile2' )
762782 call delete (' Xtestfile' )
763- endfunc
783+ endfunc
764784
765785" Test for quickfix directory stack support
766786func s: dir_stack_tests (cchar)
@@ -919,20 +939,26 @@ func Test_efm2()
919939 call assert_equal (l [0 ].pattern, ' ^\VLine search text\$' )
920940 call assert_equal (l [0 ].lnum, 0 )
921941
942+ let l = split (execute (' clist' , ' ' ), " \n " )
943+ call assert_equal ([' 1 Xtestfile:^\VLine search text\$: ' ], l )
944+
922945 " Test for %P, %Q and %t format specifiers
923946 let lines = [" [Xtestfile1]" ,
924947 \ " (1,17) error: ';' missing" ,
925948 \ " (21,2) warning: variable 'z' not defined" ,
926949 \ " (67,3) error: end of file found before string ended" ,
950+ \ " --" ,
927951 \ " " ,
928952 \ " [Xtestfile2]" ,
953+ \ " --" ,
929954 \ " " ,
930955 \ " [Xtestfile3]" ,
931956 \ " NEW compiler v1.1" ,
932957 \ " (2,2) warning: variable 'x' not defined" ,
933- \ " (67,3) warning: 's' already defined"
958+ \ " (67,3) warning: 's' already defined" ,
959+ \ " --"
934960 \]
935- set efm = %+ P [% f ],(% l \\ ,% c )%* [\ ]% t %* [^:]:\ % m ,%- Q
961+ set efm = %+ P [% f ]% r ,(% l \\ ,% c )%* [\ ]% t %* [^:]:\ % m ,%+ Q --% r
936962 " To exercise the push/pop file functionality in quickfix, the test files
937963 " need to be created.
938964 call writefile ([' Line1' ], ' Xtestfile1' )
@@ -943,7 +969,7 @@ func Test_efm2()
943969 caddexpr l
944970 endfor
945971 let l = getqflist ()
946- call assert_equal (9 , len (l ))
972+ call assert_equal (12 , len (l ))
947973 call assert_equal (21 , l [2 ].lnum)
948974 call assert_equal (2 , l [2 ].col )
949975 call assert_equal (' w' , l [2 ].type )
@@ -1098,6 +1124,13 @@ func SetXlistTests(cchar, bnum)
10981124 call g: Xsetlist ([])
10991125 let l = g: Xgetlist ()
11001126 call assert_equal (0 , len (l ))
1127+
1128+ " Error cases:
1129+ " Refer to a non-existing buffer and pass a non-dictionary type
1130+ call assert_fails (" call g:Xsetlist([{'bufnr':998, 'lnum':4}," .
1131+ \ " {'bufnr':999, 'lnum':5}])" , ' E92:' )
1132+ call g: Xsetlist ([[1 , 2 ,3 ]])
1133+ call assert_equal (0 , len (g: Xgetlist ()))
11011134endfunc
11021135
11031136func Test_setqflist ()
@@ -1116,7 +1149,8 @@ func Xlist_empty_middle(cchar)
11161149 call s: setup_commands (a: cchar )
11171150
11181151 " create three quickfix lists
1119- Xvimgrep Test_ test_quickfix.vim
1152+ let @/ = ' Test_'
1153+ Xvimgrep // test_quickfix.vim
11201154 let testlen = len (g: Xgetlist ())
11211155 call assert_true (testlen > 0 )
11221156 Xvimgrep empty test_quickfix.vim
@@ -1609,23 +1643,41 @@ func Xproperty_tests(cchar)
16091643 call g: Xsetlist ([], ' ' , {' title' : ' N3' })
16101644 call assert_equal (' N2' , g: Xgetlist ({' nr' :2 , ' title' :1 }).title )
16111645
1646+ " Changing the title of an earlier quickfix list
1647+ call g: Xsetlist ([], ' ' , {' title' : ' NewTitle' , ' nr' : 2 })
1648+ call assert_equal (' NewTitle' , g: Xgetlist ({' nr' :2 , ' title' :1 }).title )
1649+
1650+ " Changing the title of an invalid quickfix list
1651+ call assert_equal (-1 , g: Xsetlist ([], ' ' ,
1652+ \ {' title' : ' SomeTitle' , ' nr' : 99 }))
1653+ call assert_equal (-1 , g: Xsetlist ([], ' ' ,
1654+ \ {' title' : ' SomeTitle' , ' nr' : ' abc' }))
1655+
1656+ if a: cchar == ' c'
1657+ copen
1658+ call assert_equal ({' winid' : win_getid ()}, getqflist ({' winid' :1 }))
1659+ cclose
1660+ endif
1661+
16121662 " Invalid arguments
16131663 call assert_fails (' call g:Xgetlist([])' , ' E715' )
16141664 call assert_fails (' call g:Xsetlist([], "a", [])' , ' E715' )
16151665 let s = g: Xsetlist ([], ' a' , {' abc' :1 })
16161666 call assert_equal (-1 , s )
16171667
16181668 call assert_equal ({}, g: Xgetlist ({' abc' :1 }))
1669+ call assert_equal ({}, g: Xgetlist ({' nr' :99 , ' title' :1 }))
1670+ call assert_equal ({}, g: Xgetlist ({' nr' :[], ' title' :1 }))
16191671
16201672 if a: cchar == ' l'
16211673 call assert_equal ({}, getloclist (99 , {' title' : 1 }))
16221674 endif
1623- endfunc
1675+ endfunc
16241676
16251677func Test_qf_property ()
16261678 call Xproperty_tests (' c' )
16271679 call Xproperty_tests (' l' )
1628- endfunc
1680+ endfunc
16291681
16301682" Tests for the QuickFixCmdPre/QuickFixCmdPost autocommands
16311683func QfAutoCmdHandler (loc , cmd)
@@ -1774,3 +1826,55 @@ func Test_cwindow_jump()
17741826 enew | only
17751827 set efm &vim
17761828endfunc
1829+
1830+ func XvimgrepTests (cchar)
1831+ call s: setup_commands (a: cchar )
1832+
1833+ call writefile ([' Editor:VIM vim' ,
1834+ \ ' Editor:Emacs EmAcS' ,
1835+ \ ' Editor:Notepad NOTEPAD' ], ' Xtestfile1' )
1836+ call writefile ([' Linux' , ' MacOS' , ' MS-Windows' ], ' Xtestfile2' )
1837+
1838+ " Error cases
1839+ call assert_fails (' Xvimgrep /abc *' , ' E682:' )
1840+
1841+ let @/ = ' '
1842+ call assert_fails (' Xvimgrep // *' , ' E35:' )
1843+
1844+ call assert_fails (' Xvimgrep abc' , ' E683:' )
1845+ call assert_fails (' Xvimgrep a1b2c3 Xtestfile1' , ' E480:' )
1846+ call assert_fails (' Xvimgrep pat Xa1b2c3' , ' E480:' )
1847+
1848+ Xexpr " "
1849+ Xvimgrepadd Notepad Xtestfile1
1850+ Xvimgrepadd MacOS Xtestfile2
1851+ let l = g: Xgetlist ()
1852+ call assert_equal (2 , len (l ))
1853+ call assert_equal (' Editor:Notepad NOTEPAD' , l [0 ].text)
1854+
1855+ Xvimgrep #\c vim#g Xtestfile?
1856+ let l = g: Xgetlist ()
1857+ call assert_equal (2 , len (l ))
1858+ call assert_equal (8 , l [0 ].col )
1859+ call assert_equal (12 , l [1 ].col )
1860+
1861+ 1 Xvimgrep ?Editor? Xtestfile*
1862+ let l = g: Xgetlist ()
1863+ call assert_equal (1 , len (l ))
1864+ call assert_equal (' Editor:VIM vim' , l [0 ].text)
1865+
1866+ edit + 3 Xtestfile2
1867+ Xvimgrep + \c emacs+ j Xtestfile1
1868+ let l = g: Xgetlist ()
1869+ call assert_equal (' Xtestfile2' , bufname (' ' ))
1870+ call assert_equal (' Editor:Emacs EmAcS' , l [0 ].text)
1871+
1872+ call delete (' Xtestfile1' )
1873+ call delete (' Xtestfile2' )
1874+ endfunc
1875+
1876+ " Tests for the :vimgrep command
1877+ func Test_vimgrep ()
1878+ call XvimgrepTests (' c' )
1879+ call XvimgrepTests (' l' )
1880+ endfunc
0 commit comments