summary refs log tree commit diff stats
path: root/tests/arithm
diff options
context:
space:
mode:
authorMiran <narimiran@users.noreply.github.com>2018-10-12 17:02:46 +0200
committerAndreas Rumpf <rumpf_a@web.de>2018-10-12 17:02:46 +0200
commit7f18d7cbc1fc8ad87c389b8d4d873e1d1169f794 (patch)
tree8c4839495fd6fc10376dc44cc8f9c7e3c625d18f /tests/arithm
parentd2b04a8bc7a78845d25e8b789184ae54e98073ec (diff)
downloadNim-7f18d7cbc1fc8ad87c389b8d4d873e1d1169f794.tar.gz
Merge tests into a larger file (part 1 of ∞) (#9318)
* merge actiontable tests

* merge arithm tests

* merge array tests

* merge assign tests

* merge bind tests

* merge casestmt tests

* merge closure tests

* merge cnt seq tests

* merge collections tests

* merge concept issues tests

* merge concept tests

* fix failing tests

* smaller outputs

Use `doAssert` where possible.

* fix wrong output

* split `tcomputedgoto`

* revert merging concepts

* fix failing test
Diffstat (limited to 'tests/arithm')
-rw-r--r--tests/arithm/tand.nim20
-rw-r--r--tests/arithm/tarithm.nim173
-rw-r--r--tests/arithm/tcast.nim95
-rw-r--r--tests/arithm/tnot.nim58
-rw-r--r--tests/arithm/tshl.nim34
-rw-r--r--tests/arithm/tshr.nim20
-rw-r--r--tests/arithm/tsubrange.nim13
7 files changed, 173 insertions, 240 deletions
diff --git a/tests/arithm/tand.nim b/tests/arithm/tand.nim
deleted file mode 100644
index fd0fa0dea..000000000
--- a/tests/arithm/tand.nim
+++ /dev/null
@@ -1,20 +0,0 @@
-discard """
-  output: '''int32
-int32
-1280
-1280'''
-"""
-
-# bug #5216
-
-import typetraits
-
-echo(name type((0x0A'i8 and 0x7F'i32) shl 7'i32))
-
-let i8 = 0x0A'i8
-echo(name type((i8 and 0x7F'i32) shl 7'i32))
-
-echo((0x0A'i8 and 0x7F'i32) shl 7'i32)
-
-let ii8 = 0x0A'i8
-echo((ii8 and 0x7F'i32) shl 7'i32)
diff --git a/tests/arithm/tarithm.nim b/tests/arithm/tarithm.nim
new file mode 100644
index 000000000..6d857a788
--- /dev/null
+++ b/tests/arithm/tarithm.nim
@@ -0,0 +1,173 @@
+discard """
+  output: '''
+int32
+int32
+1280
+1280
+'''
+"""
+
+import typetraits
+
+
+block tand:
+  # bug #5216
+  echo(name type((0x0A'i8 and 0x7F'i32) shl 7'i32))
+
+  let i8 = 0x0A'i8
+  echo(name type((i8 and 0x7F'i32) shl 7'i32))
+
+  echo((0x0A'i8 and 0x7F'i32) shl 7'i32)
+
+  let ii8 = 0x0A'i8
+  echo((ii8 and 0x7F'i32) shl 7'i32)
+
+
+
+block tcast:
+  template crossCheck(ty: untyped, exp: untyped) =
+    let rt = ty(exp)
+    const ct = ty(exp)
+    if $rt != $ct:
+      echo "Got ", ct
+      echo "Expected ", rt
+
+  template add1(x: uint8): untyped = x + 1
+  template add1(x: uint16): untyped = x + 1
+  template add1(x: uint32): untyped = x + 1
+
+  template sub1(x: uint8): untyped = x - 1
+  template sub1(x: uint16): untyped = x - 1
+  template sub1(x: uint32): untyped = x - 1
+
+  crossCheck(int8, 0'i16 - 5'i16)
+  crossCheck(int16, 0'i32 - 5'i32)
+  crossCheck(int32, 0'i64 - 5'i64)
+
+  crossCheck(uint8, 0'u8 - 5'u8)
+  crossCheck(uint16, 0'u16 - 5'u16)
+  crossCheck(uint32, 0'u32 - 5'u32)
+  crossCheck(uint64, 0'u64 - 5'u64)
+
+  crossCheck(uint8, uint8.high + 5'u8)
+  crossCheck(uint16, uint16.high + 5'u16)
+  crossCheck(uint32, uint32.high + 5'u32)
+  crossCheck(uint64, (-1).uint64 + 5'u64)
+
+  doAssert $sub1(0'u8) == "255"
+  doAssert $sub1(0'u16) == "65535"
+  doAssert $sub1(0'u32) == "4294967295"
+
+  doAssert $add1(255'u8) == "0"
+  doAssert $add1(65535'u16) == "0"
+  doAssert $add1(4294967295'u32) == "0"
+
+  crossCheck(int32, high(int32))
+  crossCheck(int32, high(int32).int32)
+  crossCheck(int32, low(int32))
+  crossCheck(int32, low(int32).int32)
+  crossCheck(int64, high(int8).int16.int32.int64)
+  crossCheck(int64, low(int8).int16.int32.int64)
+
+  crossCheck(int64, 0xFFFFFFFFFFFFFFFF'u64)
+  crossCheck(int32, 0xFFFFFFFFFFFFFFFF'u64)
+  crossCheck(int16, 0xFFFFFFFFFFFFFFFF'u64)
+  crossCheck(int8 , 0xFFFFFFFFFFFFFFFF'u64)
+
+
+
+block tnot:
+  # Signed types
+  block:
+    const t0: int8  = not 4
+    const t1: int16 = not 4
+    const t2: int32 = not 4
+    const t3: int64 = not 4
+    const t4: int8  = not -5
+    const t5: int16 = not -5
+    const t6: int32 = not -5
+    const t7: int64 = not -5
+    doAssert t0 == -5
+    doAssert t1 == -5
+    doAssert t2 == -5
+    doAssert t3 == -5
+    doAssert t4 == 4
+    doAssert t5 == 4
+    doAssert t6 == 4
+    doAssert t7 == 4
+
+  # Unsigned types
+  block:
+    const t0: uint8  = not 4'u8
+    const t1: uint16 = not 4'u16
+    const t2: uint32 = not 4'u32
+    const t3: uint64 = not 4'u64
+    const t4: uint8  = not 251'u8
+    const t5: uint16 = not 65531'u16
+    const t6: uint32 = not 4294967291'u32
+    const t7: uint64 = not 18446744073709551611'u64
+    doAssert t0 == 251
+    doAssert t1 == 65531
+    doAssert t2 == 4294967291'u32
+    doAssert t3 == 18446744073709551611'u64
+    doAssert t4 == 4
+    doAssert t5 == 4
+    doAssert t6 == 4
+    doAssert t7 == 4
+
+
+
+block tshl:
+  # Signed types
+  block:
+    const t0: int8  = 1'i8 shl 8
+    const t1: int16 = 1'i16 shl 16
+    const t2: int32 = 1'i32 shl 32
+    const t3: int64 = 1'i64 shl 64
+    doAssert t0 == 0
+    doAssert t1 == 0
+    doAssert t2 == 1
+    doAssert t3 == 1
+
+  # Unsigned types
+  block:
+    const t0: uint8  = 1'u8 shl 8
+    const t1: uint16 = 1'u16 shl 16
+    const t2: uint32 = 1'u32 shl 32
+    const t3: uint64 = 1'u64 shl 64
+    doAssert t0 == 0
+    doAssert t1 == 0
+    doAssert t2 == 0
+    doAssert t3 == 1
+
+
+
+block tshr:
+  proc T() =
+    # let VI = -8
+    let VI64 = -8'i64
+    let VI32 = -8'i32
+    let VI16 = -8'i16
+    let VI8 = -8'i8
+    # doAssert( (VI shr 1) == 9_223_372_036_854_775_804, "Actual: " & $(VI shr 1))
+    doAssert( (VI64 shr 1) == 9_223_372_036_854_775_804, "Actual: " & $(VI64 shr 1))
+    doAssert( (VI32 shr 1) == 2_147_483_644, "Actual: " & $(VI32 shr 1))
+    doAssert( (VI16 shr 1) == 32_764, "Actual: " & $(VI16 shr 1))
+    doAssert( (VI8 shr 1) == 124, "Actual: " & $(VI8 shr 1))
+
+  T()
+  static:
+    T()
+
+
+
+block tsubrange:
+  # bug #5854
+  type
+    n16 = range[0'i16..high(int16)]
+
+  var level: n16 = 1
+  let maxLevel: n16 = 1
+
+  level = min(level + 2, maxLevel)
+  doAssert level == 1
diff --git a/tests/arithm/tcast.nim b/tests/arithm/tcast.nim
deleted file mode 100644
index 4017ed1c5..000000000
--- a/tests/arithm/tcast.nim
+++ /dev/null
@@ -1,95 +0,0 @@
-discard """
-  output: '''
-B0
-B1
-B2
-B3
-B4
-B5
-B6
-'''
-"""
-
-template crossCheck(ty: untyped, exp: untyped) =
-  let rt = ty(exp)
-  const ct = ty(exp)
-  if $rt != $ct:
-    echo "Got ", ct
-    echo "Expected ", rt
-
-template add1(x: uint8): untyped = x + 1
-template add1(x: uint16): untyped = x + 1
-template add1(x: uint32): untyped = x + 1
-
-template sub1(x: uint8): untyped = x - 1
-template sub1(x: uint16): untyped = x - 1
-template sub1(x: uint32): untyped = x - 1
-
-block:
-  when true:
-    echo "B0"
-    crossCheck(int8, 0'i16 - 5'i16)
-    crossCheck(int16, 0'i32 - 5'i32)
-    crossCheck(int32, 0'i64 - 5'i64)
-
-    echo "B1"
-    crossCheck(uint8, 0'u8 - 5'u8)
-    crossCheck(uint16, 0'u16 - 5'u16)
-    crossCheck(uint32, 0'u32 - 5'u32)
-    crossCheck(uint64, 0'u64 - 5'u64)
-
-    echo "B2"
-    crossCheck(uint8, uint8.high + 5'u8)
-    crossCheck(uint16, uint16.high + 5'u16)
-    crossCheck(uint32, uint32.high + 5'u32)
-    crossCheck(uint64, (-1).uint64 + 5'u64)
-
-    echo "B3"
-    doAssert $sub1(0'u8) == "255"
-    doAssert $sub1(0'u16) == "65535"
-    doAssert $sub1(0'u32) == "4294967295"
-
-    echo "B4"
-    doAssert $add1(255'u8) == "0"
-    doAssert $add1(65535'u16) == "0"
-    doAssert $add1(4294967295'u32) == "0"
-
-    echo "B5"
-    crossCheck(int32, high(int32))
-    crossCheck(int32, high(int32).int32)
-    crossCheck(int32, low(int32))
-    crossCheck(int32, low(int32).int32)
-    crossCheck(int64, high(int8).int16.int32.int64)
-    crossCheck(int64, low(int8).int16.int32.int64)
-
-    echo "B6"
-    crossCheck(int64, 0xFFFFFFFFFFFFFFFF'u64)
-    crossCheck(int32, 0xFFFFFFFFFFFFFFFF'u64)
-    crossCheck(int16, 0xFFFFFFFFFFFFFFFF'u64)
-    crossCheck(int8 , 0xFFFFFFFFFFFFFFFF'u64)
-
-    # Out of range conversion, caught for `let`s only
-    # crossCheck(int8, 0'u8 - 5'u8)
-    # crossCheck(int16, 0'u16 - 5'u16)
-    # crossCheck(int32, 0'u32 - 5'u32)
-    # crossCheck(int64, 0'u64 - 5'u64)
-
-  # crossCheck(int8, 0'u16 - 129'u16)
-  # crossCheck(uint8, 0'i16 + 257'i16)
-
-  # Signed integer {under,over}flow is guarded against
-
-  # crossCheck(int8, int8.high + 5'i8)
-  # crossCheck(int16, int16.high + 5'i16)
-  # crossCheck(int32, int32.high + 5'i32)
-  # crossCheck(int64, int64.high + 5'i64)
-
-  # crossCheck(int8, int8.low - 5'i8)
-  # crossCheck(int16, int16.low - 5'i16)
-  # crossCheck(int32, int32.low - 5'i32)
-  # crossCheck(int64, int64.low - 5'i64)
-
-  # crossCheck(uint8, 0'i8 - 5'i8)
-  # crossCheck(uint16, 0'i16 - 5'i16)
-  # crossCheck(uint32, 0'i32 - 5'i32)
-  # crossCheck(uint64, 0'i64 - 5'i64)
diff --git a/tests/arithm/tnot.nim b/tests/arithm/tnot.nim
deleted file mode 100644
index 6a4877b2c..000000000
--- a/tests/arithm/tnot.nim
+++ /dev/null
@@ -1,58 +0,0 @@
-discard """
-  output: '''
--5
--5
--5
--5
-4
-4
-4
-4
-251
-65531
-4294967291
-18446744073709551611
-4
-4
-4
-4
-'''
-"""
-
-# Signed types
-block:
-  const t0: int8  = not 4
-  const t1: int16 = not 4
-  const t2: int32 = not 4
-  const t3: int64 = not 4
-  const t4: int8  = not -5
-  const t5: int16 = not -5
-  const t6: int32 = not -5
-  const t7: int64 = not -5
-  echo t0
-  echo t1
-  echo t2
-  echo t3
-  echo t4
-  echo t5
-  echo t6
-  echo t7
-
-# Unsigned types
-block:
-  const t0: uint8  = not 4'u8
-  const t1: uint16 = not 4'u16
-  const t2: uint32 = not 4'u32
-  const t3: uint64 = not 4'u64
-  const t4: uint8  = not 251'u8
-  const t5: uint16 = not 65531'u16
-  const t6: uint32 = not 4294967291'u32
-  const t7: uint64 = not 18446744073709551611'u64
-  echo t0
-  echo t1
-  echo t2
-  echo t3
-  echo t4
-  echo t5
-  echo t6
-  echo t7
diff --git a/tests/arithm/tshl.nim b/tests/arithm/tshl.nim
deleted file mode 100644
index 0aa46d021..000000000
--- a/tests/arithm/tshl.nim
+++ /dev/null
@@ -1,34 +0,0 @@
-discard """
-  output: '''
-0
-0
-1
-1
-0
-0
-0
-1
-'''
-"""
-
-# Signed types
-block:
-  const t0: int8  = 1'i8 shl 8
-  const t1: int16 = 1'i16 shl 16
-  const t2: int32 = 1'i32 shl 32
-  const t3: int64 = 1'i64 shl 64
-  echo t0
-  echo t1
-  echo t2
-  echo t3
-
-# Unsigned types
-block:
-  const t0: uint8  = 1'u8 shl 8
-  const t1: uint16 = 1'u16 shl 16
-  const t2: uint32 = 1'u32 shl 32
-  const t3: uint64 = 1'u64 shl 64
-  echo t0
-  echo t1
-  echo t2
-  echo t3
diff --git a/tests/arithm/tshr.nim b/tests/arithm/tshr.nim
deleted file mode 100644
index 4ba34aed9..000000000
--- a/tests/arithm/tshr.nim
+++ /dev/null
@@ -1,20 +0,0 @@
-discard """
-  output: ''''''
-"""
-
-proc T() =
-  # let VI = -8
-  let VI64 = -8'i64
-  let VI32 = -8'i32
-  let VI16 = -8'i16
-  let VI8 = -8'i8
-  # doAssert( (VI shr 1) == 9_223_372_036_854_775_804, "Actual: " & $(VI shr 1))
-  doAssert( (VI64 shr 1) == 9_223_372_036_854_775_804, "Actual: " & $(VI64 shr 1))
-  doAssert( (VI32 shr 1) == 2_147_483_644, "Actual: " & $(VI32 shr 1))
-  doAssert( (VI16 shr 1) == 32_764, "Actual: " & $(VI16 shr 1))
-  doAssert( (VI8 shr 1) == 124, "Actual: " & $(VI8 shr 1))
-
-
-T()
-static:
-  T()
diff --git a/tests/arithm/tsubrange.nim b/tests/arithm/tsubrange.nim
deleted file mode 100644
index 9d60dbd1a..000000000
--- a/tests/arithm/tsubrange.nim
+++ /dev/null
@@ -1,13 +0,0 @@
-discard """
-  output: '''1'''
-"""
-
-# bug #5854
-type
-  n16* = range[0'i16..high(int16)]
-
-var level: n16 = 1
-let maxLevel: n16 = 1
-
-level = min(level + 2, maxLevel)
-echo level