Added tests for argument mapping
This commit is contained in:
@@ -34,6 +34,12 @@ import kotlin.test.assertEquals
|
||||
import kotlin.test.assertTrue
|
||||
import org.jetbrains.jet.lang.resolve.calls.model.VariableAsFunctionResolvedCall
|
||||
import org.jetbrains.jet.lang.resolve.lazy.JvmResolveUtil
|
||||
import java.util.ArrayList
|
||||
import org.jetbrains.jet.lang.resolve.calls.model.ArgumentMapping
|
||||
import org.jetbrains.jet.lang.resolve.calls.model.ArgumentMatch
|
||||
import org.jetbrains.jet.lang.diagnostics.rendering.Renderers
|
||||
import org.jetbrains.jet.lang.resolve.calls.util.getAllValueArguments
|
||||
import org.jetbrains.jet.renderer.DescriptorRenderer
|
||||
|
||||
public abstract class AbstractResolvedCallsTest() : JetLiteFixture() {
|
||||
override fun createEnvironment(): JetCoreEnvironment = createEnvironmentWithMockJdk(ConfigurationKind.JDK_ONLY)
|
||||
@@ -43,6 +49,7 @@ public abstract class AbstractResolvedCallsTest() : JetLiteFixture() {
|
||||
val text = JetTestUtils.doLoadFile(file)
|
||||
val directives = JetTestUtils.parseDirectives(text)
|
||||
|
||||
val onlyArguments = directives.onlyArguments()
|
||||
val (callName, thisObject, receiverArgument) = with (directives) {
|
||||
Triple(get("CALL"), get("THIS_OBJECT"), get("RECEIVER_ARGUMENT"))
|
||||
}
|
||||
@@ -50,12 +57,14 @@ public abstract class AbstractResolvedCallsTest() : JetLiteFixture() {
|
||||
|
||||
fun analyzeFileAndGetResolvedCallEntries(): Map<JetElement, ResolvedCall<*>> {
|
||||
val psiFile = JetTestUtils.loadJetFile(getProject(), file)!!
|
||||
val analyzeExhaust = JvmResolveUtil.analyzeOneFileWithJavaIntegrationAndCheckForErrors(psiFile)
|
||||
val analyzeExhaust = JvmResolveUtil.analyzeOneFileWithJavaIntegration(psiFile)
|
||||
val bindingContext = analyzeExhaust.getBindingContext()
|
||||
return bindingContext.getSliceContents(BindingContext.RESOLVED_CALL)
|
||||
}
|
||||
|
||||
fun checkResolvedCall(resolvedCall: ResolvedCall<*>, element: JetElement) {
|
||||
if (onlyArguments) return
|
||||
|
||||
val lineAndColumn = DiagnosticUtils.getLineAndColumnInPsiFile(element.getContainingFile(), element.getTextRange())
|
||||
|
||||
val (actualThisObject, actualReceiverArgument, actualExplicitReceiverKind) = with(resolvedCall) {
|
||||
@@ -66,10 +75,26 @@ public abstract class AbstractResolvedCallsTest() : JetLiteFixture() {
|
||||
|
||||
assertEquals(thisObject, actualThisObject, "${actualDataMessage}This object mismatch: ")
|
||||
assertEquals(receiverArgument, actualReceiverArgument, "${actualDataMessage}Receiver argument mismatch: ")
|
||||
assertEquals(explicitReceiverKind, actualExplicitReceiverKind, "$actualDataMessage" +
|
||||
assertEquals(explicitReceiverKind, actualExplicitReceiverKind,
|
||||
"$actualDataMessage" +
|
||||
"Explicit receiver kind for resolved call for '${element.getText()}'$lineAndColumn in not as expected")
|
||||
}
|
||||
|
||||
val argumentsExpectedData = directives.getArgumentsExpectedData()
|
||||
fun checkArguments(resolvedCall: ResolvedCall<*>) {
|
||||
if (argumentsExpectedData.isEmpty()) return
|
||||
|
||||
for ((index, valueArgument) in resolvedCall.getCall().getAllValueArguments().withIndices()) {
|
||||
val (argText, argumentMapping) = argumentsExpectedData[index]
|
||||
if (argText != null) {
|
||||
assertEquals(argText, valueArgument.getArgumentExpression()!!.getText(),
|
||||
"An argument expression is incorrect")
|
||||
}
|
||||
assertEquals(argumentMapping, resolvedCall.getArgumentMapping(valueArgument).print(),
|
||||
"Argument mapping is incorrect")
|
||||
}
|
||||
}
|
||||
|
||||
var callFound = false
|
||||
for ((element, resolvedCall) in analyzeFileAndGetResolvedCallEntries()) {
|
||||
|
||||
@@ -77,6 +102,7 @@ public abstract class AbstractResolvedCallsTest() : JetLiteFixture() {
|
||||
if (callName == null || callName != actualName) return
|
||||
callFound = true
|
||||
checkResolvedCall(resolvedCall, element)
|
||||
checkArguments(resolvedCall)
|
||||
}
|
||||
|
||||
if (resolvedCall is VariableAsFunctionResolvedCall) {
|
||||
@@ -101,11 +127,12 @@ private fun ReceiverValue.getText() =
|
||||
else toString()
|
||||
|
||||
private val EXPLICIT_RECEIVER_KIND_DIRECTIVE: String = "EXPLICIT_RECEIVER_KIND"
|
||||
private fun Map<String, String>.getExplicitReceiverKind(): ExplicitReceiverKind {
|
||||
private fun Map<String, String>.getExplicitReceiverKind(): ExplicitReceiverKind? {
|
||||
if (onlyArguments()) return null
|
||||
|
||||
val explicitReceiverKind = get(EXPLICIT_RECEIVER_KIND_DIRECTIVE)
|
||||
assert(explicitReceiverKind != null) { "$EXPLICIT_RECEIVER_KIND_DIRECTIVE should be present." }
|
||||
try
|
||||
{
|
||||
try {
|
||||
return ExplicitReceiverKind.valueOf(explicitReceiverKind!!)
|
||||
}
|
||||
catch (e: IllegalArgumentException) {
|
||||
@@ -117,4 +144,32 @@ private fun Map<String, String>.getExplicitReceiverKind(): ExplicitReceiverKind
|
||||
message.append("\nnot $explicitReceiverKind.")
|
||||
throw AssertionError(message)
|
||||
}
|
||||
}
|
||||
|
||||
private fun Map<String, String>.getArgumentsExpectedData(): List<Pair<String?, String>> {
|
||||
val result = ArrayList<Pair<String?, String>>()
|
||||
for (i in 1..7) {
|
||||
val argData = get("ARG_$i")
|
||||
if (argData == null) continue
|
||||
|
||||
if (argData.contains("=")) {
|
||||
val strings = argData.split("=")
|
||||
assert(strings.size == 2, "Incorrect input data for an argument ARG_$i : $argData")
|
||||
result.add(Pair(strings[0].trim(), strings[1].trim()))
|
||||
}
|
||||
else {
|
||||
result.add(Pair(null, argData))
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
private fun Map<String, String>.onlyArguments() = containsKey("ONLY_ARGUMENTS")
|
||||
|
||||
fun ArgumentMapping.print() = when (this) {
|
||||
is ArgumentMatch -> {
|
||||
val parameterType = DescriptorRenderer.SHORT_NAMES_IN_TYPES.renderType(valueParameter.getType())
|
||||
"ArgumentMatch(${valueParameter.getName()} : ${parameterType}, ${status.name()})"
|
||||
}
|
||||
else -> "ArgumentUnmapped"
|
||||
}
|
||||
@@ -31,7 +31,7 @@ import org.jetbrains.jet.resolve.calls.AbstractResolvedCallsTest;
|
||||
/** This class is generated by {@link org.jetbrains.jet.generators.tests.TestsPackage}. DO NOT MODIFY MANUALLY */
|
||||
@SuppressWarnings("all")
|
||||
@TestMetadata("compiler/testData/resolvedCalls")
|
||||
@InnerTestClasses({ResolvedCallsTestGenerated.FunctionTypes.class, ResolvedCallsTestGenerated.Invoke.class, ResolvedCallsTestGenerated.RealExamples.class})
|
||||
@InnerTestClasses({ResolvedCallsTestGenerated.Arguments.class, ResolvedCallsTestGenerated.FunctionTypes.class, ResolvedCallsTestGenerated.Invoke.class, ResolvedCallsTestGenerated.RealExamples.class})
|
||||
public class ResolvedCallsTestGenerated extends AbstractResolvedCallsTest {
|
||||
public void testAllFilesPresentInResolvedCalls() throws Exception {
|
||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.TestsPackage", new File("compiler/testData/resolvedCalls"), Pattern.compile("^(.+)\\.kt$"), true);
|
||||
@@ -77,6 +77,169 @@ public class ResolvedCallsTestGenerated extends AbstractResolvedCallsTest {
|
||||
doTest("compiler/testData/resolvedCalls/simpleCall.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/resolvedCalls/arguments")
|
||||
@InnerTestClasses({Arguments.FunctionLiterals.class, Arguments.GenericCalls.class, Arguments.NamedArguments.class, Arguments.OneArgument.class, Arguments.RealExamples.class, Arguments.SeveralCandidates.class})
|
||||
public static class Arguments extends AbstractResolvedCallsTest {
|
||||
public void testAllFilesPresentInArguments() throws Exception {
|
||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.TestsPackage", new File("compiler/testData/resolvedCalls/arguments"), Pattern.compile("^(.+)\\.kt$"), true);
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/resolvedCalls/arguments/functionLiterals")
|
||||
public static class FunctionLiterals extends AbstractResolvedCallsTest {
|
||||
public void testAllFilesPresentInFunctionLiterals() throws Exception {
|
||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.TestsPackage", new File("compiler/testData/resolvedCalls/arguments/functionLiterals"), Pattern.compile("^(.+)\\.kt$"), true);
|
||||
}
|
||||
|
||||
@TestMetadata("chainedLambdas.kt")
|
||||
public void testChainedLambdas() throws Exception {
|
||||
doTest("compiler/testData/resolvedCalls/arguments/functionLiterals/chainedLambdas.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("notInferredLambdaReturnType.kt")
|
||||
public void testNotInferredLambdaReturnType() throws Exception {
|
||||
doTest("compiler/testData/resolvedCalls/arguments/functionLiterals/notInferredLambdaReturnType.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("notInferredLambdaType.kt")
|
||||
public void testNotInferredLambdaType() throws Exception {
|
||||
doTest("compiler/testData/resolvedCalls/arguments/functionLiterals/notInferredLambdaType.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("simpleGenericLambda.kt")
|
||||
public void testSimpleGenericLambda() throws Exception {
|
||||
doTest("compiler/testData/resolvedCalls/arguments/functionLiterals/simpleGenericLambda.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("simpleLambda.kt")
|
||||
public void testSimpleLambda() throws Exception {
|
||||
doTest("compiler/testData/resolvedCalls/arguments/functionLiterals/simpleLambda.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("unmappedLambda.kt")
|
||||
public void testUnmappedLambda() throws Exception {
|
||||
doTest("compiler/testData/resolvedCalls/arguments/functionLiterals/unmappedLambda.kt");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/resolvedCalls/arguments/genericCalls")
|
||||
public static class GenericCalls extends AbstractResolvedCallsTest {
|
||||
public void testAllFilesPresentInGenericCalls() throws Exception {
|
||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.TestsPackage", new File("compiler/testData/resolvedCalls/arguments/genericCalls"), Pattern.compile("^(.+)\\.kt$"), true);
|
||||
}
|
||||
|
||||
@TestMetadata("inferredParameter.kt")
|
||||
public void testInferredParameter() throws Exception {
|
||||
doTest("compiler/testData/resolvedCalls/arguments/genericCalls/inferredParameter.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("simpleGeneric.kt")
|
||||
public void testSimpleGeneric() throws Exception {
|
||||
doTest("compiler/testData/resolvedCalls/arguments/genericCalls/simpleGeneric.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("uninferredParameter.kt")
|
||||
public void testUninferredParameter() throws Exception {
|
||||
doTest("compiler/testData/resolvedCalls/arguments/genericCalls/uninferredParameter.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("uninferredParameterTypeMismatch.kt")
|
||||
public void testUninferredParameterTypeMismatch() throws Exception {
|
||||
doTest("compiler/testData/resolvedCalls/arguments/genericCalls/uninferredParameterTypeMismatch.kt");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/resolvedCalls/arguments/namedArguments")
|
||||
public static class NamedArguments extends AbstractResolvedCallsTest {
|
||||
public void testAllFilesPresentInNamedArguments() throws Exception {
|
||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.TestsPackage", new File("compiler/testData/resolvedCalls/arguments/namedArguments"), Pattern.compile("^(.+)\\.kt$"), true);
|
||||
}
|
||||
|
||||
@TestMetadata("positionedAfterNamed.kt")
|
||||
public void testPositionedAfterNamed() throws Exception {
|
||||
doTest("compiler/testData/resolvedCalls/arguments/namedArguments/positionedAfterNamed.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("shiftedArgsMatch.kt")
|
||||
public void testShiftedArgsMatch() throws Exception {
|
||||
doTest("compiler/testData/resolvedCalls/arguments/namedArguments/shiftedArgsMatch.kt");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/resolvedCalls/arguments/oneArgument")
|
||||
public static class OneArgument extends AbstractResolvedCallsTest {
|
||||
public void testAllFilesPresentInOneArgument() throws Exception {
|
||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.TestsPackage", new File("compiler/testData/resolvedCalls/arguments/oneArgument"), Pattern.compile("^(.+)\\.kt$"), true);
|
||||
}
|
||||
|
||||
@TestMetadata("argumentHasNoType.kt")
|
||||
public void testArgumentHasNoType() throws Exception {
|
||||
doTest("compiler/testData/resolvedCalls/arguments/oneArgument/argumentHasNoType.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("simpleMatch.kt")
|
||||
public void testSimpleMatch() throws Exception {
|
||||
doTest("compiler/testData/resolvedCalls/arguments/oneArgument/simpleMatch.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("typeMismatch.kt")
|
||||
public void testTypeMismatch() throws Exception {
|
||||
doTest("compiler/testData/resolvedCalls/arguments/oneArgument/typeMismatch.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("unmappedArgument.kt")
|
||||
public void testUnmappedArgument() throws Exception {
|
||||
doTest("compiler/testData/resolvedCalls/arguments/oneArgument/unmappedArgument.kt");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/resolvedCalls/arguments/realExamples")
|
||||
public static class RealExamples extends AbstractResolvedCallsTest {
|
||||
public void testAllFilesPresentInRealExamples() throws Exception {
|
||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.TestsPackage", new File("compiler/testData/resolvedCalls/arguments/realExamples"), Pattern.compile("^(.+)\\.kt$"), true);
|
||||
}
|
||||
|
||||
@TestMetadata("emptyList.kt")
|
||||
public void testEmptyList() throws Exception {
|
||||
doTest("compiler/testData/resolvedCalls/arguments/realExamples/emptyList.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("emptyMutableList.kt")
|
||||
public void testEmptyMutableList() throws Exception {
|
||||
doTest("compiler/testData/resolvedCalls/arguments/realExamples/emptyMutableList.kt");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/resolvedCalls/arguments/severalCandidates")
|
||||
public static class SeveralCandidates extends AbstractResolvedCallsTest {
|
||||
public void testAllFilesPresentInSeveralCandidates() throws Exception {
|
||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.TestsPackage", new File("compiler/testData/resolvedCalls/arguments/severalCandidates"), Pattern.compile("^(.+)\\.kt$"), true);
|
||||
}
|
||||
|
||||
@TestMetadata("mostSpecific.kt")
|
||||
public void testMostSpecific() throws Exception {
|
||||
doTest("compiler/testData/resolvedCalls/arguments/severalCandidates/mostSpecific.kt");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static Test innerSuite() {
|
||||
TestSuite suite = new TestSuite("Arguments");
|
||||
suite.addTestSuite(Arguments.class);
|
||||
suite.addTestSuite(FunctionLiterals.class);
|
||||
suite.addTestSuite(GenericCalls.class);
|
||||
suite.addTestSuite(NamedArguments.class);
|
||||
suite.addTestSuite(OneArgument.class);
|
||||
suite.addTestSuite(RealExamples.class);
|
||||
suite.addTestSuite(SeveralCandidates.class);
|
||||
return suite;
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/resolvedCalls/functionTypes")
|
||||
public static class FunctionTypes extends AbstractResolvedCallsTest {
|
||||
public void testAllFilesPresentInFunctionTypes() throws Exception {
|
||||
@@ -159,6 +322,7 @@ public class ResolvedCallsTestGenerated extends AbstractResolvedCallsTest {
|
||||
public static Test suite() {
|
||||
TestSuite suite = new TestSuite("ResolvedCallsTestGenerated");
|
||||
suite.addTestSuite(ResolvedCallsTestGenerated.class);
|
||||
suite.addTest(Arguments.innerSuite());
|
||||
suite.addTestSuite(FunctionTypes.class);
|
||||
suite.addTestSuite(Invoke.class);
|
||||
suite.addTestSuite(RealExamples.class);
|
||||
|
||||
Reference in New Issue
Block a user