package kotlinx.coroutines.flow import kotlinx.coroutines.testing.* import kotlinx.coroutines.* import kotlin.test.* class DropWhileTest : TestBase() { @Test fun testDropWhile() = runTest { val flow = flow { emit(1) emit(2) emit(3) } assertEquals(6, flow.dropWhile { false }.sum()) assertNull(flow.dropWhile { true }.singleOrNull()) assertEquals(5, flow.dropWhile { it < 2 }.sum()) assertEquals(1, flow.take(1).dropWhile { it > 1 }.single()) } @Test fun testEmptyFlow() = runTest { assertEquals(0, flowOf().dropWhile { true }.sum()) assertEquals(0, flowOf().dropWhile { false }.sum()) } @Test fun testErrorCancelsUpstream() = runTest { val flow = flow { coroutineScope { launch(start = CoroutineStart.ATOMIC) { hang { expect(4) } } expect(2) emit(1) expectUnreached() } }.dropWhile { expect(3) throw TestException() } expect(1) assertFailsWith(flow) finish(5) } }