Ejemplo n.º 1
0
  @Test
  public void testMore() throws InterruptedException {
    final Element e1 = TestUtils.getElement("test1", Regexp.<AbstractStructuralNode>getMutable());
    final Element e2 = TestUtils.getElement("test2", Regexp.<AbstractStructuralNode>getMutable());
    final Element e3 = TestUtils.getElement("test3", Regexp.<AbstractStructuralNode>getMutable());
    final Element e4 = TestUtils.getElement("test4", Regexp.<AbstractStructuralNode>getMutable());

    e1.getSubnodes().setType(RegexpType.CONCATENATION);
    e1.getSubnodes().setInterval(RegexpInterval.getOnce());
    e2.getSubnodes().setType(RegexpType.CONCATENATION);
    e2.getSubnodes().setInterval(RegexpInterval.getOnce());
    e3.getSubnodes().setType(RegexpType.CONCATENATION);
    e3.getSubnodes().setInterval(RegexpInterval.getOnce());
    e4.getSubnodes().setType(RegexpType.CONCATENATION);
    e4.getSubnodes().setInterval(RegexpInterval.getOnce());

    e1.getSubnodes().addChild(Regexp.<AbstractStructuralNode>getToken(e2));
    e1.getSubnodes().addChild(Regexp.<AbstractStructuralNode>getToken(e3));
    e3.getSubnodes().addChild(Regexp.<AbstractStructuralNode>getToken(e4));

    final List<Element> elements = Arrays.asList(e1, e2);

    Collections.shuffle(elements);

    final TopologicalSort s = new TopologicalSort(elements);
    final List<Element> toposorted = s.sort();

    assertEquals(2, toposorted.size());
    assertTrue(toposorted.indexOf(e1) > toposorted.indexOf(e2));
    assertTrue(toposorted.indexOf(e1) > toposorted.indexOf(e3));
    assertTrue(toposorted.indexOf(e2) > toposorted.indexOf(e4));
  }
Ejemplo n.º 2
0
 @Test
 public void testOne() throws InterruptedException {
   final Element e = TestUtils.getElement("test", Regexp.<AbstractStructuralNode>getMutable());
   e.getSubnodes().setType(RegexpType.CONCATENATION);
   e.getSubnodes().setInterval(RegexpInterval.getOnce());
   final TopologicalSort s = new TopologicalSort(Arrays.asList(e));
   final List<Element> elements = s.sort();
   assertEquals(1, elements.size());
   assertEquals(e, elements.get(0));
 }
  /** Test of start method, of class SchemaGeneratorImpl. */
  @Test
  public void testStart1() throws Exception {
    System.out.println("start alt 2,5");

    Element c = Element.getMutable();
    c.setName("c");
    c.getSubnodes().setType(RegexpType.LAMBDA);
    c.getSubnodes().setImmutable();

    Element b = Element.getMutable();
    b.setName("b");
    b.getSubnodes().setType(RegexpType.LAMBDA);
    b.getSubnodes().setImmutable();

    Regexp<AbstractStructuralNode> rb = Regexp.<AbstractStructuralNode>getToken(b);
    Regexp<AbstractStructuralNode> rc = Regexp.<AbstractStructuralNode>getToken(c);

    Element treeBase = Element.getMutable();
    treeBase.setName("a");
    treeBase.getSubnodes().setType(RegexpType.ALTERNATION);
    treeBase.getSubnodes().getChildren().add(rb);
    treeBase.getSubnodes().getChildren().add(rc);
    treeBase.getSubnodes().setInterval(RegexpInterval.getBounded(2, 5));

    List<Element> grammar = new ArrayList<Element>();
    grammar.add(treeBase);

    SchemaGeneratorCallback callback =
        new SchemaGeneratorCallback() {

          @Override
          public void finished(String schema, String extension) {
            assertEquals(
                "<!-- %generated% -->\n<!ELEMENT a ((b|c),(b|c),(b|c)?,(b|c)?,(b|c)?)>\n", schema);
          }
        };
    SchemaGeneratorImpl instance = new SchemaGeneratorImpl();
    instance.start(grammar, callback);
  }
Ejemplo n.º 4
0
 /**
  * Decides whether the two provided tokens are "the same".
  *
  * <p>Two tokens are considered to be same iff:
  *
  * <ul>
  *   <li>If they are both simple data, or
  *   <li>If they are both elements of the same name (case <strong>insensitive</strong>), or
  *   <li>If they are both attributes of the same name (case <strong>insensitive</strong>).
  * </ul>
  *
  * @param t1 First regexp - token.
  * @param t2 Second regexp - token.
  * @return True, if tokens are equal in the sense described above. False otherwise.
  * @throws IllegalArgumentException When one of the regexps is not a token.
  */
 public static boolean equalTokens(final Regexp<AbstractNode> t1, final Regexp<AbstractNode> t2) {
   if (!t1.isToken() || !t2.isToken()) {
     throw new IllegalArgumentException();
   }
   if (t1.getContent().isSimpleData() && t2.getContent().isSimpleData()) {
     return true;
   }
   if (t1.getContent().isElement()
       && t2.getContent().isElement()
       && t1.getContent().getName().equalsIgnoreCase(t2.getContent().getName())) {
     return true;
   }
   if (t1.getContent().isAttribute()
       && t2.getContent().isAttribute()
       && t1.getContent().getName().equalsIgnoreCase(t2.getContent().getName())) {
     return true;
   }
   return false;
 }
  /** Test of cleanRegularExpression method, of class CleanerEmptyChildren. */
  @Test
  public void testCleanRegularExpression2() {
    System.out.println("cleanRegularExpression2");

    final Regexp<String> r3 = Regexp.<String>getMutable();
    r3.setInterval(RegexpInterval.getOnce());
    r3.setType(RegexpType.TOKEN);
    r3.setContent("a");
    r3.setImmutable();

    final Regexp<String> r2 = Regexp.<String>getMutable();
    r2.setInterval(RegexpInterval.getOnce());
    r2.setType(RegexpType.CONCATENATION);
    r2.addChild(r3);
    r2.setImmutable();

    final Regexp<String> r1 = Regexp.<String>getMutable();
    r1.setInterval(RegexpInterval.getOnce());
    r1.setType(RegexpType.CONCATENATION);
    r1.addChild(r2);
    r1.setImmutable();

    final Regexp<String> regexp = r1;
    final EmptyChildren<String> instance = new EmptyChildren<String>();
    final Regexp<String> result = instance.cleanRegularExpression(regexp);
    assertEquals("a", result.toString());
  }