jspwiki-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ajaqu...@apache.org
Subject svn commit: r627271 [7/8] - in /incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki: ./ action/ attachment/ auth/ auth/acl/ auth/authorize/ auth/login/ auth/permissions/ auth/user/ dav/ diff/ filters/ htmltowiki/ parser/
Date Wed, 13 Feb 2008 06:24:06 GMT
Added: incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/htmltowiki/HtmlStringToWikiTranslatorTest.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/htmltowiki/HtmlStringToWikiTranslatorTest.java?rev=627271&view=auto
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/htmltowiki/HtmlStringToWikiTranslatorTest.java (added)
+++ incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/htmltowiki/HtmlStringToWikiTranslatorTest.java Tue Feb 12 22:24:02 2008
@@ -0,0 +1,389 @@
+package com.ecyrd.jspwiki.htmltowiki;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+/**
+ * JUnit test cases for Converting Html to Wiki Markup.
+ * 
+ * @author Sebastian Baltes (sbaltes@gmx.com)
+ */
+public class HtmlStringToWikiTranslatorTest extends TestCase
+{
+    HtmlStringToWikiTranslator html2wiki;
+
+    public static void main( String[] args )
+    {
+        junit.textui.TestRunner.run( HtmlStringToWikiTranslatorTest.class );
+    }
+
+    public HtmlStringToWikiTranslatorTest( String arg0 )
+    {
+        super( arg0 );
+    }
+
+    public void setUp()
+    {
+        html2wiki = new HtmlStringToWikiTranslator();
+    }
+    
+    public void testAnchor() throws Exception
+    {
+        assertEquals(
+                     "[startup.bat]",
+                     html2wiki
+                             .translate( " <a class=\"attachment\" href=\"attach?page=startup.bat\">startup.bat</a><a href=\"PageInfo.jsp?page=startup.bat\"><img src=\"images/attachment_small.png\" alt=\"(att)\" border=\"0\"></a>" ) );
+
+       assertEquals(
+                     "[http://www.startup.de]",
+                     html2wiki
+                             .translate( "<a class=\"external\" href=\"http://www.startup.de\">http://www.startup.de</a><img class=\"outlink\" src=\"images/out.png\" alt=\"\">" ) );
+
+       assertEquals( " [AbsolutelyTestNotExisting]\n\n", html2wiki
+                     .translate( "<table class=\"imageplugin\" align=\"left\" border=\"0\">\r\n" + "<tbody><tr><td><br>\r\n"
+                                 + "</td></tr>\r\n" + "</tbody></table>\r\n" + "\r\n" + " [AbsolutelyTestNotExisting]<p>\r\n"
+                                 + "<table class=\"imageplugin\" align=\"left\" border=\"0\">\r\n" + "\r\n" + "<tbody>\r\n"
+                                 + "</tbody></table>\r\n" + "\r\n" + "</p><p>\r\n" + "</p>" ) );
+
+       assertEquals( "[ThisPageDoesNotExist]", html2wiki
+                     .translate( "<a href=\"Edit.jsp?page=ThisPageDoesNotExist\">ThisPageDoesNotExist</a>" ) );
+
+       assertEquals( "[/JSPWiki/wysiwyg/FCKeditor/editor/images/smiley/msn/sad_smile.gif]", html2wiki
+                     .translate( "<img src=\"/JSPWiki/wysiwyg/FCKeditor/editor/images/smiley/msn/sad_smile.gif\" alt=\"\"/>" ) );
+
+       assertEquals( "[AugumentedWikiLinks|AugumentedWikiLinks|title='my \"custom\" title' target='_blank']", html2wiki
+                     .translate( "<a class=\"wikipage\" href=\"Wiki.jsp?page=AugumentedWikiLinks\" target=\"_blank\" title=\"my 'custom' title\">AugumentedWikiLinks</a>" ) );
+    }
+    
+    public void testTable() throws Exception
+    {
+        assertEquals( "a\n| erste\n", html2wiki
+                      .translate( "a <table border=\"1\"> <tbody><tr> <td> erste</td> </tr> </tbody> </table>" ) );
+
+        assertEquals(
+                     "|| Throalisches Jahr || Ereignis\n"
+                                                                                       + "| 100 v. TH | Elianer Messias übersetzt die tausendjährigen Bücher von Harrow.\n"
+                                                                                       + "| 50 v. TH | Gründung Nehr?eshams und der ewigen Bibliothek.\n",
+                     html2wiki
+                             .translate( "<table class=\"wikitable\" border=\"1\"><tbody><tr><th> Throalisches Jahr </th><th> Ereignis</th></tr>\n"
+                                         + "<tr><td> 100 v. TH</td><td> Elianer Messias übersetzt die tausendjährigen Bücher von Harrow.</td></tr>\n"
+                                         + "<tr><td> 50 v. TH</td><td> Gründung Nehr?eshams und der ewigen Bibliothek.</td></tr>\n"
+                                         + "</tbody></table>" ) );
+
+       assertEquals(
+                     "|| Throalisches Jahr || Ereignis\n"
+                                                                                       + "| 100 v. TH | Elianer Messias übersetzt die tausendjährigen Bücher von Harrow.\n"
+                                                                                       + "| 50 v. TH | Gründung Nehr?eshams und der ewigen Bibliothek.\n\u00A0",
+                     html2wiki
+                             .translate( "<table class=\"wikitable\" border=\"1\"><tbody><tr><th> Throalisches Jahr </th><th> Ereignis</th></tr>\n"
+                                    + "<tr><td> 100 v. TH</td><td> Elianer Messias übersetzt die tausendjährigen Bücher von Harrow.</td></tr>\n"
+                                    + "<tr><td> 50 v. TH</td><td> Gründung Nehr?eshams und der ewigen Bibliothek.</td></tr>\n"
+                                    + "</tbody></table> &nbsp;" ) );
+
+       assertEquals(
+                    "| 3. Rang | Name des Helden, den der Bogen töten sollte.\n"
+                                                                                      + "| Fähigkeit | Bonus auf die Initiative von 1\n",
+                    html2wiki
+                            .translate( "<table class=\"wikitable\" border=\"1\"><tbody><tr><td> 3. Rang</td><td> Name des Helden, den der Bogen töten sollte.</td></tr>\n"
+                                        + "<tr><td> Fähigkeit</td><td> Bonus auf die Initiative von 1</td></tr></tbody></table></p><p>" ) );
+
+       assertEquals(
+                    "| Name: [Christian|ChristianS] \\\\ Geschicklichkeit: 2 \\\\ Hang zu perversen Sexorgien. Jongliert mit Worten und Köpfen. \\\\ [Berian Nachtschleicher|Berian] \\\\ [XLerul] \\\\ [Effifot Erif|EffifotErif]\n",
+                    html2wiki
+                            .translate( "<table class=\"wikitable\" border=\"1\"><tbody><tr><td> Name: <a class=\"wikipage\" href=\"Wiki.jsp?page=ChristianS\">Christian</a> <br> Geschicklichkeit: 2 <br> Hang zu perversen Sexorgien. Jongliert mit Worten und Köpfen. <br> <a class=\"wikipage\" href=\"Wiki.jsp?page=Berian\">Berian Nachtschleicher</a> <br> <a class=\"wikipage\" href=\"Wiki.jsp?page=XLerul\">XLerul</a> <br> <a class=\"wikipage\" href=\"Wiki.jsp?page=EffifotErif\">Effifot Erif</a></td></tr> </tbody></table>" ) );
+
+        
+    }
+
+    public void testRulers() throws Exception
+    {
+        assertEquals( "a\n----\nb", html2wiki.translate( "a<hr/>b" ) );        
+        assertEquals( "by\n" + "----\n" + "Dies", html2wiki.translate( "by\n" + "<hr>\n" + "Dies" ) );
+
+    }
+    
+    public void testParagraphs() throws Exception
+    {
+        assertEquals( "a\nb\nc", html2wiki.translate( "a<p>b</p>c" ) );
+
+        assertEquals( "ab", html2wiki.translate( "a<p></p>b" ) );
+
+        assertEquals( "a\n\nb", html2wiki.translate( "a<p>\n</p>b" ) );        
+
+        assertEquals(
+                     "\n\\\\\n__Willkommen__ \\\\\n\\\\\nUnd niemand wird sie sehen \\\\\nEine Page ...\n\nAls Unterthema\n",
+                     html2wiki
+                             .translate( "<p><br />\n<strong>Willkommen</strong> <br />\n<br />\nUnd niemand wird sie sehen <br />\nEine Page ...</p>\n<p>Als Unterthema</p>" ) );
+
+        assertEquals( "\n\u00A0\n\nTop\n\nBottom\n\n\n", html2wiki.translate( "<p>&nbsp;</p><p>Top</p>\n<p></p>\n<p></p>\n<p>Bottom</p> <p> </p>" ) );
+    }
+    
+    public void testWhitespace() throws Exception
+    {
+        assertEquals( "", html2wiki.translate( "" ) );
+
+        assertEquals( "", html2wiki.translate( "   " ) );
+
+        assertEquals( "", html2wiki.translate( "<div>\n\n\n</div>" ) );        
+
+        assertEquals( "a ", html2wiki.translate( "a\n  \n\n \t\r\n" ) );
+    }
+
+    public void testLists() throws Exception
+    {
+        assertEquals( "\n* Punkt 1\n* Punkt 2\n", html2wiki.translate( "<ul><li>Punkt 1</li><li>Punkt 2</li></ul>" ) );
+
+        assertEquals( "\n# Punkt 1\n# Punkt 2\n", html2wiki.translate( "<ol><li>Punkt 1</li><li>Punkt 2</li></ol>" ) );
+
+        assertEquals( "\n# Punkt 1\n## Punkt 2\n\n", html2wiki.translate( "<ol><li>Punkt 1<ol><li>Punkt 2</li></ol></li></ol>" ) );
+
+        assertEquals( "\n* Punkt 1\n** Punkt 2\n\n", html2wiki.translate( "<ul><li>Punkt 1<ul><li>Punkt 2</li></ul></li></ul>" ) );
+
+        assertEquals( "\n* Punkt 1\n*# Punkt 2\n\n", html2wiki.translate( "<ul><li>Punkt 1<ol><li>Punkt 2</li></ol></li></ul>" ) );
+
+        assertEquals(
+                     "\n# list item 1\n# list item 2\n## list item 2.1\n##* list item 2.1.1\n##* list item 2.1.2\n## list item 2.2\n# list item 3\n## list item 3.1\n##* list item 3.1.1\n## list item 3.2\n# list item 4\n",
+                     html2wiki
+                             .translate( "<ol> <li>list item 1</li> <li>list item 2 <ol> <li>list item 2.1 <ul> <li>list item 2.1.1</li> <li>list item 2.1.2</li> </ul> </li> <li>list item 2.2</li> </ol> </li> <li>list item 3 <ol> <li>list item 3.1 <ul> <li>list item 3.1.1</li> </ul> </li> <li>list item 3.2</li> </ol> </li> <li>list item 4</li> </ol>" ) );
+
+        assertEquals(
+                     "\n* Diese Karte kann von jedem editiert und um neue Links erweitert werden. \\\\Klickt einfach unten neben der Karte auf {{{[edit]}}}\n",
+                     html2wiki
+                             .translate( "<ul><li> Diese Karte kann von jedem editiert und um neue Links erweitert werden.<br>Klickt einfach unten neben der Karte auf <span style=\"font-family: monospace; white-space: pre;\">[edit]</span></li></ul>" ) );
+
+       assertEquals(
+                     "\n* Diese Karte kann von jedem editiert und um neue Links erweitert werden. \\\\Klickt einfach unten neben der Karte auf {{{[edit]}}}\n",
+                     html2wiki
+                             .translate( "<ul><li> Diese Karte kann von jedem editiert und um neue Links erweitert werden.<br>Klickt einfach unten neben der Karte auf <span style=\"font-family: monospace; white-space: pre;\">[edit]</span></li></ul>" ) );
+
+
+    }
+    
+    public void testPre() throws Exception
+    {
+        
+        assertEquals( "\n{{{\nhallo\n}}}\n", html2wiki.translate( "<pre>hallo</pre>" ) );
+
+        assertEquals( "\n{{{\nHallo\nWelt!\n\n\n}}}\n", html2wiki.translate( "<pre>Hallo<br>Welt!<br><br></pre>" ) );
+
+        assertEquals( "\n{{{\n\n\n\n\nHallo\n\n\n\nWelt!\n\n\n\n\n}}}\n", html2wiki
+                .translate( "\n\n\n\n<pre>\n\n\n\nHallo\n\n\n\nWelt!\n\n\n\n</pre>\n\n\n\n" ) );
+
+        assertEquals( "\n{{{\n\n\n* Baltramon \n  lasdjfh\n\n\n}}}\n", html2wiki.translate( "<pre>\n\n* Baltramon \n  lasdjfh\n\n</pre>" ) );
+
+        /*
+        // The style "font-family: courier new" is no longer translated as monospace text, so this test case is no longer needed.
+        assertEquals( "Diese Karte{{{ kann }}} von", html2wiki
+                      .translate( "Diese Karte<span style=\"font-family: courier new,courier,mono;\"> kann </span> von" ) );
+        */
+
+        assertEquals(
+                     "Fahrt einfac{{{h mit\u00A0\u00A0 \n der \u00A0 Maus}}} drueber",
+                     html2wiki
+                             .translate( "Fahrt einfac<span style=\"font-family: monospace; white-space: pre;\">h mit&nbsp;&nbsp; <br> der &nbsp; Maus</span> drueber" ) );
+
+
+    }
+
+    public void testTT() throws Exception
+    {
+        assertEquals( "{{hallo}}", html2wiki.translate( "<tt>hallo</tt>" ) );
+
+        assertEquals( "{{hallo}}", html2wiki.translate( "<code>hallo</code>" ) );        
+    }
+    
+    public void testCenter() throws Exception
+    {
+        assertEquals( "\n%%( text-align: center; )\nHello \\\\\nWorld!\n%%\n", html2wiki
+                      .translate( "<div style=\"text-align: center;\">Hello<br>World!</div>" ) );
+
+              assertEquals( "__%%( text-align: center; display: block; )Hello \\\\World!%%__", html2wiki
+                      .translate( "<span style=\"font-weight: bold; text-align: center; display: block;\">Hello<br>World!</span>" ) );
+
+        
+    }
+
+    public void testImage() throws Exception
+    {
+        assertEquals(
+                     "[{Image src='Homunkulus/homunculus4.jpg' align='left'}]",
+                     html2wiki
+                             .translate( "<table class=\"imageplugin\" align=\"left\" border=\"0\"> <tbody><tr><td><img src=\"attach?page=Homunkulus%2Fhomunculus4.jpg\"></td></tr> </tbody></table>" ) );
+
+       assertEquals( "[{Image src=\'AbenteuerQuilpins/Quilpins.jpg\' align=\'left\'}]", html2wiki
+               .translate( "<table class=\"imageplugin\" align=\"left\" border=\"0\">\r\n"
+                           + "<tbody><tr><td><img src=\"attach?page=AbenteuerQuilpins%2FQuilpins.jpg\"></td></tr>\r\n</tbody>"
+                           + "</table>" ) );
+
+       assertEquals(
+                     "[{Image src=\'AbenteuerQuilpins/Quilpins.jpg\' caption=\'Testing Image\' style=\'font-size: 120%; color: green;\'}]",
+                     html2wiki
+                             .translate( "<table class=\"imageplugin\" style=\"font-size: 120%; color: green;\" border=\"0\">\r\n"
+                                         + "<caption align=\"bottom\">Testing Image</caption>\r\n"
+                                         + "<tbody><tr><td><img src=\"attach?page=AbenteuerQuilpins%2FQuilpins.jpg\"></td></tr>\r\n</tbody>"
+                                         + "</table>" ) );
+
+
+       assertEquals(
+                     "[{Image src=\'http://opi.yahoo.com/online?u=YahooUser1234&m=g&t=2\' link=\'http://edit.yahoo.com/config/send_webmesg?.target=YahooUser1234&.src=pg\'}]",
+                     html2wiki
+                             .translate( "<table class=\"imageplugin\" border=\"0\">\r\n"
+                                         + "<tbody><tr><td>"
+                                         + "<a href=\"http://edit.yahoo.com/config/send_webmesg?.target=YahooUser1234&amp;.src=pg\">"
+                                         + "<img src=\"http://opi.yahoo.com/online?u=YahooUser1234&amp;m=g&amp;t=2\">"
+                                         + "</a></td></tr>\r\n" + "</tbody>" + "</table>" ) );
+
+       assertEquals(
+                     "[{Image src=\'homunculus4.jpg\' align=\'left\' height=\'100px\' width=\'100px\' alt=\'alt text\' caption=\'caption text\' link=\'http://google.de\' border=\'1\'}]",
+                     html2wiki
+                             .translate( "<table class=\"imageplugin\" align=\"left\" border=\"0\"> \r\n"
+                                         + "  <caption align=\"bottom\">caption text</caption> \r\n"
+                                         + "  <tbody><tr><td>\r\n"
+                                         + "    <a href=\"http://google.de\"><img src=\"homunculus4.jpg\" alt=\"alt text\" border=\"1\" height=\"100px\" width=\"100px\">\r\n"
+                                         + "    </a></td></tr> \r\n" + "  </tbody>  \r\n" + "</table>" ) );
+
+       assertEquals(
+                     "[{Image src=\'http://opi.yahoo.com/online?u=YahooUser1234&m=g&t=2\' link=\'http://edit.yahoo.com/config/send_webmesg?.target=YahooUser1234&.src=pg\'}]",
+                     html2wiki
+                             .translate( "  <a href=\"http://edit.yahoo.com/config/send_webmesg?.target=YahooUser1234&amp;.src=pg\">\r\n"
+                                         + "  <img src=\"http://opi.yahoo.com/online?u=YahooUser1234&amp;m=g&amp;t=2\">\r\n"
+                                         + "  </a" ) );
+        
+    }
+    
+    public void testPlugin() throws Exception
+    {
+        assertEquals( "This is a private homepage done by\n" + "----\n"
+                      + "Dies ist eine private, nicht-kommerzielle Homepage von\n"
+                      + "[{Text2gif width=\'150\' height=\'100\' \n" + " \n" + "Sebastian L. Baltes \n" + "Lange Str. 53 \n"
+                      + "44137 Dortmund \n" + " \n" + "email: info@sorokan.de \n" + "}]\n", html2wiki
+                .translate( "This is a private homepage done by\n" + "<hr>\n"
+                            + "Dies ist eine private, nicht-kommerzielle Homepage von\n" + "<p>\n"
+                            + "[{Text2gif width=\'150\' height=\'100\'\n" + "<br> <br>Sebastian L. Baltes\n"
+                            + "<br>Lange Str. 53\n" + "<br>44137 Dortmund\n" + "<br> <br>email: info@sorokan.de\n" + "<br>}]\n"
+                            + "</p><p>" ) );
+        
+    }
+
+    public void testCSS() throws Exception
+    {
+        assertEquals( "%%( color: rgb(255, 0, 0); )Und niemand wird sie sehen%%, die", html2wiki
+                      .translate( "<span style=\"color: rgb(255, 0, 0);\">Und niemand wird sie sehen</span>, die" ) );
+
+        assertEquals( "\n%%information\nCSS class here\n%%\n\nFont %%( color: #ff9900; font-family: arial; font-size: large; )styling here.%% Some %%( background-color: #ffff00; )more here%%.\n", 
+                      html2wiki.translate( "<div class=\"information\">CSS class here</div>\n"
+                                  + "<p>Font <font face=\"Arial\" color=\"#ff9900\" size=\"5\">styling here.</font>"
+                                  + " Some <font style=\"background-color: #ffff00\">more here</font>.</p>" ) );
+        
+        assertEquals( "\n\n%%( text-align: center; )\nsome leading text %%strike line through this text%% some trailing text\n%%\n\n",
+                      html2wiki.translate( "<p align=\"center\">some leading text <strike>line through this text</strike> some trailing text</p>" ) );
+    }
+
+    public void testParsing() throws Exception
+    {
+        assertEquals( "Hello World!", html2wiki.translate( "Hello World!" ) );
+
+        assertEquals( "a", html2wiki.translate( "a" ) );
+
+
+        assertEquals( "a \\\\b", html2wiki.translate( "a<br/>b" ) );
+
+        assertEquals( "\\\\\\", html2wiki.translate( "\\\\\\" ) );
+
+        assertEquals( "[{Test\nHello World!}]", html2wiki.translate( "[{Test\\\\Hello World!}]" ) );
+
+        assertEquals( "{{{[{Test\\\\Hello World!}]}}}", html2wiki.translate( "{{{[{Test\\\\Hello World!}]}}}" ) );
+
+        assertEquals(
+                      "{{{[{Test\\\\Hello World!}]}}}{{{[{Test\\\\\\\\Hello World!}]}}}[{Test\n\nHello World!}][{Test\n\nHello World!}]",
+                      html2wiki
+                              .translate( "{{{[{Test\\\\Hello World!}]}}}{{{[{Test\\\\\\\\Hello World!}]}}}[{Test\\\\\\\\Hello World!}][{Test\\\\\\\\Hello World!}]" ) );
+
+    }
+
+    public void testBoldAndItalic()
+        throws Exception
+    {
+        assertEquals(
+                     "Dies ist __bold__, ''italic'' und __''both''__.",
+                     html2wiki.translate( "Dies ist <span style=\"font-weight: bold;\">bold</span>, <span style=\"font-style: italic;\">italic</span> und <span style=\"font-style: italic; font-weight: bold;\">both</span>." ) );
+
+        assertEquals(
+                     "Dies ist __bold__, ''italic'' und __''both''__ 2.",
+                     html2wiki.translate( "Dies ist <b>bold</b>, <i>italic</i> und <b><i>both</i></b> 2." ) );
+
+        assertEquals(
+                     "Dies ist __bold__, ''italic'' und __''both''__ 3.",
+                     html2wiki.translate( "Dies ist <strong>bold</strong>, <em>italic</em> und <strong><em>both</em></strong> 3." ) );
+
+        assertEquals( "Wilma: ''Ich möchte hiermal in allerDeutlichkeit sagen! ''", html2wiki
+                      .translate( "Wilma: <i>Ich             möchte hier\nmal in aller\nDeutlichkeit sagen! </i>" ) );
+
+    }
+    
+    public void testHeading() throws Exception
+    {
+        assertEquals( "\n!!! Heading 1 should be translated to large heading.\n",
+                     html2wiki.translate( "<h1>Heading 1 should be translated to large heading.</h1>" ) );
+        
+        assertEquals( "\n!!! Heading 2 should be translated to large heading.\n",
+                      html2wiki.translate( "<h2>Heading 2 should be translated to large heading.</h2>" ) );
+        
+        assertEquals( "\n!! Heading 3 should be translated to medium heading.\n",
+                      html2wiki.translate( "<h3>Heading 3 should be translated to medium heading.</h3>" ) );
+        
+        assertEquals( "\n! Heading 4 should be translated to small heading.\n",
+                      html2wiki.translate( "<h4>Heading 4 should be translated to small heading.</h4>" ) );        
+    }
+    
+    public void testForm() throws Exception
+    {
+        assertEquals( "\n[{FormOpen form='myForm'}]\n\n[{FormClose}]\n",
+                      html2wiki.translate( "<div class=\"wikiform\">\n<form name=\"myForm\"><input name=\"formname\" value=\"myForm\" type=\"hidden\">\n</div>" ) );
+        
+        assertEquals( "[{FormInput type='hidden' name='myHiddenField' value='myHiddenField'}]myHiddenField",
+                      html2wiki.translate( "<input name=\"nbf_myHiddenField\" value=\"myHiddenField\" type=\"hidden\">myHiddenField" ) );
+        
+        assertEquals( "[{FormInput type='checkbox' name='myCheckbox' value='myCheckbox' checked='checked'}]myCheckbox",
+                      html2wiki.translate( "<input checked=\"checked\" value=\"myCheckbox\" name=\"nbf_myCheckbox\" type=\"checkbox\">myCheckbox" ) );
+        
+        assertEquals( "[{FormInput type='radio' name='myRadioButton' value='myRadioButton'}]myRadioButton",
+                      html2wiki.translate( "<input name=\"nbf_myRadioButton\" value=\"myRadioButton\" type=\"radio\">myRadioButton" ) );
+        
+        assertEquals( "[{FormInput type='button' name='myButton' value='myButton'}]myButton",
+                      html2wiki.translate( "<input name=\"nbf_myButton\" value=\"myButton\" type=\"button\">myButton" ) );
+
+        assertEquals( "[{FormTextarea name='myTextarea' rows='6' cols='50'}]myTextarea",
+                      html2wiki.translate( "<textarea cols=\"50\" name=\"nbf_myTextarea\" rows=\"6\"></textarea>myTextarea" ) );
+        
+        assertEquals( "[{FormSelect name='mySelectionList' value='apple;*orange;pear'}]mySelectList",
+                      html2wiki.translate( "<select name=\"nbf_mySelectionList\">\n"
+                                           + "<option value=\"apple\">apple</option>\n"
+                                           + "<option selected=\"selected\" value=\"orange\">orange</option>\n"
+                                           + "<option value=\"pear\">pear</option>\n"
+                                           + "</select>mySelectList" ) );
+        
+    }
+    
+    public void testDefinitionList() throws Exception
+    {
+        assertEquals( "\n;__Priority__:High\n\n;__TODO Name__:Initialization\n\n;__Requester__:John Smith\n",
+                      html2wiki.translate( "<dl><dt><b>Priority</b></dt><dd>High</dd></dl>\n"
+                                           + "<dl><dt><b>TODO Name</b></dt><dd>Initialization</dd></dl>\n"
+                                           + "<dl><dt><b>Requester</b></dt><dd>John Smith</dd></dl>\n" ) );
+        
+        assertEquals( "Some text here\n;:(A)indented comment here\n\n;:(B)another comment here\n",
+                      html2wiki.translate( "Some text here\n<dl><dt></dt><dd>(A)indented comment here</dd></dl>\n"
+                                           + "<dl><dt></dt><dd>(B)another comment here</dd></dl>\n" ) );
+
+        assertEquals( "\n;__New Page Name__:[{FormInput type='text' name='newPageName'}]\n",
+                      html2wiki.translate( "\n<dl><dt><b>New Page Name</b></dt><dd><input name=\"nbf_newPageName\" type=\"text\"></dd></dl>\n" ) );
+    }
+    
+    public static Test suite()
+    {
+        return new TestSuite( HtmlStringToWikiTranslatorTest.class );
+    }
+    
+}

