use of org.whole.lang.templates.ITemplateManager in project whole by wholeplatform.
the class ControlQueriesTest method testCall2.
@Test
public void testCall2() {
Grammar grammar = new TestXmlGrammar().create();
IBindingManager bm = BindingManagerFactory.instance.createArguments();
ITemplateManager tm = ControlQueriesTemplateManager.instance();
PathExpression query = (PathExpression) tm.create("call2");
int count = 0;
for (IEntity p : BehaviorUtils.compileAndLazyEvaluate(query, grammar, bm)) {
assertTrue(Matcher.match(GrammarsEntityDescriptorEnum.NonTerminal, p));
count++;
}
assertEquals(16, count);
}
use of org.whole.lang.templates.ITemplateManager in project whole by wholeplatform.
the class ControlQueriesTest method testQueryDecl8.
@Test
public void testQueryDecl8() {
ModelsEntityFactory mef = ModelsEntityFactory.instance;
FeatureModifiers modifiers = mef.createFeatureModifiers(mef.createFeatureModifier(FeatureModifierEnum.optional), mef.createFeatureModifier(FeatureModifierEnum.derived), mef.createFeatureModifier(FeatureModifierEnum.id));
ITemplateManager tm = ControlQueriesTemplateManager.instance();
PathExpression query = (PathExpression) tm.create("queryDecl8");
int count = 0;
for (IEntity p : BehaviorUtils.compileAndLazyEvaluate(query, modifiers)) {
IEntity modifier = modifiers.wGet(count++);
assertTrue(Matcher.match(modifier, p));
}
assertEquals(modifiers.wSize(), count);
}
use of org.whole.lang.templates.ITemplateManager in project whole by wholeplatform.
the class ControlQueriesTest method testIf5.
@Test
public void testIf5() {
ITemplateManager tm = ControlQueriesTemplateManager.instance();
PathExpression query = (PathExpression) tm.create("if5");
QueriesEntityFactory qef = QueriesEntityFactory.instance;
IEntity queryExp1 = qef.createDivision(qef.createIntLiteral(10), qef.createIntLiteral(8));
IBindingManager bm = BindingManagerFactory.instance.createBindingManager();
IEntity queryRes1 = BehaviorUtils.evaluateFirstResult(query, queryExp1, bm);
assertNotSame(queryExp1.wGet(0), queryRes1.wGet(0));
assertTrue(Matcher.match(queryExp1.wGet(0), queryRes1.wGet(0)));
assertNotSame(queryExp1.wGet(1), queryRes1.wGet(1));
assertTrue(Matcher.match(queryExp1.wGet(1), queryRes1.wGet(1)));
assertTrue(bm.wIsSet("a"));
assertTrue(bm.wIsSet("b"));
assertFalse(bm.wIsSet("exp1"));
assertFalse(bm.wIsSet("exp2"));
}
use of org.whole.lang.templates.ITemplateManager in project whole by wholeplatform.
the class ControlQueriesTest method testChoose1.
@Test
public void testChoose1() {
Model model = new ModelsModel().create();
ModelDeclarations decls = model.getDeclarations();
ITemplateManager tm = ControlQueriesTemplateManager.instance();
PathExpression query = (PathExpression) tm.create("choose1");
assertFalse(BehaviorUtils.compileAndLazyEvaluate(query, model).hasNext());
int i = 0;
while (!Matcher.match(ModelsEntityDescriptorEnum.SimpleEntity, decls.wGet(i))) i++;
SimpleEntity simpleEntity = (SimpleEntity) decls.wGet(i);
int j = 0;
for (IEntity name : BehaviorUtils.compileAndLazyEvaluate(query, simpleEntity)) {
assertEquals(((Feature) simpleEntity.getFeatures().wGet(j++)).getName().wStringValue(), name.wStringValue());
}
assertEquals(simpleEntity.getFeatures().wSize(), j);
while (!Matcher.match(ModelsEntityDescriptorEnum.CompositeEntity, decls.wGet(i))) i++;
CompositeEntity compositeEntity = (CompositeEntity) decls.wGet(i);
IEntityIterator<IEntity> iterator = BehaviorUtils.compileAndLazyEvaluate(query, compositeEntity);
assertTrue(iterator.hasNext());
assertEquals(compositeEntity.getComponentType().wStringValue(), iterator.next().wStringValue());
assertFalse(iterator.hasNext());
while (!Matcher.match(ModelsEntityDescriptorEnum.EnumEntity, decls.wGet(i))) i++;
EnumEntity enumEntity = (EnumEntity) decls.wGet(i);
iterator = BehaviorUtils.compileAndLazyEvaluate(query, enumEntity);
assertTrue(iterator.hasNext());
assertTrue(iterator.next() instanceof EnumValues);
assertFalse(iterator.hasNext());
}
use of org.whole.lang.templates.ITemplateManager in project whole by wholeplatform.
the class ControlQueriesTest method testCall5.
@Test
public void testCall5() {
Grammar grammar = new TestXmlGrammar().create();
IBindingManager bm = BindingManagerFactory.instance.createArguments();
ITemplateManager tm = ControlQueriesTemplateManager.instance();
PathExpression query = (PathExpression) tm.create("call5");
int count = 0;
for (IEntity p : BehaviorUtils.compileAndLazyEvaluate(query, grammar, bm)) {
assertTrue(Matcher.match(GrammarsEntityDescriptorEnum.Production, p));
count++;
}
assertEquals(4, count);
}
Aggregations