Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add varint and varlong tests #142

Merged
merged 1 commit into from
Sep 18, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
31 changes: 31 additions & 0 deletions tests/mcp/test_datautils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from spock.mcp import datautils
from spock.utils import BoundBuffer


def test_unpack_varint():
largebuff = BoundBuffer(b'\x80\x94\xeb\xdc\x03')
smallbuff = BoundBuffer(b'\x14')
assert datautils.unpack_varint(smallbuff) == 20
assert datautils.unpack_varint(largebuff) == 1000000000


def test_pack_varint():
assert datautils.pack_varint(20) == b'\x14'
assert datautils.pack_varint(1000000000) == b'\x80\x94\xeb\xdc\x03'
assert datautils.pack_varint(-10000000000) is None
assert datautils.pack_varint(10000000000) is None


def test_unpack_varlong():
largebuff = BoundBuffer(b'\x80\xc8\xaf\xa0%')
smallbuff = BoundBuffer(b'\x14')
assert datautils.unpack_varlong(smallbuff) == 20
assert datautils.unpack_varlong(largebuff) == 10000000000
pass


def test_pack_varlong():
assert datautils.pack_varlong(20) == b'\x14'
assert datautils.pack_varlong(10000000000) == b'\x80\xc8\xaf\xa0%'
assert datautils.pack_varlong(10000000000000000000) is None
assert datautils.pack_varlong(-10000000000000000000) is None