Search in sources :

Example 31 with TestXmlGrammar

use of org.whole.lang.grammars.util.TestXmlGrammar in project whole by wholeplatform.

the class IteratorFactoryTest method testParentIteratorMarkReset.

@Test
public void testParentIteratorMarkReset() {
    Grammar g = new TestXmlGrammar().create();
    Rule r = Matcher.find(GrammarsEntityDescriptorEnum.As, g, false);
    IEntityIterator<IEntity> i = IteratorFactory.parentIterator();
    i.reset(r);
    IEntityIterator<IEntity> i2 = i.clone();
    assertTrue(i.hasNext());
    IEntity e1 = i.next();
    assertSame(r.wGetParent(), e1);
    assertTrue(i2.hasNext());
    assertSame(r.wGetParent(), i2.next());
}
Also used : IEntity(org.whole.lang.model.IEntity) TestXmlGrammar(org.whole.lang.grammars.util.TestXmlGrammar) TestXmlGrammar(org.whole.lang.grammars.util.TestXmlGrammar) Grammar(org.whole.lang.grammars.model.Grammar) Rule(org.whole.lang.grammars.model.Rule) Test(org.junit.Test)

Example 32 with TestXmlGrammar

use of org.whole.lang.grammars.util.TestXmlGrammar in project whole by wholeplatform.

the class IteratorFactoryTest method testTopDownMatcherIteratorRemove.

@Test
public void testTopDownMatcherIteratorRemove() {
    Grammar g = new TestXmlGrammar().create();
    g.wRemove(GrammarsFeatureDescriptorEnum.lexicalStructure);
    Productions productions = g.getPhraseStructure();
    IEntityIterator<Production> ci = IteratorFactory.<Production>descendantOrSelfMatcherIterator().withPattern(GrammarsEntityDescriptorEnum.Production);
    ci.reset(g);
    while (ci.hasNext()) {
        Production p = ci.next();
        assertSame(productions.wGet(0), p);
        ci.remove();
    }
    assertEquals(0, productions.wSize());
    g = new TestXmlGrammar().create();
    IEntityIterator<NonTerminal> ci2 = IteratorFactory.<NonTerminal>descendantOrSelfMatcherIterator().withPattern(GrammarsEntityDescriptorEnum.NonTerminal);
    ci2.reset(g);
    while (ci2.hasNext()) {
        NonTerminal nt = ci2.next();
        ci2.remove();
    }
    assertNull(Matcher.find(GenericTraversalFactory.instance.sequence(GenericMatcherFactory.instance.hasTypeMatcher(GrammarsEntityDescriptorEnum.NonTerminal), GenericMatcherFactory.instance.isImplMatcher()), g, false));
}
Also used : Productions(org.whole.lang.grammars.model.Productions) TestXmlGrammar(org.whole.lang.grammars.util.TestXmlGrammar) Production(org.whole.lang.grammars.model.Production) NonTerminal(org.whole.lang.grammars.model.NonTerminal) TestXmlGrammar(org.whole.lang.grammars.util.TestXmlGrammar) Grammar(org.whole.lang.grammars.model.Grammar) Test(org.junit.Test)

Example 33 with TestXmlGrammar

use of org.whole.lang.grammars.util.TestXmlGrammar in project whole by wholeplatform.

the class IteratorFactoryTest method testChildIteratorAdd.

@Test
public void testChildIteratorAdd() {
    Grammar g = new TestXmlGrammar().create();
    Productions productions = g.getPhraseStructure();
    int size = productions.wSize();
    int count = 0;
    Production pAdded1 = null;
    Production pAdded2 = null;
    IEntityIterator<Production> i = IteratorFactory.<Production>childIterator();
    i.reset(productions);
    while (i.hasNext()) {
        Production p = i.next();
        assertNotSame(pAdded1, p);
        assertNotSame(pAdded2, p);
        count++;
        if (count == 1)
            i.add(pAdded1 = GrammarsEntityFactory.instance.createProduction());
        if (count == 3) {
            i.add(pAdded1 = GrammarsEntityFactory.instance.createProduction());
            i.add(pAdded2 = GrammarsEntityFactory.instance.createProduction());
        }
    }
    assertEquals(size, count);
    assertEquals(size + 3, productions.wSize());
}
Also used : Productions(org.whole.lang.grammars.model.Productions) TestXmlGrammar(org.whole.lang.grammars.util.TestXmlGrammar) Production(org.whole.lang.grammars.model.Production) TestXmlGrammar(org.whole.lang.grammars.util.TestXmlGrammar) Grammar(org.whole.lang.grammars.model.Grammar) Test(org.junit.Test)

