Search in sources :

Example 1 with Choose

use of org.whole.lang.grammars.model.Choose in project whole by wholeplatform.

the class IteratorFactoryTest method testTopDownIteratorAdd.

@Test
public void testTopDownIteratorAdd() {
    Grammar g = new TestXmlGrammar().create();
    Production production = (Production) g.getPhraseStructure().wGet(3);
    Choose choose = (Choose) production.getRule();
    int size = choose.wSize();
    int count = 0;
    Rule rAdded1 = null;
    Rule rAdded2 = null;
    IEntityIterator<IEntity> i = IteratorFactory.<IEntity>descendantOrSelfIterator();
    i.reset(production);
    i.next();
    i.next();
    while (i.hasNext()) {
        IEntity r = i.next();
        assertNotSame(rAdded1, r);
        assertNotSame(rAdded2, r);
        if (count == 0)
            assertSame(choose, r);
        else if (count == 1)
            i.add(rAdded1 = GrammarsEntityFactory.instance.createProduction());
        else if (count == 10) {
            i.add(rAdded1 = GrammarsEntityFactory.instance.createProduction());
            i.add(rAdded2 = GrammarsEntityFactory.instance.createProduction());
        }
        count++;
    }
    assertEquals(size + 3, choose.wSize());
}
Also used : Choose(org.whole.lang.grammars.model.Choose) 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) Rule(org.whole.lang.grammars.model.Rule) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)1 Choose (org.whole.lang.grammars.model.Choose)1 Grammar (org.whole.lang.grammars.model.Grammar)1 Production (org.whole.lang.grammars.model.Production)1 Rule (org.whole.lang.grammars.model.Rule)1 TestXmlGrammar (org.whole.lang.grammars.util.TestXmlGrammar)1 IEntity (org.whole.lang.model.IEntity)1