mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Every guy in the town should be able to use UnwrapTestCase
This commit is contained in:
@@ -24,6 +24,7 @@ import com.intellij.psi.*;
|
||||
|
||||
public class UnwrapAction extends BaseCodeInsightAction{
|
||||
public UnwrapAction() {
|
||||
super(true);
|
||||
setEnabledInModalContext(true);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
package com.intellij.codeInsight.unwrap;
|
||||
|
||||
import com.intellij.openapi.actionSystem.AnAction;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.testFramework.LightPlatformCodeInsightTestCase;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class UnwrapTestCase extends LightPlatformCodeInsightTestCase {
|
||||
protected void assertUnwrapped(String codeBefore, String expectedCodeAfter) throws Exception {
|
||||
assertUnwrapped(codeBefore, expectedCodeAfter, 0);
|
||||
}
|
||||
|
||||
protected void assertUnwrapped(String codeBefore, String expectedCodeAfter, final int option) throws Exception {
|
||||
configureCode(codeBefore);
|
||||
|
||||
UnwrapHandler h = new UnwrapHandler() {
|
||||
@Override
|
||||
protected void selectOption(List<AnAction> options, Editor editor, PsiFile file) {
|
||||
if (options.isEmpty()) return;
|
||||
options.get(option).actionPerformed(null);
|
||||
}
|
||||
};
|
||||
|
||||
h.invoke(getProject(), getEditor(), getFile());
|
||||
|
||||
checkResultByText(createCode(expectedCodeAfter));
|
||||
}
|
||||
|
||||
protected void assertOptions(String code, String... expectedOptions) throws IOException {
|
||||
configureCode(code);
|
||||
|
||||
final List<String> actualOptions = new ArrayList<String>();
|
||||
|
||||
UnwrapHandler h = new UnwrapHandler() {
|
||||
@Override
|
||||
protected void selectOption(List<AnAction> options, Editor editor, PsiFile file) {
|
||||
for (AnAction each : options) {
|
||||
actualOptions.add(each.getTemplatePresentation().getText());
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
h.invoke(getProject(), getEditor(), getFile());
|
||||
|
||||
assertEquals(Arrays.asList(expectedOptions), actualOptions);
|
||||
}
|
||||
|
||||
protected void configureCode(final String codeBefore) throws IOException {
|
||||
configureFromFileText(getFileNameToCreate(), createCode(codeBefore));
|
||||
}
|
||||
|
||||
protected String getFileNameToCreate() {
|
||||
return "A.java";
|
||||
}
|
||||
|
||||
protected String createCode(String codeBefore) {
|
||||
return "public class A {\n" +
|
||||
" void foo() {\n" +
|
||||
indentTwice(codeBefore) +
|
||||
" }\n" +
|
||||
"}";
|
||||
}
|
||||
|
||||
protected String indentTwice(String code) {
|
||||
String result = "";
|
||||
for (String line : StringUtil.tokenize(code, "\n")) {
|
||||
result += " " + line + "\n";
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user