tests/basics: Add tests for int.from_bytes when src has trailing zeros.

The trailing zeros should be truncated from the converted value.
pull/2975/merge
Damien George 2017-04-25 12:07:02 +10:00
rodzic c7aa86ce6f
commit 810133d97d
2 zmienionych plików z 7 dodań i 0 usunięć

Wyświetl plik

@ -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)

Wyświetl plik

@ -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"))