@@ -366,3 +366,115 @@ function Test_efm()
366366 call assert_equal (" [['W', 1], ['ZZZZ', 0], ['E^@CCCC', 1], ['YYYY', 0]]" , l )
367367 let &efm = save_efm
368368endfunction
369+
370+ " This will test for problems in quickfix:
371+ " A. incorrectly copying location lists which caused the location list to show
372+ " a different name than the file that was actually being displayed.
373+ " B. not reusing the window for which the location list window is opened but
374+ " instead creating new windows.
375+ " C. make sure that the location list window is not reused instead of the
376+ " window it belongs to.
377+ "
378+ " Set up the test environment:
379+ function ! ReadTestProtocol (name)
380+ let base = substitute (a: name , ' \v^test://(.*)%(\.[^.]+)?' , ' \1' , ' ' )
381+ let word = substitute (base, ' \v(.*)\..*' , ' \1' , ' ' )
382+
383+ setl modifiable
384+ setl noreadonly
385+ setl noswapfile
386+ setl bufhidden = delete
387+ % del _
388+ " For problem 2:
389+ " 'buftype' has to be set to reproduce the constant opening of new windows
390+ setl buftype = nofile
391+
392+ call setline (1 , word)
393+
394+ setl nomodified
395+ setl nomodifiable
396+ setl readonly
397+ exe ' doautocmd BufRead ' . substitute (a: name , ' \v^test://(.*)' , ' \1' , ' ' )
398+ endfunction
399+
400+ function Test_locationlist ()
401+ enew
402+
403+ augroup testgroup
404+ au !
405+ autocmd BufReadCmd test://* call ReadTestProtocol (expand (" <amatch>" ))
406+ augroup END
407+
408+ let words = [ " foo" , " bar" , " baz" , " quux" , " shmoo" , " spam" , " eggs" ]
409+
410+ let qflist = []
411+ for word in words
412+ call add (qflist, {' filename' : ' test://' . word . ' .txt' , ' text' : ' file ' . word . ' .txt' , })
413+ " NOTE: problem 1:
414+ " intentionally not setting 'lnum' so that the quickfix entries are not
415+ " valid
416+ call setloclist (0 , qflist, ' ' )
417+ endfor
418+
419+ " Test A
420+ lrewind
421+ enew
422+ lopen
423+ lnext
424+ lnext
425+ lnext
426+ lnext
427+ vert split
428+ wincmd L
429+ lopen
430+ wincmd p
431+ lnext
432+ let fileName = expand (" %" )
433+ wincmd p
434+ let locationListFileName = substitute (getline (line (' .' )), ' \([^|]*\)|.*' , ' \1' , ' ' )
435+ let fileName = substitute (fileName, ' \\' , ' /' , ' g' )
436+ let locationListFileName = substitute (locationListFileName, ' \\' , ' /' , ' g' )
437+ call assert_equal (" test://bar.txt" , fileName)
438+ call assert_equal (" test://bar.txt" , locationListFileName)
439+
440+ wincmd n | only
441+
442+ " Test B:
443+ lrewind
444+ lopen
445+ 2
446+ exe " normal \<CR> "
447+ wincmd p
448+ 3
449+ exe " normal \<CR> "
450+ wincmd p
451+ 4
452+ exe " normal \<CR> "
453+ call assert_equal (2 , winnr (' $' ))
454+ wincmd n | only
455+
456+ " Test C:
457+ lrewind
458+ lopen
459+ " Let's move the location list window to the top to check whether it (the
460+ " first window found) will be reused when we try to open new windows:
461+ wincmd K
462+ 2
463+ exe " normal \<CR> "
464+ wincmd p
465+ 3
466+ exe " normal \<CR> "
467+ wincmd p
468+ 4
469+ exe " normal \<CR> "
470+ 1 wincmd w
471+ call assert_equal (' quickfix' , &buftype )
472+ 2 wincmd w
473+ let bufferName = expand (" %" )
474+ let bufferName = substitute (bufferName, ' \\' , ' /' , ' g' )
475+ call assert_equal (' test://quux.txt' , bufferName)
476+
477+ wincmd n | only
478+
479+ augroup ! testgroup
480+ endfunction
0 commit comments