Search in sources :

Example 11 with Tree

use of org.eclipse.xtext.parser.indentation.indentationAwareTestLanguage.Tree in project xtext-core by eclipse.

the class IndentationAwareLanguageTest method testTree_01.

@Test
public void testTree_01() {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("a");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("b");
    _builder.newLine();
    _builder.append("\t ");
    _builder.append("c");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("d");
    _builder.newLine();
    final Tree tree = this.parseAndValidate(_builder);
    StringConcatenation _builder_1 = new StringConcatenation();
    _builder_1.append("a");
    _builder_1.newLine();
    _builder_1.append("\t");
    _builder_1.append("b");
    _builder_1.newLine();
    _builder_1.append("\t\t");
    _builder_1.append("c");
    _builder_1.newLine();
    _builder_1.append("\t");
    _builder_1.append("d");
    _builder_1.newLine();
    Assert.assertEquals(_builder_1.toString(), this.asText(tree));
}
Also used : StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) Tree(org.eclipse.xtext.parser.indentation.indentationAwareTestLanguage.Tree) Test(org.junit.Test)

Example 12 with Tree

use of org.eclipse.xtext.parser.indentation.indentationAwareTestLanguage.Tree in project xtext-core by eclipse.

the class IndentationAwareLanguageTest method parseAndValidate.

private Tree parseAndValidate(final CharSequence s) {
    final Tree result = this.parse(s);
    this.validationTestHelper.assertNoIssues(result);
    Resource _eResource = result.eResource();
    final XtextResource resource = ((XtextResource) _eResource);
    final ICompositeNode node = resource.getParseResult().getRootNode();
    this.invariantChecker.checkInvariant(node);
    return result;
}
Also used : XtextResource(org.eclipse.xtext.resource.XtextResource) Resource(org.eclipse.emf.ecore.resource.Resource) Tree(org.eclipse.xtext.parser.indentation.indentationAwareTestLanguage.Tree) ICompositeNode(org.eclipse.xtext.nodemodel.ICompositeNode) XtextResource(org.eclipse.xtext.resource.XtextResource)

Example 13 with Tree

use of org.eclipse.xtext.parser.indentation.indentationAwareTestLanguage.Tree in project xtext-core by eclipse.

the class IndentationAwarePartialParsingErrorTest method testResourceUpdate_02.

@Test
public void testResourceUpdate_02() {
    try {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("a");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("x");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("b // two tabs");
        _builder.newLine();
        _builder.append("\t         ");
        _builder.append("// tab and 8 spaces (eq 2 tabs)");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("y");
        _builder.newLine();
        final String model = _builder.toString();
        final Tree tree = this.parseHelper.parse(model);
        Resource _eResource = tree.eResource();
        final XtextResource resource = ((XtextResource) _eResource);
        final int idx = model.indexOf(" // tab");
        resource.update(idx, 0, "c");
        EObject _head = IterableExtensions.<EObject>head(resource.getContents());
        final Tree reparsed = ((Tree) _head);
        Assert.assertNotSame(tree, reparsed);
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : EObject(org.eclipse.emf.ecore.EObject) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) XtextResource(org.eclipse.xtext.resource.XtextResource) Resource(org.eclipse.emf.ecore.resource.Resource) Tree(org.eclipse.xtext.parser.indentation.indentationAwareTestLanguage.Tree) XtextResource(org.eclipse.xtext.resource.XtextResource) Test(org.junit.Test)

Example 14 with Tree

use of org.eclipse.xtext.parser.indentation.indentationAwareTestLanguage.Tree in project xtext-core by eclipse.

the class IndentationAwareLanguageTest method testIgnoreEmptyLines_4.

@Test
public void testIgnoreEmptyLines_4() {
    final Tree tree = this.parse("\"first\"\n\t");
    Assert.assertNotNull(tree);
    Assert.assertEquals(1, tree.getMoreNodes().size());
    Assert.assertEquals("first", IterableExtensions.<OtherTreeNode>head(tree.getMoreNodes()).getName());
    Assert.assertNull(IterableExtensions.<OtherTreeNode>head(tree.getMoreNodes()).getChildList());
}
Also used : OtherTreeNode(org.eclipse.xtext.parser.indentation.indentationAwareTestLanguage.OtherTreeNode) Tree(org.eclipse.xtext.parser.indentation.indentationAwareTestLanguage.Tree) Test(org.junit.Test)

Example 15 with Tree

use of org.eclipse.xtext.parser.indentation.indentationAwareTestLanguage.Tree in project xtext-core by eclipse.

the class IndentationAwareLanguageTest method testTree_07.

@Test
public void testTree_07() {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("\"a\"");
    _builder.newLine();
    _builder.append("\t");
    _builder.newLine();
    _builder.append("\"b\"");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.newLine();
    final Tree tree = this.parseAndValidate(_builder);
    StringConcatenation _builder_1 = new StringConcatenation();
    _builder_1.append("a");
    _builder_1.newLine();
    _builder_1.append("b");
    _builder_1.newLine();
    Assert.assertEquals(_builder_1.toString(), this.asText(tree));
}
Also used : StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) Tree(org.eclipse.xtext.parser.indentation.indentationAwareTestLanguage.Tree) Test(org.junit.Test)

Aggregations

Tree (org.eclipse.xtext.parser.indentation.indentationAwareTestLanguage.Tree)24 Test (org.junit.Test)21 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)15 OtherTreeNode (org.eclipse.xtext.parser.indentation.indentationAwareTestLanguage.OtherTreeNode)10 TreeNode (org.eclipse.xtext.parser.indentation.indentationAwareTestLanguage.TreeNode)7 Resource (org.eclipse.emf.ecore.resource.Resource)3 XtextResource (org.eclipse.xtext.resource.XtextResource)3 EObject (org.eclipse.emf.ecore.EObject)2 ICompositeNode (org.eclipse.xtext.nodemodel.ICompositeNode)2 EPackage (org.eclipse.emf.ecore.EPackage)1 Action (org.eclipse.xtext.Action)1 Parameter (org.eclipse.xtext.Parameter)1 ParserRule (org.eclipse.xtext.ParserRule)1 ChildList (org.eclipse.xtext.parser.indentation.indentationAwareTestLanguage.ChildList)1