diff options
Diffstat (limited to 'test/functional')
-rw-r--r-- | test/functional/legacy/051_highlight_spec.lua | 61 | ||||
-rw-r--r-- | test/functional/ui/popupmenu_spec.lua | 294 |
2 files changed, 320 insertions, 35 deletions
diff --git a/test/functional/legacy/051_highlight_spec.lua b/test/functional/legacy/051_highlight_spec.lua index 40f70de2ec..0c9c9621ee 100644 --- a/test/functional/legacy/051_highlight_spec.lua +++ b/test/functional/legacy/051_highlight_spec.lua @@ -3,10 +3,11 @@ local Screen = require('test.functional.ui.screen') local helpers = require('test.functional.helpers')(after_each) local clear, feed = helpers.clear, helpers.feed -local command, expect = helpers.command, helpers.expect +local expect = helpers.expect local eq = helpers.eq local wait = helpers.wait local exc_exec = helpers.exc_exec +local feed_command = helpers.feed_command describe(':highlight', function() setup(clear) @@ -15,7 +16,7 @@ describe(':highlight', function() local screen = Screen.new(35, 10) screen:attach() -- Basic test if ":highlight" doesn't crash - command('set more') + feed_command('set more') feed(':highlight<CR>') -- FIXME(tarruda): We need to be sure the prompt is displayed before -- continuing, or risk a race condition where some of the following input @@ -34,52 +35,62 @@ describe(':highlight', function() ]]) feed('q') wait() -- wait until we're back to normal - command('hi Search') - command('hi Normal') + feed_command('hi Search') + feed_command('hi Normal') -- Test setting colors. -- Test clearing one color and all doesn't generate error or warning - command('hi NewGroup cterm=italic ctermfg=DarkBlue ctermbg=Grey gui=NONE guifg=#00ff00 guibg=Cyan') - command('hi Group2 cterm=NONE') - command('hi Group3 cterm=bold') - command('redir! @a') - command('hi NewGroup') - command('hi Group2') - command('hi Group3') - command('hi clear NewGroup') - command('hi NewGroup') - command('hi Group2') - command('hi Group2 NONE') - command('hi Group2') - command('hi clear') - command('hi Group3') + feed_command('hi NewGroup cterm=italic ctermfg=DarkBlue ctermbg=Grey gui=NONE guifg=#00ff00 guibg=Cyan') + feed_command('hi Group2 cterm=NONE') + feed_command('hi Group3 cterm=bold') + feed_command('redir! @a') + feed_command('hi NewGroup') + feed_command('hi Group2') + feed_command('hi Group3') + feed_command('hi clear NewGroup') + feed_command('hi NewGroup') + feed_command('hi Group2') + feed_command('hi Group2 NONE') + feed_command('hi Group2') + feed_command('hi clear') + feed_command('hi Group3') + feed('<cr>') eq('Vim(highlight):E475: Invalid argument: cterm=\'asdf', exc_exec([[hi Crash cterm='asdf]])) - command('redir END') + feed_command('redir END') -- Filter ctermfg and ctermbg, the numbers depend on the terminal - command('0put a') - command([[%s/ctermfg=\d*/ctermfg=2/]]) - command([[%s/ctermbg=\d*/ctermbg=3/]]) + feed_command('0put a') + feed_command([[%s/ctermfg=\d*/ctermfg=2/]]) + feed_command([[%s/ctermbg=\d*/ctermbg=3/]]) -- Fix the fileformat - command('set ff&') - command('$d') + feed_command('set ff&') + feed_command('$d') -- Assert buffer contents. expect([[ + NewGroup xxx cterm=italic ctermfg=2 ctermbg=3 guifg=#00ff00 guibg=Cyan + Group2 xxx cleared + Group3 xxx cterm=bold + + NewGroup xxx cleared + Group2 xxx cleared + + Group2 xxx cleared + + Group3 xxx cleared]]) - screen:detach() end) end) diff --git a/test/functional/ui/popupmenu_spec.lua b/test/functional/ui/popupmenu_spec.lua index af9abeba80..9424931de4 100644 --- a/test/functional/ui/popupmenu_spec.lua +++ b/test/functional/ui/popupmenu_spec.lua @@ -3,6 +3,8 @@ local Screen = require('test.functional.ui.screen') local clear, feed = helpers.clear, helpers.feed local source = helpers.source local insert = helpers.insert +local meths = helpers.meths +local command = helpers.command describe('ui/ext_popupmenu', function() local screen @@ -15,22 +17,25 @@ describe('ui/ext_popupmenu', function() [2] = {bold = true}, [3] = {reverse = true}, [4] = {bold = true, reverse = true}, - [5] = {bold = true, foreground = Screen.colors.SeaGreen} + [5] = {bold = true, foreground = Screen.colors.SeaGreen}, + [6] = {background = Screen.colors.WebGray}, + [7] = {background = Screen.colors.LightMagenta}, }) - end) - - it('works', function() source([[ function! TestComplete() abort - call complete(1, ['foo', 'bar', 'spam']) + call complete(1, [{'word':'foo', 'abbr':'fo', 'menu':'the foo', 'info':'foo-y', 'kind':'x'}, 'bar', 'spam']) return '' endfunction ]]) - local expected = { - {'foo', '', '', ''}, - {'bar', '', '', ''}, - {'spam', '', '', ''}, - } + end) + + local expected = { + {'fo', 'x', 'the foo', 'foo-y'}, + {'bar', '', '', ''}, + {'spam', '', '', ''}, + } + + it('works', function() feed('o<C-r>=TestComplete()<CR>') screen:expect{grid=[[ | @@ -92,8 +97,277 @@ describe('ui/ext_popupmenu', function() {2:-- INSERT --} | ]]} end) + + it('can be controlled by API', function() + feed('o<C-r>=TestComplete()<CR>') + screen:expect{grid=[[ + | + foo^ | + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {2:-- INSERT --} | + ]], popupmenu={ + items=expected, + pos=0, + anchor={1,0}, + }} + + meths.select_popupmenu_item(1,false,false,{}) + screen:expect{grid=[[ + | + foo^ | + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {2:-- INSERT --} | + ]], popupmenu={ + items=expected, + pos=1, + anchor={1,0}, + }} + + meths.select_popupmenu_item(2,true,false,{}) + screen:expect{grid=[[ + | + spam^ | + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {2:-- INSERT --} | + ]], popupmenu={ + items=expected, + pos=2, + anchor={1,0}, + }} + + meths.select_popupmenu_item(0,true,true,{}) + screen:expect([[ + | + foo^ | + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {2:-- INSERT --} | + ]]) + + + feed('<c-w><C-r>=TestComplete()<CR>') + screen:expect{grid=[[ + | + foo^ | + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {2:-- INSERT --} | + ]], popupmenu={ + items=expected, + pos=0, + anchor={1,0}, + }} + + meths.select_popupmenu_item(-1,false,false,{}) + screen:expect{grid=[[ + | + foo^ | + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {2:-- INSERT --} | + ]], popupmenu={ + items=expected, + pos=-1, + anchor={1,0}, + }} + + meths.select_popupmenu_item(1,true,false,{}) + screen:expect{grid=[[ + | + bar^ | + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {2:-- INSERT --} | + ]], popupmenu={ + items=expected, + pos=1, + anchor={1,0}, + }} + + meths.select_popupmenu_item(-1,true,false,{}) + screen:expect{grid=[[ + | + ^ | + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {2:-- INSERT --} | + ]], popupmenu={ + items=expected, + pos=-1, + anchor={1,0}, + }} + + meths.select_popupmenu_item(0,true,false,{}) + screen:expect{grid=[[ + | + foo^ | + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {2:-- INSERT --} | + ]], popupmenu={ + items=expected, + pos=0, + anchor={1,0}, + }} + + meths.select_popupmenu_item(-1,true,true,{}) + screen:expect([[ + | + ^ | + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {2:-- INSERT --} | + ]]) + + command('imap <f1> <cmd>call nvim_select_popupmenu_item(2,v:true,v:false,{})<cr>') + command('imap <f2> <cmd>call nvim_select_popupmenu_item(-1,v:false,v:false,{})<cr>') + command('imap <f3> <cmd>call nvim_select_popupmenu_item(1,v:false,v:true,{})<cr>') + feed('<C-r>=TestComplete()<CR>') + screen:expect{grid=[[ + | + foo^ | + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {2:-- INSERT --} | + ]], popupmenu={ + items=expected, + pos=0, + anchor={1,0}, + }} + + feed('<f1>') + screen:expect{grid=[[ + | + spam^ | + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {2:-- INSERT --} | + ]], popupmenu={ + items=expected, + pos=2, + anchor={1,0}, + }} + + feed('<f2>') + screen:expect{grid=[[ + | + spam^ | + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {2:-- INSERT --} | + ]], popupmenu={ + items=expected, + pos=-1, + anchor={1,0}, + }} + + feed('<f3>') + screen:expect([[ + | + bar^ | + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {2:-- INSERT --} | + ]]) + + -- also should work for builtin popupmenu + screen:set_option('ext_popupmenu', false) + feed('<C-r>=TestComplete()<CR>') + screen:expect([[ + | + foo^ | + {6:fo x the foo }{1: }| + {7:bar }{1: }| + {7:spam }{1: }| + {1:~ }| + {1:~ }| + {2:-- INSERT --} | + ]]) + + feed('<f1>') + screen:expect([[ + | + spam^ | + {7:fo x the foo }{1: }| + {7:bar }{1: }| + {6:spam }{1: }| + {1:~ }| + {1:~ }| + {2:-- INSERT --} | + ]]) + + feed('<f2>') + screen:expect([[ + | + spam^ | + {7:fo x the foo }{1: }| + {7:bar }{1: }| + {7:spam }{1: }| + {1:~ }| + {1:~ }| + {2:-- INSERT --} | + ]]) + + feed('<f3>') + screen:expect([[ + | + bar^ | + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {2:-- INSERT --} | + ]]) + end) end) + describe('popup placement', function() local screen before_each(function() |