Search in sources :

Example 21 with TestXmlGrammar

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

the class SelectQueriesTest method testSelectPathExpression1.

@Test
public void testSelectPathExpression1() {
    ITemplateManager tm = SelectQueriesTemplateManager.instance();
    Grammar g = new TestXmlGrammar().create();
    PathExpression pe1 = (PathExpression) tm.create("selectPath1");
    StringBuilder names = new StringBuilder();
    for (NonTerminal nt : BehaviorUtils.<NonTerminal>compileAndLazyEvaluate(pe1, g)) names.append(nt.getValue());
    assertEquals("DocumentElementINameIContent", names.toString());
}
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) Test(org.junit.Test)

Example 22 with TestXmlGrammar

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

the class SelectQueriesTest method testSelectTemplate1.

@Test
public void testSelectTemplate1() {
    ITemplateManager tm = SelectQueriesTemplateManager.instance();
    Grammar model = new TestXmlGrammar().create();
    IBindingManager bm = BindingManagerFactory.instance.createArguments();
    PathExpression query = (PathExpression) tm.create("selectTemplate1");
    for (IEntity tuple : BehaviorUtils.compileAndLazyEvaluate(query, model, bm)) {
        Feature f = (Feature) tuple.wGet(0);
        As e = (As) tuple.wGet(1);
        assertEquals(e.getName().getValue(), f.getName().wStringValue());
        assertEquals(e.getRule().wStringValue(), f.getType().wStringValue());
    }
}
Also used : As(org.whole.lang.grammars.model.As) 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) Feature(org.whole.lang.models.model.Feature) Test(org.junit.Test)

Example 23 with TestXmlGrammar

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

the class SelectQueriesTest method testSelectTuple1.

@Test
public void testSelectTuple1() {
    ITemplateManager tm = SelectQueriesTemplateManager.instance();
    Grammar g = new TestXmlGrammar().create();
    PathExpression pe1 = (PathExpression) tm.create("selectTuple1");
    int count = 0;
    for (IEntity t : BehaviorUtils.compileAndLazyEvaluate(pe1, g)) {
        NonTerminal name = (NonTerminal) t.wGet(0);
        Rule rule = (Rule) t.wGet(1);
        Production prod = (Production) t.wGet(2);
        assertEquals(name, prod.getName());
        assertSame(rule, prod.getRule());
        assertEquals(g.getName(), t.wGet(3));
        count++;
    }
    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) 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) Rule(org.whole.lang.grammars.model.Rule) Test(org.junit.Test)

Example 24 with TestXmlGrammar

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

the class IteratorFactoryTest method testPrune.

@Test
public void testPrune() {
    Grammar g = new TestXmlGrammar().create();
    IEntityIterator<IEntity> i1 = IteratorFactory.<IEntity>descendantOrSelfIterator();
    i1.reset(g);
    IEntityIterator<IEntity> i2 = IteratorFactory.<IEntity>descendantOrSelfIterator();
    i2.reset(g);
    for (IEntity e : i1) {
        assertSame(e, i2.next());
        IEntityIterator<IEntity> i12 = i1.clone();
        i12.prune();
    }
    assertSame(i1.hasNext(), i2.hasNext());
    i1 = IteratorFactory.<IEntity>descendantOrSelfIterator();
    i1.reset(g);
    for (IEntity e : i1) {
        IEntityIterator<IEntity> i3 = IteratorFactory.<IEntity>followingSiblingIterator();
        i3.reset(e);
        if (i3.hasNext()) {
            IEntityIterator<IEntity> i12 = i1.clone();
            i12.prune();
            IEntity e1 = i12.next();
            IEntity e2 = i3.next();
            assertSame(e1, e2);
        }
    }
}
Also used : IEntity(org.whole.lang.model.IEntity) TestXmlGrammar(org.whole.lang.grammars.util.TestXmlGrammar) TestXmlGrammar(org.whole.lang.grammars.util.TestXmlGrammar) Grammar(org.whole.lang.grammars.model.Grammar) Test(org.junit.Test)

Example 25 with TestXmlGrammar

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

the class IteratorFactoryTest method testTopDownIterator.

@Test
public void testTopDownIterator() throws Exception {
    Grammar g = new TestXmlGrammar().create();
    final Productions productions = g.getPhraseStructure();
    final IEntityIterator<IEntity> ci = IteratorFactory.<IEntity>descendantOrSelfIterator();
    ci.reset(productions);
    IVisitor v = GenericTraversalFactory.instance.topDown(new GenericIdentityVisitor() {

        public void visit(IEntity entity) {
            if (ci.hasNext())
                assertSame(entity, ci.next());
            else
                fail();
        }
    }, false);
    v.visit(productions);
    final IEntityIterator<IEntity> ci2 = IteratorFactory.<IEntity>descendantOrSelfScannerIterator();
    ci2.reset(productions);
    v = GenericTraversalFactory.instance.topDown(new GenericIdentityVisitor() {

        public void visit(IEntity entity) {
            if (EntityUtils.isResolver(entity))
                return;
            if (ci2.hasNext())
                assertSame(entity, ci2.next());
            else
                fail();
        }
    }, false);
    v.visit(productions);
    final IEntityIterator<IEntity> ci3 = IteratorFactory.<IEntity>descendantOrSelfMatcherIterator().withPattern(GrammarsEntityDescriptorEnum.Production);
    ci3.reset(productions);
    v = GenericTraversalFactory.instance.topDown(new GenericIdentityVisitor() {

        public void visit(IEntity entity) {
            if (!Matcher.match(GrammarsEntityDescriptorEnum.Production, entity))
                return;
            if (ci3.hasNext())
                assertSame(entity, ci3.next());
            else
                fail();
        }
    }, false);
    v.visit(productions);
    IEntity artifactsModel = XmlBuilderPersistenceKit.instance().readModel(new ClasspathPersistenceProvider("org/whole/lang/artifacts/ArtifactsModel.xwl"));
    Set<Type> typeSet = new HashSet<Type>();
    IEntityIterator<Type> ci4 = IteratorFactory.<Type>descendantOrSelfMatcherIterator().withPattern(ModelsEntityFactory.instance.createSimpleName("Atifacts"));
    ci4.reset(artifactsModel);
    while (ci4.hasNext()) assertTrue(typeSet.add(ci4.next()));
}
Also used : Productions(org.whole.lang.grammars.model.Productions) Type(org.whole.lang.models.model.Type) IEntity(org.whole.lang.model.IEntity) IVisitor(org.whole.lang.visitors.IVisitor) TestXmlGrammar(org.whole.lang.grammars.util.TestXmlGrammar) ClasspathPersistenceProvider(org.whole.lang.codebase.ClasspathPersistenceProvider) TestXmlGrammar(org.whole.lang.grammars.util.TestXmlGrammar) Grammar(org.whole.lang.grammars.model.Grammar) GenericIdentityVisitor(org.whole.lang.visitors.GenericIdentityVisitor) HashSet(java.util.HashSet) 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