diff options
author | David Bürgin <676c7473@gmail.com> | 2015-03-22 12:28:03 +0100 |
---|---|---|
committer | Justin M. Keyes <justinkz@gmail.com> | 2015-05-04 23:36:08 -0400 |
commit | 9e91bb461f9704db13d2c75c815d79cc2cb0c4be (patch) | |
tree | 99cffa2f3564fb1d0b9978af1d4c608c6ba7d616 | |
parent | 34b5cee533e457cb72314a0fcca4c227bde8487a (diff) | |
download | rneovim-9e91bb461f9704db13d2c75c815d79cc2cb0c4be.tar.gz rneovim-9e91bb461f9704db13d2c75c815d79cc2cb0c4be.tar.bz2 rneovim-9e91bb461f9704db13d2c75c815d79cc2cb0c4be.zip |
tests: Migrate legacy test 96 #2220
-rw-r--r-- | src/nvim/testdir/Makefile | 1 | ||||
-rw-r--r-- | src/nvim/testdir/test96.in | 142 | ||||
-rw-r--r-- | src/nvim/testdir/test96.ok | 9 | ||||
-rw-r--r-- | test/functional/legacy/096_location_list_spec.lua | 190 |
4 files changed, 190 insertions, 152 deletions
diff --git a/src/nvim/testdir/Makefile b/src/nvim/testdir/Makefile index 2dedc3db12..ee3eb89bd8 100644 --- a/src/nvim/testdir/Makefile +++ b/src/nvim/testdir/Makefile @@ -27,7 +27,6 @@ SCRIPTS := test_autoformat_join.out \ test76.out test79.out test80.out \ test82.out test83.out \ test86.out test87.out test88.out \ - test96.out \ test_listlbr.out \ test_breakindent.out \ test_argument_count.out \ diff --git a/src/nvim/testdir/test96.in b/src/nvim/testdir/test96.in deleted file mode 100644 index 9d1a2c83a5..0000000000 --- a/src/nvim/testdir/test96.in +++ /dev/null @@ -1,142 +0,0 @@ -This will test for problems in quickfix: -A. incorrectly copying location lists which caused the location list to show a - different name than the file that was actually being displayed. -B. not reusing the window for which the location list window is opened but - instead creating new windows. -C. make sure that the location list window is not reused instead of the window - it belongs to. - -Note: to debug a problem comment out the last ":b 1" in a test and testing will -stop at this point. - -STARTTEST -:so small.vim -: enew -: w! test.out -: b 1 -: " Set up the test environment: -: function! ReadTestProtocol(name) -: let base = substitute(a:name, '\v^test://(.*)%(\.[^.]+)?', '\1', '') -: let word = substitute(base, '\v(.*)\..*', '\1', '') -: -: setl modifiable -: setl noreadonly -: setl noswapfile -: setl bufhidden=delete -: %del _ -: " For problem 2: -: " 'buftype' has to be set to reproduce the constant opening of new windows -: setl buftype=nofile -: -: call setline(1, word) -: -: setl nomodified -: setl nomodifiable -: setl readonly -: exe 'doautocmd BufRead ' . substitute(a:name, '\v^test://(.*)', '\1', '') -: endfunction -: augroup testgroup -: au! -: autocmd BufReadCmd test://* call ReadTestProtocol(expand("<amatch>")) -: augroup END -: let words = [ "foo", "bar", "baz", "quux", "shmoo", "spam", "eggs" ] -: -: let qflist = [] -: for word in words -: call add(qflist, {'filename': 'test://' . word . '.txt', 'text': 'file ' . word . '.txt', }) -: " NOTE: problem 1: -: " intentionally not setting 'lnum' so that the quickfix entries are not -: " valid -: call setloclist(0, qflist, ' ') -: endfor -ENDTEST - -Test A: -STARTTEST -:lrewind -:enew -:lopen -:lnext -:lnext -:lnext -:lnext -:vert split -:wincmd L -:lopen -:wincmd p -:lnext -:"b 1 -:let fileName = expand("%") -:wincmd p -:let locationListFileName = substitute(getline(line('.')), '\([^|]*\)|.*', '\1', '') -:wincmd n -:wincmd K -:b test.out -:let fileName = substitute(fileName, '\\', '/', 'g') -:let locationListFileName = substitute(locationListFileName, '\\', '/', 'g') -:call append(line('$'), "Test A:") -:call append(line('$'), " - file name displayed: " . fileName) -:call append(line('$'), " - quickfix claims that the file name displayed is: " . locationListFileName) -:w -:wincmd o -:b 1 -ENDTEST - -Test B: -STARTTEST -:lrewind -:lopen -:2 -:exe "normal \<CR>" -:wincmd p -:3 -:exe "normal \<CR>" -:wincmd p -:4 -:exe "normal \<CR>" -:let numberOfWindowsOpen = winnr('$') -:wincmd n -:wincmd K -:b test.out -:call append(line('$'), "Test B:") -:call append(line('$'), " - number of window open: " . numberOfWindowsOpen) -:w -:wincmd o -:b 1 -ENDTEST - -Test C: -STARTTEST -:lrewind -:lopen -:" Let's move the location list window to the top to check whether it (the first -:" window found) will be reused when we try to open new windows: -:wincmd K -:2 -:exe "normal \<CR>" -:wincmd p -:3 -:exe "normal \<CR>" -:wincmd p -:4 -:exe "normal \<CR>" -:1wincmd w -:let locationListWindowBufType = &buftype -:2wincmd w -:let bufferName = expand("%") -:wincmd n -:wincmd K -:b test.out -:let bufferName = substitute(bufferName, '\\', '/', 'g') -:call append(line('$'), "Test C:") -:call append(line('$'), " - 'buftype' of the location list window: " . locationListWindowBufType) -:call append(line('$'), " - buffer displayed in the 2nd window: " . bufferName) -:w -:wincmd o -:b 1 -ENDTEST - -STARTTEST -:qa -ENDTEST - diff --git a/src/nvim/testdir/test96.ok b/src/nvim/testdir/test96.ok deleted file mode 100644 index 3498e52f73..0000000000 --- a/src/nvim/testdir/test96.ok +++ /dev/null @@ -1,9 +0,0 @@ - -Test A: - - file name displayed: test://bar.txt - - quickfix claims that the file name displayed is: test://bar.txt -Test B: - - number of window open: 2 -Test C: - - 'buftype' of the location list window: quickfix - - buffer displayed in the 2nd window: test://quux.txt diff --git a/test/functional/legacy/096_location_list_spec.lua b/test/functional/legacy/096_location_list_spec.lua new file mode 100644 index 0000000000..2ccfd3530d --- /dev/null +++ b/test/functional/legacy/096_location_list_spec.lua @@ -0,0 +1,190 @@ +-- Test for problems in quickfix/location list: +-- A. incorrectly copying location lists which caused the location list to show a +-- different name than the file that was actually being displayed. +-- B. not reusing the window for which the location list window is opened but +-- instead creating new windows. +-- C. make sure that the location list window is not reused instead of the window +-- it belongs to. + +local helpers = require('test.functional.helpers') +local feed, insert, source = helpers.feed, helpers.insert, helpers.source +local clear, execute, expect = helpers.clear, helpers.execute, helpers.expect + +describe('location list', function() + setup(clear) + + teardown(function() + os.remove('test.out') + end) + + it('is working', function() + -- Set up the test environment. + source( + -- This function serves as a callback which is executed on editing a new + -- buffer. It accepts a "test protocol" file name that looks like + -- "test://foo.txt". It sets some buffer-local settings and populates the + -- buffer with one line consisting of the base name ("foo"). + [[ + function! ReadTestProtocol(name) + let base = substitute(a:name, '\v^test://(.*)%(\.[^.]+)?', '\1', '') + let word = substitute(base, '\v(.*)\..*', '\1', '') + + setl modifiable + setl noreadonly + setl noswapfile + setl bufhidden=delete + %del _ + " For problem 2: + " 'buftype' has to be set to reproduce the constant opening of new windows. + setl buftype=nofile + + call setline(1, word) + + setl nomodified + setl nomodifiable + setl readonly + exe 'doautocmd BufRead ' . substitute(a:name, '\v^test://(.*)', '\1', '') + endfunction + ]] .. + + -- Register the above buffer setup function to be executed before + -- starting to edit a new "test protocol" buffer. + [[ + augroup testgroup + au! + autocmd BufReadCmd test://* call ReadTestProtocol(expand("<amatch>")) + augroup END + ]] .. + + -- Populate the location list of the current window with some test + -- protocol file locations such as "test://foo.txt". + [[ + let words = [ "foo", "bar", "baz", "quux", "shmoo", "spam", "eggs" ] + let qflist = [] + for word in words + call add(qflist, {'filename': 'test://' . word . '.txt', 'text': 'file ' . word . '.txt', }) + " NOTE: problem 1: + " Intentionally not setting 'lnum' so that the quickfix entries are not + " valid. + call setloclist(0, qflist, ' ') + endfor + ]]) + + -- Set up the result buffer "test.out". + execute('enew') + execute('w! test.out') + execute('b 1') + + -- Test A. + + -- Open a new buffer as the sole window, rewind and open the prepopulated + -- location list and navigate through the entries. + execute('lrewind') + execute('enew') + execute('lopen') + execute('lnext', 'lnext', 'lnext', 'lnext') + + -- Split the window, copying the location list, then open the copied + -- location list and again navigate forward. + execute('vert split') + execute('wincmd L') + execute('lopen') + execute('wincmd p') + execute('lnext') + + -- Record the current file name and the file name of the corresponding + -- location list entry, then open the result buffer. + execute('let fileName = expand("%")') + execute('wincmd p') + execute([[let locationListFileName = substitute(getline(line('.')), '\([^|]*\)|.*', '\1', '')]]) + execute('wincmd n') + execute('wincmd K') + execute('b test.out') + + -- Prepare test output and write it to the result buffer. + execute([[let fileName = substitute(fileName, '\\', '/', 'g')]]) + execute([[let locationListFileName = substitute(locationListFileName, '\\', '/', 'g')]]) + execute([[call append(line('$'), "Test A:")]]) + execute([[call append(line('$'), " - file name displayed: " . fileName)]]) + execute([[call append(line('$'), " - quickfix claims that the file name displayed is: " . locationListFileName)]]) + execute('w') + + -- Clean slate for the next test. + execute('wincmd o') + execute('b 1') + + -- Test B. + + -- Rewind the location list, then open it and browse through it by running + -- ":{number}" followed by Enter repeatedly in the location list window. + execute('lrewind') + execute('lopen') + execute('2', [[exe "normal \\<CR>"]]) + execute('wincmd p') + execute('3', [[exe "normal \<CR>"]]) + execute('wincmd p') + execute('4', [[exe "normal \<CR>"]]) + + -- Record the number of windows open, then go back to the result buffer. + execute('let numberOfWindowsOpen = winnr("$")') + execute('wincmd n') + execute('wincmd K') + execute('b test.out') + + -- Prepare test output and write it to the result buffer. + execute('call append(line("$"), "Test B:")') + execute('call append(line("$"), " - number of window open: " . numberOfWindowsOpen)') + execute('w') + + -- Clean slate. + execute('wincmd o') + execute('b 1') + + -- Test C. + + -- Rewind the location list, then open it and again do the ":{number}" plus + -- Enter browsing. But this time, move the location list window to the top + -- to check whether it (the first window found) will be reused when we try + -- to open new windows. + execute('lrewind') + execute('lopen') + execute('wincmd K') + execute('2', [[exe "normal \<CR>"]]) + execute('wincmd p') + execute('3', [[exe "normal \<CR>"]]) + execute('wincmd p') + execute('4', [[exe "normal \<CR>"]]) + + -- Record the 'buftype' of window 1 (the location list) and the buffer name + -- of window 2 (the current "test protocol" buffer), then go back to the + -- result buffer. + execute('1wincmd w') + execute('let locationListWindowBufType = &buftype') + execute('2wincmd w') + execute('let bufferName = expand("%")') + execute('wincmd n') + execute('wincmd K') + execute('b test.out') + + -- Prepare test output and write it to the result buffer. + execute([[let bufferName = substitute(bufferName, '\\', '/', 'g')]]) + execute([[call append(line("$"), "Test C:")]]) + execute([[call append(line('$'), " - 'buftype' of the location list window: " . locationListWindowBufType)]]) + execute([[call append(line('$'), " - buffer displayed in the 2nd window: " . bufferName)]]) + execute('w') + execute('wincmd o') + execute('b 1') + + -- Assert buffer contents. + expect([[ + + Test A: + - file name displayed: test://bar.txt + - quickfix claims that the file name displayed is: test://bar.txt + Test B: + - number of window open: 2 + Test C: + - 'buftype' of the location list window: quickfix + - buffer displayed in the 2nd window: test://quux.txt]]) + end) +end) |