Search in sources :

Example 1 with IFormattedRegion

use of org.eclipse.xtext.formatting.INodeModelFormatter.IFormattedRegion in project xtext-core by eclipse.

the class FormatterTest method testBug471212.

@Test
public void testBug471212() throws Exception {
    String model = "test wrappingdt f\nb kw1";
    ICompositeNode node = NodeModelUtils.getNode(getModel(model)).getRootNode();
    AccessibleFormatter formatter = get(AccessibleFormatter.class);
    formatter.setNodeModelStreamer(get(BrokenStreamer.class));
    IFormattedRegion region = formatter.format(node, 0, model.length());
    String actual = region.getFormattedText();
    assertEquals(model, actual);
    assertEqualTokenStreams(model);
    assertPreserved(model);
}
Also used : IFormattedRegion(org.eclipse.xtext.formatting.INodeModelFormatter.IFormattedRegion) ICompositeNode(org.eclipse.xtext.nodemodel.ICompositeNode) Test(org.junit.Test)

Example 2 with IFormattedRegion

use of org.eclipse.xtext.formatting.INodeModelFormatter.IFormattedRegion in project dsl-devkit by dsldevkit.

the class AbstractFormatterTest method assertFormattedNM.

// test formatting based on the NodeModel
protected void assertFormattedNM(final String expected, final String model, final int offset, final int length) throws IOException {
    ICompositeNode node = NodeModelUtils.getNode(getModel(model)).getRootNode();
    IFormattedRegion r = getXtextTestUtil().get(INodeModelFormatter.class).format(node, offset, length);
    String actual = model.substring(0, r.getOffset()) + r.getFormattedText() + model.substring(r.getLength() + r.getOffset());
    Assert.assertEquals(expected, actual);
}
Also used : INodeModelFormatter(org.eclipse.xtext.formatting.INodeModelFormatter) IFormattedRegion(org.eclipse.xtext.formatting.INodeModelFormatter.IFormattedRegion) ICompositeNode(org.eclipse.xtext.nodemodel.ICompositeNode)

Example 3 with IFormattedRegion

use of org.eclipse.xtext.formatting.INodeModelFormatter.IFormattedRegion in project xtext-core by eclipse.

the class FormatterTest method assertFormattedNM.

// test formatting based on the NodeModel
protected void assertFormattedNM(String expected, String model, int offset, int lengt) throws Exception {
    EObject m = getModel(model);
    ICompositeNode node = NodeModelUtils.getNode(m).getRootNode();
    // System.out.println(EmfFormatter.objToStr(node));
    IFormattedRegion r = getNodeModelFormatter().format(node, offset, lengt);
    String actual = model.substring(0, r.getOffset()) + r.getFormattedText() + model.substring(r.getLength() + r.getOffset());
    assertEquals(expected, actual);
}
Also used : IFormattedRegion(org.eclipse.xtext.formatting.INodeModelFormatter.IFormattedRegion) EObject(org.eclipse.emf.ecore.EObject) ICompositeNode(org.eclipse.xtext.nodemodel.ICompositeNode)

Example 4 with IFormattedRegion

use of org.eclipse.xtext.formatting.INodeModelFormatter.IFormattedRegion in project xtext-core by eclipse.

the class FormatterWindowsLinebreakTest method assertFormattedNM.

@Override
protected void assertFormattedNM(String expected, final String modelP, int offset, int length) throws Exception {
    if (length != modelP.length() && offset != 0)
        return;
    String model = convertLineBreaks(modelP);
    ICompositeNode node = NodeModelUtils.getNode(getModel(model)).getRootNode();
    // System.out.println(EmfFormatter.objToStr(node));
    IFormattedRegion r = getNodeModelFormatter().format(node, 0, model.length());
    String actual = model.substring(0, r.getOffset()) + r.getFormattedText() + model.substring(r.getLength() + r.getOffset());
    assertEquals(revealLineBreaks(convertLineBreaks(expected)), revealLineBreaks(actual));
}
Also used : IFormattedRegion(org.eclipse.xtext.formatting.INodeModelFormatter.IFormattedRegion) ICompositeNode(org.eclipse.xtext.nodemodel.ICompositeNode)

Example 5 with IFormattedRegion

use of org.eclipse.xtext.formatting.INodeModelFormatter.IFormattedRegion in project dsl-devkit by dsldevkit.

the class AbstractFormattingTest method assertFormattedNodeModel.

/**
 * Test formatting based on the NodeModel.
 *
 * @param model
 *          the model to check
 * @param input
 *          String representing a serialized model
 * @param expected
 *          Expected formatted String
 * @param offset
 *          Offset from which to start formatting
 * @param length
 *          Length of region to format
 */
private void assertFormattedNodeModel(final EObject model, final String input, final String expected, final int offset, final int length) {
    ICompositeNode node = NodeModelUtils.getNode(model).getRootNode();
    IFormattedRegion region = getXtextTestUtil().get(INodeModelFormatter.class).format(node, offset, length);
    String actual = input.substring(0, offset) + region.getFormattedText() + input.substring(length + offset);
    Assert.assertEquals(expected.replaceAll(CR_LF, LF), actual.replaceAll(CR_LF, LF));
}
Also used : INodeModelFormatter(org.eclipse.xtext.formatting.INodeModelFormatter) IFormattedRegion(org.eclipse.xtext.formatting.INodeModelFormatter.IFormattedRegion) ICompositeNode(org.eclipse.xtext.nodemodel.ICompositeNode)

Aggregations

IFormattedRegion (org.eclipse.xtext.formatting.INodeModelFormatter.IFormattedRegion)5 ICompositeNode (org.eclipse.xtext.nodemodel.ICompositeNode)5 INodeModelFormatter (org.eclipse.xtext.formatting.INodeModelFormatter)2 EObject (org.eclipse.emf.ecore.EObject)1 Test (org.junit.Test)1