85c46019d3
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.
52 lines
1.8 KiB
Java
52 lines
1.8 KiB
Java
/*
|
|
* 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 "";
|
|
}
|
|
}
|