Search in sources :

Example 6 with TestXmlGrammar

use of org.whole.lang.grammars.util.TestXmlGrammar 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)

Example 7 with TestXmlGrammar

use of org.whole.lang.grammars.util.TestXmlGrammar in project whole by wholeplatform.

the class PathExpressionsQueriesTest method testPatternWithVariablePredicate.

@Test
public void testPatternWithVariablePredicate() {
    ITemplateManager tm = PathExpressionsQueriesTemplateManager.instance();
    Grammar g = new TestXmlGrammar().create();
    StringBuilder names = new StringBuilder();
    IBindingManager bm = BindingManagerFactory.instance.createArguments();
    IEntityIterator<Production> iterator = BehaviorUtils.<Production>compileAndLazyEvaluate((PathExpression) tm.create("path8"), g, bm);
    for (Production p : iterator) {
        Assert.assertEquals(bm.wStringValue("name"), p.getName().getValue());
        names.append(p.getName().getValue());
    }
    Assert.assertEquals("VersionEncodingValueNameNameSpaceCharDataCDataSectDataCommentText", names.toString());
}
Also used : 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 8 with TestXmlGrammar

use of org.whole.lang.grammars.util.TestXmlGrammar in project whole by wholeplatform.

the class PathExpressionsQueriesTest method testPatternPredicate.

@Test
public void testPatternPredicate() {
    ITemplateManager tm = PathExpressionsQueriesTemplateManager.instance();
    Grammar g = new TestXmlGrammar().create();
    int count = 0;
    for (As as : BehaviorUtils.<As>compileAndLazyEvaluate((PathExpression) tm.create("path7"), g)) {
        Assert.assertEquals("tag", as.getName().wStringValue());
        count++;
    }
    Assert.assertEquals(2, count);
}
Also used : As(org.whole.lang.grammars.model.As) TestXmlGrammar(org.whole.lang.grammars.util.TestXmlGrammar) 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 9 with TestXmlGrammar

use of org.whole.lang.grammars.util.TestXmlGrammar in project whole by wholeplatform.

the class PathExpressionsQueriesTest method testPathWithFiltersIterator.

@Test
public void testPathWithFiltersIterator() {
    ITemplateManager tm = PathExpressionsQueriesTemplateManager.instance();
    Grammar g = new TestXmlGrammar().create();
    Set<String> l = new HashSet<String>();
    for (Production p : BehaviorUtils.<Production>compileAndLazyEvaluate((PathExpression) tm.create("path4"), g)) l.add(p.getName().getValue());
    Assert.assertEquals(16, l.size());
}
Also used : 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) PrettyPrinterOperation.toPrettyPrintString(org.whole.lang.operations.PrettyPrinterOperation.toPrettyPrintString) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 10 with TestXmlGrammar

use of org.whole.lang.grammars.util.TestXmlGrammar in project whole by wholeplatform.

the class PathExpressionsQueriesTest method testProduct2.

@Test
public void testProduct2() {
    ITemplateManager tm = PathExpressionsQueriesTemplateManager.instance();
    Grammar g = new TestXmlGrammar().create();
    PathExpression pe1 = (PathExpression) tm.create("testProduct2");
    IBindingManager bm = BindingManagerFactory.instance.createArguments();
    int count = 0;
    for (IEntity tuple : BehaviorUtils.compileAndLazyEvaluate(pe1, g, bm)) {
        String prodname = ((Production) bm.wGet("prod")).getName().getValue();
        Assert.assertEquals(prodname, tuple.wGet(0).wStringValue());
        count++;
    }
    Assert.assertEquals(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) 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)

Aggregations

Test (org.junit.Test)75 TestXmlGrammar (org.whole.lang.grammars.util.TestXmlGrammar)75 Grammar (org.whole.lang.grammars.model.Grammar)74 IEntity (org.whole.lang.model.IEntity)46 ITemplateManager (org.whole.lang.templates.ITemplateManager)41 Production (org.whole.lang.grammars.model.Production)35 PathExpression (org.whole.lang.queries.model.PathExpression)33 IBindingManager (org.whole.lang.bindings.IBindingManager)27 QueriesGrammar (org.whole.lang.grammars.codebase.QueriesGrammar)19 Productions (org.whole.lang.grammars.model.Productions)14 NonTerminal (org.whole.lang.grammars.model.NonTerminal)13 PrettyPrinterOperation.toPrettyPrintString (org.whole.lang.operations.PrettyPrinterOperation.toPrettyPrintString)7 HashSet (java.util.HashSet)6 Rule (org.whole.lang.grammars.model.Rule)6 As (org.whole.lang.grammars.model.As)3 Feature (org.whole.lang.models.model.Feature)3 ArrayList (java.util.ArrayList)1 Category (org.junit.experimental.categories.Category)1 ClasspathPersistenceProvider (org.whole.lang.codebase.ClasspathPersistenceProvider)1 Choose (org.whole.lang.grammars.model.Choose)1