Search in sources :

Example 41 with TestXmlGrammar

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

the class IteratorFactoryTest method testTopDownIteratorAdd.

@Test
public void testTopDownIteratorAdd() {
    Grammar g = new TestXmlGrammar().create();
    Production production = (Production) g.getPhraseStructure().wGet(3);
    Choose choose = (Choose) production.getRule();
    int size = choose.wSize();
    int count = 0;
    Rule rAdded1 = null;
    Rule rAdded2 = null;
    IEntityIterator<IEntity> i = IteratorFactory.<IEntity>descendantOrSelfIterator();
    i.reset(production);
    i.next();
    i.next();
    while (i.hasNext()) {
        IEntity r = i.next();
        assertNotSame(rAdded1, r);
        assertNotSame(rAdded2, r);
        if (count == 0)
            assertSame(choose, r);
        else if (count == 1)
            i.add(rAdded1 = GrammarsEntityFactory.instance.createProduction());
        else if (count == 10) {
            i.add(rAdded1 = GrammarsEntityFactory.instance.createProduction());
            i.add(rAdded2 = GrammarsEntityFactory.instance.createProduction());
        }
        count++;
    }
    assertEquals(size + 3, choose.wSize());
}
Also used : Choose(org.whole.lang.grammars.model.Choose) IEntity(org.whole.lang.model.IEntity) TestXmlGrammar(org.whole.lang.grammars.util.TestXmlGrammar) Production(org.whole.lang.grammars.model.Production) 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 42 with TestXmlGrammar

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

the class IteratorFactoryTest method testPrecedingSiblingIterator.

@Test
public void testPrecedingSiblingIterator() {
    Grammar g = new TestXmlGrammar().create();
    Productions productions = g.getPhraseStructure();
    int index = 0;
    IEntityIterator<Production> ci = IteratorFactory.<Production>childIterator();
    ci.reset(productions);
    while (ci.hasNext()) {
        Production p = ci.next();
        IEntityIterator<Production> fi = IteratorFactory.<Production>precedingSiblingIterator();
        fi.reset(p);
        int findex = index++;
        for (Production fp : fi) assertSame(productions.wGet(--findex), fp);
    }
    for (int i = g.wSize() - 1; i >= 0; i--) {
        IEntityIterator<IEntity> fi = IteratorFactory.<IEntity>precedingSiblingIterator();
        fi.reset(g.wGet(i));
        for (int j = i - 1; j >= 0; j--) assertSame(g.wGet(j), fi.next());
    }
    for (int i = productions.wSize() - 1; i >= 0; i--) {
        IEntityIterator<Production> fi = IteratorFactory.<Production>precedingSiblingIterator();
        fi.reset(productions.wGet(i));
        for (int j = i - 1; j >= 0; j--) assertSame(productions.wGet(j), fi.next());
    }
}
Also used : Productions(org.whole.lang.grammars.model.Productions) IEntity(org.whole.lang.model.IEntity) TestXmlGrammar(org.whole.lang.grammars.util.TestXmlGrammar) Production(org.whole.lang.grammars.model.Production) TestXmlGrammar(org.whole.lang.grammars.util.TestXmlGrammar) Grammar(org.whole.lang.grammars.model.Grammar) Test(org.junit.Test)

Example 43 with TestXmlGrammar

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

the class IteratorFactoryTest method testAxesPartitionInvariant.

