@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 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 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 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());
      }
    }
  }
  public void visit(LinkNode linkNode) {
    append("<a href=\"");
    append(HtmlUtil.escape(linkNode.getLink()));
    append("\">");

    if (linkNode.hasAltCollectionNode()) {
      CollectionNode altCollectionNode = linkNode.getAltCollectionNode();

      traverse(altCollectionNode.getASTNodes());
    } else {
      append(HtmlUtil.escape(linkNode.getLink()));
    }

    append("</a>");
  }
  @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());
  }
  public void visit(ImageNode imageNode) {
    append("<img src=\"");
    append(HtmlUtil.escape(imageNode.getLink()));
    append("\" ");

    if (imageNode.hasAltCollectionNode()) {
      append("alt=\"");

      CollectionNode altCollectionNode = imageNode.getAltNode();

      traverse(altCollectionNode.getASTNodes());

      append("\"");
    }

    append("/>");
  }
  @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 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());
  }
 public void visit(CollectionNode collectionNode) {
   for (ASTNode astNode : collectionNode.getASTNodes()) {
     astNode.accept(this);
   }
 }