aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorHarald Welte <laforge@osmocom.org>2022-02-11 18:05:48 +0100
committerHarald Welte <laforge@osmocom.org>2022-02-14 00:41:24 +0100
commitd0519e0c372b07947f005dd0f110277b81253e78 (patch)
tree331b3edea3369c7d1061df796bc88049e6aa4cea /tests
parente8d177d88f89db216362284533d6e7ed27f9382a (diff)
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
Diffstat (limited to 'tests')
-rw-r--r--tests/test_construct.py26
1 files changed, 26 insertions, 0 deletions
diff --git a/tests/test_construct.py b/tests/test_construct.py
new file mode 100644
index 0000000..ad409b1
--- /dev/null
+++ b/tests/test_construct.py
@@ -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()