use of org.whole.lang.grammars.util.TestXmlGrammar 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.util.TestXmlGrammar 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());
}
use of org.whole.lang.grammars.util.TestXmlGrammar in project whole by wholeplatform.
the class PathExpressionsQueriesTest method testProduct3.
@Test
public void testProduct3() {
ITemplateManager tm = PathExpressionsQueriesTemplateManager.instance();
Grammar g = new TestXmlGrammar().create();
PathExpression pe1 = (PathExpression) tm.create("testProduct3");
IBindingManager bm = BindingManagerFactory.instance.createArguments();
int count = 0;
for (IEntity tuple : BehaviorUtils.compileAndLazyEvaluate(pe1, g, bm)) {
String vname = ((NonTerminal) bm.wGet("name1")).getValue() + "x" + ((NonTerminal) bm.wGet("name2")).getValue();
String tname = tuple.wGet(0).wStringValue() + "x" + tuple.wGet(1).wStringValue();
Assert.assertEquals(vname, tname);
count++;
}
Assert.assertEquals(g.getPhraseStructure().wSize() * g.getPhraseStructure().wSize(), count);
}
use of org.whole.lang.grammars.util.TestXmlGrammar in project whole by wholeplatform.
the class PathExpressionsQueriesTest method testProduct4.
@Test
public void testProduct4() {
ITemplateManager tm = PathExpressionsQueriesTemplateManager.instance();
Grammar g = new TestXmlGrammar().create();
Productions productions = g.getPhraseStructure();
PathExpression pe1 = (PathExpression) tm.create("testProduct4");
IBindingManager bm = BindingManagerFactory.instance.createArguments();
int count = 0;
for (IEntity tuple : BehaviorUtils.compileAndLazyEvaluate(pe1, g, bm)) {
Production p = (Production) productions.wGet(count++);
Assert.assertSame(p.getName(), bm.wGet("name"));
Assert.assertSame(p.getRule(), bm.wGet("rule"));
Assert.assertSame(p.getName(), tuple.wGet(0));
Assert.assertSame(p.getRule(), tuple.wGet(1));
}
Assert.assertEquals(g.getPhraseStructure().wSize(), count);
}
use of org.whole.lang.grammars.util.TestXmlGrammar in project whole by wholeplatform.
the class PathExpressionsQueriesTest method testPathWithPatternFiltersIterator.
@Test
public void testPathWithPatternFiltersIterator() {
ITemplateManager tm = PathExpressionsQueriesTemplateManager.instance();
Grammar g = new TestXmlGrammar().create();
Set<String> l = new HashSet<String>();
for (Production p : BehaviorUtils.<Production>compileAndLazyEvaluate((PathExpression) tm.create("path5"), g)) l.add(p.getName().getValue());
Assert.assertEquals(2, l.size());
}
Aggregations