summary refs log tree commit diff stats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/js/tasyncjs.nim (renamed from tests/js/tasync.nim)20
-rw-r--r--tests/js/tasyncjs_bad.nim (renamed from tests/js/tasyncjs_fail.nim)0
-rw-r--r--tests/js/tasyncjs_pragma.nim (renamed from tests/js/tasync_pragma.nim)2
3 files changed, 22 insertions, 0 deletions
diff --git a/tests/js/tasync.nim b/tests/js/tasyncjs.nim
index e676ba14b..00753a16c 100644
--- a/tests/js/tasync.nim
+++ b/tests/js/tasyncjs.nim
@@ -50,6 +50,14 @@ proc fn(n: int): Future[int] {.async.} =
   else:
     return 10
 
+proc asyncFact(n: int): Future[int] {.async.} =
+  if n > 0: result = n * await asyncFact(n-1)
+  else: result = 1
+
+proc asyncIdentity(n: int): Future[int] {.async.} =
+  if n > 0: result = 1 + await asyncIdentity(n-1)
+  else: result = 0
+
 proc main() {.async.} =
   block: # then
     let x = await fn(4)
@@ -63,6 +71,18 @@ proc main() {.async.} =
     let x2 = await fn(4).then((a: int) => (discard)).then(() => 13)
     doAssert x2 == 13
 
+    let x4 = await asyncFact(3).then(asyncIdentity).then(asyncIdentity).then((a:int) => a * 7).then(asyncIdentity)
+    doAssert x4 == 3 * 2 * 7
+
+    block: # bug #17177
+      proc asyncIdentityNested(n: int): Future[int] {.async.} = return n
+      let x5 = await asyncFact(3).then(asyncIdentityNested)
+      doAssert x5 == 3 * 2
+
+    when false: # xxx pending bug #17254
+      let x6 = await asyncFact(3).then((a:int) {.async.} => a * 11)
+      doAssert x6 == 3 * 2 * 11
+
   block: # catch
     var reason: Error
     await fn(6).then((a: int) => (witness.add $a)).catch((r: Error) => (reason = r))
diff --git a/tests/js/tasyncjs_fail.nim b/tests/js/tasyncjs_bad.nim
index b1e5a7bc3..b1e5a7bc3 100644
--- a/tests/js/tasyncjs_fail.nim
+++ b/tests/js/tasyncjs_bad.nim
diff --git a/tests/js/tasync_pragma.nim b/tests/js/tasyncjs_pragma.nim
index 916769fad..2b6f32e92 100644
--- a/tests/js/tasync_pragma.nim
+++ b/tests/js/tasyncjs_pragma.nim
@@ -5,6 +5,8 @@ t
 '''
 """
 
+# xxx merge into tasyncjs.nim
+
 import asyncjs, macros
 
 macro f*(a: untyped): untyped =