From 502cb1e45621bf2023d3a89802ff27ea2d81b697 Mon Sep 17 00:00:00 2001 From: "Vitaliy.Bibaev" Date: Fri, 17 Nov 2017 15:55:40 +0300 Subject: [PATCH] Add test cases to check types of chain operations --- .../streams/kotlin/psi/TypedChainTestCase.kt | 41 +++++++++++++++++++ .../collection/TypedCollectionChainTest.kt | 12 ++++++ .../kotlin/psi/java/TypedJavaChainTest.kt | 12 ++++++ 3 files changed, 65 insertions(+) create mode 100644 idea/tests/com/intellij/debugger/streams/kotlin/psi/TypedChainTestCase.kt create mode 100644 idea/tests/com/intellij/debugger/streams/kotlin/psi/collection/TypedCollectionChainTest.kt create mode 100644 idea/tests/com/intellij/debugger/streams/kotlin/psi/java/TypedJavaChainTest.kt diff --git a/idea/tests/com/intellij/debugger/streams/kotlin/psi/TypedChainTestCase.kt b/idea/tests/com/intellij/debugger/streams/kotlin/psi/TypedChainTestCase.kt new file mode 100644 index 00000000000..b658dd87925 --- /dev/null +++ b/idea/tests/com/intellij/debugger/streams/kotlin/psi/TypedChainTestCase.kt @@ -0,0 +1,41 @@ +package com.intellij.debugger.streams.kotlin.psi + +import com.intellij.debugger.streams.kotlin.KotlinPsiChainBuilderTestCase +import com.intellij.debugger.streams.trace.impl.handler.type.GenericType + +/** + * @author Vitaliy.Bibaev + */ +abstract class TypedChainTestCase(relativePath: String) : KotlinPsiChainBuilderTestCase(relativePath) { + + protected fun doTest(producerAfterType: GenericType, + vararg intermediateAfterTypes: GenericType) { + val elementAtCaret = configureAndGetElementAtCaret() + assertNotNull(elementAtCaret) + val chains = chainBuilder.build(elementAtCaret) + assertFalse(chains.isEmpty()) + val chain = chains[0] + val intermediateCalls = chain.intermediateCalls + assertEquals(intermediateAfterTypes.size, intermediateCalls.size) + assertEquals(producerAfterType, chain.qualifierExpression.typeAfter) + + if (intermediateAfterTypes.isNotEmpty()) { + assertEquals(producerAfterType, intermediateCalls[0].typeBefore) + for (i in 0 until intermediateAfterTypes.size - 1) { + assertEquals(intermediateAfterTypes[i], intermediateCalls[i].typeAfter) + assertEquals(intermediateAfterTypes[i], intermediateCalls[i + 1].typeBefore) + } + + val lastAfterType = intermediateAfterTypes[intermediateAfterTypes.size - 1] + assertEquals(lastAfterType, chain.terminationCall.typeBefore) + val lastCall = intermediateCalls[intermediateCalls.size - 1] + assertEquals(lastAfterType, lastCall.typeAfter) + } else { + assertEquals(producerAfterType, chain.terminationCall.typeBefore) + } + } + + override fun doTest() { + fail("Use doTest(producerAfterType, vararg intermediateAfterTypes)") + } +} \ No newline at end of file diff --git a/idea/tests/com/intellij/debugger/streams/kotlin/psi/collection/TypedCollectionChainTest.kt b/idea/tests/com/intellij/debugger/streams/kotlin/psi/collection/TypedCollectionChainTest.kt new file mode 100644 index 00000000000..e82b5f30e50 --- /dev/null +++ b/idea/tests/com/intellij/debugger/streams/kotlin/psi/collection/TypedCollectionChainTest.kt @@ -0,0 +1,12 @@ +package com.intellij.debugger.streams.kotlin.psi.collection + +import com.intellij.debugger.streams.kotlin.lib.KotlinCollectionSupportProvider +import com.intellij.debugger.streams.kotlin.psi.TypedChainTestCase +import com.intellij.debugger.streams.wrapper.StreamChainBuilder + +/** + * @author Vitaliy.Bibaev + */ +class TypedCollectionChainTest : TypedChainTestCase("collection/positive/types") { + override val kotlinChainBuilder: StreamChainBuilder = KotlinCollectionSupportProvider().chainBuilder +} \ No newline at end of file diff --git a/idea/tests/com/intellij/debugger/streams/kotlin/psi/java/TypedJavaChainTest.kt b/idea/tests/com/intellij/debugger/streams/kotlin/psi/java/TypedJavaChainTest.kt new file mode 100644 index 00000000000..02b9ed6bf16 --- /dev/null +++ b/idea/tests/com/intellij/debugger/streams/kotlin/psi/java/TypedJavaChainTest.kt @@ -0,0 +1,12 @@ +package com.intellij.debugger.streams.kotlin.psi.java + +import com.intellij.debugger.streams.kotlin.psi.TypedChainTestCase +import com.intellij.debugger.streams.lib.impl.StandardLibrarySupportProvider +import com.intellij.debugger.streams.wrapper.StreamChainBuilder + +/** + * @author Vitaliy.Bibaev + */ +class TypedJavaChainTest : TypedChainTestCase("streams/positive/types") { + override val kotlinChainBuilder: StreamChainBuilder = StandardLibrarySupportProvider().chainBuilder +} \ No newline at end of file