Add utility method for getting before and after text
This commit is contained in:
@@ -24,6 +24,7 @@ import com.intellij.openapi.editor.Document;
|
|||||||
import com.intellij.openapi.project.Project;
|
import com.intellij.openapi.project.Project;
|
||||||
import com.intellij.openapi.util.ShutDownTracker;
|
import com.intellij.openapi.util.ShutDownTracker;
|
||||||
import com.intellij.openapi.util.io.FileUtil;
|
import com.intellij.openapi.util.io.FileUtil;
|
||||||
|
import com.intellij.openapi.util.text.StringUtil;
|
||||||
import com.intellij.openapi.vfs.CharsetToolkit;
|
import com.intellij.openapi.vfs.CharsetToolkit;
|
||||||
import com.intellij.psi.PsiFileFactory;
|
import com.intellij.psi.PsiFileFactory;
|
||||||
import com.intellij.psi.impl.PsiFileFactoryImpl;
|
import com.intellij.psi.impl.PsiFileFactoryImpl;
|
||||||
@@ -402,6 +403,29 @@ public class JetTestUtils {
|
|||||||
return testFileFiles;
|
return testFileFiles;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static List<String> loadBeforeAfterText(String filePath) {
|
||||||
|
String content;
|
||||||
|
|
||||||
|
try {
|
||||||
|
content = StringUtil.convertLineSeparators(FileUtil.loadFile(new File(filePath)));
|
||||||
|
}
|
||||||
|
catch (IOException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
List<String> files = createTestFiles("", content, new TestFileFactory<String>() {
|
||||||
|
@Override
|
||||||
|
public String create(String fileName, String text) {
|
||||||
|
int firstLineEnd = text.indexOf('\n');
|
||||||
|
return StringUtil.trimTrailing(text.substring(firstLineEnd + 1));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Assert.assertTrue("Exactly two files expected: ", files.size() == 2);
|
||||||
|
|
||||||
|
return files;
|
||||||
|
}
|
||||||
|
|
||||||
public static String getLastCommentedLines(@NotNull Document document) {
|
public static String getLastCommentedLines(@NotNull Document document) {
|
||||||
List<CharSequence> resultLines = new ArrayList<CharSequence>();
|
List<CharSequence> resultLines = new ArrayList<CharSequence>();
|
||||||
for (int i = document.getLineCount() - 1; i >= 0; i--) {
|
for (int i = document.getLineCount() - 1; i >= 0; i--) {
|
||||||
|
|||||||
Reference in New Issue
Block a user