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

📄 jspwikimarkupparsertest.java

📁 jspwiki source code,jspwiki source code
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
        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\">"+                      "<tr class=\"odd\"><th> heading </th><th> heading2 </th></tr>\n"+                      "<tr><td> Cell 1 </td><td> Cell 2 </td></tr>\n"+                      "<tr class=\"odd\"><td> Cell 3 </td><td> Cell 4</td></tr>\n"+                      "</table><p />",                      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\">"+                      "<tr class=\"odd\"><th>heading</th><th>heading2</th></tr>\n"+                      "<tr><td>Cell 1</td><td> Cell 2</td></tr>\n"+                      "<tr class=\"odd\"><td> Cell 3 </td><td>Cell 4</td></tr>\n"+                      "</table><p />",                      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\">"+                      "<tr class=\"odd\"><td>Cell 1</td><td> Cell 2</td></tr>\n"+                      "<tr><td> Cell 3 </td><td>Cell 4</td></tr>\n"+                      "</table><p />",                      translate(src) );    }    public void testTable4()    throws Exception    {        String src="|a\nbc";        assertEquals( "<table class=\"wikitable\" border=\"1\">"+                      "<tr class=\"odd\"><td>a</td></tr>\n"+                      "</table>"+                      "bc",                      translate(src) );    }    /**     * Tests BugTableHeaderNotXHMTLCompliant     * @throws Exception     */    public void testTable5()    throws Exception    {        String src="Testtable\n||header|cell\n\n|cell||header";        assertEquals( "<p>Testtable\n</p>"+                      "<table class=\"wikitable\" border=\"1\">"+                      "<tr class=\"odd\"><th>header</th><td>cell</td></tr>\n</table><p />\n"+                      "<table class=\"wikitable\" border=\"1\">"+                      "<tr class=\"odd\"><td>cell</td><th>header</th></tr>"+                      "</table>",                      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\">"+                      "<tr class=\"odd\"><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><p />",                      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\">"+                      "<tr class=\"odd\"><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><p />",                      translate(src) );    }    public void testDescription()    throws Exception    {        String src=";:Foo";        assertEquals( "<dl><dt></dt><dd>Foo</dd></dl>",                      translate(src) );    }    public void testDescription2()    throws Exception    {        String src=";Bar:Foo";        assertEquals( "<dl><dt>Bar</dt><dd>Foo</dd></dl>",                      translate(src) );    }    public void testDescription3()    throws Exception    {        String src=";:";        assertEquals( "<dl><dt></dt><dd /></dl>",                      translate(src) );    }    public void testDescription4()    throws Exception    {        String src=";Bar:Foo :-)";        assertEquals( "<dl><dt>Bar</dt><dd>Foo :-)</dd></dl>",                      translate(src) );    }    public void testDescription5()    throws Exception    {        String src=";Bar:Foo :-) ;-) :*]";        assertEquals( "<dl><dt>Bar</dt><dd>Foo :-) ;-) :*]</dd></dl>",                      translate(src) );    }    public void testRuler()    throws Exception    {        String src="----";        assertEquals( "<hr />",                      translate(src) );    }    public void testRulerCombo()    throws Exception    {        String src="----Foo";        assertEquals( "<hr />Foo",                      translate(src) );    }    public void testRulerCombo2()    throws Exception    {        String src="Bar----Foo";        assertEquals( "Bar----Foo",                      translate(src) );    }    public void testShortRuler1()    throws Exception    {        String src="-";        assertEquals( "-",                      translate(src) );    }    public void testShortRuler2()    throws Exception    {        String src="--";        assertEquals( "--",                      translate(src) );    }    public void testShortRuler3()    throws Exception    {        String src="---";        assertEquals( "---",                      translate(src) );    }    public void testLongRuler()    throws Exception    {        String src="------";        assertEquals( "<hr />",                      translate(src) );    }    public void testHeading1()    throws Exception    {        String src="!Hello\nThis is a test";        assertEquals( "<h4 id=\"section-testpage-Hello\">Hello<a class=\"hashlink\" href=\"#section-testpage-Hello\">#</a></h4>\nThis is a test",                      translate(src) );    }    public void testHeading2()    throws Exception    {        String src="!!Hello, testing 1, 2, 3";        assertEquals( "<h3 id=\"section-testpage-HelloTesting123\">Hello, testing 1, 2, 3<a class=\"hashlink\" href=\"#section-testpage-HelloTesting123\">#</a></h3>",                      translate(src) );    }    public void testHeading3()    throws Exception    {        String src="!!!Hello there, how are you doing?";        assertEquals( "<h2 id=\"section-testpage-HelloThereHowAreYouDoing\">Hello there, how are you doing?<a class=\"hashlink\" href=\"#section-testpage-HelloThereHowAreYouDoing\">#</a></h2>",                      translate(src) );    }    public void testHeadingHyperlinks()    throws Exception    {        String src="!!![Hello]";        assertEquals( "<h2 id=\"section-testpage-Hello\"><a class=\"createpage\" href=\"/Edit.jsp?page=Hello\" title=\"Create &quot;Hello&quot;\">Hello</a><a class=\"hashlink\" href=\"#section-testpage-Hello\">#</a></h2>",                      translate(src) );    }    public void testHeadingHyperlinks2()    throws Exception    {        String src="!!![Hello|http://www.google.com/]";        assertEquals( "<h2 id=\"section-testpage-Hello\"><a class=\"external\" href=\"http://www.google.com/\">Hello</a><a class=\"hashlink\" href=\"#section-testpage-Hello\">#</a></h2>",                      translate(src) );    }    public void testHeadingHyperlinks3()    throws Exception    {        String src="![Hello|http://www.google.com/?p=a&c=d]";        assertEquals( "<h4 id=\"section-testpage-Hello\"><a class=\"external\" href=\"http://www.google.com/?p=a&amp;c=d\">Hello</a><a class=\"hashlink\" href=\"#section-testpage-Hello\">#</a></h4>",                      translate(src) );    }    /**     *  in 2.0.0, this one throws OutofMemoryError.     */    public void testBrokenPageText()    throws Exception    {        String translation = translate( brokenPageText );        assertNotNull( translation );    }    /**     *  Shortened version of the previous one.     */    public void testBrokenPageTextShort()    throws Exception    {        String src = "{{{\ncode.}}\n";        assertEquals( "<pre>\ncode.}}\n</pre>", translate(src) );    }    /**     *  Shortened version of the previous one.     */    public void testBrokenPageTextShort2()    throws Exception    {        String src = "{{{\ncode.}\n";        assertEquals( "<pre>\ncode.}\n</pre>", translate(src) );    }    public void testExtraExclamation()        throws Exception    {        String src = "Hello!";        assertEquals( "Hello!", translate(src) );    }    /**     * Used by the ACL tests.     * @param array     * @param key     * @return     */    /*    private boolean inArray( Object[] array, Object key )    {        for( int i = 0; i < array.length; i++ )        {            if ( array[i].equals( key ) )            {                return true;            }        }        return false;    }    */    /**     * Used by the ACL tests.     * @param array     * @param key     * @return     */    /*    private boolean inGroup( Object[] array, Principal key )    {        for( int i = 0; i < array.length; i++ )        {            if (array[i] instanceof Group)            {                if (((Group)array[i]).isMember(key))                {                    return true;                }            }        }        return false;    }    */    /**     *  ACL tests.     */    /*     public void testSimpleACL1()     throws Exception     {     String src = "Foobar.[{ALLOW view JanneJalkanen}]";     WikiPage p = new WikiPage( PAGE_NAME );     String res = translate( p, src );     assertEquals("Page text", "Foobar.", res);     Acl acl = p.getAcl();     Principal prof = new WikiPrincipal("JanneJalkanen");     assertTrue( "has read", inArray( acl.findPrincipals( new PagePermission( PAGE_NAME, "view") ), prof ) );     assertFalse( "no edit", inArray( acl.findPrincipals( new PagePermission( PAGE_NAME, "edit") ), prof ) );     }     public void testSimpleACL2()     throws Exception     {     String src = "Foobar.[{ALLOW view JanneJalkanen}]\n"+     "[{ALLOW edit JanneJalkanen, SuloVilen}]";     WikiPage p = new WikiPage( PAGE_NAME );     String res = translate( p, src );     assertEquals("Page text", "Foobar.\n", res);     Acl acl = p.getAcl();     // ACL says Janne can read and edit      Principal prof = new WikiPrincipal("JanneJalkanen");      assertTrue( "read for JJ", inArray( acl.findPrincipals( new PagePermission( PAGE_NAME, "view") ), prof ) );      assertTrue( "edit for JJ", inArray( acl.findPrincipals( new PagePermission( PAGE_NAME, "edit") ), prof ) );      // ACL doesn't say Erik can read or edit       prof = new WikiPrincipal("ErikBunn");       assertFalse( "no read for BB", inArray( acl.findPrincipals( new PagePermission( PAGE_NAME, "view") ), prof ) );       assertFalse( "no edit for EB", inArray( acl.findPrincipals( new PagePermission( PAGE_NAME, "edit") ), prof ) );       // ACL says Sulo can edit, but doens't say he can read (though the AuthMgr will tell us it's implied)        prof = new WikiPrincipal("SuloVilen");        assertFalse( "read for SV", inArray( acl.findPrincipals( new PagePermission( PAGE_NAME, "view") ), prof ) );        assertTrue( "edit for SV", inArray( acl.findPrincipals( new PagePermission( PAGE_NAME, "edit") ), prof ) );        }        */    /*    private boolean containsGroup( List l, String name )    {        for( Iterator i = l.iterator(); i.hasNext(); )        {            String group = (String) i.next();            if( group.equals( name ) )                return true;        }        return false;    }    */    /**     *   Metadata tests     */    public void testSet1()    throws Exception    {        String src = "Foobar.[{SET name=foo}]";        WikiPage p = new WikiPage( testEngine, PAGE_NAME );        String res = translate( p, src );        assertEquals("Page text", "Foobar.", res);        assertEquals( "foo", p.getAttribute("name") );    }    public void testSet2()    throws Exception    {        String src = "Foobar.[{SET name = foo}]";        WikiPage p = new WikiPage( testEngine, PAGE_NAME );        String res = translate( p, src );        assertEquals("Page text", "Foobar.", res);        assertEquals( "foo", p.getAttribute("name") );    }    public void testSet3()    throws Exception    {        String src = "

⌨️ 快捷键说明

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