use of org.whole.lang.grammars.util.TestXmlGrammar in project whole by wholeplatform.
the class PathExpressionsQueriesTest method testRebindVariable.
@Test
public void testRebindVariable() {
ITemplateManager tm = PathExpressionsQueriesTemplateManager.instance();
Grammar g = new TestXmlGrammar().create();
IBindingManager bm = BindingManagerFactory.instance.createArguments();
bm.wDef("pname", GrammarsEntityFactory.instance.createNonTerminal("Element"));
int count = 0;
for (Production p : BehaviorUtils.<Production>compileAndLazyEvaluate((PathExpression) tm.create("findProduction"), g, bm)) count++;
Assert.assertEquals(1, count);
count = 0;
for (Production p : BehaviorUtils.<Production>compileAndLazyEvaluate((PathExpression) tm.create("findProduction"), g)) count++;
Assert.assertEquals(6, count);
}
use of org.whole.lang.grammars.util.TestXmlGrammar in project whole by wholeplatform.
the class PathExpressionsQueriesTest method testSingleVariableTestInPathLastStep.
@Test
public void testSingleVariableTestInPathLastStep() {
ITemplateManager tm = PathExpressionsQueriesTemplateManager.instance();
Grammar g = new TestXmlGrammar().create();
PathExpression pe1 = (PathExpression) tm.create("findNonTerminalOccurrences");
PathExpression pe2 = (PathExpression) tm.create("bindNonTerminalOccurrences");
IBindingManager bm = BindingManagerFactory.instance.createArguments();
IEntityIterator<NonTerminal> i1 = BehaviorUtils.<NonTerminal>compileAndLazyEvaluate(pe1, g);
for (NonTerminal nt : BehaviorUtils.<NonTerminal>compileAndLazyEvaluate(pe2, g, bm)) {
Assert.assertSame(nt, i1.next());
Assert.assertEquals(nt.getValue(), bm.wStringValue("nt"));
}
Assert.assertFalse(i1.hasNext());
}
use of org.whole.lang.grammars.util.TestXmlGrammar in project whole by wholeplatform.
the class PathExpressionsQueriesTest method testBindingOfSelfIndex.
@Category(KnownFailingTests.class)
@Test
public void testBindingOfSelfIndex() {
ITemplateManager tm = PathExpressionsQueriesTemplateManager.instance();
Grammar g = new TestXmlGrammar().create();
int count = 0;
for (Production p : BehaviorUtils.<Production>compileAndLazyEvaluate((PathExpression) tm.create("path6"), g)) {
Assert.assertTrue(g.getPhraseStructure().wIndexOf(p) >= 2);
count++;
}
Assert.assertEquals(2, count);
}
use of org.whole.lang.grammars.util.TestXmlGrammar in project whole by wholeplatform.
the class RewriteQueriesTest method testDelete2.
@Test
public void testDelete2() {
Grammar model = new TestXmlGrammar().create();
ITemplateManager tm = RewriteQueriesTemplateManager.instance();
PathExpression query = (PathExpression) tm.create("delete2");
for (Name name : BehaviorUtils.<Name>compileAndLazyEvaluate(query, model)) assertTrue(Matcher.match(GrammarsEntityDescriptorEnum.Name, name));
for (IEntity name : BehaviorUtils.compileAndLazyEvaluate(query, model)) assertTrue(EntityUtils.isResolver(name));
}
use of org.whole.lang.grammars.util.TestXmlGrammar 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());
}
Aggregations