From ed6230434b2b0a07ece03272b871412929bfcb53 Mon Sep 17 00:00:00 2001 From: Yatao Li Date: Thu, 5 Mar 2020 15:51:02 +0800 Subject: gen_api_dispatch.lua: allow msgpack int for Float args; test: add ui_pum_set_bounds and tv_dict_add_float tests --- test/functional/ui/popupmenu_spec.lua | 86 +++++++++++++++++++++++++++++++++-- 1 file changed, 81 insertions(+), 5 deletions(-) (limited to 'test/functional/ui') diff --git a/test/functional/ui/popupmenu_spec.lua b/test/functional/ui/popupmenu_spec.lua index 11c3f4123e..9b6ca8032a 100644 --- a/test/functional/ui/popupmenu_spec.lua +++ b/test/functional/ui/popupmenu_spec.lua @@ -382,7 +382,7 @@ describe('ui/ext_popupmenu', function() end describe('pum_set_height', function() - it('can be set pum height', function() + it('can set pum height', function() source_complete_month() local month_expected = { {'January', '', '', ''}, @@ -423,23 +423,99 @@ describe('ui/ext_popupmenu', function() it('an error occurs if set 0 or less', function() local ok, err, _ ok, _ = pcall(meths.ui_pum_set_height, 1) - eq(ok, true) + eq(true, ok) ok, err = pcall(meths.ui_pum_set_height, 0) - eq(ok, false) + eq(false, ok) 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) + eq(true, ok) screen:set_option('ext_popupmenu', false) ok, err = pcall(meths.ui_pum_set_height, 1) - eq(ok, false) + eq(false, ok) matches('.*: It must support the ext_popupmenu option', err) end) end) + describe('pum_set_bounds', function() + it('can set pum bounds', 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=TestCompleteMonth()') + meths.ui_pum_set_height(pum_height) + -- set bounds w h r c + meths.ui_pum_set_bounds(10.5, 5.2, 6.3, 7.4) + feed('') + -- 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 row or col set less than 0', function() + local ok, err, _ + ok, _ = pcall(meths.ui_pum_set_bounds, 1.0, 1.0, 0.0, 1.5) + eq(true, ok) + ok, err = pcall(meths.ui_pum_set_bounds, 1.0, 1.0, -1.0, 0.0) + eq(false, ok) + matches('.*: Expected pumpos row >= 0', err) + ok, err = pcall(meths.ui_pum_set_bounds, 1.0, 1.0, 0.0, -1.0) + eq(false, ok) + matches('.*: Expected pumpos col >= 0', err) + end) + + it('an error occurs if width or height set 0 or less', function() + local ok, err, _ + ok, _ = pcall(meths.ui_pum_set_bounds, 1.0, 1.0, 0.0, 1.5) + eq(true, ok) + ok, err = pcall(meths.ui_pum_set_bounds, 0.0, 1.0, 1.0, 0.0) + eq(false, ok) + matches('.*: Expected pumpos width > 0', err) + ok, err = pcall(meths.ui_pum_set_bounds, 1.0, 0.0, 1.0, 0.0) + eq(false, ok) + matches('.*: Expected pumpos height > 0', err) + end) + + it('an error occurs when ext_popupmenu is false', function() + local ok, err, _ + ok, _ = pcall(meths.ui_pum_set_bounds, 1.0, 1.0, 0.0, 1.5) + eq(true, ok) + screen:set_option('ext_popupmenu', false) + ok, err = pcall(meths.ui_pum_set_bounds, 1.0, 1.0, 0.0, 1.5) + eq(false, ok) + matches('.*: UI must support the ext_popupmenu option', err) + end) + end) + it(', works without ui_pum_set_height', function() source_complete_month() local month_expected = { -- cgit From d372c804aa33a272f6659f6d08d5dfee704d30d9 Mon Sep 17 00:00:00 2001 From: Yatao Li Date: Sun, 22 Mar 2020 17:27:49 +0800 Subject: api/ui: allow set bounds row and col to be less than 0; ui_pum_get_pos: return first extui bounds information instead of reducing --- test/functional/ui/popupmenu_spec.lua | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) (limited to 'test/functional/ui') diff --git a/test/functional/ui/popupmenu_spec.lua b/test/functional/ui/popupmenu_spec.lua index 9b6ca8032a..3108d21508 100644 --- a/test/functional/ui/popupmenu_spec.lua +++ b/test/functional/ui/popupmenu_spec.lua @@ -481,16 +481,14 @@ describe('ui/ext_popupmenu', function() }} end) - it('an error occurs if row or col set less than 0', function() + it('no error occurs if row or col set less than 0', function() local ok, err, _ ok, _ = pcall(meths.ui_pum_set_bounds, 1.0, 1.0, 0.0, 1.5) eq(true, ok) - ok, err = pcall(meths.ui_pum_set_bounds, 1.0, 1.0, -1.0, 0.0) - eq(false, ok) - matches('.*: Expected pumpos row >= 0', err) - ok, err = pcall(meths.ui_pum_set_bounds, 1.0, 1.0, 0.0, -1.0) - eq(false, ok) - matches('.*: Expected pumpos col >= 0', err) + ok, _ = pcall(meths.ui_pum_set_bounds, 1.0, 1.0, -1.0, 0.0) + eq(true, ok) + ok, _ = pcall(meths.ui_pum_set_bounds, 1.0, 1.0, 0.0, -1.0) + eq(true, ok) end) it('an error occurs if width or height set 0 or less', function() -- cgit From e34684b2ad02e759dec39c0f0958c7882120ecdc Mon Sep 17 00:00:00 2001 From: Yatao Li Date: Sun, 22 Mar 2020 17:53:45 +0800 Subject: api/ui: simplify popup menu position get/set logic; fix test --- test/functional/ui/popupmenu_spec.lua | 53 ++++++++++++----------------------- 1 file changed, 18 insertions(+), 35 deletions(-) (limited to 'test/functional/ui') diff --git a/test/functional/ui/popupmenu_spec.lua b/test/functional/ui/popupmenu_spec.lua index 3108d21508..c1c5d1ce2e 100644 --- a/test/functional/ui/popupmenu_spec.lua +++ b/test/functional/ui/popupmenu_spec.lua @@ -8,7 +8,7 @@ local command = helpers.command local funcs = helpers.funcs local get_pathsep = helpers.get_pathsep local eq = helpers.eq -local matches = helpers.matches +local pcall_err = helpers.pcall_err describe('ui/ext_popupmenu', function() local screen @@ -421,22 +421,16 @@ describe('ui/ext_popupmenu', function() end) it('an error occurs if set 0 or less', function() - local ok, err, _ - ok, _ = pcall(meths.ui_pum_set_height, 1) - eq(true, ok) - ok, err = pcall(meths.ui_pum_set_height, 0) - eq(false, ok) - matches('.*: Expected pum height > 0', err) + meths.ui_pum_set_height(1) + eq('Expected pum height > 0', + pcall_err(meths.ui_pum_set_height, 0)) end) it('an error occurs when ext_popupmenu is false', function() - local ok, err, _ - ok, _ = pcall(meths.ui_pum_set_height, 1) - eq(true, ok) + meths.ui_pum_set_height(1) screen:set_option('ext_popupmenu', false) - ok, err = pcall(meths.ui_pum_set_height, 1) - eq(false, ok) - matches('.*: It must support the ext_popupmenu option', err) + eq('It must support the ext_popupmenu option', + pcall_err(meths.ui_pum_set_height, 1)) end) end) @@ -482,35 +476,24 @@ describe('ui/ext_popupmenu', function() end) it('no error occurs if row or col set less than 0', function() - local ok, err, _ - ok, _ = pcall(meths.ui_pum_set_bounds, 1.0, 1.0, 0.0, 1.5) - eq(true, ok) - ok, _ = pcall(meths.ui_pum_set_bounds, 1.0, 1.0, -1.0, 0.0) - eq(true, ok) - ok, _ = pcall(meths.ui_pum_set_bounds, 1.0, 1.0, 0.0, -1.0) - eq(true, ok) + meths.ui_pum_set_bounds(1.0, 1.0, 0.0, 1.5) + meths.ui_pum_set_bounds(1.0, 1.0, -1.0, 0.0) + meths.ui_pum_set_bounds(1.0, 1.0, 0.0, -1.0) end) it('an error occurs if width or height set 0 or less', function() - local ok, err, _ - ok, _ = pcall(meths.ui_pum_set_bounds, 1.0, 1.0, 0.0, 1.5) - eq(true, ok) - ok, err = pcall(meths.ui_pum_set_bounds, 0.0, 1.0, 1.0, 0.0) - eq(false, ok) - matches('.*: Expected pumpos width > 0', err) - ok, err = pcall(meths.ui_pum_set_bounds, 1.0, 0.0, 1.0, 0.0) - eq(false, ok) - matches('.*: Expected pumpos height > 0', err) + meths.ui_pum_set_bounds(1.0, 1.0, 0.0, 1.5) + eq('Expected width > 0', + pcall_err(meths.ui_pum_set_bounds, 0.0, 1.0, 1.0, 0.0)) + eq('Expected height > 0', + pcall_err(meths.ui_pum_set_bounds, 1.0, -1.0, 1.0, 0.0)) end) it('an error occurs when ext_popupmenu is false', function() - local ok, err, _ - ok, _ = pcall(meths.ui_pum_set_bounds, 1.0, 1.0, 0.0, 1.5) - eq(true, ok) + meths.ui_pum_set_bounds(1.0, 1.0, 0.0, 1.5) screen:set_option('ext_popupmenu', false) - ok, err = pcall(meths.ui_pum_set_bounds, 1.0, 1.0, 0.0, 1.5) - eq(false, ok) - matches('.*: UI must support the ext_popupmenu option', err) + eq('UI must support the ext_popupmenu option', + pcall_err(meths.ui_pum_set_bounds, 1.0, 1.0, 0.0, 1.5)) end) end) -- cgit