CVS update: /cowiki/misc/development/tests/

[email protected] 29 May 2005 15:46:11 -0000
Newsgroups gmane.comp.php.cowiki.cvs
Message-ID <[email protected]>
User: cmarble 
Date: 2005/05/29 08:46:11

Modified:
   cowiki/misc/development/tests/RunTests.php
   cowiki/misc/development/tests/class.ParserTest.php

Log:
 The parser test now has 234 tests, fore and back (WikiParser & ReverseParser).
 
 It's supposedly quite robust now, and shouldn't eat your wiki. Please thrash it to breaking point and beyond. class.ParserTest.php is very large, but quite repetitive.
 
 To run tests, 
 
 #cd misc/development/tests
 #php RunTests.php
 
 The code should locate itself according to 'include_path' set in htdocs.
 
 Enjoy.
 

File Changes:

Directory: /cowiki/misc/development/tests/
==========================================

File [changed]: RunTests.php
Url: http://cowiki.tigris.org/source/browse/cowiki/misc/development/tests/RunTests.php?r1=1.2&r2=1.3
Delta lines:  +9 -4
-------------------
--- RunTests.php	8 May 2005 14:23:21 -0000	1.2
+++ RunTests.php	29 May 2005 15:46:09 -0000	1.3
@@ -1,7 +1,7 @@
 <?php
 /**
  *
- * $Id: RunTests.php,v 1.2 2005/05/08 14:23:21 cmarble Exp $
+ * $Id: RunTests.php,v 1.3 2005/05/29 15:46:09 cmarble Exp $
  *
  * This file is part of coWiki. coWiki is free software under the terms of
  * the GNU General Public License (GPL). Read the LICENSE file. If you did
@@ -16,7 +16,7 @@
  * @author      Paul Hanchett <[email protected]>
  * @copyright   (C) Paul Hanchett, 2005
  * @license     http://www.gnu.org/licenses/gpl.html
- * @version     $Revision: 1.2 $
+ * @version     $Revision: 1.3 $
  *
  */
 //
@@ -33,6 +33,7 @@
 $suite->addTestSuite(ParserBoldAsteriskFormattingTest);
 $suite->addTestSuite(ParserItalicSlashFormattingTest);
 $suite->addTestSuite(ParserUnderlineUnderbarFormattingTest);
+
 $suite->addTestSuite(ParserFixedwidthEqualsFormattingTest);
 $suite->addTestSuite(ParserstrikeoutHyphenFormattingTest);
 
@@ -52,11 +53,15 @@
 $suite->addTestSuite(ParserBadTagFormattingTest);
 
 $suite->addTestSuite(ParserNoopTagFormattingTest);
-$suite->addTestSuite(ParserPreTagFormattingTest);
+$suite->addTestSuite(ParserRemTagFormattingTest);
+
 $suite->addTestSuite(ParserCodeTagFormattingTest);
+$suite->addTestSuite(ParserPreTagFormattingTest);
 $suite->addTestSuite(ParserPostingTagFormattingTest);
 $suite->addTestSuite(ParserQTagFormattingTest);
-$suite->addTestSuite(ParserRemTagFormattingTest);
+
+$suite->addTestSuite(ParserOtherProcessContentFormattingTest);
+$suite->addTestSuite(ParserOtherParseFormattingTest);
 
 $suite->run($result);
 

File [changed]: class.ParserTest.php
Url: http://cowiki.tigris.org/source/browse/cowiki/misc/development/tests/class.ParserTest.php?r1=1.1&r2=1.2
Delta lines:  +763 -26
----------------------
--- class.ParserTest.php	8 May 2005 14:23:21 -0000	1.1
+++ class.ParserTest.php	29 May 2005 15:46:09 -0000	1.2
@@ -1,7 +1,7 @@
 <?php
 /**
  *
- * $Id: class.ParserTest.php,v 1.1 2005/05/08 14:23:21 cmarble Exp $
+ * $Id: class.ParserTest.php,v 1.2 2005/05/29 15:46:09 cmarble Exp $
  *
  * This file is part of coWiki. coWiki is free software under the terms of
  * the GNU General Public License (GPL). Read the LICENSE file. If you did
@@ -16,7 +16,7 @@
  * @author      Paul Hanchett <[email protected]>
  * @copyright   (C) Paul Hanchett, 2005
  * @license     http://www.gnu.org/licenses/gpl.html
- * @version     $Revision: 1.1 $
+ * @version     $Revision: 1.2 $
  *
  */
 
@@ -33,7 +33,7 @@
     //--------------------------------------------------------------
     function setUp()
     {
-        $this->p = CoWikiParser :: getInstance();
+        $this->p = TestWikiParser :: getInstance();
         $this->r = TestReverseParser :: getInstance();
     }
 
@@ -81,8 +81,8 @@
 	$inputString = "Line with eol\n";
 	$outputString = "<p>Line with eol</p>";
 	$messageString = "Lines with <eol> are a paragraph";
-	$reformString = $inputString;
-	$ressageString = "Paragraphs are a line with eol";
+	$reformString = "Line with eol";
+	$ressageString = "Paragraphs are a line without eol";
 	$this->assertEquals($outputString, $this->p->parse($inputString), $messageString);
 	$this->assertEquals($reformString, $this->r->parse($outputString), $ressageString);
     }
