mirror of
https://github.com/neovim/neovim.git
synced 2024-12-24 13:15:09 -07:00
a141f6e922
Problem: 1. "unpack" has an unrelated meaning in Lua: https://www.lua.org/manual/5.1/manual.html#pdf-unpack 2. We already have msgpackparse()/msgpackdump() and json_encode()/json_decode(), so introducing another name for the same thing is entropy. Solution: - Rename vim.mpack.pack/unpack => vim.mpack.encode/decode Caveat: This is incongruent with the `Unpacker` and `Packer` functions. - It's probably too invasive to rename those. - They also aren't part of our documented interface. - This commit is "reversible" in the sense that we can always revert it and add `vim.mpack.encode/decode` as _aliases_ to `vim.mpack.pack/unpack`, at any time in the future, if we want stricter fidelity with upstream libmpack. Meanwhile, `vim.mpack.encode/decode` is currently the total _documented_ interface of `vim.mpack`, so this change serves the purpose of consistent naming in the Nvim stdlib.
24 lines
766 B
Lua
24 lines
766 B
Lua
-- Test suite for testing interactions with API bindings
|
|
local helpers = require('test.functional.helpers')(after_each)
|
|
|
|
local clear = helpers.clear
|
|
local eq = helpers.eq
|
|
local exec_lua = helpers.exec_lua
|
|
|
|
describe('lua vim.mpack', function()
|
|
before_each(clear)
|
|
it('encodes vim.NIL', function()
|
|
eq({true, true, true, true}, exec_lua [[
|
|
local var = vim.mpack.decode(vim.mpack.encode({33, vim.NIL, 77}))
|
|
return {var[1]==33, var[2]==vim.NIL, var[3]==77, var[4]==nil}
|
|
]])
|
|
end)
|
|
|
|
it('encodes vim.empty_dict()', function()
|
|
eq({{{}, "foo", {}}, true, false}, exec_lua [[
|
|
local var = vim.mpack.decode(vim.mpack.encode({{}, "foo", vim.empty_dict()}))
|
|
return {var, vim.tbl_islist(var[1]), vim.tbl_islist(var[3])}
|
|
]])
|
|
end)
|
|
end)
|