@Test
public void testAxesPartitionInvariant() {
    Grammar g = new TestXmlGrammar().create();
    IEntityIterator<IEntity> i = IteratorFactory.<IEntity>descendantOrSelfIterator();
    i.reset(g);
    Set<IEntity> s = entities(i);
    IEntityIterator<IEntity> i2 = IteratorFactory.<IEntity>descendantOrSelfIterator();
    i2.reset(g);
    for (IEntity e : i2) {
        IEntityIterator<IEntity> i1 = IteratorFactory.<IEntity>ancestorIterator();
        i1.reset(e);
        Set<IEntity> s1 = entities(i1);
        IEntityIterator<IEntity> i22 = IteratorFactory.selfIterator();
        i22.reset(e);
        Set<IEntity> s2 = entities(i22);
        IEntityIterator<IEntity> i3 = IteratorFactory.<IEntity>descendantIterator();
        i3.reset(e);
        Set<IEntity> s3 = entities(i3);
        IEntityIterator<IEntity> i4 = IteratorFactory.<IEntity>precedingIterator();
        i4.reset(e);
        Set<IEntity> s4 = entities(i4);
        IEntityIterator<IEntity> i5 = IteratorFactory.<IEntity>followingIterator();
        i5.reset(e);
        Set<IEntity> s5 = entities(i5);
        assertFalse(s1.removeAll(s2));
        assertFalse(s1.removeAll(s3));
        assertFalse(s1.removeAll(s4));
        assertFalse(s1.removeAll(s5));
        assertFalse(s2.removeAll(s3));
        assertFalse(s2.removeAll(s4));
        assertFalse(s2.removeAll(s5));
        assertFalse(s3.removeAll(s4));
        assertFalse(s3.removeAll(s5));
        assertFalse(s4.removeAll(s5));
        assertFalse(s.addAll(s1));
        assertFalse(s.addAll(s2));
        assertFalse(s.addAll(s3));
        assertFalse(s.addAll(s4));
        assertFalse(s.addAll(s5));
        assertEquals(s.size(), s1.size() + s2.size() + s3.size() + s4.size() + s5.size());
    }
}
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 44 with TestXmlGrammar

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

the class PathExpressionsQueriesTest method testProduct1.

@Test
public void testProduct1() {
    ITemplateManager tm = PathExpressionsQueriesTemplateManager.instance();
    Grammar g = new TestXmlGrammar().create();
    PathExpression pe1 = (PathExpression) tm.create("testProduct1");
    IBindingManager bm = BindingManagerFactory.instance.createArguments();
    int count = 0;
    for (IEntity tuple : BehaviorUtils.compileAndLazyEvaluate(pe1, g, bm)) {
        String vname = ((Production) bm.wGet("pp")).getName().getValue() + "x" + ((Production) bm.wGet("lp")).getName().getValue();
        String tname = ((Production) tuple.wGet(0)).getName().getValue() + "x" + ((Production) tuple.wGet(1)).getName().getValue();
        Assert.assertEquals(vname, tname);
        count++;
    }
    Assert.assertEquals(g.getPhraseStructure().wSize() * g.getLexicalStructure().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) 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 45 with TestXmlGrammar

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

the class PathExpressionsQueriesTest method testPathWithKindAndLogicFiltersIterator.

@Test
public void testPathWithKindAndLogicFiltersIterator() {
    ITemplateManager tm = PathExpressionsQueriesTemplateManager.instance();
    QueriesEntityFactory ef = QueriesEntityFactory.instance;
    for (IEntity p : BehaviorUtils.compileAndLazyEvaluate((PathExpression) tm.create("path2"), new TestXmlGrammar().create())) Assert.assertTrue(p.wGetEntityKind().equals(EntityKinds.SIMPLE) || p.wGetEntityKind().equals(EntityKinds.DATA));
    for (IEntity p : BehaviorUtils.compileAndLazyEvaluate((PathExpression) tm.create("path3"), new TestXmlGrammar().create())) Assert.assertFalse(p.wGetEntityKind().equals(EntityKinds.COMPOSITE));
}
Also used : IEntity(org.whole.lang.model.IEntity) QueriesEntityFactory(org.whole.lang.queries.factories.QueriesEntityFactory) TestXmlGrammar(org.whole.lang.grammars.util.TestXmlGrammar) ITemplateManager(org.whole.lang.templates.ITemplateManager) 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