mirror of
https://github.com/msgpack/msgpack-c.git
synced 2025-10-28 11:31:55 +01:00
erlang: unpack_map's silly bug fixed. use dict:store/3....
This commit is contained in:
@@ -195,7 +195,7 @@ unpack_map_(Bin, Len, Dict) when is_binary(Bin) and is_integer(Len) ->
|
|||||||
case unpack(Rest) of
|
case unpack(Rest) of
|
||||||
{more, MoreLen} -> { more, MoreLen+Len-1 };
|
{more, MoreLen} -> { more, MoreLen+Len-1 };
|
||||||
{ Value, Rest2 }->
|
{ Value, Rest2 }->
|
||||||
unpack_map_(Rest2,Len-1,dict:append(Key,Value,Dict))
|
unpack_map_(Rest2,Len-1,dict:store(Key,Value,Dict))
|
||||||
end
|
end
|
||||||
end.
|
end.
|
||||||
|
|
||||||
@@ -352,7 +352,7 @@ test_data()->
|
|||||||
-1, -23, -512, -1230, -567898, -16#FFFFFFFFFF,
|
-1, -23, -512, -1230, -567898, -16#FFFFFFFFFF,
|
||||||
123.123, -234.4355, 1.0e-34, 1.0e64,
|
123.123, -234.4355, 1.0e-34, 1.0e64,
|
||||||
[23, 234, 0.23],
|
[23, 234, 0.23],
|
||||||
"hogehoge", "243546rf7g68h798j",
|
<<"hogehoge">>, <<"243546rf7g68h798j", 0, 23, 255>>,
|
||||||
<<"hoasfdafdas][">>,
|
<<"hoasfdafdas][">>,
|
||||||
[0,42,"sum", [1,2]], [1,42, nil, [3]]
|
[0,42,"sum", [1,2]], [1,42, nil, [3]]
|
||||||
].
|
].
|
||||||
@@ -387,34 +387,31 @@ partial_test()-> % error handling test.
|
|||||||
[test_p(X, Term, Bin, BinLen) || X <- lists:seq(0,BinLen)].
|
[test_p(X, Term, Bin, BinLen) || X <- lists:seq(0,BinLen)].
|
||||||
|
|
||||||
long_test()->
|
long_test()->
|
||||||
Longer = lists:seq(0, 65), %55),
|
Longer = lists:seq(0, 655),
|
||||||
% Longest = lists:seq(0,12345),
|
% Longest = lists:seq(0,12345),
|
||||||
{Longer, <<>>} = msgpack:unpack(msgpack:pack(Longer)),
|
{Longer, <<>>} = msgpack:unpack(msgpack:pack(Longer)),
|
||||||
% {Longest, <<>>} = msgpack:unpack(msgpack:pack(Longest)).
|
% {Longest, <<>>} = msgpack:unpack(msgpack:pack(Longest)).
|
||||||
ok.
|
ok.
|
||||||
|
|
||||||
map_test()->
|
map_test()->
|
||||||
Ints = lists:seq(0, 65), %55),
|
Ints = lists:seq(0, 65),
|
||||||
Map = dict:from_list([ {X, X*2} || X <- Ints ]),
|
Map = dict:from_list([ {X, X*2} || X <- Ints ]),
|
||||||
S=msgpack:pack(Map),
|
{Map2, <<>>} = msgpack:unpack(msgpack:pack(Map)),
|
||||||
% ?debugVal(msgpack:unpack(S)),
|
|
||||||
{Map2, <<>>} = msgpack:unpack(S),
|
|
||||||
?assertEqual(dict:size(Map), dict:size(Map2)),
|
?assertEqual(dict:size(Map), dict:size(Map2)),
|
||||||
% ?debugVal(dict:to_list(Map2)),
|
|
||||||
OrdMap = orddict:from_list( dict:to_list(Map) ),
|
OrdMap = orddict:from_list( dict:to_list(Map) ),
|
||||||
OrdMap2 = orddict:from_list( dict:to_list(Map2) ),
|
OrdMap2 = orddict:from_list( dict:to_list(Map2) ),
|
||||||
% ?assertEqual(OrdMap, OrdMap2), % FIXME!! its a misery bug.
|
?assertEqual(OrdMap, OrdMap2),
|
||||||
%% {Longest, <<>>} = msgpack:unpack(msgpack:pack(Longest)).
|
|
||||||
ok.
|
ok.
|
||||||
|
|
||||||
unknown_test()->
|
unknown_test()->
|
||||||
Tests = [0, 1, 2, 123, 512, 1230, 678908,
|
Tests = [0, 1, 2, 123, 512, 1230, 678908,
|
||||||
-1, -23, -512, -1230, -567898,
|
-1, -23, -512, -1230, -567898,
|
||||||
<<"hogehoge">>, <<"243546rf7g68h798j">>,
|
<<"hogehoge">>, <<"243546rf7g68h798j">>,
|
||||||
% 123.123, %FIXME
|
123.123,
|
||||||
% -234.4355, 1.0e-34, 1.0e64, % FIXME
|
-234.4355, 1.0e-34, 1.0e64,
|
||||||
[23, 234, 0.23],
|
[23, 234, 0.23],
|
||||||
[0,42,<<"sum">>, [1,2]], [1,42, nil, [3]],
|
[0,42,<<"sum">>, [1,2]], [1,42, nil, [3]],
|
||||||
|
dict:from_list([{1,2},{<<"hoge">>,nil}]),
|
||||||
42
|
42
|
||||||
],
|
],
|
||||||
Port = open_port({spawn, "ruby testcase_generator.rb"}, [binary]),
|
Port = open_port({spawn, "ruby testcase_generator.rb"}, [binary]),
|
||||||
@@ -428,7 +425,6 @@ test_([]) -> 0;
|
|||||||
test_([S|Rest])->
|
test_([S|Rest])->
|
||||||
Pack = msgpack:pack(S),
|
Pack = msgpack:pack(S),
|
||||||
{S, <<>>} = msgpack:unpack( Pack ),
|
{S, <<>>} = msgpack:unpack( Pack ),
|
||||||
% ?debugVal( hoge ),
|
|
||||||
1+test_(Rest).
|
1+test_(Rest).
|
||||||
|
|
||||||
other_test()->
|
other_test()->
|
||||||
|
|||||||
@@ -40,10 +40,11 @@ end
|
|||||||
objs = [0, 1, 2, 123, 512, 1230, 678908,
|
objs = [0, 1, 2, 123, 512, 1230, 678908,
|
||||||
-1, -23, -512, -1230, -567898,
|
-1, -23, -512, -1230, -567898,
|
||||||
"hogehoge", "243546rf7g68h798j",
|
"hogehoge", "243546rf7g68h798j",
|
||||||
# 123.123 , #FIXME
|
123.123,
|
||||||
# -234.4355, 1.0e-34, 1.0e64,
|
-234.4355, 1.0e-34, 1.0e64,
|
||||||
[23, 234, 0.23],
|
[23, 234, 0.23],
|
||||||
[0,42,"sum", [1,2]], [1,42, nil, [3]],
|
[0,42,"sum", [1,2]], [1,42, nil, [3]],
|
||||||
|
{ 1 => 2, "hoge" => nil },
|
||||||
42
|
42
|
||||||
]
|
]
|
||||||
begin
|
begin
|
||||||
|
|||||||
Reference in New Issue
Block a user