Search in sources :

Example 1 with SerializerTester

use of org.eclipse.xtext.junit4.serializer.SerializerTester in project xtext-eclipse by eclipse.

the class AbstractXtextTests method getResourceAndExpect.

public final XtextResource getResourceAndExpect(InputStream in, URI uri, int expectedErrors) throws Exception {
    XtextResource resource = doGetResource(in, uri);
    checkNodeModel(resource);
    if (expectedErrors != UNKNOWN_EXPECTATION) {
        if (expectedErrors == EXPECT_ERRORS)
            assertFalse(Joiner.on('\n').join(resource.getErrors()), resource.getErrors().isEmpty());
        else
            assertEquals(Joiner.on('\n').join(resource.getErrors()), expectedErrors, resource.getErrors().size());
    }
    for (Diagnostic d : resource.getErrors()) {
        if (d instanceof ExceptionDiagnostic)
            fail(d.getMessage());
    }
    if (expectedErrors == 0 && resource.getContents().size() > 0 && shouldTestSerializer(resource)) {
        SerializerTester tester = get(SerializerTester.class);
        EObject obj = resource.getContents().get(0);
        tester.assertSerializeWithNodeModel(obj);
        tester.assertSerializeWithoutNodeModel(obj);
    }
    return resource;
}
Also used : ExceptionDiagnostic(org.eclipse.xtext.diagnostics.ExceptionDiagnostic) EObject(org.eclipse.emf.ecore.EObject) Diagnostic(org.eclipse.emf.ecore.resource.Resource.Diagnostic) ExceptionDiagnostic(org.eclipse.xtext.diagnostics.ExceptionDiagnostic) XtextResource(org.eclipse.xtext.resource.XtextResource) SerializerTester(org.eclipse.xtext.junit4.serializer.SerializerTester)

Aggregations

EObject (org.eclipse.emf.ecore.EObject)1 Diagnostic (org.eclipse.emf.ecore.resource.Resource.Diagnostic)1 ExceptionDiagnostic (org.eclipse.xtext.diagnostics.ExceptionDiagnostic)1 SerializerTester (org.eclipse.xtext.junit4.serializer.SerializerTester)1 XtextResource (org.eclipse.xtext.resource.XtextResource)1