Search in sources :

Example 91 with ITemplateManager

use of org.whole.lang.templates.ITemplateManager in project whole by wholeplatform.

the class PathExpressionsQueriesTest method testOnePredicate.

@Test
public void testOnePredicate() {
    ITemplateManager tm = PathExpressionsQueriesTemplateManager.instance();
    Grammar g = new TestXmlGrammar().create();
    PathExpression pe1 = (PathExpression) tm.create("exactlyOneDefUse");
    IBindingManager bm = BindingManagerFactory.instance.createArguments();
    IEntityIterator<Production> iterator = BehaviorUtils.<Production>compileAndLazyEvaluate(pe1, g, bm);
    Assert.assertTrue(iterator.hasNext());
    Production p = iterator.next();
    Assert.assertEquals("IName", p.getName().getValue());
    Assert.assertFalse(iterator.hasNext());
}
Also used : PathExpression(org.whole.lang.queries.model.PathExpression) TestXmlGrammar(org.whole.lang.grammars.util.TestXmlGrammar) Production(org.whole.lang.grammars.model.Production) IBindingManager(org.whole.lang.bindings.IBindingManager) ITemplateManager(org.whole.lang.templates.ITemplateManager) TestXmlGrammar(org.whole.lang.grammars.util.TestXmlGrammar) Grammar(org.whole.lang.grammars.model.Grammar) QueriesGrammar(org.whole.lang.grammars.codebase.QueriesGrammar) Test(org.junit.Test)

Example 92 with ITemplateManager

use of org.whole.lang.templates.ITemplateManager in project whole by wholeplatform.

the class PathExpressionsQueriesTest method testVariableJoinTest2.

@Test
public void testVariableJoinTest2() {
    ITemplateManager tm = PathExpressionsQueriesTemplateManager.instance();
    Grammar g = new QueriesGrammar().create();
    PathExpression pe1 = (PathExpression) tm.create("recursiveProduction2");
    StringBuilder names = new StringBuilder();
    for (Production p : BehaviorUtils.<Production>compileAndLazyEvaluate(pe1, g)) names.append(p.getName().getValue());
    Assert.assertEquals("ExpressionPathExpressionStepExpressionPredicate", names.toString());
}
Also used : PathExpression(org.whole.lang.queries.model.PathExpression) Production(org.whole.lang.grammars.model.Production) ITemplateManager(org.whole.lang.templates.ITemplateManager) TestXmlGrammar(org.whole.lang.grammars.util.TestXmlGrammar) Grammar(org.whole.lang.grammars.model.Grammar) QueriesGrammar(org.whole.lang.grammars.codebase.QueriesGrammar) QueriesGrammar(org.whole.lang.grammars.codebase.QueriesGrammar) Test(org.junit.Test)

Example 93 with ITemplateManager

use of org.whole.lang.templates.ITemplateManager in project whole by wholeplatform.

the class PathExpressionsQueriesTest method testIndexTest.

@Test
public void testIndexTest() {
    ITemplateManager tm = PathExpressionsQueriesTemplateManager.instance();
    Grammar g = new TestXmlGrammar().create();
    IEntityIterator<Production> pi = BehaviorUtils.compileAndLazyEvaluate((PathExpression) tm.create("path1a"), g);
    Assert.assertTrue(pi.hasNext());
    Assert.assertSame(g.getPhraseStructure().wGet(2), pi.next());
    Assert.assertFalse(pi.hasNext());
    pi = BehaviorUtils.compileAndLazyEvaluate((PathExpression) tm.create("path1b"), g);
    Assert.assertTrue(pi.hasNext());
    Assert.assertSame(g.getPhraseStructure().wGet(2), pi.next());
    Assert.assertFalse(pi.hasNext());
    pi = BehaviorUtils.compileAndLazyEvaluate((PathExpression) tm.create("path1c"), g);
    Assert.assertTrue(pi.hasNext());
    Assert.assertSame(g.getPhraseStructure().wGet(3), pi.next());
    Assert.assertFalse(pi.hasNext());
    pi = BehaviorUtils.compileAndLazyEvaluate((PathExpression) tm.create("path1d"), g);
    Assert.assertTrue(pi.hasNext());
    Assert.assertSame(g.getPhraseStructure().wGet(3), pi.next());
    Assert.assertFalse(pi.hasNext());
}
Also used : PathExpression(org.whole.lang.queries.model.PathExpression) TestXmlGrammar(org.whole.lang.grammars.util.TestXmlGrammar) Production(org.whole.lang.grammars.model.Production) ITemplateManager(org.whole.lang.templates.ITemplateManager) TestXmlGrammar(org.whole.lang.grammars.util.TestXmlGrammar) Grammar(org.whole.lang.grammars.model.Grammar) QueriesGrammar(org.whole.lang.grammars.codebase.QueriesGrammar) Test(org.junit.Test)

