Search in sources :

Example 66 with TestXmlGrammar

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

the class IteratorFactoryTest method testTopDownIteratorMarkReset.

@Test
public void testTopDownIteratorMarkReset() {
    Grammar g = new TestXmlGrammar().create();
    IEntityIterator<IEntity> i = IteratorFactory.<IEntity>descendantOrSelfIterator();
    i.reset(g);
    for (int j = 0; j < 15; j++) i.next();
    IEntityIterator<IEntity> i2 = i.clone();
    IEntityIterator<IEntity> i3 = i.clone();
    IEntity e1 = i.next();
    IEntity e2 = i.next();
    for (int j = 0; j < 7; j++) i.next();
    assertSame(e1, i2.next());
    assertSame(e1, i3.next());
    assertSame(e2, i3.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) Test(org.junit.Test)

Example 67 with TestXmlGrammar

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

the class IteratorFactoryTest method testTopDownMatcherIteratorMarkReset.

@Test
public void testTopDownMatcherIteratorMarkReset() {
    Grammar g = new TestXmlGrammar().create();
    IEntityIterator<IEntity> i = IteratorFactory.<IEntity>descendantOrSelfMatcherIterator().withPattern(GrammarsEntityDescriptorEnum.Rule);
    i.reset(g);
    for (int j = 0; j < 15; j++) i.next();
    IEntityIterator<IEntity> i2 = i.clone();
    IEntityIterator<IEntity> i3 = i.clone();
    IEntity e1 = i.next();
    IEntity e2 = i.next();
    for (int j = 0; j < 7; j++) i.next();
    assertSame(e1, i2.next());
    assertSame(e1, i3.next());
    assertSame(e2, i3.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) Test(org.junit.Test)

Example 68 with TestXmlGrammar

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

the class IteratorFactoryTest method testChildScannerIteratorAdd.

@Test
public void testChildScannerIteratorAdd() {
    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>childScannerIterator();
    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 69 with TestXmlGrammar

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

the class IteratorFactoryTest method testRootIteratorMarkReset.

@Test
public void testRootIteratorMarkReset() {
    Grammar g = new TestXmlGrammar().create();
    NonTerminal prologNt = ((Production) ((Production) g.getPhraseStructure().wGet(0)).getRule().wGet(0)).getName();
    IEntityIterator<IEntity> i = IteratorFactory.rootIterator();
    i.reset(prologNt);
    IEntityIterator<IEntity> i2 = i.clone();
    assertTrue(i.hasNext());
    assertSame(g, i.next());
    assertFalse(i.hasNext());
    assertTrue(i2.hasNext());
    assertSame(g, i2.next());
}
Also used : IEntity(org.whole.lang.model.IEntity) 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 70 with TestXmlGrammar

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

the class IteratorFactoryTest method testFollowingSiblingIterator.

@Test
public void testFollowingSiblingIterator() {
    Grammar g = new TestXmlGrammar().create();
    Productions productions = g.getPhraseStructure();
    int index = 0;
    IEntityIterator<Production> ci = IteratorFactory.<Production>childIterator();
    ci.reset(productions);
    while (ci.hasNext()) {
        Production p = ci.next();
        IEntityIterator<Production> fi = IteratorFactory.<Production>followingSiblingIterator();
        fi.reset(p);
        int findex = ++index;
        for (Production fp : fi) assertSame(productions.wGet(findex++), fp);
    }
    for (int i = 0; i < g.wSize(); i++) {
        IEntityIterator<IEntity> fi = IteratorFactory.<IEntity>followingSiblingIterator();
        fi.reset(g.wGet(i));
        for (int j = i + 1; j < g.wSize(); j++) assertSame(g.wGet(j), fi.next());
    }
    for (int i = 0; i < productions.wSize(); i++) {
        IEntityIterator<Production> fi = IteratorFactory.<Production>followingSiblingIterator();
        fi.reset(productions.wGet(i));
        for (int j = i + 1; j < productions.wSize(); j++) assertSame(productions.wGet(j), fi.next());
    }
}
Also used : Productions(org.whole.lang.grammars.model.Productions) IEntity(org.whole.lang.model.IEntity) 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)

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