comparison src/testdir/test_quickfix.vim @ 21765:08940efa6b4e v8.2.1432

patch 8.2.1432: various inconsistencies in test files Commit: https://github.com/vim/vim/commit/6d91bcb4d23b5c6a0be72c384beaf385e2d9d606 Author: Bram Moolenaar <Bram@vim.org> Date: Wed Aug 12 18:50:36 2020 +0200 patch 8.2.1432: various inconsistencies in test files Problem: Various inconsistencies in test files. Solution: Add modelines where they were missing. Use Check commands instead of silently skipping over tests. Adjust indents and comments. (Ken Takata, closes #6695)
author Bram Moolenaar <Bram@vim.org>
date Wed, 12 Aug 2020 19:00:08 +0200
parents baccf9e06efe
children d8065205ea82
comparison
equal deleted inserted replaced
21764:476b6faad407 21765:08940efa6b4e
806 setl readonly 806 setl readonly
807 exe 'doautocmd BufRead ' . substitute(a:name, '\v^test://(.*)', '\1', '') 807 exe 'doautocmd BufRead ' . substitute(a:name, '\v^test://(.*)', '\1', '')
808 endfunc 808 endfunc
809 809
810 func Test_locationlist() 810 func Test_locationlist()
811 enew 811 enew
812 812
813 augroup testgroup 813 augroup testgroup
814 au! 814 au!
815 autocmd BufReadCmd test://* call ReadTestProtocol(expand("<amatch>")) 815 autocmd BufReadCmd test://* call ReadTestProtocol(expand("<amatch>"))
816 augroup END 816 augroup END
817 817
818 let words = [ "foo", "bar", "baz", "quux", "shmoo", "spam", "eggs" ] 818 let words = [ "foo", "bar", "baz", "quux", "shmoo", "spam", "eggs" ]
819 819
820 let qflist = [] 820 let qflist = []
821 for word in words 821 for word in words
822 call add(qflist, {'filename': 'test://' . word . '.txt', 'text': 'file ' . word . '.txt', }) 822 call add(qflist, {'filename': 'test://' . word . '.txt', 'text': 'file ' . word . '.txt', })
823 " NOTE: problem 1: 823 " NOTE: problem 1:
824 " intentionally not setting 'lnum' so that the quickfix entries are not 824 " intentionally not setting 'lnum' so that the quickfix entries are not
825 " valid 825 " valid
826 eval qflist->setloclist(0, ' ') 826 eval qflist->setloclist(0, ' ')
827 endfor 827 endfor
828 828
829 " Test A 829 " Test A
830 lrewind 830 lrewind
831 enew 831 enew
832 lopen 832 lopen
833 4lnext 833 4lnext
834 vert split 834 vert split
835 wincmd L 835 wincmd L
836 lopen 836 lopen
837 wincmd p 837 wincmd p
838 lnext 838 lnext
839 let fileName = expand("%") 839 let fileName = expand("%")
840 wincmd p 840 wincmd p
841 let locationListFileName = substitute(getline(line('.')), '\([^|]*\)|.*', '\1', '') 841 let locationListFileName = substitute(getline(line('.')), '\([^|]*\)|.*', '\1', '')
842 let fileName = substitute(fileName, '\\', '/', 'g') 842 let fileName = substitute(fileName, '\\', '/', 'g')
843 let locationListFileName = substitute(locationListFileName, '\\', '/', 'g') 843 let locationListFileName = substitute(locationListFileName, '\\', '/', 'g')
844 call assert_equal("test://bar.txt", fileName) 844 call assert_equal("test://bar.txt", fileName)
845 call assert_equal("test://bar.txt", locationListFileName) 845 call assert_equal("test://bar.txt", locationListFileName)
846 846
847 wincmd n | only 847 wincmd n | only
848 848
849 " Test B: 849 " Test B:
850 lrewind 850 lrewind
851 lopen 851 lopen
852 2 852 2
853 exe "normal \<CR>" 853 exe "normal \<CR>"
854 wincmd p 854 wincmd p
855 3 855 3
856 exe "normal \<CR>" 856 exe "normal \<CR>"
857 wincmd p 857 wincmd p
858 4 858 4
859 exe "normal \<CR>" 859 exe "normal \<CR>"
860 call assert_equal(2, winnr('$')) 860 call assert_equal(2, winnr('$'))
861 wincmd n | only 861 wincmd n | only
862 862
863 " Test C: 863 " Test C:
864 lrewind 864 lrewind
865 lopen 865 lopen
866 " Let's move the location list window to the top to check whether it (the 866 " Let's move the location list window to the top to check whether it (the
867 " first window found) will be reused when we try to open new windows: 867 " first window found) will be reused when we try to open new windows:
868 wincmd K 868 wincmd K
869 2 869 2
870 exe "normal \<CR>" 870 exe "normal \<CR>"
871 wincmd p 871 wincmd p
872 3 872 3
873 exe "normal \<CR>" 873 exe "normal \<CR>"
874 wincmd p 874 wincmd p
875 4 875 4
876 exe "normal \<CR>" 876 exe "normal \<CR>"
877 1wincmd w 877 1wincmd w
878 call assert_equal('quickfix', &buftype) 878 call assert_equal('quickfix', &buftype)
879 2wincmd w 879 2wincmd w
880 let bufferName = expand("%") 880 let bufferName = expand("%")
881 let bufferName = substitute(bufferName, '\\', '/', 'g') 881 let bufferName = substitute(bufferName, '\\', '/', 'g')
882 call assert_equal('test://quux.txt', bufferName) 882 call assert_equal('test://quux.txt', bufferName)
883 883
884 wincmd n | only 884 wincmd n | only
885 885
886 augroup! testgroup 886 augroup! testgroup
887 endfunc 887 endfunc
888 888
889 func Test_locationlist_curwin_was_closed() 889 func Test_locationlist_curwin_was_closed()
890 augroup testgroup 890 augroup testgroup
891 au! 891 au!
892 autocmd BufReadCmd test_curwin.txt call R(expand("<amatch>")) 892 autocmd BufReadCmd test_curwin.txt call R(expand("<amatch>"))
893 augroup END 893 augroup END
894 894
895 func! R(n) 895 func! R(n)
896 quit 896 quit
897 endfunc 897 endfunc
898 898
899 new 899 new
900 let q = [] 900 let q = []
901 call add(q, {'filename': 'test_curwin.txt' }) 901 call add(q, {'filename': 'test_curwin.txt' })
902 call setloclist(0, q) 902 call setloclist(0, q)
903 call assert_fails('lrewind', 'E924:') 903 call assert_fails('lrewind', 'E924:')
904 904
905 augroup! testgroup 905 augroup! testgroup
906 endfunc 906 endfunc
907 907
908 func Test_locationlist_cross_tab_jump() 908 func Test_locationlist_cross_tab_jump()
909 call writefile(['loclistfoo'], 'loclistfoo') 909 call writefile(['loclistfoo'], 'loclistfoo')
910 call writefile(['loclistbar'], 'loclistbar') 910 call writefile(['loclistbar'], 'loclistbar')
921 call delete('loclistbar') 921 call delete('loclistbar')
922 endfunc 922 endfunc
923 923
924 " More tests for 'errorformat' 924 " More tests for 'errorformat'
925 func Test_efm1() 925 func Test_efm1()
926 if !has('unix') 926 " The 'errorformat' setting is different on non-Unix systems.
927 " The 'errorformat' setting is different on non-Unix systems. 927 " This test works only on Unix-like systems.
928 " This test works only on Unix-like systems. 928 CheckUnix
929 return 929
930 endif 930 let l =<< trim [DATA]
931 931 "Xtestfile", line 4.12: 1506-045 (S) Undeclared identifier fd_set.
932 let l =<< trim [DATA] 932 "Xtestfile", line 6 col 19; this is an error
933 "Xtestfile", line 4.12: 1506-045 (S) Undeclared identifier fd_set. 933 gcc -c -DHAVE_CONFIsing-prototypes -I/usr/X11R6/include version.c
934 "Xtestfile", line 6 col 19; this is an error 934 Xtestfile:9: parse error before `asd'
935 gcc -c -DHAVE_CONFIsing-prototypes -I/usr/X11R6/include version.c 935 make: *** [vim] Error 1
936 Xtestfile:9: parse error before `asd' 936 in file "Xtestfile" linenr 10: there is an error
937 make: *** [vim] Error 1 937
938 in file "Xtestfile" linenr 10: there is an error 938 2 returned
939 939 "Xtestfile", line 11 col 1; this is an error
940 2 returned 940 "Xtestfile", line 12 col 2; this is another error
941 "Xtestfile", line 11 col 1; this is an error 941 "Xtestfile", line 14:10; this is an error in column 10
942 "Xtestfile", line 12 col 2; this is another error 942 =Xtestfile=, line 15:10; this is another error, but in vcol 10 this time
943 "Xtestfile", line 14:10; this is an error in column 10 943 "Xtestfile", linenr 16: yet another problem
944 =Xtestfile=, line 15:10; this is another error, but in vcol 10 this time 944 Error in "Xtestfile" at line 17:
945 "Xtestfile", linenr 16: yet another problem 945 x should be a dot
946 Error in "Xtestfile" at line 17: 946 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 17
947 x should be a dot 947 ^
948 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 17 948 Error in "Xtestfile" at line 18:
949 ^ 949 x should be a dot
950 Error in "Xtestfile" at line 18: 950 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 18
951 x should be a dot 951 .............^
952 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 18 952 Error in "Xtestfile" at line 19:
953 .............^ 953 x should be a dot
954 Error in "Xtestfile" at line 19: 954 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 19
955 x should be a dot 955 --------------^
956 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 19 956 Error in "Xtestfile" at line 20:
957 --------------^ 957 x should be a dot
958 Error in "Xtestfile" at line 20: 958 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 20
959 x should be a dot 959 ^
960 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 20 960
961 ^ 961 Does anyone know what is the problem and how to correction it?
962 962 "Xtestfile", line 21 col 9: What is the title of the quickfix window?
963 Does anyone know what is the problem and how to correction it? 963 "Xtestfile", line 22 col 9: What is the title of the quickfix window?
964 "Xtestfile", line 21 col 9: What is the title of the quickfix window? 964 [DATA]
965 "Xtestfile", line 22 col 9: What is the title of the quickfix window? 965
966 [DATA] 966 call writefile(l, 'Xerrorfile1')
967 967 call writefile(l[:-2], 'Xerrorfile2')
968 call writefile(l, 'Xerrorfile1') 968
969 call writefile(l[:-2], 'Xerrorfile2') 969 let m =<< [DATA]
970
971 let m =<< [DATA]
972 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 2 970 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 2
973 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 3 971 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 3
974 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 4 972 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 4
975 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 5 973 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 5
976 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 6 974 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 6
989 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 19 987 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 19
990 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 20 988 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 20
991 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 21 989 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 21
992 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 22 990 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 22
993 [DATA] 991 [DATA]
994 call writefile(m, 'Xtestfile') 992 call writefile(m, 'Xtestfile')
995 993
996 let save_efm = &efm 994 let save_efm = &efm
997 set efm+==%f=\\,\ line\ %l%*\\D%v%*[^\ ]\ %m 995 set efm+==%f=\\,\ line\ %l%*\\D%v%*[^\ ]\ %m
998 set efm^=%AError\ in\ \"%f\"\ at\ line\ %l:,%Z%p^,%C%m 996 set efm^=%AError\ in\ \"%f\"\ at\ line\ %l:,%Z%p^,%C%m
999 997
1000 exe 'cf Xerrorfile2' 998 exe 'cf Xerrorfile2'
1001 clast 999 clast
1002 copen 1000 copen
1003 call assert_equal(':cf Xerrorfile2', w:quickfix_title) 1001 call assert_equal(':cf Xerrorfile2', w:quickfix_title)
1004 wincmd p 1002 wincmd p
1005 1003
1006 exe 'cf Xerrorfile1' 1004 exe 'cf Xerrorfile1'
1007 call assert_equal([4, 12], [line('.'), col('.')]) 1005 call assert_equal([4, 12], [line('.'), col('.')])
1008 cn 1006 cn
1009 call assert_equal([6, 19], [line('.'), col('.')]) 1007 call assert_equal([6, 19], [line('.'), col('.')])
1010 cn 1008 cn
1011 call assert_equal([9, 2], [line('.'), col('.')]) 1009 call assert_equal([9, 2], [line('.'), col('.')])
1012 cn 1010 cn
1013 call assert_equal([10, 2], [line('.'), col('.')]) 1011 call assert_equal([10, 2], [line('.'), col('.')])
1014 cn 1012 cn
1015 call assert_equal([11, 1], [line('.'), col('.')]) 1013 call assert_equal([11, 1], [line('.'), col('.')])
1016 cn 1014 cn
1017 call assert_equal([12, 2], [line('.'), col('.')]) 1015 call assert_equal([12, 2], [line('.'), col('.')])
1018 cn 1016 cn
1019 call assert_equal([14, 10], [line('.'), col('.')]) 1017 call assert_equal([14, 10], [line('.'), col('.')])
1020 cn 1018 cn
1021 call assert_equal([15, 3, 10], [line('.'), col('.'), virtcol('.')]) 1019 call assert_equal([15, 3, 10], [line('.'), col('.'), virtcol('.')])
1022 cn 1020 cn
1023 call assert_equal([16, 2], [line('.'), col('.')]) 1021 call assert_equal([16, 2], [line('.'), col('.')])
1024 cn 1022 cn
1025 call assert_equal([17, 6], [line('.'), col('.')]) 1023 call assert_equal([17, 6], [line('.'), col('.')])
1026 cn 1024 cn
1027 call assert_equal([18, 7], [line('.'), col('.')]) 1025 call assert_equal([18, 7], [line('.'), col('.')])
1028 cn 1026 cn
1029 call assert_equal([19, 8], [line('.'), col('.')]) 1027 call assert_equal([19, 8], [line('.'), col('.')])
1030 cn 1028 cn
1031 call assert_equal([20, 9], [line('.'), col('.')]) 1029 call assert_equal([20, 9], [line('.'), col('.')])
1032 clast 1030 clast
1033 cprev 1031 cprev
1034 cprev 1032 cprev
1035 wincmd w 1033 wincmd w
1036 call assert_equal(':cf Xerrorfile1', w:quickfix_title) 1034 call assert_equal(':cf Xerrorfile1', w:quickfix_title)
1037 wincmd p 1035 wincmd p
1038 1036
1039 let &efm = save_efm 1037 let &efm = save_efm
1040 call delete('Xerrorfile1') 1038 call delete('Xerrorfile1')
1041 call delete('Xerrorfile2') 1039 call delete('Xerrorfile2')
1042 call delete('Xtestfile') 1040 call delete('Xtestfile')
1043 endfunc 1041 endfunc
1044 1042
1045 " Test for quickfix directory stack support 1043 " Test for quickfix directory stack support
1046 func s:dir_stack_tests(cchar) 1044 func s:dir_stack_tests(cchar)
1047 call s:setup_commands(a:cchar) 1045 call s:setup_commands(a:cchar)
1979 call assert_false(filereadable('XtestTempFile')) 1977 call assert_false(filereadable('XtestTempFile'))
1980 set makeef&vim 1978 set makeef&vim
1981 endfunc 1979 endfunc
1982 1980
1983 func Test_grep() 1981 func Test_grep()
1984 if !has('unix') 1982 " The grepprg may not be set on non-Unix systems
1985 " The grepprg may not be set on non-Unix systems 1983 CheckUnix
1986 return
1987 endif
1988 1984
1989 call s:test_xgrep('c') 1985 call s:test_xgrep('c')
1990 call s:test_xgrep('l') 1986 call s:test_xgrep('l')
1991 endfunc 1987 endfunc
1992 1988
2120 call delete('Xgrepthis') 2116 call delete('Xgrepthis')
2121 endfunc 2117 endfunc
2122 2118
2123 " Quickfix/Location list set/get properties tests 2119 " Quickfix/Location list set/get properties tests
2124 func Xproperty_tests(cchar) 2120 func Xproperty_tests(cchar)
2125 call s:setup_commands(a:cchar) 2121 call s:setup_commands(a:cchar)
2126 2122
2127 " Error cases 2123 " Error cases
2128 call assert_fails('call g:Xgetlist(99)', 'E715:') 2124 call assert_fails('call g:Xgetlist(99)', 'E715:')
2129 call assert_fails('call g:Xsetlist(99)', 'E714:') 2125 call assert_fails('call g:Xsetlist(99)', 'E714:')
2130 call assert_fails('call g:Xsetlist([], "a", [])', 'E715:') 2126 call assert_fails('call g:Xsetlist([], "a", [])', 'E715:')
2131 2127
2132 " Set and get the title 2128 " Set and get the title
2133 call g:Xsetlist([]) 2129 call g:Xsetlist([])
2130 Xopen
2131 wincmd p
2132 call g:Xsetlist([{'filename':'foo', 'lnum':27}])
2133 let s = g:Xsetlist([], 'a', {'title' : 'Sample'})
2134 call assert_equal(0, s)
2135 let d = g:Xgetlist({"title":1})
2136 call assert_equal('Sample', d.title)
2137 " Try setting title to a non-string value
2138 call assert_equal(-1, g:Xsetlist([], 'a', {'title' : ['Test']}))
2139 call assert_equal('Sample', g:Xgetlist({"title":1}).title)
2140
2141 Xopen
2142 call assert_equal('Sample', w:quickfix_title)
2143 Xclose
2144
2145 " Tests for action argument
2146 silent! Xolder 999
2147 let qfnr = g:Xgetlist({'all':1}).nr
2148 call g:Xsetlist([], 'r', {'title' : 'N1'})
2149 call assert_equal('N1', g:Xgetlist({'all':1}).title)
2150 call g:Xsetlist([], ' ', {'title' : 'N2'})
2151 call assert_equal(qfnr + 1, g:Xgetlist({'all':1}).nr)
2152
2153 let res = g:Xgetlist({'nr': 0})
2154 call assert_equal(qfnr + 1, res.nr)
2155 call assert_equal(['nr'], keys(res))
2156
2157 call g:Xsetlist([], ' ', {'title' : 'N3'})
2158 call assert_equal('N2', g:Xgetlist({'nr':2, 'title':1}).title)
2159
2160 " Changing the title of an earlier quickfix list
2161 call g:Xsetlist([], 'r', {'title' : 'NewTitle', 'nr' : 2})
2162 call assert_equal('NewTitle', g:Xgetlist({'nr':2, 'title':1}).title)
2163
2164 " Changing the title of an invalid quickfix list
2165 call assert_equal(-1, g:Xsetlist([], ' ',
2166 \ {'title' : 'SomeTitle', 'nr' : 99}))
2167 call assert_equal(-1, g:Xsetlist([], ' ',
2168 \ {'title' : 'SomeTitle', 'nr' : 'abc'}))
2169
2170 if a:cchar == 'c'
2171 copen
2172 call assert_equal({'winid':win_getid()}, getqflist({'winid':1}))
2173 cclose
2174 endif
2175
2176 " Invalid arguments
2177 call assert_fails('call g:Xgetlist([])', 'E715')
2178 call assert_fails('call g:Xsetlist([], "a", [])', 'E715')
2179 let s = g:Xsetlist([], 'a', {'abc':1})
2180 call assert_equal(-1, s)
2181
2182 call assert_equal({}, g:Xgetlist({'abc':1}))
2183 call assert_equal('', g:Xgetlist({'nr':99, 'title':1}).title)
2184 call assert_equal('', g:Xgetlist({'nr':[], 'title':1}).title)
2185
2186 if a:cchar == 'l'
2187 call assert_equal({}, getloclist(99, {'title': 1}))
2188 endif
2189
2190 " Context related tests
2191 let s = g:Xsetlist([], 'a', {'context':[1,2,3]})
2192 call assert_equal(0, s)
2193 call test_garbagecollect_now()
2194 let d = g:Xgetlist({'context':1})
2195 call assert_equal([1,2,3], d.context)
2196 call g:Xsetlist([], 'a', {'context':{'color':'green'}})
2197 let d = g:Xgetlist({'context':1})
2198 call assert_equal({'color':'green'}, d.context)
2199 call g:Xsetlist([], 'a', {'context':"Context info"})
2200 let d = g:Xgetlist({'context':1})
2201 call assert_equal("Context info", d.context)
2202 call g:Xsetlist([], 'a', {'context':246})
2203 let d = g:Xgetlist({'context':1})
2204 call assert_equal(246, d.context)
2205 " set other Vim data types as context
2206 call g:Xsetlist([], 'a', {'context' : test_null_blob()})
2207 if has('channel')
2208 call g:Xsetlist([], 'a', {'context' : test_null_channel()})
2209 endif
2210 if has('job')
2211 call g:Xsetlist([], 'a', {'context' : test_null_job()})
2212 endif
2213 call g:Xsetlist([], 'a', {'context' : test_null_function()})
2214 call g:Xsetlist([], 'a', {'context' : test_null_partial()})
2215 call g:Xsetlist([], 'a', {'context' : ''})
2216 call test_garbagecollect_now()
2217 if a:cchar == 'l'
2218 " Test for copying context across two different location lists
2219 new | only
2220 let w1_id = win_getid()
2221 let l = [1]
2222 call setloclist(0, [], 'a', {'context':l})
2223 new
2224 let w2_id = win_getid()
2225 call add(l, 2)
2226 call assert_equal([1, 2], getloclist(w1_id, {'context':1}).context)
2227 call assert_equal([1, 2], getloclist(w2_id, {'context':1}).context)
2228 unlet! l
2229 call assert_equal([1, 2], getloclist(w2_id, {'context':1}).context)
2230 only
2231 call setloclist(0, [], 'f')
2232 call assert_equal('', getloclist(0, {'context':1}).context)
2233 endif
2234
2235 " Test for changing the context of previous quickfix lists
2236 call g:Xsetlist([], 'f')
2237 Xexpr "One"
2238 Xexpr "Two"
2239 Xexpr "Three"
2240 call g:Xsetlist([], 'r', {'context' : [1], 'nr' : 1})
2241 call g:Xsetlist([], 'a', {'context' : [2], 'nr' : 2})
2242 " Also, check for setting the context using quickfix list number zero.
2243 call g:Xsetlist([], 'r', {'context' : [3], 'nr' : 0})
2244 call test_garbagecollect_now()
2245 let l = g:Xgetlist({'nr' : 1, 'context' : 1})
2246 call assert_equal([1], l.context)
2247 let l = g:Xgetlist({'nr' : 2, 'context' : 1})
2248 call assert_equal([2], l.context)
2249 let l = g:Xgetlist({'nr' : 3, 'context' : 1})
2250 call assert_equal([3], l.context)
2251
2252 " Test for changing the context through reference and for garbage
2253 " collection of quickfix context
2254 let l = ["red"]
2255 call g:Xsetlist([], ' ', {'context' : l})
2256 call add(l, "blue")
2257 let x = g:Xgetlist({'context' : 1})
2258 call add(x.context, "green")
2259 call assert_equal(["red", "blue", "green"], l)
2260 call assert_equal(["red", "blue", "green"], x.context)
2261 unlet l
2262 call test_garbagecollect_now()
2263 let m = g:Xgetlist({'context' : 1})
2264 call assert_equal(["red", "blue", "green"], m.context)
2265
2266 " Test for setting/getting items
2267 Xexpr ""
2268 let qfprev = g:Xgetlist({'nr':0})
2269 let s = g:Xsetlist([], ' ', {'title':'Green',
2270 \ 'items' : [{'filename':'F1', 'lnum':10}]})
2271 call assert_equal(0, s)
2272 let qfcur = g:Xgetlist({'nr':0})
2273 call assert_true(qfcur.nr == qfprev.nr + 1)
2274 let l = g:Xgetlist({'items':1})
2275 call assert_equal('F1', bufname(l.items[0].bufnr))
2276 call assert_equal(10, l.items[0].lnum)
2277 call g:Xsetlist([], 'a', {'items' : [{'filename':'F2', 'lnum':20},
2278 \ {'filename':'F2', 'lnum':30}]})
2279 let l = g:Xgetlist({'items':1})
2280 call assert_equal('F2', bufname(l.items[2].bufnr))
2281 call assert_equal(30, l.items[2].lnum)
2282 call g:Xsetlist([], 'r', {'items' : [{'filename':'F3', 'lnum':40}]})
2283 let l = g:Xgetlist({'items':1})
2284 call assert_equal('F3', bufname(l.items[0].bufnr))
2285 call assert_equal(40, l.items[0].lnum)
2286 call g:Xsetlist([], 'r', {'items' : []})
2287 let l = g:Xgetlist({'items':1})
2288 call assert_equal(0, len(l.items))
2289
2290 call g:Xsetlist([], 'r', {'title' : 'TestTitle'})
2291 call g:Xsetlist([], 'r', {'items' : [{'filename' : 'F1', 'lnum' : 10, 'text' : 'L10'}]})
2292 call g:Xsetlist([], 'r', {'items' : [{'filename' : 'F1', 'lnum' : 10, 'text' : 'L10'}]})
2293 call assert_equal('TestTitle', g:Xgetlist({'title' : 1}).title)
2294
2295 " Test for getting id of window associated with a location list window
2296 if a:cchar == 'l'
2297 only
2298 call assert_equal(0, g:Xgetlist({'all' : 1}).filewinid)
2299 let wid = win_getid()
2134 Xopen 2300 Xopen
2135 wincmd p 2301 call assert_equal(wid, g:Xgetlist({'filewinid' : 1}).filewinid)
2136 call g:Xsetlist([{'filename':'foo', 'lnum':27}]) 2302 wincmd w
2137 let s = g:Xsetlist([], 'a', {'title' : 'Sample'}) 2303 call assert_equal(0, g:Xgetlist({'filewinid' : 1}).filewinid)
2138 call assert_equal(0, s) 2304 only
2139 let d = g:Xgetlist({"title":1}) 2305 endif
2140 call assert_equal('Sample', d.title) 2306
2141 " Try setting title to a non-string value 2307 " The following used to crash Vim with address sanitizer
2142 call assert_equal(-1, g:Xsetlist([], 'a', {'title' : ['Test']})) 2308 call g:Xsetlist([], 'f')
2143 call assert_equal('Sample', g:Xgetlist({"title":1}).title) 2309 call g:Xsetlist([], 'a', {'items' : [{'filename':'F1', 'lnum':10}]})
2144 2310 call assert_equal(10, g:Xgetlist({'items':1}).items[0].lnum)
2145 Xopen 2311
2146 call assert_equal('Sample', w:quickfix_title) 2312 " Try setting the items using a string
2147 Xclose 2313 call assert_equal(-1, g:Xsetlist([], ' ', {'items' : 'Test'}))
2148 2314
2149 " Tests for action argument 2315 " Save and restore the quickfix stack
2150 silent! Xolder 999 2316 call g:Xsetlist([], 'f')
2151 let qfnr = g:Xgetlist({'all':1}).nr 2317 call assert_equal(0, g:Xgetlist({'nr':'$'}).nr)
2152 call g:Xsetlist([], 'r', {'title' : 'N1'}) 2318 Xexpr "File1:10:Line1"
2153 call assert_equal('N1', g:Xgetlist({'all':1}).title) 2319 Xexpr "File2:20:Line2"
2154 call g:Xsetlist([], ' ', {'title' : 'N2'}) 2320 Xexpr "File3:30:Line3"
2155 call assert_equal(qfnr + 1, g:Xgetlist({'all':1}).nr) 2321 let last_qf = g:Xgetlist({'nr':'$'}).nr
2156 2322 call assert_equal(3, last_qf)
2157 let res = g:Xgetlist({'nr': 0}) 2323 let qstack = []
2158 call assert_equal(qfnr + 1, res.nr) 2324 for i in range(1, last_qf)
2159 call assert_equal(['nr'], keys(res)) 2325 let qstack = add(qstack, g:Xgetlist({'nr':i, 'all':1}))
2160 2326 endfor
2161 call g:Xsetlist([], ' ', {'title' : 'N3'}) 2327 call g:Xsetlist([], 'f')
2162 call assert_equal('N2', g:Xgetlist({'nr':2, 'title':1}).title) 2328 for i in range(len(qstack))
2163 2329 call g:Xsetlist([], ' ', qstack[i])
2164 " Changing the title of an earlier quickfix list 2330 endfor
2165 call g:Xsetlist([], 'r', {'title' : 'NewTitle', 'nr' : 2}) 2331 call assert_equal(3, g:Xgetlist({'nr':'$'}).nr)
2166 call assert_equal('NewTitle', g:Xgetlist({'nr':2, 'title':1}).title) 2332 call assert_equal(10, g:Xgetlist({'nr':1, 'items':1}).items[0].lnum)
2167 2333 call assert_equal(20, g:Xgetlist({'nr':2, 'items':1}).items[0].lnum)
2168 " Changing the title of an invalid quickfix list 2334 call assert_equal(30, g:Xgetlist({'nr':3, 'items':1}).items[0].lnum)
2169 call assert_equal(-1, g:Xsetlist([], ' ', 2335 call g:Xsetlist([], 'f')
2170 \ {'title' : 'SomeTitle', 'nr' : 99})) 2336
2171 call assert_equal(-1, g:Xsetlist([], ' ', 2337 " Swap two quickfix lists
2172 \ {'title' : 'SomeTitle', 'nr' : 'abc'})) 2338 Xexpr "File1:10:Line10"
2173 2339 Xexpr "File2:20:Line20"
2174 if a:cchar == 'c' 2340 Xexpr "File3:30:Line30"
2175 copen 2341 call g:Xsetlist([], 'r', {'nr':1,'title':'Colors','context':['Colors']})
2176 call assert_equal({'winid':win_getid()}, getqflist({'winid':1})) 2342 call g:Xsetlist([], 'r', {'nr':2,'title':'Fruits','context':['Fruits']})
2177 cclose 2343 let l1=g:Xgetlist({'nr':1,'all':1})
2178 endif 2344 let l2=g:Xgetlist({'nr':2,'all':1})
2179 2345 let save_id = l1.id
2180 " Invalid arguments 2346 let l1.id=l2.id
2181 call assert_fails('call g:Xgetlist([])', 'E715') 2347 let l2.id=save_id
2182 call assert_fails('call g:Xsetlist([], "a", [])', 'E715') 2348 call g:Xsetlist([], 'r', l1)
2183 let s = g:Xsetlist([], 'a', {'abc':1}) 2349 call g:Xsetlist([], 'r', l2)
2184 call assert_equal(-1, s) 2350 let newl1=g:Xgetlist({'nr':1,'all':1})
2185 2351 let newl2=g:Xgetlist({'nr':2,'all':1})
2186 call assert_equal({}, g:Xgetlist({'abc':1})) 2352 call assert_equal('Fruits', newl1.title)
2187 call assert_equal('', g:Xgetlist({'nr':99, 'title':1}).title) 2353 call assert_equal(['Fruits'], newl1.context)
2188 call assert_equal('', g:Xgetlist({'nr':[], 'title':1}).title) 2354 call assert_equal('Line20', newl1.items[0].text)
2189 2355 call assert_equal('Colors', newl2.title)
2190 if a:cchar == 'l' 2356 call assert_equal(['Colors'], newl2.context)
2191 call assert_equal({}, getloclist(99, {'title': 1})) 2357 call assert_equal('Line10', newl2.items[0].text)
2192 endif 2358 call g:Xsetlist([], 'f')
2193 2359
2194 " Context related tests 2360 " Cannot specify both a non-empty list argument and a dict argument
2195 let s = g:Xsetlist([], 'a', {'context':[1,2,3]}) 2361 call assert_fails("call g:Xsetlist([{}], ' ', {})", 'E475:')
2196 call assert_equal(0, s)
2197 call test_garbagecollect_now()
2198 let d = g:Xgetlist({'context':1})
2199 call assert_equal([1,2,3], d.context)
2200 call g:Xsetlist([], 'a', {'context':{'color':'green'}})
2201 let d = g:Xgetlist({'context':1})
2202 call assert_equal({'color':'green'}, d.context)
2203 call g:Xsetlist([], 'a', {'context':"Context info"})
2204 let d = g:Xgetlist({'context':1})
2205 call assert_equal("Context info", d.context)
2206 call g:Xsetlist([], 'a', {'context':246})
2207 let d = g:Xgetlist({'context':1})
2208 call assert_equal(246, d.context)
2209 " set other Vim data types as context
2210 call g:Xsetlist([], 'a', {'context' : test_null_blob()})
2211 if has('channel')
2212 call g:Xsetlist([], 'a', {'context' : test_null_channel()})
2213 endif
2214 if has('job')
2215 call g:Xsetlist([], 'a', {'context' : test_null_job()})
2216 endif
2217 call g:Xsetlist([], 'a', {'context' : test_null_function()})
2218 call g:Xsetlist([], 'a', {'context' : test_null_partial()})
2219 call g:Xsetlist([], 'a', {'context' : ''})
2220 call test_garbagecollect_now()
2221 if a:cchar == 'l'
2222 " Test for copying context across two different location lists
2223 new | only
2224 let w1_id = win_getid()
2225 let l = [1]
2226 call setloclist(0, [], 'a', {'context':l})
2227 new
2228 let w2_id = win_getid()
2229 call add(l, 2)
2230 call assert_equal([1, 2], getloclist(w1_id, {'context':1}).context)
2231 call assert_equal([1, 2], getloclist(w2_id, {'context':1}).context)
2232 unlet! l
2233 call assert_equal([1, 2], getloclist(w2_id, {'context':1}).context)
2234 only
2235 call setloclist(0, [], 'f')
2236 call assert_equal('', getloclist(0, {'context':1}).context)
2237 endif
2238
2239 " Test for changing the context of previous quickfix lists
2240 call g:Xsetlist([], 'f')
2241 Xexpr "One"
2242 Xexpr "Two"
2243 Xexpr "Three"
2244 call g:Xsetlist([], 'r', {'context' : [1], 'nr' : 1})
2245 call g:Xsetlist([], 'a', {'context' : [2], 'nr' : 2})
2246 " Also, check for setting the context using quickfix list number zero.
2247 call g:Xsetlist([], 'r', {'context' : [3], 'nr' : 0})
2248 call test_garbagecollect_now()
2249 let l = g:Xgetlist({'nr' : 1, 'context' : 1})
2250 call assert_equal([1], l.context)
2251 let l = g:Xgetlist({'nr' : 2, 'context' : 1})
2252 call assert_equal([2], l.context)
2253 let l = g:Xgetlist({'nr' : 3, 'context' : 1})
2254 call assert_equal([3], l.context)
2255
2256 " Test for changing the context through reference and for garbage
2257 " collection of quickfix context
2258 let l = ["red"]
2259 call g:Xsetlist([], ' ', {'context' : l})
2260 call add(l, "blue")
2261 let x = g:Xgetlist({'context' : 1})
2262 call add(x.context, "green")
2263 call assert_equal(["red", "blue", "green"], l)
2264 call assert_equal(["red", "blue", "green"], x.context)
2265 unlet l
2266 call test_garbagecollect_now()
2267 let m = g:Xgetlist({'context' : 1})
2268 call assert_equal(["red", "blue", "green"], m.context)
2269
2270 " Test for setting/getting items
2271 Xexpr ""
2272 let qfprev = g:Xgetlist({'nr':0})
2273 let s = g:Xsetlist([], ' ', {'title':'Green',
2274 \ 'items' : [{'filename':'F1', 'lnum':10}]})
2275 call assert_equal(0, s)
2276 let qfcur = g:Xgetlist({'nr':0})
2277 call assert_true(qfcur.nr == qfprev.nr + 1)
2278 let l = g:Xgetlist({'items':1})
2279 call assert_equal('F1', bufname(l.items[0].bufnr))
2280 call assert_equal(10, l.items[0].lnum)
2281 call g:Xsetlist([], 'a', {'items' : [{'filename':'F2', 'lnum':20},
2282 \ {'filename':'F2', 'lnum':30}]})
2283 let l = g:Xgetlist({'items':1})
2284 call assert_equal('F2', bufname(l.items[2].bufnr))
2285 call assert_equal(30, l.items[2].lnum)
2286 call g:Xsetlist([], 'r', {'items' : [{'filename':'F3', 'lnum':40}]})
2287 let l = g:Xgetlist({'items':1})
2288 call assert_equal('F3', bufname(l.items[0].bufnr))
2289 call assert_equal(40, l.items[0].lnum)
2290 call g:Xsetlist([], 'r', {'items' : []})
2291 let l = g:Xgetlist({'items':1})
2292 call assert_equal(0, len(l.items))
2293
2294 call g:Xsetlist([], 'r', {'title' : 'TestTitle'})
2295 call g:Xsetlist([], 'r', {'items' : [{'filename' : 'F1', 'lnum' : 10, 'text' : 'L10'}]})
2296 call g:Xsetlist([], 'r', {'items' : [{'filename' : 'F1', 'lnum' : 10, 'text' : 'L10'}]})
2297 call assert_equal('TestTitle', g:Xgetlist({'title' : 1}).title)
2298
2299 " Test for getting id of window associated with a location list window
2300 if a:cchar == 'l'
2301 only
2302 call assert_equal(0, g:Xgetlist({'all' : 1}).filewinid)
2303 let wid = win_getid()
2304 Xopen
2305 call assert_equal(wid, g:Xgetlist({'filewinid' : 1}).filewinid)
2306 wincmd w
2307 call assert_equal(0, g:Xgetlist({'filewinid' : 1}).filewinid)
2308 only
2309 endif
2310
2311 " The following used to crash Vim with address sanitizer
2312 call g:Xsetlist([], 'f')
2313 call g:Xsetlist([], 'a', {'items' : [{'filename':'F1', 'lnum':10}]})
2314 call assert_equal(10, g:Xgetlist({'items':1}).items[0].lnum)
2315
2316 " Try setting the items using a string
2317 call assert_equal(-1, g:Xsetlist([], ' ', {'items' : 'Test'}))
2318
2319 " Save and restore the quickfix stack
2320 call g:Xsetlist([], 'f')
2321 call assert_equal(0, g:Xgetlist({'nr':'$'}).nr)
2322 Xexpr "File1:10:Line1"
2323 Xexpr "File2:20:Line2"
2324 Xexpr "File3:30:Line3"
2325 let last_qf = g:Xgetlist({'nr':'$'}).nr
2326 call assert_equal(3, last_qf)
2327 let qstack = []
2328 for i in range(1, last_qf)
2329 let qstack = add(qstack, g:Xgetlist({'nr':i, 'all':1}))
2330 endfor
2331 call g:Xsetlist([], 'f')
2332 for i in range(len(qstack))
2333 call g:Xsetlist([], ' ', qstack[i])
2334 endfor
2335 call assert_equal(3, g:Xgetlist({'nr':'$'}).nr)
2336 call assert_equal(10, g:Xgetlist({'nr':1, 'items':1}).items[0].lnum)
2337 call assert_equal(20, g:Xgetlist({'nr':2, 'items':1}).items[0].lnum)
2338 call assert_equal(30, g:Xgetlist({'nr':3, 'items':1}).items[0].lnum)
2339 call g:Xsetlist([], 'f')
2340
2341 " Swap two quickfix lists
2342 Xexpr "File1:10:Line10"
2343 Xexpr "File2:20:Line20"
2344 Xexpr "File3:30:Line30"
2345 call g:Xsetlist([], 'r', {'nr':1,'title':'Colors','context':['Colors']})
2346 call g:Xsetlist([], 'r', {'nr':2,'title':'Fruits','context':['Fruits']})
2347 let l1=g:Xgetlist({'nr':1,'all':1})
2348 let l2=g:Xgetlist({'nr':2,'all':1})
2349 let save_id = l1.id
2350 let l1.id=l2.id
2351 let l2.id=save_id
2352 call g:Xsetlist([], 'r', l1)
2353 call g:Xsetlist([], 'r', l2)
2354 let newl1=g:Xgetlist({'nr':1,'all':1})
2355 let newl2=g:Xgetlist({'nr':2,'all':1})
2356 call assert_equal('Fruits', newl1.title)
2357 call assert_equal(['Fruits'], newl1.context)
2358 call assert_equal('Line20', newl1.items[0].text)
2359 call assert_equal('Colors', newl2.title)
2360 call assert_equal(['Colors'], newl2.context)
2361 call assert_equal('Line10', newl2.items[0].text)
2362 call g:Xsetlist([], 'f')
2363
2364 " Cannot specify both a non-empty list argument and a dict argument
2365 call assert_fails("call g:Xsetlist([{}], ' ', {})", 'E475:')
2366 endfunc 2362 endfunc
2367 2363
2368 func Test_qf_property() 2364 func Test_qf_property()
2369 call Xproperty_tests('c') 2365 call Xproperty_tests('c')
2370 call Xproperty_tests('l') 2366 call Xproperty_tests('l')
2371 endfunc 2367 endfunc
2372 2368
2373 " Test for setting the current index in the location/quickfix list 2369 " Test for setting the current index in the location/quickfix list
2374 func Xtest_setqfidx(cchar) 2370 func Xtest_setqfidx(cchar)
2375 call s:setup_commands(a:cchar) 2371 call s:setup_commands(a:cchar)
2848 vimgrep apple Xapple 2844 vimgrep apple Xapple
2849 call assert_equal(1, g:foundSwap) 2845 call assert_equal(1, g:foundSwap)
2850 call assert_match('.Xapple.swo', swapname('')) 2846 call assert_match('.Xapple.swo', swapname(''))
2851 2847
2852 call delete('Xapple') 2848 call delete('Xapple')
2853 call delete('Xapple.swp') 2849 call delete('.Xapple.swp')
2854 augroup grep 2850 augroup grep
2855 au! SwapExists 2851 au! SwapExists
2856 augroup END 2852 augroup END
2857 unlet g:ignoreSwapExists 2853 unlet g:ignoreSwapExists
2858 endfunc 2854 endfunc
3020 3016
3021 augroup! QF_Test 3017 augroup! QF_Test
3022 endfunc 3018 endfunc
3023 3019
3024 func Test_resize_from_copen() 3020 func Test_resize_from_copen()
3021 augroup QF_Test
3022 au!
3023 au FileType qf resize 5
3024 augroup END
3025 try
3026 " This should succeed without any exception. No other buffers are
3027 " involved in the autocmd.
3028 copen
3029 finally
3025 augroup QF_Test 3030 augroup QF_Test
3026 au! 3031 au!
3027 au FileType qf resize 5
3028 augroup END 3032 augroup END
3029 try 3033 augroup! QF_Test
3030 " This should succeed without any exception. No other buffers are 3034 endtry
3031 " involved in the autocmd.
3032 copen
3033 finally
3034 augroup QF_Test
3035 au!
3036 augroup END
3037 augroup! QF_Test
3038 endtry
3039 endfunc 3035 endfunc
3040 3036
3041 " Tests for the quickfix buffer b:changedtick variable 3037 " Tests for the quickfix buffer b:changedtick variable
3042 func Xchangedtick_tests(cchar) 3038 func Xchangedtick_tests(cchar)
3043 call s:setup_commands(a:cchar) 3039 call s:setup_commands(a:cchar)
3225 endfunc 3221 endfunc
3226 3222
3227 " Open multiple help windows using ":lhelpgrep 3223 " Open multiple help windows using ":lhelpgrep
3228 " This test used to crash Vim 3224 " This test used to crash Vim
3229 func Test_Multi_LL_Help() 3225 func Test_Multi_LL_Help()
3230 new | only 3226 new | only
3231 lhelpgrep window 3227 lhelpgrep window
3232 lopen 3228 lopen
3233 e# 3229 e#
3234 lhelpgrep buffer 3230 lhelpgrep buffer
3235 call assert_equal(3, winnr('$')) 3231 call assert_equal(3, winnr('$'))
3236 call assert_true(len(getloclist(1)) != 0) 3232 call assert_true(len(getloclist(1)) != 0)
3237 call assert_true(len(getloclist(2)) != 0) 3233 call assert_true(len(getloclist(2)) != 0)
3238 new | only 3234 new | only
3239 endfunc 3235 endfunc
3240 3236
3241 " Tests for adding new quickfix lists using setqflist() 3237 " Tests for adding new quickfix lists using setqflist()
3242 func XaddQf_tests(cchar) 3238 func XaddQf_tests(cchar)
3243 call s:setup_commands(a:cchar) 3239 call s:setup_commands(a:cchar)
3924 endfunc 3920 endfunc
3925 3921
3926 " Test for shortening/simplifying the file name when opening the 3922 " Test for shortening/simplifying the file name when opening the
3927 " quickfix window or when displaying the quickfix list 3923 " quickfix window or when displaying the quickfix list
3928 func Test_shorten_fname() 3924 func Test_shorten_fname()
3929 if !has('unix') 3925 CheckUnix
3930 return
3931 endif
3932 %bwipe 3926 %bwipe
3933 " Create a quickfix list with a absolute path filename 3927 " Create a quickfix list with a absolute path filename
3934 let fname = getcwd() . '/test_quickfix.vim' 3928 let fname = getcwd() . '/test_quickfix.vim'
3935 call setqflist([], ' ', {'lines':[fname . ":20:Line20"], 'efm':'%f:%l:%m'}) 3929 call setqflist([], ' ', {'lines':[fname . ":20:Line20"], 'efm':'%f:%l:%m'})
3936 call assert_equal(fname, bufname('test_quickfix.vim')) 3930 call assert_equal(fname, bufname('test_quickfix.vim'))