Skip to content

Commit 8db7b99

Browse files
committed
Complicate HandleTest.coroutineAndReader
1 parent 5627d99 commit 8db7b99

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

library/src/commonTest/kotlin/HandleTest.kt

+13-2
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,27 @@
11
import io.kotest.matchers.shouldBe
22
import kotlinx.coroutines.test.runTest
3+
import kotlin.random.Random
34
import kotlin.test.Test
45

56
class HandleTest {
67
@Test
78
fun coroutineAndReader() = runTest {
9+
val randomAdds = List(4) { Random.nextInt(1, 10) }
10+
val randomAddsIterator = randomAdds.iterator()
811
val printed = mutableListOf<Int>()
912
runCC {
1013
runReader(10) {
1114
suspend fun Handle<Int, Unit>.handler(error: Int, cont: Cont<Unit, Unit>) {
1215
printed.add(error)
13-
handleShallow(::handler) { pushReader(ask() + 1) { cont(Unit) } }
16+
newReset<Unit> {
17+
pushReader(ask() + randomAddsIterator.next()) {
18+
handleShallow({ e, c ->
19+
abortS0 {
20+
handler(e, c)
21+
}
22+
}) { cont(Unit) }
23+
}
24+
}
1425
}
1526
newHandleShallow<Int, Unit, _>(Handle<Int, Unit>::handler) {
1627
call(ask())
@@ -22,7 +33,7 @@ class HandleTest {
2233
}
2334
}
2435
}
25-
printed shouldBe listOf(10, 11, 21, 21)
36+
printed shouldBe listOf(10, 10 + randomAdds[0], 20 + randomAdds[1], 20 + randomAdds[1])
2637
}
2738

2839
@Test

0 commit comments

Comments
 (0)