diff options
Diffstat (limited to 'test/functional/ui/popupmenu_spec.lua')
| -rw-r--r-- | test/functional/ui/popupmenu_spec.lua | 121 | 
1 files changed, 121 insertions, 0 deletions
| diff --git a/test/functional/ui/popupmenu_spec.lua b/test/functional/ui/popupmenu_spec.lua index 1db6a5150e..3b4b281c81 100644 --- a/test/functional/ui/popupmenu_spec.lua +++ b/test/functional/ui/popupmenu_spec.lua @@ -7,6 +7,8 @@ local meths = helpers.meths  local command = helpers.command  local funcs = helpers.funcs  local get_pathsep = helpers.get_pathsep +local eq = helpers.eq +local matches = helpers.matches  describe('ui/ext_popupmenu', function()    local screen @@ -368,6 +370,125 @@ describe('ui/ext_popupmenu', function()      ]])    end) +  local function source_complete_month() +    source([[ +    function! TestCompleteMonth() abort +    call complete(1, ['January', 'February', 'March', 'April', +    \ 'May', 'June', 'July', 'August', +    \ 'September', 'October', 'November', 'December']) +    return '' +    endfunction +    ]]) +  end + +  describe('pum_set_height', function() +    it('can be set pum height', function() +      source_complete_month() +      local month_expected = { +        {'January', '', '', ''}, +        {'February', '', '', ''}, +        {'March', '', '', ''}, +        {'April', '', '', ''}, +        {'May', '', '', ''}, +        {'June', '', '', ''}, +        {'July', '', '', ''}, +        {'August', '', '', ''}, +        {'September', '', '', ''}, +        {'October', '', '', ''}, +        {'November', '', '', ''}, +        {'December', '', '', ''}, +      } +      local pum_height = 6 +      feed('o<C-r>=TestCompleteMonth()<CR>') +      meths.ui_pum_set_height(pum_height) +      feed('<PageDown>') +      -- pos becomes pum_height-2 because it is subtracting 2 to keep some +      -- context in ins_compl_key2count() +      screen:expect{grid=[[ +                                                                  | +      January^                                                     | +      {1:~                                                           }| +      {1:~                                                           }| +      {1:~                                                           }| +      {1:~                                                           }| +      {1:~                                                           }| +      {2:-- INSERT --}                                                | +      ]], popupmenu={ +        items=month_expected, +        pos=pum_height-2, +        anchor={1,1,0}, +      }} +    end) + +    it('an error occurs if set 0 or less', function() +      local ok, err, _ +      ok, _ = pcall(meths.ui_pum_set_height, 1) +      eq(ok, true) +      ok, err = pcall(meths.ui_pum_set_height, 0) +      eq(ok, false) +      matches('.*: Expected pum height > 0', err) +    end) + +    it('an error occurs when ext_popupmenu is false', function() +      local ok, err, _ +      ok, _ = pcall(meths.ui_pum_set_height, 1) +      eq(ok, true) +      screen:set_option('ext_popupmenu', false) +      ok, err = pcall(meths.ui_pum_set_height, 1) +      eq(ok, false) +      matches('.*: It must support the ext_popupmenu option', err) +    end) +  end) + +  it('<PageUP>, <PageDown> works without ui_pum_set_height', function() +    source_complete_month() +    local month_expected = { +      {'January', '', '', ''}, +      {'February', '', '', ''}, +      {'March', '', '', ''}, +      {'April', '', '', ''}, +      {'May', '', '', ''}, +      {'June', '', '', ''}, +      {'July', '', '', ''}, +      {'August', '', '', ''}, +      {'September', '', '', ''}, +      {'October', '', '', ''}, +      {'November', '', '', ''}, +      {'December', '', '', ''}, +    } +    feed('o<C-r>=TestCompleteMonth()<CR>') +    feed('<PageDown>') +    screen:expect{grid=[[ +                                                                | +    January^                                                     | +    {1:~                                                           }| +    {1:~                                                           }| +    {1:~                                                           }| +    {1:~                                                           }| +    {1:~                                                           }| +    {2:-- INSERT --}                                                | +    ]], popupmenu={ +      items=month_expected, +      pos=3, +      anchor={1,1,0}, +    }} +    feed('<PageUp>') +    screen:expect{grid=[[ +                                                                | +    January^                                                     | +    {1:~                                                           }| +    {1:~                                                           }| +    {1:~                                                           }| +    {1:~                                                           }| +    {1:~                                                           }| +    {2:-- INSERT --}                                                | +    ]], popupmenu={ +      items=month_expected, +      pos=0, +      anchor={1,1,0}, +    }} +  end) +    it('works with wildoptions=pum', function()      screen:try_resize(32,10)      command('set wildmenu') | 