Example 34 with TestXmlGrammar

use of org.whole.lang.grammars.util.TestXmlGrammar in project whole by wholeplatform.

the class IteratorFactoryTest method testRootBehavior.

@Test
public void testRootBehavior() {
    Grammar g = new TestXmlGrammar().create();
    CommonsEntityFactory.instance.createRootFragment(g.wGetAdapter(CommonsEntityDescriptorEnum.Any));
    // rootParent
    IEntity gParent = g.wGetParent();
    IEntityIterator<IEntity> i = IteratorFactory.rootIterator();
    i.reset(g);
    assertTrue(i.hasNext());
    IEntity e1 = i.next();
    assertSame(g, e1);
    i = IteratorFactory.rootIterator();
    i.reset(gParent);
    assertTrue(i.hasNext());
    e1 = i.next();
    assertSame(g, e1);
    i = IteratorFactory.fragmentRootIterator();
    i.reset(gParent);
    assertTrue(i.hasNext());
    e1 = i.next();
    assertSame(g, e1);
    i = IteratorFactory.parentIterator();
    i.reset(g);
    assertTrue(i.hasNext());
    e1 = i.next();
    assertSame(g.wGetParent(), e1);
    i = IteratorFactory.parentIterator();
    i.reset(gParent);
    assertFalse(i.hasNext());
    assertNull(i.lookahead());
    i = IteratorFactory.ancestorIterator();
    i.reset(g);
    assertTrue(i.hasNext());
    e1 = i.next();
    assertSame(g.wGetParent(), e1);
    i = IteratorFactory.ancestorIterator();
    i.reset(gParent);
    assertFalse(i.hasNext());
    assertNull(i.lookahead());
    i = IteratorFactory.ancestorOrSelfIterator();
    i.reset(g);
    assertTrue(i.hasNext());
    e1 = i.next();
    assertSame(g, e1);
    assertTrue(i.hasNext());
    e1 = i.next();
    assertSame(g.wGetParent(), e1);
    i = IteratorFactory.ancestorOrSelfIterator();
    i.reset(gParent);
    assertTrue(i.hasNext());
    e1 = i.next();
    assertSame(g.wGetParent(), e1);
    assertFalse(i.hasNext());
    assertNull(i.lookahead());
    IEntityIterator<Grammar> i2 = IteratorFactory.selfIterator();
    i2.reset(g);
    assertTrue(i2.hasNext());
    e1 = i2.next();
    assertSame(g, e1);
    assertFalse(i2.hasNext());
    assertNull(i2.lookahead());
    i = IteratorFactory.selfIterator();
    i.reset(gParent);
    assertTrue(i.hasNext());
    e1 = i.next();
    assertSame(gParent, e1);
    assertFalse(i.hasNext());
    assertNull(i.lookahead());
    g = GrammarsEntityFactory.instance.createGrammar();
    // nullEntity
    gParent = g.wGetParent();
    i = IteratorFactory.rootIterator();
    i.reset(g);
    assertTrue(i.hasNext());
    e1 = i.next();
    assertSame(g, e1);
    i = IteratorFactory.rootIterator();
    i.reset(gParent);
    assertFalse(i.hasNext());
    assertNull(i.lookahead());
    i = IteratorFactory.parentIterator();
    i.reset(g);
    assertFalse(i.hasNext());
    assertNull(i.lookahead());
    i = IteratorFactory.parentIterator();
    i.reset(gParent);
    assertFalse(i.hasNext());
    assertNull(i.lookahead());
    i = IteratorFactory.ancestorIterator();
    i.reset(g);
    assertFalse(i.hasNext());
    assertNull(i.lookahead());
    i = IteratorFactory.ancestorIterator();
    i.reset(gParent);
    assertFalse(i.hasNext());
    assertNull(i.lookahead());
    i = IteratorFactory.ancestorOrSelfIterator();
    i.reset(g);
    assertTrue(i.hasNext());
    e1 = i.next();
    assertSame(g, e1);
    assertFalse(i.hasNext());
    assertNull(i.lookahead());
    i = IteratorFactory.ancestorOrSelfIterator();
    i.reset(gParent);
    assertFalse(i.hasNext());
    assertNull(i.lookahead());
    i2 = IteratorFactory.selfIterator();
    i2.reset(g);
    assertTrue(i2.hasNext());
    e1 = i2.next();
    assertSame(g, e1);
    assertFalse(i2.hasNext());
    assertNull(i2.lookahead());
    i = IteratorFactory.selfIterator();
    i.reset(gParent);
    assertFalse(i.hasNext());
    assertNull(i.lookahead());
}
Also used : IEntity(org.whole.lang.model.IEntity) TestXmlGrammar(org.whole.lang.grammars.util.TestXmlGrammar) TestXmlGrammar(org.whole.lang.grammars.util.TestXmlGrammar) Grammar(org.whole.lang.grammars.model.Grammar) Test(org.junit.Test)

