Search in sources :

Example 26 with TestXmlGrammar

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

the class IteratorFactoryTest method testChildReverseIteratorRemove.

@Test
public void testChildReverseIteratorRemove() {
    Grammar g = new TestXmlGrammar().create();
    Productions productions = EntityUtils.clone(g.getPhraseStructure());
    IEntityIterator<Production> ci = IteratorFactory.<Production>childReverseIterator();
    ci.reset(productions);
    while (ci.hasNext()) {
        Production p = ci.next();
        assertSame(productions.wGet(productions.wSize() - 1), p);
        ci.remove();
    }
    assertEquals(0, productions.wSize());
    productions = EntityUtils.clone(g.getPhraseStructure());
    ci = IteratorFactory.<Production>childReverseScannerIterator();
    ci.reset(productions);
    while (ci.hasNext()) {
        Production p = ci.next();
        assertSame(productions.wGet(productions.wSize() - 1), p);
        ci.remove();
    }
    assertEquals(0, productions.wSize());
    productions = EntityUtils.clone(g.getPhraseStructure());
    ci = IteratorFactory.<Production>childReverseMatcherIterator().withPattern(GrammarsEntityDescriptorEnum.Production);
    ci.reset(productions);
    while (ci.hasNext()) {
        Production p = ci.next();
        assertSame(productions.wGet(productions.wSize() - 1), p);
        ci.remove();
    }
    assertEquals(0, 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 27 with TestXmlGrammar

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

the class IteratorFactoryTest method testChildIteratorRemove.

@Test
public void testChildIteratorRemove() {
    Grammar g = new TestXmlGrammar().create();
    Productions productions = EntityUtils.clone(g.getPhraseStructure());
    IEntityIterator<Production> ci = IteratorFactory.<Production>childIterator();
    ci.reset(productions);
    while (ci.hasNext()) {
        Production p = ci.next();
        assertSame(productions.wGet(0), p);
        ci.remove();
    }
    assertEquals(0, productions.wSize());
    productions = EntityUtils.clone(g.getPhraseStructure());
    ci = IteratorFactory.<Production>childScannerIterator();
    ci.reset(productions);
    while (ci.hasNext()) {
        Production p = ci.next();
        assertSame(productions.wGet(0), p);
        ci.remove();
    }
    assertEquals(0, productions.wSize());
    productions = EntityUtils.clone(g.getPhraseStructure());
    ci = IteratorFactory.<Production>childMatcherIterator().withPattern(GrammarsEntityDescriptorEnum.Production);
    ci.reset(productions);
    while (ci.hasNext()) {
        Production p = ci.next();
        assertSame(productions.wGet(0), p);
        ci.remove();
    }
    assertEquals(0, 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 28 with TestXmlGrammar

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

the class IteratorFactoryTest method testFilterByIndexIterator.

@Test
public void testFilterByIndexIterator() {
    Grammar g = new TestXmlGrammar().create();
    Productions productions = g.getPhraseStructure();
    Production p = (Production) productions.wGet(1);
    IEntityIterator<?> i = IteratorFactory.filterByIndexIterator(IteratorFactory.followingSiblingIterator(), 0);
    i.reset(p);
    assertSingleton(i, productions.wGet(2));
    i = IteratorFactory.filterByIndexIterator(IteratorFactory.followingSiblingIterator(), 1);
    i.reset(p);
    assertSingleton(i, productions.wGet(3));
    i = IteratorFactory.filterByIndexIterator(IteratorFactory.ancestorOrSelfIterator(), 2);
    i.reset(p);
    assertSingleton(i, productions.wGetParent());
    i = IteratorFactory.filterByIndexIterator(IteratorFactory.descendantOrSelfIterator(), 1);
    i.reset(p);
    assertSingleton(i, p.getName());
}
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 29 with TestXmlGrammar

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

the class IteratorFactoryTest method testFollowingIterator.

@Test
public void testFollowingIterator() {
    Grammar g = new TestXmlGrammar().create();
    IEntityIterator<IEntity> tdi = IteratorFactory.<IEntity>descendantOrSelfIterator();
    tdi.reset(g);
    for (IEntity e : tdi) {
        IEntityIterator<IEntity> fi = IteratorFactory.<IEntity>followingIterator();
        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)

Example 30 with TestXmlGrammar

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

the class IteratorFactoryTest method testVariableIterator.

@Test
public void testVariableIterator() {
    Grammar g = new TestXmlGrammar().create();
    IBindingManager bindings = BindingManagerFactory.instance.createBindingManager();
    IEntityIterator<IEntity> i = IteratorFactory.variableIterator("testVar");
    i.setBindings(bindings);
    assertFalse(i.hasNext());
    i.reset(g);
    assertFalse(i.hasNext());
    bindings.wDef("testVar", g);
    assertTrue(i.hasNext());
    IEntity g1 = i.next();
    assertSame(g, g1);
    assertFalse(i.hasNext());
    i.reset(g);
    assertTrue(i.hasNext());
    g1 = i.next();
    assertSame(g, g1);
    assertFalse(i.hasNext());
    bindings = BindingManagerFactory.instance.createBindingManager();
    bindings.wDef("testVar", g);
    i = IteratorFactory.variableIterator("testVar");
    i.setBindings(bindings);
    assertTrue(i.hasNext());
    g1 = i.next();
    assertSame(g, g1);
    assertFalse(i.hasNext());
    i.reset(g);
    IEntityIterator<IEntity> i2 = i.clone();
    assertTrue(i.hasNext());
    g1 = i.next();
    assertSame(g, g1);
    assertFalse(i.hasNext());
    assertTrue(i2.hasNext());
    g1 = i2.next();
    assertSame(g, g1);
    assertFalse(i2.hasNext());
}
Also used : IEntity(org.whole.lang.model.IEntity) TestXmlGrammar(org.whole.lang.grammars.util.TestXmlGrammar) IBindingManager(org.whole.lang.bindings.IBindingManager) 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