Use directive configuring in resolve reference tests
This commit is contained in:
@@ -74,8 +74,12 @@ public final class InTextDirectivesUtils {
|
||||
if (strings.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
assert strings.size() == 1 : "There is more than one string with given prefixes " +
|
||||
Arrays.toString(prefixes) + ". Use findListWithPrefixes() instead.";
|
||||
|
||||
if (strings.size() != 1) {
|
||||
throw new IllegalStateException("There is more than one string with given prefixes " +
|
||||
Arrays.toString(prefixes) + ". Use findListWithPrefixes() instead.");
|
||||
}
|
||||
|
||||
return strings.get(0);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
open class Test
|
||||
|
||||
class SomeTest : <caret>Test()
|
||||
class SomeTest : <caret>Test()
|
||||
|
||||
// REF: (<root>).Test
|
||||
@@ -2,4 +2,6 @@ package test1.test2
|
||||
|
||||
class Some()
|
||||
|
||||
val test : <caret>test1.test2.Some = Some()
|
||||
val test : <caret>test1.test2.Some = Some()
|
||||
|
||||
// REF: test1
|
||||
@@ -1 +1,3 @@
|
||||
val c = javax.swing.SwingUtilities.<caret>invokeLater { }
|
||||
val c = javax.swing.SwingUtilities.<caret>invokeLater { }
|
||||
|
||||
// REF: (in javax.swing.SwingUtilities).invokeLater(Runnable)
|
||||
@@ -1 +1,3 @@
|
||||
val c = java.util.<caret>Comparator {(x: Int, y: Int) -> 1}
|
||||
val c = java.util.<caret>Comparator {(x: Int, y: Int) -> 1}
|
||||
|
||||
// REF: (java.util).Comparator
|
||||
@@ -1 +1,3 @@
|
||||
val c = java.util.<caret>Comparator<Int> { x, y -> 1 }
|
||||
val c = java.util.<caret>Comparator<Int> { x, y -> 1 }
|
||||
|
||||
// REF: (java.util).Comparator
|
||||
@@ -25,7 +25,8 @@ import com.intellij.psi.PsiReference;
|
||||
import com.intellij.psi.ResolveResult;
|
||||
import com.intellij.testFramework.LightCodeInsightTestCase;
|
||||
import junit.framework.Assert;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.InTextDirectivesUtils;
|
||||
import org.jetbrains.jet.plugin.PluginTestCaseBase;
|
||||
import org.jetbrains.jet.testing.ReferenceUtils;
|
||||
|
||||
@@ -43,41 +44,44 @@ public class ResolveBaseTest extends LightCodeInsightTestCase {
|
||||
}
|
||||
|
||||
public void testResolveClass() throws Exception {
|
||||
doSingleResolveTest("(<root>).Test");
|
||||
doSingleResolveTest();
|
||||
}
|
||||
|
||||
public void testResolvePackageInProperty() throws Exception {
|
||||
doSingleResolveTest("test1");
|
||||
doSingleResolveTest();
|
||||
}
|
||||
|
||||
public void testSamConstructor() throws Exception {
|
||||
doSingleResolveTest("(java.util).Comparator");
|
||||
doSingleResolveTest();
|
||||
}
|
||||
|
||||
public void testSamConstructorTypeArguments() throws Exception {
|
||||
doSingleResolveTest("(java.util).Comparator");
|
||||
doSingleResolveTest();
|
||||
}
|
||||
|
||||
public void testSamAdapter() throws Exception {
|
||||
doSingleResolveTest("(in javax.swing.SwingUtilities).invokeLater(Runnable)");
|
||||
doSingleResolveTest();
|
||||
}
|
||||
|
||||
public void testSeveralOverrides() throws Exception {
|
||||
doMultiResolveTest();
|
||||
}
|
||||
|
||||
protected void doSingleResolveTest(@Nullable String referenceToString) throws Exception {
|
||||
protected void doSingleResolveTest() throws Exception {
|
||||
String testName = getTestName(false);
|
||||
configureByFile(testName + ".kt");
|
||||
|
||||
String referenceToString = InTextDirectivesUtils.findStringWithPrefixes(getFile().getText(), "REF:");
|
||||
Assert.assertNotNull("Test data wasn't found, use \"// REF: \" directive", referenceToString);
|
||||
|
||||
int offset = getEditor().getCaretModel().getOffset();
|
||||
PsiReference psiReference = getFile().findReferenceAt(offset);
|
||||
if (psiReference != null) {
|
||||
PsiElement resolvedTo = psiReference.resolve();
|
||||
if (resolvedTo != null) {
|
||||
String resolvedToElementStr = ReferenceUtils.renderAsGotoImplementation(resolvedTo);
|
||||
String notEqualMessage = String.format("Found reference to '%s', but '%s' was expected", resolvedToElementStr,
|
||||
referenceToString != null ? referenceToString : "<null>");
|
||||
String notEqualMessage = String.format("Found reference to '%s', but '%s' was expected",
|
||||
resolvedToElementStr, referenceToString);
|
||||
assertEquals(notEqualMessage, referenceToString, resolvedToElementStr);
|
||||
}
|
||||
else {
|
||||
@@ -116,6 +120,7 @@ public class ResolveBaseTest extends LightCodeInsightTestCase {
|
||||
return PluginTestCaseBase.jdkFromIdeaHome();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected String getTestDataPath() {
|
||||
return new File(PluginTestCaseBase.getTestDataPathBase(), "/resolve/").getPath() + File.separator;
|
||||
|
||||
Reference in New Issue
Block a user