diff options
Diffstat (limited to 'test/functional/ui/popupmenu_spec.lua')
-rw-r--r-- | test/functional/ui/popupmenu_spec.lua | 370 |
1 files changed, 360 insertions, 10 deletions
diff --git a/test/functional/ui/popupmenu_spec.lua b/test/functional/ui/popupmenu_spec.lua index 606c7c1e26..9424931de4 100644 --- a/test/functional/ui/popupmenu_spec.lua +++ b/test/functional/ui/popupmenu_spec.lua @@ -2,6 +2,9 @@ local helpers = require('test.functional.helpers')(after_each) 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 @@ -14,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=[[ | @@ -91,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() @@ -257,4 +532,79 @@ describe('popup placement', function() {2:-- }{5:match 1 of 10} | ]]) end) + + it('works with vsplits', function() + insert('aaa aab aac\n') + feed(':vsplit<cr>') + screen:expect([[ + aaa aab aac {3:│}aaa aab aac| + ^ {3:│} | + {1:~ }{3:│}{1:~ }| + {1:~ }{3:│}{1:~ }| + {1:~ }{3:│}{1:~ }| + {1:~ }{3:│}{1:~ }| + {1:~ }{3:│}{1:~ }| + {1:~ }{3:│}{1:~ }| + {1:~ }{3:│}{1:~ }| + {1:~ }{3:│}{1:~ }| + {1:~ }{3:│}{1:~ }| + {1:~ }{3:│}{1:~ }| + {1:~ }{3:│}{1:~ }| + {1:~ }{3:│}{1:~ }| + {1:~ }{3:│}{1:~ }| + {1:~ }{3:│}{1:~ }| + {1:~ }{3:│}{1:~ }| + {1:~ }{3:│}{1:~ }| + {4:[No Name] [+] }{3:<Name] [+] }| + :vsplit | + ]]) + + feed('ibbb a<c-x><c-n>') + screen:expect([[ + aaa aab aac {3:│}aaa aab aac| + bbb aaa^ {3:│}bbb aaa | + {1:~ }{s: aaa }{1: }{3:│}{1:~ }| + {1:~ }{n: aab }{1: }{3:│}{1:~ }| + {1:~ }{n: aac }{1: }{3:│}{1:~ }| + {1:~ }{3:│}{1:~ }| + {1:~ }{3:│}{1:~ }| + {1:~ }{3:│}{1:~ }| + {1:~ }{3:│}{1:~ }| + {1:~ }{3:│}{1:~ }| + {1:~ }{3:│}{1:~ }| + {1:~ }{3:│}{1:~ }| + {1:~ }{3:│}{1:~ }| + {1:~ }{3:│}{1:~ }| + {1:~ }{3:│}{1:~ }| + {1:~ }{3:│}{1:~ }| + {1:~ }{3:│}{1:~ }| + {1:~ }{3:│}{1:~ }| + {4:[No Name] [+] }{3:<Name] [+] }| + {2:-- }{5:match 1 of 3} | + ]]) + + feed('<esc><c-w><c-w>oc a<c-x><c-n>') + screen:expect([[ + aaa aab aac{3:│}aaa aab aac | + bbb aaa {3:│}bbb aaa | + c aaa {3:│}c aaa^ | + {1:~ }{3:│}{1:~}{s: aaa }{1: }| + {1:~ }{3:│}{1:~}{n: aab }{1: }| + {1:~ }{3:│}{1:~}{n: aac }{1: }| + {1:~ }{3:│}{1:~ }| + {1:~ }{3:│}{1:~ }| + {1:~ }{3:│}{1:~ }| + {1:~ }{3:│}{1:~ }| + {1:~ }{3:│}{1:~ }| + {1:~ }{3:│}{1:~ }| + {1:~ }{3:│}{1:~ }| + {1:~ }{3:│}{1:~ }| + {1:~ }{3:│}{1:~ }| + {1:~ }{3:│}{1:~ }| + {1:~ }{3:│}{1:~ }| + {1:~ }{3:│}{1:~ }| + {3:<Name] [+] }{4:[No Name] [+] }| + {2:-- }{5:match 1 of 3} | + ]]) + end) end) |