Search in sources :

Example 1 with AnnotatedTextToString

use of org.eclipse.xtext.ui.testing.util.AnnotatedTextToString in project xtext-eclipse by eclipse.

the class AbstractMultiQuickfixTest method assertContentsAndMarkers.

protected void assertContentsAndMarkers(IFile file, IMarker[] markers, CharSequence expectation) {
    String actual = new AnnotatedTextToString().withFile(file).withMarkers(markers).toString().trim();
    String exp = expectation.toString().trim();
    Assert.assertEquals(Strings.toUnixLineSeparator(exp), Strings.toUnixLineSeparator(actual));
}
Also used : AnnotatedTextToString(org.eclipse.xtext.ui.testing.util.AnnotatedTextToString) AnnotatedTextToString(org.eclipse.xtext.ui.testing.util.AnnotatedTextToString)

Example 2 with AnnotatedTextToString

use of org.eclipse.xtext.ui.testing.util.AnnotatedTextToString in project xtext-eclipse by eclipse.

the class IssueDataTest method testIssueData.

@Test
public void testIssueData() throws Exception {
    IFile dslFile = dslFile(getProjectName(), getFileName(), getFileExtension(), MODEL_WITH_LINKING_ERROR);
    XtextEditor xtextEditor = openEditor(dslFile);
    IXtextDocument document = xtextEditor.getDocument();
    IResource file = xtextEditor.getResource();
    List<Issue> issues = getAllValidationIssues(document);
    assertEquals(1, issues.size());
    Issue issue = issues.get(0);
    assertEquals(2, issue.getLineNumber().intValue());
    assertEquals(3, issue.getColumn().intValue());
    assertEquals(PREFIX.length(), issue.getOffset().intValue());
    assertEquals(QuickfixCrossrefTestLanguageValidator.TRIGGER_VALIDATION_ISSUE.length(), issue.getLength().intValue());
    String[] expectedIssueData = new String[] { QuickfixCrossrefTestLanguageValidator.ISSUE_DATA_0, QuickfixCrossrefTestLanguageValidator.ISSUE_DATA_1 };
    assertTrue(Arrays.equals(expectedIssueData, issue.getData()));
    Thread.sleep(1000);
    IAnnotationModel annotationModel = xtextEditor.getDocumentProvider().getAnnotationModel(xtextEditor.getEditorInput());
    AnnotationIssueProcessor annotationIssueProcessor = new AnnotationIssueProcessor(document, annotationModel, new IssueResolutionProvider.NullImpl());
    annotationIssueProcessor.processIssues(issues, new NullProgressMonitor());
    Iterator<?> annotationIterator = annotationModel.getAnnotationIterator();
    // filter QuickDiffAnnotations
    List<Object> allAnnotations = Lists.newArrayList(annotationIterator);
    List<XtextAnnotation> annotations = newArrayList(filter(allAnnotations, XtextAnnotation.class));
    assertEquals(annotations.toString(), 1, annotations.size());
    XtextAnnotation annotation = annotations.get(0);
    assertTrue(Arrays.equals(expectedIssueData, annotation.getIssueData()));
    IssueUtil issueUtil = new IssueUtil();
    Issue issueFromAnnotation = issueUtil.getIssueFromAnnotation(annotation);
    assertTrue(Arrays.equals(expectedIssueData, issueFromAnnotation.getData()));
    new MarkerCreator().createMarker(issue, file, MarkerTypes.FAST_VALIDATION);
    IMarker[] markers = file.findMarkers(MarkerTypes.FAST_VALIDATION, true, IResource.DEPTH_ZERO);
    String errorMessage = new AnnotatedTextToString().withFile(dslFile).withMarkers(markers).toString().trim();
    assertEquals(errorMessage, 1, markers.length);
    String attribute = (String) markers[0].getAttribute(Issue.DATA_KEY);
    assertNotNull(attribute);
    assertTrue(Arrays.equals(expectedIssueData, Strings.unpack(attribute)));
    Issue issueFromMarker = issueUtil.createIssue(markers[0]);
    assertEquals(issue.getColumn(), issueFromMarker.getColumn());
    assertEquals(issue.getLineNumber(), issueFromMarker.getLineNumber());
    assertEquals(issue.getOffset(), issueFromMarker.getOffset());
    assertEquals(issue.getLength(), issueFromMarker.getLength());
    assertTrue(Arrays.equals(expectedIssueData, issueFromMarker.getData()));
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IFile(org.eclipse.core.resources.IFile) Issue(org.eclipse.xtext.validation.Issue) AnnotatedTextToString(org.eclipse.xtext.ui.testing.util.AnnotatedTextToString) XtextEditor(org.eclipse.xtext.ui.editor.XtextEditor) AnnotatedTextToString(org.eclipse.xtext.ui.testing.util.AnnotatedTextToString) IAnnotationModel(org.eclipse.jface.text.source.IAnnotationModel) IssueUtil(org.eclipse.xtext.ui.util.IssueUtil) AnnotationIssueProcessor(org.eclipse.xtext.ui.editor.validation.AnnotationIssueProcessor) XtextAnnotation(org.eclipse.xtext.ui.editor.validation.XtextAnnotation) IssueResolutionProvider(org.eclipse.xtext.ui.editor.quickfix.IssueResolutionProvider) IMarker(org.eclipse.core.resources.IMarker) MarkerCreator(org.eclipse.xtext.ui.editor.validation.MarkerCreator) IResource(org.eclipse.core.resources.IResource) IXtextDocument(org.eclipse.xtext.ui.editor.model.IXtextDocument) AbstractQuickfixTest(org.eclipse.xtext.ui.testing.AbstractQuickfixTest) Test(org.junit.Test)

Example 3 with AnnotatedTextToString

use of org.eclipse.xtext.ui.testing.util.AnnotatedTextToString in project xtext-eclipse by eclipse.

the class AbstractQuickfixTest method assertContentsAndMarkers.

protected void assertContentsAndMarkers(IFile file, IMarker[] markers, CharSequence expectation) {
    String actual = new AnnotatedTextToString().withFile(file).withMarkers(markers).toString().trim();
    String exp = expectation.toString().trim();
    Assert.assertEquals(Strings.toUnixLineSeparator(exp), Strings.toUnixLineSeparator(actual));
}
Also used : AnnotatedTextToString(org.eclipse.xtext.ui.testing.util.AnnotatedTextToString) AnnotatedTextToString(org.eclipse.xtext.ui.testing.util.AnnotatedTextToString)

Aggregations

AnnotatedTextToString (org.eclipse.xtext.ui.testing.util.AnnotatedTextToString)3 IFile (org.eclipse.core.resources.IFile)1 IMarker (org.eclipse.core.resources.IMarker)1 IResource (org.eclipse.core.resources.IResource)1 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)1 IAnnotationModel (org.eclipse.jface.text.source.IAnnotationModel)1 XtextEditor (org.eclipse.xtext.ui.editor.XtextEditor)1 IXtextDocument (org.eclipse.xtext.ui.editor.model.IXtextDocument)1 IssueResolutionProvider (org.eclipse.xtext.ui.editor.quickfix.IssueResolutionProvider)1 AnnotationIssueProcessor (org.eclipse.xtext.ui.editor.validation.AnnotationIssueProcessor)1 MarkerCreator (org.eclipse.xtext.ui.editor.validation.MarkerCreator)1 XtextAnnotation (org.eclipse.xtext.ui.editor.validation.XtextAnnotation)1 AbstractQuickfixTest (org.eclipse.xtext.ui.testing.AbstractQuickfixTest)1 IssueUtil (org.eclipse.xtext.ui.util.IssueUtil)1 Issue (org.eclipse.xtext.validation.Issue)1 Test (org.junit.Test)1