use of org.whole.lang.queries.model.PathExpression in project whole by wholeplatform.
the class ControlQueriesTest method testCall6.
@Test
public void testCall6() {
Grammar grammar = new TestXmlGrammar().create();
IBindingManager bm = BindingManagerFactory.instance.createArguments();
ITemplateManager tm = ControlQueriesTemplateManager.instance();
PathExpression query = (PathExpression) tm.create("call6");
int count = 0;
for (IEntity p : BehaviorUtils.compileAndLazyEvaluate(query, grammar, bm)) {
assertTrue(Matcher.match(GrammarsEntityDescriptorEnum.Production, p));
assertEquals("IContent", ((Production) p).getName().getValue());
count++;
}
assertEquals(1, count);
}
use of org.whole.lang.queries.model.PathExpression in project whole by wholeplatform.
the class ControlQueriesTest method testFor1.
@Test
public void testFor1() {
Model model = new XmlModel().create();
ModelDeclarations decls = model.getDeclarations();
ITemplateManager tm = ControlQueriesTemplateManager.instance();
PathExpression query = (PathExpression) tm.create("for1");
int i = 0;
for (IEntity name : BehaviorUtils.compileAndLazyEvaluate(query, model)) {
while (!Matcher.match(ModelsEntityDescriptorEnum.SimpleEntity, decls.wGet(i))) i++;
assertEquals(((SimpleEntity) decls.wGet(i++)).getName().wStringValue(), name.wStringValue());
}
assertTrue(i > 0);
}
use of org.whole.lang.queries.model.PathExpression in project whole by wholeplatform.
the class ControlQueriesTest method testChoose3.
@Test
public void testChoose3() {
Model model = new ModelsModel().create();
ModelDeclarations decls = model.getDeclarations();
ITemplateManager tm = ControlQueriesTemplateManager.instance();
PathExpression query = (PathExpression) tm.create("choose3");
int i = 0;
IEntityIterator<IEntity> iterator = BehaviorUtils.compileAndLazyEvaluate(query, model);
while (iterator.hasNext()) {
IEntity result = iterator.next();
IEntity decl = decls.wGet(i++);
switch(decl.wGetEntityOrd()) {
case ModelsEntityDescriptorEnum.SimpleEntity_ord:
Features features = ((SimpleEntity) decl).getFeatures();
if (!features.isEmpty())
assertEquals(features.get(0).getName().wStringValue(), result.wStringValue());
break;
case ModelsEntityDescriptorEnum.CompositeEntity_ord:
CompositeEntity compositeEntity = (CompositeEntity) decl;
assertEquals(compositeEntity.getComponentType().wStringValue(), result.wStringValue());
break;
case ModelsEntityDescriptorEnum.DataEntity_ord:
DataEntity dataEntity = (DataEntity) decl;
assertEquals(dataEntity.getDataType().wStringValue(), result.wStringValue());
break;
case ModelsEntityDescriptorEnum.EnumEntity_ord:
EnumEntity enumEntity = (EnumEntity) decl;
assertEquals(enumEntity.getValues().wGet(0).wStringValue(), result.wStringValue());
break;
}
}
}
use of org.whole.lang.queries.model.PathExpression in project whole by wholeplatform.
the class ControlQueriesTest method testQueryDecl5.
@Test
public void testQueryDecl5() {
Model model = new ModelsModel().create();
ModelDeclarations decls = model.getDeclarations();
IBindingManager bm = BindingManagerFactory.instance.createArguments();
ITemplateManager tm = ControlQueriesTemplateManager.instance();
PathExpression query = (PathExpression) tm.create("queryDecl5");
int count = 0;
int index = 0;
for (IEntity p : BehaviorUtils.compileAndLazyEvaluate(query, model, bm)) {
IEntity decl = decls.wGet(index++);
switch(decl.wGetEntityOrd()) {
case ModelsEntityDescriptorEnum.SimpleEntity_ord:
Features features = ((SimpleEntity) decl).getFeatures();
if (!features.isEmpty())
assertEquals(features.get(0).getName().wStringValue(), p.wStringValue());
break;
case ModelsEntityDescriptorEnum.CompositeEntity_ord:
assertEquals(((CompositeEntity) decl).getComponentType().wStringValue(), p.wStringValue());
break;
case ModelsEntityDescriptorEnum.DataEntity_ord:
assertEquals(((DataEntity) decl).getName().wStringValue(), p.wStringValue());
break;
case ModelsEntityDescriptorEnum.EnumEntity_ord:
assertTrue(Matcher.matchImpl(ModelsEntityDescriptorEnum.EnumEntity, p));
break;
}
count++;
}
assertEquals(33, count);
}
use of org.whole.lang.queries.model.PathExpression in project whole by wholeplatform.
the class ControlQueriesTest method testChoose2.
@Test
public void testChoose2() {
Model model = new ModelsModel().create();
ModelDeclarations decls = model.getDeclarations();
ITemplateManager tm = ControlQueriesTemplateManager.instance();
PathExpression query = (PathExpression) tm.create("choose2");
int i = 0;
IEntityIterator<IEntity> iterator = BehaviorUtils.compileAndLazyEvaluate(query, model);
while (iterator.hasNext()) {
IEntity result;
IEntity decl = decls.wGet(i++);
switch(decl.wGetEntityOrd()) {
case ModelsEntityDescriptorEnum.SimpleEntity_ord:
IEntity features = ((SimpleEntity) decl).getFeatures();
for (int j = 0; j < features.wSize(); j++) {
result = iterator.next();
assertEquals(((Feature) features.wGet(j)).getName().wStringValue(), result.wStringValue());
}
break;
case ModelsEntityDescriptorEnum.CompositeEntity_ord:
result = iterator.next();
CompositeEntity compositeEntity = (CompositeEntity) decl;
assertEquals(compositeEntity.getComponentType().wStringValue(), result.wStringValue());
break;
case ModelsEntityDescriptorEnum.DataEntity_ord:
result = iterator.next();
DataEntity dataEntity = (DataEntity) decl;
assertEquals(dataEntity.getDataType().wStringValue(), result.wStringValue());
break;
case ModelsEntityDescriptorEnum.EnumEntity_ord:
EnumValues enumValues = ((EnumEntity) decl).getValues();
if (enumValues.wIsEmpty())
iterator.next();
else
for (int j = 0; j < enumValues.wSize(); j++) {
result = iterator.next();
assertEquals(enumValues.wGet(j).wStringValue(), result.wStringValue());
}
break;
}
}
}
Aggregations