From 6006f53e681a53d52740c7ef025ee27e96bbc0ec Mon Sep 17 00:00:00 2001 From: Alexey Sedunov Date: Tue, 8 Apr 2014 17:06:52 +0400 Subject: [PATCH] Auto-generate test class for "Introduce variable" refactoring --- .../jet/generators/tests/GenerateTests.kt | 5 + .../AbstractJetIntroduceVariableTest.java | 63 ++++++ .../JetIntroduceVariableTest.java | 172 ----------------- .../JetIntroduceVariableTestGenerated.java | 179 ++++++++++++++++++ 4 files changed, 247 insertions(+), 172 deletions(-) create mode 100644 idea/tests/org/jetbrains/jet/plugin/refactoring/introduce/introduceVariable/AbstractJetIntroduceVariableTest.java delete mode 100644 idea/tests/org/jetbrains/jet/plugin/refactoring/introduce/introduceVariable/JetIntroduceVariableTest.java create mode 100644 idea/tests/org/jetbrains/jet/plugin/refactoring/introduce/introduceVariable/JetIntroduceVariableTestGenerated.java diff --git a/generators/src/org/jetbrains/jet/generators/tests/GenerateTests.kt b/generators/src/org/jetbrains/jet/generators/tests/GenerateTests.kt index eba79973b0e..4ad7701216f 100644 --- a/generators/src/org/jetbrains/jet/generators/tests/GenerateTests.kt +++ b/generators/src/org/jetbrains/jet/generators/tests/GenerateTests.kt @@ -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) { System.setProperty("java.awt.headless", "true") @@ -561,6 +562,10 @@ fun main(args: Array) { testClass(javaClass()) { model("completion/basic/multifile", pattern = """^([^\.]+)\.kt$""") } + + testClass(javaClass()) { + model("refactoring/introduceVariable", extension = "kt") + } } testGroup("j2k/tests/test", "j2k/tests/testData") { diff --git a/idea/tests/org/jetbrains/jet/plugin/refactoring/introduce/introduceVariable/AbstractJetIntroduceVariableTest.java b/idea/tests/org/jetbrains/jet/plugin/refactoring/introduce/introduceVariable/AbstractJetIntroduceVariableTest.java new file mode 100644 index 00000000000..c707b0e406c --- /dev/null +++ b/idea/tests/org/jetbrains/jet/plugin/refactoring/introduce/introduceVariable/AbstractJetIntroduceVariableTest.java @@ -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()); + } +} diff --git a/idea/tests/org/jetbrains/jet/plugin/refactoring/introduce/introduceVariable/JetIntroduceVariableTest.java b/idea/tests/org/jetbrains/jet/plugin/refactoring/introduce/introduceVariable/JetIntroduceVariableTest.java deleted file mode 100644 index 24ac1528fc9..00000000000 --- a/idea/tests/org/jetbrains/jet/plugin/refactoring/introduce/introduceVariable/JetIntroduceVariableTest.java +++ /dev/null @@ -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()); - } -} diff --git a/idea/tests/org/jetbrains/jet/plugin/refactoring/introduce/introduceVariable/JetIntroduceVariableTestGenerated.java b/idea/tests/org/jetbrains/jet/plugin/refactoring/introduce/introduceVariable/JetIntroduceVariableTestGenerated.java new file mode 100644 index 00000000000..d41ea7f5fc9 --- /dev/null +++ b/idea/tests/org/jetbrains/jet/plugin/refactoring/introduce/introduceVariable/JetIntroduceVariableTestGenerated.java @@ -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"); + } + +}