summaryrefslogtreecommitdiffstatshomepage
path: root/tests/basics/struct2.py
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2016-05-28 23:27:38 +0100
committerDamien George <damien.p.george@gmail.com>2016-05-28 23:27:38 +0100
commit715ee9d925871f2c44632442ff42cb58c99ee9c7 (patch)
tree539bc75e65a8b20ac8c4110fa7a878266d05cd88 /tests/basics/struct2.py
parent282d81a40e275bcb4502a7eb5b3f2ae0cfcb08fc (diff)
downloadmicropython-715ee9d925871f2c44632442ff42cb58c99ee9c7.tar.gz
micropython-715ee9d925871f2c44632442ff42cb58c99ee9c7.zip
py/modstruct: Allow to have "0s" in struct format.
Diffstat (limited to 'tests/basics/struct2.py')
-rw-r--r--tests/basics/struct2.py28
1 files changed, 28 insertions, 0 deletions
diff --git a/tests/basics/struct2.py b/tests/basics/struct2.py
new file mode 100644
index 0000000000..f438bb55d2
--- /dev/null
+++ b/tests/basics/struct2.py
@@ -0,0 +1,28 @@
+# test ustruct with a count specified before the type
+
+try:
+ import ustruct as struct
+except:
+ import struct
+
+print(struct.calcsize('0s'))
+print(struct.unpack('0s', b''))
+print(struct.pack('0s', b'123'))
+
+print(struct.calcsize('2s'))
+print(struct.unpack('2s', b'12'))
+print(struct.pack('2s', b'123'))
+
+print(struct.calcsize('2H'))
+print(struct.unpack('<2H', b'1234'))
+print(struct.pack('<2H', 258, 515))
+
+print(struct.calcsize('0s1s0H2H'))
+print(struct.unpack('<0s1s0H2H', b'01234'))
+print(struct.pack('<0s1s0H2H', b'abc', b'abc', 258, 515))
+
+# check that zero of an unknown type raises an exception
+try:
+ struct.calcsize('0z')
+except:
+ print('Exception')