private void doElementDescriptionCheck() { PsiElement elementAtCaret = myFixture.getElementAtCaret(); assertNotNull(elementAtCaret); StringBuilder actualDump = new StringBuilder(); LOCATIONS.forEach( location -> { String actual = ElementDescriptionUtil.getElementDescription(elementAtCaret, location); String locationName = location.getClass().getSimpleName(); actualDump.append(locationName) .append(": ") .append(actual) .append("\n"); } ); UsefulTestCase.assertSameLinesWithFile(getTestResultsFilePath(), actualDump.toString()); }
public void checkSerializedReferencesWithFile(@NotNull String appendix) { CodeInsightTestFixtureImpl.ensureIndexesUpToDate(getProject()); addVirtualFileFilter(); StringBuilder sb = new StringBuilder(); List<PsiReference> references = collectFileReferences(); for (PsiReference psiReference : references) { psiReference.resolve(); } removeVirtualFileFilter(); for (PsiReference psiReference : references) { sb.append(serializeReference(psiReference)).append("\n"); } UsefulTestCase.assertSameLinesWithFile(getTestResultsFilePath(appendix), sb.toString()); }
protected void doTestTyping(@NotNull String toType) { initWithFileSmart(); myFixture.type(toType); UsefulTestCase.assertSameLinesWithFile(getTestResultsFilePath(), getEditorTextWithCaretsAndSelections()); }
protected void doTest(@NotNull String newName) { initWithFileSmart(); doRenameAtCaret(newName); UsefulTestCase.assertSameLinesWithFile(getTestResultsFilePath(), getFile().getText()); } }
protected void doTestEnter() { initWithFileSmart(); myFixture.type('\n'); UsefulTestCase.assertSameLinesWithFile(getTestResultsFilePath(), getEditorTextWithCaretsAndSelections()); }
protected void doTest(@NotNull String newName) { initWithFileSmart(); doRenameAtCaret(newName); UsefulTestCase.assertSameLinesWithFile(getTestResultsFilePath(), getFile().getText()); }
protected void doTestLightElements() { initWithFileSmartWithoutErrors(); StringBuilder sb = new StringBuilder(); getFile().accept(new PsiRecursiveElementVisitor() { @Override public void visitElement(PsiElement element) { if (element instanceof PerlPolyNamedElement) { sb.append("Poly-named provider: ").append(serializePsiElement(element)).append("\n"); for (PerlDelegatingLightNamedElement namedElement : ((PerlPolyNamedElement)element).getLightElements()) { sb.append("\t").append(serializePsiElement(namedElement)).append("\n"); } sb.append("\n"); } if (element instanceof PerlImplicitVariablesProvider) { sb.append("Implicit variables provider: ").append(serializePsiElement(element)).append("\n"); for (PerlVariableDeclarationElement declarationElement : ((PerlImplicitVariablesProvider)element).getImplicitVariables()) { sb.append("\t").append(serializePsiElement(declarationElement)).append("\n"); } sb.append("\n"); } super.visitElement(element); } }); UsefulTestCase.assertSameLinesWithFile(getTestResultsFilePath(), sb.toString()); }
UsefulTestCase.assertSameLinesWithFile(getTestResultsFilePath(), sb.toString());
UsefulTestCase.assertSameLinesWithFile(getTestResultsFilePath(answerSuffix), StringUtil.join(result, "\n"));
private void doTestIntentionWithoutLoad(@NotNull String intentionPrefix, boolean checkErrors) { myFixture.launchAction(getSingleIntention(intentionPrefix)); if (checkErrors) { assertNoErrorElements(); } UsefulTestCase.assertSameLinesWithFile(getTestResultsFilePath(), getFile().getText()); }
private void doTest() { initWithFileSmartWithoutErrors(); assertInjected(); UsefulTestCase.assertSameLinesWithFile(getTestResultsFilePath(), getHeredocDecodedText(getHeredocUnderCursor())); } }
private void doTest() { initWithFileSmartWithoutErrors(); List<Integer> caretsOffsets = getAndRemoveCarets(); StringBuilder sb = new StringBuilder(); for (int i = 0; i < caretsOffsets.size(); i++) { Integer caretOffset = caretsOffsets.get(i); if (caretsOffsets.size() > 1) { sb.append("---------------------- ").append("Caret #").append(i).append(" at: ").append(caretOffset) .append("-----------------------------\n"); } getEditor().getCaretModel().moveToOffset(caretOffset); PsiElement elementAtCaret = getFile().getViewProvider().findElementAt(getEditor().getCaretModel().getOffset(), getLanguage()); assertNotNull(elementAtCaret); DocumentationProvider documentationProvider = DocumentationManager.getProviderFromElement(elementAtCaret); assertInstanceOf(documentationProvider, DocumentationProviderEx.class); PsiElement targetElement = DocumentationManager.getInstance(getProject()).findTargetElement(getEditor(), getFile(), elementAtCaret); assertNotNull(targetElement); String generatedDoc = documentationProvider.generateDoc(targetElement, elementAtCaret); assertNotNull(generatedDoc); sb.append(generatedDoc).append("\n"); } UsefulTestCase.assertSameLinesWithFile(getTestResultsFilePath(), sb.toString()); } }
private void doTest(@NotNull String textToUpdate) { WriteCommandAction.writeCommandAction(getProject()).run(() -> getHeredocUnderCursor().updateText(textToUpdate)); UsefulTestCase.assertSameLinesWithFile(getTestResultsFilePath(), getFile().getText()); } }
protected void doTestFindUsages() { initWithFileSmart(); int flags = TargetElementUtil.ELEMENT_NAME_ACCEPTED | TargetElementUtil.REFERENCED_ELEMENT_ACCEPTED; PsiElement targetElement = TargetElementUtil.findTargetElement(getEditor(), flags); assertNotNull("Cannot find referenced element", targetElement); UsefulTestCase.assertSameLinesWithFile(getTestResultsFilePath(), checkAndSerializeFindUsages(targetElement)); }
protected final void doTestControlFlow() { initWithFileSmartWithoutErrors(); ControlFlow controlFlow = PerlControlFlowBuilder.getFor(getFile()); final String stringifiedControlFlow = StringUtil.join(controlFlow.getInstructions(), Object::toString, "\n"); if (ENABLE_SVG_GENERATION) { try { String svgDataPath = getSvgDataPath(); //if (!new File(svgDataPath).exists()) { // fixme this check may be configurable saveSvgFile(svgDataPath, controlFlow); //} } catch (Exception e) { e.printStackTrace(); } } UsefulTestCase.assertSameLinesWithFile(getTestResultsFilePath(), stringifiedControlFlow); }
protected void doTestPackageProcessorDescriptors() { initWithFileSmartWithoutErrors(); PsiElement elementAtCaret = getElementAtCaretWithoutInjection(); assertNotNull(elementAtCaret); PerlNamespaceDefinitionElement namespace = PerlPackageUtil.getNamespaceContainerForElement(elementAtCaret); assertNotNull(namespace); StringBuilder sb = new StringBuilder(); appendDescriptors("Scalars", sb, namespace.getImportedScalarDescriptors()); appendDescriptors("Arrays", sb, namespace.getImportedArrayDescriptors()); appendDescriptors("Hashes", sb, namespace.getImportedHashDescriptors()); appendDescriptors("Subs", sb, namespace.getImportedSubsDescriptors()); UsefulTestCase.assertSameLinesWithFile(getTestResultsFilePath(), sb.toString()); }
protected void doLineCommenterTest() { initWithFileSmart(); MultiCaretCodeInsightAction action = (MultiCaretCodeInsightAction)ActionManager.getInstance().getAction(IdeActions.ACTION_COMMENT_LINE); action.actionPerformedImpl(myModule.getProject(), myFixture.getEditor()); UsefulTestCase.assertSameLinesWithFile(getTestResultsFilePath(), getEditorTextWithCaretsAndSelections()); }
protected void doTestWorldSelector() { initWithFileSmartWithoutErrors(); List<Integer> offsets = getAndRemoveCarets(); List<Pair<Integer, String>> macroses = new ArrayList<>(); Caret currentCaret = getEditor().getCaretModel().getCurrentCaret(); for (Integer offset : offsets) { currentCaret.moveToOffset(offset); new SelectWordHandler(null).execute(getEditor(), currentCaret, getEditorDataContext()); addCaretInfo(currentCaret, macroses); currentCaret.removeSelection(); } UsefulTestCase.assertSameLinesWithFile(getTestResultsFilePath(), getEditorTextWithMacroses(macroses)); }
protected void doTestStructureView() { initWithFileSmartWithoutErrors(); PsiFile psiFile = getFile(); final VirtualFile virtualFile = psiFile.getVirtualFile(); final FileEditor fileEditor = FileEditorManager.getInstance(getProject()).getSelectedEditor(virtualFile); final StructureViewBuilder builder = LanguageStructureViewBuilder.INSTANCE.getStructureViewBuilder(psiFile); assertNotNull(builder); StructureView structureView = builder.createStructureView(fileEditor, getProject()); assertNotNull(structureView); addTearDownListener(structureView); StructureViewModel structureViewModel = structureView.getTreeModel(); StringBuilder sb = new StringBuilder(); serializeTree(structureViewModel.getRoot(), structureViewModel, sb, null, "", new THashSet<>()); UsefulTestCase.assertSameLinesWithFile(getTestResultsFilePath(), sb.toString()); }
protected void doFormatTestWithoutInitialization(@NotNull String resultFileName, @NotNull String resultSuffix) { WriteCommandAction.writeCommandAction(getProject()).run(() -> { PsiFile file = myFixture.getFile(); if (file.getViewProvider() instanceof InjectedFileViewProvider) { //noinspection ConstantConditions file = file.getContext().getContainingFile(); } TextRange rangeToUse = file.getTextRange(); CodeStyleManager.getInstance(getProject()).reformatText(file, rangeToUse.getStartOffset(), rangeToUse.getEndOffset()); }); String resultFilePath = getTestDataPath() + "/" + resultFileName + resultSuffix + ".txt"; UsefulTestCase.assertSameLinesWithFile(resultFilePath, myFixture.getFile().getText()); assertNoErrorElements(); }