summary refs log tree commit diff stats
path: root/tests/range
diff options
context:
space:
mode:
authorAraq <rumpf_a@web.de>2019-09-02 10:27:33 +0200
committerAraq <rumpf_a@web.de>2019-09-02 10:27:33 +0200
commite6ec88d4c39c458404061198b2a2f6b86c2caeaf (patch)
tree7238ba2a2e124abe4eaf7e1d3e84db6b37a8758b /tests/range
parentab8241ad42635693df8a50326ebb24d52343059a (diff)
downloadNim-e6ec88d4c39c458404061198b2a2f6b86c2caeaf.tar.gz
renamed and moved test
Diffstat (limited to 'tests/range')
-rw-r--r--tests/range/tcompiletime_range_checks.nim42
1 files changed, 42 insertions, 0 deletions
diff --git a/tests/range/tcompiletime_range_checks.nim b/tests/range/tcompiletime_range_checks.nim
new file mode 100644
index 000000000..ea61fd88d
--- /dev/null
+++ b/tests/range/tcompiletime_range_checks.nim
@@ -0,0 +1,42 @@
+template reject(e) =
+  static: assert(not compiles(e))
+
+template accept(e) =
+  static: assert(compiles(e))
+
+type
+  UnsignedRange   = 0'u64 .. 100'u64
+  SemiOutOfBounds = 0x7ffffffffffffe00'u64 .. 0x8000000000000100'u64
+  FullOutOfBounds = 0x8000000000000000'u64 .. 0x8000000000000200'u64
+
+  FullNegativeRange = -200 .. -100
+  HalfNegativeRange = -50 .. 50
+  FullPositiveRange = 100 .. 200
+
+reject(int32(0x80000000'i64))
+accept(int32(0x7fffffff'i64))
+
+reject(uint64(-1'i64))
+accept(uint64(0'i64))
+
+reject(FullNegativeRange(0xff'u32))
+reject(HalfNegativeRange(0xffffffffffffffff'u64)) # internal `intVal` is `-1` which would be in range.
+accept(HalfNegativeRange(25'u64))
+reject(FullPositiveRange(300'u64))
+
+accept(UnsignedRange(50'u64))
+reject(UnsignedRange(101'u64))
+
+accept(SemiOutOfBounds(0x7ffffffffffffe00'i64))
+reject(SemiOutOfBounds(0x8000000000000000'i64))  #
+accept(SemiOutOfBounds(0x8000000000000000'u64))  # the last two literals have internally the same `intVal`.
+
+reject(int32(NaN))
+reject(int64(1e100))
+reject(uint64(1e100))
+
+# removed cross checks from tarithm.nim
+reject(int64(0xFFFFFFFFFFFFFFFF'u64))
+reject(int32(0xFFFFFFFFFFFFFFFF'u64))
+reject(int16(0xFFFFFFFFFFFFFFFF'u64))
+reject( int8(0xFFFFFFFFFFFFFFFF'u64))