use of org.whole.lang.grammars.model.Grammar in project whole by wholeplatform.
the class PathExpressionsQueriesTest method testPathWithFiltersIterator.
@Test
public void testPathWithFiltersIterator() {
ITemplateManager tm = PathExpressionsQueriesTemplateManager.instance();
Grammar g = new TestXmlGrammar().create();
Set<String> l = new HashSet<String>();
for (Production p : BehaviorUtils.<Production>compileAndLazyEvaluate((PathExpression) tm.create("path4"), g)) l.add(p.getName().getValue());
Assert.assertEquals(16, l.size());
}
use of org.whole.lang.grammars.model.Grammar 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.grammars.model.Grammar 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.grammars.model.Grammar 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.grammars.model.Grammar 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