@@ -70,3 +70,28 @@ behaviour_test() ->
7070 Opt = [{ext , ? MODULE }],
7171 Term = {native , {self (), make_ref (), foobar , fun () -> ok end }},
7272 {ok , Term } = msgpack :unpack (msgpack :pack (Term , Opt ), Opt ).
73+
74+
75+ ext_typecode_range_test () ->
76+ % % typecode range from msgpack spec. [-128,-1] is the "reserved"
77+ % % range, [0,127] is the "user-defined" range.
78+ TypecodeMin = - 128 ,
79+ TypecodeMax = 127 ,
80+ Packer = fun ({thing , N }, _ ) ->
81+ {ok , {N , msgpack :pack (N )}}
82+ end ,
83+ Unpacker = fun (_N , Bin , _ ) ->
84+ msgpack :unpack (Bin )
85+ end ,
86+ Opt = [{ext ,{Packer ,Unpacker }}],
87+ % % it should be possible to use an uncontroversial ext type code:
88+ Enc = msgpack :pack ({thing ,1 }, Opt ),
89+ ? assertMatch ({ok , 1 }, msgpack :unpack (Enc , Opt )),
90+ % % it should be possible to use ext typecodes covering the entire
91+ % % range specified in the msgpack specification:
92+ [begin
93+ Encoded = msgpack :pack ({thing , N }, Opt ),
94+ Result = msgpack :unpack (Encoded , Opt ),
95+ ? assertMatch ({ok , N }, Result )
96+ end || N <- lists :seq (TypecodeMin ,TypecodeMax )],
97+ ok .
0 commit comments