comparison src/testdir/test_quickfix.vim @ 13026:7c0e0e923537 v8.0.1389

patch 8.0.1389: getqflist() items are missing if not set commit https://github.com/vim/vim/commit/a6d4849c711379b773529afaed640455287ac934 Author: Bram Moolenaar <Bram@vim.org> Date: Tue Dec 12 22:45:31 2017 +0100 patch 8.0.1389: getqflist() items are missing if not set Problem: getqflist() items are missing if not set, that makes it more difficult to handle the values. Solution: When a value is not available return zero or another invalid value. (Yegappan Lakshmanan, closes #2430)
author Christian Brabandt <cb@256bit.org>
date Tue, 12 Dec 2017 23:00:06 +0100
parents e47e70300f30
children 6479dadcf214
comparison
equal deleted inserted replaced
13025:5f7d269284a3 13026:7c0e0e923537
1831 call assert_fails('call g:Xsetlist([], "a", [])', 'E715') 1831 call assert_fails('call g:Xsetlist([], "a", [])', 'E715')
1832 let s = g:Xsetlist([], 'a', {'abc':1}) 1832 let s = g:Xsetlist([], 'a', {'abc':1})
1833 call assert_equal(-1, s) 1833 call assert_equal(-1, s)
1834 1834
1835 call assert_equal({}, g:Xgetlist({'abc':1})) 1835 call assert_equal({}, g:Xgetlist({'abc':1}))
1836 call assert_equal({}, g:Xgetlist({'nr':99, 'title':1})) 1836 call assert_equal('', g:Xgetlist({'nr':99, 'title':1}).title)
1837 call assert_equal({}, g:Xgetlist({'nr':[], 'title':1})) 1837 call assert_equal('', g:Xgetlist({'nr':[], 'title':1}).title)
1838 1838
1839 if a:cchar == 'l' 1839 if a:cchar == 'l'
1840 call assert_equal({}, getloclist(99, {'title': 1})) 1840 call assert_equal({}, getloclist(99, {'title': 1}))
1841 endif 1841 endif
1842 1842
1868 call assert_equal([1, 2], getloclist(w2_id, {'context':1}).context) 1868 call assert_equal([1, 2], getloclist(w2_id, {'context':1}).context)
1869 unlet! l 1869 unlet! l
1870 call assert_equal([1, 2], getloclist(w2_id, {'context':1}).context) 1870 call assert_equal([1, 2], getloclist(w2_id, {'context':1}).context)
1871 only 1871 only
1872 call setloclist(0, [], 'f') 1872 call setloclist(0, [], 'f')
1873 call assert_equal({}, getloclist(0, {'context':1})) 1873 call assert_equal('', getloclist(0, {'context':1}).context)
1874 endif 1874 endif
1875 1875
1876 " Test for changing the context of previous quickfix lists 1876 " Test for changing the context of previous quickfix lists
1877 call g:Xsetlist([], 'f') 1877 call g:Xsetlist([], 'f')
1878 Xexpr "One" 1878 Xexpr "One"
2381 func XsizeTests(cchar) 2381 func XsizeTests(cchar)
2382 call s:setup_commands(a:cchar) 2382 call s:setup_commands(a:cchar)
2383 2383
2384 call g:Xsetlist([], 'f') 2384 call g:Xsetlist([], 'f')
2385 call assert_equal(0, g:Xgetlist({'nr':'$'}).nr) 2385 call assert_equal(0, g:Xgetlist({'nr':'$'}).nr)
2386 call assert_equal(1, len(g:Xgetlist({'nr':'$', 'all':1}))) 2386 call assert_equal('', g:Xgetlist({'nr':'$', 'all':1}).title)
2387 call assert_equal(0, len(g:Xgetlist({'nr':0}))) 2387 call assert_equal(0, g:Xgetlist({'nr':0}).nr)
2388 2388
2389 Xexpr "File1:10:Line1" 2389 Xexpr "File1:10:Line1"
2390 Xexpr "File2:20:Line2" 2390 Xexpr "File2:20:Line2"
2391 Xexpr "File3:30:Line3" 2391 Xexpr "File3:30:Line3"
2392 Xolder | Xolder 2392 Xolder | Xolder
2752 " Tests for the quickfix list id 2752 " Tests for the quickfix list id
2753 func Xqfid_tests(cchar) 2753 func Xqfid_tests(cchar)
2754 call s:setup_commands(a:cchar) 2754 call s:setup_commands(a:cchar)
2755 2755
2756 call g:Xsetlist([], 'f') 2756 call g:Xsetlist([], 'f')
2757 call assert_equal({}, g:Xgetlist({'id':0})) 2757 call assert_equal(0, g:Xgetlist({'id':0}).id)
2758 Xexpr '' 2758 Xexpr ''
2759 let start_id = g:Xgetlist({'id' : 0}).id 2759 let start_id = g:Xgetlist({'id' : 0}).id
2760 Xexpr '' | Xexpr '' 2760 Xexpr '' | Xexpr ''
2761 Xolder 2761 Xolder
2762 call assert_equal(start_id, g:Xgetlist({'id':0, 'nr':1}).id) 2762 call assert_equal(start_id, g:Xgetlist({'id':0, 'nr':1}).id)
2763 call assert_equal(start_id + 1, g:Xgetlist({'id':0, 'nr':0}).id) 2763 call assert_equal(start_id + 1, g:Xgetlist({'id':0, 'nr':0}).id)
2764 call assert_equal(start_id + 2, g:Xgetlist({'id':0, 'nr':'$'}).id) 2764 call assert_equal(start_id + 2, g:Xgetlist({'id':0, 'nr':'$'}).id)
2765 call assert_equal({}, g:Xgetlist({'id':0, 'nr':99})) 2765 call assert_equal(0, g:Xgetlist({'id':0, 'nr':99}).id)
2766 call assert_equal(2, g:Xgetlist({'id':start_id + 1, 'nr':0}).nr) 2766 call assert_equal(2, g:Xgetlist({'id':start_id + 1, 'nr':0}).nr)
2767 call assert_equal({}, g:Xgetlist({'id':99, 'nr':0})) 2767 call assert_equal(0, g:Xgetlist({'id':99, 'nr':0}).id)
2768 call assert_equal({}, g:Xgetlist({'id':"abc", 'nr':0})) 2768 call assert_equal(0, g:Xgetlist({'id':"abc", 'nr':0}).id)
2769 2769
2770 call g:Xsetlist([], 'a', {'id':start_id, 'context':[1,2]}) 2770 call g:Xsetlist([], 'a', {'id':start_id, 'context':[1,2]})
2771 call assert_equal([1,2], g:Xgetlist({'nr':1, 'context':1}).context) 2771 call assert_equal([1,2], g:Xgetlist({'nr':1, 'context':1}).context)
2772 call g:Xsetlist([], 'a', {'id':start_id+1, 'lines':['F1:10:L10']}) 2772 call g:Xsetlist([], 'a', {'id':start_id+1, 'lines':['F1:10:L10']})
2773 call assert_equal('L10', g:Xgetlist({'nr':2, 'items':1}).items[0].text) 2773 call assert_equal('L10', g:Xgetlist({'nr':2, 'items':1}).items[0].text)
2774 call assert_equal(-1, g:Xsetlist([], 'a', {'id':999, 'title':'Vim'})) 2774 call assert_equal(-1, g:Xsetlist([], 'a', {'id':999, 'title':'Vim'}))
2775 call assert_equal(-1, g:Xsetlist([], 'a', {'id':'abc', 'title':'Vim'})) 2775 call assert_equal(-1, g:Xsetlist([], 'a', {'id':'abc', 'title':'Vim'}))
2776 2776
2777 let qfid = g:Xgetlist({'id':0, 'nr':0}) 2777 let qfid = g:Xgetlist({'id':0, 'nr':0})
2778 call g:Xsetlist([], 'f') 2778 call g:Xsetlist([], 'f')
2779 call assert_equal({}, g:Xgetlist({'id':qfid, 'nr':0})) 2779 call assert_equal(0, g:Xgetlist({'id':qfid, 'nr':0}).id)
2780 endfunc 2780 endfunc
2781 2781
2782 func Test_qf_id() 2782 func Test_qf_id()
2783 call Xqfid_tests('c') 2783 call Xqfid_tests('c')
2784 call Xqfid_tests('l') 2784 call Xqfid_tests('l')
2878 2878
2879 func Test_qfjump() 2879 func Test_qfjump()
2880 call Xqfjump_tests('c') 2880 call Xqfjump_tests('c')
2881 call Xqfjump_tests('l') 2881 call Xqfjump_tests('l')
2882 endfunc 2882 endfunc
2883
2884 " Tests for the getqflist() and getloclist() functions when the list is not
2885 " present or is empty
2886 func Xgetlist_empty_tests(cchar)
2887 call s:setup_commands(a:cchar)
2888
2889 " Empty quickfix stack
2890 call g:Xsetlist([], 'f')
2891 call assert_equal('', g:Xgetlist({'context' : 0}).context)
2892 call assert_equal(0, g:Xgetlist({'id' : 0}).id)
2893 call assert_equal(0, g:Xgetlist({'idx' : 0}).idx)
2894 call assert_equal([], g:Xgetlist({'items' : 0}).items)
2895 call assert_equal(0, g:Xgetlist({'nr' : 0}).nr)
2896 call assert_equal(0, g:Xgetlist({'size' : 0}).size)
2897 call assert_equal('', g:Xgetlist({'title' : 0}).title)
2898 call assert_equal(0, g:Xgetlist({'winid' : 0}).winid)
2899 call assert_equal({'context' : '', 'id' : 0, 'idx' : 0, 'items' : [], 'nr' : 0, 'size' : 0, 'title' : '', 'winid' : 0}, g:Xgetlist({'all' : 0}))
2900
2901 " Empty quickfix list
2902 Xexpr ""
2903 call assert_equal('', g:Xgetlist({'context' : 0}).context)
2904 call assert_notequal(0, g:Xgetlist({'id' : 0}).id)
2905 call assert_equal(0, g:Xgetlist({'idx' : 0}).idx)
2906 call assert_equal([], g:Xgetlist({'items' : 0}).items)
2907 call assert_notequal(0, g:Xgetlist({'nr' : 0}).nr)
2908 call assert_equal(0, g:Xgetlist({'size' : 0}).size)
2909 call assert_notequal('', g:Xgetlist({'title' : 0}).title)
2910 call assert_equal(0, g:Xgetlist({'winid' : 0}).winid)
2911
2912 let qfid = g:Xgetlist({'id' : 0}).id
2913 call g:Xsetlist([], 'f')
2914
2915 " Non-existing quickfix identifier
2916 call assert_equal('', g:Xgetlist({'id' : qfid, 'context' : 0}).context)
2917 call assert_equal(0, g:Xgetlist({'id' : qfid}).id)
2918 call assert_equal(0, g:Xgetlist({'id' : qfid, 'idx' : 0}).idx)
2919 call assert_equal([], g:Xgetlist({'id' : qfid, 'items' : 0}).items)
2920 call assert_equal(0, g:Xgetlist({'id' : qfid, 'nr' : 0}).nr)
2921 call assert_equal(0, g:Xgetlist({'id' : qfid, 'size' : 0}).size)
2922 call assert_equal('', g:Xgetlist({'id' : qfid, 'title' : 0}).title)
2923 call assert_equal(0, g:Xgetlist({'id' : qfid, 'winid' : 0}).winid)
2924 call assert_equal({'context' : '', 'id' : 0, 'idx' : 0, 'items' : [], 'nr' : 0, 'size' : 0, 'title' : '', 'winid' : 0}, g:Xgetlist({'id' : qfid, 'all' : 0}))
2925
2926 " Non-existing quickfix list number
2927 call assert_equal('', g:Xgetlist({'nr' : 5, 'context' : 0}).context)
2928 call assert_equal(0, g:Xgetlist({'nr' : 5}).nr)
2929 call assert_equal(0, g:Xgetlist({'nr' : 5, 'idx' : 0}).idx)
2930 call assert_equal([], g:Xgetlist({'nr' : 5, 'items' : 0}).items)
2931 call assert_equal(0, g:Xgetlist({'nr' : 5, 'id' : 0}).id)
2932 call assert_equal(0, g:Xgetlist({'nr' : 5, 'size' : 0}).size)
2933 call assert_equal('', g:Xgetlist({'nr' : 5, 'title' : 0}).title)
2934 call assert_equal(0, g:Xgetlist({'nr' : 5, 'winid' : 0}).winid)
2935 call assert_equal({'context' : '', 'id' : 0, 'idx' : 0, 'items' : [], 'nr' : 0, 'size' : 0, 'title' : '', 'winid' : 0}, g:Xgetlist({'nr' : 5, 'all' : 0}))
2936 endfunc
2937
2938 func Test_getqflist()
2939 call Xgetlist_empty_tests('c')
2940 call Xgetlist_empty_tests('l')
2941 endfunc