From 24d8557a5a323d71ea40a71b28a10c98def7b520 Mon Sep 17 00:00:00 2001 From: Alexey Sedunov Date: Thu, 10 Apr 2014 20:07:09 +0400 Subject: [PATCH] Translate AbstractJetExtractionTest to Kotlin --- annotations/com/intellij/ide/annotations.xml | 5 ++ .../testFramework/fixtures/annotations.xml | 9 +++ .../AbstractJetExtractionTest.java | 63 ----------------- .../AbstractJetExtractionTest.kt | 67 +++++++++++++++++++ 4 files changed, 81 insertions(+), 63 deletions(-) create mode 100644 annotations/com/intellij/ide/annotations.xml delete mode 100644 idea/tests/org/jetbrains/jet/plugin/refactoring/introduce/introduceVariable/AbstractJetExtractionTest.java create mode 100644 idea/tests/org/jetbrains/jet/plugin/refactoring/introduce/introduceVariable/AbstractJetExtractionTest.kt diff --git a/annotations/com/intellij/ide/annotations.xml b/annotations/com/intellij/ide/annotations.xml new file mode 100644 index 00000000000..e94fa17f59d --- /dev/null +++ b/annotations/com/intellij/ide/annotations.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/annotations/com/intellij/testFramework/fixtures/annotations.xml b/annotations/com/intellij/testFramework/fixtures/annotations.xml index b8f79647ddc..79625be7be6 100644 --- a/annotations/com/intellij/testFramework/fixtures/annotations.xml +++ b/annotations/com/intellij/testFramework/fixtures/annotations.xml @@ -1,4 +1,7 @@ + + + @@ -11,7 +14,13 @@ + + + + + + \ No newline at end of file diff --git a/idea/tests/org/jetbrains/jet/plugin/refactoring/introduce/introduceVariable/AbstractJetExtractionTest.java b/idea/tests/org/jetbrains/jet/plugin/refactoring/introduce/introduceVariable/AbstractJetExtractionTest.java deleted file mode 100644 index 68be187088d..00000000000 --- a/idea/tests/org/jetbrains/jet/plugin/refactoring/introduce/introduceVariable/AbstractJetExtractionTest.java +++ /dev/null @@ -1,63 +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.psi.PsiElement; -import com.intellij.refactoring.RefactoringActionHandler; -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 org.jetbrains.jet.plugin.refactoring.extractFunction.ExtractKotlinFunctionHandler; - -import java.io.File; - -public abstract class AbstractJetExtractionTest extends LightCodeInsightFixtureTestCase { - protected void doIntroduceVariableTest(@NotNull String path) { - doTest(path, new KotlinIntroduceVariableHandler()); - } - - protected void doTest(@NotNull String path, @NotNull RefactoringActionHandler handler) { - File mainFile = new File(path); - - myFixture.setTestDataPath(JetTestCaseBuilder.getHomeDirectory() + "/" + mainFile.getParent()); - - 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; - - handler.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/AbstractJetExtractionTest.kt b/idea/tests/org/jetbrains/jet/plugin/refactoring/introduce/introduceVariable/AbstractJetExtractionTest.kt new file mode 100644 index 00000000000..cc45ce281ee --- /dev/null +++ b/idea/tests/org/jetbrains/jet/plugin/refactoring/introduce/introduceVariable/AbstractJetExtractionTest.kt @@ -0,0 +1,67 @@ +/* + * 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 com.intellij.ide.DataManager +import com.intellij.psi.PsiElement +import com.intellij.refactoring.RefactoringActionHandler +import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase +import org.jetbrains.jet.JetTestCaseBuilder +import org.jetbrains.jet.lang.psi.JetFile +import org.jetbrains.jet.lexer.JetTokens +import org.jetbrains.jet.plugin.refactoring.extractFunction.ExtractKotlinFunctionHandler +import java.io.File +import junit.framework.TestCase +import kotlin.test.assertEquals + +public abstract class AbstractJetExtractionTest() : LightCodeInsightFixtureTestCase() { + protected fun doIntroduceVariableTest(path: String) { + doTest(path, KotlinIntroduceVariableHandler()) + } + + protected fun doTest(path: String, handler: RefactoringActionHandler) { + val mainFile = File(path) + + myFixture.setTestDataPath("${JetTestCaseBuilder.getHomeDirectory()}/${mainFile.getParent()}") + + val file = myFixture.configureByFile(mainFile.getName()) as JetFile + + val lastChild = file.getLastChild() + assert(lastChild != null) + + val expectedResultText = + when (lastChild!!.getNode()!!.getElementType()) { + JetTokens.BLOCK_COMMENT -> { + val lastChildText = lastChild.getText() + lastChildText!!.substring(2, lastChildText.length() - 2).trim() + } + + JetTokens.EOL_COMMENT -> { + lastChild.getText()!!.substring(2).trim() + } + + else -> null + } + assert(expectedResultText != null) + + handler.invoke( + getProject(), myFixture.getEditor(), file, DataManager.getInstance().getDataContext(myFixture.getEditor().getComponent())) + + val endOffset = file.getLastChild()!!.getTextRange()!!.getStartOffset() + assertEquals(expectedResultText, file.getText()!!.substring(0, endOffset).trim()) + } +}