Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
yairco1990 committed Dec 10, 2023
1 parent 608e33a commit b592bc1
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 7 deletions.
1 change: 1 addition & 0 deletions Common/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ intellij {
type = 'IC'
updateSinceUntilBuild = false
pluginName = 'TabNine'
plugins = ['java']
}

def channelName = project.hasProperty('channel') ? project.channel : 'alpha'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>) : InlayHintsProvider<NoSettings> {
open class TabnineLensBaseProvider(private val supportedElementTypes: List<String>) : InlayHintsProvider<NoSettings> {
override fun getCollectorFor(
file: PsiFile,
editor: Editor,
Expand All @@ -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"))
1 change: 1 addition & 0 deletions Tabnine/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ intellij {
type = 'IC'
updateSinceUntilBuild = false
pluginName = 'TabNine'
plugins = ['java']
}

def PRODUCTION_CHANNEL = null
Expand Down
57 changes: 57 additions & 0 deletions Tabnine/src/test/kotlin/TabnineLensIntegrationTest.kt
Original file line number Diff line number Diff line change
@@ -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)
}
}

0 comments on commit b592bc1

Please sign in to comment.