use of com.intellij.testFramework.TestDataFile in project intellij-community by JetBrains.
the class PyResolveTestCase method configureByFile.
protected PsiReference configureByFile(@TestDataFile final String filePath) {
VirtualFile testDataRoot = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(new File(getTestDataPath()));
final VirtualFile file = testDataRoot.findFileByRelativePath(filePath);
assertNotNull(file);
String fileText;
try {
fileText = StringUtil.convertLineSeparators(VfsUtil.loadText(file));
} catch (IOException e) {
throw new RuntimeException(e);
}
int offset = fileText.indexOf(MARKER);
assertTrue(offset >= 0);
fileText = fileText.substring(0, offset) + fileText.substring(offset + MARKER.length());
final String finalFileText = fileText;
myFixture.configureByText(new File(filePath).getName(), finalFileText);
final PsiReference reference = myFixture.getFile().findReferenceAt(offset);
return reference;
}
use of com.intellij.testFramework.TestDataFile in project intellij-community by JetBrains.
the class CodeInsightTestUtil method doWordSelectionTestOnDirectory.
public static void doWordSelectionTestOnDirectory(@NotNull final CodeInsightTestFixture fixture, @TestDataFile @NotNull final String directoryName, @NotNull final String filesExtension) {
final SelectWordHandler action = new SelectWordHandler(null);
fixture.copyDirectoryToProject(directoryName, directoryName);
fixture.configureByFile(directoryName + "/before." + filesExtension);
int i = 1;
while (true) {
final String fileName = directoryName + "/after" + i + "." + filesExtension;
if (new File(fixture.getTestDataPath() + "/" + fileName).exists()) {
action.execute(fixture.getEditor(), DataManager.getInstance().getDataContext(fixture.getEditor().getComponent()));
fixture.checkResultByFile(fileName);
i++;
} else {
break;
}
}
assertTrue("At least one 'after'-file required", i > 1);
}
use of com.intellij.testFramework.TestDataFile in project intellij-community by JetBrains.
the class EditorPaintingTest method checkResult.
private void checkResult(@TestDataFile String expectedResultFileName) throws IOException {
myEditor.getSettings().setAdditionalLinesCount(0);
myEditor.getSettings().setAdditionalColumnsCount(1);
JComponent editorComponent = myEditor.getContentComponent();
Dimension size = editorComponent.getPreferredSize();
editorComponent.setSize(size);
//noinspection UndesirableClassUsage
BufferedImage image = new BufferedImage(size.width, size.height, BufferedImage.TYPE_INT_ARGB);
BitmapFont plainFont = BitmapFont.loadFromFile(getFontFile(false));
BitmapFont boldFont = BitmapFont.loadFromFile(getFontFile(true));
MyGraphics graphics = new MyGraphics(image.createGraphics(), plainFont, boldFont);
try {
editorComponent.paint(graphics);
} finally {
graphics.dispose();
}
File fileWithExpectedResult = getTestDataFile(expectedResultFileName);
if (OVERWRITE_TESTDATA) {
ImageIO.write(image, "png", fileWithExpectedResult);
System.out.println("File " + fileWithExpectedResult.getPath() + " created.");
}
if (fileWithExpectedResult.exists()) {
BufferedImage expectedResult = ImageIO.read(fileWithExpectedResult);
if (expectedResult.getWidth() != image.getWidth()) {
fail("Unexpected image width", fileWithExpectedResult, image);
}
if (expectedResult.getHeight() != image.getHeight()) {
fail("Unexpected image height", fileWithExpectedResult, image);
}
for (int i = 0; i < expectedResult.getWidth(); i++) {
for (int j = 0; j < expectedResult.getHeight(); j++) {
if (expectedResult.getRGB(i, j) != image.getRGB(i, j)) {
fail("Unexpected image contents", fileWithExpectedResult, image);
}
}
}
} else {
ImageIO.write(image, "png", fileWithExpectedResult);
fail("Missing test data created: " + fileWithExpectedResult.getPath());
}
}
Aggregations