From 85c46019d3f08dd6b0fb6acca1631251886fb753 Mon Sep 17 00:00:00 2001 From: Tuomas Tynkkynen Date: Fri, 7 Feb 2014 14:46:26 -0800 Subject: [PATCH] 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 marker specifying the place where the smart selector will be run. Then, the last comment in the file should contain the expected outcome. --- .../jet/generators/tests/GenerateTests.kt | 5 ++ idea/testData/smartSelection/simple.kt | 9 ++++ .../plugin/AbstractSmartSelectionTest.java | 51 +++++++++++++++++++ .../plugin/SmartSelectionTestGenerated.java | 44 ++++++++++++++++ 4 files changed, 109 insertions(+) create mode 100644 idea/testData/smartSelection/simple.kt create mode 100644 idea/tests/org/jetbrains/jet/plugin/AbstractSmartSelectionTest.java create mode 100644 idea/tests/org/jetbrains/jet/plugin/SmartSelectionTestGenerated.java diff --git a/generators/src/org/jetbrains/jet/generators/tests/GenerateTests.kt b/generators/src/org/jetbrains/jet/generators/tests/GenerateTests.kt index e22104be2d1..9a55fc5124f 100644 --- a/generators/src/org/jetbrains/jet/generators/tests/GenerateTests.kt +++ b/generators/src/org/jetbrains/jet/generators/tests/GenerateTests.kt @@ -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) { testClass(javaClass()) { model("completion/injava", extension = "java") } + + testClass(javaClass()) { + model("smartSelection", testMethod = "doTestSmartSelection", pattern = """^([^\.]+)\.kt$""") + } } testGroup("j2k/tests/test", "j2k/tests/testData") { diff --git a/idea/testData/smartSelection/simple.kt b/idea/testData/smartSelection/simple.kt new file mode 100644 index 00000000000..b8d82baaafe --- /dev/null +++ b/idea/testData/smartSelection/simple.kt @@ -0,0 +1,9 @@ +fun main(args: Array) { + print(Math.pow(1.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))) +*/ diff --git a/idea/tests/org/jetbrains/jet/plugin/AbstractSmartSelectionTest.java b/idea/tests/org/jetbrains/jet/plugin/AbstractSmartSelectionTest.java new file mode 100644 index 00000000000..90b50d28811 --- /dev/null +++ b/idea/tests/org/jetbrains/jet/plugin/AbstractSmartSelectionTest.java @@ -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 expressions = JetRefactoringUtil.getSmartSelectSuggestions( + getFile(), getEditor().getCaretModel().getOffset()); + + List textualExpressions = new ArrayList(); + for (JetExpression expression : expressions) { + textualExpressions.add(expression.getText()); + } + assertEquals(expectedResultText, StringUtil.join(textualExpressions, "\n")); + } + + @NotNull + @Override + protected String getTestDataPath() { + return ""; + } +} diff --git a/idea/tests/org/jetbrains/jet/plugin/SmartSelectionTestGenerated.java b/idea/tests/org/jetbrains/jet/plugin/SmartSelectionTestGenerated.java new file mode 100644 index 00000000000..a9b34705922 --- /dev/null +++ b/idea/tests/org/jetbrains/jet/plugin/SmartSelectionTestGenerated.java @@ -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"); + } + +}