Skip to content

Commit 985d4c1

Browse files
committed
add a test for unpacking extended types
1 parent ff85838 commit 985d4c1

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

test/test_extension.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,28 @@ def p(s):
1616
assert p('A'*0x0123) == '\xc8\x01\x23\x42' + 'A'*0x0123 # ext 16
1717
assert p('A'*0x00012345) == '\xc9\x00\x01\x23\x45\x42' + 'A'*0x00012345 # ext 32
1818

19+
def test_unpack_extended_type():
20+
class MyUnpacker(msgpack.Unpacker):
21+
def read_extended_type(self, typecode, data):
22+
return (typecode, data)
23+
24+
def u(s):
25+
unpacker = MyUnpacker()
26+
unpacker.feed(s)
27+
return unpacker.unpack_one()
28+
29+
assert u('\xd4\x42A') == (0x42, 'A') # fixext 1
30+
assert u('\xd5\x42AB') == (0x42, 'AB') # fixext 2
31+
assert u('\xd6\x42ABCD') == (0x42, 'ABCD') # fixext 4
32+
assert u('\xd7\x42ABCDEFGH') == (0x42, 'ABCDEFGH') # fixext 8
33+
assert u('\xd8\x42' + 'A'*16) == (0x42, 'A'*16) # fixext 16
34+
assert u('\xc7\x03\x42ABC') == (0x42, 'ABC') # ext 8
35+
assert (u('\xc8\x01\x23\x42' + 'A'*0x0123) ==
36+
(0x42, 'A'*0x0123)) # ext 16
37+
assert (u('\xc9\x00\x01\x23\x45\x42' + 'A'*0x00012345) ==
38+
(0x42, 'A'*0x00012345)) # ext 32
39+
40+
1941
def test_extension_type():
2042
class MyPacker(msgpack.Packer):
2143
def handle_unknown_type(self, obj):

0 commit comments

Comments
 (0)