⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 translatorreadertest.java

📁 wiki建站资源 java编写的 很好用
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
        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( "&quot;Test&quot;&quot;", 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 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( "A\n<ul>\n<li><ul>\n<li>\n</li>\n</ul>\n</li>\n</ul>\n<p>B</p>\n",                       translate(src) );    }    public void testEmptySecondLevelList2()        throws Exception    {        String src="A\n\n##\n\nB";        // System.out.println(translate(src));        assertEquals( "A\n<ol>\n<li><ol>\n<li>\n</li>\n</ol>\n</li>\n</ol>\n<p>B</p>\n",                       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>"+                      "</ol>",                      result );    }    public void testNestedList()        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"+                      "<ul><li>Numbered 1</li>"+                      "<li>Numbered 2</li>"+                      "</ul></li>"+                      "<li>Item B</li>"+                      "</ul>",                      result );    }    public void testNestedList2()        throws Exception    {        String src="*Item A\n**Numbered 1\n**Numbered 2\n***Numbered3\n*Item B\n";        String result = translate(src);        // Remove newlines for easier parsing.        result = TextUtil.replaceString( result, "\n", "" );        assertEquals( "<ul><li>Item A"+                      "<ul><li>Numbered 1</li>"+                      "<li>Numbered 2"+                      "<ul><li>Numbered3</li>"+                      "</ul></li>"+                      "</ul></li>"+                      "<li>Item B</li>"+                      "</ul>",                      result );    }    public void testPluginInsert()        throws Exception    {        String src="[{INSERT com.ecyrd.jspwiki.plugin.SamplePlugin WHERE text=test}]";        assertEquals( "test", translate(src) );    }    public void testPluginNoInsert()        throws Exception    {        String src="[{SamplePlugin text=test}]";        assertEquals( "test", translate(src) );    }    public void testPluginInsertJS()        throws Exception    {        String src="Today: [{INSERT JavaScriptPlugin}] ''day''.";        assertEquals( "Today: <script language=\"JavaScript\"><!--\nfoo='';\n--></script>\n <i>day</i>.", translate(src) );    }    public void testShortPluginInsert()        throws Exception    {        String src="[{INSERT SamplePlugin WHERE text=test}]";        assertEquals( "test", translate(src) );    }    /**     *  Test two plugins on same row.     */    public void testShortPluginInsert2()        throws Exception    {        String src="[{INSERT SamplePlugin WHERE text=test}] [{INSERT SamplePlugin WHERE text=test2}]";        assertEquals( "test test2", translate(src) );    }    public void testPluginQuotedArgs()        throws Exception    {        String src="[{INSERT SamplePlugin WHERE text='test me now'}]";        assertEquals( "test me now", translate(src) );    }    public void testPluginDoublyQuotedArgs()        throws Exception    {        String src="[{INSERT SamplePlugin WHERE text='test \\'me too\\' now'}]";        assertEquals( "test 'me too' now", translate(src) );    }    public void testPluginQuotedArgs2()        throws Exception    {        String src="[{INSERT SamplePlugin WHERE text=foo}] [{INSERT SamplePlugin WHERE text='test \\'me too\\' now'}]";        assertEquals( "foo test 'me too' now", translate(src) );    }    /**     *  Plugin output must not be parsed as Wiki text.     */    public void testPluginWikiText()        throws Exception    {        String src="[{INSERT SamplePlugin WHERE text=PageContent}]";        assertEquals( "PageContent", translate(src) );    }    /**     *  Nor should plugin input be interpreted as wiki text.     */    public void testPluginWikiText2()        throws Exception    {        String src="[{INSERT SamplePlugin WHERE text='----'}]";        assertEquals( "----", translate(src) );    }    public void testMultilinePlugin1()        throws Exception    {        String src="Test [{INSERT SamplePlugin WHERE\n text=PageContent}]";        assertEquals( "Test PageContent", translate(src) );    }    public void testMultilinePluginBodyContent()        throws Exception    {        String src="Test [{INSERT SamplePlugin\ntext=PageContent\n\n123\n456\n}]";        assertEquals( "Test PageContent (123+456+)", translate(src) );    }    public void testMultilinePluginBodyContent2()        throws Exception    {        String src="Test [{INSERT SamplePlugin\ntext=PageContent\n\n\n123\n456\n}]";        assertEquals( "Test PageContent (+123+456+)", translate(src) );    }    public void testMultilinePluginBodyContent3()        throws Exception    {        String src="Test [{INSERT SamplePlugin\n\n123\n456\n}]";        assertEquals( "Test  (123+456+)", translate(src) );    }    /**     *  Has an extra space after plugin name.     */    public void testMultilinePluginBodyContent4()        throws Exception    {        String src="Test [{INSERT SamplePlugin \n\n123\n456\n}]";        assertEquals( "Test  (123+456+)", translate(src) );    }    /**     *  Check that plugin end is correctly recognized.     */    public void testPluginEnd()        throws Exception    {        String src="Test [{INSERT SamplePlugin text=']'}]";        assertEquals( "Test ]", translate(src) );    }    public void testPluginEnd2()        throws Exception    {        String src="Test [{INSERT SamplePlugin text='a[]+b'}]";        assertEquals( "Test a[]+b", translate(src) );    }    public void testPluginEnd3()        throws Exception    {        String src="Test [{INSERT SamplePlugin\n\na[]+b\n}]";        assertEquals( "Test  (a[]+b+)", translate(src) );    }    public void testPluginEnd4()        throws Exception    {        String src="Test [{INSERT SamplePlugin text='}'}]";        assertEquals( "Test }", translate(src) );    }    public void testPluginEnd5()        throws Exception    {        String src="Test [{INSERT SamplePlugin\n\na[]+b{}\nGlob.\n}]";        assertEquals( "Test  (a[]+b{}+Glob.+)", translate(src) );    }    public void testPluginEnd6()        throws Exception    {        String src="Test [{INSERT SamplePlugin\n\na[]+b{}\nGlob.\n}}]";        assertEquals( "Test  (a[]+b{}+Glob.+})", translate(src) );    }    //  FIXME: I am not entirely certain if this is the right result    //  Perhaps some sort of an error should be checked?    public void testPluginNoEnd()        throws Exception    {        String src="Test [{INSERT SamplePlugin\n\na+b{}\nGlob.\n}";        assertEquals( "Test {INSERT SamplePlugin\n\na+b{}\nGlob.\n}", translate(src) );    }    public void testVariableInsert()        throws Exception    {        String src="[{$pagename}]";        assertEquals( PAGE_NAME+"", translate(src) );    }    public void testTable1()        throws Exception    {        String src="|| heading || heading2 \n| Cell 1 | Cell 2 \n| Cell 3 | Cell 4\n\n";        assertEquals( "<table class=\"wikitable\" border=\"1\">\n"+                      "<tr><th> heading </th><th> heading2 </th></tr>\n"+                      "<tr><td> Cell 1 </td><td> Cell 2 </td></tr>\n"+                      "<tr><td> Cell 3 </td><td> Cell 4</td></tr>\n"+                      "</table>\n<p></p>\n",                      translate(src) );    }    public void testTable2()        throws Exception    {        String src="||heading||heading2\n|Cell 1| Cell 2\n| Cell 3 |Cell 4\n\n";        assertEquals( "<table class=\"wikitable\" border=\"1\">\n"+                      "<tr><th>heading</th><th>heading2</th></tr>\n"+                      "<tr><td>Cell 1</td><td> Cell 2</td></tr>\n"+                      "<tr><td> Cell 3 </td><td>Cell 4</td></tr>\n"+                      "</table>\n<p></p>\n",                      translate(src) );    }    public void testTable3()        throws Exception    {        String src="|Cell 1| Cell 2\n| Cell 3 |Cell 4\n\n";        assertEquals( "<table class=\"wikitable\" border=\"1\">\n"+                      "<tr><td>Cell 1</td><td> Cell 2</td></tr>\n"+                      "<tr><td> Cell 3 </td><td>Cell 4</td></tr>\n"+                      "</table>\n<p></p>\n",                      translate(src) );    }    public void testTableLink()        throws Exception    {        String src="|Cell 1| Cell 2\n|[Cell 3|ReallyALink]|Cell 4\n\n";        newPage("ReallyALink");        assertEquals( "<table class=\"wikitable\" border=\"1\">\n"+                      "<tr><td>Cell 1</td><td> Cell 2</td></tr>\n"+                      "<tr><td><a class=\"wikipage\" href=\"Wiki.jsp?page=ReallyALink\">Cell 3</a></td><td>Cell 4</td></tr>\n"+                      "</table>\n<p></p>\n",                      translate(src) );    }    public void testTableLinkEscapedBar()        throws Exception    {        String src="|Cell 1| Cell~| 2\n|[Cell 3|ReallyALink]|Cell 4\n\n";        newPage("ReallyALink");        assertEquals( "<table class=\"wikitable\" border=\"1\">\n"+                      "<tr><td>Cell 1</td><td> Cell| 2</td></tr>\n"+                      "<tr><td><a class=\"wikipage\" href=\"Wiki.jsp?page=ReallyALink\">Cell 3</a></td><td>Cell 4</td></tr>\n"+                      "</table>\n<p></p>\n",                      translate(src) );    }    public void testDescription()        throws Exception    {        String src=";:Foo";        assertEquals( "<dl>\n<dt></dt><dd>Foo</dd>\n</dl>",                      translate(src) );    }    public void testDescription2()        throws Exception    {        String src=";Bar:Foo";        assertEquals( "<dl>\n<dt>Bar</dt><dd>Foo</dd>\n</dl>",                      translate(src) );    }    public void testDescription3()        throws Exception    {        String src=";:";        assertEquals( "<dl>\n<dt></dt><dd></dd>\n</dl>",                      translate(src) );    }    public void testDescription4()        throws Exception    {        String src=";Bar:Foo :-)";        assertEquals( "<dl>\n<dt>Bar</dt><dd>Foo :-)</dd>\n</dl>",                      translate(src) );    }    public void testRuler()        throws Exception    {        String src="----";        assertEquals( "<hr />",                      translate(src) );    }    public void testRulerCombo()        throws Exception    {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -