eval/decode: Make msgpackparse() function use new v: vars

This commit is contained in:
ZyX 2016-02-03 20:04:16 +03:00
parent ed6756563c
commit cddd7d47c3
3 changed files with 15 additions and 24 deletions

View File

@ -4907,9 +4907,13 @@ msgpackparse({list}) {Nvim} *msgpackparse()*
contains name of the key from |v:msgpack_types|):
Key Value ~
nil Zero, ignored when dumping.
boolean One or zero. When dumping it is only checked that
value is a |Number|.
nil Zero, ignored when dumping. This value cannot
possibly appear in |msgpackparse()| output in Neovim
versions which have |v:null|.
boolean One or zero. When dumping it is only checked that
value is a |Number|. This value cannot possibly
appear in |msgpackparse()| output in Neovim versions
which have |v:true| and |v:false|.
integer |List| with four numbers: sign (-1 or 1), highest two
bits, number with bits from 62nd to 31st, lowest 31
bits. I.e. to get actual number one will need to use

View File

@ -551,21 +551,11 @@ int msgpack_to_vim(const msgpack_object mobj, typval_T *const rettv)
{
switch (mobj.type) {
case MSGPACK_OBJECT_NIL: {
create_special_dict(rettv, kMPNil, ((typval_T) {
.v_type = VAR_NUMBER,
.v_lock = 0,
.vval = { .v_number = 0 },
}));
*rettv = get_vim_var_tv(VV_NULL);
break;
}
case MSGPACK_OBJECT_BOOLEAN: {
create_special_dict(rettv, kMPBoolean, ((typval_T) {
.v_type = VAR_NUMBER,
.v_lock = 0,
.vval = {
.v_number = (varnumber_T) mobj.via.boolean,
},
}));
*rettv = get_vim_var_tv(mobj.via.boolean ? VV_TRUE : VV_FALSE);
break;
}
case MSGPACK_OBJECT_POSITIVE_INTEGER: {

View File

@ -393,25 +393,22 @@ end)
describe('msgpackparse() function', function()
before_each(clear)
it('restores nil as special dict', function()
it('restores nil as v:null', function()
execute('let dumped = ["\\xC0"]')
execute('let parsed = msgpackparse(dumped)')
eq({{_TYPE={}, _VAL=0}}, eval('parsed'))
eq(1, eval('g:parsed[0]._TYPE is v:msgpack_types.nil'))
eq('[v:null]', eval('string(parsed)'))
end)
it('restores boolean false as zero', function()
it('restores boolean false as v:false', function()
execute('let dumped = ["\\xC2"]')
execute('let parsed = msgpackparse(dumped)')
eq({{_TYPE={}, _VAL=0}}, eval('parsed'))
eq(1, eval('g:parsed[0]._TYPE is v:msgpack_types.boolean'))
eq({false}, eval('parsed'))
end)
it('restores boolean true as one', function()
it('restores boolean true as v:true', function()
execute('let dumped = ["\\xC3"]')
execute('let parsed = msgpackparse(dumped)')
eq({{_TYPE={}, _VAL=1}}, eval('parsed'))
eq(1, eval('g:parsed[0]._TYPE is v:msgpack_types.boolean'))
eq({true}, eval('parsed'))
end)
it('restores FIXSTR as special dict', function()