diff options
Diffstat (limited to 'test/old/testdir/test_quickfix.vim')
-rw-r--r-- | test/old/testdir/test_quickfix.vim | 755 |
1 files changed, 406 insertions, 349 deletions
diff --git a/test/old/testdir/test_quickfix.vim b/test/old/testdir/test_quickfix.vim index a708cabc26..753875963b 100644 --- a/test/old/testdir/test_quickfix.vim +++ b/test/old/testdir/test_quickfix.vim @@ -1020,52 +1020,50 @@ endfunc " More tests for 'errorformat' func Test_efm1() - if !has('unix') - " The 'errorformat' setting is different on non-Unix systems. - " This test works only on Unix-like systems. - return - endif + " The 'errorformat' setting is different on non-Unix systems. + " This test works only on Unix-like systems. + CheckUnix + + let l =<< trim [DATA] + "Xtestfile", line 4.12: 1506-045 (S) Undeclared identifier fd_set. + "Xtestfile", line 6 col 19; this is an error + gcc -c -DHAVE_CONFIsing-prototypes -I/usr/X11R6/include version.c + Xtestfile:9: parse error before `asd' + make: *** [src/vim/testdir/Makefile:100: test_quickfix] Error 1 + in file "Xtestfile" linenr 10: there is an error + + 2 returned + "Xtestfile", line 11 col 1; this is an error + "Xtestfile", line 12 col 2; this is another error + "Xtestfile", line 14:10; this is an error in column 10 + =Xtestfile=, line 15:10; this is another error, but in vcol 10 this time + "Xtestfile", linenr 16: yet another problem + Error in "Xtestfile" at line 17: + x should be a dot + xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 17 + ^ + Error in "Xtestfile" at line 18: + x should be a dot + xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 18 + .............^ + Error in "Xtestfile" at line 19: + x should be a dot + xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 19 + --------------^ + Error in "Xtestfile" at line 20: + x should be a dot + xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 20 + ^ - let l =<< trim [DATA] - "Xtestfile", line 4.12: 1506-045 (S) Undeclared identifier fd_set. - "Xtestfile", line 6 col 19; this is an error - gcc -c -DHAVE_CONFIsing-prototypes -I/usr/X11R6/include version.c - Xtestfile:9: parse error before `asd' - make: *** [src/vim/testdir/Makefile:100: test_quickfix] Error 1 - in file "Xtestfile" linenr 10: there is an error - - 2 returned - "Xtestfile", line 11 col 1; this is an error - "Xtestfile", line 12 col 2; this is another error - "Xtestfile", line 14:10; this is an error in column 10 - =Xtestfile=, line 15:10; this is another error, but in vcol 10 this time - "Xtestfile", linenr 16: yet another problem - Error in "Xtestfile" at line 17: - x should be a dot - xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 17 - ^ - Error in "Xtestfile" at line 18: - x should be a dot - xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 18 - .............^ - Error in "Xtestfile" at line 19: - x should be a dot - xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 19 - --------------^ - Error in "Xtestfile" at line 20: - x should be a dot - xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 20 - ^ - - Does anyone know what is the problem and how to correction it? - "Xtestfile", line 21 col 9: What is the title of the quickfix window? - "Xtestfile", line 22 col 9: What is the title of the quickfix window? - [DATA] - - call writefile(l, 'Xerrorfile1') - call writefile(l[:-2], 'Xerrorfile2') - - let m =<< [DATA] + Does anyone know what is the problem and how to correction it? + "Xtestfile", line 21 col 9: What is the title of the quickfix window? + "Xtestfile", line 22 col 9: What is the title of the quickfix window? + [DATA] + + call writefile(l, 'Xerrorfile1') + call writefile(l[:-2], 'Xerrorfile2') + + let m =<< [DATA] xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 2 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 3 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 4 @@ -1088,55 +1086,55 @@ func Test_efm1() xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 21 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 22 [DATA] - call writefile(m, 'Xtestfile') + call writefile(m, 'Xtestfile') - let save_efm = &efm - set efm+==%f=\\,\ line\ %l%*\\D%v%*[^\ ]\ %m - set efm^=%AError\ in\ \"%f\"\ at\ line\ %l:,%Z%p^,%C%m + let save_efm = &efm + set efm+==%f=\\,\ line\ %l%*\\D%v%*[^\ ]\ %m + set efm^=%AError\ in\ \"%f\"\ at\ line\ %l:,%Z%p^,%C%m - exe 'cf Xerrorfile2' - clast - copen - call assert_equal(':cf Xerrorfile2', w:quickfix_title) - wincmd p + exe 'cf Xerrorfile2' + clast + copen + call assert_equal(':cf Xerrorfile2', w:quickfix_title) + wincmd p - exe 'cf Xerrorfile1' - call assert_equal([4, 12], [line('.'), col('.')]) - cn - call assert_equal([6, 19], [line('.'), col('.')]) - cn - call assert_equal([9, 2], [line('.'), col('.')]) - cn - call assert_equal([10, 2], [line('.'), col('.')]) - cn - call assert_equal([11, 1], [line('.'), col('.')]) - cn - call assert_equal([12, 2], [line('.'), col('.')]) - cn - call assert_equal([14, 10], [line('.'), col('.')]) - cn - call assert_equal([15, 3, 10], [line('.'), col('.'), virtcol('.')]) - cn - call assert_equal([16, 2], [line('.'), col('.')]) - cn - call assert_equal([17, 6], [line('.'), col('.')]) - cn - call assert_equal([18, 7], [line('.'), col('.')]) - cn - call assert_equal([19, 8], [line('.'), col('.')]) - cn - call assert_equal([20, 9], [line('.'), col('.')]) - clast - cprev - cprev - wincmd w - call assert_equal(':cf Xerrorfile1', w:quickfix_title) - wincmd p + exe 'cf Xerrorfile1' + call assert_equal([4, 12], [line('.'), col('.')]) + cn + call assert_equal([6, 19], [line('.'), col('.')]) + cn + call assert_equal([9, 2], [line('.'), col('.')]) + cn + call assert_equal([10, 2], [line('.'), col('.')]) + cn + call assert_equal([11, 1], [line('.'), col('.')]) + cn + call assert_equal([12, 2], [line('.'), col('.')]) + cn + call assert_equal([14, 10], [line('.'), col('.')]) + cn + call assert_equal([15, 3, 10], [line('.'), col('.'), virtcol('.')]) + cn + call assert_equal([16, 2], [line('.'), col('.')]) + cn + call assert_equal([17, 6], [line('.'), col('.')]) + cn + call assert_equal([18, 7], [line('.'), col('.')]) + cn + call assert_equal([19, 8], [line('.'), col('.')]) + cn + call assert_equal([20, 9], [line('.'), col('.')]) + clast + cprev + cprev + wincmd w + call assert_equal(':cf Xerrorfile1', w:quickfix_title) + wincmd p - let &efm = save_efm - call delete('Xerrorfile1') - call delete('Xerrorfile2') - call delete('Xtestfile') + let &efm = save_efm + call delete('Xerrorfile1') + call delete('Xerrorfile2') + call delete('Xtestfile') endfunc " Test for quickfix directory stack support @@ -1410,7 +1408,7 @@ func Test_efm2() failUnlessEqual raise self.failureException, \\ W:AssertionError: 34 != 33 - + -------------------------------------------------------------- Ran 27 tests in 0.063s [DATA] @@ -2210,10 +2208,8 @@ func s:test_xgrep(cchar) endfunc func Test_grep() - if !has('unix') - " The grepprg may not be set on non-Unix systems - return - endif + " The grepprg may not be set on non-Unix systems + CheckUnix call s:test_xgrep('c') call s:test_xgrep('l') @@ -2351,254 +2347,254 @@ endfunc " Quickfix/Location list set/get properties tests func Xproperty_tests(cchar) - call s:setup_commands(a:cchar) + call s:setup_commands(a:cchar) - " Error cases - call assert_fails('call g:Xgetlist(99)', 'E715:') - call assert_fails('call g:Xsetlist(99)', 'E714:') - call assert_fails('call g:Xsetlist([], "a", [])', 'E715:') + " Error cases + call assert_fails('call g:Xgetlist(99)', 'E715:') + call assert_fails('call g:Xsetlist(99)', 'E714:') + call assert_fails('call g:Xsetlist([], "a", [])', 'E715:') - " Set and get the title - call g:Xsetlist([]) - Xopen - wincmd p - call g:Xsetlist([{'filename':'foo', 'lnum':27}]) - let s = g:Xsetlist([], 'a', {'title' : 'Sample'}) - call assert_equal(0, s) - let d = g:Xgetlist({"title":1}) - call assert_equal('Sample', d.title) - " Try setting title to a non-string value - call assert_equal(-1, g:Xsetlist([], 'a', {'title' : ['Test']})) - call assert_equal('Sample', g:Xgetlist({"title":1}).title) + " Set and get the title + call g:Xsetlist([]) + Xopen + wincmd p + call g:Xsetlist([{'filename':'foo', 'lnum':27}]) + let s = g:Xsetlist([], 'a', {'title' : 'Sample'}) + call assert_equal(0, s) + let d = g:Xgetlist({"title":1}) + call assert_equal('Sample', d.title) + " Try setting title to a non-string value + call assert_equal(-1, g:Xsetlist([], 'a', {'title' : ['Test']})) + call assert_equal('Sample', g:Xgetlist({"title":1}).title) - Xopen - call assert_equal('Sample', w:quickfix_title) - Xclose - - " Tests for action argument - silent! Xolder 999 - let qfnr = g:Xgetlist({'all':1}).nr - call g:Xsetlist([], 'r', {'title' : 'N1'}) - call assert_equal('N1', g:Xgetlist({'all':1}).title) - call g:Xsetlist([], ' ', {'title' : 'N2'}) - call assert_equal(qfnr + 1, g:Xgetlist({'all':1}).nr) - - let res = g:Xgetlist({'nr': 0}) - call assert_equal(qfnr + 1, res.nr) - call assert_equal(['nr'], keys(res)) - - call g:Xsetlist([], ' ', {'title' : 'N3'}) - call assert_equal('N2', g:Xgetlist({'nr':2, 'title':1}).title) - - " Changing the title of an earlier quickfix list - call g:Xsetlist([], 'r', {'title' : 'NewTitle', 'nr' : 2}) - call assert_equal('NewTitle', g:Xgetlist({'nr':2, 'title':1}).title) - - " Changing the title of an invalid quickfix list - call assert_equal(-1, g:Xsetlist([], ' ', - \ {'title' : 'SomeTitle', 'nr' : 99})) - call assert_equal(-1, g:Xsetlist([], ' ', - \ {'title' : 'SomeTitle', 'nr' : 'abc'})) - - if a:cchar == 'c' - copen - call assert_equal({'winid':win_getid()}, getqflist({'winid':1})) - cclose - endif + Xopen + call assert_equal('Sample', w:quickfix_title) + Xclose - " Invalid arguments - call assert_fails('call g:Xgetlist([])', 'E715') - call assert_fails('call g:Xsetlist([], "a", [])', 'E715') - let s = g:Xsetlist([], 'a', {'abc':1}) - call assert_equal(-1, s) + " Tests for action argument + silent! Xolder 999 + let qfnr = g:Xgetlist({'all':1}).nr + call g:Xsetlist([], 'r', {'title' : 'N1'}) + call assert_equal('N1', g:Xgetlist({'all':1}).title) + call g:Xsetlist([], ' ', {'title' : 'N2'}) + call assert_equal(qfnr + 1, g:Xgetlist({'all':1}).nr) - call assert_equal({}, g:Xgetlist({'abc':1})) - call assert_equal('', g:Xgetlist({'nr':99, 'title':1}).title) - call assert_equal('', g:Xgetlist({'nr':[], 'title':1}).title) + let res = g:Xgetlist({'nr': 0}) + call assert_equal(qfnr + 1, res.nr) + call assert_equal(['nr'], keys(res)) - if a:cchar == 'l' - call assert_equal({}, getloclist(99, {'title': 1})) - endif + call g:Xsetlist([], ' ', {'title' : 'N3'}) + call assert_equal('N2', g:Xgetlist({'nr':2, 'title':1}).title) - " Context related tests - let s = g:Xsetlist([], 'a', {'context':[1,2,3]}) - call assert_equal(0, s) - call test_garbagecollect_now() - let d = g:Xgetlist({'context':1}) - call assert_equal([1,2,3], d.context) - call g:Xsetlist([], 'a', {'context':{'color':'green'}}) - let d = g:Xgetlist({'context':1}) - call assert_equal({'color':'green'}, d.context) - call g:Xsetlist([], 'a', {'context':"Context info"}) - let d = g:Xgetlist({'context':1}) - call assert_equal("Context info", d.context) - call g:Xsetlist([], 'a', {'context':246}) - let d = g:Xgetlist({'context':1}) - call assert_equal(246, d.context) - " set other Vim data types as context - call g:Xsetlist([], 'a', {'context' : v:_null_blob}) - if has('channel') - call g:Xsetlist([], 'a', {'context' : test_null_channel()}) - endif - if has('job') - call g:Xsetlist([], 'a', {'context' : test_null_job()}) - endif - " Nvim doesn't have null functions - " call g:Xsetlist([], 'a', {'context' : test_null_function()}) - " Nvim doesn't have null partials - " call g:Xsetlist([], 'a', {'context' : test_null_partial()}) - call g:Xsetlist([], 'a', {'context' : ''}) - call test_garbagecollect_now() - if a:cchar == 'l' - " Test for copying context across two different location lists - new | only - let w1_id = win_getid() - let l = [1] - call setloclist(0, [], 'a', {'context':l}) - new - let w2_id = win_getid() - call add(l, 2) - call assert_equal([1, 2], getloclist(w1_id, {'context':1}).context) - call assert_equal([1, 2], getloclist(w2_id, {'context':1}).context) - unlet! l - call assert_equal([1, 2], getloclist(w2_id, {'context':1}).context) - only - call setloclist(0, [], 'f') - call assert_equal('', getloclist(0, {'context':1}).context) - endif + " Changing the title of an earlier quickfix list + call g:Xsetlist([], 'r', {'title' : 'NewTitle', 'nr' : 2}) + call assert_equal('NewTitle', g:Xgetlist({'nr':2, 'title':1}).title) - " Test for changing the context of previous quickfix lists - call g:Xsetlist([], 'f') - Xexpr "One" - Xexpr "Two" - Xexpr "Three" - call g:Xsetlist([], 'r', {'context' : [1], 'nr' : 1}) - call g:Xsetlist([], 'a', {'context' : [2], 'nr' : 2}) - " Also, check for setting the context using quickfix list number zero. - call g:Xsetlist([], 'r', {'context' : [3], 'nr' : 0}) - call test_garbagecollect_now() - let l = g:Xgetlist({'nr' : 1, 'context' : 1}) - call assert_equal([1], l.context) - let l = g:Xgetlist({'nr' : 2, 'context' : 1}) - call assert_equal([2], l.context) - let l = g:Xgetlist({'nr' : 3, 'context' : 1}) - call assert_equal([3], l.context) - - " Test for changing the context through reference and for garbage - " collection of quickfix context - let l = ["red"] - call g:Xsetlist([], ' ', {'context' : l}) - call add(l, "blue") - let x = g:Xgetlist({'context' : 1}) - call add(x.context, "green") - call assert_equal(["red", "blue", "green"], l) - call assert_equal(["red", "blue", "green"], x.context) - unlet l - call test_garbagecollect_now() - let m = g:Xgetlist({'context' : 1}) - call assert_equal(["red", "blue", "green"], m.context) - - " Test for setting/getting items - Xexpr "" - let qfprev = g:Xgetlist({'nr':0}) - let s = g:Xsetlist([], ' ', {'title':'Green', - \ 'items' : [{'filename':'F1', 'lnum':10}]}) - call assert_equal(0, s) - let qfcur = g:Xgetlist({'nr':0}) - call assert_true(qfcur.nr == qfprev.nr + 1) - let l = g:Xgetlist({'items':1}) - call assert_equal('F1', bufname(l.items[0].bufnr)) - call assert_equal(10, l.items[0].lnum) - call g:Xsetlist([], 'a', {'items' : [{'filename':'F2', 'lnum':20}, - \ {'filename':'F2', 'lnum':30}]}) - let l = g:Xgetlist({'items':1}) - call assert_equal('F2', bufname(l.items[2].bufnr)) - call assert_equal(30, l.items[2].lnum) - call g:Xsetlist([], 'r', {'items' : [{'filename':'F3', 'lnum':40}]}) - let l = g:Xgetlist({'items':1}) - call assert_equal('F3', bufname(l.items[0].bufnr)) - call assert_equal(40, l.items[0].lnum) - call g:Xsetlist([], 'r', {'items' : []}) - let l = g:Xgetlist({'items':1}) - call assert_equal(0, len(l.items)) - - call g:Xsetlist([], 'r', {'title' : 'TestTitle'}) - call g:Xsetlist([], 'r', {'items' : [{'filename' : 'F1', 'lnum' : 10, 'text' : 'L10'}]}) - call g:Xsetlist([], 'r', {'items' : [{'filename' : 'F1', 'lnum' : 10, 'text' : 'L10'}]}) - call assert_equal('TestTitle', g:Xgetlist({'title' : 1}).title) - - " Test for getting id of window associated with a location list window - if a:cchar == 'l' - only - call assert_equal(0, g:Xgetlist({'all' : 1}).filewinid) - let wid = win_getid() - Xopen - call assert_equal(wid, g:Xgetlist({'filewinid' : 1}).filewinid) - wincmd w - call assert_equal(0, g:Xgetlist({'filewinid' : 1}).filewinid) - only - endif + " Changing the title of an invalid quickfix list + call assert_equal(-1, g:Xsetlist([], ' ', + \ {'title' : 'SomeTitle', 'nr' : 99})) + call assert_equal(-1, g:Xsetlist([], ' ', + \ {'title' : 'SomeTitle', 'nr' : 'abc'})) - " The following used to crash Vim with address sanitizer - call g:Xsetlist([], 'f') - call g:Xsetlist([], 'a', {'items' : [{'filename':'F1', 'lnum':10}]}) - call assert_equal(10, g:Xgetlist({'items':1}).items[0].lnum) + if a:cchar == 'c' + copen + call assert_equal({'winid':win_getid()}, getqflist({'winid':1})) + cclose + endif - " Try setting the items using a string - call assert_equal(-1, g:Xsetlist([], ' ', {'items' : 'Test'})) + " Invalid arguments + call assert_fails('call g:Xgetlist([])', 'E715') + call assert_fails('call g:Xsetlist([], "a", [])', 'E715') + let s = g:Xsetlist([], 'a', {'abc':1}) + call assert_equal(-1, s) - " Save and restore the quickfix stack - call g:Xsetlist([], 'f') - call assert_equal(0, g:Xgetlist({'nr':'$'}).nr) - Xexpr "File1:10:Line1" - Xexpr "File2:20:Line2" - Xexpr "File3:30:Line3" - let last_qf = g:Xgetlist({'nr':'$'}).nr - call assert_equal(3, last_qf) - let qstack = [] - for i in range(1, last_qf) - let qstack = add(qstack, g:Xgetlist({'nr':i, 'all':1})) - endfor - call g:Xsetlist([], 'f') - for i in range(len(qstack)) - call g:Xsetlist([], ' ', qstack[i]) - endfor - call assert_equal(3, g:Xgetlist({'nr':'$'}).nr) - call assert_equal(10, g:Xgetlist({'nr':1, 'items':1}).items[0].lnum) - call assert_equal(20, g:Xgetlist({'nr':2, 'items':1}).items[0].lnum) - call assert_equal(30, g:Xgetlist({'nr':3, 'items':1}).items[0].lnum) - call g:Xsetlist([], 'f') + call assert_equal({}, g:Xgetlist({'abc':1})) + call assert_equal('', g:Xgetlist({'nr':99, 'title':1}).title) + call assert_equal('', g:Xgetlist({'nr':[], 'title':1}).title) - " Swap two quickfix lists - Xexpr "File1:10:Line10" - Xexpr "File2:20:Line20" - Xexpr "File3:30:Line30" - call g:Xsetlist([], 'r', {'nr':1,'title':'Colors','context':['Colors']}) - call g:Xsetlist([], 'r', {'nr':2,'title':'Fruits','context':['Fruits']}) - let l1=g:Xgetlist({'nr':1,'all':1}) - let l2=g:Xgetlist({'nr':2,'all':1}) - let save_id = l1.id - let l1.id=l2.id - let l2.id=save_id - call g:Xsetlist([], 'r', l1) - call g:Xsetlist([], 'r', l2) - let newl1=g:Xgetlist({'nr':1,'all':1}) - let newl2=g:Xgetlist({'nr':2,'all':1}) - call assert_equal('Fruits', newl1.title) - call assert_equal(['Fruits'], newl1.context) - call assert_equal('Line20', newl1.items[0].text) - call assert_equal('Colors', newl2.title) - call assert_equal(['Colors'], newl2.context) - call assert_equal('Line10', newl2.items[0].text) - call g:Xsetlist([], 'f') + if a:cchar == 'l' + call assert_equal({}, getloclist(99, {'title': 1})) + endif - " Cannot specify both a non-empty list argument and a dict argument - call assert_fails("call g:Xsetlist([{}], ' ', {})", 'E475:') + " Context related tests + let s = g:Xsetlist([], 'a', {'context':[1,2,3]}) + call assert_equal(0, s) + call test_garbagecollect_now() + let d = g:Xgetlist({'context':1}) + call assert_equal([1,2,3], d.context) + call g:Xsetlist([], 'a', {'context':{'color':'green'}}) + let d = g:Xgetlist({'context':1}) + call assert_equal({'color':'green'}, d.context) + call g:Xsetlist([], 'a', {'context':"Context info"}) + let d = g:Xgetlist({'context':1}) + call assert_equal("Context info", d.context) + call g:Xsetlist([], 'a', {'context':246}) + let d = g:Xgetlist({'context':1}) + call assert_equal(246, d.context) + " set other Vim data types as context + call g:Xsetlist([], 'a', {'context' : v:_null_blob}) + if has('channel') + call g:Xsetlist([], 'a', {'context' : test_null_channel()}) + endif + if has('job') + call g:Xsetlist([], 'a', {'context' : test_null_job()}) + endif + " Nvim doesn't have null functions + " call g:Xsetlist([], 'a', {'context' : test_null_function()}) + " Nvim doesn't have null partials + " call g:Xsetlist([], 'a', {'context' : test_null_partial()}) + call g:Xsetlist([], 'a', {'context' : ''}) + call test_garbagecollect_now() + if a:cchar == 'l' + " Test for copying context across two different location lists + new | only + let w1_id = win_getid() + let l = [1] + call setloclist(0, [], 'a', {'context':l}) + new + let w2_id = win_getid() + call add(l, 2) + call assert_equal([1, 2], getloclist(w1_id, {'context':1}).context) + call assert_equal([1, 2], getloclist(w2_id, {'context':1}).context) + unlet! l + call assert_equal([1, 2], getloclist(w2_id, {'context':1}).context) + only + call setloclist(0, [], 'f') + call assert_equal('', getloclist(0, {'context':1}).context) + endif + + " Test for changing the context of previous quickfix lists + call g:Xsetlist([], 'f') + Xexpr "One" + Xexpr "Two" + Xexpr "Three" + call g:Xsetlist([], 'r', {'context' : [1], 'nr' : 1}) + call g:Xsetlist([], 'a', {'context' : [2], 'nr' : 2}) + " Also, check for setting the context using quickfix list number zero. + call g:Xsetlist([], 'r', {'context' : [3], 'nr' : 0}) + call test_garbagecollect_now() + let l = g:Xgetlist({'nr' : 1, 'context' : 1}) + call assert_equal([1], l.context) + let l = g:Xgetlist({'nr' : 2, 'context' : 1}) + call assert_equal([2], l.context) + let l = g:Xgetlist({'nr' : 3, 'context' : 1}) + call assert_equal([3], l.context) + + " Test for changing the context through reference and for garbage + " collection of quickfix context + let l = ["red"] + call g:Xsetlist([], ' ', {'context' : l}) + call add(l, "blue") + let x = g:Xgetlist({'context' : 1}) + call add(x.context, "green") + call assert_equal(["red", "blue", "green"], l) + call assert_equal(["red", "blue", "green"], x.context) + unlet l + call test_garbagecollect_now() + let m = g:Xgetlist({'context' : 1}) + call assert_equal(["red", "blue", "green"], m.context) + + " Test for setting/getting items + Xexpr "" + let qfprev = g:Xgetlist({'nr':0}) + let s = g:Xsetlist([], ' ', {'title':'Green', + \ 'items' : [{'filename':'F1', 'lnum':10}]}) + call assert_equal(0, s) + let qfcur = g:Xgetlist({'nr':0}) + call assert_true(qfcur.nr == qfprev.nr + 1) + let l = g:Xgetlist({'items':1}) + call assert_equal('F1', bufname(l.items[0].bufnr)) + call assert_equal(10, l.items[0].lnum) + call g:Xsetlist([], 'a', {'items' : [{'filename':'F2', 'lnum':20}, + \ {'filename':'F2', 'lnum':30}]}) + let l = g:Xgetlist({'items':1}) + call assert_equal('F2', bufname(l.items[2].bufnr)) + call assert_equal(30, l.items[2].lnum) + call g:Xsetlist([], 'r', {'items' : [{'filename':'F3', 'lnum':40}]}) + let l = g:Xgetlist({'items':1}) + call assert_equal('F3', bufname(l.items[0].bufnr)) + call assert_equal(40, l.items[0].lnum) + call g:Xsetlist([], 'r', {'items' : []}) + let l = g:Xgetlist({'items':1}) + call assert_equal(0, len(l.items)) + + call g:Xsetlist([], 'r', {'title' : 'TestTitle'}) + call g:Xsetlist([], 'r', {'items' : [{'filename' : 'F1', 'lnum' : 10, 'text' : 'L10'}]}) + call g:Xsetlist([], 'r', {'items' : [{'filename' : 'F1', 'lnum' : 10, 'text' : 'L10'}]}) + call assert_equal('TestTitle', g:Xgetlist({'title' : 1}).title) + + " Test for getting id of window associated with a location list window + if a:cchar == 'l' + only + call assert_equal(0, g:Xgetlist({'all' : 1}).filewinid) + let wid = win_getid() + Xopen + call assert_equal(wid, g:Xgetlist({'filewinid' : 1}).filewinid) + wincmd w + call assert_equal(0, g:Xgetlist({'filewinid' : 1}).filewinid) + only + endif + + " The following used to crash Vim with address sanitizer + call g:Xsetlist([], 'f') + call g:Xsetlist([], 'a', {'items' : [{'filename':'F1', 'lnum':10}]}) + call assert_equal(10, g:Xgetlist({'items':1}).items[0].lnum) + + " Try setting the items using a string + call assert_equal(-1, g:Xsetlist([], ' ', {'items' : 'Test'})) + + " Save and restore the quickfix stack + call g:Xsetlist([], 'f') + call assert_equal(0, g:Xgetlist({'nr':'$'}).nr) + Xexpr "File1:10:Line1" + Xexpr "File2:20:Line2" + Xexpr "File3:30:Line3" + let last_qf = g:Xgetlist({'nr':'$'}).nr + call assert_equal(3, last_qf) + let qstack = [] + for i in range(1, last_qf) + let qstack = add(qstack, g:Xgetlist({'nr':i, 'all':1})) + endfor + call g:Xsetlist([], 'f') + for i in range(len(qstack)) + call g:Xsetlist([], ' ', qstack[i]) + endfor + call assert_equal(3, g:Xgetlist({'nr':'$'}).nr) + call assert_equal(10, g:Xgetlist({'nr':1, 'items':1}).items[0].lnum) + call assert_equal(20, g:Xgetlist({'nr':2, 'items':1}).items[0].lnum) + call assert_equal(30, g:Xgetlist({'nr':3, 'items':1}).items[0].lnum) + call g:Xsetlist([], 'f') + + " Swap two quickfix lists + Xexpr "File1:10:Line10" + Xexpr "File2:20:Line20" + Xexpr "File3:30:Line30" + call g:Xsetlist([], 'r', {'nr':1,'title':'Colors','context':['Colors']}) + call g:Xsetlist([], 'r', {'nr':2,'title':'Fruits','context':['Fruits']}) + let l1=g:Xgetlist({'nr':1,'all':1}) + let l2=g:Xgetlist({'nr':2,'all':1}) + let save_id = l1.id + let l1.id=l2.id + let l2.id=save_id + call g:Xsetlist([], 'r', l1) + call g:Xsetlist([], 'r', l2) + let newl1=g:Xgetlist({'nr':1,'all':1}) + let newl2=g:Xgetlist({'nr':2,'all':1}) + call assert_equal('Fruits', newl1.title) + call assert_equal(['Fruits'], newl1.context) + call assert_equal('Line20', newl1.items[0].text) + call assert_equal('Colors', newl2.title) + call assert_equal(['Colors'], newl2.context) + call assert_equal('Line10', newl2.items[0].text) + call g:Xsetlist([], 'f') + + " Cannot specify both a non-empty list argument and a dict argument + call assert_fails("call g:Xsetlist([{}], ' ', {})", 'E475:') endfunc func Test_qf_property() - call Xproperty_tests('c') - call Xproperty_tests('l') + call Xproperty_tests('c') + call Xproperty_tests('l') endfunc " Test for setting the current index in the location/quickfix list @@ -3132,7 +3128,7 @@ func Test_vimgrep_existing_swapfile() call assert_match('.Xapple.swo', swapname('')) call delete('Xapple') - call delete('Xapple.swp') + call delete('.Xapple.swp') augroup grep au! SwapExists augroup END @@ -3212,8 +3208,11 @@ func Test_bufoverflow() cgetexpr ['Compiler: ' . repeat('a', 1015), 'File1:10:Hello World'] set efm=%DEntering\ directory\ %f,%f:%l:%m - cgetexpr ['Entering directory ' . repeat('a', 1006), - \ 'File1:10:Hello World'] + let lines =<< trim eval END + Entering directory $"{repeat('a', 1006)}" + File1:10:Hello World + END + cgetexpr lines set efm&vim endfunc @@ -3585,15 +3584,15 @@ endfunc " Open multiple help windows using ":lhelpgrep " This test used to crash Vim func Test_Multi_LL_Help() - new | only - lhelpgrep window - lopen - e# - lhelpgrep buffer - call assert_equal(3, winnr('$')) - call assert_true(len(getloclist(1)) != 0) - call assert_true(len(getloclist(2)) != 0) - new | only + new | only + lhelpgrep window + lopen + e# + lhelpgrep buffer + call assert_equal(3, winnr('$')) + call assert_true(len(getloclist(1)) != 0) + call assert_true(len(getloclist(2)) != 0) + new | only endfunc " Tests for adding new quickfix lists using setqflist() @@ -4072,11 +4071,23 @@ func Test_ll_window_ctx() enew | only endfunc +" Similar to the problem above, but for user data. +func Test_ll_window_user_data() + call setloclist(0, [#{bufnr: bufnr(), user_data: {}}]) + lopen + wincmd t + close + call test_garbagecollect_now() + call feedkeys("\<CR>", 'tx') + call test_garbagecollect_now() + %bwipe! +endfunc + " The following test used to crash vim func Test_lfile_crash() sp Xtest au QuickFixCmdPre * bw - call assert_fails('lfile', 'E40') + call assert_fails('lfile', 'E40:') au! QuickFixCmdPre endfunc @@ -4129,6 +4140,7 @@ endfunc " The following test used to crash Vim func Test_lvimgrep_crash() + " this leaves a swapfile .test_quickfix.vim.swp around, why? sv Xtest augroup QF_Test au! @@ -4191,8 +4203,8 @@ endfunc " :vimgrep/:lvimgrep commands are running. func Test_vimgrep_autocmd() call setqflist([], 'f') - call writefile(['stars'], 'Xtest1.txt') - call writefile(['stars'], 'Xtest2.txt') + call writefile(['stars'], 'Xtest1.txt', 'D') + call writefile(['stars'], 'Xtest2.txt', 'D') " Test 1: " When searching for a pattern using :vimgrep, if the quickfix list is @@ -4222,9 +4234,9 @@ func Test_vimgrep_autocmd() autocmd BufRead Xtest2.txt call setloclist(g:save_winid, [], 'f') call assert_fails('lvimgrep stars Xtest*.txt', 'E926:') au! BufRead Xtest2.txt + " cleanup the swap files + bw! Xtest2.txt Xtest1.txt - call delete('Xtest1.txt') - call delete('Xtest2.txt') call setqflist([], 'f') endfunc @@ -4353,11 +4365,9 @@ endfunc " Test for shortening/simplifying the file name when opening the " quickfix window or when displaying the quickfix list func Test_shorten_fname() - if !has('unix') - return - endif + CheckUnix %bwipe - " Create a quickfix list with a absolute path filename + " Create a quickfix list with an absolute path filename let fname = getcwd() . '/test_quickfix.vim' call setqflist([], ' ', {'lines':[fname . ":20:Line20"], 'efm':'%f:%l:%m'}) call assert_equal(fname, bufname('test_quickfix.vim')) @@ -4366,7 +4376,7 @@ func Test_shorten_fname() call assert_equal('test_quickfix.vim', bufname('test_quickfix.vim')) cclose %bwipe - " Create a quickfix list with a absolute path filename + " Create a quickfix list with an absolute path filename call setqflist([], ' ', {'lines':[fname . ":20:Line20"], 'efm':'%f:%l:%m'}) call assert_equal(fname, bufname('test_quickfix.vim')) " Displaying the quickfix list should simplify the file path @@ -5926,6 +5936,16 @@ func Test_qfbuf_update() call Xqfbuf_update('l') endfunc +func Test_vimgrep_noswapfile() + set noswapfile + call writefile(['one', 'two', 'three'], 'Xgreppie') + vimgrep two Xgreppie + call assert_equal('two', getline('.')) + + call delete('Xgreppie') + set swapfile +endfunc + " Test for the :vimgrep 'f' flag (fuzzy match) func Xvimgrep_fuzzy_match(cchar) call s:setup_commands(a:cchar) @@ -6439,4 +6459,41 @@ func Test_cbuffer_range() call XbufferTests_range('l') endfunc +" Test for displaying fname pass from setqflist when the name +" are hard links to prevent seemly duplicate entries. +func Xtest_hardlink_fname(cchar) + call s:setup_commands(a:cchar) + %bwipe + " Create a sample source file + let lines =<< trim END + void sample() {} + int main() { sample(); return 0; } + END + call writefile(lines, 'test_qf_hardlink1.c', 'D') + defer delete('test_qf_hardlink1.c') + defer delete('test_qf_hardlink2.c') + call system('ln test_qf_hardlink1.c test_qf_hardlink2.c') + if v:shell_error + throw 'Skipped: ln throws error on this platform' + endif + call g:Xsetlist([], 'f') + " Make a qflist that contains the file and it's hard link + " like how LSP plugins set response into qflist + call g:Xsetlist([{'filename' : 'test_qf_hardlink1.c', 'lnum' : 1}, + \ {'filename' : 'test_qf_hardlink2.c', 'lnum' : 1}], ' ') + Xopen + " Ensure that two entries are displayed with different name + " so that they aren't seen as duplication. + call assert_equal(['test_qf_hardlink1.c|1| ', + \ 'test_qf_hardlink2.c|1| '], getline(1, '$')) + Xclose +endfunc + +func Test_hardlink_fname() + CheckUnix + CheckExecutable ln + call Xtest_hardlink_fname('c') + call Xtest_hardlink_fname('l') +endfunc + " vim: shiftwidth=2 sts=2 expandtab |