use of org.whole.lang.templates.ITemplateManager in project whole by wholeplatform.
the class SelectQueriesTest method testSelectDistinct.
@Test
public void testSelectDistinct() {
ITemplateManager tm = SelectQueriesTemplateManager.instance();
Grammar g = new TestXmlGrammar().create();
PathExpression pe1 = (PathExpression) tm.create("selectNonTerminalSet");
Set<String> set = new HashSet<String>();
for (NonTerminal nt : BehaviorUtils.<NonTerminal>compileAndLazyEvaluate(pe1, g)) if (!set.add(nt.getValue()))
fail();
assertEquals(22, set.size());
}
use of org.whole.lang.templates.ITemplateManager in project whole by wholeplatform.
the class SelectQueriesTest method testSelectTupleOfTemplatesAs.
@Test
public void testSelectTupleOfTemplatesAs() {
Model model = new XmlModel().create();
ITemplateManager tm = SelectQueriesTemplateManager.instance();
PathExpression query = (PathExpression) tm.create("selectTupleOfTemplatesAs");
IBindingManager bm = BindingManagerFactory.instance.createArguments();
for (IEntity tuple : BehaviorUtils.compileAndLazyEvaluate(query, model, bm)) {
FieldDeclaration f = (FieldDeclaration) tuple.wGet(0);
SingleVariableDeclaration p = (SingleVariableDeclaration) tuple.wGet(1);
ExpressionStatement s = (ExpressionStatement) tuple.wGet(2);
Feature e = (Feature) tuple.wGet(3);
String ptype = e.getType().wStringValue();
String pname = e.getName().wStringValue();
assertSame(f, bm.wGet("field"));
assertEquals(ptype, f.getType().wStringValue());
assertSame(p, bm.wGet("param"));
assertEquals(ptype, p.getType().wStringValue());
assertEquals(pname, p.getName().wStringValue());
assertSame(s, bm.wGet("init"));
assertEquals(pname, ((Assignment) s.getExpression()).getRightHandSide().wStringValue());
}
}
use of org.whole.lang.templates.ITemplateManager in project whole by wholeplatform.
the class SelectQueriesTest method testBindingScopes.
@Test
public void testBindingScopes() {
Model m = new XmlModel().create();
ITemplateManager tm = SelectQueriesTemplateManager.instance();
PathExpression query = (PathExpression) tm.create("selectBindingScopes");
IBindingManager bm = BindingManagerFactory.instance.createArguments();
BindingsTester bt = new BindingsTester(bm);
bm.wDefValue("bindingsTester", bt);
for (IEntity tuple : BehaviorUtils.compileAndLazyEvaluate(query, m, bm)) {
Document d = (Document) tuple.wGet(0);
SimpleEntity e = (SimpleEntity) tuple.wGet(1);
String eName = e.getName().getValue();
assertEquals(eName, d.wGet(0).wGet(1).wStringValue());
assertEquals(eName + eName, d.wGet(1).wGet(1).wStringValue());
assertEquals(eName + eName + eName + eName, d.wGet(2).wGet(1).wStringValue());
for (int f = 0; f < e.getFeatures().wSize(); f++) {
assertEquals(eName + eName + eName + eName + eName + eName + eName + eName, d.wGet(3).wGet(1 + f).wStringValue());
assertEquals("true", d.wGet(4).wGet(1 + f).wStringValue());
assertEquals("true", d.wGet(5).wGet(1 + f).wStringValue());
}
assertEquals(3, d.wGet(6).wSize());
assertTrue(EntityUtils.isVariable(d.wGet(6).wGet(1)));
assertTrue(EntityUtils.isVariable(d.wGet(6).wGet(2)));
}
}
use of org.whole.lang.templates.ITemplateManager in project whole by wholeplatform.
the class SelectQueriesTest method testSelectTemplateWithNestedEmptyQuery.
@Test
public void testSelectTemplateWithNestedEmptyQuery() {
ITemplateManager tm = SelectQueriesTemplateManager.instance();
Model m = new XmlModel().create();
PathExpression pe1 = (PathExpression) tm.create("selectTemplateWithNestedEmptyQuery");
for (ClassDeclaration t : BehaviorUtils.<ClassDeclaration>compileAndLazyEvaluate(pe1, m)) {
assertEquals(JavaEntityDescriptorEnum.ClassDeclaration, t.wGetEntityDescriptor());
assertEquals(2, t.getBodyDeclarations().wSize());
}
}
use of org.whole.lang.templates.ITemplateManager in project whole by wholeplatform.
the class SelectQueriesTest method testSelectTupleWithTemplates.
@Test
public void testSelectTupleWithTemplates() {
ITemplateManager tm = SelectQueriesTemplateManager.instance();
Grammar model = new TestXmlGrammar().create();
IBindingManager bm = BindingManagerFactory.instance.createArguments();
PathExpression query = (PathExpression) tm.create("selectTupleWithTemplates");
for (IEntity tuple : BehaviorUtils.compileAndLazyEvaluate(query, model, bm)) {
FieldDeclaration fd = (FieldDeclaration) tuple.wGet(0);
Feature f = (Feature) tuple.wGet(1);
As e = (As) tuple.wGet(2);
assertEquals(e.getName().getValue(), fd.getFragments().wGet(0).wGet(0).wStringValue());
assertEquals(e.getRule().wStringValue(), fd.getType().wStringValue());
assertEquals(e.getName().getValue(), f.getName().wStringValue());
assertEquals(e.getRule().wStringValue(), f.getType().wStringValue());
}
}
Aggregations