mirror of
https://gitea.osmocom.org/sim-card/pysim.git
synced 2026-03-19 20:08:36 +03:00
construct: Add Construct for variable-length int 'GreedyInteger'
We have a number of integers with variable-length encoding, so add a Construct for this. Naming inspired by GreedyBytes. Related to https://github.com/construct/construct/issues/962 Change-Id: Ic6049b74ea3705fda24855f34b4a1d5f2c9327f7
This commit is contained in:
26
tests/test_construct.py
Normal file
26
tests/test_construct.py
Normal file
@@ -0,0 +1,26 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import unittest
|
||||
from pySim.construct import GreedyInteger
|
||||
|
||||
tests = [
|
||||
( b'\x80', 0x80 ),
|
||||
( b'\x80\x01', 0x8001 ),
|
||||
( b'\x80\x00\x01', 0x800001 ),
|
||||
( b'\x80\x23\x42\x01', 0x80234201 ),
|
||||
]
|
||||
|
||||
class TestGreedyInt(unittest.TestCase):
|
||||
def test_GreedyInt_decoder(self):
|
||||
gi = GreedyInteger()
|
||||
for t in tests:
|
||||
self.assertEqual(gi.parse(t[0]), t[1])
|
||||
def test_GreedyInt_encoder(self):
|
||||
gi = GreedyInteger()
|
||||
for t in tests:
|
||||
self.assertEqual(t[0], gi.build(t[1]))
|
||||
pass
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user