Example 94 with ITemplateManager

use of org.whole.lang.templates.ITemplateManager in project whole by wholeplatform.

the class PathExpressionsQueriesTest method testPathWithTuple.

@Category(KnownFailingTests.class)
@Test
public void testPathWithTuple() {
    ITemplateManager tm = PathExpressionsQueriesTemplateManager.instance();
    IEntityIterator<IEntity> i = DynamicCompilerOperation.compile(tm.create("pathWithTuple"), BindingManagerFactory.instance.createArguments()).getResultIterator();
    Assert.assertTrue(i.hasNext());
    IEntity e0 = i.next();
    Assert.assertFalse(i.hasNext());
}
Also used : IEntity(org.whole.lang.model.IEntity) ITemplateManager(org.whole.lang.templates.ITemplateManager) Category(org.junit.experimental.categories.Category) Test(org.junit.Test)

Example 95 with ITemplateManager

use of org.whole.lang.templates.ITemplateManager in project whole by wholeplatform.

the class PathExpressionsQueriesTest method testPathByNameAndByIndexSteps.

@Test
public void testPathByNameAndByIndexSteps() {
    ITemplateManager tm = PathExpressionsQueriesTemplateManager.instance();
    Grammar g = new TestXmlGrammar().create();
    NonTerminal prologNt = ((Production) ((Production) g.getPhraseStructure().wGet(0)).getRule().wGet(0)).getName();
    IEntityIterator<NonTerminal> nti = BehaviorUtils.compileAndLazyEvaluate((PathExpression) tm.create("path1"), g);
    Assert.assertTrue(nti.hasNext());
    Assert.assertSame(prologNt, nti.next());
    nti.reset(g.getPhraseStructure());
    Assert.assertFalse(nti.hasNext());
    nti.reset(g);
    Assert.assertTrue(nti.hasNext());
    Assert.assertSame(prologNt, nti.next());
}
Also used : TestXmlGrammar(org.whole.lang.grammars.util.TestXmlGrammar) Production(org.whole.lang.grammars.model.Production) ITemplateManager(org.whole.lang.templates.ITemplateManager) NonTerminal(org.whole.lang.grammars.model.NonTerminal) TestXmlGrammar(org.whole.lang.grammars.util.TestXmlGrammar) Grammar(org.whole.lang.grammars.model.Grammar) QueriesGrammar(org.whole.lang.grammars.codebase.QueriesGrammar) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)96 ITemplateManager (org.whole.lang.templates.ITemplateManager)96 PathExpression (org.whole.lang.queries.model.PathExpression)87 IEntity (org.whole.lang.model.IEntity)61 TestXmlGrammar (org.whole.lang.grammars.util.TestXmlGrammar)47 Grammar (org.whole.lang.grammars.model.Grammar)46 Model (org.whole.lang.models.model.Model)41 IBindingManager (org.whole.lang.bindings.IBindingManager)40 XmlModel (org.whole.lang.models.codebase.XmlModel)27 Production (org.whole.lang.grammars.model.Production)26 QueriesGrammar (org.whole.lang.grammars.codebase.QueriesGrammar)25 ModelsModel (org.whole.lang.models.codebase.ModelsModel)23 ModelDeclarations (org.whole.lang.models.model.ModelDeclarations)18 SimpleEntity (org.whole.lang.models.model.SimpleEntity)13 ClassDeclaration (org.whole.lang.java.model.ClassDeclaration)11 DataEntity (org.whole.lang.models.model.DataEntity)10 NonTerminal (org.whole.lang.grammars.model.NonTerminal)9 Feature (org.whole.lang.models.model.Feature)9 FieldDeclaration (org.whole.lang.java.model.FieldDeclaration)7 PrettyPrinterOperation.toPrettyPrintString (org.whole.lang.operations.PrettyPrinterOperation.toPrettyPrintString)7