Repository: Kotlin/kotlinx.coroutines
File: kotlinx-coroutines-core/common/test/CoroutineScopeTest.kt (Kotlin)

Code before:
    }

    @Test
    fun testNewCoroutineContextDispatcher() {
        fun newContextDispatcher(c1: CoroutineContext, c2: CoroutineContext) =
            ContextScope(c1).newCoroutineContext(c2)[ContinuationInterceptor]

        assertSame(Dispatchers.Default, newContextDispatcher(EmptyCoroutineContext, EmptyCoroutineContext))
        assertSame(Dispatchers.Default, newContextDispatcher(EmptyCoroutineContext, Dispatchers.Default))
        assertSame(Dispatchers.Default, newContextDispatcher(Dispatchers.Default, EmptyCoroutineContext))
        assertSame(Dispatchers.Default, newContextDispatcher(Dispatchers.Default, Dispatchers.Default))
        assertSame(Dispatchers.Default, newContextDispatcher(Dispatchers.Unconfined, Dispatchers.Default))
        assertSame(Dispatchers.Unconfined, newContextDispatcher(Dispatchers.Default, Dispatchers.Unconfined))
        assertSame(Dispatchers.Unconfined, newContextDispatcher(Dispatchers.Unconfined, Dispatchers.Unconfined))
    }

    @Test
    fun testScopePlusContext() {
        assertSame(EmptyCoroutineContext, scopePlusContext(EmptyCoroutineContext, EmptyCoroutineContext))
        assertSame(Dispatchers.Default, scopePlusContext(EmptyCoroutineContext, Dispatchers.Default))
        assertSame(Dispatchers.Default, scopePlusContext(Dispatchers.Default, EmptyCoroutineContext))
        assertSame(Dispatchers.Default, scopePlusContext(Dispatchers.Default, Dispatchers.Default))
        assertSame(Dispatchers.Default, scopePlusContext(Dispatchers.Unconfined, Dispatchers.Default))
        assertSame(Dispatchers.Unconfined, scopePlusContext(Dispatchers.Default, Dispatchers.Unconfined))
        assertSame(Dispatchers.Unconfined, scopePlusContext(Dispatchers.Unconfined, Dispatchers.Unconfined))
    }

    @Test
    fun testIncompleteScopeState() = runTest {
        lateinit var scopeJob: Job
        coroutineScope {
            scopeJob = coroutineContext[Job]!!
            scopeJob.invokeOnCompletion { }
        }

        scopeJob.join()
        assertTrue(scopeJob.isCompleted)
        assertFalse(scopeJob.isActive)
        assertFalse(scopeJob.isCancelled)
    }

    private fun scopePlusContext(c1: CoroutineContext, c2: CoroutineContext) =
        (ContextScope(c1) + c2).coroutineContext

    @Test
    fun testIsActiveWithoutJob() {
        var invoked = false
        suspend fun testIsActive() {
            assertTrue(coroutineContext.isActive)
            invoked = true
        }

Review comment (bug):
I think we also need to check the user-visible bug directly, like what you have in your reproducer:
```kotlin
    runTest {
        val job = Job()
        val scope = CoroutineScope(job + coroutineContext[CoroutineExceptionHandler]!!)
        scope.launch(Dispatchers.Default) {
            assertSame(Dispatchers.Default, coroutineContext[ContinuationInterceptor])
        }
        scope.launch {
            assertSame(Dispatchers.Default, coroutineContext[ContinuationInterceptor])
        }
        job.complete()
        job.join()
    }
```

Code after:
    }

    @Test
    fun testLaunchContainsDefaultDispatcher() = runTest {
        val scopeWithoutDispatcher = CoroutineScope(coroutineContext.minusKey(ContinuationInterceptor))
        scopeWithoutDispatcher.launch(Dispatchers.Default) {
            assertSame(Dispatchers.Default, coroutineContext[ContinuationInterceptor])
        }.join()
        scopeWithoutDispatcher.launch {
            assertSame(Dispatchers.Default, coroutineContext[ContinuationInterceptor])
        }.join()
    }

    @Test
    fun testNewCoroutineContextDispatcher() {
        fun newContextDispatcher(c1: CoroutineContext, c2: CoroutineContext) =
            ContextScope(c1).newCoroutineContext(c2)[ContinuationInterceptor]

        assertSame(Dispatchers.Default, newContextDispatcher(EmptyCoroutineContext, EmptyCoroutineContext))
        assertSame(Dispatchers.Default, newContextDispatcher(EmptyCoroutineContext, Dispatchers.Default))
        assertSame(Dispatchers.Default, newContextDispatcher(Dispatchers.Default, EmptyCoroutineContext))
        assertSame(Dispatchers.Default, newContextDispatcher(Dispatchers.Default, Dispatchers.Default))
        assertSame(Dispatchers.Default, newContextDispatcher(Dispatchers.Unconfined, Dispatchers.Default))
        assertSame(Dispatchers.Unconfined, newContextDispatcher(Dispatchers.Default, Dispatchers.Unconfined))
        assertSame(Dispatchers.Unconfined, newContextDispatcher(Dispatchers.Unconfined, Dispatchers.Unconfined))
    }

    @Test
    fun testScopePlusContext() {
        assertSame(EmptyCoroutineContext, scopePlusContext(EmptyCoroutineContext, EmptyCoroutineContext))
        assertSame(Dispatchers.Default, scopePlusContext(EmptyCoroutineContext, Dispatchers.Default))
        assertSame(Dispatchers.Default, scopePlusContext(Dispatchers.Default, EmptyCoroutineContext))
        assertSame(Dispatchers.Default, scopePlusContext(Dispatchers.Default, Dispatchers.Default))
        assertSame(Dispatchers.Default, scopePlusContext(Dispatchers.Unconfined, Dispatchers.Default))
        assertSame(Dispatchers.Unconfined, scopePlusContext(Dispatchers.Default, Dispatchers.Unconfined))
        assertSame(Dispatchers.Unconfined, scopePlusContext(Dispatchers.Unconfined, Dispatchers.Unconfined))
    }

    @Test
    fun testIncompleteScopeState() = runTest {
        lateinit var scopeJob: Job
        coroutineScope {
            scopeJob = coroutineContext[Job]!!
            scopeJob.invokeOnCompletion { }
        }

        scopeJob.join()
        assertTrue(scopeJob.isCompleted)
        assertFalse(scopeJob.isActive)
        assertFalse(scopeJob.isCancelled)
    }