/
test_quickfix.vim
6391 lines (5602 loc) · 182 KB
/
test_quickfix.vim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
" Test for the quickfix feature.
source check.vim
import './vim9.vim' as v9
CheckFeature quickfix
source screendump.vim
set encoding=utf-8
func s:setup_commands(cchar)
if a:cchar == 'c'
command! -nargs=* -bang Xlist <mods>clist<bang> <args>
command! -nargs=* Xgetexpr <mods>cgetexpr <args>
command! -nargs=* Xaddexpr <mods>caddexpr <args>
command! -nargs=* -count Xolder <mods><count>colder <args>
command! -nargs=* Xnewer <mods>cnewer <args>
command! -nargs=* Xopen <mods> copen <args>
command! -nargs=* Xwindow <mods>cwindow <args>
command! -nargs=* Xbottom <mods>cbottom <args>
command! -nargs=* Xclose <mods>cclose <args>
command! -nargs=* -bang Xfile <mods>cfile<bang> <args>
command! -nargs=* Xgetfile <mods>cgetfile <args>
command! -nargs=* Xaddfile <mods>caddfile <args>
command! -nargs=* -bang Xbuffer <mods>cbuffer<bang> <args>
command! -nargs=* Xgetbuffer <mods>cgetbuffer <args>
command! -nargs=* Xaddbuffer <mods>caddbuffer <args>
command! -nargs=* Xrewind <mods>crewind <args>
command! -count -nargs=* -bang Xnext <mods><count>cnext<bang> <args>
command! -count -nargs=* -bang Xprev <mods><count>cprev<bang> <args>
command! -nargs=* -bang Xfirst <mods>cfirst<bang> <args>
command! -nargs=* -bang Xlast <mods>clast<bang> <args>
command! -count -nargs=* -bang Xnfile <mods><count>cnfile<bang> <args>
command! -nargs=* -bang Xpfile <mods>cpfile<bang> <args>
command! -nargs=* Xexpr <mods>cexpr <args>
command! -count=999 -nargs=* Xvimgrep <mods> <count>vimgrep <args>
command! -nargs=* Xvimgrepadd <mods> vimgrepadd <args>
command! -nargs=* Xgrep <mods> grep <args>
command! -nargs=* Xgrepadd <mods> grepadd <args>
command! -nargs=* Xhelpgrep helpgrep <args>
command! -nargs=0 -count Xcc <count>cc
command! -count=1 -nargs=0 Xbelow <mods><count>cbelow
command! -count=1 -nargs=0 Xabove <mods><count>cabove
command! -count=1 -nargs=0 Xbefore <mods><count>cbefore
command! -count=1 -nargs=0 Xafter <mods><count>cafter
let g:Xgetlist = function('getqflist')
let g:Xsetlist = function('setqflist')
call setqflist([], 'f')
else
command! -nargs=* -bang Xlist <mods>llist<bang> <args>
command! -nargs=* Xgetexpr <mods>lgetexpr <args>
command! -nargs=* Xaddexpr <mods>laddexpr <args>
command! -nargs=* -count Xolder <mods><count>lolder <args>
command! -nargs=* Xnewer <mods>lnewer <args>
command! -nargs=* Xopen <mods> lopen <args>
command! -nargs=* Xwindow <mods>lwindow <args>
command! -nargs=* Xbottom <mods>lbottom <args>
command! -nargs=* Xclose <mods>lclose <args>
command! -nargs=* -bang Xfile <mods>lfile<bang> <args>
command! -nargs=* Xgetfile <mods>lgetfile <args>
command! -nargs=* Xaddfile <mods>laddfile <args>
command! -nargs=* -bang Xbuffer <mods>lbuffer<bang> <args>
command! -nargs=* Xgetbuffer <mods>lgetbuffer <args>
command! -nargs=* Xaddbuffer <mods>laddbuffer <args>
command! -nargs=* Xrewind <mods>lrewind <args>
command! -count -nargs=* -bang Xnext <mods><count>lnext<bang> <args>
command! -count -nargs=* -bang Xprev <mods><count>lprev<bang> <args>
command! -nargs=* -bang Xfirst <mods>lfirst<bang> <args>
command! -nargs=* -bang Xlast <mods>llast<bang> <args>
command! -count -nargs=* -bang Xnfile <mods><count>lnfile<bang> <args>
command! -nargs=* -bang Xpfile <mods>lpfile<bang> <args>
command! -nargs=* Xexpr <mods>lexpr <args>
command! -count=999 -nargs=* Xvimgrep <mods> <count>lvimgrep <args>
command! -nargs=* Xvimgrepadd <mods> lvimgrepadd <args>
command! -nargs=* Xgrep <mods> lgrep <args>
command! -nargs=* Xgrepadd <mods> lgrepadd <args>
command! -nargs=* Xhelpgrep lhelpgrep <args>
command! -nargs=0 -count Xcc <count>ll
command! -count=1 -nargs=0 Xbelow <mods><count>lbelow
command! -count=1 -nargs=0 Xabove <mods><count>labove
command! -count=1 -nargs=0 Xbefore <mods><count>lbefore
command! -count=1 -nargs=0 Xafter <mods><count>lafter
let g:Xgetlist = function('getloclist', [0])
let g:Xsetlist = function('setloclist', [0])
call setloclist(0, [], 'f')
endif
endfunc
" This must be run before any error lists are created.
func Test_AA_cc_no_errors()
call assert_fails('cc', 'E42:')
call assert_fails('ll', 'E42:')
endfunc
" Tests for the :clist and :llist commands
func XlistTests(cchar)
call s:setup_commands(a:cchar)
if a:cchar == 'l'
call assert_fails('llist', 'E776:')
endif
" With an empty list, command should return error
Xgetexpr []
silent! Xlist
call assert_true(v:errmsg ==# 'E42: No Errors')
" Populate the list and then try
let lines =<< trim END
non-error 1
Xtestfile1:1:3:Line1
non-error 2
Xtestfile2:2:2:Line2
non-error| 3
Xtestfile3:3:1:Line3
END
Xgetexpr lines
" List only valid entries
let l = split(execute('Xlist', ''), "\n")
call assert_equal([' 2 Xtestfile1:1 col 3: Line1',
\ ' 4 Xtestfile2:2 col 2: Line2',
\ ' 6 Xtestfile3:3 col 1: Line3'], l)
" List all the entries
let l = split(execute('Xlist!', ''), "\n")
call assert_equal([' 1: non-error 1', ' 2 Xtestfile1:1 col 3: Line1',
\ ' 3: non-error 2', ' 4 Xtestfile2:2 col 2: Line2',
\ ' 5: non-error| 3', ' 6 Xtestfile3:3 col 1: Line3'], l)
" List a range of errors
let l = split(execute('Xlist 3,6', ''), "\n")
call assert_equal([' 4 Xtestfile2:2 col 2: Line2',
\ ' 6 Xtestfile3:3 col 1: Line3'], l)
let l = split(execute('Xlist! 3,4', ''), "\n")
call assert_equal([' 3: non-error 2', ' 4 Xtestfile2:2 col 2: Line2'], l)
let l = split(execute('Xlist -6,-4', ''), "\n")
call assert_equal([' 2 Xtestfile1:1 col 3: Line1'], l)
let l = split(execute('Xlist! -5,-3', ''), "\n")
call assert_equal([' 2 Xtestfile1:1 col 3: Line1',
\ ' 3: non-error 2', ' 4 Xtestfile2:2 col 2: Line2'], l)
" Test for '+'
let l = split(execute('Xlist! +2', ''), "\n")
call assert_equal([' 2 Xtestfile1:1 col 3: Line1',
\ ' 3: non-error 2', ' 4 Xtestfile2:2 col 2: Line2'], l)
" Ranged entries
call g:Xsetlist([{'lnum':10,'text':'Line1'},
\ {'lnum':20,'col':10,'text':'Line2'},
\ {'lnum':30,'col':15,'end_col':20,'text':'Line3'},
\ {'lnum':40,'end_lnum':45,'text':'Line4'},
\ {'lnum':50,'end_lnum':55,'col':15,'text':'Line5'},
\ {'lnum':60,'end_lnum':65,'col':25,'end_col':35,'text':'Line6'}])
let l = split(execute('Xlist', ""), "\n")
call assert_equal([' 1:10: Line1',
\ ' 2:20 col 10: Line2',
\ ' 3:30 col 15-20: Line3',
\ ' 4:40-45: Line4',
\ ' 5:50-55 col 15: Line5',
\ ' 6:60-65 col 25-35: Line6'], l)
" Different types of errors
call g:Xsetlist([{'lnum':10,'col':5,'type':'W', 'text':'Warning','nr':11},
\ {'lnum':20,'col':10,'type':'e','text':'Error','nr':22},
\ {'lnum':30,'col':15,'type':'i','text':'Info','nr':33},
\ {'lnum':40,'col':20,'type':'x', 'text':'Other','nr':44},
\ {'lnum':50,'col':25,'type':"\<C-A>",'text':'one','nr':55}])
let l = split(execute('Xlist', ""), "\n")
call assert_equal([' 1:10 col 5 warning 11: Warning',
\ ' 2:20 col 10 error 22: Error',
\ ' 3:30 col 15 info 33: Info',
\ ' 4:40 col 20 x 44: Other',
\ ' 5:50 col 25 55: one'], l)
" Test for module names, one needs to explicitly set `'valid':v:true` so
call g:Xsetlist([
\ {'lnum':10,'col':5,'type':'W','module':'Data.Text','text':'ModuleWarning','nr':11,'valid':v:true},
\ {'lnum':20,'col':10,'type':'W','module':'Data.Text','filename':'Data/Text.hs','text':'ModuleWarning','nr':22,'valid':v:true},
\ {'lnum':30,'col':15,'type':'W','filename':'Data/Text.hs','text':'FileWarning','nr':33,'valid':v:true}])
let l = split(execute('Xlist', ""), "\n")
call assert_equal([' 1 Data.Text:10 col 5 warning 11: ModuleWarning',
\ ' 2 Data.Text:20 col 10 warning 22: ModuleWarning',
\ ' 3 Data/Text.hs:30 col 15 warning 33: FileWarning'], l)
" Very long line should be displayed.
let text = 'Line' .. repeat('1234567890', 130)
let lines = ['Xtestfile9:2:9:' .. text]
Xgetexpr lines
let l = split(execute('Xlist', ''), "\n")
call assert_equal([' 1 Xtestfile9:2 col 9: ' .. text] , l)
" For help entries in the quickfix list, only the filename without directory
" should be displayed
Xhelpgrep setqflist()
let l = split(execute('Xlist 1', ''), "\n")
call assert_match('^ 1 [^\\/]\{-}:', l[0])
" Error cases
call assert_fails('Xlist abc', 'E488:')
endfunc
func Test_clist()
call XlistTests('c')
call XlistTests('l')
endfunc
" Tests for the :colder, :cnewer, :lolder and :lnewer commands
" Note that this test assumes that a quickfix/location list is
" already set by the caller.
func XageTests(cchar)
call s:setup_commands(a:cchar)
if a:cchar == 'l'
" No location list for the current window
call assert_fails('lolder', 'E776:')
call assert_fails('lnewer', 'E776:')
endif
let list = [{'bufnr': bufnr('%'), 'lnum': 1}]
call g:Xsetlist(list)
" Jumping to a non existent list should return error
silent! Xolder 99
call assert_true(v:errmsg ==# 'E380: At bottom of quickfix stack')
silent! Xnewer 99
call assert_true(v:errmsg ==# 'E381: At top of quickfix stack')
" Add three quickfix/location lists
Xgetexpr ['Xtestfile1:1:3:Line1']
Xgetexpr ['Xtestfile2:2:2:Line2']
Xgetexpr ['Xtestfile3:3:1:Line3']
" Go back two lists
Xolder
let l = g:Xgetlist()
call assert_equal('Line2', l[0].text)
" Go forward two lists
Xnewer
let l = g:Xgetlist()
call assert_equal('Line3', l[0].text)
" Test for the optional count argument
Xolder 2
let l = g:Xgetlist()
call assert_equal('Line1', l[0].text)
Xnewer 2
let l = g:Xgetlist()
call assert_equal('Line3', l[0].text)
endfunc
func Test_cage()
call XageTests('c')
call XageTests('l')
endfunc
" Tests for the :cwindow, :lwindow :cclose, :lclose, :copen and :lopen
" commands
func XwindowTests(cchar)
call s:setup_commands(a:cchar)
" Opening the location list window without any errors should fail
if a:cchar == 'l'
call assert_fails('lopen', 'E776:')
call assert_fails('lwindow', 'E776:')
endif
" Create a list with no valid entries
Xgetexpr ['non-error 1', 'non-error 2', 'non-error 3']
" Quickfix/Location window should not open with no valid errors
Xwindow
call assert_true(winnr('$') == 1)
" Create a list with valid entries
let lines =<< trim END
Xtestfile1:1:3:Line1
Xtestfile2:2:2:Line2
Xtestfile3:3:1:Line3
END
Xgetexpr lines
" Open the window
Xwindow
call assert_true(winnr('$') == 2 && winnr() == 2 &&
\ getline('.') ==# 'Xtestfile1|1 col 3| Line1')
redraw!
" Close the window
Xclose
call assert_true(winnr('$') == 1)
" Create a list with no valid entries
Xgetexpr ['non-error 1', 'non-error 2', 'non-error 3']
" Open the window
Xopen 5
call assert_true(winnr('$') == 2 && getline('.') ==# '|| non-error 1'
\ && winheight(0) == 5)
" Opening the window again, should move the cursor to that window
wincmd t
Xopen 7
call assert_true(winnr('$') == 2 && winnr() == 2 &&
\ winheight(0) == 7 &&
\ getline('.') ==# '|| non-error 1')
" :cnext in quickfix window should move to the next entry
Xnext
call assert_equal(2, g:Xgetlist({'idx' : 0}).idx)
" Calling cwindow should close the quickfix window with no valid errors
Xwindow
call assert_true(winnr('$') == 1)
" Specifying the width should adjust the width for a vertically split
" quickfix window.
vert Xopen
call assert_equal(10, winwidth(0))
vert Xopen 12
call assert_equal(12, winwidth(0))
Xclose
" Horizontally or vertically splitting the quickfix window should create a
" normal window/buffer
Xopen
wincmd s
call assert_equal(0, getwininfo(win_getid())[0].quickfix)
call assert_equal(0, getwininfo(win_getid())[0].loclist)
call assert_notequal('quickfix', &buftype)
close
Xopen
wincmd v
call assert_equal(0, getwininfo(win_getid())[0].quickfix)
call assert_equal(0, getwininfo(win_getid())[0].loclist)
call assert_notequal('quickfix', &buftype)
close
Xopen
Xclose
if a:cchar == 'c'
" Opening the quickfix window in multiple tab pages should reuse the
" quickfix buffer
let lines =<< trim END
Xtestfile1:1:3:Line1
Xtestfile2:2:2:Line2
Xtestfile3:3:1:Line3
END
Xgetexpr lines
Xopen
let qfbufnum = bufnr('%')
tabnew
Xopen
call assert_equal(qfbufnum, bufnr('%'))
new | only | tabonly
endif
endfunc
func Test_cwindow()
call XwindowTests('c')
call XwindowTests('l')
endfunc
func Test_copenHeight()
copen
wincmd H
let height = winheight(0)
copen 10
call assert_equal(height, winheight(0))
quit
endfunc
func Test_copenHeight_tabline()
set tabline=foo showtabline=2
copen
wincmd H
let height = winheight(0)
copen 10
call assert_equal(height, winheight(0))
quit
set tabline& showtabline&
endfunc
" Tests for the :cfile, :lfile, :caddfile, :laddfile, :cgetfile and :lgetfile
" commands.
func XfileTests(cchar)
call s:setup_commands(a:cchar)
let lines =<< trim END
Xtestfile1:700:10:Line 700
Xtestfile2:800:15:Line 800
END
call writefile(lines, 'Xqftestfile1', 'D')
enew!
Xfile Xqftestfile1
let l = g:Xgetlist()
call assert_true(len(l) == 2 &&
\ l[0].lnum == 700 && l[0].col == 10 && l[0].text ==# 'Line 700' &&
\ l[1].lnum == 800 && l[1].col == 15 && l[1].text ==# 'Line 800')
" Test with a non existent file
call assert_fails('Xfile non_existent_file', 'E40:')
" Run cfile/lfile from a modified buffer
enew!
silent! put ='Quickfix'
silent! Xfile Xqftestfile1
call assert_true(v:errmsg ==# 'E37: No write since last change (add ! to override)')
call writefile(['Xtestfile3:900:30:Line 900'], 'Xqftestfile1')
Xaddfile Xqftestfile1
let l = g:Xgetlist()
call assert_true(len(l) == 3 &&
\ l[2].lnum == 900 && l[2].col == 30 && l[2].text ==# 'Line 900')
let lines =<< trim END
Xtestfile1:222:77:Line 222
Xtestfile2:333:88:Line 333
END
call writefile(lines, 'Xqftestfile1')
enew!
Xgetfile Xqftestfile1
let l = g:Xgetlist()
call assert_true(len(l) == 2 &&
\ l[0].lnum == 222 && l[0].col == 77 && l[0].text ==# 'Line 222' &&
\ l[1].lnum == 333 && l[1].col == 88 && l[1].text ==# 'Line 333')
" Test for a file with a long line and without a newline at the end
let text = repeat('x', 1024)
let t = 'a.txt:18:' . text
call writefile([t], 'Xqftestfile1', 'b')
silent! Xfile Xqftestfile1
call assert_equal(text, g:Xgetlist()[0].text)
endfunc
func Test_cfile()
call XfileTests('c')
call XfileTests('l')
endfunc
" Tests for the :cbuffer, :lbuffer, :caddbuffer, :laddbuffer, :cgetbuffer and
" :lgetbuffer commands.
func XbufferTests(cchar)
call s:setup_commands(a:cchar)
enew!
let lines =<< trim END
Xtestfile7:700:10:Line 700
Xtestfile8:800:15:Line 800
END
silent! call setline(1, lines)
Xbuffer!
let l = g:Xgetlist()
call assert_true(len(l) == 2 &&
\ l[0].lnum == 700 && l[0].col == 10 && l[0].text ==# 'Line 700' &&
\ l[1].lnum == 800 && l[1].col == 15 && l[1].text ==# 'Line 800')
enew!
let lines =<< trim END
Xtestfile9:900:55:Line 900
Xtestfile10:950:66:Line 950
END
silent! call setline(1, lines)
Xgetbuffer
let l = g:Xgetlist()
call assert_true(len(l) == 2 &&
\ l[0].lnum == 900 && l[0].col == 55 && l[0].text ==# 'Line 900' &&
\ l[1].lnum == 950 && l[1].col == 66 && l[1].text ==# 'Line 950')
enew!
let lines =<< trim END
Xtestfile11:700:20:Line 700
Xtestfile12:750:25:Line 750
END
silent! call setline(1, lines)
Xaddbuffer
let l = g:Xgetlist()
call assert_true(len(l) == 4 &&
\ l[1].lnum == 950 && l[1].col == 66 && l[1].text ==# 'Line 950' &&
\ l[2].lnum == 700 && l[2].col == 20 && l[2].text ==# 'Line 700' &&
\ l[3].lnum == 750 && l[3].col == 25 && l[3].text ==# 'Line 750')
enew!
" Check for invalid buffer
call assert_fails('Xbuffer 199', 'E474:')
" Check for unloaded buffer
edit Xtestfile1
let bnr = bufnr('%')
enew!
call assert_fails('Xbuffer ' . bnr, 'E681:')
" Check for invalid range
" Using Xbuffer will not run the range check in the cbuffer/lbuffer
" commands. So directly call the commands.
if (a:cchar == 'c')
call assert_fails('900,999cbuffer', 'E16:')
else
call assert_fails('900,999lbuffer', 'E16:')
endif
endfunc
func Test_cbuffer()
call XbufferTests('c')
call XbufferTests('l')
endfunc
func XexprTests(cchar)
call s:setup_commands(a:cchar)
call assert_fails('Xexpr 10', 'E777:')
endfunc
func Test_cexpr()
call XexprTests('c')
call XexprTests('l')
endfunc
" Tests for :cnext, :cprev, :cfirst, :clast commands
func Xtest_browse(cchar)
call s:setup_commands(a:cchar)
call g:Xsetlist([], 'f')
" Jumping to first or next location list entry without any error should
" result in failure
if a:cchar == 'c'
let err = 'E42:'
let cmd = '$cc'
else
let err = 'E776:'
let cmd = '$ll'
endif
call assert_fails('Xnext', err)
call assert_fails('Xprev', err)
call assert_fails('Xnfile', err)
call assert_fails('Xpfile', err)
call assert_fails(cmd, err)
Xexpr ''
call assert_fails(cmd, 'E42:')
call s:create_test_file('Xqftestfile1')
call s:create_test_file('Xqftestfile2')
let lines =<< trim END
Xqftestfile1:5:Line5
Xqftestfile1:6:Line6
Xqftestfile2:10:Line10
Xqftestfile2:11:Line11
RegularLine1
RegularLine2
END
Xgetexpr lines
Xfirst
call assert_fails('-5Xcc', 'E16:')
call assert_fails('Xprev', 'E553:')
call assert_fails('Xpfile', 'E553:')
Xnfile
call assert_equal('Xqftestfile2', @%)
call assert_equal(10, line('.'))
Xpfile
call assert_equal('Xqftestfile1', @%)
call assert_equal(6, line('.'))
5Xcc
call assert_equal(5, g:Xgetlist({'idx':0}).idx)
2Xcc
call assert_equal(2, g:Xgetlist({'idx':0}).idx)
if a:cchar == 'c'
cc
else
ll
endif
call assert_equal(2, g:Xgetlist({'idx':0}).idx)
10Xcc
call assert_equal(6, g:Xgetlist({'idx':0}).idx)
Xlast
Xprev
call assert_equal('Xqftestfile2', @%)
call assert_equal(11, line('.'))
call assert_fails('Xnext', 'E553:')
call assert_fails('Xnfile', 'E553:')
" To process the range using quickfix list entries, directly use the
" quickfix commands (don't use the user defined commands)
if a:cchar == 'c'
$cc
else
$ll
endif
call assert_equal(6, g:Xgetlist({'idx':0}).idx)
Xrewind
call assert_equal('Xqftestfile1', @%)
call assert_equal(5, line('.'))
10Xnext
call assert_equal('Xqftestfile2', @%)
call assert_equal(11, line('.'))
10Xprev
call assert_equal('Xqftestfile1', @%)
call assert_equal(5, line('.'))
" Jumping to an error from the error window using cc command
let lines =<< trim END
Xqftestfile1:5:Line5
Xqftestfile1:6:Line6
Xqftestfile2:10:Line10
Xqftestfile2:11:Line11
END
Xgetexpr lines
Xopen
10Xcc
call assert_equal(11, line('.'))
call assert_equal('Xqftestfile2', @%)
Xopen
call cursor(2, 1)
if a:cchar == 'c'
.cc
else
.ll
endif
call assert_equal(6, line('.'))
call assert_equal('Xqftestfile1', @%)
" Jumping to an error from the error window (when only the error window is
" present)
Xopen | only
Xlast 1
call assert_equal(5, line('.'))
call assert_equal('Xqftestfile1', @%)
Xexpr ""
call assert_fails('Xnext', 'E42:')
call delete('Xqftestfile1')
call delete('Xqftestfile2')
" Should be able to use next/prev with invalid entries
Xexpr ""
call assert_equal(0, g:Xgetlist({'idx' : 0}).idx)
call assert_equal(0, g:Xgetlist({'size' : 0}).size)
Xaddexpr ['foo', 'bar', 'baz', 'quux', 'sh|moo']
call assert_equal(5, g:Xgetlist({'size' : 0}).size)
Xlast
call assert_equal(5, g:Xgetlist({'idx' : 0}).idx)
Xfirst
call assert_equal(1, g:Xgetlist({'idx' : 0}).idx)
2Xnext
call assert_equal(3, g:Xgetlist({'idx' : 0}).idx)
endfunc
func Test_browse()
call Xtest_browse('c')
call Xtest_browse('l')
endfunc
" Test for memory allocation failures
func Xnomem_tests(cchar)
call s:setup_commands(a:cchar)
call test_alloc_fail(GetAllocId('qf_dirname_start'), 0, 0)
call assert_fails('Xvimgrep vim runtest.vim', 'E342:')
call test_alloc_fail(GetAllocId('qf_dirname_now'), 0, 0)
call assert_fails('Xvimgrep vim runtest.vim', 'E342:')
call test_alloc_fail(GetAllocId('qf_namebuf'), 0, 0)
call assert_fails('Xfile runtest.vim', 'E342:')
call test_alloc_fail(GetAllocId('qf_errmsg'), 0, 0)
call assert_fails('Xfile runtest.vim', 'E342:')
call test_alloc_fail(GetAllocId('qf_pattern'), 0, 0)
call assert_fails('Xfile runtest.vim', 'E342:')
call test_alloc_fail(GetAllocId('qf_efm_fmtstr'), 0, 0)
set efm=%f
call assert_fails('Xexpr ["Xfile1"]', 'E342:')
set efm&
call test_alloc_fail(GetAllocId('qf_efm_fmtpart'), 0, 0)
set efm=%f:%l:%m,%f-%l-%m
call assert_fails('Xaddexpr ["Xfile2", "Xfile3"]', 'E342:')
set efm&
call test_alloc_fail(GetAllocId('qf_title'), 0, 0)
call assert_fails('Xexpr ""', 'E342:')
call assert_equal('', g:Xgetlist({'all': 1}).title)
call test_alloc_fail(GetAllocId('qf_mef_name'), 0, 0)
set makeef=Xtmp##.err
call assert_fails('Xgrep needle haystack', 'E342:')
set makeef&
call test_alloc_fail(GetAllocId('qf_qfline'), 0, 0)
call assert_fails('Xexpr "Xfile1:10:Line10"', 'E342:')
if a:cchar == 'l'
for id in ['qf_qfline', 'qf_qfinfo']
lgetexpr ["Xfile1:10:L10", "Xfile2:20:L20"]
call test_alloc_fail(GetAllocId(id), 0, 0)
call assert_fails('new', 'E342:')
call assert_equal(2, winnr('$'))
call assert_equal([], getloclist(0))
%bw!
endfor
endif
call test_alloc_fail(GetAllocId('qf_qfline'), 0, 0)
try
call assert_fails('Xvimgrep vim runtest.vim', 'E342:')
catch /^Vim:Interrupt$/
endtry
call test_alloc_fail(GetAllocId('qf_qfline'), 0, 0)
try
call assert_fails('Xvimgrep /vim/f runtest.vim', 'E342:')
catch /^Vim:Interrupt$/
endtry
let l = getqflist({"lines": ["Xfile1:10:L10"]})
call test_alloc_fail(GetAllocId('qf_qfline'), 0, 0)
call assert_fails('call g:Xsetlist(l.items)', 'E342:')
call test_alloc_fail(GetAllocId('qf_qfline'), 0, 0)
try
call assert_fails('Xhelpgrep quickfix', 'E342:')
catch /^Vim:Interrupt$/
endtry
call test_alloc_fail(GetAllocId('qf_qfinfo'), 0, 0)
call assert_fails('let l = g:Xgetlist({"lines": ["Xfile1:10:L10"]})', 'E342:')
call assert_equal(#{items: []}, l)
if a:cchar == 'l'
call setqflist([], 'f')
call setloclist(0, [], 'f')
call test_alloc_fail(GetAllocId('qf_qfinfo'), 0, 0)
call assert_fails('lhelpgrep quickfix', 'E342:')
call assert_equal([], getloclist(0))
call test_alloc_fail(GetAllocId('qf_qfinfo'), 0, 0)
call assert_fails('lvimgrep vim runtest.vim', 'E342:')
let l = getqflist({"lines": ["Xfile1:10:L10"]})
call test_alloc_fail(GetAllocId('qf_qfinfo'), 0, 0)
call assert_fails('call setloclist(0, l.items)', 'E342:')
call test_alloc_fail(GetAllocId('qf_qfinfo'), 0, 0)
call assert_fails('lbuffer', 'E342:')
call test_alloc_fail(GetAllocId('qf_qfinfo'), 0, 0)
call assert_fails('lexpr ["Xfile1:10:L10", "Xfile2:20:L20"]', 'E342:')
call test_alloc_fail(GetAllocId('qf_qfinfo'), 0, 0)
call assert_fails('lfile runtest.vim', 'E342:')
endif
call test_alloc_fail(GetAllocId('qf_dirstack'), 0, 0)
set efm=%DEntering\ dir\ %f,%f:%l:%m
call assert_fails('Xexpr ["Entering dir abc", "abc.txt:1:Hello world"]', 'E342:')
set efm&
call test_alloc_fail(GetAllocId('qf_dirstack'), 0, 0)
set efm=%+P[%f],(%l)%m
call assert_fails('Xexpr ["[runtest.vim]", "(1)Hello"]', 'E342:')
set efm&
call test_alloc_fail(GetAllocId('qf_multiline_pfx'), 0, 0)
set efm=%EError,%Cline\ %l,%Z%m
call assert_fails('Xexpr ["Error", "line 1", "msg"]', 'E342:')
set efm&
call test_alloc_fail(GetAllocId('qf_makecmd'), 0, 0)
call assert_fails('Xgrep vim runtest.vim', 'E342:')
call test_alloc_fail(GetAllocId('qf_linebuf'), 0, 0)
call assert_fails('Xexpr repeat("a", 8192)', 'E342:')
call test_alloc_fail(GetAllocId('qf_linebuf'), 0, 0)
call assert_fails('Xexpr [repeat("a", 8192)]', 'E342:')
new
call setline(1, repeat('a', 8192))
call test_alloc_fail(GetAllocId('qf_linebuf'), 0, 0)
call assert_fails('Xbuffer', 'E342:')
%bw!
call writefile([repeat('a', 8192)], 'Xtest', 'D')
call test_alloc_fail(GetAllocId('qf_linebuf'), 0, 0)
call assert_fails('Xfile Xtest', 'E342:')
endfunc
func Test_nomem()
call Xnomem_tests('c')
call Xnomem_tests('l')
endfunc
func s:test_xhelpgrep(cchar)
call s:setup_commands(a:cchar)
Xhelpgrep quickfix
Xopen
if a:cchar == 'c'
let title_text = ':helpgrep quickfix'
else
let title_text = ':lhelpgrep quickfix'
endif
call assert_true(w:quickfix_title =~ title_text, w:quickfix_title)
" Jumping to a help topic should open the help window
only
Xnext
call assert_true(&buftype == 'help')
call assert_true(winnr('$') == 2)
" Jumping to the next match should reuse the help window
Xnext
call assert_true(&buftype == 'help')
call assert_true(winnr() == 1)
call assert_true(winnr('$') == 2)
" Jumping to the next match from the quickfix window should reuse the help
" window
Xopen
Xnext
call assert_true(&buftype == 'help')
call assert_true(winnr() == 1)
call assert_true(winnr('$') == 2)
call assert_match('|\d\+ col \d\+-\d\+|', getbufline(winbufnr(2), 1)[0])
" This wipes out the buffer, make sure that doesn't cause trouble.
Xclose
" When the current window is vertically split, jumping to a help match
" should open the help window at the top.
only | enew
let w1 = win_getid()
vert new
let w2 = win_getid()
Xnext
let w3 = win_getid()
call assert_true(&buftype == 'help')
call assert_true(winnr() == 1)
" See jump_to_help_window() for details
let w2_width = winwidth(w2)
if w2_width != &columns && w2_width < 80
call assert_equal(['col', [['leaf', w3],
\ ['row', [['leaf', w2], ['leaf', w1]]]]], winlayout())
else
call assert_equal(['row', [['col', [['leaf', w3], ['leaf', w2]]],
\ ['leaf', w1]]] , winlayout())
endif
new | only
set buftype=help
set modified
call assert_fails('Xnext', 'E37:')
set nomodified
new | only
if a:cchar == 'l'
" When a help window is present, running :lhelpgrep should reuse the
" help window and not the current window
new | only
call g:Xsetlist([], 'f')
help index.txt
wincmd w
lhelpgrep quickfix
call assert_equal(1, winnr())
call assert_notequal([], getloclist(1))
call assert_equal([], getloclist(2))
endif
new | only
" Search for non existing help string
call assert_fails('Xhelpgrep a1b2c3', 'E480:')
" Invalid regular expression
call assert_fails('Xhelpgrep \@<!', 'E866:')
endfunc
func Test_helpgrep()
call s:test_xhelpgrep('c')
helpclose
call s:test_xhelpgrep('l')
endfunc
def Test_helpgrep_vim9_restore_cpo()
assert_equal('aABceFs', &cpo)
var rtp_save = &rtp
var dir = 'Xruntime/after'
&rtp ..= ',' .. dir
mkdir(dir .. '/ftplugin', 'pR')
writefile(['vim9script'], dir .. '/ftplugin/qf.vim')
filetype plugin on
silent helpgrep grail
cwindow
silent helpgrep grail
assert_equal('aABceFs', &cpo)
&rtp = rtp_save
cclose
helpclose
enddef
" When running the :helpgrep command, if an autocmd modifies the 'cpoptions'
" value, then Vim crashes. (issue fixed by 7.2b-004 and 8.2.4453)
func Test_helpgrep_restore_cpo_aucmd()
let save_cpo = &cpo
augroup QF_Test
au!
autocmd BufNew * set cpo=acd
augroup END
helpgrep quickfix
call assert_equal('acd', &cpo)
%bw!
set cpo&vim
augroup QF_Test
au!
autocmd BufReadPost * set cpo=
augroup END
helpgrep buffer
call assert_equal('', &cpo)
augroup QF_Test
au!
augroup END
%bw!
let &cpo = save_cpo
endfunc
def Test_vim9_cexpr()
var text = 'somefile:95:error'
cexpr text
var l = getqflist()
assert_equal(1, l->len())
assert_equal(95, l[0].lnum)
assert_equal('error', l[0].text)
text = 'somefile:77:warning'
caddexpr text
l = getqflist()
assert_equal(2, l->len())
assert_equal(77, l[1].lnum)
assert_equal('warning', l[1].text)
enddef
func Test_errortitle()
augroup QfBufWinEnter
au!
au BufWinEnter * :let g:a=get(w:, 'quickfix_title', 'NONE')
augroup END
copen
let a=[{'lnum': 308, 'bufnr': bufnr(''), 'col': 58, 'valid': 1, 'vcol': 0, 'nr': 0, 'type': '', 'pattern': '', 'text': ' au BufWinEnter * :let g:a=get(w:, ''quickfix_title'', ''NONE'')'}]
call setqflist(a)
call assert_equal(':setqflist()', g:a)
augroup QfBufWinEnter
au!
augroup END
augroup! QfBufWinEnter
endfunc
func Test_vimgreptitle()
augroup QfBufWinEnter
au!
au BufWinEnter * :let g:a=get(w:, 'quickfix_title', 'NONE')
augroup END
try
vimgrep /pattern/j file
catch /E480/
endtry
copen
call assert_equal(': vimgrep /pattern/j file', g:a)
augroup QfBufWinEnter
au!
augroup END
augroup! QfBufWinEnter
endfunc
func Test_bufwinenter_once()
augroup QfBufWinEnter
au!
au BufWinEnter * let g:got_afile ..= 'got ' .. expand('<afile>')
augroup END
let g:got_afile = ''
copen
call assert_equal('got quickfix', g:got_afile)
cclose
unlet g:got_afile
augroup QfBufWinEnter