summary refs log tree commit diff stats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/casestmt/tcasestm.nim59
-rw-r--r--tests/js/tasync.nim18
-rw-r--r--tests/pragmas/tnoreturn.nim22
-rw-r--r--tests/stdlib/tfrexp1.nim44
-rw-r--r--tests/stdlib/tstring.nim20
-rw-r--r--tests/stdlib/tunittest.nim38
6 files changed, 195 insertions, 6 deletions
diff --git a/tests/casestmt/tcasestm.nim b/tests/casestmt/tcasestm.nim
index 7ac20bf2f..b005d8120 100644
--- a/tests/casestmt/tcasestm.nim
+++ b/tests/casestmt/tcasestm.nim
@@ -36,5 +36,64 @@ var z = case i
 echo z
 #OUT ayyy
 
+let str1 = "Y"
+let str2 = "NN"
+let a = case str1:
+  of "Y": true
+  of "N": false
+  else: 
+    echo "no good"
+    quit("quiting")
 
+let b = case str2:
+  of nil, "": raise newException(ValueError, "Invalid boolean")
+  elif str2[0] == 'Y': true
+  elif str2[0] == 'N': false
+  else: "error".quit(2)
 
+doAssert(a == true)
+doAssert(b == false)
+
+var bb: bool
+doassert(not compiles(
+  bb = case str2:
+    of nil, "": raise newException(ValueError, "Invalid boolean")
+    elif str.startsWith("Y"): true
+    elif str.startsWith("N"): false
+))
+
+doassert(not compiles(
+  bb = case str2:
+    of "Y": true
+    of "N": false
+))
+
+doassert(not compiles(
+  bb = case str2:
+    of "Y": true
+    of "N": raise newException(ValueError, "N not allowed")
+))
+
+doassert(not compiles(
+  bb = case str2:
+    of "Y": raise newException(ValueError, "Invalid Y")
+    else: raise newException(ValueError, "Invalid N")
+))
+
+
+doassert(not compiles(
+  bb = case str2:
+    of "Y":
+      raise newException(ValueError, "Invalid Y")
+      true    
+    else: raise newException(ValueError, "Invalid")
+))
+
+
+doassert(not compiles(
+  bb = case str2:
+    of "Y":
+      "invalid Y".quit(3)
+      true    
+    else: raise newException(ValueError, "Invalid")
+))
\ No newline at end of file
diff --git a/tests/js/tasync.nim b/tests/js/tasync.nim
index a164827d2..34ef97b8b 100644
--- a/tests/js/tasync.nim
+++ b/tests/js/tasync.nim
@@ -1,8 +1,8 @@
 discard """
   disabled: true
   output: '''
-0
 x
+e
 '''
 """
 
@@ -10,16 +10,22 @@ import asyncjs
 
 # demonstrate forward definition
 # for js
-proc y(e: int): Future[string]
+proc y(e: int): Future[string] {.async.}
 
-proc x(e: int) {.async.} =
+proc e: int {.discardable.} =
+  echo "e"
+  return 2
+
+proc x(e: int): Future[void] {.async.} =
   var s = await y(e)
   echo s
+  e()
 
 proc y(e: int): Future[string] {.async.} =
-  echo 0
-  return "x"
-
+  if e > 0:
+    return await y(0)
+  else:
+    return "x"
 
 
 discard x(2)
