mirror of
https://github.com/neovim/neovim.git
synced 2025-09-18 09:18:19 +00:00
feat(api): convert Blobs to API strings
Note that these are not NUL-terminated; the API supports this.
This commit is contained in:
@@ -445,7 +445,14 @@ void set_option_to(uint64_t channel_id, void *to, int type,
|
||||
TYPVAL_ENCODE_CONV_NIL(tv)
|
||||
|
||||
#define TYPVAL_ENCODE_CONV_BLOB(tv, blob, len) \
|
||||
abort() /* TODO(seandewar) */ \
|
||||
do { \
|
||||
const size_t len_ = (size_t)(len); \
|
||||
const blob_T *const blob_ = (blob); \
|
||||
kvi_push(edata->stack, STRING_OBJ(((String) { \
|
||||
.data = len_ != 0 ? xmemdup(blob_->bv_ga.ga_data, len_) : NULL, \
|
||||
.size = len_ \
|
||||
}))); \
|
||||
} while (0)
|
||||
|
||||
#define TYPVAL_ENCODE_CONV_FUNC_START(tv, fun) \
|
||||
do { \
|
||||
|
@@ -155,4 +155,13 @@ describe('eval-API', function()
|
||||
pcall_err(command, "sandbox call nvim_input('ievil')"))
|
||||
eq({''}, meths.buf_get_lines(0, 0, -1, true))
|
||||
end)
|
||||
|
||||
it('converts blobs to API strings', function()
|
||||
command('let g:v1 = nvim__id(0z68656c6c6f)')
|
||||
command('let g:v2 = nvim__id(v:_null_blob)')
|
||||
eq(1, eval('type(g:v1)'))
|
||||
eq(1, eval('type(g:v2)'))
|
||||
eq('hello', eval('g:v1'))
|
||||
eq('', eval('g:v2'))
|
||||
end)
|
||||
end)
|
||||
|
@@ -64,6 +64,7 @@ describe('luaeval(vim.api.…)', function()
|
||||
it('correctly converts from API objects', function()
|
||||
eq(1, funcs.luaeval('vim.api.nvim_eval("1")'))
|
||||
eq('1', funcs.luaeval([[vim.api.nvim_eval('"1"')]]))
|
||||
eq('Blobby', funcs.luaeval('vim.api.nvim_eval("0z426c6f626279")'))
|
||||
eq({}, funcs.luaeval('vim.api.nvim_eval("[]")'))
|
||||
eq({}, funcs.luaeval('vim.api.nvim_eval("{}")'))
|
||||
eq(1, funcs.luaeval('vim.api.nvim_eval("1.0")'))
|
||||
@@ -73,6 +74,7 @@ describe('luaeval(vim.api.…)', function()
|
||||
|
||||
eq(0, eval([[type(luaeval('vim.api.nvim_eval("1")'))]]))
|
||||
eq(1, eval([[type(luaeval('vim.api.nvim_eval("''1''")'))]]))
|
||||
eq(1, eval([[type(luaeval('vim.api.nvim_eval("0zbeef")'))]]))
|
||||
eq(3, eval([[type(luaeval('vim.api.nvim_eval("[]")'))]]))
|
||||
eq(4, eval([[type(luaeval('vim.api.nvim_eval("{}")'))]]))
|
||||
eq(5, eval([[type(luaeval('vim.api.nvim_eval("1.0")'))]]))
|
||||
|
Reference in New Issue
Block a user