diff options
| author | Damien George | 2017-04-25 12:07:02 +1000 |
|---|---|---|
| committer | Damien George | 2017-04-25 12:07:02 +1000 |
| commit | 810133d97d4391151e86af90508222c480f362b7 (patch) | |
| tree | 883486ed31822c2b6b2311ced03ce52bb6e92d18 | |
| parent | c7aa86ce6f17f52aadff898b79c95d968da6bfa2 (diff) | |
tests/basics: Add tests for int.from_bytes when src has trailing zeros.
The trailing zeros should be truncated from the converted value.
| -rw-r--r-- | tests/basics/int_bytes.py | 4 | ||||
| -rw-r--r-- | tests/basics/int_bytes_intbig.py | 3 |
2 files changed, 7 insertions, 0 deletions
diff --git a/tests/basics/int_bytes.py b/tests/basics/int_bytes.py index 45965ed46..93c00bba1 100644 --- a/tests/basics/int_bytes.py +++ b/tests/basics/int_bytes.py @@ -4,3 +4,7 @@ print((100).to_bytes(10, "little")) print(int.from_bytes(b"\x00\x01\0\0\0\0\0\0", "little")) print(int.from_bytes(b"\x01\0\0\0\0\0\0\0", "little")) print(int.from_bytes(b"\x00\x01\0\0\0\0\0\0", "little")) + +# check that extra zero bytes don't change the internal int value +print(int.from_bytes(bytes(20), "little") == 0) +print(int.from_bytes(b"\x01" + bytes(20), "little") == 1) diff --git a/tests/basics/int_bytes_intbig.py b/tests/basics/int_bytes_intbig.py index 39cd67d26..0e0ad1cbb 100644 --- a/tests/basics/int_bytes_intbig.py +++ b/tests/basics/int_bytes_intbig.py @@ -7,3 +7,6 @@ ib = int.from_bytes(b, "big") print(il) print(ib) print(il.to_bytes(20, "little")) + +# check that extra zero bytes don't change the internal int value +print(int.from_bytes(b + bytes(10), "little") == int.from_bytes(b, "little")) |
