📄 translatorreadertest.java
字号:
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) ); } // // 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 <u>HyperLinks</u><a href=\"Edit.jsp?page=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 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 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 href=\"http://link.to/\"><img class=\"inline\" src=\"http://foobar.jpg\" /></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( "1\n<p>\n2\n</p><p>\n3</p>", translate(src) ); } public void testParagraph2() throws Exception { String src = "[WikiEtiquette]\r\n\r\n[Find page]"; newPage( "WikiEtiquette" ); assertEquals( "<a class=\"wikipage\" href=\"Wiki.jsp?page=WikiEtiquette\">WikiEtiquette</a>\n"+ "<p>\n<a class=\"wikipage\" href=\"Wiki.jsp?page=FindPage\">Find page</a></p>", translate(src) ); } public void testLinebreak() throws Exception { String src = "1\\\\2"; assertEquals( "1<br />2", translate(src) ); } public void testLinebreakClear() throws Exception { String src = "1\\\\\\2"; assertEquals( "1<br clear=\"all\" />2", translate(src) ); } public void testTT() throws Exception { String src = "1{{2345}}6"; assertEquals( "1<tt>2345</tt>6", translate(src) ); } public void testTTAcrossLines() throws Exception { String src = "1{{\n2345\n}}6"; assertEquals( "1<tt>\n2345\n</tt>6", translate(src) ); } public void testTTLinks() throws Exception { String src = "1{{\n2345\n[a link]\n}}6"; newPage("ALink"); assertEquals( "1<tt>\n2345\n<a class=\"wikipage\" href=\"Wiki.jsp?page=ALink\">a link</a>\n</tt>6", translate(src) ); } public void testPre() throws Exception { String src = "1{{{2345}}}6"; assertEquals( "1<span style=\"font-family:monospace; whitespace:pre;\">2345</span>6", translate(src) ); } public void testPre2() throws Exception { String src = "1 {{{ {{{ 2345 }}} }}} 6"; assertEquals( "1 <span style=\"font-family:monospace; whitespace:pre;\"> {{{ 2345 </span> }}} 6", translate(src) ); } public void testHTMLInPre() throws Exception { String src = "1\n{{{ <b> }}}"; assertEquals( "1\n<pre> <b> </pre>\n", translate(src) ); } public void testCamelCaseInPre() throws Exception { String src = "1\n{{{ CamelCase }}}"; assertEquals( "1\n<pre> CamelCase </pre>\n", translate(src) ); } public void testList1() throws Exception { String src = "A list:\n* One\n* Two\n* Three\n"; assertEquals( "A list:\n<ul>\n<li> One\n</li>\n<li> Two\n</li>\n<li> Three\n</li>\n</ul>\n", translate(src) ); } /** Plain multi line testing: <pre> * One continuing * Two * Three </pre> */ public void testMultilineList1() throws Exception { String src = "A list:\n* One\n continuing.\n* Two\n* Three\n"; assertEquals( "A list:\n<ul>\n<li> One\n continuing.\n</li>\n<li> Two\n</li>\n<li> Three\n</li>\n</ul>\n", translate(src) ); } public void testMultilineList2() throws Exception { String src = "A list:\n* One\n continuing.\n* Two\n* Three\nShould be normal."; assertEquals( "A list:\n<ul>\n<li> One\n continuing.\n</li>\n<li> Two\n</li>\n<li> Three\n</li>\n</ul>\nShould be normal.", translate(src) ); } public void testHTML() throws Exception { String src = "<b>Test</b>"; assertEquals( "<b>Test</b>", translate(src) ); } public void testHTML2() throws Exception { String src = "<p>"; assertEquals( "<p>", translate(src) ); } public void testHTMLWhenAllowed() throws Exception { String src = "<p>"; props.setProperty( "jspwiki.translatorReader.allowHTML", "true" ); testEngine = new TestEngine( props ); WikiContext context = new WikiContext( testEngine, new WikiPage(PAGE_NAME) ); Reader r = new TranslatorReader( context, new BufferedReader( new StringReader(src)) ); StringWriter out = new StringWriter(); int c; while( ( c=r.read()) != -1 ) { out.write( c ); } assertEquals( "<p>", out.toString() ); } public void testQuotes() throws Exception { String src = "\"Test\"\""; assertEquals( ""Test""", translate(src) ); } public void testItalicAcrossLinebreak() throws Exception { String src="''This is a\ntest.''"; assertEquals( "<i>This is a\ntest.</i>", translate(src) ); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -