Add test suite for smart expression selector
Add test suite for smart expression selector (the small expression list popup in e.g. Extract Variable.) The test file format is similar to that in JetNameSuggesterTest: a .kt file with the usual <caret> marker specifying the place where the smart selector will be run. Then, the last comment in the file should contain the expected outcome.
This commit is contained in:
committed by
Nikolay Krasko
parent
815ca2fe57
commit
85c46019d3
@@ -57,6 +57,7 @@ import org.jetbrains.jet.plugin.highlighter.AbstractHighlightingTest
|
||||
import org.jetbrains.jet.plugin.folding.AbstractKotlinFoldingTest
|
||||
import org.jetbrains.jet.plugin.codeInsight.surroundWith.AbstractSurroundWithTest
|
||||
import org.jetbrains.jet.plugin.intentions.AbstractCodeTransformationTest
|
||||
import org.jetbrains.jet.plugin.AbstractSmartSelectionTest
|
||||
import org.jetbrains.jet.plugin.hierarchy.AbstractHierarchyTest
|
||||
import org.jetbrains.jet.plugin.codeInsight.moveUpDown.AbstractCodeMoverTest
|
||||
import org.jetbrains.jet.plugin.refactoring.inline.AbstractInlineTest
|
||||
@@ -458,6 +459,10 @@ fun main(args: Array<String>) {
|
||||
testClass(javaClass<AbstractKotlinSourceInJavaCompletionTest>()) {
|
||||
model("completion/injava", extension = "java")
|
||||
}
|
||||
|
||||
testClass(javaClass<AbstractSmartSelectionTest>()) {
|
||||
model("smartSelection", testMethod = "doTestSmartSelection", pattern = """^([^\.]+)\.kt$""")
|
||||
}
|
||||
}
|
||||
|
||||
testGroup("j2k/tests/test", "j2k/tests/testData") {
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
fun main(args: Array<String>) {
|
||||
print(Math.pow(1.<caret>0 + 1, Math.abs(-42.0)))
|
||||
}
|
||||
/*
|
||||
1.0
|
||||
1.0 + 1
|
||||
Math.pow(1.0 + 1, Math.abs(-42.0))
|
||||
print(Math.pow(1.0 + 1, Math.abs(-42.0)))
|
||||
*/
|
||||
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.testFramework.LightCodeInsightTestCase;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
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;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class AbstractSmartSelectionTest extends LightCodeInsightTestCase {
|
||||
|
||||
public void doTestSmartSelection(@NotNull String path) throws Exception {
|
||||
configureByFile(path);
|
||||
String expectedResultText = JetTestUtils.getLastCommentInFile((JetFile) getFile());
|
||||
|
||||
List<JetExpression> expressions = JetRefactoringUtil.getSmartSelectSuggestions(
|
||||
getFile(), getEditor().getCaretModel().getOffset());
|
||||
|
||||
List<String> textualExpressions = new ArrayList<String>();
|
||||
for (JetExpression expression : expressions) {
|
||||
textualExpressions.add(expression.getText());
|
||||
}
|
||||
assertEquals(expectedResultText, StringUtil.join(textualExpressions, "\n"));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected String getTestDataPath() {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* 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.AbstractSmartSelectionTest;
|
||||
|
||||
/** This class is generated by {@link org.jetbrains.jet.generators.tests.TestsPackage}. DO NOT MODIFY MANUALLY */
|
||||
@SuppressWarnings("all")
|
||||
@TestMetadata("idea/testData/smartSelection")
|
||||
public class SmartSelectionTestGenerated extends AbstractSmartSelectionTest {
|
||||
public void testAllFilesPresentInSmartSelection() throws Exception {
|
||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.TestsPackage", new File("idea/testData/smartSelection"), Pattern.compile("^([^\\.]+)\\.kt$"), true);
|
||||
}
|
||||
|
||||
@TestMetadata("simple.kt")
|
||||
public void testSimple() throws Exception {
|
||||
doTestSmartSelection("idea/testData/smartSelection/simple.kt");
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user