Search in sources :

Example 1 with Serializer

use of org.eclipse.xtext.serializer.impl.Serializer in project xtext-core by eclipse.

the class CommentAssociationTest method checkReplaceRegion.

private void checkReplaceRegion(Element element, String expectedText, String completeModel) {
    Serializer serializer = get(Serializer.class);
    ReplaceRegion replacement = serializer.serializeReplacement(element, SaveOptions.defaultOptions());
    assertEquals(expectedText, replacement.getText());
    assertEquals(completeModel.indexOf(expectedText), replacement.getOffset());
    assertEquals(expectedText.length(), replacement.getLength());
}
Also used : ReplaceRegion(org.eclipse.xtext.util.ReplaceRegion) Serializer(org.eclipse.xtext.serializer.impl.Serializer)

Example 2 with Serializer

use of org.eclipse.xtext.serializer.impl.Serializer in project xtext-core by eclipse.

the class PartialParserTest method testBug370426.

@Test
public void testBug370426() throws Exception {
    with(SimpleExpressionsTestLanguageStandaloneSetup.class);
    String model = "a/b\n+c";
    XtextResource resource = getResourceFromString(model);
    assertTrue(resource.getErrors().toString(), resource.getErrors().isEmpty());
    // turn /b into a comment
    resource.update(model.indexOf("/"), 0, "/");
    assertTrue(resource.getErrors().toString(), resource.getErrors().isEmpty());
    Serializer serializer = get(Serializer.class);
    String newModel = serializer.serialize(EcoreUtil.copy(resource.getContents().get(0)));
    assertEquals("a + c", newModel);
    // change comment back into /b
    resource.update(model.indexOf("/"), 1, "");
    assertTrue(resource.getErrors().toString(), resource.getErrors().isEmpty());
    assertEquals(model, serialize(resource.getContents().get(0)));
}
Also used : XtextResource(org.eclipse.xtext.resource.XtextResource) Serializer(org.eclipse.xtext.serializer.impl.Serializer) Test(org.junit.Test)

Aggregations

Serializer (org.eclipse.xtext.serializer.impl.Serializer)2 XtextResource (org.eclipse.xtext.resource.XtextResource)1 ReplaceRegion (org.eclipse.xtext.util.ReplaceRegion)1 Test (org.junit.Test)1