@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()); } }
@Test public void testParseSimpleLinkTagWithoutDescription() { WikiPageNode wikiPageNode = getWikiPageNode("link-2.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()); Assert.assertNull(linkNode.getAltCollectionNode()); }
@Test public void testParseSimpleImageTagWithNoAlternative() { WikiPageNode wikiPageNode = getWikiPageNode("image-2.creole"); Assert.assertNotNull(wikiPageNode); ParagraphNode paragraphNode = (ParagraphNode) wikiPageNode.getChildASTNode(0); LineNode lineNode = (LineNode) paragraphNode.getChildASTNode(0); Assert.assertEquals(1, lineNode.getChildASTNodesCount()); ImageNode imageNode = (ImageNode) lineNode.getChildASTNode(0); Assert.assertEquals("link", imageNode.getLink()); CollectionNode collectionNode = imageNode.getAltNode(); Assert.assertNull(collectionNode); }
@Test public void testParseOnlySpacesContentInImageTag() { WikiPageNode wikiPageNode = getWikiPageNode("image-3.creole"); Assert.assertNotNull(wikiPageNode); ParagraphNode paragraphNode = (ParagraphNode) wikiPageNode.getChildASTNode(0); LineNode lineNode = (LineNode) paragraphNode.getChildASTNode(0); Assert.assertEquals(1, lineNode.getChildASTNodesCount()); ImageNode imageNode = (ImageNode) lineNode.getChildASTNode(0); Assert.assertEquals(" ", imageNode.getLink()); CollectionNode collectionNode = imageNode.getAltNode(); Assert.assertNull(collectionNode); }
@Test public void testParseMultipleImageTags() { WikiPageNode wikiPageNode = getWikiPageNode("image-5.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 (int i = 0; i < astNodes.size(); ) { ImageNode imageNode = (ImageNode) astNodes.get(i); Assert.assertEquals("L" + ++i, imageNode.getLink()); } }
@Test public void testParseEmpyImageTag() { WikiPageNode wikiPageNode = getWikiPageNode("image-4.creole"); Assert.assertNotNull(wikiPageNode); ParagraphNode paragraphNode = (ParagraphNode) wikiPageNode.getChildASTNode(0); LineNode lineNode = (LineNode) paragraphNode.getChildASTNode(0); Assert.assertEquals(1, lineNode.getChildASTNodesCount()); ImageNode imageNode = (ImageNode) lineNode.getChildASTNode(0); Assert.assertEquals(StringPool.BLANK, imageNode.getLink()); CollectionNode collectionNode = imageNode.getAltNode(); Assert.assertNull(collectionNode); }
@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()); }
public void visit(LineNode lineNode) { traverse(lineNode.getChildASTNodes(), null, StringPool.SPACE); }
public void visit(LineNode lineNode) { traverse(lineNode.getChildASTNodes()); }