Added: incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/parser/AllTests.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/parser/AllTests.java?rev=627271&view=auto
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/parser/AllTests.java (added)
+++ incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/parser/AllTests.java Tue Feb 12 22:24:02 2008
@@ -0,0 +1,27 @@
+/*
+ * (C) Janne Jalkanen 2005
+ * 
+ */
+package com.ecyrd.jspwiki.parser;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+public class AllTests extends TestCase
+{
+    public AllTests( String s )
+    {
+        super( s );
+    }
+
+    public static Test suite()
+    {
+        TestSuite suite = new TestSuite("Parser tests");
+
+        suite.addTest( JSPWikiMarkupParserTest.suite() );
+        suite.addTest( MarkupParserTest.suite() );
+        suite.addTest( CreoleToJSPWikiTranslatorTest.suite() );
+        return suite;
+    }
+}

Added: incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/parser/AndyTest.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/parser/AndyTest.java?rev=627271&view=auto
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/parser/AndyTest.java (added)
+++ incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/parser/AndyTest.java Tue Feb 12 22:24:02 2008
@@ -0,0 +1,269 @@
+package com.ecyrd.jspwiki.parser;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.IOException;
+import java.io.StringReader;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.Properties;
+import java.util.Vector;
+
+import javax.servlet.ServletException;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+import stress.Benchmark;
+
+import com.ecyrd.jspwiki.*;
+import com.ecyrd.jspwiki.attachment.Attachment;
+import com.ecyrd.jspwiki.providers.BasicAttachmentProvider;
+import com.ecyrd.jspwiki.render.XHTMLRenderer;
+
+public class AndyTest extends TestCase
+{
+    // 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";
+    static final String PAGE_NAME = "testpage";
+
+    public static void main( String[] argv )
+    {
+        if( argv.length > 0 )
+            junit.textui.TestRunner.run(suiteSingle(argv[0]));
+        else
+            junit.textui.TestRunner.run(suite());
+    }
+
+    public static Test suite()
+    {
+        return new TestSuite( AndyTest.class );
+    }
+
+
+    public static Test suiteSingle( String test )
+    {
+        return new TestSuite( AndyTest.class, test );
+    }
+
+    Properties props = new Properties();
+
+    Vector     created = new Vector();
+
+    TestEngine testEngine;
+
+    public AndyTest( String s )
+    {
+        super( s );
+    }
+
+    public void setUp()
+    throws Exception
+    {
+        props.load( TestEngine.findTestProperties() );
+
+        props.setProperty( "jspwiki.translatorReader.matchEnglishPlurals", "true" );
+        testEngine = new TestEngine( props );
+    }
+
+    public void tearDown()
+    {
+        deleteCreatedPages();
+    }
+
+
+    public void testAttachmentLink()
+    throws Exception
+    {
+        newPage("Test");
+
+        Attachment att = new Attachment( testEngine, "Test", "TestAtt.txt" );
+        att.setAuthor( "FirstPost" );
+        testEngine.getAttachmentManager().storeAttachment( att, testEngine.makeAttachmentFile() );
+
+        String src = "This should be an [attachment link|Test/TestAtt.txt]";
+
+        String dest =  translate(src);
+        
+        assertEquals( "This should be an <a class=\"attachment\" href=\"/attach/Test/TestAtt.txt\">attachment link</a>"+
+                      "<a href=\"/PageInfo.jsp?page=Test/TestAtt.txt\"><img src=\"/images/attachment_small.png\" border=\"0\" alt=\"(info)\" /></a>",
+                     dest );
+    }
+
+    public void testHyperlinks2()
+    throws Exception
+    {
+        newPage("Hyperlink");
+
+        String src = "This should be a [hyperlink]";
+
+        assertEquals( "This should be a <a class=\"wikipage\" href=\"/Wiki.jsp?page=Hyperlink\">hyperlink</a>",
+                      translate(src) );
+    }
+
+    private void deleteCreatedPages()
+    {
+        for( Iterator i = created.iterator(); i.hasNext(); )
+        {
+            String name = (String) i.next();
+
+            TestEngine.deleteTestPage(name);
+            testEngine.deleteAttachments(name);
+        }
+
+        created.clear();
+    }
+    
+    private void newPage( String name )
+        throws WikiException
+    {
+        testEngine.saveText( name, "<test>" );
+
+        created.addElement( name );
+    }
+
+    private String translate( String src )
+    throws IOException,
+            NoRequiredPropertyException,
+            ServletException
+    {
+        return translate( new WikiPage(testEngine, PAGE_NAME), src );
+    }
+
+    private String translate( WikiEngine e, String src )
+        throws IOException,
+               NoRequiredPropertyException,
+               ServletException
+    {
+        return translate( e, new WikiPage(testEngine, PAGE_NAME), src );
+    }
+
+    private String translate( WikiEngine e, WikiPage p, String src )
+        throws IOException,
+               NoRequiredPropertyException,
+               ServletException
+    {
+        WikiContext context = e.getWikiActionBeanFactory().newViewActionBean( p );
+        JSPWikiMarkupParser tr = new JSPWikiMarkupParser( context, 
+                                                          new BufferedReader( new StringReader(src)) );
+
+        XHTMLRenderer conv = new XHTMLRenderer( context, tr.parse() );
+
+        return conv.getString();
+    }
+
+    private String translate( WikiPage p, String src )
+        throws IOException,
+               NoRequiredPropertyException,
+               ServletException
+    {
+        return translate( testEngine, p, src );
+    }
+    private String translate_nofollow( String src )
+        throws IOException,
+               NoRequiredPropertyException,
+               ServletException,
+               WikiException
+    {
+        props.load( TestEngine.findTestProperties() );
+
+        props.setProperty( "jspwiki.translatorReader.useRelNofollow", "true" );
+        TestEngine testEngine2 = new TestEngine( props );
+
+        WikiContext context = testEngine2.getWikiActionBeanFactory().newViewActionBean(
+                                               new WikiPage(testEngine2, PAGE_NAME) );
+        JSPWikiMarkupParser r = new JSPWikiMarkupParser( context,
+                                                         new BufferedReader( new StringReader(src)) );
+
+        XHTMLRenderer conv = new XHTMLRenderer( context, r.parse() );
+
+        return conv.getString();
+    }
+}
+

