mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[inline hints] added method to test inline hints inside CodeInsightTestFixtureImpl
This commit is contained in:
+3
-2
@@ -17,11 +17,12 @@ package com.intellij.codeInsight.daemon.inlays
|
||||
|
||||
import com.intellij.codeInsight.hints.settings.ParameterNameHintsSettings
|
||||
import com.intellij.lang.java.JavaLanguage
|
||||
import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase
|
||||
|
||||
class JavaInlayParameterHintsTest : InlayParameterHintsTest() {
|
||||
class JavaInlayParameterHintsTest : LightCodeInsightFixtureTestCase() {
|
||||
|
||||
fun check(text: String) {
|
||||
checkInlays("A.java", text)
|
||||
myFixture.testInlays("A.java", text)
|
||||
}
|
||||
|
||||
fun `test insert literal arguments`() {
|
||||
|
||||
+2
@@ -539,6 +539,8 @@ public interface CodeInsightTestFixture extends IdeaProjectTestFixture {
|
||||
|
||||
void testRainbow(@NotNull String fileName, @NotNull String text, boolean isRainbowOn, boolean withColor);
|
||||
|
||||
void testInlays(@NotNull String fileName, @NotNull String text);
|
||||
|
||||
void assertPreferredCompletionItems(int selected, @NotNull String... expected);
|
||||
|
||||
/**
|
||||
|
||||
+13
@@ -116,6 +116,7 @@ import com.intellij.refactoring.rename.*;
|
||||
import com.intellij.rt.execution.junit.FileComparisonFailure;
|
||||
import com.intellij.testFramework.*;
|
||||
import com.intellij.testFramework.fixtures.*;
|
||||
import com.intellij.testFramework.utils.inlays.InlayHintsChecker;
|
||||
import com.intellij.usageView.UsageInfo;
|
||||
import com.intellij.util.*;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
@@ -1694,6 +1695,18 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void testInlays(@NotNull String fileName, @NotNull String text) {
|
||||
InlayHintsChecker checker = new InlayHintsChecker(this);
|
||||
try {
|
||||
checker.setUp();
|
||||
checker.checkInlays(fileName, text);
|
||||
}
|
||||
finally {
|
||||
checker.tearDown();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void assertPreferredCompletionItems(final int selected, @NotNull final String... expected) {
|
||||
final LookupImpl lookup = getLookup();
|
||||
|
||||
+21
-38
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2016 JetBrains s.r.o.
|
||||
* Copyright 2000-2017 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -13,76 +13,59 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.codeInsight.daemon.inlays
|
||||
package com.intellij.testFramework.utils.inlays
|
||||
|
||||
import com.intellij.codeInsight.daemon.impl.ParameterHintsPresentationManager
|
||||
import com.intellij.codeInsight.hints.InlayInfo
|
||||
import com.intellij.codeInsight.hints.ParameterHintsPassFactory
|
||||
import com.intellij.codeInsight.hints.settings.ParameterNameHintsSettings
|
||||
import com.intellij.openapi.command.WriteCommandAction
|
||||
import com.intellij.openapi.editor.Document
|
||||
import com.intellij.openapi.editor.ex.EditorSettingsExternalizable
|
||||
import com.intellij.psi.PsiDocumentManager
|
||||
import com.intellij.psi.PsiFile
|
||||
import com.intellij.psi.impl.DebugUtil
|
||||
import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase
|
||||
import org.assertj.core.api.Assertions.assertThat
|
||||
import org.jdom.Element
|
||||
import com.intellij.testFramework.fixtures.CodeInsightTestFixture
|
||||
import org.junit.Assert.assertEquals
|
||||
import java.util.regex.Pattern
|
||||
|
||||
|
||||
abstract class InlayParameterHintsTest : LightCodeInsightFixtureTestCase() {
|
||||
|
||||
private var isParamHintsEnabledBefore = false
|
||||
private lateinit var stateBefore: Element
|
||||
class InlayHintsChecker(private val myFixture: CodeInsightTestFixture) {
|
||||
|
||||
private var isParamHintsEnabledBefore = false
|
||||
|
||||
companion object {
|
||||
val pattern: Pattern = Pattern.compile("<hint\\s+text=\"([0-9a-zA-Z]+)\"/>")
|
||||
}
|
||||
|
||||
override fun setUp() {
|
||||
super.setUp()
|
||||
|
||||
private val default = ParameterNameHintsSettings()
|
||||
}
|
||||
|
||||
fun setUp() {
|
||||
val settings = EditorSettingsExternalizable.getInstance()
|
||||
isParamHintsEnabledBefore = settings.isShowParameterNameHints
|
||||
settings.isShowParameterNameHints = true
|
||||
|
||||
stateBefore = ParameterNameHintsSettings.getInstance().state
|
||||
}
|
||||
|
||||
override fun tearDown() {
|
||||
fun tearDown() {
|
||||
EditorSettingsExternalizable.getInstance().isShowParameterNameHints = isParamHintsEnabledBefore
|
||||
ParameterNameHintsSettings.getInstance().loadState(stateBefore)
|
||||
val hintSettings = ParameterNameHintsSettings.getInstance()
|
||||
|
||||
super.tearDown()
|
||||
hintSettings.loadState(default.state)
|
||||
hintSettings.isShowForParamsWithSameType = default.isShowForParamsWithSameType
|
||||
hintSettings.isDoNotShowIfMethodNameContainsParameterName = default.isDoNotShowIfMethodNameContainsParameterName
|
||||
}
|
||||
|
||||
fun checkInlays(fileName: String, text: String) {
|
||||
myFixture.configureByText(fileName, text)
|
||||
|
||||
val document = myFixture.getDocument(myFixture.file)
|
||||
val file = myFixture.file
|
||||
val document = myFixture.getDocument(file)
|
||||
val expectedInlays = extractInlays(document)
|
||||
val actualInlays = getActualInlays()
|
||||
|
||||
assertThat(actualInlays.size)
|
||||
.withFailMessage("Expected ${expectedInlays.size} elements with hints, Actual elements count ${actualInlays.size}" +
|
||||
", file text: \n\n ${file.text} \n\n isCommitted ${isCommitted(file)} \n\n" +
|
||||
"All inlays: ${actualInlays}")
|
||||
.isEqualTo(expectedInlays.size)
|
||||
|
||||
assertEquals(expectedInlays.size, actualInlays.size)
|
||||
|
||||
actualInlays.zip(expectedInlays).forEach {
|
||||
assertThat(it.first).isEqualTo(it.second)
|
||||
assertEquals(it.second, it.first)
|
||||
}
|
||||
}
|
||||
|
||||
private fun isCommitted(file: PsiFile): Boolean {
|
||||
val manager = PsiDocumentManager.getInstance(file.project)
|
||||
val document = manager.getDocument(file)
|
||||
|
||||
assertThat(document).isNotNull()
|
||||
return manager.isCommitted(document!!)
|
||||
}
|
||||
|
||||
private fun getActualInlays(): List<InlayInfo> {
|
||||
myFixture.doHighlighting()
|
||||
val editor = myFixture.editor
|
||||
Reference in New Issue
Block a user