Search in sources :

Example 11 with ITemplateManager

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

the class ControlQueriesTest method testChoose2.

@Test
public void testChoose2() {
    Model model = new ModelsModel().create();
    ModelDeclarations decls = model.getDeclarations();
    ITemplateManager tm = ControlQueriesTemplateManager.instance();
    PathExpression query = (PathExpression) tm.create("choose2");
    int i = 0;
    IEntityIterator<IEntity> iterator = BehaviorUtils.compileAndLazyEvaluate(query, model);
    while (iterator.hasNext()) {
        IEntity result;
        IEntity decl = decls.wGet(i++);
        switch(decl.wGetEntityOrd()) {
            case ModelsEntityDescriptorEnum.SimpleEntity_ord:
                IEntity features = ((SimpleEntity) decl).getFeatures();
                for (int j = 0; j < features.wSize(); j++) {
                    result = iterator.next();
                    assertEquals(((Feature) features.wGet(j)).getName().wStringValue(), result.wStringValue());
                }
                break;
            case ModelsEntityDescriptorEnum.CompositeEntity_ord:
                result = iterator.next();
                CompositeEntity compositeEntity = (CompositeEntity) decl;
                assertEquals(compositeEntity.getComponentType().wStringValue(), result.wStringValue());
                break;
            case ModelsEntityDescriptorEnum.DataEntity_ord:
                result = iterator.next();
                DataEntity dataEntity = (DataEntity) decl;
                assertEquals(dataEntity.getDataType().wStringValue(), result.wStringValue());
                break;
            case ModelsEntityDescriptorEnum.EnumEntity_ord:
                EnumValues enumValues = ((EnumEntity) decl).getValues();
                if (enumValues.wIsEmpty())
                    iterator.next();
                else
                    for (int j = 0; j < enumValues.wSize(); j++) {
                        result = iterator.next();
                        assertEquals(enumValues.wGet(j).wStringValue(), result.wStringValue());
                    }
                break;
        }
    }
}
Also used : EnumEntity(org.whole.lang.models.model.EnumEntity) IEntity(org.whole.lang.model.IEntity) SimpleEntity(org.whole.lang.models.model.SimpleEntity) ITemplateManager(org.whole.lang.templates.ITemplateManager) Feature(org.whole.lang.models.model.Feature) EnumValues(org.whole.lang.models.model.EnumValues) ModelDeclarations(org.whole.lang.models.model.ModelDeclarations) PathExpression(org.whole.lang.queries.model.PathExpression) XmlModel(org.whole.lang.models.codebase.XmlModel) ModelsModel(org.whole.lang.models.codebase.ModelsModel) Model(org.whole.lang.models.model.Model) CompositeEntity(org.whole.lang.models.model.CompositeEntity) DataEntity(org.whole.lang.models.model.DataEntity) ModelsModel(org.whole.lang.models.codebase.ModelsModel) Test(org.junit.Test)

Example 12 with ITemplateManager

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

the class ControlQueriesTest method testCall3.

@Test
public void testCall3() {
    Grammar grammar = new TestXmlGrammar().create();
    IBindingManager bm = BindingManagerFactory.instance.createArguments();
    ITemplateManager tm = ControlQueriesTemplateManager.instance();
    PathExpression query = (PathExpression) tm.create("call3");
    int count = 0;
    for (IEntity p : BehaviorUtils.compileAndLazyEvaluate(query, grammar, bm)) {
        assertTrue(Matcher.match(GrammarsEntityDescriptorEnum.Production, p));
        assertEquals("IContent", ((Production) p).getName().getValue());
        count++;
    }
    assertEquals(1, count);
}
Also used : PathExpression(org.whole.lang.queries.model.PathExpression) IEntity(org.whole.lang.model.IEntity) 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) Test(org.junit.Test)

Example 13 with ITemplateManager

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

the class ControlQueriesTest method testQueryDecl2.

@Test
public void testQueryDecl2() {
    Grammar grammar = new TestXmlGrammar().create();
    IBindingManager bm = BindingManagerFactory.instance.createArguments();
    ITemplateManager tm = ControlQueriesTemplateManager.instance();
    PathExpression query = (PathExpression) tm.create("queryDecl2");
    int count = 0;
    for (IEntity p : BehaviorUtils.compileAndLazyEvaluate(query, grammar, bm)) {
        assertTrue(Matcher.match(GrammarsEntityDescriptorEnum.Production, p));
        assertEquals("IContent", ((Production) p).getName().getValue());
        count++;
    }
    assertEquals(1, count);
}
Also used : PathExpression(org.whole.lang.queries.model.PathExpression) IEntity(org.whole.lang.model.IEntity) 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) Test(org.junit.Test)

Example 14 with ITemplateManager

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

the class ControlQueriesTest method testQueryDecl6.

@Test
public void testQueryDecl6() {
    // not used
    Grammar grammar = new TestXmlGrammar().create();
    IBindingManager bm = BindingManagerFactory.instance.createArguments();
    ITemplateManager tm = ControlQueriesTemplateManager.instance();
    PathExpression query = (PathExpression) tm.create("queryDecl6");
    int count = 0;
    for (IEntity p : BehaviorUtils.compileAndLazyEvaluate(query, grammar, bm)) {
        if (++count == 1)
            assertEquals(5, p.wIntValue());
        else if (count == 2)
            assertEquals(10, p.wIntValue());
        else if (count == 3)
            assertEquals(8, p.wIntValue());
    }
    assertEquals(3, count);
}
Also used : PathExpression(org.whole.lang.queries.model.PathExpression) IEntity(org.whole.lang.model.IEntity) TestXmlGrammar(org.whole.lang.grammars.util.TestXmlGrammar) 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) Test(org.junit.Test)

Example 15 with ITemplateManager

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

the class ControlQueriesTest method testQueryDecl1.

@Test
public void testQueryDecl1() {
    Grammar grammar = new TestXmlGrammar().create();
    IBindingManager bm = BindingManagerFactory.instance.createArguments();
    ITemplateManager tm = ControlQueriesTemplateManager.instance();
    PathExpression query = (PathExpression) tm.create("queryDecl1");
    int count = 0;
    for (IEntity p : BehaviorUtils.compileAndLazyEvaluate(query, grammar, bm)) {
        assertTrue(Matcher.match(GrammarsEntityDescriptorEnum.Production, p));
        assertEquals("IContent", ((Production) p).getName().getValue());
        count++;
    }
    assertEquals(1, count);
}
Also used : PathExpression(org.whole.lang.queries.model.PathExpression) IEntity(org.whole.lang.model.IEntity) 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) 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