From b592bc162a7a31554669a70e0d26a4bd344753fe Mon Sep 17 00:00:00 2001 From: yair Date: Sun, 10 Dec 2023 13:38:23 +0200 Subject: [PATCH] tests --- Common/build.gradle | 1 + .../chat/lens/TabnineLensBaseProvider.kt | 14 ++--- Tabnine/build.gradle | 1 + .../test/kotlin/TabnineLensIntegrationTest.kt | 57 +++++++++++++++++++ 4 files changed, 66 insertions(+), 7 deletions(-) create mode 100644 Tabnine/src/test/kotlin/TabnineLensIntegrationTest.kt diff --git a/Common/build.gradle b/Common/build.gradle index 4e977ab67..9456c4c2a 100644 --- a/Common/build.gradle +++ b/Common/build.gradle @@ -42,6 +42,7 @@ intellij { type = 'IC' updateSinceUntilBuild = false pluginName = 'TabNine' + plugins = ['java'] } def channelName = project.hasProperty('channel') ? project.channel : 'alpha' diff --git a/Common/src/main/java/com/tabnineCommon/chat/lens/TabnineLensBaseProvider.kt b/Common/src/main/java/com/tabnineCommon/chat/lens/TabnineLensBaseProvider.kt index 22fc0a336..f8b224724 100644 --- a/Common/src/main/java/com/tabnineCommon/chat/lens/TabnineLensBaseProvider.kt +++ b/Common/src/main/java/com/tabnineCommon/chat/lens/TabnineLensBaseProvider.kt @@ -11,7 +11,7 @@ import com.intellij.psi.PsiFile import javax.swing.JComponent import javax.swing.JPanel -internal open class TabnineLensBaseProvider(private val supportedElementTypes: List) : InlayHintsProvider { +open class TabnineLensBaseProvider(private val supportedElementTypes: List) : InlayHintsProvider { override fun getCollectorFor( file: PsiFile, editor: Editor, @@ -36,9 +36,9 @@ internal open class TabnineLensBaseProvider(private val supportedElementTypes: L } } -internal class TabnineLensPythonProvider : TabnineLensBaseProvider(listOf("Py:CLASS_DECLARATION", "Py:FUNCTION_DECLARATION")) -internal class TabnineLensTypescriptProvider : TabnineLensBaseProvider(listOf("JS:FUNCTION_DECLARATION", "JS:ES6_CLASS", "JS:CLASS", "JS:TYPESCRIPT_FUNCTION", "JS:TYPESCRIPT_CLASS")) -internal class TabnineLensJavaProvider : TabnineLensBaseProvider(listOf("CLASS", "METHOD")) -internal class TabnineLensKotlinProvider : TabnineLensBaseProvider(listOf("CLASS", "FUN")) -internal class TabnineLensPhpProvider : TabnineLensBaseProvider(listOf("Class", "Class method", "Function")) -internal class TabnineLensRustProvider : TabnineLensBaseProvider(listOf("FUNCTION")) +open class TabnineLensJavaProvider : TabnineLensBaseProvider(listOf("CLASS", "METHOD")) +open class TabnineLensPythonProvider : TabnineLensBaseProvider(listOf("Py:CLASS_DECLARATION", "Py:FUNCTION_DECLARATION")) +open class TabnineLensTypescriptProvider : TabnineLensBaseProvider(listOf("JS:FUNCTION_DECLARATION", "JS:ES6_CLASS", "JS:CLASS", "JS:TYPESCRIPT_FUNCTION", "JS:TYPESCRIPT_CLASS")) +open class TabnineLensKotlinProvider : TabnineLensBaseProvider(listOf("CLASS", "FUN")) +open class TabnineLensPhpProvider : TabnineLensBaseProvider(listOf("Class", "Class method", "Function")) +open class TabnineLensRustProvider : TabnineLensBaseProvider(listOf("FUNCTION")) diff --git a/Tabnine/build.gradle b/Tabnine/build.gradle index 2d24221a7..e557b5eed 100644 --- a/Tabnine/build.gradle +++ b/Tabnine/build.gradle @@ -66,6 +66,7 @@ intellij { type = 'IC' updateSinceUntilBuild = false pluginName = 'TabNine' + plugins = ['java'] } def PRODUCTION_CHANNEL = null diff --git a/Tabnine/src/test/kotlin/TabnineLensIntegrationTest.kt b/Tabnine/src/test/kotlin/TabnineLensIntegrationTest.kt new file mode 100644 index 000000000..827369ad9 --- /dev/null +++ b/Tabnine/src/test/kotlin/TabnineLensIntegrationTest.kt @@ -0,0 +1,57 @@ + +import com.intellij.codeInsight.hints.CollectorWithSettings +import com.intellij.codeInsight.hints.InlayHintsSinkImpl +import com.intellij.codeInsight.hints.NoSettings +import com.intellij.openapi.application.ApplicationManager +import com.intellij.testFramework.fixtures.LightPlatformCodeInsightFixture4TestCase +import com.intellij.testFramework.replaceService +import com.tabnineCommon.capabilities.CapabilitiesService +import com.tabnineCommon.capabilities.Capability +import com.tabnineCommon.chat.lens.TabnineLensJavaProvider +import org.junit.Test + +class TabnineLensIntegrationTest : LightPlatformCodeInsightFixture4TestCase() { + + @Test + fun `should return inlay hints for java function`() { + ApplicationManager.getApplication().replaceService( + CapabilitiesService::class.java, + object : CapabilitiesService() { + override fun isCapabilityEnabled(capability: Capability): Boolean { + return when (capability) { + Capability.TABNINE_CHAT -> true + else -> false + } + } + }, + testRootDisposable + ) + + myFixture.configureByText( + "Test.java", + "public class Test {\n public void test() {\n System.out.println(\"Hello World\");\n }\n}" + ) + + val provider = TabnineLensJavaProvider() + + val file = myFixture.file + val editor = myFixture.editor + val sink = InlayHintsSinkImpl(editor) + + val collector = provider.getCollectorFor(file, editor, NoSettings(), sink) + val collectorWithSettings = CollectorWithSettings(collector, provider.key, file.language, sink) + collectorWithSettings.collectTraversingAndApply( + editor, + file, + true + ) + val blockElementsInRange = myFixture.editor.inlayModel.getBlockElementsInRange( + file.textRange.startOffset, + file.textRange.endOffset + ) + + assertEquals(blockElementsInRange.get(0).offset, 0) + assertEquals(blockElementsInRange.get(1).offset, 20) + assertEquals(blockElementsInRange.size, 2) + } +}