Search in sources :

Example 71 with TestXmlGrammar

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

the class IteratorFactoryTest method testAncestorIteratorMarkReset.

@Test
public void testAncestorIteratorMarkReset() {
    Grammar g = new TestXmlGrammar().create();
    Rule r = Matcher.find(GrammarsEntityDescriptorEnum.As, g, false);
    IEntityIterator<IEntity> i = IteratorFactory.ancestorIterator();
    i.reset(r);
    i.next();
    i.next();
    IEntityIterator<IEntity> i2 = i.clone();
    IEntityIterator<IEntity> i3 = i.clone();
    IEntity e1 = i.next();
    IEntity e2 = 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) Rule(org.whole.lang.grammars.model.Rule) Test(org.junit.Test)

Example 72 with TestXmlGrammar

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

the class IteratorFactoryTest method testAncestorOrSelfIteratorRemoveSet.

@Test
public void testAncestorOrSelfIteratorRemoveSet() {
    Grammar g = new TestXmlGrammar().create();
    MiscEntityFactory mef = MiscEntityFactory.instance(RegistryConfigurations.RESOLVER);
    Any any = CommonsEntityAdapterFactory.create(MiscEntityDescriptorEnum.Any, g);
    Misc innerMisc = mef.createMisc(any);
    any = CommonsEntityAdapterFactory.create(MiscEntityDescriptorEnum.Any, innerMisc);
    Misc outerMisc = mef.createMisc(any);
    Rule r = Matcher.find(GrammarsEntityDescriptorEnum.As, outerMisc, false);
    IEntityIterator<IEntity> i = IteratorFactory.ancestorOrSelfIterator();
    i.reset(r);
    IEntity next = null;
    while (i.hasNext()) {
        next = i.next();
        if (Matcher.match(MiscEntityDescriptorEnum.Misc, next))
            break;
    }
    assertSame(innerMisc, next);
    i.set(EntityUtils.clone(any));
    assertEquals(1, outerMisc.wSize());
    Rule r2 = Matcher.find(GrammarsEntityDescriptorEnum.As, outerMisc, false);
    assertTrue(Matcher.match(r, r2));
    assertNotSame(r, r2);
    i.remove();
    assertEquals(0, outerMisc.wSize());
    i.reset(r2);
    while (i.hasNext()) {
        next = i.next();
        if (i.hasNext())
            i.remove();
    }
    assertFalse(EntityUtils.hasParent(next));
}
Also used : MiscEntityFactory(org.whole.lang.misc.factories.MiscEntityFactory) IEntity(org.whole.lang.model.IEntity) TestXmlGrammar(org.whole.lang.grammars.util.TestXmlGrammar) Misc(org.whole.lang.misc.model.Misc) TestXmlGrammar(org.whole.lang.grammars.util.TestXmlGrammar) Grammar(org.whole.lang.grammars.model.Grammar) Rule(org.whole.lang.grammars.model.Rule) Any(org.whole.lang.misc.model.Any) Test(org.junit.Test)

Example 73 with TestXmlGrammar

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

the class IteratorFactoryTest method testChildReverseIteratorMarkReset.

@Test
public void testChildReverseIteratorMarkReset() {
    Grammar g = new TestXmlGrammar().create();
    IEntityIterator<IEntity> i = IteratorFactory.<IEntity>childReverseIterator();
    i.reset(g);
    i.next();
    i.next();
    IEntityIterator<IEntity> i2 = i.clone();
    IEntityIterator<IEntity> i3 = i.clone();
    IEntity e1 = i.next();
    IEntity e2 = 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 74 with TestXmlGrammar

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

the class IteratorFactoryTest method testChildIterator.

@Test
public void testChildIterator() {
    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();
        assertSame(productions.wGet(index++), p);
    }
    index = 0;
    ci = IteratorFactory.<Production>childScannerIterator();
    ci.reset(productions);
    while (ci.hasNext()) {
        Production p = ci.next();
        assertSame(productions.wGet(index++), p);
    }
    index = 0;
    ci = IteratorFactory.<Production>childMatcherIterator().withPattern(GrammarsEntityDescriptorEnum.Production);
    ci.reset(productions);
    while (ci.hasNext()) {
        Production p = ci.next();
        assertSame(productions.wGet(index++), p);
    }
}
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 75 with TestXmlGrammar

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

the class IteratorFactoryTest method testAncestorOrSelfIteratorMarkReset.

@Test
public void testAncestorOrSelfIteratorMarkReset() {
    Grammar g = new TestXmlGrammar().create();
    Rule r = Matcher.find(GrammarsEntityDescriptorEnum.As, g, false);
    IEntityIterator<IEntity> i = IteratorFactory.ancestorOrSelfIterator();
    i.reset(r);
    IEntity e1 = i.next();
    assertSame(r, e1);
    e1 = i.next();
    assertSame(r.wGetParent(), e1);
    IEntityIterator<IEntity> i2 = i.clone();
    IEntityIterator<IEntity> i3 = i.clone();
    e1 = i.next();
    IEntity e2 = 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) Rule(org.whole.lang.grammars.model.Rule) 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