robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
f907614088
master
1-- Test for problems in quickfix/location list: 2-- A. incorrectly copying location lists which caused the location list to show a 3-- different name than the file that was actually being displayed. 4-- B. not reusing the window for which the location list window is opened but 5-- instead creating new windows. 6-- C. make sure that the location list window is not reused instead of the window 7-- it belongs to. 8 9local n =require ( 'test.functional.testnvim' )() 10local t =require ( 'test.testutil' ) 11 12local describe , it , setup , teardown =t . describe , t . it , t . setup , t . teardown 13local source =n . source 14local clear , command , expect =n . clear , n . command , n . expect 15 16describe ( 'location list' , function () 17local test_file ='Xtest-096_location_list.out' 18setup ( clear ) 19teardown ( function () 20os . remove ( test_file ) 21end ) 22 23it ( 'is working' , function () 24-- Set up the test environment. 25source ( 26-- This function serves as a callback which is executed on editing a new 27-- buffer. It accepts a "test protocol" file name that looks like 28-- "test://foo.txt". It sets some buffer-local settings and populates the 29-- buffer with one line consisting of the base name ("foo"). 30[[ 31function! ReadTestProtocol(name) 32let base = substitute(a:name, '\v^test://(.*)%(\.[^.]+)?', '\1', '') 33let word = substitute(base, '\v(.*)\..*', '\1', '') 34 35setl modifiable 36setl noreadonly 37setl noswapfile 38setl bufhidden=delete 39%del _ 40" For problem 2: 41" 'buftype' has to be set to reproduce the constant opening of new windows. 42setl buftype=nofile 43 44call setline(1, word) 45 46setl nomodified 47setl nomodifiable 48setl readonly 49exe 'doautocmd BufRead ' . substitute(a:name, '\v^test://(.*)', '\1', '') 50endfunction 51]] 52-- Register the above buffer setup function to be executed before 53-- starting to edit a new "test protocol" buffer. 54.. [[ 55augroup testgroup 56au! 57autocmd BufReadCmd test://* call ReadTestProtocol(expand("<amatch>")) 58augroup END 59]] 60-- Populate the location list of the current window with some test 61-- protocol file locations such as "test://foo.txt". 62.. [[ 63let words = [ "foo", "bar", "baz", "quux", "shmoo", "spam", "eggs" ] 64let qflist = [] 65for word in words 66call add(qflist, {'filename': 'test://' . word . '.txt', 'text': 'file ' . word . '.txt', }) 67" NOTE: problem 1: 68" Intentionally not setting 'lnum' so that the quickfix entries are not 69" valid. 70call setloclist(0, qflist, ' ') 71endfor 72]] 73) 74 75-- Set up the result buffer. 76command ( 'enew' ) 77command ( 'w! ' .. test_file ) 78command ( 'b 1' ) 79 80-- Test A. 81 82-- Open a new buffer as the sole window, rewind and open the prepopulated 83-- location list and navigate through the entries. 84command ( 'lrewind' ) 85command ( 'enew' ) 86command ( 'lopen' ) 87command (( 'lnext|' ): rep ( 4 )) 88 89-- Split the window, copying the location list, then open the copied 90-- location list and again navigate forward. 91command ( 'vert split' ) 92command ( 'wincmd L' ) 93command ( 'lopen' ) 94command ( 'wincmd p' ) 95command ( 'lnext' ) 96 97-- Record the current file name and the file name of the corresponding 98-- location list entry, then open the result buffer. 99command ( 'let fileName = expand("%")' ) 100command ( 'wincmd p' ) 101command ( [[let locationListFileName = substitute(getline(line('.')), '\([^|]*\)|.*', '\1', '')]] ) 102command ( 'wincmd n' ) 103command ( 'wincmd K' ) 104command ( 'b ' .. test_file ) 105 106-- Prepare test output and write it to the result buffer. 107command ( [[let fileName = substitute(fileName, '\\', '/', 'g')]] ) 108command ( [[let locationListFileName = substitute(locationListFileName, '\\', '/', 'g')]] ) 109command ( [[call append(line('$'), "Test A:")]] ) 110command ( [[call append(line('$'), " - file name displayed: " . fileName)]] ) 111command ( 112[[call append(line('$'), " - quickfix claims that the file name displayed is: " . locationListFileName)]] 113) 114command ( 'w' ) 115 116-- Clean slate for the next test. 117command ( 'wincmd o' ) 118command ( 'b 1' ) 119 120-- Test B. 121 122-- Rewind the location list, then open it and browse through it by running 123-- ":{number}" followed by Enter repeatedly in the location list window. 124command ( 'lrewind' ) 125command ( 'lopen' ) 126command ( '2' ) 127command ( [[exe "normal \\<CR>"]] ) 128command ( 'wincmd p' ) 129command ( '3' ) 130command ( [[exe "normal \<CR>"]] ) 131command ( 'wincmd p' ) 132command ( '4' ) 133command ( [[exe "normal \<CR>"]] ) 134 135-- Record the number of windows open, then go back to the result buffer. 136command ( 'let numberOfWindowsOpen = winnr("$")' ) 137command ( 'wincmd n' ) 138command ( 'wincmd K' ) 139command ( 'b ' .. test_file ) 140 141-- Prepare test output and write it to the result buffer. 142command ( 'call append(line("$"), "Test B:")' ) 143command ( 'call append(line("$"), " - number of window open: " . numberOfWindowsOpen)' ) 144command ( 'w' ) 145 146-- Clean slate. 147command ( 'wincmd o' ) 148command ( 'b 1' ) 149 150-- Test C. 151 152-- Rewind the location list, then open it and again do the ":{number}" plus 153-- Enter browsing. But this time, move the location list window to the top 154-- to check whether it (the first window found) will be reused when we try 155-- to open new windows. 156command ( 'lrewind' ) 157command ( 'lopen' ) 158command ( 'wincmd K' ) 159command ( '2' ) 160command ( [[exe "normal \<CR>"]] ) 161command ( 'wincmd p' ) 162command ( '3' ) 163command ( [[exe "normal \<CR>"]] ) 164command ( 'wincmd p' ) 165command ( '4' ) 166command ( [[exe "normal \<CR>"]] ) 167 168-- Record the 'buftype' of window 1 (the location list) and the buffer name 169-- of window 2 (the current "test protocol" buffer), then go back to the 170-- result buffer. 171command ( '1wincmd w' ) 172command ( 'let locationListWindowBufType = &buftype' ) 173command ( '2wincmd w' ) 174command ( 'let bufferName = expand("%")' ) 175command ( 'wincmd n' ) 176command ( 'wincmd K' ) 177command ( 'b ' .. test_file ) 178 179-- Prepare test output and write it to the result buffer. 180command ( [[let bufferName = substitute(bufferName, '\\', '/', 'g')]] ) 181command ( [[call append(line("$"), "Test C:")]] ) 182command ( 183[[call append(line('$'), " - 'buftype' of the location list window: " . locationListWindowBufType)]] 184) 185command ( [[call append(line('$'), " - buffer displayed in the 2nd window: " . bufferName)]] ) 186command ( 'w' ) 187command ( 'wincmd o' ) 188command ( 'b 1' ) 189 190-- Assert buffer contents. 191expect ( [[ 192 193Test A: 194- file name displayed: test://bar.txt 195- quickfix claims that the file name displayed is: test://bar.txt 196Test B: 197- number of window open: 2 198Test C: 199- 'buftype' of the location list window: quickfix 200- buffer displayed in the 2nd window: test://quux.txt]] ) 201end ) 202end )