@Test
  public void testSimpleEscapedCharacter() {
    WikiPageNode wikiPageNode = getWikiPageNode("escape-1.creole");

    Assert.assertNotNull(wikiPageNode);
    Assert.assertEquals(1, wikiPageNode.getChildASTNodesCount());

    ParagraphNode paragraphNode = (ParagraphNode) wikiPageNode.getChildASTNode(0);

    Assert.assertEquals(2, paragraphNode.getChildASTNodesCount());

    LineNode lineNode = (LineNode) paragraphNode.getChildASTNode(0);

    Assert.assertEquals(2, lineNode.getChildASTNodesCount());

    UnformattedTextNode unformattedTextNode = (UnformattedTextNode) lineNode.getChildASTNode(0);

    ScapedNode scapedNode = (ScapedNode) unformattedTextNode.getChildASTNode(0);

    Assert.assertEquals("E", scapedNode.getContent());

    CollectionNode collectionNode = (CollectionNode) lineNode.getChildASTNode(1);

    unformattedTextNode = (UnformattedTextNode) collectionNode.get(0);

    Assert.assertEquals("SCAPED1", unformattedTextNode.getContent());
  }
  @Test
  public void testParseSimpleTextWithForcedEndline() {
    WikiPageNode wikiPageNode = getWikiPageNode("text-7.creole");

    Assert.assertNotNull(wikiPageNode);
    Assert.assertEquals(1, wikiPageNode.getChildASTNodesCount());

    ParagraphNode paragraphNode = (ParagraphNode) wikiPageNode.getChildASTNode(0);

    Assert.assertEquals(1, paragraphNode.getChildASTNodesCount());

    LineNode lineNode = (LineNode) paragraphNode.getChildASTNode(0);

    Assert.assertEquals(3, lineNode.getChildASTNodesCount());

    UnformattedTextNode unformattedTextNode = (UnformattedTextNode) lineNode.getChildASTNode(0);

    unformattedTextNode = (UnformattedTextNode) unformattedTextNode.getChildASTNode(0);

    Assert.assertEquals("Text with ", unformattedTextNode.getContent());

    CollectionNode collectionNode = (CollectionNode) lineNode.getChildASTNode(1);

    Assert.assertEquals(1, collectionNode.size());
    Assert.assertTrue(collectionNode.get(0) instanceof ForcedEndOfLineNode);

    collectionNode = (CollectionNode) lineNode.getChildASTNode(2);

    unformattedTextNode = (UnformattedTextNode) collectionNode.get(0);

    Assert.assertEquals("forced line break", unformattedTextNode.getContent());
  }
  @Test
  public void testParseSimpleLinkTag() {
    WikiPageNode wikiPageNode = getWikiPageNode("link-1.creole");

    Assert.assertNotNull(wikiPageNode);

    ParagraphNode paragraphNode = (ParagraphNode) wikiPageNode.getChildASTNode(0);

    LineNode lineNode = (LineNode) paragraphNode.getChildASTNode(0);

    Assert.assertEquals(1, lineNode.getChildASTNodesCount());

    LinkNode linkNode = (LinkNode) lineNode.getChildASTNode(0);

    Assert.assertEquals("link", linkNode.getLink());

    CollectionNode collectionNode = linkNode.getAltCollectionNode();

    Assert.assertNotNull(collectionNode);
    Assert.assertEquals(1, collectionNode.size());

    List<ASTNode> astNodes = collectionNode.getASTNodes();

    UnformattedTextNode unformattedTextNode = (UnformattedTextNode) astNodes.get(0);

    CollectionNode unformattedTextNodes = (CollectionNode) unformattedTextNode.getChildASTNode(0);

    unformattedTextNode = (UnformattedTextNode) unformattedTextNodes.get(0);

    Assert.assertEquals("alternative text", unformattedTextNode.getContent());
  }
  @Test
  public void testParseSimpleTextWithBoldAndItalics() {
    WikiPageNode wikiPageNode = getWikiPageNode("text-5.creole");

    Assert.assertNotNull(wikiPageNode);
    Assert.assertEquals(1, wikiPageNode.getChildASTNodesCount());

    ParagraphNode paragraphNode = (ParagraphNode) wikiPageNode.getChildASTNode(0);

    Assert.assertEquals(1, paragraphNode.getChildASTNodesCount());

    LineNode lineNode = (LineNode) paragraphNode.getChildASTNode(0);

    Assert.assertEquals(4, lineNode.getChildASTNodesCount());

    UnformattedTextNode unformattedTextNode = (UnformattedTextNode) lineNode.getChildASTNode(0);

    unformattedTextNode = (UnformattedTextNode) unformattedTextNode.getChildASTNode(0);

    Assert.assertEquals("Text with some content in ", unformattedTextNode.getContent());

    BoldTextNode boldTextNode = (BoldTextNode) lineNode.getChildASTNode(1);

    Assert.assertEquals(1, boldTextNode.getChildASTNodesCount());

    FormattedTextNode formattedTextNode = (FormattedTextNode) boldTextNode.getChildASTNode(0);

    CollectionNode collectionNode = (CollectionNode) formattedTextNode.getChildASTNode(0);

    unformattedTextNode = (UnformattedTextNode) collectionNode.get(0);

    Assert.assertEquals("bold", unformattedTextNode.getContent());
  }
  @Test
  public void testParseSimpleTextBoldAndItalics() {
    WikiPageNode wikiPageNode = getWikiPageNode("text-6.creole");

    Assert.assertNotNull(wikiPageNode);
    Assert.assertEquals(1, wikiPageNode.getChildASTNodesCount());

    ParagraphNode paragraphNode = (ParagraphNode) wikiPageNode.getChildASTNode(0);

    Assert.assertEquals(1, paragraphNode.getChildASTNodesCount());

    LineNode lineNode = (LineNode) paragraphNode.getChildASTNode(0);

    Assert.assertEquals(2, lineNode.getChildASTNodesCount());

    UnformattedTextNode unformattedTextNode = (UnformattedTextNode) lineNode.getChildASTNode(0);

    unformattedTextNode = (UnformattedTextNode) unformattedTextNode.getChildASTNode(0);

    Assert.assertEquals("Text ", unformattedTextNode.getContent());

    BoldTextNode boldTextNode = (BoldTextNode) lineNode.getChildASTNode(1);

    Assert.assertEquals(1, boldTextNode.getChildASTNodesCount());

    ItalicTextNode italicTextNode = (ItalicTextNode) boldTextNode.getChildASTNode(0);

    CollectionNode collectionNode = (CollectionNode) italicTextNode.getChildASTNode(0);

    unformattedTextNode = (UnformattedTextNode) collectionNode.get(0);

    Assert.assertEquals("ItalicAndBold", unformattedTextNode.getContent());
  }
  @Test
  public void testParseMultilineTextParagraph() {
    WikiPageNode wikiPageNode = getWikiPageNode("text-2.creole");

    Assert.assertNotNull(wikiPageNode);
    Assert.assertEquals(1, wikiPageNode.getChildASTNodesCount());

    ParagraphNode paragraphNode = (ParagraphNode) wikiPageNode.getChildASTNode(0);

    List<ASTNode> astNodes = paragraphNode.getChildASTNodes();

    Assert.assertEquals(10, astNodes.size());

    for (int i = 0; i < astNodes.size(); i++) {
      ASTNode astNode = astNodes.get(i);

      LineNode lineNode = (LineNode) astNode;

      Assert.assertEquals(1, lineNode.getChildASTNodesCount());

      UnformattedTextNode unformattedTextNode = (UnformattedTextNode) lineNode.getChildASTNode(0);

      unformattedTextNode = (UnformattedTextNode) unformattedTextNode.getChildASTNode(0);

      Assert.assertEquals("Simple P" + i, unformattedTextNode.getContent());
    }
  }
 public void visit(UnformattedTextNode unformattedTextNode) {
   if (unformattedTextNode.hasContent()) {
     append(HtmlUtil.escape(unformattedTextNode.getContent()));
   } else {
     traverse(unformattedTextNode.getChildASTNodes());
   }
 }
  @Test
  public void testParseTableMultipleRowsAndCOlumns() {
    WikiPageNode wikiPageNode = getWikiPageNode("table-2.creole");

    Assert.assertNotNull(wikiPageNode);

    TableNode tableNode = (TableNode) wikiPageNode.getChildASTNode(0);

    Assert.assertNotNull(tableNode);
    Assert.assertEquals(4, tableNode.getChildASTNodesCount());

    CollectionNode collectionNode = (CollectionNode) tableNode.getChildASTNode(0);

    Assert.assertEquals(4, collectionNode.size());

    for (int i = 0; i < 4; ++i) {
      TableHeaderNode tableHeaderNode = (TableHeaderNode) collectionNode.get(i);

      Assert.assertNotNull(tableHeaderNode);

      UnformattedTextNode unformattedTextNode =
          (UnformattedTextNode) tableHeaderNode.getChildASTNode(0);

      Assert.assertNotNull(unformattedTextNode);
      Assert.assertEquals(1, unformattedTextNode.getChildASTNodesCount());

      unformattedTextNode = (UnformattedTextNode) unformattedTextNode.getChildASTNode(0);

      Assert.assertEquals("H" + (i + 1), unformattedTextNode.getContent());
    }

    int count = 1;

    for (int row = 1; row < 4; ++row) {
      collectionNode = (CollectionNode) tableNode.getChildASTNode(row);

      Assert.assertEquals(4, collectionNode.size());

      for (int column = 0; column < 4; ++column) {
        TableDataNode tableDataNode = (TableDataNode) collectionNode.get(column);

        Assert.assertNotNull(tableDataNode);

        UnformattedTextNode unformattedTextNode =
            (UnformattedTextNode) tableDataNode.getChildASTNode(0);

        Assert.assertNotNull(unformattedTextNode);
        Assert.assertEquals(1, unformattedTextNode.getChildASTNodesCount());

        unformattedTextNode = (UnformattedTextNode) unformattedTextNode.getChildASTNode(0);

        Assert.assertEquals("C" + count++, unformattedTextNode.getContent());
      }
    }
  }
  @Test
  public void testParseCorrectlyBoldContentInListItems() {
    UnorderedListNode unorderedListNode = (UnorderedListNode) parseBaseListNode("list-6.creole");

    Assert.assertEquals(1, unorderedListNode.getChildASTNodesCount());

    UnorderedListItemNode unorderedListItemNode =
        (UnorderedListItemNode) unorderedListNode.getChildASTNode(0);

    Assert.assertNotNull(unorderedListItemNode);

    FormattedTextNode formattedTextNode =
        (FormattedTextNode) unorderedListItemNode.getChildASTNode(1);

    BoldTextNode boldTextNode = (BoldTextNode) formattedTextNode.getChildASTNode(0);

    CollectionNode collectionNode = (CollectionNode) boldTextNode.getChildASTNode(0);

    UnformattedTextNode unformattedTextNode = (UnformattedTextNode) collectionNode.get(0);

    Assert.assertEquals("abcdefg", unformattedTextNode.getContent());
  }
  @Test
  public void testParseSimpleLinkTagWithoutDescription2() {
    WikiPageNode wikiPageNode = getWikiPageNode("link-3.creole");

    Assert.assertNotNull(wikiPageNode);

    ParagraphNode paragraphNode = (ParagraphNode) wikiPageNode.getChildASTNode(0);

    LineNode lineNode = (LineNode) paragraphNode.getChildASTNode(0);

    Assert.assertEquals(5, lineNode.getChildASTNodesCount());

    List<ASTNode> astNodes = lineNode.getChildASTNodes();

    for (ASTNode astNode : astNodes) {
      if (!(astNode instanceof LinkNode)) {
        continue;
      }

      LinkNode linkNode = (LinkNode) astNode;

      Assert.assertEquals("L", linkNode.getLink());

      CollectionNode collectionNode = linkNode.getAltCollectionNode();

      Assert.assertNotNull(collectionNode);
      Assert.assertEquals(1, collectionNode.size());

      List<ASTNode> collectionNodeASTNodes = collectionNode.getASTNodes();

      UnformattedTextNode unformattedTextNode = (UnformattedTextNode) collectionNodeASTNodes.get(0);

      collectionNode = (CollectionNode) unformattedTextNode.getChildASTNode(0);

      unformattedTextNode = (UnformattedTextNode) collectionNode.get(0);

      Assert.assertEquals("A", unformattedTextNode.getContent());
    }
  }
  @Test
  public void testParseSimpleTextParagraph() {
    WikiPageNode wikiPageNode = getWikiPageNode("text-1.creole");

    Assert.assertNotNull(wikiPageNode);
    Assert.assertEquals(1, wikiPageNode.getChildASTNodesCount());

    ParagraphNode paragraphNode = (ParagraphNode) wikiPageNode.getChildASTNode(0);

    List<ASTNode> astNodes = paragraphNode.getChildASTNodes();

    Assert.assertEquals(1, astNodes.size());

    LineNode lineNode = (LineNode) paragraphNode.getChildASTNode(0);

    Assert.assertEquals(1, lineNode.getChildASTNodesCount());

    UnformattedTextNode unformattedTextNode = (UnformattedTextNode) lineNode.getChildASTNode(0);

    unformattedTextNode = (UnformattedTextNode) unformattedTextNode.getChildASTNode(0);

    Assert.assertEquals("Simple paragraph", unformattedTextNode.getContent());
  }
  @Test
  public void testParseSimpleTextWithItalics() {
    WikiPageNode wikiPageNode = getWikiPageNode("text-3.creole");

    Assert.assertNotNull(wikiPageNode);

    List<ASTNode> astNodes = wikiPageNode.getChildASTNodes();

    Assert.assertEquals(1, astNodes.size());

    ParagraphNode paragraphNode = (ParagraphNode) astNodes.get(0);

    astNodes = paragraphNode.getChildASTNodes();

    Assert.assertEquals(1, astNodes.size());

    LineNode lineNode = (LineNode) paragraphNode.getChildASTNode(0);

    Assert.assertEquals(2, lineNode.getChildASTNodesCount());

    UnformattedTextNode unformattedTextNode = (UnformattedTextNode) lineNode.getChildASTNode(0);

    unformattedTextNode = (UnformattedTextNode) unformattedTextNode.getChildASTNode(0);

    Assert.assertEquals("Text with some content in ", unformattedTextNode.getContent());

    ItalicTextNode italicTextNode = (ItalicTextNode) lineNode.getChildASTNode(1);

    FormattedTextNode formattedTextNode = (FormattedTextNode) italicTextNode.getChildASTNode(0);

    CollectionNode collectionNode = (CollectionNode) formattedTextNode.getChildASTNode(0);

    unformattedTextNode = (UnformattedTextNode) collectionNode.get(0);

    Assert.assertEquals("italic", unformattedTextNode.getContent());
  }
  @Test
  public void testParseTableOneRowOneColumn() {
    WikiPageNode wikiPageNode = getWikiPageNode("table-1.creole");

    Assert.assertNotNull(wikiPageNode);

    TableNode tableNode = (TableNode) wikiPageNode.getChildASTNode(0);

    Assert.assertNotNull(tableNode);
    Assert.assertEquals(2, tableNode.getChildASTNodesCount());

    CollectionNode collectionNode = (CollectionNode) tableNode.getChildASTNode(0);

    Assert.assertEquals(1, collectionNode.size());

    TableHeaderNode tableHeaderNode = (TableHeaderNode) collectionNode.get(0);

    Assert.assertNotNull(tableHeaderNode);

    UnformattedTextNode unformattedTextNode =
        (UnformattedTextNode) tableHeaderNode.getChildASTNode(0);

    Assert.assertNotNull(unformattedTextNode);
    Assert.assertEquals(1, unformattedTextNode.getChildASTNodesCount());

    unformattedTextNode = (UnformattedTextNode) unformattedTextNode.getChildASTNode(0);

    Assert.assertEquals("H1", unformattedTextNode.getContent());

    List<ASTNode> astNodes = tableNode.getChildASTNodes();

    collectionNode = (CollectionNode) astNodes.get(1);

    Assert.assertEquals(1, collectionNode.size());

    TableDataNode tableDataNode = (TableDataNode) collectionNode.get(0);

    Assert.assertNotNull(tableDataNode);

    unformattedTextNode = (UnformattedTextNode) tableDataNode.getChildASTNode(0);

    Assert.assertNotNull(unformattedTextNode);
    Assert.assertEquals(1, unformattedTextNode.getChildASTNodesCount());

    unformattedTextNode = (UnformattedTextNode) unformattedTextNode.getChildASTNode(0);

    Assert.assertEquals("C1.1", unformattedTextNode.getContent());
  }
Example #14
0
 public void visit(UnformattedTextNode unformattedTextNode) {
   if (unformattedTextNode.getChildASTNodesCount() > 0) {
     traverse(unformattedTextNode.getChildASTNodes());
   }
 }