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

📄 translatorreadertest.java

📁 wiki建站资源 java编写的 很好用
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
        String src="----Foo";        assertEquals( "<hr />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</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</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?</h2>",                      translate(src) );    }    public void testHeadingHyperlinks()        throws Exception    {        String src="!!![Hello]";        assertEquals( "<h2 id='section-testpage-Hello'><a class=\"editpage\" title=\"Create 'Hello'\" href=\"Edit.jsp?page=Hello\">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></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></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>\n", translate(src) );    }    /**     *  Shortened version of the previous one.     */    public void testBrokenPageTextShort2()        throws Exception    {        String src = "{{{\ncode.}\n";        assertEquals( "<pre>\ncode.}\n</pre>\n", translate(src) );    }    /**     *  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);        AccessControlList acl = p.getAcl();        UserProfile prof = new UserProfile();        prof.setName("JanneJalkanen");        assertTrue(  "no read", acl.checkPermission( prof, new ViewPermission() ) );        assertFalse( "has edit", acl.checkPermission( prof, new EditPermission() ) );    }    public void testSimpleACL2()        throws Exception    {        String src = "Foobar.[{ALLOW view JanneJalkanen}]\n"+                     "[{DENY view ErikBunn, SuloVilen}]\n"+                     "[{ALLOW edit JanneJalkanen, SuloVilen}]";        WikiPage p = new WikiPage( PAGE_NAME );        String res = translate( p, src );        assertEquals("Page text", "Foobar.\n\n", res);        AccessControlList acl = p.getAcl();        UserProfile prof = new UserProfile();        prof.setName("JanneJalkanen");        assertTrue( "no read for JJ", acl.checkPermission( prof, new ViewPermission() ) );        assertTrue( "no edit for JJ", acl.checkPermission( prof, new EditPermission() ) );        prof.setName("ErikBunn");        assertFalse(  "read for EB", acl.checkPermission( prof, new ViewPermission() ) );        assertFalse( "has edit for EB", acl.checkPermission( prof, new EditPermission() ) );        prof.setName("SuloVilen");        assertFalse("read for SV", acl.checkPermission( prof, new ViewPermission() ) );        assertTrue( "no edit for SV", acl.checkPermission( prof, new EditPermission() ) );    }*/    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( 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( PAGE_NAME );        String res = translate( p, src );        assertEquals("Page text", "Foobar.", res);        assertEquals( "foo", p.getAttribute("name") );    }    public void testSet3()        throws Exception    {        String src = "Foobar.[{SET name= Janne Jalkanen}]";        WikiPage p = new WikiPage( PAGE_NAME );        String res = translate( p, src );        assertEquals("Page text", "Foobar.", res);        assertEquals( "Janne Jalkanen", p.getAttribute("name") );    }    public void testSet4()        throws Exception    {        String src = "Foobar.[{SET name='Janne Jalkanen'}][{SET too='{$name}'}]";        WikiPage p = new WikiPage( PAGE_NAME );        String res = translate( p, src );        assertEquals("Page text", "Foobar.", res);        assertEquals( "Janne Jalkanen", p.getAttribute("name") );        assertEquals( "Janne Jalkanen", p.getAttribute("too") );    }    /**     *  Test collection of links.     */    public void testCollectingLinks()        throws Exception    {        LinkCollector coll = new LinkCollector();        String src = "[Test]";        WikiContext context = new WikiContext( testEngine,                                               new WikiPage(PAGE_NAME) );        TranslatorReader r = new TranslatorReader( context,                                                    new BufferedReader( new StringReader(src)) );        r.addLocalLinkHook( coll );        r.addExternalLinkHook( coll );        r.addAttachmentLinkHook( coll );        StringWriter out = new StringWriter();                FileUtil.copyContents( r, out );        Collection links = coll.getLinks();        assertEquals( "no links found", 1, links.size() );        assertEquals( "wrong link", "Test", links.iterator().next() );    }    public void testCollectingLinks2()        throws Exception    {        LinkCollector coll = new LinkCollector();        String src = "["+PAGE_NAME+"/Test.txt]";        WikiContext context = new WikiContext( testEngine,                                               new WikiPage(PAGE_NAME) );        TranslatorReader r = new TranslatorReader( context,                                                    new BufferedReader( new StringReader(src)) );        r.addLocalLinkHook( coll );        r.addExternalLinkHook( coll );        r.addAttachmentLinkHook( coll );        StringWriter out = new StringWriter();                FileUtil.copyContents( r, out );        Collection links = coll.getLinks();        assertEquals( "no links found", 1, links.size() );        assertEquals( "wrong link", PAGE_NAME+"/Test.txt",                       links.iterator().next() );    }    public void testCollectingLinksAttachment()        throws Exception    {        // First, make an attachment.        try        {            Attachment att = new Attachment( PAGE_NAME, "TestAtt.txt" );            att.setAuthor( "FirstPost" );            testEngine.getAttachmentManager().storeAttachment( att, testEngine.makeAttachmentFile() );            LinkCollector coll        = new LinkCollector();            LinkCollector coll_others = new LinkCollector();            String src = "[TestAtt.txt]";            WikiContext context = new WikiContext( testEngine,                                                   new WikiPage(PAGE_NAME) );            TranslatorReader r = new TranslatorReader( context,                                                        new BufferedReader( new StringReader(src)) );            r.addLocalLinkHook( coll_others );            r.addExternalLinkHook( coll_others );            r.addAttachmentLinkHook( coll );            StringWriter out = new StringWriter();                    FileUtil.copyContents( r, out );            Collection links = coll.getLinks();            assertEquals( "no links found", 1, links.size() );            assertEquals( "wrong link", PAGE_NAME+"/TestAtt.txt",                           links.iterator().next() );            assertEquals( "wrong links found", 0, coll_others.getLinks().size() );        }        finally        {            String files = testEngine.getWikiProperties().getProperty( BasicAttachmentProvider.PROP_STORAGEDIR );            File storagedir = new File( files, PAGE_NAME+BasicAttachmentProvider.DIR_EXTENSION );            if( storagedir.exists() && storagedir.isDirectory() )                TestEngine.deleteAll( storagedir );        }    }    public void testDivStyle1()        throws Exception    {        String src = "%%foo\ntest\n%%\n";                assertEquals( "<div class=\"foo\">\ntest\n</div>\n", translate(src) );    }    public void testDivStyle2()    throws Exception    {        String src = "%%(foo:bar;)\ntest\n%%\n";            assertEquals( "<div style=\"foo:bar;\">\ntest\n</div>\n", translate(src) );    }    public void testSpanStyle1()        throws Exception    {        String src = "%%foo test%%\n";            assertEquals( "<span class=\"foo\">test</span>\n", translate(src) );    }    public void testSpanStyle2()    throws Exception    {        String src = "%%(foo:bar;)test%%\n";                assertEquals( "<span style=\"foo:bar;\">test</span>\n", translate(src) );    }    public void testSpanStyle3()    throws Exception    {        String src = "Johan %%(foo:bar;)test%%\n";                assertEquals( "Johan <span style=\"foo:bar;\">test</span>\n", translate(src) );    }    public void testSpanNested()    throws Exception    {        String src = "Johan %%(color: rgb(1,2,3);)test%%\n";                assertEquals( "Johan <span style=\"color: rgb(1,2,3);\">test</span>\n", translate(src) );    }    public void testSpanStyleTable()    throws Exception    {        String src = "|%%(foo:bar;)test%%|no test\n";                assertEquals( "<table class=\"wikitable\" border=\"1\">\n<tr><td><span style=\"foo:bar;\">test</span></td><td>no test</td></tr>\n</table>\n",                       translate(src) );    }        // This is a random find: the following page text caused an eternal loop in V2.0.x.    private static final String brokenPageText =                 "Please ''check [RecentChanges].\n" +         "\n" +         "Testing. fewfwefe\n" +         "\n" +         "CHeck [testpage]\n" +         "\n" +         "More testing.\n" +         "dsadsadsa''\n" +         "Is this {{truetype}} or not?\n" +         "What about {{{This}}}?\n" +         "How about {{this?\n" +         "\n" +         "{{{\n" +         "{{text}}\n" +         "}}}\n" +         "goo\n" +         "\n" +         "<b>Not bold</b>\n" +         "\n" +         "motto\n" +         "\n" +         "* This is a list which we\n" +         "shall continue on a other line.\n" +         "* There is a list item here.\n" +         "*  Another item.\n" +         "* More stuff, which continues\n" +         "on a second line.  And on\n" +         "a third line as well.\n" +         "And a fourth line.\n" +         "* Third item.\n" +         "\n" +         "Foobar.\n" +         "\n" +         "----\n" +         "\n" +         "!!!Really big heading\n" +         "Text.\n" +         "!! Just a normal heading [with a hyperlink|Main]\n" +         "More text.\n" +         "!Just a small heading.\n" +         "\n" +         "This should be __bold__ text.\n" +         "\n" +         "__more bold text continuing\n" +         "on the next line.__\n" +         "\n" +         "__more bold text continuing\n" +         "\n" +         "on the next paragraph.__\n" +         "\n" +         "\n" +         "This should be normal.\n" +        "\n" +         "Now, let's try ''italic text''.\n" +         "\n" +         "Bulleted lists:\n" +         "* One\n" +         "Or more.\n" +         "* Two\n" +         "\n" +         "** Two.One\n" +         "\n" +         "*** Two.One.One\n" +         "\n" +         "* Three\n" +         "\n" +         "Numbered lists.\n" +         "# One\n" +         "# Two\n" +         "# Three\n" +         "## Three.One\n" +         "## Three.Two\n" +         "## Three.Three\n" +         "### Three.Three.One\n" +         "# Four\n" +         "\n" +        "End?\n" +         "\n" +         "No, let's {{break}} things.\\ {{{ {{{ {{text}} }}} }}}\n" +        "\n" +         "More breaking.\n" +         "\n" +        "{{{\n" +         "code.}}\n" +         "----\n" +        "author: [Asser], [Ebu], [JanneJalkanen], [Jarmo|mailto:jarmo@regex.com.au]\n";        public static Test suite()    {        return new TestSuite( TranslatorReaderTest.class );    }}

⌨️ 快捷键说明

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