aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYatao Li <yatli@microsoft.com>2020-03-05 15:51:02 +0800
committerYatao Li <yatli@microsoft.com>2020-04-28 01:53:43 +0800
commited6230434b2b0a07ece03272b871412929bfcb53 (patch)
tree54072632d666f18df56b53cf2ae593d58acebd8f
parent6da16ac931eec7be2487ee98e7f605fa12b0171d (diff)
downloadrneovim-ed6230434b2b0a07ece03272b871412929bfcb53.tar.gz
rneovim-ed6230434b2b0a07ece03272b871412929bfcb53.tar.bz2
rneovim-ed6230434b2b0a07ece03272b871412929bfcb53.zip
gen_api_dispatch.lua: allow msgpack int for Float args; test: add ui_pum_set_bounds and tv_dict_add_float tests
-rw-r--r--src/nvim/generators/gen_api_dispatch.lua6
-rw-r--r--test/functional/ui/popupmenu_spec.lua86
-rw-r--r--test/unit/eval/typval_spec.lua20
3 files changed, 107 insertions, 5 deletions
diff --git a/src/nvim/generators/gen_api_dispatch.lua b/src/nvim/generators/gen_api_dispatch.lua
index e861cfda35..6e80ad0e5c 100644
--- a/src/nvim/generators/gen_api_dispatch.lua
+++ b/src/nvim/generators/gen_api_dispatch.lua
@@ -237,6 +237,12 @@ for i = 1, #functions do
(j - 1)..'].type == kObjectTypeInteger && args.items['..(j - 1)..'].data.integer >= 0) {')
output:write('\n '..converted..' = (handle_T)args.items['..(j - 1)..'].data.integer;')
end
+ if rt:match('^Float$') then
+ -- accept integers for Floats
+ output:write('\n } else if (args.items['..
+ (j - 1)..'].type == kObjectTypeInteger) {')
+ output:write('\n '..converted..' = (Float)args.items['..(j - 1)..'].data.integer;')
+ end
-- accept empty lua tables as empty dictionarys
if rt:match('^Dictionary') then
output:write('\n } else if (args.items['..(j - 1)..'].type == kObjectTypeArray && args.items['..(j - 1)..'].data.array.size == 0) {') --luacheck: ignore 631
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<C-r>=TestCompleteMonth()<CR>')
+ 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('<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 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('<PageUP>, <PageDown> works without ui_pum_set_height', function()
source_complete_month()
local month_expected = {
diff --git a/test/unit/eval/typval_spec.lua b/test/unit/eval/typval_spec.lua
index 1651eb9bcc..ea86ccbf1c 100644
--- a/test/unit/eval/typval_spec.lua
+++ b/test/unit/eval/typval_spec.lua
@@ -2026,6 +2026,26 @@ describe('typval.c', function()
alloc_log:check({})
end)
end)
+ describe('float()', function()
+ itp('works', function()
+ local d = dict({test=10})
+ alloc_log:clear()
+ eq({test=10}, dct2tbl(d))
+ eq(OK, lib.tv_dict_add_float(d, 'testt', 3, 1.5))
+ local dis = dict_items(d)
+ alloc_log:check({a.di(dis.tes, 'tes')})
+ eq({test=10, tes=1.5}, dct2tbl(d))
+ eq(FAIL, check_emsg(function() return lib.tv_dict_add_float(d, 'testt', 3, 1.5) end,
+ 'E685: Internal error: hash_add()'))
+ alloc_log:clear()
+ lib.emsg_skip = lib.emsg_skip + 1
+ eq(FAIL, check_emsg(function() return lib.tv_dict_add_float(d, 'testt', 3, 1.5) end,
+ nil))
+ lib.emsg_skip = lib.emsg_skip - 1
+ alloc_log:clear_tmp_allocs()
+ alloc_log:check({})
+ end)
+ end)
describe('str()', function()
itp('works', function()
local d = dict({test=10})