Skip to content

Commit

Permalink
Merge pull request #99 from msgpack/map-proper
Browse files Browse the repository at this point in the history
Add tests for map type
  • Loading branch information
kuenishi committed Sep 17, 2023
2 parents 87a3fb5 + 21c9012 commit 6b544de
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 8 deletions.
1 change: 1 addition & 0 deletions src/msgpack.hrl
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
-type msgpack_term() :: [msgpack_term()] | msgpack_map() |
integer() | float() | boolean() | binary() | string() | {string, string()}.

%% jiffy, jsx would be soon deprecated as the map is now primitive type.
-type format_type() :: jsx|jiffy|map.

-define(DEFAULT_MAP_FORMAT, map).
Expand Down
36 changes: 28 additions & 8 deletions test/prop_msgpack.erl
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ prop_array_primitive() ->
{oneof([fix_array_primitive(), array16_primitive()]), stable_opts()},
pack_and_unpack(Array, Opts)).

prop_map_primitive() ->
?FORALL(
{Map, Opts},
{oneof([fix_map_primitive(), map16_primitive()]), stable_opts()},
pack_and_unpack(Map, Opts)).

prop_msgpack() ->
?FORALL({Obj, Opts},
{msgpack_object(), stable_opts()},
Expand Down Expand Up @@ -101,11 +107,7 @@ pack_and_unpack(Obj, Opts) ->
%%% Generators %%%
stable_opts() ->
% TODO: build property tests on options
oneof([
[],
[{map_format, jiffy}],
[{map_format, jsx}]
]).
[].

null() -> null.

Expand Down Expand Up @@ -148,16 +150,34 @@ primitive_types() ->


container_types() ->
[ fix_array_primitive(), array16_primitive() ].
[ fix_array_primitive(), array16_primitive(),
fix_map_primitive(), map16_primitive() ].

fix_array_primitive() ->
% up to 2^4-1
%% up to 2^4-1
%% TODO: check the first 4 bits be 1001
resize(15, proper_types:list(oneof(primitive_types()))).

array16_primitive() ->
% Up to 2^16-1, but for performance
%% Up to 2^16-1, but for performance
%% TODO: check the first byte be 0xdc (so s 0xdd for array32)
resize(128, proper_types:list(oneof(primitive_types()))).

fix_map_primitive() ->
%% up to 2^4-1
%% TODO: check the first 4 bits be 1000
resize(15,
proper_types:map(
oneof(primitive_types()),
oneof(primitive_types()))).

map16_primitive() ->
%% Up to 2^16-1, but for performance
%% TODO: check the first byte be 0xde (so s 0xdf for map32)
resize(128,
proper_types:map(
oneof(primitive_types()),
oneof(primitive_types()))).

%% TODO: add map
msgpack_object() ->
Expand Down

0 comments on commit 6b544de

Please sign in to comment.