Auto-generate test class for "Introduce variable" refactoring

This commit is contained in:
Alexey Sedunov
2014-04-08 17:06:52 +04:00
parent a72d785d62
commit 6006f53e68
4 changed files with 247 additions and 172 deletions
@@ -104,6 +104,7 @@ import org.jetbrains.jet.plugin.stubs.AbstractStubBuilderTest
import org.jetbrains.jet.plugin.codeInsight.AbstractJetInspectionTest
import org.jetbrains.jet.plugin.debugger.AbstractKotlinSteppingTest
import org.jetbrains.jet.completion.AbstractMultiFileJvmBasicCompletionTest
import org.jetbrains.jet.plugin.refactoring.introduce.introduceVariable.AbstractJetIntroduceVariableTest
fun main(args: Array<String>) {
System.setProperty("java.awt.headless", "true")
@@ -561,6 +562,10 @@ fun main(args: Array<String>) {
testClass(javaClass<AbstractMultiFileJvmBasicCompletionTest>()) {
model("completion/basic/multifile", pattern = """^([^\.]+)\.kt$""")
}
testClass(javaClass<AbstractJetIntroduceVariableTest>()) {
model("refactoring/introduceVariable", extension = "kt")
}
}
testGroup("j2k/tests/test", "j2k/tests/testData") {
@@ -0,0 +1,63 @@
/*
* 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.refactoring.introduce.introduceVariable;
import com.intellij.ide.DataManager;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.psi.PsiElement;
import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.JetTestCaseBuilder;
import org.jetbrains.jet.lang.psi.JetFile;
import org.jetbrains.jet.lexer.JetTokens;
import java.io.File;
public abstract class AbstractJetIntroduceVariableTest extends LightCodeInsightFixtureTestCase {
protected void doTest(@NotNull String path) {
File mainFile = new File(path);
myFixture.setTestDataPath(JetTestCaseBuilder.getHomeDirectory() + "/" + mainFile.getParent());
final JetFile file = (JetFile) myFixture.configureByFile(mainFile.getName());
PsiElement lastChild = file.getLastChild();
assert lastChild != null;
String expectedResultText = null;
if (lastChild.getNode().getElementType().equals(JetTokens.BLOCK_COMMENT)) {
String lastChildText = lastChild.getText();
expectedResultText = lastChildText.substring(2, lastChildText.length() - 2).trim();
}
else if (lastChild.getNode().getElementType().equals(JetTokens.EOL_COMMENT)) {
expectedResultText = lastChild.getText().substring(2).trim();
}
assert expectedResultText != null;
ApplicationManager.getApplication().runWriteAction(new Runnable() {
@Override
public void run() {
new KotlinIntroduceVariableHandler().invoke(getProject(), myFixture.getEditor(), file,
DataManager.getInstance().getDataContext(myFixture.getEditor().
getComponent()));
}
});
int endOffset = file.getLastChild().getTextRange().getStartOffset();
assertEquals(expectedResultText, file.getText().substring(0, endOffset).trim());
}
}
@@ -1,172 +0,0 @@
/*
* 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.refactoring.introduce.introduceVariable;
import com.intellij.ide.DataManager;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.psi.PsiElement;
import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase;
import org.jetbrains.jet.lang.psi.JetFile;
import org.jetbrains.jet.lexer.JetTokens;
import org.jetbrains.jet.plugin.PluginTestCaseBase;
public class JetIntroduceVariableTest extends LightCodeInsightFixtureTestCase {
public void testClassBody() {
doTest();
}
public void testDoWhileAddBlock() {
doTest();
}
public void testDoWhileAddBlockInner() {
doTest();
}
public void testFewOccurrences() {
doTest();
}
public void testFunctionAddBlock() {
doTest();
}
public void testFunctionAddBlockInner() {
doTest();
}
public void testFunctionLiteral() {
doTest();
}
public void testFunctionLiteralFromExpected() {
doTest();
}
public void testIfCondition() {
doTest();
}
public void testIfElseAddBlock() {
doTest();
}
public void testIfElseAddBlockInner() {
doTest();
}
public void testIfThenAddBlock() {
doTest();
}
public void testIfThenAddBlockInner() {
doTest();
}
public void testIt() {
doTest();
}
public void testLoopRange() {
doTest();
}
public void testManyInnerOccurences() {
doTest();
}
public void testManyOccurrences() {
doTest();
}
public void testReplaceOccurence() {
doTest();
}
public void testSimple() {
doTest();
}
public void testSimpleCreateValue() {
doTest();
}
public void testStringInjection() {
doTest();
}
public void testWhenAddBlock() {
doTest();
}
public void testWhenAddBlockInner() {
doTest();
}
public void testWhenParts() {
doTest();
}
public void testWhileAddBlock() {
doTest();
}
public void testWhileAddBlockInner() {
doTest();
}
public void testWhileCondition() {
doTest();
}
public void testArrayAccessExpr() {
doTest();
}
@Override
protected void setUp() throws Exception {
super.setUp();
myFixture.setTestDataPath(PluginTestCaseBase.getTestDataPathBase() + "/refactoring/introduceVariable");
}
private void doTest() {
myFixture.configureByFile(getTestName(false) + ".kt");
final JetFile file = (JetFile) myFixture.getFile();
PsiElement lastChild = file.getLastChild();
assert lastChild != null;
String expectedResultText = null;
if (lastChild.getNode().getElementType().equals(JetTokens.BLOCK_COMMENT)) {
String lastChildText = lastChild.getText();
expectedResultText = lastChildText.substring(2, lastChildText.length() - 2).trim();
}
else if (lastChild.getNode().getElementType().equals(JetTokens.EOL_COMMENT)) {
expectedResultText = lastChild.getText().substring(2).trim();
}
assert expectedResultText != null;
ApplicationManager.getApplication().runWriteAction(new Runnable() {
@Override
public void run() {
new KotlinIntroduceVariableHandler().invoke(getProject(), myFixture.getEditor(), file,
DataManager.getInstance().getDataContext(myFixture.getEditor().
getComponent()));
}
});
int endOffset = file.getLastChild().getTextRange().getStartOffset();
// System.out.println(file.getText().substring(0, endOffset).trim());
assertEquals(expectedResultText, file.getText().substring(0, endOffset).trim());
}
}
@@ -0,0 +1,179 @@
/*
* Copyright 2010-2014 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.refactoring.introduce.introduceVariable;
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.refactoring.introduce.introduceVariable.AbstractJetIntroduceVariableTest;
/** This class is generated by {@link org.jetbrains.jet.generators.tests.TestsPackage}. DO NOT MODIFY MANUALLY */
@SuppressWarnings("all")
@TestMetadata("idea/testData/refactoring/introduceVariable")
public class JetIntroduceVariableTestGenerated extends AbstractJetIntroduceVariableTest {
public void testAllFilesPresentInIntroduceVariable() throws Exception {
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.TestsPackage", new File("idea/testData/refactoring/introduceVariable"), Pattern.compile("^(.+)\\.kt$"), true);
}
@TestMetadata("ArrayAccessExpr.kt")
public void testArrayAccessExpr() throws Exception {
doTest("idea/testData/refactoring/introduceVariable/ArrayAccessExpr.kt");
}
@TestMetadata("ClassBody.kt")
public void testClassBody() throws Exception {
doTest("idea/testData/refactoring/introduceVariable/ClassBody.kt");
}
@TestMetadata("DoWhileAddBlock.kt")
public void testDoWhileAddBlock() throws Exception {
doTest("idea/testData/refactoring/introduceVariable/DoWhileAddBlock.kt");
}
@TestMetadata("DoWhileAddBlockInner.kt")
public void testDoWhileAddBlockInner() throws Exception {
doTest("idea/testData/refactoring/introduceVariable/DoWhileAddBlockInner.kt");
}
@TestMetadata("FewOccurrences.kt")
public void testFewOccurrences() throws Exception {
doTest("idea/testData/refactoring/introduceVariable/FewOccurrences.kt");
}
@TestMetadata("FunctionAddBlock.kt")
public void testFunctionAddBlock() throws Exception {
doTest("idea/testData/refactoring/introduceVariable/FunctionAddBlock.kt");
}
@TestMetadata("FunctionAddBlockInner.kt")
public void testFunctionAddBlockInner() throws Exception {
doTest("idea/testData/refactoring/introduceVariable/FunctionAddBlockInner.kt");
}
@TestMetadata("FunctionLiteral.kt")
public void testFunctionLiteral() throws Exception {
doTest("idea/testData/refactoring/introduceVariable/FunctionLiteral.kt");
}
@TestMetadata("FunctionLiteralFromExpected.kt")
public void testFunctionLiteralFromExpected() throws Exception {
doTest("idea/testData/refactoring/introduceVariable/FunctionLiteralFromExpected.kt");
}
@TestMetadata("IfCondition.kt")
public void testIfCondition() throws Exception {
doTest("idea/testData/refactoring/introduceVariable/IfCondition.kt");
}
@TestMetadata("IfElseAddBlock.kt")
public void testIfElseAddBlock() throws Exception {
doTest("idea/testData/refactoring/introduceVariable/IfElseAddBlock.kt");
}
@TestMetadata("IfElseAddBlockInner.kt")
public void testIfElseAddBlockInner() throws Exception {
doTest("idea/testData/refactoring/introduceVariable/IfElseAddBlockInner.kt");
}
@TestMetadata("IfThenAddBlock.kt")
public void testIfThenAddBlock() throws Exception {
doTest("idea/testData/refactoring/introduceVariable/IfThenAddBlock.kt");
}
@TestMetadata("IfThenAddBlockInner.kt")
public void testIfThenAddBlockInner() throws Exception {
doTest("idea/testData/refactoring/introduceVariable/IfThenAddBlockInner.kt");
}
@TestMetadata("It.kt")
public void testIt() throws Exception {
doTest("idea/testData/refactoring/introduceVariable/It.kt");
}
@TestMetadata("LoopRange.kt")
public void testLoopRange() throws Exception {
doTest("idea/testData/refactoring/introduceVariable/LoopRange.kt");
}
@TestMetadata("ManyInnerOccurences.kt")
public void testManyInnerOccurences() throws Exception {
doTest("idea/testData/refactoring/introduceVariable/ManyInnerOccurences.kt");
}
@TestMetadata("ManyOccurrences.kt")
public void testManyOccurrences() throws Exception {
doTest("idea/testData/refactoring/introduceVariable/ManyOccurrences.kt");
}
@TestMetadata("ReplaceOccurence.kt")
public void testReplaceOccurence() throws Exception {
doTest("idea/testData/refactoring/introduceVariable/ReplaceOccurence.kt");
}
@TestMetadata("Simple.kt")
public void testSimple() throws Exception {
doTest("idea/testData/refactoring/introduceVariable/Simple.kt");
}
@TestMetadata("SimpleCreateValue.kt")
public void testSimpleCreateValue() throws Exception {
doTest("idea/testData/refactoring/introduceVariable/SimpleCreateValue.kt");
}
@TestMetadata("StringInjection.kt")
public void testStringInjection() throws Exception {
doTest("idea/testData/refactoring/introduceVariable/StringInjection.kt");
}
@TestMetadata("WhenAddBlock.kt")
public void testWhenAddBlock() throws Exception {
doTest("idea/testData/refactoring/introduceVariable/WhenAddBlock.kt");
}
@TestMetadata("WhenAddBlockInner.kt")
public void testWhenAddBlockInner() throws Exception {
doTest("idea/testData/refactoring/introduceVariable/WhenAddBlockInner.kt");
}
@TestMetadata("WhenParts.kt")
public void testWhenParts() throws Exception {
doTest("idea/testData/refactoring/introduceVariable/WhenParts.kt");
}
@TestMetadata("WhileAddBlock.kt")
public void testWhileAddBlock() throws Exception {
doTest("idea/testData/refactoring/introduceVariable/WhileAddBlock.kt");
}
@TestMetadata("WhileAddBlockInner.kt")
public void testWhileAddBlockInner() throws Exception {
doTest("idea/testData/refactoring/introduceVariable/WhileAddBlockInner.kt");
}
@TestMetadata("WhileCondition.kt")
public void testWhileCondition() throws Exception {
doTest("idea/testData/refactoring/introduceVariable/WhileCondition.kt");
}
}