Search in sources :

Example 26 with PathExpression

use of org.whole.lang.queries.model.PathExpression 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());
}
Also used : PathExpression(org.whole.lang.queries.model.PathExpression) TestXmlGrammar(org.whole.lang.grammars.util.TestXmlGrammar) 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) PrettyPrinterOperation.toPrettyPrintString(org.whole.lang.operations.PrettyPrinterOperation.toPrettyPrintString) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 27 with PathExpression

use of org.whole.lang.queries.model.PathExpression 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);
}
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) 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) PrettyPrinterOperation.toPrettyPrintString(org.whole.lang.operations.PrettyPrinterOperation.toPrettyPrintString) Test(org.junit.Test)

Example 28 with PathExpression

use of org.whole.lang.queries.model.PathExpression 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);
}
Also used : Productions(org.whole.lang.grammars.model.Productions) 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) QueriesGrammar(org.whole.lang.grammars.codebase.QueriesGrammar) Test(org.junit.Test)

Example 29 with PathExpression

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

the class PathExpressionsQueriesTest method testVariablesInQuantifiedPredicate.

@Test
public void testVariablesInQuantifiedPredicate() {
    ITemplateManager tm = PathExpressionsQueriesTemplateManager.instance();
    Grammar g = new TestXmlGrammar().create();
    PathExpression pe1 = (PathExpression) tm.create("recursiveProduction6");
    IBindingManager bm = BindingManagerFactory.instance.createArguments();
    IEntityIterator<Production> iterator = BehaviorUtils.<Production>compileAndLazyEvaluate(pe1, g, bm);
    iterator.next();
    Assert.assertTrue(bm.wIsSet("pname"));
    Assert.assertTrue(bm.wIsSet("nt"));
    pe1 = (PathExpression) tm.create("exactlyOneDefUse");
    bm = BindingManagerFactory.instance.createArguments();
    iterator = BehaviorUtils.<Production>compileAndLazyEvaluate(pe1, g, bm);
    iterator.next();
    Assert.assertTrue(bm.wIsSet("pname"));
    Assert.assertTrue(bm.wIsSet("nt"));
    pe1 = (PathExpression) tm.create("unusedProduction");
    bm = BindingManagerFactory.instance.createArguments();
    iterator = BehaviorUtils.<Production>compileAndLazyEvaluate(pe1, g, bm);
    iterator.next();
    Assert.assertTrue(bm.wNames().isEmpty());
}
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 30 with PathExpression

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

the class PathExpressionsQueriesTest method testPrettyPrint.

@Test
public void testPrettyPrint() {
    ITemplateManager tm = PathExpressionsQueriesTemplateManager.instance();
    QueriesEntityFactory ef = QueriesEntityFactory.instance;
    Assert.assertEquals("phraseStructure/child()[0]/rule/child()[0]/name", toPrettyPrintString((PathExpression) tm.create("path1")));
    Assert.assertEquals("phraseStructure/child()[2]", toPrettyPrintString((PathExpression) tm.create("path1a")));
    Assert.assertEquals("phraseStructure/child()[2][type() = Production]", toPrettyPrintString((PathExpression) tm.create("path1b")));
    Assert.assertEquals("phraseStructure/child()[0]/following-sibling()[2]", toPrettyPrintString((PathExpression) tm.create("path1c")));
    Assert.assertEquals("phraseStructure/child()[0]/following-sibling()[2][type() = Production]", toPrettyPrintString((PathExpression) tm.create("path1d")));
    Assert.assertEquals("phraseStructure/child()[0]/rule/descendant()[kind() = SIMPLE]|[kind() = DATA]", toPrettyPrintString((PathExpression) tm.create("path2")));
    Assert.assertEquals("phraseStructure/child()[0]/rule/descendant()![kind() = COMPOSITE]", toPrettyPrintString((PathExpression) tm.create("path3")));
    Assert.assertEquals("phraseStructure/child()[type() <: Production]/rule/descendant()[type() <: Production]", toPrettyPrintString((PathExpression) tm.create("path4")));
    Assert.assertEquals("(phraseStructure, lexicalStructure)/child()[type() <: Production][some rule[type() = Choose] satisfies ]", toPrettyPrintString((PathExpression) tm.create("path5")));
    Assert.assertEquals("phraseStructure/child()[type() = Production][name[visitor: startsWith(\"I\")]]", toPrettyPrintString(buildPath9(ef)));
}
Also used : PathExpression(org.whole.lang.queries.model.PathExpression) QueriesEntityFactory(org.whole.lang.queries.factories.QueriesEntityFactory) ITemplateManager(org.whole.lang.templates.ITemplateManager) 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