diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/arithm/tarithm.nim | 1 | ||||
-rw-r--r-- | tests/misc/tlowhigh.nim | 14 | ||||
-rw-r--r-- | tests/range/tcompiletime_range_checks.nim | 52 | ||||
-rw-r--r-- | tests/stdlib/tbitops.nim | 14 | ||||
-rw-r--r-- | tests/vm/ttouintconv.nim | 4 | ||||
-rw-r--r-- | tests/vm/tzero_extend.nim | 6 |
6 files changed, 79 insertions, 12 deletions
diff --git a/tests/arithm/tarithm.nim b/tests/arithm/tarithm.nim index a79f897a7..4625a5ecf 100644 --- a/tests/arithm/tarithm.nim +++ b/tests/arithm/tarithm.nim @@ -54,6 +54,7 @@ block tcast: crossCheck(uint16, uint16.high + 5'u16) crossCheck(uint32, uint32.high + 5'u32) crossCheck(uint64, 0xFFFFFFFFFFFFFFFF'u64 + 5'u64) + crossCheck(uint64, uint64.high + 5'u64) doAssert $sub1(0'u8) == "255" doAssert $sub1(0'u16) == "65535" diff --git a/tests/misc/tlowhigh.nim b/tests/misc/tlowhigh.nim index 76f298a4a..6ae871255 100644 --- a/tests/misc/tlowhigh.nim +++ b/tests/misc/tlowhigh.nim @@ -1,5 +1,12 @@ discard """ action: run + output: ''' +18446744073709551615 +9223372036854775807 +4294967295 +0 +0 +''' """ var x: range[-1'f32..1'f32] @@ -16,3 +23,10 @@ doAssert y.type.high == 1'f64 # bug #11972 var num: uint8 doAssert num.high.float == 255.0 + +echo high(uint64) +echo high(int64) +echo high(uint32) + +echo low(uint64) +echo low(uint32) diff --git a/tests/range/tcompiletime_range_checks.nim b/tests/range/tcompiletime_range_checks.nim new file mode 100644 index 000000000..37095e0b7 --- /dev/null +++ b/tests/range/tcompiletime_range_checks.nim @@ -0,0 +1,52 @@ +discard """ + cmd: "nim check --hint[Processing]:off --hint[Conf]:off $file" + errormsg: "18446744073709551615 can't be converted to int8" + nimout: '''tcompiletime_range_checks.nim(36, 21) Error: 2147483648 can't be converted to int32 +tcompiletime_range_checks.nim(37, 23) Error: -1 can't be converted to uint64 +tcompiletime_range_checks.nim(38, 34) Error: 255 can't be converted to FullNegativeRange +tcompiletime_range_checks.nim(39, 34) Error: 18446744073709551615 can't be converted to HalfNegativeRange +tcompiletime_range_checks.nim(40, 34) Error: 300 can't be converted to FullPositiveRange +tcompiletime_range_checks.nim(41, 30) Error: 101 can't be converted to UnsignedRange +tcompiletime_range_checks.nim(42, 32) Error: -9223372036854775808 can't be converted to SemiOutOfBounds +tcompiletime_range_checks.nim(44, 22) Error: nan can't be converted to int32 +tcompiletime_range_checks.nim(46, 23) Error: 1e+100 can't be converted to uint64 +tcompiletime_range_checks.nim(49, 22) Error: 18446744073709551615 can't be converted to int64 +tcompiletime_range_checks.nim(50, 22) Error: 18446744073709551615 can't be converted to int32 +tcompiletime_range_checks.nim(51, 22) Error: 18446744073709551615 can't be converted to int16 +tcompiletime_range_checks.nim(52, 21) Error: 18446744073709551615 can't be converted to int8 + ''' +""" + +type + UnsignedRange* = range[0'u64 .. 100'u64] + SemiOutOfBounds* = range[0x7ffffffffffffe00'u64 .. 0x8000000000000100'u64] + FullOutOfBounds* = range[0x8000000000000000'u64 .. 0x8000000000000200'u64] + + FullNegativeRange* = range[-200 .. -100] + HalfNegativeRange* = range[-50 .. 50] + FullPositiveRange* = range[100 .. 200] + +let acceptA* = int32(0x7fffffff'i64) +let acceptB* = (uint64(0'i64)) +let acceptD* = (HalfNegativeRange(25'u64)) +let acceptE* = (UnsignedRange(50'u64)) +let acceptF* = (SemiOutOfBounds(0x7ffffffffffffe00'i64)) +let acceptH* = (SemiOutOfBounds(0x8000000000000000'u64)) + +let rejectA* = int32(0x80000000'i64) +let rejectB* = (uint64(-1'i64)) +let rejectC* = (FullNegativeRange(0xff'u32)) +let rejectD* = (HalfNegativeRange(0xffffffffffffffff'u64)) # internal `intVal` is `-1` which would be in range. +let rejectE* = (FullPositiveRange(300'u64)) +let rejectF* = (UnsignedRange(101'u64)) +let rejectG* = (SemiOutOfBounds(0x8000000000000000'i64)) # + +let rejectH* = (int32(NaN)) +let rejectI* = (int64(1e100)) +let rejectJ* = (uint64(1e100)) + +# removed cross checks from tarithm.nim +let rejectK* = (int64(0xFFFFFFFFFFFFFFFF'u64)) +let rejectL* = (int32(0xFFFFFFFFFFFFFFFF'u64)) +let rejectM* = (int16(0xFFFFFFFFFFFFFFFF'u64)) +let rejectN* = (int8(0xFFFFFFFFFFFFFFFF'u64)) diff --git a/tests/stdlib/tbitops.nim b/tests/stdlib/tbitops.nim index b2393b755..e4461345e 100644 --- a/tests/stdlib/tbitops.nim +++ b/tests/stdlib/tbitops.nim @@ -211,15 +211,15 @@ proc main() = proc testReverseBitsPerType(x, reversed: uint64) = doAssert reverseBits(x) == reversed - doAssert reverseBits(uint32(x)) == uint32(reversed shr 32) - doAssert reverseBits(uint32(x shr 16)) == uint32(reversed shr 16) - doAssert reverseBits(uint16(x)) == uint16(reversed shr 48) - doAssert reverseBits(uint8(x)) == uint8(reversed shr 56) + doAssert reverseBits(cast[uint32](x)) == cast[uint32](reversed shr 32) + doAssert reverseBits(cast[uint32](x shr 16)) == cast[uint32](reversed shr 16) + doAssert reverseBits(cast[uint16](x)) == cast[uint16](reversed shr 48) + doAssert reverseBits(cast[uint8](x)) == cast[uint8](reversed shr 56) testReverseBitsInvo(x) - testReverseBitsInvo(uint32(x)) - testReverseBitsInvo(uint16(x)) - testReverseBitsInvo(uint8(x)) + testReverseBitsInvo(cast[uint32](x)) + testReverseBitsInvo(cast[uint16](x)) + testReverseBitsInvo(cast[uint8](x)) proc testReverseBitsRefl(x, reversed: uint64) = testReverseBitsPerType(x, reversed) diff --git a/tests/vm/ttouintconv.nim b/tests/vm/ttouintconv.nim index 403de8f41..ff2187a36 100644 --- a/tests/vm/ttouintconv.nim +++ b/tests/vm/ttouintconv.nim @@ -69,8 +69,8 @@ macro foo2() = echo zz var ww = -9 - var vv = ww.uint - var kk = vv.uint32 + var vv = cast[uint](ww) + var kk = cast[uint32](vv) echo kk foo() diff --git a/tests/vm/tzero_extend.nim b/tests/vm/tzero_extend.nim index 76aa9ee67..1fed5d419 100644 --- a/tests/vm/tzero_extend.nim +++ b/tests/vm/tzero_extend.nim @@ -18,9 +18,9 @@ proc get_values(): (seq[int8], seq[int16], seq[int32]) = let i32 = -(1'i64 shl 33) + offset # higher bits are masked. these should be exactly equal to offset. - result[0].add cast[int8 ](uint8 cast[uint64](i8 )) - result[1].add cast[int16](uint16 cast[uint64](i16)) - result[2].add cast[int32](uint32 cast[uint64](i32)) + result[0].add cast[int8](cast[uint64](i8)) + result[1].add cast[int16](cast[uint64](i16)) + result[2].add cast[int32](cast[uint64](i32)) # these values this computed by VM |