diff --git a/tests/pragmas/tnoreturn.nim b/tests/pragmas/tnoreturn.nim
new file mode 100644
index 000000000..4d00c6034
--- /dev/null
+++ b/tests/pragmas/tnoreturn.nim
@@ -0,0 +1,22 @@
+discard """
+ccodeCheck: "\\i @'__attribute__((noreturn))' .*"
+"""
+
+proc noret1*(i: int) {.noreturn.} = 
+  echo i
+
+
+proc noret2*(i: int): void {.noreturn.} = 
+  echo i
+
+var p {.used.}: proc(i: int): int
+doAssert(not compiles(
+  p = proc(i: int): int {.noreturn.} = i # noreturn lambda returns int
+))
+
+
+doAssert(not compiles(
+  block:
+    noret1(5)
+    echo 1 # statement after noreturn
+))
diff --git a/tests/stdlib/tfrexp1.nim b/tests/stdlib/tfrexp1.nim
new file mode 100644
index 000000000..c6bb2b38c
--- /dev/null
+++ b/tests/stdlib/tfrexp1.nim
@@ -0,0 +1,44 @@
+discard """
+  targets: "js c c++"
+  output: '''ok'''
+"""
+
+import math
+import strformat
+
+const manualTest = false
+
+proc frexp_test(lo, hi, step: float64) =
+  var exp: int
+  var frac: float64
+
+  var eps = 1e-15.float64
+
+  var x:float64 = lo
+  while x <= hi:
+    frac = frexp(x.float, exp)
+    let rslt = pow(2.0, float(exp)) * frac
+
+    doAssert(abs(rslt - x) < eps)
+
+    when manualTest:
+      echo fmt("x: {x:10.3f} exp: {exp:4d} frac: {frac:24.20f} check: {$(abs(rslt - x) < eps):-5s} {rslt: 9.3f}")
+    x += step
+
+when manualTest:
+  var exp: int
+  var frac: float64
+
+  for flval in [1.7976931348623157e+308, -1.7976931348623157e+308, # max, min float64
+                3.4028234663852886e+38, -3.4028234663852886e+38,   # max, min float32
+                4.9406564584124654e-324, -4.9406564584124654e-324, # smallest/largest positive/negative float64
+                1.4012984643248171e-45, -1.4012984643248171e-45,   # smallest/largest positive/negative float32
+                2.2250738585072014e-308, 1.1754943508222875e-38]:  # smallest normal float64/float32
+    frac = frexp(flval, exp)
+    echo fmt("{flval:25.16e}, {exp: 6d}, {frac: .20f} {frac * pow(2.0, float(exp)): .20e}")
+
+  frexp_test(-1000.0, 1000.0, 0.0125)
+else:
+  frexp_test(-1000000.0, 1000000.0, 0.125)
+
+echo "ok"
diff --git a/tests/stdlib/tstring.nim b/tests/stdlib/tstring.nim
index 904bc462a..660746150 100644
--- a/tests/stdlib/tstring.nim
+++ b/tests/stdlib/tstring.nim
@@ -56,4 +56,24 @@ proc test_string_slice() =
 
   echo("OK")
 
+proc test_string_cmp() =
+  let world = "hello\0world"
+  let earth = "hello\0earth"
+  let short = "hello\0"
+  let hello = "hello"
+  let goodbye = "goodbye"
+
+  doAssert world == world
+  doAssert world != earth
+  doAssert world != short
+  doAssert world != hello
+  doAssert world != goodbye
+
+  doAssert cmp(world, world) == 0
+  doAssert cmp(world, earth) > 0
+  doAssert cmp(world, short) > 0
+  doAssert cmp(world, hello) > 0
+  doAssert cmp(world, goodbye) > 0
+
 test_string_slice()
+test_string_cmp()
diff --git a/tests/stdlib/tunittest.nim b/tests/stdlib/tunittest.nim
index e4a801871..86b9fd037 100644
--- a/tests/stdlib/tunittest.nim
+++ b/tests/stdlib/tunittest.nim
@@ -13,6 +13,8 @@ discard """
 
 [Suite] bug #5784
 
+[Suite] test name filtering
+
 '''
 """
 
@@ -120,3 +122,39 @@ suite "bug #5784":
       field: int
     var obj: Obj
     check obj.isNil or obj.field == 0
+
+when defined(testing):
+  suite "test name filtering":
+    test "test name":
+      check matchFilter("suite1", "foo", "")
+      check matchFilter("suite1", "foo", "foo")
+      check matchFilter("suite1", "foo", "::")
+      check matchFilter("suite1", "foo", "*")
+      check matchFilter("suite1", "foo", "::foo")
+      check matchFilter("suite1", "::foo", "::foo")
+
+    test "test name - glob":
+      check matchFilter("suite1", "foo", "f*")
+      check matchFilter("suite1", "foo", "*oo")
+      check matchFilter("suite1", "12345", "12*345")
+      check matchFilter("suite1", "q*wefoo", "q*wefoo")
+      check false == matchFilter("suite1", "foo", "::x")
+      check false == matchFilter("suite1", "foo", "::x*")
+      check false == matchFilter("suite1", "foo", "::*x")
+      #  overlap
+      check false == matchFilter("suite1", "12345", "123*345")
+      check matchFilter("suite1", "ab*c::d*e::f", "ab*c::d*e::f")
+
+    test "suite name":
+      check matchFilter("suite1", "foo", "suite1::")
+      check false == matchFilter("suite1", "foo", "suite2::")
+      check matchFilter("suite1", "qwe::foo", "qwe::foo")
+      check matchFilter("suite1", "qwe::foo", "suite1::qwe::foo")
+
+    test "suite name - glob":
+      check matchFilter("suite1", "foo", "::*")
+      check matchFilter("suite1", "foo", "*::*")
+      check matchFilter("suite1", "foo", "*::foo")
+      check false == matchFilter("suite1", "foo", "*ite2::")
+      check matchFilter("suite1", "q**we::foo", "q**we::foo")
+      check matchFilter("suite1", "a::b*c::d*e", "a::b*c::d*e")