use of org.whole.lang.templates.ITemplateManager in project whole by wholeplatform.
the class PathExpressionsQueriesTest method testHelperResultAs.
@Test
public void testHelperResultAs() {
ITemplateManager tm = PathExpressionsQueriesTemplateManager.instance();
Model m = new XmlModel().create();
PathExpression query = (PathExpression) tm.create("helperResultAs");
IBindingManager bm = BindingManagerFactory.instance.createArguments();
bm.wDefValue("ftype", "firstName");
IEntityIterator<?> iterator = BehaviorUtils.<FieldDeclaration>compileAndLazyEvaluate(query, m, bm);
Assert.assertTrue(iterator.hasNext());
IEntity result = iterator.next();
IEntity as = bm.wGet("jtype");
Assert.assertEquals("FirstName", result.wStringValue());
Assert.assertEquals("FirstName", as.wStringValue());
Assert.assertFalse(iterator.hasNext());
iterator.reset(m);
bm.wDefValue("ftype", "secondName");
Assert.assertTrue(iterator.hasNext());
IEntity result2 = iterator.next();
IEntity as2 = bm.wGet("jtype");
Assert.assertEquals("SecondName", result2.wStringValue());
Assert.assertEquals("SecondName", as2.wStringValue());
}
use of org.whole.lang.templates.ITemplateManager in project whole by wholeplatform.
the class PathExpressionsQueriesTest method testProduct2.
@Test
public void testProduct2() {
ITemplateManager tm = PathExpressionsQueriesTemplateManager.instance();
Grammar g = new TestXmlGrammar().create();
PathExpression pe1 = (PathExpression) tm.create("testProduct2");
IBindingManager bm = BindingManagerFactory.instance.createArguments();
int count = 0;
for (IEntity tuple : BehaviorUtils.compileAndLazyEvaluate(pe1, g, bm)) {
String prodname = ((Production) bm.wGet("prod")).getName().getValue();
Assert.assertEquals(prodname, tuple.wGet(0).wStringValue());
count++;
}
Assert.assertEquals(g.getPhraseStructure().wSize(), count);
}
use of org.whole.lang.templates.ITemplateManager in project whole by wholeplatform.
the class PathExpressionsQueriesTest method testVariableJoinTest3.
@Test
public void testVariableJoinTest3() {
ITemplateManager tm = PathExpressionsQueriesTemplateManager.instance();
Grammar g = new QueriesGrammar().create();
PathExpression pe1 = (PathExpression) tm.create("recursiveProduction3");
StringBuilder names = new StringBuilder();
for (Production p : BehaviorUtils.<Production>compileAndLazyEvaluate(pe1, g)) names.append(p.getName().getValue());
Assert.assertEquals("ExpressionPathExpressionStepExpressionPredicate", names.toString());
}
use of org.whole.lang.templates.ITemplateManager in project whole by wholeplatform.
the class PathExpressionsQueriesTest method testSingleVariableTestInPathExpPredicate.
@Test
public void testSingleVariableTestInPathExpPredicate() {
ITemplateManager tm = PathExpressionsQueriesTemplateManager.instance();
Grammar g = new TestXmlGrammar().create();
Production p = (Production) g.getPhraseStructure().wGet(1);
PathExpression pe1 = (PathExpression) tm.create("findProduction");
IBindingManager bm = BindingManagerFactory.instance.createArguments();
// FIXME bm.wDefValue("pname", "Element");
bm.wDef("pname", GrammarsEntityFactory.instance.createNonTerminal("Element"));
IEntity p1 = BehaviorUtils.evaluateFirstResult(pe1, g, bm);
Assert.assertSame(p, p1);
bm.wDef("pname", GrammarsEntityFactory.instance.createNonTerminal("invented"));
p1 = BehaviorUtils.evaluateFirstResult(pe1, g, bm);
Assert.assertNull(p1);
}
use of org.whole.lang.templates.ITemplateManager in project whole by wholeplatform.
the class PathExpressionsQueriesTest method testDistinct.
@Test
public void testDistinct() {
ITemplateManager tm = PathExpressionsQueriesTemplateManager.instance();
Grammar g = new TestXmlGrammar().create();
PathExpression pe1 = (PathExpression) tm.create("nonTerminalSet");
Set<String> set = new HashSet<String>();
for (NonTerminal nt : BehaviorUtils.<NonTerminal>compileAndLazyEvaluate(pe1, g)) if (!set.add(nt.getValue()))
Assert.fail();
Assert.assertEquals(22, set.size());
}
Aggregations