mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
change inlay hints testing api
The current approach allows for greater test source flexibility. Also it enables the use of FileComparisonFailure to ease working with tests.
This commit is contained in:
+35
-34
@@ -22,7 +22,8 @@ import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase
|
||||
class JavaInlayParameterHintsTest : LightCodeInsightFixtureTestCase() {
|
||||
|
||||
fun check(text: String) {
|
||||
myFixture.testInlays("A.java", text)
|
||||
myFixture.configureByText("A.java", text)
|
||||
myFixture.testInlays()
|
||||
}
|
||||
|
||||
fun `test insert literal arguments`() {
|
||||
@@ -51,11 +52,11 @@ class Groo {
|
||||
fun `test do not show for Exceptions`() {
|
||||
check("""
|
||||
class Fooo {
|
||||
|
||||
|
||||
public void test() {
|
||||
Throwable t = new IllegalStateException("crime");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
""")
|
||||
}
|
||||
@@ -77,7 +78,7 @@ class Fooo {
|
||||
|
||||
}""")
|
||||
}
|
||||
|
||||
|
||||
|
||||
fun `test no hints for generic builders`() {
|
||||
check("""
|
||||
@@ -98,7 +99,7 @@ class Stream<T> {
|
||||
""")
|
||||
}
|
||||
|
||||
|
||||
|
||||
fun `test do not show hints on setters`() {
|
||||
check("""class Groo {
|
||||
|
||||
@@ -114,7 +115,7 @@ class Stream<T> {
|
||||
|
||||
}""")
|
||||
}
|
||||
|
||||
|
||||
|
||||
fun `test single varargs hint`() {
|
||||
check("""
|
||||
@@ -150,7 +151,7 @@ public class VarArgTest {
|
||||
""")
|
||||
}
|
||||
|
||||
|
||||
|
||||
fun `test multiple vararg hint`() {
|
||||
check("""
|
||||
public class VarArgTest {
|
||||
@@ -167,8 +168,8 @@ public class VarArgTest {
|
||||
}
|
||||
""")
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
fun `test do not inline known subsequent parameter names`() {
|
||||
check("""
|
||||
public class Test {
|
||||
@@ -196,7 +197,7 @@ public class Test {
|
||||
}
|
||||
""")
|
||||
}
|
||||
|
||||
|
||||
|
||||
fun `test show if can be assigned`() {
|
||||
check("""
|
||||
@@ -242,34 +243,34 @@ public class Test {
|
||||
}
|
||||
}
|
||||
""")
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
fun `test ignored methods`() {
|
||||
check("""
|
||||
public class Test {
|
||||
|
||||
|
||||
List<String> list = new ArrayList<>();
|
||||
StringBuilder builder = new StringBuilder();
|
||||
|
||||
public void main() {
|
||||
System.out.println("A");
|
||||
System.out.print("A");
|
||||
|
||||
|
||||
list.add("sss");
|
||||
list.get(1);
|
||||
list.set(1, "sss");
|
||||
|
||||
|
||||
setNewIndex(10);
|
||||
"sss".contains("s");
|
||||
builder.append("sdfsdf");
|
||||
"sfsdf".startWith("s");
|
||||
"sss".charAt(3);
|
||||
|
||||
|
||||
clearStatus(<hint text="updatedRecently"/>false);
|
||||
}
|
||||
|
||||
|
||||
void print(String s) {}
|
||||
void println(String s) {}
|
||||
void get(int index) {}
|
||||
@@ -365,7 +366,7 @@ public class VarArgTest {
|
||||
fun `test if any param matches inline all`() {
|
||||
check("""
|
||||
public class VarArgTest {
|
||||
|
||||
|
||||
public void main() {
|
||||
check(<hint text="x"/>10, <hint text="paramNameLength"/>1000);
|
||||
}
|
||||
@@ -380,7 +381,7 @@ public class VarArgTest {
|
||||
fun `test inline common name pair if more that 2 args`() {
|
||||
check("""
|
||||
public class VarArgTest {
|
||||
|
||||
|
||||
public void main() {
|
||||
String s = "su";
|
||||
check(<hint text="beginIndex"/>10, <hint text="endIndex"/>1000, s);
|
||||
@@ -396,11 +397,11 @@ public class VarArgTest {
|
||||
fun `test ignore String methods`() {
|
||||
check("""
|
||||
class Test {
|
||||
|
||||
|
||||
public void main() {
|
||||
String.format("line", "eee", "www");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
""")
|
||||
}
|
||||
@@ -408,7 +409,7 @@ class Test {
|
||||
fun `test inline common name pair if more that 2 args xxx`() {
|
||||
check("""
|
||||
public class VarArgTest {
|
||||
|
||||
|
||||
public void main() {
|
||||
check(<hint text="beginIndex"/>10, <hint text="endIndex"/>1000, <hint text="x"/>"su");
|
||||
}
|
||||
@@ -423,7 +424,7 @@ public class VarArgTest {
|
||||
fun `test inline this`() {
|
||||
check("""
|
||||
public class VarArgTest {
|
||||
|
||||
|
||||
public void main() {
|
||||
check(<hint text="test"/>this, <hint text="endIndex"/>1000);
|
||||
}
|
||||
@@ -438,7 +439,7 @@ public class VarArgTest {
|
||||
fun `test inline strange methods`() {
|
||||
check("""
|
||||
public class Test {
|
||||
|
||||
|
||||
void main() {
|
||||
createContent(<hint text="manager"/>null);
|
||||
createNewContent(<hint text="test"/>this);
|
||||
@@ -462,13 +463,13 @@ class Builder {
|
||||
}
|
||||
|
||||
class Test {
|
||||
|
||||
|
||||
public void test() {
|
||||
Builder builder = new Builder();
|
||||
builder.await(<hint text="value"/>true);
|
||||
builder.bwait(false).timeWait(100);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
""")
|
||||
}
|
||||
@@ -494,7 +495,7 @@ class Test {
|
||||
fun `test do not show single parameter hint if it is string literal`() {
|
||||
check("""
|
||||
public class Test {
|
||||
|
||||
|
||||
public void test() {
|
||||
debug("Error message");
|
||||
info("Error message", new Object());
|
||||
@@ -502,11 +503,11 @@ public class Test {
|
||||
|
||||
void debug(String message) {}
|
||||
void info(String message, Object error) {}
|
||||
|
||||
|
||||
}
|
||||
""")
|
||||
}
|
||||
|
||||
|
||||
fun `test show single`() {
|
||||
check("""
|
||||
class Test {
|
||||
@@ -531,13 +532,13 @@ class Test {
|
||||
fun `test do not show for setters`() {
|
||||
check("""
|
||||
class Test {
|
||||
|
||||
|
||||
void main() {
|
||||
set(10);
|
||||
}
|
||||
|
||||
|
||||
void set(int newValue) {}
|
||||
|
||||
|
||||
}
|
||||
""")
|
||||
}
|
||||
@@ -556,13 +557,13 @@ class Test {
|
||||
fun `test more blacklisted items`() {
|
||||
check("""
|
||||
class Test {
|
||||
|
||||
|
||||
void test() {
|
||||
System.getProperty("aaa");
|
||||
System.setProperty("aaa", "bbb");
|
||||
new Key().create(10);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
class Key {
|
||||
@@ -592,7 +593,7 @@ class Test {
|
||||
check("""
|
||||
class Test {
|
||||
void test() {
|
||||
check(<hint text="isShow"/>1000);
|
||||
check(<hint text="isShow"/>1000);
|
||||
}
|
||||
void check(int isShow) {}
|
||||
}
|
||||
|
||||
+1
-1
@@ -539,7 +539,7 @@ 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 testInlays();
|
||||
|
||||
void assertPreferredCompletionItems(int selected, @NotNull String... expected);
|
||||
|
||||
|
||||
+2
-2
@@ -1696,11 +1696,11 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig
|
||||
}
|
||||
|
||||
@Override
|
||||
public void testInlays(@NotNull String fileName, @NotNull String text) {
|
||||
public void testInlays() {
|
||||
InlayHintsChecker checker = new InlayHintsChecker(this);
|
||||
try {
|
||||
checker.setUp();
|
||||
checker.checkInlays(fileName, text);
|
||||
checker.checkInlays();
|
||||
}
|
||||
finally {
|
||||
checker.tearDown();
|
||||
|
||||
+11
-7
@@ -21,8 +21,10 @@ 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.rt.execution.junit.FileComparisonFailure
|
||||
import com.intellij.testFramework.VfsTestUtil
|
||||
import com.intellij.testFramework.fixtures.CodeInsightTestFixture
|
||||
import org.junit.Assert.assertEquals
|
||||
import junit.framework.ComparisonFailure
|
||||
import java.util.regex.Pattern
|
||||
|
||||
|
||||
@@ -51,18 +53,20 @@ class InlayHintsChecker(private val myFixture: CodeInsightTestFixture) {
|
||||
hintSettings.isDoNotShowIfMethodNameContainsParameterName = default.isDoNotShowIfMethodNameContainsParameterName
|
||||
}
|
||||
|
||||
fun checkInlays(fileName: String, text: String) {
|
||||
myFixture.configureByText(fileName, text)
|
||||
|
||||
fun checkInlays() {
|
||||
val file = myFixture.file
|
||||
val document = myFixture.getDocument(file)
|
||||
val originalText = document.text
|
||||
val expectedInlays = extractInlays(document)
|
||||
val actualInlays = getActualInlays()
|
||||
|
||||
assertEquals(expectedInlays.size, actualInlays.size)
|
||||
if (expectedInlays.size != actualInlays.size || actualInlays.zip(expectedInlays).any { it.second != it.first }) {
|
||||
val proposedText = StringBuilder(document.text)
|
||||
actualInlays.asReversed().forEach { proposedText.insert(it.offset, "<hint text=\"${it.text}\" />") }
|
||||
|
||||
actualInlays.zip(expectedInlays).forEach {
|
||||
assertEquals(it.second, it.first)
|
||||
VfsTestUtil.TEST_DATA_FILE_PATH.get(file.virtualFile)?.let { originalPath ->
|
||||
throw FileComparisonFailure("Hints differ", originalText, proposedText.toString(), originalPath)
|
||||
} ?: throw ComparisonFailure("Hints differ", originalText, proposedText.toString())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user