use of org.whole.lang.grammars.util.TestXmlGrammar 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());
}
use of org.whole.lang.grammars.util.TestXmlGrammar in project whole by wholeplatform.
the class IteratorFactoryTest method testPrecedingSiblingIterator.
@Test
public void testPrecedingSiblingIterator() {
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>precedingSiblingIterator();
fi.reset(p);
int findex = index++;
for (Production fp : fi) assertSame(productions.wGet(--findex), fp);
}
for (int i = g.wSize() - 1; i >= 0; i--) {
IEntityIterator<IEntity> fi = IteratorFactory.<IEntity>precedingSiblingIterator();
fi.reset(g.wGet(i));
for (int j = i - 1; j >= 0; j--) assertSame(g.wGet(j), fi.next());
}
for (int i = productions.wSize() - 1; i >= 0; i--) {
IEntityIterator<Production> fi = IteratorFactory.<Production>precedingSiblingIterator();
fi.reset(productions.wGet(i));
for (int j = i - 1; j >= 0; j--) assertSame(productions.wGet(j), fi.next());
}
}
use of org.whole.lang.grammars.util.TestXmlGrammar in project whole by wholeplatform.
the class IteratorFactoryTest method testAxesPartitionInvariant.
@Test
public void testAxesPartitionInvariant() {
Grammar g = new TestXmlGrammar().create();
IEntityIterator<IEntity> i = IteratorFactory.<IEntity>descendantOrSelfIterator();
i.reset(g);
Set<IEntity> s = entities(i);
IEntityIterator<IEntity> i2 = IteratorFactory.<IEntity>descendantOrSelfIterator();
i2.reset(g);
for (IEntity e : i2) {
IEntityIterator<IEntity> i1 = IteratorFactory.<IEntity>ancestorIterator();
i1.reset(e);
Set<IEntity> s1 = entities(i1);
IEntityIterator<IEntity> i22 = IteratorFactory.selfIterator();
i22.reset(e);
Set<IEntity> s2 = entities(i22);
IEntityIterator<IEntity> i3 = IteratorFactory.<IEntity>descendantIterator();
i3.reset(e);
Set<IEntity> s3 = entities(i3);
IEntityIterator<IEntity> i4 = IteratorFactory.<IEntity>precedingIterator();
i4.reset(e);
Set<IEntity> s4 = entities(i4);
IEntityIterator<IEntity> i5 = IteratorFactory.<IEntity>followingIterator();
i5.reset(e);
Set<IEntity> s5 = entities(i5);
assertFalse(s1.removeAll(s2));
assertFalse(s1.removeAll(s3));
assertFalse(s1.removeAll(s4));
assertFalse(s1.removeAll(s5));
assertFalse(s2.removeAll(s3));
assertFalse(s2.removeAll(s4));
assertFalse(s2.removeAll(s5));
assertFalse(s3.removeAll(s4));
assertFalse(s3.removeAll(s5));
assertFalse(s4.removeAll(s5));
assertFalse(s.addAll(s1));
assertFalse(s.addAll(s2));
assertFalse(s.addAll(s3));
assertFalse(s.addAll(s4));
assertFalse(s.addAll(s5));
assertEquals(s.size(), s1.size() + s2.size() + s3.size() + s4.size() + s5.size());
}
}
use of org.whole.lang.grammars.util.TestXmlGrammar in project whole by wholeplatform.
the class PathExpressionsQueriesTest method testProduct1.
@Test
public void testProduct1() {
ITemplateManager tm = PathExpressionsQueriesTemplateManager.instance();
Grammar g = new TestXmlGrammar().create();
PathExpression pe1 = (PathExpression) tm.create("testProduct1");
IBindingManager bm = BindingManagerFactory.instance.createArguments();
int count = 0;
for (IEntity tuple : BehaviorUtils.compileAndLazyEvaluate(pe1, g, bm)) {
String vname = ((Production) bm.wGet("pp")).getName().getValue() + "x" + ((Production) bm.wGet("lp")).getName().getValue();
String tname = ((Production) tuple.wGet(0)).getName().getValue() + "x" + ((Production) tuple.wGet(1)).getName().getValue();
Assert.assertEquals(vname, tname);
count++;
}
Assert.assertEquals(g.getPhraseStructure().wSize() * g.getLexicalStructure().wSize(), count);
}
use of org.whole.lang.grammars.util.TestXmlGrammar in project whole by wholeplatform.
the class PathExpressionsQueriesTest method testPathWithKindAndLogicFiltersIterator.
@Test
public void testPathWithKindAndLogicFiltersIterator() {
ITemplateManager tm = PathExpressionsQueriesTemplateManager.instance();
QueriesEntityFactory ef = QueriesEntityFactory.instance;
for (IEntity p : BehaviorUtils.compileAndLazyEvaluate((PathExpression) tm.create("path2"), new TestXmlGrammar().create())) Assert.assertTrue(p.wGetEntityKind().equals(EntityKinds.SIMPLE) || p.wGetEntityKind().equals(EntityKinds.DATA));
for (IEntity p : BehaviorUtils.compileAndLazyEvaluate((PathExpression) tm.create("path3"), new TestXmlGrammar().create())) Assert.assertFalse(p.wGetEntityKind().equals(EntityKinds.COMPOSITE));
}
Aggregations