Add tests for unfolding to 'when'

This commit is contained in:
Alexey Sedunov
2013-04-16 15:18:00 +04:00
parent 64e578297c
commit 09b4a5afa3
14 changed files with 200 additions and 2 deletions
@@ -0,0 +1,21 @@
fun test(n: Int): String {
var res: String
if (3 > 2) {
<caret>res = when(n) {
1 -> {
println("***")
"one"
}
else -> {
println("***")
"two"
}
}
} else {
println("***")
res = "???"
}
return res
}
@@ -0,0 +1,21 @@
fun test(n: Int): String {
var res: String
if (3 > 2) {
<caret>when(n) {
1 -> {
println("***")
res = "one"
}
else -> {
println("***")
res = "two"
}
}
} else {
println("***")
res = "???"
}
return res
}
@@ -0,0 +1,10 @@
fun test(n: Int): String {
var res: String
<caret>res = when(n) {
1 -> "one"
else -> "two"
}
return res
}
@@ -0,0 +1,10 @@
fun test(n: Int): String {
var res: String
<caret>when(n) {
1 -> res = "one"
else -> res = "two"
}
return res
}
@@ -0,0 +1,16 @@
fun test(n: Int): String {
var res: String
<caret>res = when (n) {
1 -> {
println("***")
"one"
}
else -> {
println("***")
"two"
}
}
return res
}
@@ -0,0 +1,16 @@
fun test(n: Int): String {
var res: String
<caret>when (n) {
1 -> {
println("***")
res = "one"
}
else -> {
println("***")
res = "two"
}
}
return res
}
@@ -0,0 +1,11 @@
fun test(n: Int): String {
if (3 > 2) {
<caret>return when (n) {
1 -> "one"
else -> "two"
}
} else {
println("***")
return "???"
}
}
@@ -0,0 +1,11 @@
fun test(n: Int): String {
if (3 > 2) {
<caret>when (n) {
1 -> return "one"
else -> return "two"
}
} else {
println("***")
return "???"
}
}
@@ -0,0 +1,6 @@
fun test(n: Int): String {
<caret>return when (n) {
1 -> "one"
else -> "two"
}
}
@@ -0,0 +1,6 @@
fun test(n: Int): String {
<caret>when (n) {
1 -> return "one"
else -> return "two"
}
}
@@ -0,0 +1,11 @@
fun test(n: Int): String {
<caret>return when(n) {
1 -> {
println("***")
"one"
}
else -> {
println("***")
"two"
}
}
@@ -0,0 +1,11 @@
fun test(n: Int): String {
<caret>when(n) {
1 -> {
println("***")
return "one"
}
else -> {
println("***")
return "two"
}
}
@@ -59,7 +59,7 @@ public abstract class AbstractCodeTransformationTest extends LightCodeInsightTes
}
public void doTestUnfoldReturnToWhen(@NotNull String path) throws Exception {
doTest(path, new UnfoldAssignmentToIfIntention());
doTest(path, new UnfoldReturnToWhenIntention());
}
public void doTestRemoveUnnecessaryParentheses(@NotNull String path) throws Exception {
@@ -30,7 +30,7 @@ import org.jetbrains.jet.plugin.codeInsight.codeTransformations.AbstractCodeTran
/** This class is generated by {@link org.jetbrains.jet.generators.tests.GenerateTests}. DO NOT MODIFY MANUALLY */
@SuppressWarnings("all")
@InnerTestClasses({CodeTransformationsTestGenerated.IfToAssignment.class, CodeTransformationsTestGenerated.IfToReturn.class, CodeTransformationsTestGenerated.IfToReturnAsymmetrically.class, CodeTransformationsTestGenerated.WhenToAssignment.class, CodeTransformationsTestGenerated.WhenToReturn.class, CodeTransformationsTestGenerated.AssignmentToIf.class, CodeTransformationsTestGenerated.ReturnToIf.class})
@InnerTestClasses({CodeTransformationsTestGenerated.IfToAssignment.class, CodeTransformationsTestGenerated.IfToReturn.class, CodeTransformationsTestGenerated.IfToReturnAsymmetrically.class, CodeTransformationsTestGenerated.WhenToAssignment.class, CodeTransformationsTestGenerated.WhenToReturn.class, CodeTransformationsTestGenerated.AssignmentToIf.class, CodeTransformationsTestGenerated.AssignmentToWhen.class, CodeTransformationsTestGenerated.ReturnToIf.class, CodeTransformationsTestGenerated.ReturnToWhen.class})
public class CodeTransformationsTestGenerated extends AbstractCodeTransformationTest {
@TestMetadata("idea/testData/codeInsight/codeTransformations/branched/folding/ifToAssignment")
public static class IfToAssignment extends AbstractCodeTransformationTest {
@@ -230,6 +230,29 @@ public class CodeTransformationsTestGenerated extends AbstractCodeTransformation
}
@TestMetadata("idea/testData/codeInsight/codeTransformations/branched/unfolding/assignmentToWhen")
public static class AssignmentToWhen extends AbstractCodeTransformationTest {
public void testAllFilesPresentInAssignmentToWhen() throws Exception {
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.GenerateTests", new File("idea/testData/codeInsight/codeTransformations/branched/unfolding/assignmentToWhen"), Pattern.compile("^(.+)\\.kt$"), true);
}
@TestMetadata("innerWhenTransformed.kt")
public void testInnerWhenTransformed() throws Exception {
doTestUnfoldAssignmentToWhen("idea/testData/codeInsight/codeTransformations/branched/unfolding/assignmentToWhen/innerWhenTransformed.kt");
}
@TestMetadata("simpleWhen.kt")
public void testSimpleWhen() throws Exception {
doTestUnfoldAssignmentToWhen("idea/testData/codeInsight/codeTransformations/branched/unfolding/assignmentToWhen/simpleWhen.kt");
}
@TestMetadata("simpleWhenWithBlocks.kt")
public void testSimpleWhenWithBlocks() throws Exception {
doTestUnfoldAssignmentToWhen("idea/testData/codeInsight/codeTransformations/branched/unfolding/assignmentToWhen/simpleWhenWithBlocks.kt");
}
}
@TestMetadata("idea/testData/codeInsight/codeTransformations/branched/unfolding/returnToIf")
public static class ReturnToIf extends AbstractCodeTransformationTest {
public void testAllFilesPresentInReturnToIf() throws Exception {
@@ -253,6 +276,29 @@ public class CodeTransformationsTestGenerated extends AbstractCodeTransformation
}
@TestMetadata("idea/testData/codeInsight/codeTransformations/branched/unfolding/returnToWhen")
public static class ReturnToWhen extends AbstractCodeTransformationTest {
public void testAllFilesPresentInReturnToWhen() throws Exception {
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.GenerateTests", new File("idea/testData/codeInsight/codeTransformations/branched/unfolding/returnToWhen"), Pattern.compile("^(.+)\\.kt$"), true);
}
@TestMetadata("innerWhenTransformed.kt")
public void testInnerWhenTransformed() throws Exception {
doTestUnfoldReturnToWhen("idea/testData/codeInsight/codeTransformations/branched/unfolding/returnToWhen/innerWhenTransformed.kt");
}
@TestMetadata("simpleWhen.kt")
public void testSimpleWhen() throws Exception {
doTestUnfoldReturnToWhen("idea/testData/codeInsight/codeTransformations/branched/unfolding/returnToWhen/simpleWhen.kt");
}
@TestMetadata("simpleWhenWithBlocks.kt")
public void testSimpleWhenWithBlocks() throws Exception {
doTestUnfoldReturnToWhen("idea/testData/codeInsight/codeTransformations/branched/unfolding/returnToWhen/simpleWhenWithBlocks.kt");
}
}
public static Test suite() {
TestSuite suite = new TestSuite("CodeTransformationsTestGenerated");
suite.addTestSuite(IfToAssignment.class);
@@ -261,7 +307,9 @@ public class CodeTransformationsTestGenerated extends AbstractCodeTransformation
suite.addTestSuite(WhenToAssignment.class);
suite.addTestSuite(WhenToReturn.class);
suite.addTestSuite(AssignmentToIf.class);
suite.addTestSuite(AssignmentToWhen.class);
suite.addTestSuite(ReturnToIf.class);
suite.addTestSuite(ReturnToWhen.class);
return suite;
}
}