summary refs log tree commit diff stats
path: root/tests
diff options
context:
space:
mode:
authorTimothee Cour <timothee.cour2@gmail.com>2021-03-04 05:00:04 -0800
committerGitHub <noreply@github.com>2021-03-04 14:00:04 +0100
commita66637bda46a62972a4cca2afc3c49b71c7222c2 (patch)
tree91444f547241a374b6e790ebc487d864673d52ee /tests
parent5670b848cb87d3a437699ecaf67db6a4b35e0626 (diff)
downloadNim-a66637bda46a62972a4cca2afc3c49b71c7222c2.tar.gz
followup #16871 asyncjs.then: allow pipelining procs returning futures (#17189)
* followup #16871 asyncjs.then: allow pipelining procs returning futures
* rename test files where they belong
* fix tests
* tests for then with `onReject` callback
* rename test file containing fail to avoid messing with grep
* address comments
* cleanup
* un-disable 1 test
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 =