@@ -92,7 +92,7 @@
     //--------------------------------------------------------------
     function testTwoParagraphs()
     {
-	$inputString = "Line with eol\n\nAnd another paragraph\n";
+	$inputString = "Line with eol\nAnd another paragraph";
 	$outputString = "<p>Line with eol</p><p>And another paragraph</p>";
 	$messageString = "Multiple lines ending in <eol> are paragraphs";
 	$reformString = $inputString;
@@ -165,7 +165,7 @@
     //--------------------------------------------------------------
     function setUp()
     {
-	$this->p = CoWikiParser :: getInstance();
+	$this->p = TestWikiParser :: getInstance();
 	$this->r = TestReverseParser :: getInstance();
     }
 
@@ -268,7 +268,7 @@
     //------------------------------------------------------------------
     function testEmphasizeEndsAtEoln()
     {
-	$inputString = "A ".$this->formatChar.$this->formatChar."Emphasize phrase\n\ncannot continue".$this->formatChar.$this->formatChar." across a line.";
+	$inputString = "A ".$this->formatChar.$this->formatChar."Emphasize phrase\ncannot continue".$this->formatChar.$this->formatChar." across a line.";
 	$outputString = "<p>A ".$this->formatChar.$this->formatChar."Emphasize phrase</p><p>cannot continue".$this->formatChar.$this->formatChar." across a line.</p>";
 	$this->assertEquals($outputString, $this->p->parse($inputString));
 	$this->assertEquals(trim($inputString), trim($this->r->parse($outputString)));
@@ -361,7 +361,7 @@
     //--------------------------------------------------------------
     function setUp()
     {
-	$this->p = CoWikiParser :: getInstance();
+	$this->p = TestWikiParser :: getInstance();
 	$this->r = TestReverseParser :: getInstance();
     }
 
@@ -442,7 +442,7 @@
     //------------------------------------------------------------------
     function testEmphasizeEndsAtEoln()
     {
-	$inputString = "A ".$this->startFormat."Emphasize phrase\n\ncannot continue".$this->endFormat." across a line.";
+	$inputString = "A ".$this->startFormat."Emphasize phrase\ncannot continue".$this->endFormat." across a line.";
 	$outputString = "<p>A ".htmlentities($this->startFormat)."Emphasize phrase</p><p>cannot continue".htmlentities($this->endFormat)." across a line.</p>";
 	$this->assertEquals($outputString, $this->p->parse($inputString));
 	$this->assertEquals(trim($inputString), trim($this->r->parse($outputString)));
@@ -593,7 +593,7 @@
 
 
 //--------------------------------------------------------------------------
-//	Basic tests for formatting text with <tags> within paragraphs
+//	Basic tests for formatting text within <tags> within paragraphs
 //--------------------------------------------------------------------------
 class ParserGreedyTagFormattingTest extends PHPUnit_TestCase {
 	var $p = nil;
@@ -622,7 +622,7 @@
     //--------------------------------------------------------------
     function setUp()
     {
-	$this->p = CoWikiParser :: getInstance();
+	$this->p = TestWikiParser :: getInstance();
 	$this->r = TestReverseParser :: getInstance();
     }
 
@@ -699,10 +699,9 @@
     function testGreedyOverEoln()
     {
 	$inputString = "A ".$this->startFormat."Greedy phrase \ncan continue".$this->endFormat." across a line.";
-	$outputString = "<p>A ".$this->startFormat."Greedy phrase can continue".$this->endFormat." across a line.</p>";
-	$reformString = "A ".$this->startFormat."Greedy phrase can continue".$this->endFormat." across a line.";
+	$outputString = "<p>A ".$this->startFormat."Greedy phrase \ncan continue".$this->endFormat." across a line.</p>";
 	$this->assertEquals($outputString, $this->p->parse($inputString));
-	$this->assertEquals(trim($reformString),trim($this->r->parse($outputString)));
+	$this->assertEquals(trim($inputString),trim($this->r->parse($outputString)));
     }
 
 }
@@ -718,51 +717,789 @@
     }
 }
 //--------------------------------------------------------------------------
+//	<rem>: Remark tag for text within a paragraph
+//--------------------------------------------------------------------------
+class ParserRemTagFormattingTest extends ParserGreedyTagFormattingTest {
+    function __construct($name)
+    {
+	ParserGreedyTagFormattingTest :: __construct($name, "Rem", "<rem>", "</rem>", '<rem>', "</rem>");
+    }
+}
+
+//--------------------------------------------------------------------------
+//	Basic tests for formatting text within <tags> within paragraphs
+//--------------------------------------------------------------------------
+class ParserGreedyContentTagFormattingTest extends PHPUnit_TestCase {
+    var $p = nil;
+    var $r = nil;
+
+    var $testType = "Undefined";
+    var $startFormat = "<?>";
+    var $endFormat = "</?>";
+    var $startTag = "<start>";
+    var $endTag = "</start>";
+    var $startEmph = "<?>";
+    var $endEmph = "</?>";
+    var $startEmTag = "<start>";
+    var $endEmTag = "</start>";
+
+    //--------------------------------------------------------------
+    //	Standard constructor for unit tests.
+    //--------------------------------------------------------------
+    function __construct($name, $type, $formatStart, $formatEnd, $start, $end,
+			    $emphStart, $emphEnd, $startEm, $endEm )
+    {
+	$this->startFormat = $formatStart;
+	$this->endFormat = $formatEnd;
+	$this->startTag = $start;
+	$this->endTag = $end;
+	$this->startEmph = $emphStart;
+	$this->endEmph = $emphEnd;
+	$this->startEmTag = $startEm;
+	$this->endEmTag = $endEm;
+	$this->PHPUnit_TestCase($name);
+    }
+
+    //--------------------------------------------------------------
+    //	Setup: Set up an instance of the parser for testing
+    //--------------------------------------------------------------
+    function setUp()
+    {
+	$this->p = TestWikiParser :: getInstance();
+	$this->r = TestReverseParser :: getInstance();
+    }
+
+    //--------------------------------------------------------------
+    //	Helper function to generate input and output strings 
+    //--------------------------------------------------------------
+    function generateWikiGreedy($greedyStart, $greedyEnd, $startTag, $endTag, $begin, $middle, $ending, & $input, & $output)
+    {
+	$input = $begin.$greedyStart.$middle.$greedyEnd.$ending;
+	$output = "<p>".$begin.$startTag.$middle.$endTag.$ending."</p>";
+    }
+
+    //--------------------------------------------------------------
+    //	Test greediness on a single word
+    //--------------------------------------------------------------
+    function testGreedyWord()
+    {
+	$inputString = "";
+	$outputString = "";
+	$this->generateWikiGreedy($this->startFormat, $this->endFormat, $this->startTag, $this->endTag, "start ", "middle", " end", $inputString, $outputString);
+	$this->assertEquals($outputString, $this->p->parse($inputString));
+	$this->assertEquals(trim($inputString),trim($this->r->parse($outputString)));
+    }
+
+    //--------------------------------------------------------------
+    //	Test greediness on a phrase
+    //--------------------------------------------------------------
+    function testGreedyPhrase()
+    {
+	$inputString = "";
+	$outputString = "";
+	$this->generateWikiGreedy($this->startFormat, $this->endFormat, $this->startTag, $this->endTag, "start ", "middle words", " end", $inputString, $outputString);
+	$this->assertEquals($outputString, $this->p->parse($inputString));
+	$this->assertEquals(trim($inputString),trim($this->r->parse($outputString)));
+    }
+
+    //--------------------------------------------------------------
+    //	Test emphasize an entire line (no terminator)
+    //--------------------------------------------------------------
+    function testGreedyLine()
+    {
+	$inputString = "";
+	$outputString = "";
+	$this->generateWikiGreedy($this->startFormat, $this->endFormat, $this->startTag, $this->endTag, "", "middle words", "", $inputString, $outputString);
+	$this->assertEquals($outputString, $this->p->parse($inputString));
+	$this->assertEquals(trim($inputString),trim($this->r->parse($outputString)));
+    }
+
+    //--------------------------------------------------------------
+    //	Test mismatched greedy tags
+    //--------------------------------------------------------------
+    function testMismatchedGreedyPhrase()
+    {
+	$inputString = "this phrase ".$this->startFormat."is mismatched";
+	$outputString = "<p>this phrase ".htmlentities($this->startFormat)."is mismatched</p>";
+	$this->assertEquals($outputString, $this->p->parse($inputString));
+	$this->assertEquals(trim($inputString),trim($this->r->parse($outputString)));
+    }
+
+    //--------------------------------------------------------------
+    //	Test "this phrase <tag>is</tag> <tag>mismatched in an intersting way"
+    //--------------------------------------------------------------
+    function testMismatchedGreedyPhrase2()
+    {
+	$inputString = "this phrase ".$this->startFormat."is".$this->endFormat." ".$this->startFormat."mismatched in an intersting way";
+	$outputString = "<p>this phrase ".$this->startTag."is".$this->endTag." ".htmlentities($this->startFormat)."mismatched in an intersting way</p>";
+	$this->assertEquals($outputString, $this->p->parse($inputString));
+	$this->assertEquals(trim($inputString),trim($this->r->parse($outputString)));
+    }
+
+    //------------------------------------------------------------------
+    //	Test "A <tag>Greedy phrase \n can continue</tag> across a line."
+    //------------------------------------------------------------------
+    function testGreedyOverEoln()
+    {
+	$inputString = "A ".$this->startFormat."Greedy phrase \ncan continue".$this->endFormat." across a line.";
+	$outputString = "<p>A ".$this->startFormat."Greedy phrase can continue".$this->endFormat." across a line.</p>";
+	$reformString = "A ".$this->startFormat."Greedy phrase can continue".$this->endFormat." across a line.";
+	$this->assertEquals($outputString, $this->p->parse($inputString));
+	$this->assertEquals(trim($reformString),trim($this->r->parse($outputString)));
+    }
+
+    //--------------------------------------------------------------
+    //	Helper function to generate input and output strings 
+    //--------------------------------------------------------------
+    function generateWikiGreedyEmphasis($greedyStart, $greedyEnd, $emphasisStart, $emphasisEnd, $startTag, $endTag, $startEmph, $endEmph, $begin, $middle1, $middle2, $middle3, $ending, & $input, & $output)
+    {
+	$input = $begin.$greedyStart.$middle1.$emphasisStart.$middle2.$emphasisEnd.$middle3.$greedyEnd.$ending;
+	$output = "<p>".$begin.$startTag.$middle1.$startEmph.$middle2.$endEmph.$middle3.$endTag.$ending."</p>";
+    }
+
+    //--------------------------------------------------------------
+    //	TODO:	Need to check how special characters like punctuation
+    //			affect emphasis.  "This *word!* should /emphasize/.
+    //--------------------------------------------------------------
+
+    //--------------------------------------------------------------
+    //	Test emphasis on a single word
+    //--------------------------------------------------------------
+    function testEmphasizeWord()
+    {
+	$inputString = "";
+	$outputString = "";
+	$this->generateWikiGreedyEmphasis($this->startFormat, $this->endFormat, $this->startEmph, $this->endEmph, $this->startTag, $this->endTag, $this->startEmTag, $this->endEmTag, "start ", "middle1", "middle2", "middle3", " end", $inputString, $outputString);
+	$this->assertEquals($outputString, $this->p->parse($inputString));
+	$this->assertEquals(trim($inputString), trim($this->r->parse($outputString)));
+    }
+
+    //--------------------------------------------------------------
+    //	Test emphasis on a phrase
+    //--------------------------------------------------------------
+    function testEmphasizePhrase()
+    {
+	$inputString = "";
+	$outputString = "";
+	$this->generateWikiGreedyEmphasis($this->startFormat, $this->endFormat, $this->startEmph, $this->endEmph, $this->startTag, $this->endTag, $this->startEmTag, $this->endEmTag, "start ", "middle1", "middle2 words", "middle3", " end", $inputString, $outputString);
+	$this->assertEquals($outputString, $this->p->parse($inputString));
+	$this->assertEquals(trim($inputString), trim($this->r->parse($outputString)));
+    }
+
+    //--------------------------------------------------------------
+    //	Test emphasize an entire line (no terminator)
+    //--------------------------------------------------------------
+    function testEmphasizeLine()
+    {
+	$inputString = "";
+	$outputString = "";
+	$this->generateWikiGreedyEmphasis($this->startFormat, $this->endFormat, $this->startEmph, $this->endEmph, $this->startTag, $this->endTag, $this->startEmTag, $this->endEmTag, "", "", "middle2 words", "", "", $inputString, $outputString);
+	$this->assertEquals($outputString, $this->p->parse($inputString));
+	$this->assertEquals(trim($inputString), trim($this->r->parse($outputString)));
+    }
+
+    //--------------------------------------------------------------
+    //	Test mismatched emphasis
+    //--------------------------------------------------------------
+    function testMismatchedEmphasizedPhrase()
+    {
+	$inputString = $this->startFormat."this phrase ".$this->startEmph."is mismatched".$this->endFormat;
+	$outputString = "<p>".$this->startTag."this phrase ".htmlentities($this->startEmph)."is mismatched".$this->endTag."</p>";
+	$this->assertEquals($outputString, $this->p->parse($inputString));
+	$this->assertEquals(trim($inputString), trim($this->r->parse($outputString)));
+    }
+
+    //--------------------------------------------------------------
+    //	Test "this phrase <b>is</b> <b>mismatched in an intersting way"
+    //--------------------------------------------------------------
+    function testMismatchedEmphasizedPhrase2()
+    {
+	$inputString = $this->startFormat."this phrase ".$this->startEmph."is".$this->endEmph." ".$this->startEmph."mismatched in an intersting way".$this->endFormat;
+	$outputString = "<p>".$this->startTag."this phrase ".$this->startEmTag."is".$this->endEmTag." ".htmlentities($this->startEmph)."mismatched in an intersting way".$this->endTag."</p>";
+	$this->assertEquals($outputString, $this->p->parse($inputString));
+	$this->assertEquals(trim($inputString), trim($this->r->parse($outputString)));
+    }
+
+    //------------------------------------------------------------------
+    //	Test "A **Emphasize phrase\ncannot continue** across a line."
+    //------------------------------------------------------------------
+    function testEmphasizeEndsAtEoln()
+    {
+	$inputString = $this->startFormat."A ".$this->startEmph."Emphasize phrase \ncontinues".$this->endEmph." across a line.".$this->endFormat;
+	$outputString = "<p>".$this->startTag."A ".htmlentities($this->startEmph)."Emphasize phrase continues".htmlentities($this->endEmph)." across a line.".$this->endFormat."</p>";
+	$revString = $this->startFormat."A ".$this->startEmph."Emphasize phrase continues".$this->endEmph." across a line.".$this->endFormat;
+	$this->assertEquals($outputString, $this->p->parse($inputString));
+	$this->assertEquals(trim($revString), trim($this->r->parse($outputString)));
+    }
+
+}
+
+
+//--------------------------------------------------------------------------
 //	<pre>: Pre-formatted tag for text within a paragraph
 //--------------------------------------------------------------------------
-class ParserPreTagFormattingTest extends ParserGreedyTagFormattingTest
+class ParserPreTagFormattingTest extends ParserGreedyContentTagFormattingTest
 {
     function __construct($name)
     {
-	ParserGreedyTagFormattingTest :: __construct($name, "Pre", "<pre>", "</pre>", '<pre>', "</pre>");
+      ParserGreedyContentTagFormattingTest :: __construct($name, "Pre", "<pre>", "</pre>", '<pre>', "</pre>", "<b>", "</b>", '<b origin="html">', '</b>' );
     }
 }
 //--------------------------------------------------------------------------
 //	<code>: Code-formatting tag for text within a paragraph
 //--------------------------------------------------------------------------
-class ParserCodeTagFormattingTest extends ParserGreedyTagFormattingTest
+class ParserCodeTagFormattingTest extends ParserGreedyContentTagFormattingTest
 {
     function __construct($name)
     {
-	ParserGreedyTagFormattingTest :: __construct($name, "Code", "<code>", "</code>", '<code>', "</code>");
+	ParserGreedyContentTagFormattingTest :: __construct($name, "Code", "<code>", "</code>", '<code>', "</code>", "<b>", "</b>", '<b origin="html">', '</b>' );
     }
 }
 //--------------------------------------------------------------------------
 //	<posting>: Posting-formatted tag for text within a paragraph
 //--------------------------------------------------------------------------
-class ParserPostingTagFormattingTest extends ParserGreedyTagFormattingTest {
+class ParserPostingTagFormattingTest extends ParserGreedyContentTagFormattingTest {
     function __construct($name)
     {
-	ParserGreedyTagFormattingTest :: __construct($name, "Posting", "<posting>", "</posting>", '<posting>', "</posting>");
+	ParserGreedyContentTagFormattingTest :: __construct($name, "Posting", "<posting>", "</posting>", '<posting>', "</posting>", "<b>", "</b>", '<b origin="html">', '</b>' );
     }
 }
 //--------------------------------------------------------------------------
 //	<q>: Quote tag for text within a paragraph
 //--------------------------------------------------------------------------
-class ParserQTagFormattingTest extends ParserGreedyTagFormattingTest {
+class ParserQTagFormattingTest extends ParserGreedyContentTagFormattingTest {
     function __construct($name)
     {
-	ParserGreedyTagFormattingTest :: __construct($name, "Q", "<q>", "</q>", '<q>', "</q>");
+	ParserGreedyContentTagFormattingTest :: __construct($name, "Q", "<q>", "</q>", '<q>', "</q>", "<b>", "</b>", '<b origin="html">', '</b>' );
     }
 }
+
 //--------------------------------------------------------------------------
-//	<rem>: Remark tag for text within a paragraph
+//	<br/>, variables, links, uris & plugins
 //--------------------------------------------------------------------------
-class ParserRemTagFormattingTest extends ParserGreedyTagFormattingTest {
+class ParserOtherProcessContentFormattingTest extends PHPUnit_TestCase {
+    var $p = nil;
+    var $r = nil;
+
+    //--------------------------------------------------------------
+    //	Standard constructor for unit tests.
+    //--------------------------------------------------------------
     function __construct($name)
     {
-	ParserGreedyTagFormattingTest :: __construct($name, "Rem", "<rem>", "</rem>", '<rem>', "</rem>");
+	$this->PHPUnit_TestCase($name);
+    }
+
+    //--------------------------------------------------------------
+    //	Setup: Set up an instance of the parser for testing
+    //--------------------------------------------------------------
+    function setUp()
+    {
+	$this->p = TestWikiParser :: getInstance();
+	$this->r = TestReverseParser :: getInstance();
+    }
+
+    //--------------------------------------------------------------------------
+    //	<br/> (must include slash)
+    //--------------------------------------------------------------------------
+    function testLineBreak()
+    {
+	$inputString = "A line<br/>-break";
+	$outputString = "<p>A line<br/>-break</p>";
+	$this->assertEquals($outputString, $this->p->parse($inputString));
+	$this->assertEquals(trim($inputString), trim($this->r->parse($outputString)));
+    }
+    function testLineBreakSolo()
+    {
+	$inputString = "<br/>";
+	$outputString = "<p><br/></p>";
+	$this->assertEquals($outputString, $this->p->parse($inputString));
+	$this->assertEquals(trim($inputString), trim($this->r->parse($outputString)));
+    }
+    function testLineBreakFaulty()
+    {
+	$inputString = "<br >";
+	$outputString = "<p>&lt;br &gt;</p>";
+	$this->assertEquals($outputString, $this->p->parse($inputString));
+	$this->assertEquals(trim($inputString), trim($this->r->parse($outputString)));
+    }
+
+    //--------------------------------------------------------------------------
+    //	variables
+    //--------------------------------------------------------------------------
+    function testVariable()
+    {
+	$inputString = 'A %VARIABLE% test';
+	$outputString = '<p>A <var name="VARIABLE"/> test</p>';
+	$this->assertEquals($outputString, $this->p->parse($inputString));
+	$this->assertEquals(trim($inputString), trim($this->r->parse($outputString)));
+    }
+    function testVariableSolo()
+    {
+	$inputString = '%VARIABLE%';
+	$outputString = '<p><var name="VARIABLE"/></p>';
+	$this->assertEquals($outputString, $this->p->parse($inputString));
+	$this->assertEquals(trim($inputString), trim($this->r->parse($outputString)));
+    }
+    function testPercent()
+    {
+	$inputString = 'A 100% test';
+	$outputString = '<p>A 100% test</p>';
+	$this->assertEquals($outputString, $this->p->parse($inputString));
+	$this->assertEquals(trim($inputString), trim($this->r->parse($outputString)));
+    }
+    function testVariableFaulty()
+    {
+	$inputString = "A %LINE\nBREAK% test";
+	$outputString = "<p>A %LINE</p><p>BREAK% test</p>";
+	$this->assertEquals($outputString, $this->p->parse($inputString));
+	$this->assertEquals(trim($inputString), trim($this->r->parse($outputString)));
+    }
+
+    //--------------------------------------------------------------------------
+    //	links
+    //--------------------------------------------------------------------------
+    function testBrokenLinkSyntax1()
+    {
+	$inputString = "A ((http://www.google.co.uk)\n(Alias)) test";
+	$outputString = '<p>A ((http://www.google.co.uk)</p><p>(Alias)) test</p>';
+	$this->assertEquals($outputString, $this->p->parse($inputString));
+	$this->assertEquals(trim($inputString), trim($this->r->parse($outputString)));
+    }
+    function testBrokenLinkSyntax2()
+    {
+	$inputString = "A ((http://www.goo\ngle.co.uk)(Alias)) test";
+	$outputString = '<p>A ((http://www.goo</p><p>gle.co.uk)(Alias)) test</p>';
+	$this->assertEquals($outputString, $this->p->parse($inputString));
+	$this->assertEquals(trim($inputString), trim($this->r->parse($outputString)));
+    }
+    function testBrokenLinkSyntax3()
+    {
+	$inputString = "A ((http://www.google.co.uk)(Al\nias)) test";
+	$outputString = '<p>A ((http://www.google.co.uk)(Al</p><p>ias)) test</p>';
+	$this->assertEquals($outputString, $this->p->parse($inputString));
+	$this->assertEquals(trim($inputString), trim($this->r->parse($outputString)));
+    }
+    function testUriLinkElement()
+    {
+	$inputString = 'A ((http://www.google.co.uk)(Alias)) test';
+	$outputString = '<p>A <link origin="round" href="http://www.google.co.uk">Alias</link> test</p>';
+	$this->assertEquals($outputString, $this->p->parse($inputString));
+	$this->assertEquals(trim($inputString), trim($this->r->parse($outputString)));
+    }
+    function testGlobalLinkElement()
+    {
+	$inputString = 'A ((Web|Ref)(Alias)) test';
+	$outputString = '<p>A <link origin="round" strref="Web¦Ref">Alias</link> test</p>';
+	$revString = '<p>A <link origin="round" strref="Web|Ref">Alias</link> test</p>';
+	$this->assertEquals($outputString, $this->p->parse($inputString));
+	$this->assertEquals(trim($inputString), trim($this->r->parse($revString)));
+    }
+    function testLocalLinkElement()
+    {
+	$inputString = 'A [[Ref][Alias]] test';
+	$outputString = '<p>A <link origin="square" strref="Ref">Alias</link> test</p>';
+	$this->assertEquals($outputString, $this->p->parse($inputString));
+	$this->assertEquals(trim($inputString), trim($this->r->parse($outputString)));
+    }
+
+    //--------------------------------------------------------------------------
+    //	URIs
+    //--------------------------------------------------------------------------
+    function testURIElement()
+    {
+	$inputString = 'some text http://cowiki.tigris.org';
+	$outputString = '<p>some text <uri strref="http://cowiki.tigris.org"/></p>';
+	$this->assertEquals($outputString, $this->p->parse($inputString));
+	$this->assertEquals(trim($inputString), trim($this->r->parse($outputString)));
+    }
+    function testURIElementAlone()
+    {
+	$inputString = 'http://cowiki.tigris.org';
+	$outputString = '<p><uri strref="http://cowiki.tigris.org"/></p>';
+	$this->assertEquals($outputString, $this->p->parse($inputString));
+	$this->assertEquals(trim($inputString), trim($this->r->parse($outputString)));
+    }
+    function testURIBrokenElement()
+    {
+	$inputString = "text http://co\nwiki.tigris.org";
+	$outputString = '<p>text <uri strref="http://co"/></p><p>wiki.tigris.org</p>';
+	$this->assertEquals($outputString, $this->p->parse($inputString));
+	$this->assertEquals(trim($inputString), trim($this->r->parse($outputString)));
+    }
+    function testURIBrokenElement2()
+    {
+	$inputString = "text ht\ntp://cowiki.tigris.org";
+	$outputString = '<p>text ht</p><p>tp://cowiki.tigris.org</p>';
+	$this->assertEquals($outputString, $this->p->parse($inputString));
+	$this->assertEquals(trim($inputString), trim($this->r->parse($outputString)));
+    }
+
+    //--------------------------------------------------------------------------
+    //	plugins
+    //--------------------------------------------------------------------------
+    function testPluginElement()
+    {
+	$inputString = 'text <plugin Example>';
+	$outputString = '<p>text <plugin name="Example"/></p>';
+	$this->assertEquals($outputString, $this->p->parse($inputString));
+	$this->assertEquals(trim($inputString), trim($this->r->parse($outputString)));
+    }
+    function testPluginElementSlash()
+    {
+	$inputString = 'text <plugin Example/>';
+	$outputString = '<p>text <plugin name="Example"/></p>';
+	$revString = 'text <plugin Example>';
+	$this->assertEquals($outputString, $this->p->parse($inputString));
+	$this->assertEquals(trim($revString), trim($this->r->parse($outputString)));
+    }
+    function testPluginElementBroken()
+    {
+	$inputString = "text <plu\ngin Example/>";
+	$outputString = '<p>text &lt;plu</p><p>gin Example/&gt;</p>';
+	$this->assertEquals($outputString, $this->p->parse($inputString));
+	$this->assertEquals(trim($inputString), trim($this->r->parse($outputString)));
+    }
+    function testPluginElementBroken2()
+    {
+	$inputString = "text <plugin Exa\nmple/>";
+	$outputString = '<p>text &lt;plugin Exa</p><p>mple/&gt;</p>';
+	$this->assertEquals($outputString, $this->p->parse($inputString));
+	$this->assertEquals(trim($inputString), trim($this->r->parse($outputString)));
+    }
+    function testPluginElementBroken3()
+    {
+	$inputString = "text <plugin\nExample/>";
+	$outputString = '<p>text &lt;plugin</p><p>Example/&gt;</p>';
+	$this->assertEquals($outputString, $this->p->parse($inputString));
+	$this->assertEquals(trim($inputString), trim($this->r->parse($outputString)));
+    }
+    function testPluginElementAttributed()
+    {
+	$inputString = "text <plugin Example attr=\"val\">";
+	$outputString = '<p>text <plugin name="Example" attr="val"/></p>';
+	$this->assertEquals($outputString, $this->p->parse($inputString));
+	$this->assertEquals(trim($inputString), trim($this->r->parse($outputString)));
+    }
+    function testPluginElementMoreAttributed()
+    {
+	$inputString = "text <plugin Example attr=\"val\" attr2=\"val2\">";
+	$outputString = '<p>text <plugin name="Example" attr="val" attr2="val2"/></p>';
+	$this->assertEquals($outputString, $this->p->parse($inputString));
+	$this->assertEquals(trim($inputString), trim($this->r->parse($outputString)));
     }
 }
 
+//--------------------------------------------------------------------------
+//	Headings, tables, lists
+//--------------------------------------------------------------------------
+class ParserOtherParseFormattingTest extends PHPUnit_TestCase {
+    var $p = nil;
+    var $r = nil;
+
+    //--------------------------------------------------------------
+    //	Standard constructor for unit tests.
+    //--------------------------------------------------------------
+    function __construct($name)
+    {
+	$this->PHPUnit_TestCase($name);
+    }
+
+    //--------------------------------------------------------------
+    //	Setup: Set up an instance of the parser for testing
+    //--------------------------------------------------------------
+    function setUp()
+    {
+	$this->p = TestWikiParser :: getInstance();
+	$this->r = TestReverseParser :: getInstance();
+    }
+
+    //--------------------------------------------------------------------------
+    //	Headings
+    //--------------------------------------------------------------------------
+    function testHeadingNoSpace()
+    {
+	$inputString = "+++Heading3";
+	$outputString = "<h3>Heading3</h3>";
+	$revString = "+++ Heading3";
+	$this->assertEquals($outputString, $this->p->parse($inputString));
+	$this->assertEquals(trim($revString), trim($this->r->parse($outputString)));
+    }
+    function testHeadingSpace()
+    {
+	$inputString = "+++ Heading3\nmore text";
+	$outputString = "<h3>Heading3</h3><p>more text</p>";
+	$this->assertEquals($outputString, $this->p->parse($inputString));
+	$this->assertEquals(trim($inputString), trim($this->r->parse($outputString)));
+    }
+    function testHeadingLeadSpace()
+    {
+	$inputString = " +++ Heading3\nmore text";
+	$outputString = "<p>+++ Heading3</p><p>more text</p>";
+	$this->assertEquals($outputString, $this->p->parse($inputString));
+	$this->assertEquals(trim($inputString), trim($this->r->parse($outputString)));
+    }
+    function testHeadingEmphasis()
+    {
+	$inputString = "+++ **Heading3 bold**";
+	$outputString = '<h3><b origin="wiki">Heading3 bold</b></h3>';
+	$this->assertEquals($outputString, $this->p->parse($inputString));
+	$this->assertEquals(trim($inputString), trim($this->r->parse($outputString)));
+    }
+    function testHeadingJustification()
+    {
+	$inputString = "+++<right>Heading3</right>";
+	$outputString = '<h3><right origin="html">Heading3</right></h3>';
+	$revString = "+++ <right>Heading3</right>";
+	$this->assertEquals($outputString, $this->p->parse($inputString));
+	$this->assertEquals(trim($revString), trim($this->r->parse($outputString)));
+    }
+    function testHeadingWrongJustification()
+    {
+	$inputString = "<right>+++ Heading3</right>\nmore text";
+	$outputString = '<p><right origin="html">+++ Heading3</right></p><p>more text</p>';
+	$this->assertEquals($outputString, $this->p->parse($inputString));
+	$this->assertEquals(trim($inputString), trim($this->r->parse($outputString)));
+    }
+    function testHeadingLineBreak()
+    {
+	$inputString = "+++ Head<br/>ing\nmore text";
+	$outputString = '<h3>Head<br/>ing</h3><p>more text</p>';
+	$this->assertEquals($outputString, $this->p->parse($inputString));
+	$this->assertEquals(trim($inputString), trim($this->r->parse($outputString)));
+    }
+    function testHeadingVariable()
+    {
+	$inputString = "+++ %TITLE%\nmore text";
+	$outputString = '<h3><var name="TITLE"/></h3><p>more text</p>';
+	$this->assertEquals($outputString, $this->p->parse($inputString));
+	$this->assertEquals(trim($inputString), trim($this->r->parse($outputString)));
+    }
+    function testHeadingLink()
+    {
+	$inputString = "+++ ((www.h2g2.com)(H2G2))\nmore text";
+	$outputString = '<h3><link origin="round" strref="www.h2g2.com">H2G2</link></h3><p>more text</p>';
+	$this->assertEquals($outputString, $this->p->parse($inputString));
+	$this->assertEquals(trim($inputString), trim($this->r->parse($outputString)));
+    }
+    function testHeadingURI()
+    {
+	$inputString = "+++ http://www.h2g2.com\nmore text";
+	$outputString = '<h3><uri strref="http://www.h2g2.com"/></h3><p>more text</p>';
+	$this->assertEquals($outputString, $this->p->parse($inputString));
+	$this->assertEquals(trim($inputString), trim($this->r->parse($outputString)));
+    }
+    function testHeadingPlugin()
+    {
+	$inputString = "+++ <plugin Example>";
+	$outputString = '<h3><plugin name="Example"/></h3>';
+	$this->assertEquals($outputString, $this->p->parse($inputString));
+	$this->assertEquals(trim($inputString), trim($this->r->parse($outputString)));
+    }
+    //--------------------------------------------------------------------------
+    //	Tables
+    //--------------------------------------------------------------------------
+    function testTablesCaptionBroken()
+    {
+	$inputString = "test <table>\n|+Caption\n</table>";
+	$outputString = "<p>test &lt;table&gt;</p><p>|+Caption</p><p>&lt;/table&gt;</p>";
+
+	$this->assertEquals($outputString, $this->p->parse($inputString));
+	$this->assertEquals(trim($inputString), trim($this->r->parse($outputString)));
+    }
+    function testTablesCaption()
+    {
+	$inputString = "<table>\n|+Caption\n</table>";
+	$outputString = "<table><caption>Caption</caption>\n</table>";
+	$revString = "<table>\n|+ Caption\n</table>";
+
+	$this->assertEquals($outputString, $this->p->parse($inputString));
+	$this->assertEquals(trim($revString), trim($this->r->parse($outputString)));
+    }
+    function testTablesCaptionDouble()
+    {
+        $inputString = "<table>\n|+ Caption\n|+ Caption2\n</table>";
+	$outputString = "<table><caption>Caption</caption>\n<caption>Caption2</caption>\n</table>";
+	$this->assertEquals($outputString, $this->p->parse($inputString));
+	$this->assertEquals(trim($inputString), trim($this->r->parse($outputString)));
+    }
+    function testTablesRowParamBroken()
+    {
+        $inputString = "<table>\n|-rowparam=\"detail\"\n| cell\n</table>";
+	$outputString = "<table><tr rowparam=\"detail\"><td>cell</td>\n</tr></table>";
+	$this->assertEquals($outputString, $this->p->parse($inputString));
+	$this->assertEquals(trim($inputString), trim($this->r->parse($outputString)));
+    }
+    function testTablesRowParamBroken2()
+    {
+        $inputString = "<table>\n|-rowparam=\"detail\" | cell\n</table>";
+	$outputString = "<table><tr rowparam=\"detail\" >cell</tr></table>";
+        $revString = "<table>\n|-rowparam=\"detail\"cell\n</table>";
+	$this->assertEquals($outputString, $this->p->parse($inputString));
+	$this->assertEquals(trim($revString), trim($this->r->parse($outputString)));
+    }
+    function testTablesRowParamCell()
+    {
+        $inputString = "<table>\n|-rowparam=\"detail\"\n| cell\n</table>";
+	$outputString = "<table><tr rowparam=\"detail\"><td>cell</td>\n</tr></table>";
+        $revString = "<table>\n|-rowparam=\"detail\"\n| cell\n</table>";
+	$this->assertEquals($outputString, $this->p->parse($inputString));
+	$this->assertEquals(trim($revString), trim($this->r->parse($outputString)));
+    }
+    function testTablesRowCellParam()
+    {
+        $inputString = "<table>\n|-\n|cellparam=\"detail\"| cell\n</table>";
+	$outputString = "<table><tr><td cellparam=\"detail\">cell</td>\n</tr></table>";
+	$this->assertEquals($outputString, $this->p->parse($inputString));
+	$this->assertEquals(trim($inputString), trim($this->r->parse($outputString)));
+    }
+    function testTablesRowHeadParam()
+    {
+        $inputString = "<table>\n|-\n!cellparam=\"detail\"|head\n</table>";
+	$outputString = "<table><tr><th cellparam=\"detail\">head</th>\n</tr></table>";
+	$this->assertEquals($outputString, $this->p->parse($inputString));
+	$this->assertEquals(trim($inputString), trim($this->r->parse($outputString)));
+    }
+    //--------------------------------------------------------------------------
+    //  nospace, space, emphasis, justification, linebreak, link, uri, plugin
+    //--------------------------------------------------------------------------
+    function testTablesEmphasis()
+    {
+        $inputString = "<table>\n| some **bold** text\n</table>";
+	$outputString = "<table><td>some <b origin=\"wiki\">bold</b> text</td>\n</table>";
+	$this->assertEquals($outputString, $this->p->parse($inputString));
+	$this->assertEquals(trim($inputString), trim($this->r->parse($outputString)));
+    }
+    function testTablesJustification()
+    {
+        $inputString = "<table>\n| <right>head</right>\n</table>";
+	$outputString = "<table><td><right origin=\"html\">head</right></td>\n</table>";
+	$this->assertEquals($outputString, $this->p->parse($inputString));
+	$this->assertEquals(trim($inputString), trim($this->r->parse($outputString)));
+    }
+    function testTablesLineBreak()
+    {
+        $inputString = "<table>\n| some<br/>text\n</table>";
+	$outputString = "<table><td>some<br/>text</td>\n</table>";
+	$this->assertEquals($outputString, $this->p->parse($inputString));
+	$this->assertEquals(trim($inputString), trim($this->r->parse($outputString)));
+    }
+    function testTablesLink()
+    {
+        $inputString = "<table>\n|| some ((Web|Ref)(Alias)) text\n</table>";
+	$outputString = "<table><td origin=\"doubled\">some <link origin=\"round\" strref=\"Web¦Ref\">Alias</link> text</td>\n</table>";
+	$revString = "<table><td origin=\"doubled\">some <link origin=\"round\" strref=\"Web|Ref\">Alias</link> text</td>\n</table>";
+	$this->assertEquals($outputString, $this->p->parse($inputString));
+	$this->assertEquals(trim($inputString), trim($this->r->parse($revString)));
+    }
+    function testTablesLink2()
+    {
+        $inputString = "<table>\n|cellparam=\"doh\"| some ((Web|Ref)(Alias)) text\n</table>";
+	$outputString = "<table><td cellparam=\"doh\">some <link origin=\"round\" strref=\"Web¦Ref\">Alias</link> text</td>\n</table>";
+	$revString = "<table><td cellparam=\"doh\">some <link origin=\"round\" strref=\"Web|Ref\">Alias</link> text</td>\n</table>";
+	$this->assertEquals($outputString, $this->p->parse($inputString));
+	$this->assertEquals(trim($inputString), trim($this->r->parse($revString)));
+    }
+    function testTablesURI()
+    {
+        $inputString = "<table>\n| text http://www.h2g2.com\n</table>";
+	$outputString = "<table><td>text <uri strref=\"http://www.h2g2.com\"/></td>\n</table>";
+	$this->assertEquals($outputString, $this->p->parse($inputString));
+	$this->assertEquals(trim($inputString), trim($this->r->parse($outputString)));
+    }
+    function testTablesPlugin()
+    {
+        $inputString = "<table>\n| text <plugin Example>\n</table>";
+	$outputString = "<table><td>text <plugin name=\"Example\"/></td>\n</table>";
+	$this->assertEquals($outputString, $this->p->parse($inputString));
+	$this->assertEquals(trim($inputString), trim($this->r->parse($outputString)));
+    }
+
+    //--------------------------------------------------------------------------
+    //	Lists & Tables
+    //--------------------------------------------------------------------------
+    function testListInTable()
+    {
+	$inputString = "<table>\n|\n# First\n## Second\n</table>";
+	$outputString = "<table><td><p><list><ol><li>First<ol><li>Second</li></ol></li></ol></list></p></td>\n</table>";
+
+	$this->assertEquals($outputString, $this->p->parse($inputString));
+	$this->assertEquals(trim($inputString), trim($this->r->parse($outputString)));
+    }
+
+    //--------------------------------------------------------------------------
+    //	Lists
+    //--------------------------------------------------------------------------
+    function testList()
+    {
+	$inputString = "# List first\n## List second";
+	$outputString = "<p><list><ol><li>List first<ol><li>List second</li></ol></li></ol></list></p>";
+
+	$this->assertEquals($outputString, $this->p->parse($inputString));
+	$this->assertEquals(trim($inputString), trim($this->r->parse($outputString)));
+    }
+    function testListNoSpace()
+    {
+	$inputString = "#List first\n##List second";
+	$outputString = "<p>#List first</p><p>##List second</p>";
+
+	$this->assertEquals($outputString, $this->p->parse($inputString));
+	$this->assertEquals(trim($inputString), trim($this->r->parse($outputString)));
+    }
+    function testListBullet()
+    {
+	$inputString = "* List first\n** List second";
+	$outputString = "<p><list><ul><li>List first<ul><li>List second</li></ul></li></ul></list></p>";
+
+	$this->assertEquals($outputString, $this->p->parse($inputString));
+	$this->assertEquals(trim($inputString), trim($this->r->parse($outputString)));
+    }
+
+    //--------------------------------------------------------------------------
+    //  nospace, space, emphasis, justification, linebreak, link, uri, plugin
+    //--------------------------------------------------------------------------
+
+    function testListEmphasis()
+    {
+        $inputString = "# some **bold** text\n# more //emphasised// text";
+	$outputString = '<p><list><ol><li>some <b origin="wiki">bold</b> text</li><li>more <i origin="wiki">emphasised</i> text</li></ol></list></p>';
+	$this->assertEquals(trim($outputString), trim($this->p->parse($inputString)));
+	$this->assertEquals(trim($inputString), trim($this->r->parse($outputString)));
+    }
+    function testListJustificationDoesntWork()
+    {
+        $inputString = "# some <right>justified</right> text\n# some more text";
+	$outputString = '<p><list><ol><li>some <right origin="html">justified</right> text</li><li>some more text</li></ol></list></p>';
+	$this->assertEquals($outputString, $this->p->parse($inputString));
+	$this->assertEquals(trim($inputString), trim($this->r->parse($outputString)));
+    }
+    function testListLineBreak()
+    {
+        $inputString = "# some <br/> text\n# broken";
+	$outputString = '<p><list><ol><li>some <br/> text</li><li>broken</li></ol></list></p>';
+	$this->assertEquals($outputString, $this->p->parse($inputString));
+	$this->assertEquals(trim($inputString), trim($this->r->parse($outputString)));
+    }
+    function testListLink()
+    {
+        $inputString = "# some ((Web|Ref)(Alias)) text\n# continues";
+	$outputString = '<p><list><ol><li>some <link origin="round" strref="Web¦Ref">Alias</link> text</li><li>continues</li></ol></list></p>';
+	$revString = '<p><list><ol><li>some <link origin="round" strref="Web|Ref">Alias</link> text</li><li>continues</li></ol></list></p>';
+	$this->assertEquals($outputString, $this->p->parse($inputString));
+	$this->assertEquals(trim($inputString), trim($this->r->parse($revString)));
+    }
+    function testListURI()
+    {
+        $inputString = "# some http://www.h2g2.com\n# text";
+	$outputString = '<p><list><ol><li>some <uri strref="http://www.h2g2.com"/></li><li>text</li></ol></list></p>';
+	$this->assertEquals($outputString, $this->p->parse($inputString));
+	$this->assertEquals(trim($inputString), trim($this->r->parse($outputString)));
+    }
+    function testListPlugin()
+    {
+        $inputString = "# text <plugin Example>\n";
+	$outputString = '<p><list><ol><li>text <plugin name="Example"/></li></ol></list></p>';
+	$this->assertEquals($outputString, $this->p->parse($inputString));
+	$this->assertEquals(trim($inputString), trim($this->r->parse($outputString)));
+    }
+}
 ?>