Search in sources :

Example 1 with ReferenceGrammarTestLanguageGrammarAccess

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);
    }
}
Also used : ParserRule(org.eclipse.xtext.ParserRule) StringInputStream(org.eclipse.xtext.util.StringInputStream) XtextResource(org.eclipse.xtext.resource.XtextResource) ReferenceGrammarTestLanguageGrammarAccess(org.eclipse.xtext.testlanguages.services.ReferenceGrammarTestLanguageGrammarAccess) Test(org.junit.Test)

Aggregations

ParserRule (org.eclipse.xtext.ParserRule)1 XtextResource (org.eclipse.xtext.resource.XtextResource)1 ReferenceGrammarTestLanguageGrammarAccess (org.eclipse.xtext.testlanguages.services.ReferenceGrammarTestLanguageGrammarAccess)1 StringInputStream (org.eclipse.xtext.util.StringInputStream)1 Test (org.junit.Test)1