Added/updated tests for LexicalScope.
This commit is contained in:
@@ -20,6 +20,7 @@ import com.google.common.collect.Sets;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import kotlin.Function3;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.ConfigurationKind;
|
||||
import org.jetbrains.jet.JetTestUtils;
|
||||
import org.jetbrains.jet.analyzer.AnalyzeExhaust;
|
||||
@@ -125,11 +126,27 @@ public abstract class AbstractPseudocodeTest extends KotlinTestWithEnvironment {
|
||||
protected void checkPseudocode(PseudocodeImpl pseudocode) {
|
||||
}
|
||||
|
||||
private static String formatInstruction(Instruction instruction, int maxLength, Set<Instruction> remainedAfterPostProcessInstructions) {
|
||||
String[] parts = instruction.toString().split("\n");
|
||||
private String getIsDeadInstructionPrefix(
|
||||
@NotNull Instruction instruction,
|
||||
@NotNull Set<Instruction> remainedAfterPostProcessInstructions
|
||||
) {
|
||||
boolean isRemovedThroughPostProcess = !remainedAfterPostProcessInstructions.contains(instruction);
|
||||
assert isRemovedThroughPostProcess == ((InstructionImpl)instruction).isDead();
|
||||
String prefix = isRemovedThroughPostProcess ? "- " : " ";
|
||||
return isRemovedThroughPostProcess ? "-" : " ";
|
||||
}
|
||||
|
||||
private String getDepthInstructionPrefix(@NotNull Instruction instruction, @Nullable Instruction previous) {
|
||||
Integer prevDepth = previous != null ? previous.getLexicalScope().getDepth() : null;
|
||||
int depth = instruction.getLexicalScope().getDepth();
|
||||
if (prevDepth == null || depth != prevDepth) {
|
||||
return String.format("%2d ", depth);
|
||||
}
|
||||
return " ";
|
||||
}
|
||||
|
||||
private String formatInstruction(Instruction instruction, int maxLength, String prefix) {
|
||||
String[] parts = instruction.toString().split("\n");
|
||||
|
||||
if (parts.length == 1) {
|
||||
return prefix + String.format("%1$-" + maxLength + "s", instruction);
|
||||
}
|
||||
@@ -168,11 +185,14 @@ public abstract class AbstractPseudocodeTest extends KotlinTestWithEnvironment {
|
||||
|
||||
StringBuilder line = new StringBuilder();
|
||||
|
||||
line.append(formatInstruction(instruction, instructionColumnWidth, remainedAfterPostProcessInstructions));
|
||||
|
||||
// Only print NEXT and PREV if the values are non-trivial
|
||||
Instruction next = i == instructions.size() - 1 ? null : instructions.get(i + 1);
|
||||
Instruction prev = i == 0 ? null : instructions.get(i - 1);
|
||||
|
||||
String prefix = getIsDeadInstructionPrefix(instruction, remainedAfterPostProcessInstructions) +
|
||||
getDepthInstructionPrefix(instruction, prev);
|
||||
line.append(formatInstruction(instruction, instructionColumnWidth, prefix));
|
||||
|
||||
line.append(getInstructionData.invoke(instruction, next, prev));
|
||||
|
||||
out.append(StringUtil.trimTrailing(line.toString()));
|
||||
|
||||
@@ -31,7 +31,7 @@ import org.jetbrains.jet.cfg.AbstractDataFlowTest;
|
||||
/** This class is generated by {@link org.jetbrains.jet.generators.tests.TestsPackage}. DO NOT MODIFY MANUALLY */
|
||||
@SuppressWarnings("all")
|
||||
@TestMetadata("compiler/testData/cfg-variables")
|
||||
@InnerTestClasses({DataFlowTestGenerated.Basic.class})
|
||||
@InnerTestClasses({DataFlowTestGenerated.Basic.class, DataFlowTestGenerated.LexicalScopes.class})
|
||||
public class DataFlowTestGenerated extends AbstractDataFlowTest {
|
||||
public void testAllFilesPresentInCfg_variables() throws Exception {
|
||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.TestsPackage", new File("compiler/testData/cfg-variables"), Pattern.compile("^(.+)\\.kt$"), true);
|
||||
@@ -70,10 +70,79 @@ public class DataFlowTestGenerated extends AbstractDataFlowTest {
|
||||
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/cfg-variables/lexicalScopes")
|
||||
public static class LexicalScopes extends AbstractDataFlowTest {
|
||||
public void testAllFilesPresentInLexicalScopes() throws Exception {
|
||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.TestsPackage", new File("compiler/testData/cfg-variables/lexicalScopes"), Pattern.compile("^(.+)\\.kt$"), true);
|
||||
}
|
||||
|
||||
@TestMetadata("doWhileScope.kt")
|
||||
public void testDoWhileScope() throws Exception {
|
||||
doTest("compiler/testData/cfg-variables/lexicalScopes/doWhileScope.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("forScope.kt")
|
||||
public void testForScope() throws Exception {
|
||||
doTest("compiler/testData/cfg-variables/lexicalScopes/forScope.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("functionLiteralScope.kt")
|
||||
public void testFunctionLiteralScope() throws Exception {
|
||||
doTest("compiler/testData/cfg-variables/lexicalScopes/functionLiteralScope.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("ifScope.kt")
|
||||
public void testIfScope() throws Exception {
|
||||
doTest("compiler/testData/cfg-variables/lexicalScopes/ifScope.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("localClass.kt")
|
||||
public void testLocalClass() throws Exception {
|
||||
doTest("compiler/testData/cfg-variables/lexicalScopes/localClass.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("localFunctionScope.kt")
|
||||
public void testLocalFunctionScope() throws Exception {
|
||||
doTest("compiler/testData/cfg-variables/lexicalScopes/localFunctionScope.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("localFunctionScopeWithoutBody.kt")
|
||||
public void testLocalFunctionScopeWithoutBody() throws Exception {
|
||||
doTest("compiler/testData/cfg-variables/lexicalScopes/localFunctionScopeWithoutBody.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("localObject.kt")
|
||||
public void testLocalObject() throws Exception {
|
||||
doTest("compiler/testData/cfg-variables/lexicalScopes/localObject.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("objectLiteralScope.kt")
|
||||
public void testObjectLiteralScope() throws Exception {
|
||||
doTest("compiler/testData/cfg-variables/lexicalScopes/objectLiteralScope.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("propertyAccessorScope.kt")
|
||||
public void testPropertyAccessorScope() throws Exception {
|
||||
doTest("compiler/testData/cfg-variables/lexicalScopes/propertyAccessorScope.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("tryScope.kt")
|
||||
public void testTryScope() throws Exception {
|
||||
doTest("compiler/testData/cfg-variables/lexicalScopes/tryScope.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("whileScope.kt")
|
||||
public void testWhileScope() throws Exception {
|
||||
doTest("compiler/testData/cfg-variables/lexicalScopes/whileScope.kt");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static Test suite() {
|
||||
TestSuite suite = new TestSuite("DataFlowTestGenerated");
|
||||
suite.addTestSuite(DataFlowTestGenerated.class);
|
||||
suite.addTestSuite(Basic.class);
|
||||
suite.addTestSuite(LexicalScopes.class);
|
||||
return suite;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user