Add tests for JetRefactoringUtil.selectExpression
Add tests for JetRefactoringUtil.selectExpression, which is invoked by e.g. extract variable when some text is selected. Test cases under idea/testData/expressionSelection/ should contain Kotlin files with the usual <selection> tags, with the expected result of selectExpression in the last comment of the file.
This commit is contained in:
committed by
Nikolay Krasko
parent
4968afebf8
commit
998d2c5ec8
@@ -95,6 +95,7 @@ import org.jetbrains.jet.checkers.AbstractJetDiagnosticsTestWithStdLib
|
|||||||
import org.jetbrains.jet.plugin.codeInsight.AbstractInsertImportOnPasteTest
|
import org.jetbrains.jet.plugin.codeInsight.AbstractInsertImportOnPasteTest
|
||||||
import org.jetbrains.jet.resolve.AbstractReferenceToJavaWithWrongFileStructureTest
|
import org.jetbrains.jet.resolve.AbstractReferenceToJavaWithWrongFileStructureTest
|
||||||
import org.jetbrains.jet.plugin.navigation.AbstractKotlinGotoTest
|
import org.jetbrains.jet.plugin.navigation.AbstractKotlinGotoTest
|
||||||
|
import org.jetbrains.jet.plugin.AbstractExpressionSelectionTest
|
||||||
|
|
||||||
fun main(args: Array<String>) {
|
fun main(args: Array<String>) {
|
||||||
System.setProperty("java.awt.headless", "true")
|
System.setProperty("java.awt.headless", "true")
|
||||||
@@ -483,6 +484,10 @@ fun main(args: Array<String>) {
|
|||||||
testClass(javaClass<AbstractSmartSelectionTest>()) {
|
testClass(javaClass<AbstractSmartSelectionTest>()) {
|
||||||
model("smartSelection", testMethod = "doTestSmartSelection", pattern = """^([^\.]+)\.kt$""")
|
model("smartSelection", testMethod = "doTestSmartSelection", pattern = """^([^\.]+)\.kt$""")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
testClass(javaClass<AbstractExpressionSelectionTest>()) {
|
||||||
|
model("expressionSelection", testMethod = "doTestExpressionSelection", pattern = """^([^\.]+)\.kt$""")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
testGroup("j2k/tests/test", "j2k/tests/testData") {
|
testGroup("j2k/tests/test", "j2k/tests/testData") {
|
||||||
|
|||||||
@@ -0,0 +1,2 @@
|
|||||||
|
val f = 4<selection>0.5 + 1.</selection>5
|
||||||
|
// 40.5 + 1.5
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
<selection>val</selection> f = 42.0
|
||||||
|
/* */
|
||||||
@@ -0,0 +1,52 @@
|
|||||||
|
/*
|
||||||
|
* 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;
|
||||||
|
|
||||||
|
import com.intellij.testFramework.LightCodeInsightTestCase;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
import org.jetbrains.jet.JetTestUtils;
|
||||||
|
import org.jetbrains.jet.lang.psi.JetExpression;
|
||||||
|
import org.jetbrains.jet.lang.psi.JetFile;
|
||||||
|
import org.jetbrains.jet.plugin.refactoring.JetRefactoringUtil;
|
||||||
|
|
||||||
|
public abstract class AbstractExpressionSelectionTest extends LightCodeInsightTestCase {
|
||||||
|
|
||||||
|
public void doTestExpressionSelection(@NotNull String path) throws Exception {
|
||||||
|
configureByFile(path);
|
||||||
|
final String expectedExpression = JetTestUtils.getLastCommentInFile((JetFile) getFile());
|
||||||
|
|
||||||
|
try {
|
||||||
|
JetRefactoringUtil.selectExpression(getEditor(), getFile(), new JetRefactoringUtil.SelectExpressionCallback() {
|
||||||
|
@Override
|
||||||
|
public void run(@Nullable JetExpression expression) {
|
||||||
|
assertNotNull("Selected expression mustn't be null", expression);
|
||||||
|
assertEquals(expectedExpression, expression.getText());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
catch (JetRefactoringUtil.IntroduceRefactoringException e) {
|
||||||
|
assertEquals(expectedExpression, "");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
protected String getTestDataPath() {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,49 @@
|
|||||||
|
/*
|
||||||
|
* 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;
|
||||||
|
|
||||||
|
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.AbstractExpressionSelectionTest;
|
||||||
|
|
||||||
|
/** This class is generated by {@link org.jetbrains.jet.generators.tests.TestsPackage}. DO NOT MODIFY MANUALLY */
|
||||||
|
@SuppressWarnings("all")
|
||||||
|
@TestMetadata("idea/testData/expressionSelection")
|
||||||
|
public class ExpressionSelectionTestGenerated extends AbstractExpressionSelectionTest {
|
||||||
|
public void testAllFilesPresentInExpressionSelection() throws Exception {
|
||||||
|
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.TestsPackage", new File("idea/testData/expressionSelection"), Pattern.compile("^([^\\.]+)\\.kt$"), true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("binaryExpr.kt")
|
||||||
|
public void testBinaryExpr() throws Exception {
|
||||||
|
doTestExpressionSelection("idea/testData/expressionSelection/binaryExpr.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("noExpression.kt")
|
||||||
|
public void testNoExpression() throws Exception {
|
||||||
|
doTestExpressionSelection("idea/testData/expressionSelection/noExpression.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user