Example 35 with TestXmlGrammar

use of org.whole.lang.grammars.util.TestXmlGrammar in project whole by wholeplatform.

the class IteratorFactoryTest method testPrecedingIterator.

@Test
public void testPrecedingIterator() {
    Grammar g = new TestXmlGrammar().create();
    IEntityIterator<IEntity> tdi = IteratorFactory.<IEntity>descendantOrSelfReverseIterator();
    tdi.reset(g);
    for (IEntity e : tdi) {
        IEntityIterator<IEntity> fi = IteratorFactory.<IEntity>precedingIterator();
        fi.reset(e);
        if (fi.hasNext()) {
            IEntityIterator<IEntity> tdi2 = tdi.clone();
            tdi2.prune();
            assertSame(tdi2.hasNext(), fi.hasNext());
            assertSame(tdi2.lookahead(), fi.lookahead());
            for (IEntity fe : fi) {
                IEntity e1 = tdi2.next();
                assertSame(e1, fe);
            }
        }
    }
}
Also used : IEntity(org.whole.lang.model.IEntity) TestXmlGrammar(org.whole.lang.grammars.util.TestXmlGrammar) TestXmlGrammar(org.whole.lang.grammars.util.TestXmlGrammar) Grammar(org.whole.lang.grammars.model.Grammar) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)75 TestXmlGrammar (org.whole.lang.grammars.util.TestXmlGrammar)75 Grammar (org.whole.lang.grammars.model.Grammar)74 IEntity (org.whole.lang.model.IEntity)46 ITemplateManager (org.whole.lang.templates.ITemplateManager)41 Production (org.whole.lang.grammars.model.Production)35 PathExpression (org.whole.lang.queries.model.PathExpression)33 IBindingManager (org.whole.lang.bindings.IBindingManager)27 QueriesGrammar (org.whole.lang.grammars.codebase.QueriesGrammar)19 Productions (org.whole.lang.grammars.model.Productions)14 NonTerminal (org.whole.lang.grammars.model.NonTerminal)13 PrettyPrinterOperation.toPrettyPrintString (org.whole.lang.operations.PrettyPrinterOperation.toPrettyPrintString)7 HashSet (java.util.HashSet)6 Rule (org.whole.lang.grammars.model.Rule)6 As (org.whole.lang.grammars.model.As)3 Feature (org.whole.lang.models.model.Feature)3 ArrayList (java.util.ArrayList)1 Category (org.junit.experimental.categories.Category)1 ClasspathPersistenceProvider (org.whole.lang.codebase.ClasspathPersistenceProvider)1 Choose (org.whole.lang.grammars.model.Choose)1