summary refs log tree commit diff stats
path: root/tests/casestmt/tcasestmt.nim
diff options
context:
space:
mode:
Diffstat (limited to 'tests/casestmt/tcasestmt.nim')
-rw-r--r--tests/casestmt/tcasestmt.nim79
1 files changed, 73 insertions, 6 deletions
diff --git a/tests/casestmt/tcasestmt.nim b/tests/casestmt/tcasestmt.nim
index b7454ef99..66de4183d 100644
--- a/tests/casestmt/tcasestmt.nim
+++ b/tests/casestmt/tcasestmt.nim
@@ -41,6 +41,11 @@ block t8333:
   case 0
   of 'a': echo 0
   else: echo 1
+block: # issue #11422
+  var c: int = 5
+  case c
+  of 'a' .. 'c': discard
+  else: discard
 
 
 block emptyset_when:
@@ -184,33 +189,33 @@ block tcasestm:
     doAssert(bstatic == false)
 
   var bb: bool
-  doassert(not compiles(
+  doAssert(not compiles(
     bb = case str2:
       of "": raise newException(ValueError, "Invalid boolean")
       elif str.startsWith("Y"): true
       elif str.startsWith("N"): false
   ))
 
-  doassert(not compiles(
+  doAssert(not compiles(
     bb = case str2:
       of "Y": true
       of "N": false
   ))
 
-  doassert(not compiles(
+  doAssert(not compiles(
     bb = case str2:
       of "Y": true
       of "N": raise newException(ValueError, "N not allowed")
   ))
 
-  doassert(not compiles(
+  doAssert(not compiles(
     bb = case str2:
       of "Y": raise newException(ValueError, "Invalid Y")
       else: raise newException(ValueError, "Invalid N")
   ))
 
 
-  doassert(not compiles(
+  doAssert(not compiles(
     bb = case str2:
       of "Y":
         raise newException(ValueError, "Invalid Y")
@@ -219,7 +224,7 @@ block tcasestm:
   ))
 
 
-  doassert(not compiles(
+  doAssert(not compiles(
     bb = case str2:
       of "Y":
         "invalid Y".quit(3)
@@ -250,3 +255,65 @@ proc negativeOrNot(num: int): string =
 doAssert negativeOrNot(-1) == "negative"
 doAssert negativeOrNot(10000000) == "zero or positive"
 doAssert negativeOrNot(0) == "zero or positive"
+
+########################################################
+# issue #13490
+import strutils
+func foo(input: string): int =
+  try:
+    parseInt(input)
+  except:
+    return
+
+func foo2(b, input: string): int =
+  case b:
+    of "Y":
+      for c in input:
+        result =  if c in '0'..'9': parseInt($c)
+                  else: break
+    of "N":
+      for c in input:
+        result =  if c in '0'..'9': parseInt($c)
+                  else: continue
+    else: return
+
+
+static:
+  doAssert(foo("3") == 3)
+  doAssert(foo("a") == 0)
+  doAssert(foo2("Y", "a2") == 0)
+  doAssert(foo2("Y", "2a") == 2)
+  doAssert(foo2("N", "a3") == 3)
+  doAssert(foo2("z", "2") == 0)
+
+doAssert(foo("3") == 3)
+doAssert(foo("a") == 0)
+doAssert(foo2("Y", "a2") == 0)
+doAssert(foo2("Y", "2a") == 2)
+doAssert(foo2("N", "a3") == 3)
+doAssert(foo2("z", "2") == 0)
+
+
+# bug #20031
+proc main(a: uint64) =
+  case a
+  else:
+    discard
+
+static:
+  main(10)
+main(10)
+
+block:
+  # Just needs to compile
+  proc bar(): int {.discardable.} = discard
+
+  proc foo() {.noreturn.} = discard
+
+  case "*"
+  of "*":
+    bar()
+  else:
+    # Make sure this noreturn doesn't
+    # cause the discardable to not discard
+    foo()