Search in sources :

Example 36 with TestXmlGrammar

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

the class IteratorFactoryTest method testTopDownScannerIteratorMarkReset.

@Test
public void testTopDownScannerIteratorMarkReset() {
    Grammar g = new TestXmlGrammar().create();
    IEntityIterator<IEntity> i = IteratorFactory.<IEntity>descendantOrSelfScannerIterator();
    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 37 with TestXmlGrammar

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

the class IteratorFactoryTest method testComposeIterator.

@Test
public void testComposeIterator() {
    Grammar g = new TestXmlGrammar().create();
    // query: g/phraseStructure/child()[ED = Production]/rule//[ED = Production]
    IEntityIterator<Production> pi = IteratorFactory.composeIterator(IteratorFactory.<Production>descendantOrSelfMatcherIterator().withPattern(GrammarsEntityDescriptorEnum.Production), IteratorFactory.featureByNameIterator("rule"), IteratorFactory.<Production>childMatcherIterator().withPattern(GrammarsEntityDescriptorEnum.Production), IteratorFactory.featureByNameIterator("phraseStructure"));
    pi.reset(g);
    Set<String> l = new HashSet<String>();
    for (Production p : pi) l.add(p.getName().getValue());
    assertEquals(16, l.size());
    NonTerminal prologNt = ((Production) ((Production) g.getPhraseStructure().wGet(0)).getRule().wGet(0)).getName();
    // query: g/phraseStructure/0/rule/0/name
    IEntityIterator<? extends IEntity> nti = IteratorFactory.composeIterator(IteratorFactory.featureByNameIterator("name"), IteratorFactory.featureByIndexIterator(0), IteratorFactory.featureByNameIterator("rule"), IteratorFactory.featureByIndexIterator(0), IteratorFactory.featureByNameIterator("phraseStructure"));
    nti.reset(g);
    assertTrue(nti.hasNext());
    assertSame(prologNt, nti.next());
    nti.reset(g.getPhraseStructure());
    assertFalse(nti.hasNext());
    nti.reset(g);
    assertTrue(nti.hasNext());
    assertSame(prologNt, nti.next());
}
Also used : 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) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 38 with TestXmlGrammar

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

the class IteratorFactoryTest method testDescendantAndDescendantOrSelfIterators.

@Test
public void testDescendantAndDescendantOrSelfIterators() {
    Grammar g = new TestXmlGrammar().create();
    IEntityIterator<IEntity> dsi = IteratorFactory.<IEntity>descendantOrSelfIterator();
    dsi.reset(g);
    IEntityIterator<IEntity> di = IteratorFactory.<IEntity>descendantIterator();
    di.reset(g);
    assertSame(g, dsi.next());
    assertSame(dsi.hasNext(), di.hasNext());
    boolean hasNext;
    do {
        assertSame(dsi.lookahead(), di.lookahead());
        assertSame(dsi.next(), di.next());
        assertSame(hasNext = dsi.hasNext(), di.hasNext());
    } while (hasNext);
}
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 39 with TestXmlGrammar

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

the class IteratorFactoryTest method testChildByNameAndByIndexIterators.

@Test
public void testChildByNameAndByIndexIterators() {
    Grammar g = new TestXmlGrammar().create();
    IEntityIterator<IEntity> i1 = IteratorFactory.featureByNameIterator("phraseStructure");
    i1.reset(g);
    assertTrue(i1.hasNext());
    assertSame(g.getPhraseStructure(), i1.next());
    assertFalse(i1.hasNext());
    assertNull(i1.lookahead());
    IEntityIterator<IEntity> i2 = IteratorFactory.featureByIndexIterator(0);
    i2.reset(g);
    assertTrue(i2.hasNext());
    assertSame(g.wGet(0), i2.next());
    assertFalse(i2.hasNext());
    assertNull(i2.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 40 with TestXmlGrammar

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

the class IteratorFactoryTest method testSelfIteratorMarkReset.

@Test
public void testSelfIteratorMarkReset() {
    Grammar g = new TestXmlGrammar().create();
    IEntityIterator<Grammar> si = IteratorFactory.<Grammar>selfIterator();
    si.reset(g);
    IEntityIterator<Grammar> si2 = si.clone();
    assertSame(g, si.next());
    assertFalse(si.hasNext());
    assertTrue(si2.hasNext());
    assertSame(g, si2.next());
}
Also used : 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