Search in sources :

Example 91 with PathExpression

use of org.whole.lang.queries.model.PathExpression 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 PathExpression

use of org.whole.lang.queries.model.PathExpression 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 PathExpression

use of org.whole.lang.queries.model.PathExpression 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 PathExpression

use of org.whole.lang.queries.model.PathExpression in project whole by wholeplatform.

the class PathExpressionsQueriesTest method testLookaheadScope.

@Test
public void testLookaheadScope() {
    ITemplateManager tm = PathExpressionsQueriesTemplateManager.instance();
    Grammar g = new TestXmlGrammar().create();
    String[] templates = { "findNonTerminalOccurrences", "findProduction", "bindNonTerminalOccurrences", "recursiveProduction2", "testProduct1", "testProduct2", "testProduct3" };
    for (String template : templates) {
        PathExpression pe1 = (PathExpression) tm.create(template);
        IBindingManager bm = BindingManagerFactory.instance.createArguments();
        IEntityIterator<IEntity> i1 = BehaviorUtils.<IEntity>compileAndLazyEvaluate(pe1, g, bm);
        IEntity p1 = null;
        while ((p1 = i1.lookahead()) != null) {
            Set<String> s1 = i1.lookaheadScope().wNames();
            IEntity p2 = i1.next();
            // false for tuples        		Assert.assertSame(p1,p2);
            Assert.assertEquals(bm.wNames().size(), s1.size());
            for (String name : s1) Assert.assertTrue(bm.wIsSet(name));
        }
    }
}
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) QueriesGrammar(org.whole.lang.grammars.codebase.QueriesGrammar) PrettyPrinterOperation.toPrettyPrintString(org.whole.lang.operations.PrettyPrinterOperation.toPrettyPrintString) Test(org.junit.Test)

Example 95 with PathExpression

use of org.whole.lang.queries.model.PathExpression in project whole by wholeplatform.

the class XsdLanguageTest method testArtifactsMappedModel.

@Category(KnownFailingTests.class)
@Test
public void testArtifactsMappedModel() {
    try {
        IBindingManager bm = BindingManagerFactory.instance.createBindingManager();
        PathExpression path = new ModelToXmlSchemaQuery().create();
        IEntity model = XmlBuilderPersistenceKit.instance().readModel(new ClasspathPersistenceProvider("org/whole/lang/artifacts/ArtifactsModel.xwl"));
        Assert.assertNotNull(BehaviorUtils.evaluateFirstResult(path, model, bm));
        InterpreterOperation.interpret(bm.wGet("mapping"));
        bm.wDefValue("folderLocation", new File("test/org/whole/lang/xsd/util").getAbsolutePath());
        bm.wDefValue("packageName", "");
        IEntity artifacts = XsiPersistenceKit.instance().readModel(new StreamPersistenceProvider(getInputStream("Artifacts.xml"), null, bm));
        Assert.assertTrue(Matcher.match(new Artifacts().create(), artifacts));
    } catch (Exception e) {
        Assert.fail(e.getMessage());
    }
}
Also used : ModelToXmlSchemaQuery(org.whole.lang.xsd.codebase.ModelToXmlSchemaQuery) PathExpression(org.whole.lang.queries.model.PathExpression) IEntity(org.whole.lang.model.IEntity) IBindingManager(org.whole.lang.bindings.IBindingManager) ClasspathPersistenceProvider(org.whole.lang.codebase.ClasspathPersistenceProvider) StreamPersistenceProvider(org.whole.lang.codebase.StreamPersistenceProvider) File(java.io.File) Category(org.junit.experimental.categories.Category) Test(org.junit.Test)

Aggregations

PathExpression (org.whole.lang.queries.model.PathExpression)97 Test (org.junit.Test)94 ITemplateManager (org.whole.lang.templates.ITemplateManager)87 IEntity (org.whole.lang.model.IEntity)67 IBindingManager (org.whole.lang.bindings.IBindingManager)45 Model (org.whole.lang.models.model.Model)43 Grammar (org.whole.lang.grammars.model.Grammar)40 TestXmlGrammar (org.whole.lang.grammars.util.TestXmlGrammar)39 XmlModel (org.whole.lang.models.codebase.XmlModel)28 ModelsModel (org.whole.lang.models.codebase.ModelsModel)23 Production (org.whole.lang.grammars.model.Production)20 QueriesGrammar (org.whole.lang.grammars.codebase.QueriesGrammar)18 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 Feature (org.whole.lang.models.model.Feature)9 NonTerminal (org.whole.lang.grammars.model.NonTerminal)8 FieldDeclaration (org.whole.lang.java.model.FieldDeclaration)7 QueriesEntityFactory (org.whole.lang.queries.factories.QueriesEntityFactory)6