diff options
| author | chico ferreira <36338391+chicoferreira@users.noreply.github.com> | 2024-07-22 13:10:59 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-07-22 12:10:59 +0000 |
| commit | bd72b95d9e8d5c05f5a7392dab00d9db34534565 (patch) | |
| tree | 36030ab53019f76275e9b61bd3bed2ecb678fca7 /tests/suite | |
| parent | 9b001e21121ab7b5645aa36f0cdcb6ac57e03a2b (diff) | |
Conversion from int to bytes and back (#4490)
Co-authored-by: Laurenz <laurmaedje@gmail.com>
Diffstat (limited to 'tests/suite')
| -rw-r--r-- | tests/suite/foundations/int.typ | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/tests/suite/foundations/int.typ b/tests/suite/foundations/int.typ index 0c85dcab..1744ef88 100644 --- a/tests/suite/foundations/int.typ +++ b/tests/suite/foundations/int.typ @@ -38,6 +38,24 @@ #test(int(10.0).signum(), 1) #test(int(-10.0).signum(), -1) +--- int-from-and-to-bytes --- +// Test `int.from-bytes` and `int.to-bytes`. +#test(int.from-bytes(bytes(())), 0) +#test(int.from-bytes(bytes((1, 0, 0, 0, 0, 0, 0, 0)), endian: "little", signed: true), 1) +#test(int.from-bytes(bytes((1, 0, 0, 0, 0, 0, 0, 0)), endian: "big", signed: true), 72057594037927936) +#test(int.from-bytes(bytes((1, 0, 0, 0, 0, 0, 0, 0)), endian: "little", signed: false), 1) +#test(int.from-bytes(bytes((255,)), endian: "big", signed: true), -1) +#test(int.from-bytes(bytes((255,)), endian: "big", signed: false), 255) +#test(int.from-bytes((-1000).to-bytes(endian: "big", size: 5), endian: "big", signed: true), -1000) +#test(int.from-bytes((-1000).to-bytes(endian: "little", size: 5), endian: "little", signed: true), -1000) +#test(int.from-bytes(1000.to-bytes(endian: "big", size: 5), endian: "big", signed: true), 1000) +#test(int.from-bytes(1000.to-bytes(endian: "little", size: 5), endian: "little", signed: true), 1000) +#test(int.from-bytes(1000.to-bytes(endian: "little", size: 5), endian: "little", signed: false), 1000) + +--- int-from-and-to-bytes-too-many --- +// Error: 2-34 too many bytes to convert to a 64 bit number +#int.from-bytes(bytes((0,) * 16)) + --- int-repr --- // Test the `repr` function with integers. #repr(12) \ |
