diff options
author | Björn Linse <bjorn.linse@gmail.com> | 2016-06-08 11:26:06 +0200 |
---|---|---|
committer | Björn Linse <bjorn.linse@gmail.com> | 2016-08-29 10:17:31 +0200 |
commit | c41bacc67cb2c5be765f30c42889f168d5fc9d40 (patch) | |
tree | 492f19ea5dd57ec1ea980192fa153ef1325616b6 /test/functional/viml/completion_spec.lua | |
parent | e968d72cae57180921ad9cf24cde74fedc8b03d3 (diff) | |
download | rneovim-c41bacc67cb2c5be765f30c42889f168d5fc9d40.tar.gz rneovim-c41bacc67cb2c5be765f30c42889f168d5fc9d40.tar.bz2 rneovim-c41bacc67cb2c5be765f30c42889f168d5fc9d40.zip |
api/ui: add tests for popupmenu_external events
update screen.lua to use new style nvim_ui_attach
Diffstat (limited to 'test/functional/viml/completion_spec.lua')
-rw-r--r-- | test/functional/viml/completion_spec.lua | 102 |
1 files changed, 102 insertions, 0 deletions
diff --git a/test/functional/viml/completion_spec.lua b/test/functional/viml/completion_spec.lua index 07544a91ab..5de3bb5da7 100644 --- a/test/functional/viml/completion_spec.lua +++ b/test/functional/viml/completion_spec.lua @@ -755,4 +755,106 @@ describe('completion', function() ]]) end) end) + +end) + +describe('External completion popupmenu', function() + local screen + local items, selected, anchor + before_each(function() + clear() + screen = Screen.new(60, 8) + screen:attach({rgb=true, popupmenu_external=true}) + screen:set_default_attr_ids({ + [1] = {bold=true, foreground=Screen.colors.Blue}, + [2] = {bold = true}, + }) + screen:set_on_event_handler(function(name, data) + if name == "popupmenu_show" then + local row, col + items, selected, row, col = unpack(data) + anchor = {row, col} + elseif name == "popupmenu_select" then + selected = data[1] + elseif name == "popupmenu_hide" then + items = nil + end + end) + end) + + it('works', function() + source([[ + function! TestComplete() abort + call complete(1, ['foo', 'bar', 'spam']) + return '' + endfunction + ]]) + local expected = { + {'foo', '', '', ''}, + {'bar', '', '', ''}, + {'spam', '', '', ''}, + } + feed('o<C-r>=TestComplete()<CR>') + screen:expect([[ + | + foo^ | + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {2:-- INSERT --} | + ]], nil, nil, function() + eq(expected, items) + eq(0, selected) + eq({1,0}, anchor) + end) + + feed('<c-p>') + screen:expect([[ + | + ^ | + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {2:-- INSERT --} | + ]], nil, nil, function() + eq(expected, items) + eq(-1, selected) + eq({1,0}, anchor) + end) + + -- down moves the selection in the menu, but does not insert anything + feed('<down><down>') + screen:expect([[ + | + ^ | + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {2:-- INSERT --} | + ]], nil, nil, function() + eq(expected, items) + eq(1, selected) + eq({1,0}, anchor) + end) + + feed('<cr>') + screen:expect([[ + | + bar^ | + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {1:~ }| + {2:-- INSERT --} | + ]], nil, nil, function() + eq(nil, items) -- popupmenu was hidden + end) + end) end) |