add tests for recently closed issues (#10722)

This commit is contained in:
Miran 2019-02-23 10:41:35 +01:00 • committed by Andreas Rumpf
commit e7878c0d08
9 changed files with 177 additions and 1 deletions

19
tests/misc/tsizeof3.nim Normal file
View file

@ -0,0 +1,19 @@
discard """
output: '''
[0, 0, 0, 0, 0, 0, 48, 57]
'''
"""
# bug #7238
type ByteArrayBE*[N: static[int]] = array[N, byte]
## A byte array that stores bytes in big-endian order
proc toByteArrayBE*[T: SomeInteger](num: T): ByteArrayBE[sizeof(T)]=
## Convert an integer (in native host endianness) to a big-endian byte array
## Notice the result type
const N = T.sizeof
for i in 0 ..< N:
result[i] = byte(num shr ((N-1-i) * 8))
let a = 12345.toByteArrayBE
echo a

View file

@ -39,3 +39,7 @@ var n32 = ar[v32]
var n64 = ar[v64]
block t4176:
var yyy: uint8 = 0
yyy = yyy - 127
doAssert type(yyy) is uint8

View file

@ -26,3 +26,9 @@ block:
var x = 123'u16
x -= 125
doAssert(x == 65534'u16)
block t4175:
let i = 0u - 1u
const j = 0u - 1u
doAssert i == j
doAssert j + 1u == 0u