Skip to content

Commit 8a437fb

Browse files
committed
Test for isFlow
1 parent 60ff142 commit 8a437fb

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package kotlinx.rpc.descriptor
2+
3+
import kotlinx.coroutines.flow.Flow
4+
import kotlinx.rpc.annotations.Rpc
5+
import kotlin.reflect.typeOf
6+
import kotlin.test.Test
7+
import kotlin.test.assertEquals
8+
import kotlin.test.assertFalse
9+
import kotlin.test.assertTrue
10+
11+
@Rpc
12+
interface NewsServiceForFlowTest {
13+
fun stream(): Flow<String>
14+
suspend fun greet(name: String): String
15+
}
16+
17+
class IsFlowIntegrationTest {
18+
@Test
19+
fun stream_isFlow_and_returnType_is_Flow() {
20+
val descriptor = serviceDescriptorOf<NewsServiceForFlowTest>()
21+
val stream = descriptor.callables["stream"] ?: error("stream not found")
22+
23+
assertEquals(typeOf<Flow<String>>().toString(), stream.returnType.kType.toString())
24+
assertTrue(stream.returnsFlow)
25+
assertTrue(stream.isNonSuspendFunction)
26+
}
27+
28+
@Test
29+
fun greet_notFlow_and_returnType_is_String() {
30+
val descriptor = serviceDescriptorOf<NewsServiceForFlowTest>()
31+
val greet = descriptor.callables["greet"] ?: error("greet not found")
32+
33+
assertEquals(typeOf<String>().toString(), greet.returnType.kType.toString())
34+
assertFalse(greet.returnsFlow)
35+
// greet is suspend now
36+
kotlin.test.assertFalse(greet.isNonSuspendFunction)
37+
}
38+
}

0 commit comments

Comments
 (0)