use of org.eclipse.xtext.testlanguages.services.ReferenceGrammarTestLanguageGrammarAccess in project xtext-core by eclipse.
the class SetEntryPointOnXtextResourceTest method test1.
@Test
public void test1() {
try {
this.with(ReferenceGrammarTestLanguageStandaloneSetup.class);
final String model = "kind (Hugo 13)";
final ParserRule kindRule = this.<ReferenceGrammarTestLanguageGrammarAccess>get(ReferenceGrammarTestLanguageGrammarAccess.class).getKindRule();
final XtextResource resource = this.createResource();
resource.setEntryPoint(kindRule);
StringInputStream _stringInputStream = new StringInputStream(model);
resource.load(_stringInputStream, CollectionLiterals.<Object, Object>emptyMap());
Assert.assertTrue(resource.getErrors().isEmpty());
Assert.assertEquals(kindRule, NodeModelUtils.getEntryParserRule(resource.getParseResult().getRootNode()));
final String originalNodeModel = NodeModelUtils.compactDump(resource.getParseResult().getRootNode(), false);
resource.update(0, model.length(), ((" " + model) + " "));
final String reparsedNodeModel = NodeModelUtils.compactDump(resource.getParseResult().getRootNode(), false);
Assert.assertEquals(originalNodeModel, reparsedNodeModel);
final ParserRule erwachsenerRule = this.<ReferenceGrammarTestLanguageGrammarAccess>get(ReferenceGrammarTestLanguageGrammarAccess.class).getErwachsenerRule();
resource.setEntryPoint(erwachsenerRule);
resource.update(0, model.length(), "erwachsener (Peter 30)");
Assert.assertEquals(erwachsenerRule, NodeModelUtils.getEntryParserRule(resource.getParseResult().getRootNode()));
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
Aggregations