use of org.eclipse.xtext.formatting.INodeModelFormatter in project xtext-core by eclipse.
the class AnotherFormatterTest method loadModel.
@Test
public void loadModel() throws Exception {
ParseHelper<Root> parseHelper = getInjector().getInstance(Key.get(new TypeLiteral<ParseHelper<Root>>() {
}));
INodeModelFormatter formatter = getInjector().getInstance(INodeModelFormatter.class);
ArrayList<String> lines = Lists.newArrayList("test sample {", " // just a comment", "\t}", "");
Root root = parseHelper.parse(Joiner.on(System.lineSeparator()).join(lines));
Assert.assertNotNull(root);
EList<Resource.Diagnostic> errors = root.eResource().getErrors();
Assert.assertTrue("Unexpected errors: " + Joiner.on(", ").join(errors), errors.isEmpty());
ICompositeNode rootNode = ((XtextResource) root.eResource()).getParseResult().getRootNode();
ArrayList<String> expectedLines = Lists.newArrayList("test sample {", "", "// just a comment", "}");
String expected = Joiner.on(System.lineSeparator()).join(expectedLines);
INodeModelFormatter.IFormattedRegion formattedRegion = formatter.format(rootNode, rootNode.getTotalOffset(), rootNode.getTotalLength());
Assert.assertEquals(expected, formattedRegion.getFormattedText());
formattedRegion = formatter.format(rootNode, rootNode.getTotalOffset(), rootNode.getTotalLength());
Assert.assertEquals(expected, formattedRegion.getFormattedText());
}
Aggregations