Added: incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/parser/CreoleToJSPWikiTranslatorTest.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/parser/CreoleToJSPWikiTranslatorTest.java?rev=627271&view=auto
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/parser/CreoleToJSPWikiTranslatorTest.java (added)
+++ incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/parser/CreoleToJSPWikiTranslatorTest.java Tue Feb 12 22:24:02 2008
@@ -0,0 +1,827 @@
+package com.ecyrd.jspwiki.parser;
+
+import java.io.FileInputStream;
+import java.text.SimpleDateFormat;
+import java.util.Calendar;
+import java.util.Properties;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+public class CreoleToJSPWikiTranslatorTest extends TestCase
+{
+
+    public static final String TEST_PROPERTIES = "tests/com/ecyrd/jspwiki/parser/creole.properties";
+
+    public static void main(String[] args)
+    {
+        junit.textui.TestRunner.run(CreoleToJSPWikiTranslatorTest.class);
+    }
+
+    protected void setUp() throws Exception
+    {
+        super.setUp();
+    }
+
+    protected void tearDown() throws Exception
+    {
+        super.tearDown();
+    }
+
+    public void testBold() throws Exception
+    {
+        String src = "This is **bold**.";
+
+        assertEquals("This is __bold__.", translate(src));
+    }
+
+    public void testBoldVersusList() throws Exception
+    {
+        String src = "**This is all bold.**";
+
+        assertEquals("__This is all bold.__", translate(src));
+    }
+
+    public void testBoldAcrossLineBreaks() throws Exception
+    {
+        String src = "This is **bold\nand still bold**.";
+
+        assertEquals("This is __bold" + System.getProperty("line.separator") + "and still bold__.", translate(src));
+    }
+
+    public void testBoldAcrossLineParagraphs() throws Exception
+    {
+        String src = "This is **bold\r\n\r\nand no more bold.";
+
+        assertEquals("This is __bold__\r\n\r\nand no more bold.", translate(src));
+    }
+
+    public void testItalicAcrossLineBreaks() throws Exception
+    {
+        String src = "This is //italic\r\nand still italic//.";
+
+        assertEquals("This is ''italic\r\nand still italic''.", translate(src));
+    }
+
+    public void testItalicAcrossLineParagraphs() throws Exception
+    {
+        String src = "This is //italic\r\n\r\nnand no more italic.";
+
+        assertEquals("This is ''italic''\r\n\r\nnand no more italic.", translate(src));
+    }
+
+    public void testItalic() throws Exception
+    {
+        String src = "This is //italic//.";
+
+        assertEquals("This is ''italic''.", translate(src));
+    }
+
+    public void testImage() throws Exception
+    {
+        String src = "This is {{Image}}.";
+
+        assertEquals("This is [{Image src='Image'}].", translate(src));
+    }
+
+    public void testImageLink() throws Exception
+    {
+        String src = "This is [[http://www.wikicreole.org|{{Image}}]] with a link.";
+        assertEquals("This is [{Image src='Image' link='http://www.wikicreole.org'}] with a link.", translate(src));
+    }
+
+    public void testImageDescription() throws Exception
+    {
+        String src = "This is {{Image|Description}}.";
+        assertEquals("This is [{Image src='Image' caption='Description'}].", translate(src));
+    }
+
+    public void testImageLinkDescription() throws Exception
+    {
+        String src = "This is [[http://www.wikicreole.org|{{Image|Description}}]].";
+
+        assertEquals("This is [{Image src='Image' link='http://www.wikicreole.org' caption='Description'}].", translate(src));
+    }
+
+    public void testHyperlinks2() throws Exception
+    {
+        String src = "This should be a [[hyperlink]]";
+
+        assertEquals("This should be a [hyperlink]", translate(src));
+    }
+
+    public void testHyperlinks3() throws Exception
+    {
+        String src = "This should be a [[hyperlink too]]";
+
+        assertEquals("This should be a [hyperlink too]", translate(src));
+    }
+
+    public void testHyperlinks4() throws Exception
+    {
+        String src = "This should be a [[HyperLink]]";
+
+        assertEquals("This should be a [HyperLink]", translate(src));
+    }
+
+    public void testHyperlinks5() throws Exception
+    {
+        String src = "This should be a [[HyperLink|here]]";
+
+        assertEquals("This should be a [here|HyperLink]", translate(src));
+    }
+
+    public void testHyperlinksNamed1() throws Exception
+    {
+
+        String src = "This should be a [[HyperLink#heading|here]]";
+
+        assertEquals("This should be a [here|HyperLink#heading]", translate(src));
+    }
+
+    public void testHyperlinksNamed2() throws Exception
+    {
+        String src = "This should be a [[HyperLink#heading]]";
+
+        assertEquals("This should be a [HyperLink#heading]", translate(src));
+    }
+
+    //
+    // Testing CamelCase hyperlinks
+    //
+
+    public void testHyperLinks6() throws Exception
+    {
+
+        String src = "[[DiscussionAboutWiki]] [[WikiMarkupDevelopment]].";
+
+        assertEquals("[DiscussionAboutWiki] [WikiMarkupDevelopment].", translate(src));
+    }
+
+    /** ******* Stuff not in JSPWikiMarkupParserTest ************************* */
+    /* these are test where errors occured in the Creole Wiki */
+
+    public void testHeadingsCreole1() throws Exception
+    {
+        String src = "=====Level 4 heading";
+
+        assertEquals("__Level 4 heading__", translate(src));
+    }
+
+    public void testHyperLinksCreole1() throws Exception
+    {
+
+        String src = "Sponsored by the [Wiki Symposium|http://www.wikisym.org/] and [i3G Institute|http://www.i3g.hs-heilbronn.de].";
+
+        assertEquals(
+                     "Sponsored by the [Wiki Symposium|http://www.wikisym.org/] and [i3G Institute|http://www.i3g.hs-heilbronn.de].",
+                     translate(src));
+    }
+
+    public void testHyperLinksJSPWiki() throws Exception
+    {
+        String src = "* [http://www.wikisym.org/cgi-bin/mailman/listinfo/wiki-research|Wiki research mailing list]";
+        assertEquals(src, translate(src));
+    }
+
+    public void testHyperLinksCreole2() throws Exception
+    {
+
+        String src = "Sponsored by the [[http://www.wikisym.org/|Wiki Symposium]] and [[http://www.i3g.hs-heilbronn.de|i3G Institute]].";
+
+        assertEquals(
+                     "Sponsored by the [Wiki Symposium|http://www.wikisym.org/] and [i3G Institute|http://www.i3g.hs-heilbronn.de].",
+                     translate(src));
+    }
+
+    public void testPreformattedCreole() throws Exception
+    {
+        String src = "{{{$$...$$}}}";
+
+        assertEquals(src, translate(src));
+    }
+
+    public void testPreformattedCreole2() throws Exception
+    {
+        String src = "{{{\r\n" + "\r\n" + "[[http://en.wikipedia.org|wikipedia]]\r\n" + "}}}";
+        assertEquals(src, translate(src));
+    }
+
+    public void testPreformattedCreole3() throws Exception
+    {
+        String src = "{{{\r\n" + "Guitar Chord C:\r\n" + "\r\n" + "||---|---|---|\r\n" + "||-0-|---|---|\r\n"
+                     + "||---|-0-|---|\r\n" + "||---|---|-0-|\r\n" + "||---|---|---|\\n" + "}}}";
+
+        assertEquals(src, translate(src));
+    }
+
+    public void testPreformattedCreole4() throws Exception
+    {
+        // don't interpret plugins
+        String src = "{{{<<Test>>}}}";
+
+        assertEquals(src, translate(src));
+    }
+
+    public void testPreformattedCreole5() throws Exception
+    {
+        String src = "{{{<<<Test>>>}}}";
+
+        assertEquals(src, translate(src));
+    }
+
+    public void testPreformattedPlusLinks1() throws Exception
+    {
+        String preformatted = "{{{\r\n" + "Guitar Chord C:\r\n" + "\r\n" + "||---|---|---|\r\n" + "||-0-|---|---|\r\n"
+                              + "||---|-0-|---|\r\n" + "||---|---|-0-|\r\n" + "||---|---|---|\r\n" + "}}}";
+
+        String src = "[[http://www.wikicreole.org|external Links]]\r\n" + preformatted;
+
+        String target = "[external Links|http://www.wikicreole.org]\r\n" + preformatted;
+        assertEquals(target, translate(src));
+    }
+
+    public void testPreformattedPlusLinks2() throws Exception
+    {
+        String preformatted = "{{{\r\n" + "[[http://www.wikicreole.org]]\r\n" + "}}}";
+        String src = "[[http://www.wikicreole.org]]\r\n" + preformatted;
+
+        String target = "[http://www.wikicreole.org]\r\n" + preformatted;
+
+        assertEquals(target, translate(src));
+    }
+
+    public void testListCreole() throws Exception
+    {
+        String src = "- 1\r\n" + "-- 2\r\n" + "--- 3\r\n" + "---- 4\r\n" + "----- 5";
+        String target = "* 1\r\n" + "** 2\r\n" + "*** 3\r\n" + "**** 4\r\n" + "***** 5";
+
+        assertEquals(target, translate(src));
+    }
+
+    public void testLineAmbiguity() throws Exception
+    {
+        String src = "Some text\r\n\r\n----\r\n\r\nMore text";
+        assertEquals(src, translate(src));
+    }
+
+    public void testSignartureAmbiguity() throws Exception
+    {
+        String src = "Some **text**\r\n\r\n--Steff";
+        String target = "Some __text__\r\n\r\n--Steff";
+        assertEquals(target, translate(src));
+    }
+
+    public void disabledTestLinebreakCreole() throws Exception
+    {
+
+        String src = "My contact dates:\n" + "Pone: xyz\r\n" + "Fax: +45\n" + "Mobile: abc";
+
+        String target = "My contact dates:\\\\\n" + "Pone: xyz\\\\\r\n" + "Fax: +45\\\\\n" + "Mobile: abc";
+
+        assertEquals(target, translate(src));
+    }
+
+    public void disabledTestLinebreakCreoleShort() throws Exception
+    {
+
+        String src = "a\n" + "b\n" + "c\n";
+
+        String target = "a\\\\\n" + "b\\\\\n" + "c\n";
+
+        assertEquals(target, translate(src));
+    }
+
+    public void disabledTestLinebreakCreoleWithLists() throws Exception
+    {
+
+        String src = "*This\n" + "*Is\n" + "*a\n" + "*list";
+
+        assertEquals(src, translate(src));
+    }
+
+    public void testCSS() throws Exception
+    {
+
+        String src = "Some test\r\n" + "\r\n" + "%%commentbox\r\n" + "Aloha World!\r\n" + "%%\r\n" + "\r\n"
+                     + "Does the pagefilter mess up special jspwiki css markup?";
+
+        assertEquals(src, translate(src));
+    }
+
+    public void testSeparatorAfterHypenList() throws Exception
+    {
+
+        String src = "- 1\r\n" + "-- 1.1\r\n" + "-- 1.2\r\n" + "- 2\r\n" + "---------\r\n" + "test\r\n" + "Test";
+
+        String target = "* 1\r\n" + "** 1.1\r\n" + "** 1.2\r\n" + "* 2\r\n" + "---------\r\n" + "test\r\n" + "Test";
+
+        assertEquals(target, translate(src));
+    }
+
+    /**
+     * This might not work, users will have to resolve this ambiguity by hand...
+     *
+     * @throws Exception
+     */
+    public void testBulletListBoldAmbiguity() throws Exception
+    {
+
+        String src = "* 1\r\n" + "** 1.1\r\n" + "** 1.2\r\n" + "* 2\r\n" + "---------\r\n" + "test";
+        assertEquals(src, translate(src));
+    }
+
+    public void testEscapeHypens() throws Exception
+    {
+
+        String src = " 1\\\\\r\n" + "~- 3\\\\\r\n" + "~===\\\\\r\n" + "~- 2\\\\";
+
+        String target = " 1\\\\\r\n" + "~- 3\\\\\r\n" + "~===\\\\\r\n" + "~- 2\\\\";
+
+        assertEquals(target, translate(src));
+    }
+
+    public void testEscapeNowiki() throws Exception
+    {
+
+        String src = "{{{\r\n" + "{{{\r\n" + "{{Image}}\r\n" + "~}}}\r\n" + "}}}\r\n" + "Test";
+
+        String target = "{{{\r\n" + "{{{\r\n" + "{{Image}}\r\n" + "~}}}\r\n" + "}}}\r\n" + "Test";
+
+        assertEquals(target, translate(src));
+    }
+
+    public void testTables1() throws Exception
+    {
+
+        String src = "|a|b\r\n" + "|c|d";
+
+        assertEquals(src, translate(src));
+    }
+
+    public void testTables2() throws Exception
+    {
+
+        String src = "|a|b|\r\n" + "|c|d|";
+
+        String target = "|a|b\r\n" + "|c|d";
+
+        assertEquals(target, translate(src));
+    }
+
+    public void testTables3() throws Exception
+    {
+
+        String src = "before\r\n" + "|a|b|   \r\n" + "|c|d|\r\n" + "after";
+
+        String target = "before\r\n" + "|a|b\r\n" + "|c|d\r\n" + "after";
+
+        assertEquals(target, translate(src));
+    }
+
+    public void testTables4() throws Exception
+    {
+
+        String src = "before\r\n" + "|a\\\\b|b|\r\n" + "|c|d|\r\n" + "after";
+
+        String target = "before\r\n" + "|a\\\\b|b\r\n" + "|c|d\r\n" + "after";
+
+        assertEquals(target, translate(src));
+    }
+    
+    public void testTables5() throws Exception
+    {
+
+        // does a empty line between two tables get lost?
+        String src = "|a|b|\r\n" + "\r\n" +  "|x|y|\r\nTest";
+
+        String target = "|a|b\r\n" + "\r\n" +  "|x|y\r\nTest";
+
+        assertEquals(target, translate(src));
+    }
+
+    public void testTableHeaders1() throws Exception
+    {
+
+        String src = "|=a|=b|\r\n" + "|c|d|";
+
+        String target = "||a||b\r\n" + "|c|d";
+        assertEquals(target, translate(src));
+    }
+
+    public void testTableHeaders2() throws Exception
+    {
+
+        String src = "|=a=|=b=|\r\n" + "|c|d|";
+
+        String target = "||a||b\r\n" + "|c|d";
+
+        assertEquals(target, translate(src));
+    }
+
+    public void testTableHeaders3() throws Exception
+    {
+
+        String src = "||a||b\r\n" + "|c|d";
+
+        assertEquals(src, translate(src));
+    }
+
+    public void testExtensions1() throws Exception
+    {
+
+        String src = "<<ImagePlugin src='abc'>>";
+
+        String target = "[{ImagePlugin src='abc'}]";
+
+        assertEquals(target, translate(src));
+    }
+
+    public void testExtensions2() throws Exception
+    {
+
+        String src = "[{ImagePlugin src='abc'}]";
+
+        assertEquals(src, translate(src));
+    }
+
+    public void testExtensions3() throws Exception
+    {
+
+        String src = "<This is HTML>";
+
+        assertEquals(src, translate(src));
+    }
+
+    public void testExtensions4() throws Exception
+    {
+        String src = "<<FormOpen submit=\'http://www.jspwiki.org\' >>";
+
+        String target = "[{FormOpen submit=\'http://www.jspwiki.org\' }]";
+        
+        assertEquals(target, translate(src));
+    }
+
+    public void testExtensions5() 
+    {
+        
+        String src =
+            "<<Script\r\n" +
+            "\r\n" +
+            "//Comment\r\n" +
+            ">>\r\n" +
+            "\r\n" +
+            "[[http://www.xyz.com/]]\r\n";
+
+        String target = 
+            "[{Script\r\n" +
+            "\r\n" +
+            "//Comment\r\n" +
+            "}]\r\n" +
+            "\r\n" +
+            "[http://www.xyz.com/]";
+        
+        System.out.println(src);
+        System.out.println(translate(src));
+        
+        assertEquals(target, translate(src));
+    }
+    
+    public void testHeaderNotAtBeginning()
+    {
+        String src = "Hallo==Hallo";
+        assertEquals(src, translate(src));
+    }
+
+    public void testTableLink()
+    {
+        String src = "|=a=|=b=|\r\n" + "|[[c]]|d|";
+
+        String target = "||a||b\r\n" + "|[c]|d";
+
+        assertEquals(target, translate(src));
+    }
+
+    public void testTableImage()
+    {
+        String src = "|=a=|=b=|\r\n" + "|[[c]]|{{Image.png}}|";
+
+        String target = "||a||b\r\n" + "|[c]|[{Image src='Image.png'}]";
+
+        assertEquals(target, translate(src));
+    }
+
+    public void testHeaderAfterLinebreak()
+    {
+        String src = "Hallo das ist super\r\n===Und jetzt\r\nGehts weiter";
+
+        String target = "Hallo das ist super\r\n!!Und jetzt\r\nGehts weiter";
+
+        assertEquals(target, translate(src));
+    }
+
+    public void testBulletMixedEnum()
+    {
+        String src = "# Hallo\r\n" + "-- Hallo\r\n" + "--- Hallo\r\n" + "Hi";
+
+        String target = "# Hallo\r\n" + "** Hallo\r\n" + "*** Hallo\r\n" + "Hi";
+        assertEquals(target, translate(src));
+    }
+
+    public void testBulletMixedEnum2()
+    {
+        String src = "- Hallo\r\n" + "## Hallo\r\n" + "### Hallo\r\n" + "Hi";
+
+        String target = "* Hallo\r\n" + "## Hallo\r\n" + "### Hallo\r\n" + "Hi";
+        assertEquals(target, translate(src));
+    }
+
+    public void testBulletMixedEnum3()
+    {
+        String src = "#Headings\r\n" + "#Links (with optional title)\r\n" + "#Lists (like this one)\r\n"
+                     + "--including nested lists\r\n" + "#Tables\r\n" + "--caption\r\n" + "--headers\r\n" + "--summary\r\n"
+                     + "#Language information\r\n" + "#Acronyms and abbreviations\r\n" + "#Emphasis and strong emphasis\r\n"
+                     + "#Quotes, inline and block\r\n" + "#Images";
+
+        String target = "#Headings\r\n" + "#Links (with optional title)\r\n" + "#Lists (like this one)\r\n"
+                        + "**including nested lists\r\n" + "#Tables\r\n" + "**caption\r\n" + "**headers\r\n" + "**summary\r\n"
+                        + "#Language information\r\n" + "#Acronyms and abbreviations\r\n" + "#Emphasis and strong emphasis\r\n"
+                        + "#Quotes, inline and block\r\n" + "#Images";
+
+        assertEquals(target, translate(src));
+    }
+
+    public void testSignature()
+    {
+        String src = "Hallo\r\n--~~~";
+        String target = "Hallo\r\n-- [[Hanno]]";
+        Properties props = new Properties();
+        props.put("creole.dateFormat", "dd/MM/yyyy");
+        assertEquals(target, new CreoleToJSPWikiTranslator().translateSignature(props, src, "Hanno"));
+    }
+
+    public void testSignatureDate()
+    {
+        String src = "Hallo\r\n--~~~~";
+        Calendar cal = Calendar.getInstance();
+        String target = "Hallo\r\n-- [[Hanno]], " + (new SimpleDateFormat("dd/MM/yyyy")).format(cal.getTime());
+        Properties props = new Properties();
+        props.put("creole.dateFormat", "dd/MM/yyyy");
+        assertEquals(target, new CreoleToJSPWikiTranslator().translateSignature(props, src, "Hanno"));
+    }
+
+    public void testSignatureDate2()
+    {
+
+        String format = "\n   yyyy-MM-dd HH:mm   ";
+        String src = "Hallo\r\n--~~~~";
+        Calendar cal = Calendar.getInstance();
+        String target = "Hallo\r\n-- [[Hanno]], " + (new SimpleDateFormat(format)).format(cal.getTime());
+        Properties props = new Properties();
+        props.put("creole.dateFormat", format);
+        assertEquals(target, new CreoleToJSPWikiTranslator().translateSignature(props, src, "Hanno"));
+    }
+
+    public void testHeaderAtStart()
+    {
+        String src = "Hallo\r\n=Hallo\r\nHallo";
+        String target = "Hallo\r\n!!!Hallo\r\nHallo";
+        assertEquals(target, translate(src));
+    }
+
+    public void testSignatureSourceCode()
+    {
+        String format = "\n   yyyy-MM-dd HH:mm   ";
+        String src = "{{{Hallo\r\n" + "--~~~~\r\n" + "Hallo\r\n" + "}}}";
+        Properties props = new Properties();
+        props.put("creole.dateFormat", format);
+        assertEquals(src, new CreoleToJSPWikiTranslator().translateSignature(props, src, "Hanno"));
+    }
+
+    public void testTilde()
+    {
+        String src = "==Willkommen zum WikiWizardScript\r\n" + "~~ sdfsdf\r\n" + "\r\n" + "now what happens?\r\n" + "\r\n"
+                     + "- nothing I hope\r\n" + "- maybe something\r\n" + "- we will soon see!\r\n" + "\r\n"
+                     + "== and this is a big title =================\r\n" + "\r\n" + "What can we put here?\r\n" + "\r\n"
+                     + "{{Web2.png}}";
+        String target = "!!!Willkommen zum WikiWizardScript\r\n" + "~~ sdfsdf\r\n" + "\r\nnow what happens?\r\n"
+                        + "\r\n* nothing I hope\r\n" + "* maybe something\r\n" + "* we will soon see!\r\n"
+                        + "\r\n!!! and this is a big title ===============\r\n" + "\r\nWhat can we put here?\r\n"
+                        + "\r\n[{Image src='Web2.png'}]";
+        assertEquals(target, translate(src));
+    }
+
+    public void testWWWToHTTP()
+    {
+        String src = "Hallo\r\nHallo[[ 	www.gmx.de]]Hallo\r\nHallo";
+        String target = "Hallo\r\nHallo[http://www.gmx.de]Hallo\r\nHallo";
+        assertEquals(target, translate(src));
+
+        String src2 = "Hallo\r\nHallo[[www.gmx.de]]Hallo\r\nHallo";
+        String target2 = "Hallo\r\nHallo[http://www.gmx.de]Hallo\r\nHallo";
+        assertEquals(target2, translate(src2));
+
+        String src3 = "Hallo\r\nHallo[[www.gmx.de|GMX]]Hallo\r\nHallo";
+        String target3 = "Hallo\r\nHallo[GMX|http://www.gmx.de]Hallo\r\nHallo";
+        assertEquals(target3, translate(src3));
+    }
+
+    public void testImageX()
+    {
+        String src = "Hallo {{Image.png|Caption|M,NB}}";
+        String target = "Hallo [{ImageX src='Image.png' caption='Caption' width='250' border=0}]";
+        Properties props = new Properties();
+        props.put("creole.imagePlugin.para.M", "width='250'");
+        props.put("creole.imagePlugin.para.NB", "border=0");
+        props.put("creole.imagePlugin.name", "ImageX");
+
+        assertEquals(target, new CreoleToJSPWikiTranslator().translate(props, src));
+    }
+
+    public void testImageX11()
+    {
+        String src = "Hallo {{Image.png|Caption|250}}";
+        String target = "Hallo [{ImageX src='Image.png' caption='Caption' width='250px'}]";
+        Properties props = new Properties();
+        props.put("creole.imagePlugin.name", "ImageX");
+
+        assertEquals(target, new CreoleToJSPWikiTranslator().translate(props, src));
+    }
+
+    public void testImageX2()
+    {
+        String src = "Hallo {{Image.png|Caption}}";
+        String target = "Hallo [{ImageX src='Image.png' caption='Caption' }]";
+        Properties props = new Properties();
+        props.put("creole.imagePlugin.name", "ImageX");
+
+        assertEquals(target, new CreoleToJSPWikiTranslator().translate(props, src));
+    }
+
+    public void testImageX3()
+    {
+        String src = "Hallo {{Image.png|Caption|M,NB,TEST}}";
+        String target = "Hallo [{ImageX src='Image.png' caption='Caption' width='250' border=0}]";
+        Properties props = new Properties();
+        props.put("creole.imagePlugin.para.M", "width='250'");
+        props.put("creole.imagePlugin.para.NB", "border=0");
+        props.put("creole.imagePlugin.name", "ImageX");
+
+        assertEquals(target, new CreoleToJSPWikiTranslator().translate(props, src));
+    }
+
+    public void testImageX4()
+    {
+        String src = "Hallo {{Image.png||M,NB,TEST}}";
+        String target = "Hallo [{ImageX src='Image.png' width='250' border=0}]";
+        Properties props = new Properties();
+        props.put("creole.imagePlugin.para.M", "width='250'");
+        props.put("creole.imagePlugin.para.NB", "border=0");
+        props.put("creole.imagePlugin.name", "ImageX");
+
+        assertEquals(target, new CreoleToJSPWikiTranslator().translate(props, src));
+    }
+
+    public void testImageX5()
+    {
+        String src = "Hallo [[http://www.google.de|{{Image.png||M,NB,TEST}}]]";
+        String target = "Hallo [{ImageX src='Image.png' link='http://www.google.de' width='250' border=0}]";
+        Properties props = new Properties();
+        props.put("creole.imagePlugin.para.M", "width='250'");
+        props.put("creole.imagePlugin.para.NB", "border=0");
+        props.put("creole.imagePlugin.name", "ImageX");
+
+        assertEquals(target, new CreoleToJSPWikiTranslator().translate(props, src));
+    }
+
+    public void testImageX6() throws Exception
+    {
+        Properties props = new Properties();
+        props.load(new FileInputStream(TEST_PROPERTIES));
+        String src = "Hallo {{Image.png|Caption|M,[-]}}";
+        String target = "Hallo [{ImageX src='Image.png' caption='Caption' width='180' border=false}]";
+        assertEquals(target, new CreoleToJSPWikiTranslator().translate(props, src));
+    }
+
+    public void testImageX7() throws Exception
+    {
+        Properties props = new Properties();
+        props.load(new FileInputStream(TEST_PROPERTIES));
+        String src = "Hallo [[http://www.gmx.de|{{Image.png||XL,+X,[-]}}]]";
+        String target = "Hallo [{ImageX src='Image.png' link='http://www.gmx.de' width='540' float='right' border=false}]";
+        assertEquals(target, new CreoleToJSPWikiTranslator().translate(props, src));
+    }
+
+    public void testImageX8() throws Exception
+    {
+        Properties props = new Properties();
+        props.load(new FileInputStream(TEST_PROPERTIES));
+        String src = "Hallo [[http://www.gmx.de|{{Image.png||XL,+X,X-,[-]}}]]";
+        String target = "Hallo [{ImageX src='Image.png' link='http://www.gmx.de' width='540' float='right' align='left' border=false}]";
+        assertEquals(target, new CreoleToJSPWikiTranslator().translate(props, src));
+    }
+
+    public void testImageX9() throws Exception
+    {
+        Properties props = new Properties();
+        props.load(new FileInputStream(TEST_PROPERTIES));
+        String src = "Hallo [[http://www.gmx.de|{{Image.png|Caption|XL,+X,X-,[-]}}]]";
+        String target = "Hallo [{ImageX src='Image.png' link='http://www.gmx.de' caption='Caption' width='540' float='right' align='left' border=false}]";
+        assertEquals(target, new CreoleToJSPWikiTranslator().translate(props, src));
+    }
+
+    public void testImageX10() throws Exception
+    {
+        Properties props = new Properties();
+        props.load(new FileInputStream(TEST_PROPERTIES));
+        String src = "Hallo [[http://www.gmx.de|{{Image.png|Caption|xL, +X , X-, [-]}}]]";
+        String target = "Hallo [{ImageX src='Image.png' link='http://www.gmx.de' caption='Caption' width='540' float='right' align='left' border=false}]";
+        assertEquals(target, new CreoleToJSPWikiTranslator().translate(props, src));
+    }
+
+    public void testImageX12()
+    {
+        String src = "Hallo [[http://www.google.de|{{Image.png||120px}}]]\r\n[[http://www.google.de|{{Image.png||120cm}}]]";
+        String target = "Hallo [{ImageX src='Image.png' link='http://www.google.de' width='120'}]\r\n"
+                        + "[{ImageX src='Image.png' link='http://www.google.de' widthInCM='120'}]";
+        ;
+        Properties props = new Properties();
+        props.put("creole.imagePlugin.para.%px", "width='%'");
+        props.put("creole.imagePlugin.para.%cm", "widthInCM='%'");
+        props.put("creole.imagePlugin.name", "ImageX");
+
+        assertEquals(target, new CreoleToJSPWikiTranslator().translate(props, src));
+    }
+
+    public void testJuwi()
+    {
+        String src = "<<JudoScript\r\n" + "if this works then ok\r\n" + "else improve the programm\r\n" + ">>";
+        String target = "[{JudoScript\r\n" + "if this works then ok\r\n" + "else improve the programm\r\n" + "}]";
+        assertEquals(target, translate(src));
+    }
+
+    public void testPluginBold()
+    {
+
+        String src = "**<<CurrentTimePlugin format='HH:mm \'am\' dd-MMM-yyyy'>>**";
+        String tar = "__[{CurrentTimePlugin format='HH:mm \'am\' dd-MMM-yyyy'}]__";
+
+        assertEquals(tar, translate(src));
+    }
+
+    public void testPluginLinebreakPlugin()
+    {
+
+        String src = "<<CurrentTimePlugin format=zzzz>>\r\n" + "\r\n" + "<<RecentChangesPlugin since='30'>>";
+
+        String tar = "[{CurrentTimePlugin format=zzzz}]\r\n" + "\r\n" + "[{RecentChangesPlugin since='30'}]";
+
+        assertEquals(tar, translate(src));
+    }
+
+    public void testJuwi2()
+    {
+        String src = "<<JudoScript\r\n" + "if [[this]] works then ok\r\n" + "else improve the programm\r\n" + ">>";
+        String target = "[{JudoScript\r\n" + "if [[this]] works then ok\r\n" + "else improve the programm\r\n" + "}]";
+        assertEquals(target, translate(src));
+
+    }
+
+    public void testURL()
+    {
+        String src = "Hallo[[https://wiki.i3g.hs-heilbronn.de]]Hallo";
+        String target = "Hallo[https://wiki.i3g.hs-heilbronn.de]Hallo";
+
+        assertEquals(target, translate(src));
+    }
+
+    public void testSourcePlugin()
+    {
+        String src = "Hallo<<Hallo{{{Test}}}Hallo>>Hallo";
+        String target = "Hallo[{Hallo{{{Test}}}Hallo}]Hallo";
+
+        assertEquals(target, translate(src));
+    }
+
+    public void testMultilinePlugin3()
+    {
+        String src = "Hallo\r\n" + "<<Hallo\r\n" + "Hallo\r\n" + "Hallo\r\n" + ">>";
+
+        String target = "Hallo\r\n" + "[{Hallo\r\n" + "Hallo\r\n" + "Hallo\r\n" + "}]";
+
+        assertEquals(target, translate(src));
+    }
+
+    public String translate(String src)
+    {
+        CreoleToJSPWikiTranslator translator = new CreoleToJSPWikiTranslator();
+
+        return translator.translate(new Properties(), src);
+    }
+
+    public static Test suite()
+    {
+        return new TestSuite( JSPWikiMarkupParserTest.class );
+    }
+}



Mime
View raw message