📄 jspwikimarkupparsertest.java
字号:
{ String src = "The page ~ASamplePage is not a hyperlink."; assertEquals( "The page ASamplePage is not a hyperlink.", translate(src) ); } public void testHyperlinksCCNegated4() throws Exception { String src = "The page \"~ASamplePage\" is not a hyperlink."; assertEquals( "The page "ASamplePage" is not a hyperlink.", translate(src) ); } public void testCCLinkInList() throws Exception { newPage("HyperLink"); String src = "*HyperLink"; assertEquals( "<ul><li><a class=\"wikipage\" href=\"/Wiki.jsp?page=HyperLink\">HyperLink</a></li></ul>", translate(src) ); } public void testCCLinkBold() throws Exception { newPage("BoldHyperLink"); String src = "__BoldHyperLink__"; assertEquals( "<b><a class=\"wikipage\" href=\"/Wiki.jsp?page=BoldHyperLink\">BoldHyperLink</a></b>", translate(src) ); } public void testCCLinkBold2() throws Exception { newPage("HyperLink"); String src = "Let's see, if a bold __HyperLink__ is correct?"; assertEquals( "Let's see, if a bold <b><a class=\"wikipage\" href=\"/Wiki.jsp?page=HyperLink\">HyperLink</a></b> is correct?", translate(src) ); } public void testCCLinkItalic() throws Exception { newPage("ItalicHyperLink"); String src = "''ItalicHyperLink''"; assertEquals( "<i><a class=\"wikipage\" href=\"/Wiki.jsp?page=ItalicHyperLink\">ItalicHyperLink</a></i>", translate(src) ); } public void testCCLinkWithPunctuation() throws Exception { newPage("HyperLink"); String src = "Test. Punctuation. HyperLink."; assertEquals( "Test. Punctuation. <a class=\"wikipage\" href=\"/Wiki.jsp?page=HyperLink\">HyperLink</a>.", translate(src) ); } public void testCCLinkWithPunctuation2() throws Exception { newPage("HyperLink"); newPage("ThisToo"); String src = "Punctuations: HyperLink,ThisToo."; assertEquals( "Punctuations: <a class=\"wikipage\" href=\"/Wiki.jsp?page=HyperLink\">HyperLink</a>,<a class=\"wikipage\" href=\"/Wiki.jsp?page=ThisToo\">ThisToo</a>.", translate(src) ); } public void testCCLinkWithScandics() throws Exception { newPage("\u00c4itiSy\u00f6\u00d6ljy\u00e4"); String src = "Onko t\u00e4m\u00e4 hyperlinkki: \u00c4itiSy\u00f6\u00d6ljy\u00e4?"; assertEquals( "Onko t\u00e4m\u00e4 hyperlinkki: <a class=\"wikipage\" href=\"/Wiki.jsp?page=%C4itiSy%F6%D6ljy%E4\">\u00c4itiSy\u00f6\u00d6ljy\u00e4</a>?", translate(src) ); } public void testHyperlinksExt() throws Exception { String src = "This should be a [http://www.regex.fi/]"; assertEquals( "This should be a <a class=\"external\" href=\"http://www.regex.fi/\">http://www.regex.fi/</a>", translate(src) ); } public void testHyperlinksExt2() throws Exception { String src = "This should be a [link|http://www.regex.fi/]"; assertEquals( "This should be a <a class=\"external\" href=\"http://www.regex.fi/\">link</a>", translate(src) ); } public void testHyperlinksExtNofollow() throws Exception { String src = "This should be a [link|http://www.regex.fi/]"; assertEquals( "This should be a <a class=\"external\" href=\"http://www.regex.fi/\" rel=\"nofollow\">link</a>", translate_nofollow(src) ); } // // Testing various odds and ends about hyperlink matching. // public void testHyperlinksPluralMatch() throws Exception { String src = "This should be a [HyperLinks]"; newPage("HyperLink"); assertEquals( "This should be a <a class=\"wikipage\" href=\"/Wiki.jsp?page=HyperLink\">HyperLinks</a>", translate(src) ); } public void testHyperlinksPluralMatch2() throws Exception { String src = "This should be a [HyperLinks]"; assertEquals( "This should be a <a class=\"createpage\" href=\"/Edit.jsp?page=HyperLinks\" title=\"Create "HyperLinks"\">HyperLinks</a>", translate(src) ); } public void testHyperlinksPluralMatch3() throws Exception { String src = "This should be a [HyperLink]"; newPage("HyperLinks"); assertEquals( "This should be a <a class=\"wikipage\" href=\"/Wiki.jsp?page=HyperLinks\">HyperLink</a>", translate(src) ); } public void testHyperlinksPluralMatch4() throws Exception { String src = "This should be a [Hyper links]"; newPage("HyperLink"); assertEquals( "This should be a <a class=\"wikipage\" href=\"/Wiki.jsp?page=HyperLink\">Hyper links</a>", translate(src) ); } public void testHyperlinkJS1() throws Exception { String src = "This should be a [link|http://www.haxored.com/\" onMouseOver=\"alert('Hahhaa');\"]"; assertEquals( "This should be a <a class=\"external\" href=\"http://www.haxored.com/" onMouseOver="alert('Hahhaa');"\">link</a>", translate(src) ); } public void testHyperlinksInterWiki1() throws Exception { String src = "This should be a [link|JSPWiki:HyperLink]"; assertEquals( "This should be a <a class=\"interwiki\" href=\"http://www.ecyrd.com/JSPWiki/Wiki.jsp?page=HyperLink\">link</a>", translate(src) ); } public void testHyperlinksInterWiki2() throws Exception { String src = "This should be a [JSPWiki:HyperLink]"; assertEquals( "This should be a <a class=\"interwiki\" href=\"http://www.ecyrd.com/JSPWiki/Wiki.jsp?page=HyperLink\">JSPWiki:HyperLink</a>", translate(src) ); } public void testAttachmentLink() throws Exception { newPage("Test"); Attachment att = new Attachment( testEngine, "Test", "TestAtt.txt" ); att.setAuthor( "FirstPost" ); testEngine.getAttachmentManager().storeAttachment( att, testEngine.makeAttachmentFile() ); String src = "This should be an [attachment link|Test/TestAtt.txt]"; assertEquals( "This should be an <a class=\"attachment\" href=\"/attach/Test/TestAtt.txt\">attachment link</a>"+ "<a href=\"/PageInfo.jsp?page=Test/TestAtt.txt\" class=\"infolink\"><img src=\"/images/attachment_small.png\" border=\"0\" alt=\"(info)\" /></a>", translate(src)); } public void testAttachmentLink2() throws Exception { props.setProperty( "jspwiki.encoding", "ISO-8859-1" ); //TODO TestEngine testEngine2 = new TestEngine( props ); testEngine2.saveText( "Test", "foo "); created.addElement( "Test" ); Attachment att = new Attachment( testEngine2, "Test", "TestAtt.txt" ); att.setAuthor( "FirstPost" ); testEngine2.getAttachmentManager().storeAttachment( att, testEngine.makeAttachmentFile() ); String src = "This should be an [attachment link|Test/TestAtt.txt]"; assertEquals( "This should be an <a class=\"attachment\" href=\"/attach/Test/TestAtt.txt\">attachment link</a>"+ "<a href=\"/PageInfo.jsp?page=Test/TestAtt.txt\" class=\"infolink\"><img src=\"/images/attachment_small.png\" border=\"0\" alt=\"(info)\" /></a>", translate(testEngine2,src)); } /** * Are attachments parsed correctly also when using gappy text? */ public void testAttachmentLink3() throws Exception { TestEngine testEngine2 = new TestEngine( props ); testEngine2.saveText( "TestPage", "foo "); created.addElement( "TestPage" ); Attachment att = new Attachment( testEngine2, "TestPage", "TestAtt.txt" ); att.setAuthor( "FirstPost" ); testEngine2.getAttachmentManager().storeAttachment( att, testEngine.makeAttachmentFile() ); String src = "[Test page/TestAtt.txt]"; assertEquals( "<a class=\"attachment\" href=\"/attach/TestPage/TestAtt.txt\">Test page/TestAtt.txt</a>"+ "<a href=\"/PageInfo.jsp?page=TestPage/TestAtt.txt\" class=\"infolink\"><img src=\"/images/attachment_small.png\" border=\"0\" alt=\"(info)\" /></a>", translate(testEngine2,src)); } public void testAttachmentLink4() throws Exception { TestEngine testEngine2 = new TestEngine( props ); testEngine2.saveText( "TestPage", "foo "); created.addElement( "TestPage" ); Attachment att = new Attachment( testEngine2, "TestPage", "TestAtt.txt" ); att.setAuthor( "FirstPost" ); testEngine2.getAttachmentManager().storeAttachment( att, testEngine.makeAttachmentFile() ); String src = "["+testEngine2.beautifyTitle("TestPage/TestAtt.txt")+"]"; assertEquals( "<a class=\"attachment\" href=\"/attach/TestPage/TestAtt.txt\">Test Page/TestAtt.txt</a>"+ "<a href=\"/PageInfo.jsp?page=TestPage/TestAtt.txt\" class=\"infolink\"><img src=\"/images/attachment_small.png\" border=\"0\" alt=\"(info)\" /></a>", translate(testEngine2,src)); } public void testNoHyperlink() throws Exception { newPage("HyperLink"); String src = "This should not be a [[HyperLink]"; assertEquals( "This should not be a [HyperLink]", translate(src) ); } public void testNoHyperlink2() throws Exception { String src = "This should not be a [[[[HyperLink]"; assertEquals( "This should not be a [[[HyperLink]", translate(src) ); } public void testNoHyperlink3() throws Exception { String src = "[[HyperLink], and this [[Neither]."; assertEquals( "[HyperLink], and this [Neither].", translate(src) ); } public void testNoPlugin() throws Exception { String src = "There is [[{NoPlugin}] here."; assertEquals( "There is [{NoPlugin}] here.", translate(src) ); } public void testErroneousHyperlink() throws Exception { String src = "What if this is the last char ["; assertEquals( "What if this is the last char ", translate(src) ); } public void testErroneousHyperlink2() throws Exception { String src = "What if this is the last char [["; assertEquals( "What if this is the last char [", translate(src) ); } public void testExtraPagename1() throws Exception { String src = "Link [test_page]"; newPage("Test_page"); assertEquals("Link <a class=\"wikipage\" href=\"/Wiki.jsp?page=Test_page\">test_page</a>", translate(src) ); } public void testExtraPagename2() throws Exception { String src = "Link [test.page]"; newPage("Test.page"); assertEquals("Link <a class=\"wikipage\" href=\"/Wiki.jsp?page=Test.page\">test.page</a>", translate(src) ); } public void testExtraPagename3() throws Exception { String src = "Link [.testpage_]"; newPage(".testpage_"); assertEquals("Link <a class=\"wikipage\" href=\"/Wiki.jsp?page=.testpage_\">.testpage_</a>", translate(src) ); } public void testInlineImages() throws Exception { String src = "Link [test|http://www.ecyrd.com/test.png]"; assertEquals("Link <img class=\"inline\" src=\"http://www.ecyrd.com/test.png\" alt=\"test\" />", translate(src) ); } public void testInlineImages2() throws Exception { String src = "Link [test|http://www.ecyrd.com/test.ppm]"; assertEquals("Link <a class=\"external\" href=\"http://www.ecyrd.com/test.ppm\">test</a>", translate(src) ); } public void testInlineImages3() throws Exception { String src = "Link [test|http://images.com/testi]"; assertEquals("Link <img class=\"inline\" src=\"http://images.com/testi\" alt=\"test\" />", translate(src) ); } public void testInlineImages4() throws Exception { String src = "Link [test|http://foobar.jpg]"; assertEquals("Link <img class=\"inline\" src=\"http://foobar.jpg\" alt=\"test\" />", translate(src) ); } // No link text should be just embedded link. public void testInlineImagesLink2() throws Exception { String src = "Link [http://foobar.jpg]"; assertEquals("Link <img class=\"inline\" src=\"http://foobar.jpg\" alt=\"http://foobar.jpg\" />", translate(src) ); } public void testInlineImagesLink() throws Exception { String src = "Link [http://link.to/|http://foobar.jpg]"; assertEquals("Link <a class=\"external\" href=\"http://link.to/\"><img class=\"inline\" src=\"http://foobar.jpg\" alt=\"http://link.to/\" /></a>", translate(src) ); } public void testInlineImagesLink3() throws Exception { String src = "Link [SandBox|http://foobar.jpg]"; newPage("SandBox"); assertEquals("Link <a class=\"wikipage\" href=\"/Wiki.jsp?page=SandBox\"><img class=\"inline\" src=\"http://foobar.jpg\" alt=\"SandBox\" /></a>", translate(src) ); } public void testScandicPagename1() throws Exception { String src = "Link [\u00C5\u00E4Test]"; newPage("\u00C5\u00E4Test"); // FIXME: Should be capital assertEquals("Link <a class=\"wikipage\" href=\"/Wiki.jsp?page=%C5%E4Test\">\u00c5\u00e4Test</a>", translate(src)); } public void testParagraph() throws Exception { String src = "1\n\n2\n\n3"; assertEquals( "<p>1\n</p><p>2\n</p>\n<p>3</p>", translate(src) ); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -