Implement Unwrap/Remove for conditionals and loops
This commit is contained in:
@@ -0,0 +1,86 @@
|
||||
/*
|
||||
* Copyright 2010-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.plugin.codeInsight.unwrap;
|
||||
|
||||
import com.intellij.codeInsight.unwrap.Unwrapper;
|
||||
import com.intellij.openapi.util.Condition;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.testFramework.LightCodeInsightTestCase;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.InTextDirectivesUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class AbstractUnwrapRemoveTest extends LightCodeInsightTestCase {
|
||||
public void doTestThenUnwrapper(@NotNull String path) throws Exception {
|
||||
doTest(path, KoitlinUnwrappers.KotlinThenUnwrapper.class);
|
||||
}
|
||||
|
||||
public void doTestElseUnwrapper(@NotNull String path) throws Exception {
|
||||
doTest(path, KoitlinUnwrappers.KotlinElseUnwrapper.class);
|
||||
}
|
||||
|
||||
public void doTestElseRemover(@NotNull String path) throws Exception {
|
||||
doTest(path, KoitlinUnwrappers.KotlinElseRemover.class);
|
||||
}
|
||||
|
||||
public void doTestLoopUnwrapper(@NotNull String path) throws Exception {
|
||||
doTest(path, KoitlinUnwrappers.KotlinLoopUnwrapper.class);
|
||||
}
|
||||
|
||||
private void doTest(@NotNull String path, final Class<? extends Unwrapper> unwrapperClass) throws Exception {
|
||||
configureByFile(path);
|
||||
|
||||
String fileText = FileUtil.loadFile(new File(path), true);
|
||||
|
||||
String isApplicableString = InTextDirectivesUtils.findStringWithPrefixes(fileText, "// IS_APPLICABLE: ");
|
||||
boolean isApplicableExpected = isApplicableString == null || isApplicableString.equals("true");
|
||||
|
||||
String option = InTextDirectivesUtils.findStringWithPrefixes(fileText, "// OPTION: ");
|
||||
Integer optionIndex = option != null ? Integer.parseInt(option) : 0;
|
||||
|
||||
List<Pair<PsiElement, Unwrapper>> unwrappersWithPsi =
|
||||
new KotlinUnwrapDescriptor().collectUnwrappers(getProject(), getEditor(), getFile());
|
||||
|
||||
if (isApplicableExpected) {
|
||||
Pair<PsiElement, Unwrapper> selectedUnwrapperWithPsi = unwrappersWithPsi.get(optionIndex);
|
||||
assertEquals(unwrapperClass, selectedUnwrapperWithPsi.second.getClass());
|
||||
|
||||
selectedUnwrapperWithPsi.second.unwrap(getEditor(), selectedUnwrapperWithPsi.first);
|
||||
checkResultByFile(path + ".after");
|
||||
} else {
|
||||
assertTrue(
|
||||
ContainerUtil.and(unwrappersWithPsi, new Condition<Pair<PsiElement, Unwrapper>>() {
|
||||
@Override
|
||||
public boolean value(Pair<PsiElement, Unwrapper> pair) {
|
||||
return pair.second.getClass() != unwrapperClass;
|
||||
}
|
||||
})
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected String getTestDataPath() {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
+125
@@ -0,0 +1,125 @@
|
||||
/*
|
||||
* Copyright 2010-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.plugin.codeInsight.unwrap;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import junit.framework.Test;
|
||||
import junit.framework.TestSuite;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.regex.Pattern;
|
||||
import org.jetbrains.jet.JetTestUtils;
|
||||
import org.jetbrains.jet.test.InnerTestClasses;
|
||||
import org.jetbrains.jet.test.TestMetadata;
|
||||
|
||||
import org.jetbrains.jet.plugin.codeInsight.unwrap.AbstractUnwrapRemoveTest;
|
||||
|
||||
/** This class is generated by {@link org.jetbrains.jet.generators.tests.GenerateTests}. DO NOT MODIFY MANUALLY */
|
||||
@SuppressWarnings("all")
|
||||
@InnerTestClasses({UnwrapRemoveTestGenerated.UnwrapThen.class, UnwrapRemoveTestGenerated.UnwrapElse.class, UnwrapRemoveTestGenerated.RemoveElse.class, UnwrapRemoveTestGenerated.UnwrapLoop.class})
|
||||
public class UnwrapRemoveTestGenerated extends AbstractUnwrapRemoveTest {
|
||||
@TestMetadata("idea/testData/codeInsight/unwrapAndRemove/unwrapThen")
|
||||
public static class UnwrapThen extends AbstractUnwrapRemoveTest {
|
||||
public void testAllFilesPresentInUnwrapThen() throws Exception {
|
||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.GenerateTests", new File("idea/testData/codeInsight/unwrapAndRemove/unwrapThen"), Pattern.compile("^(.+)\\.kt$"), true);
|
||||
}
|
||||
|
||||
@TestMetadata("thenCompoundInBlock.kt")
|
||||
public void testThenCompoundInBlock() throws Exception {
|
||||
doTestThenUnwrapper("idea/testData/codeInsight/unwrapAndRemove/unwrapThen/thenCompoundInBlock.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("thenCompoundInReturn.kt")
|
||||
public void testThenCompoundInReturn() throws Exception {
|
||||
doTestThenUnwrapper("idea/testData/codeInsight/unwrapAndRemove/unwrapThen/thenCompoundInReturn.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("thenSimpleInReturn.kt")
|
||||
public void testThenSimpleInReturn() throws Exception {
|
||||
doTestThenUnwrapper("idea/testData/codeInsight/unwrapAndRemove/unwrapThen/thenSimpleInReturn.kt");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@TestMetadata("idea/testData/codeInsight/unwrapAndRemove/unwrapElse")
|
||||
public static class UnwrapElse extends AbstractUnwrapRemoveTest {
|
||||
public void testAllFilesPresentInUnwrapElse() throws Exception {
|
||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.GenerateTests", new File("idea/testData/codeInsight/unwrapAndRemove/unwrapElse"), Pattern.compile("^(.+)\\.kt$"), true);
|
||||
}
|
||||
|
||||
@TestMetadata("elseCompoundInBlock.kt")
|
||||
public void testElseCompoundInBlock() throws Exception {
|
||||
doTestElseUnwrapper("idea/testData/codeInsight/unwrapAndRemove/unwrapElse/elseCompoundInBlock.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("elseCompoundInReturn.kt")
|
||||
public void testElseCompoundInReturn() throws Exception {
|
||||
doTestElseUnwrapper("idea/testData/codeInsight/unwrapAndRemove/unwrapElse/elseCompoundInReturn.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("elseSimpleInReturn.kt")
|
||||
public void testElseSimpleInReturn() throws Exception {
|
||||
doTestElseUnwrapper("idea/testData/codeInsight/unwrapAndRemove/unwrapElse/elseSimpleInReturn.kt");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@TestMetadata("idea/testData/codeInsight/unwrapAndRemove/removeElse")
|
||||
public static class RemoveElse extends AbstractUnwrapRemoveTest {
|
||||
public void testAllFilesPresentInRemoveElse() throws Exception {
|
||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.GenerateTests", new File("idea/testData/codeInsight/unwrapAndRemove/removeElse"), Pattern.compile("^(.+)\\.kt$"), true);
|
||||
}
|
||||
|
||||
@TestMetadata("else.kt")
|
||||
public void testElse() throws Exception {
|
||||
doTestElseRemover("idea/testData/codeInsight/unwrapAndRemove/removeElse/else.kt");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@TestMetadata("idea/testData/codeInsight/unwrapAndRemove/unwrapLoop")
|
||||
public static class UnwrapLoop extends AbstractUnwrapRemoveTest {
|
||||
public void testAllFilesPresentInUnwrapLoop() throws Exception {
|
||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.GenerateTests", new File("idea/testData/codeInsight/unwrapAndRemove/unwrapLoop"), Pattern.compile("^(.+)\\.kt$"), true);
|
||||
}
|
||||
|
||||
@TestMetadata("doWhile.kt")
|
||||
public void testDoWhile() throws Exception {
|
||||
doTestLoopUnwrapper("idea/testData/codeInsight/unwrapAndRemove/unwrapLoop/doWhile.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("for.kt")
|
||||
public void testFor() throws Exception {
|
||||
doTestLoopUnwrapper("idea/testData/codeInsight/unwrapAndRemove/unwrapLoop/for.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("while.kt")
|
||||
public void testWhile() throws Exception {
|
||||
doTestLoopUnwrapper("idea/testData/codeInsight/unwrapAndRemove/unwrapLoop/while.kt");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static Test suite() {
|
||||
TestSuite suite = new TestSuite("UnwrapRemoveTestGenerated");
|
||||
suite.addTestSuite(UnwrapThen.class);
|
||||
suite.addTestSuite(UnwrapElse.class);
|
||||
suite.addTestSuite(RemoveElse.class);
|
||||
suite.addTestSuite(UnwrapLoop.class);
|
||||
return suite;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user