📄 jspwikimarkupparsertest.java
字号:
public void testParagraph2() throws Exception { String src = "[WikiEtiquette]\r\n\r\n[Find page]"; newPage( "WikiEtiquette" ); assertEquals( "<p><a class=\"wikipage\" href=\"/Wiki.jsp?page=WikiEtiquette\">WikiEtiquette</a>\n</p>"+ "<p><a class=\"wikipage\" href=\"/Wiki.jsp?page=FindPage\">Find page</a></p>", translate(src) ); } public void testParagraph3() throws Exception { String src = "\r\n\r\n!Testi\r\n\r\nFoo."; assertEquals( "<p />\n<h4 id=\"section-testpage-Testi\">Testi<a class=\"hashlink\" href=\"#section-testpage-Testi\">#</a></h4>\n<p>Foo.</p>", translate(src) ); } public void testParagraph4() throws Exception { String src = "\r\n[Recent Changes]\\\\\r\n[WikiEtiquette]\r\n\r\n[Find pages|FindPage]\\\\\r\n[Unused pages|UnusedPages]"; newPage("WikiEtiquette"); newPage("RecentChanges"); newPage("FindPage"); newPage("UnusedPages"); assertEquals( "<p><a class=\"wikipage\" href=\"/Wiki.jsp?page=RecentChanges\">Recent Changes</a><br />\n"+ "<a class=\"wikipage\" href=\"/Wiki.jsp?page=WikiEtiquette\">WikiEtiquette</a>\n</p>\n"+ "<p><a class=\"wikipage\" href=\"/Wiki.jsp?page=FindPage\">Find pages</a><br />\n"+ "<a class=\"wikipage\" href=\"/Wiki.jsp?page=UnusedPages\">Unused pages</a></p>", translate(src) ); } public void testParagraph5() throws Exception { String src = "__File type sniffing__ is a way of identifying the content type of a document.\n\n"+ "In UNIX, the file(1) command can be used."; assertEquals( "<p><b>File type sniffing</b> is a way of identifying the content type of a document.\n</p>"+ "<p>In UNIX, the file(1) command can be used.</p>", translate(src) ); } public void testParagraph6() throws Exception { String src = "[{Counter}]\n\n__File type sniffing__ is a way of identifying the content type of a document.\n\n"+ "In UNIX, the file(1) command can be used."; assertEquals( "<p>1\n</p><p><b>File type sniffing</b> is a way of identifying the content type of a document.\n</p>\n"+ "<p>In UNIX, the file(1) command can be used.</p>", translate(src) ); } public void testParagraph7() throws Exception { String src = "[{$encoding}]\n\n__File type sniffing__ is a way of identifying the content type of a document.\n\n"+ "In UNIX, the file(1) command can be used."; assertEquals( "<p>ISO-8859-1\n</p><p><b>File type sniffing</b> is a way of identifying the content type of a document.\n</p>\n"+ "<p>In UNIX, the file(1) command can be used.</p>", translate(src) ); } public void testParagraph8() throws Exception { String src = "[{SET foo=bar}]\n\n__File type sniffing__ is a way of identifying the content type of a document.\n\n"+ "In UNIX, the file(1) command can be used."; assertEquals( "<p><b>File type sniffing</b> is a way of identifying the content type of a document.\n</p>\n"+ "<p>In UNIX, the file(1) command can be used.</p>", translate(src) ); } public void testLinebreak() throws Exception { String src = "1\\\\2"; assertEquals( "1<br />2", translate(src) ); } public void testLinebreakEscape() throws Exception { String src = "1~\\\\2"; assertEquals( "1\\\\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; white-space:pre;\">2345</span>6", translate(src) ); } public void testPre2() throws Exception { String src = "1 {{{ {{{ 2345 }}} }}} 6"; assertEquals( "1 <span style=\"font-family:monospace; white-space:pre;\"> {{{ 2345 </span> }}} 6", translate(src) ); } public void testPre3() throws Exception { String src = "foo\n\nbar{{{2345}}}6"; assertEquals( "<p>foo\n</p><p>bar<span style=\"font-family:monospace; white-space:pre;\">2345</span>6</p>", translate(src) ); } public void testPreEscape() throws Exception { String src = "1~{{{2345}}}6"; assertEquals( "1{{{2345}}}6", translate(src) ); } public void testPreEscape2() throws Exception { String src = "1{{{{{{2345~}}}}}}6"; assertEquals( "1<span style=\"font-family:monospace; white-space:pre;\">{{{2345}}}</span>6", translate(src) ); } public void testPreEscape3() throws Exception { String src = "1 {{{ {{{ 2345 ~}}} }}} 6"; assertEquals( "1 <span style=\"font-family:monospace; white-space:pre;\"> {{{ 2345 }}} </span> 6", translate(src) ); } public void testPreEscape4() throws Exception { String src = "1{{{ {{{2345~}} }}}6"; assertEquals( "1<span style=\"font-family:monospace; white-space:pre;\"> {{{2345~}} </span>6", translate(src) ); } public void testPreEscape5() throws Exception { String src = "1{{{ ~ }}}6"; assertEquals( "1<span style=\"font-family:monospace; white-space:pre;\"> ~ </span>6", translate(src) ); } public void testHTMLInPre() throws Exception { String src = "1\n{{{ <b> }}}"; assertEquals( "1\n<pre> <b> </pre>", translate(src) ); } public void testCamelCaseInPre() throws Exception { String src = "1\n{{{ CamelCase }}}"; assertEquals( "1\n<pre> CamelCase </pre>", translate(src) ); } public void testPreWithLines() throws Exception { String src = "1\r\n{{{\r\nZippadii\r\n}}}"; assertEquals( "1\n<pre>\nZippadii\n</pre>", translate(src) ); } public void testList1() throws Exception { String src = "A list:\n* One\n* Two\n* Three\n"; assertEquals( "A list:\n<ul><li>One\n</li><li>Two\n</li><li>Three\n</li></ul>", 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><li>One\n continuing.\n</li><li>Two\n</li><li>Three\n</li></ul>", 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><li>One\n continuing.\n</li><li>Two\n</li><li>Three\n</li></ul>Should 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 ); WikiPage page = new WikiPage(testEngine,PAGE_NAME); String out = translate( testEngine, page, src ); assertEquals( "<p>", out ); } public void testHTMLWhenAllowedPre() throws Exception { String src = "{{{ <br /> }}}"; props.setProperty( "jspwiki.translatorReader.allowHTML", "true" ); testEngine = new TestEngine( props ); WikiPage page = new WikiPage(testEngine,PAGE_NAME); String out = translate( testEngine, page, src ); assertEquals( "<pre> <br /> </pre>", out ); } /* // This test is not really needed anymore: the JDOM output mechanism // handles attribute and element content escaping properly. public void testQuotes() throws Exception { String src = "\"Test\"\""; assertEquals( ""Test""", translate(src) ); } */ public void testHTMLEntities() throws Exception { String src = "& ↓ foo bar " ߤ&"; assertEquals( "& ↓ foo bar " ߤ&", translate(src) ); } public void testItalicAcrossLinebreak() throws Exception { String src="''This is a\ntest.''"; assertEquals( "<i>This is a\ntest.</i>", translate(src) ); } public void testBoldAcrossLinebreak() throws Exception { String src="__This is a\ntest.__"; assertEquals( "<b>This is a\ntest.</b>", translate(src) ); } public void testBoldAcrossParagraph() throws Exception { String src="__This is a\n\ntest.__"; assertEquals( "<p><b>This is a\n</b></p><p><b>test.</b></p>", translate(src) ); } public void testBoldItalic() throws Exception { String src="__This ''is'' a test.__"; assertEquals( "<b>This <i>is</i> a test.</b>", translate(src) ); } public void testFootnote1() throws Exception { String src="Footnote[1]"; assertEquals( "Footnote<a class=\"footnoteref\" href=\"#ref-testpage-1\">[1]</a>", translate(src) ); } public void testFootnote2() throws Exception { String src="[#2356] Footnote."; assertEquals( "<a class=\"footnote\" name=\"ref-testpage-2356\">[#2356]</a> Footnote.", translate(src) ); } /** Check an reported error condition where empty list items could cause crashes */ public void testEmptySecondLevelList() throws Exception { String src="A\n\n**\n\nB"; // System.out.println(translate(src)); assertEquals( "<p>A\n</p><ul><li><ul><li>\n</li></ul></li></ul><p>B</p>", translate(src) ); } public void testEmptySecondLevelList2() throws Exception { String src="A\n\n##\n\nB"; // System.out.println(translate(src)); assertEquals( "<p>A\n</p><ol><li><ol><li>\n</li></ol></li></ol><p>B</p>", translate(src) ); } /** * <pre> * *Item A * ##Numbered 1 * ##Numbered 2 * *Item B * </pre> * * would come out as: *<ul> * <li>Item A * </ul> * <ol> * <ol> * <li>Numbered 1 * <li>Numbered 2 * <ul> * <li></ol> * </ol> * Item B * </ul> * * (by Mahlen Morris). */ public void testMixedList() throws Exception { String src="*Item A\n##Numbered 1\n##Numbered 2\n*Item B\n"; String result = translate(src); // Remove newlines for easier parsing. result = TextUtil.replaceString( result, "\n", "" ); assertEquals( "<ul><li>Item A"+ "<ol><li>Numbered 1</li>"+ "<li>Numbered 2</li>"+ "</ol></li>"+ "<li>Item B</li>"+ "</ul>", result ); } /** * Like testMixedList() but the list types have been reversed. */ public void testMixedList2() throws Exception { String src="#Item A\n**Numbered 1\n**Numbered 2\n#Item B\n"; String result = translate(src); // Remove newlines for easier parsing. result = TextUtil.replaceString( result, "\n", "" ); assertEquals( "<ol><li>Item A"+ "<ul><li>Numbered 1</li>"+ "<li>Numbered 2</li>"+ "</ul></li>"+ "<li>Item B</li>"+
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -