* Now passing msg:search as the third paramater to googlesearch
[lhc/web/wiklou.git] / includes / normal / CleanUpTest.php
index e9156ab..527c5ff 100644 (file)
@@ -1,4 +1,36 @@
 <?php
+# Copyright (C) 2004 Brion Vibber <brion@pobox.com>
+# http://www.mediawiki.org/
+# 
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or 
+# (at your option) any later version.
+# 
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, write to the Free Software Foundation, Inc.,
+# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+# http://www.gnu.org/copyleft/gpl.html
+
+/**
+ * Additional tests for UtfNormal::cleanUp() function, inclusion
+ * regression checks for known problems.
+ *
+ * Requires PHPUnit.
+ * 
+ * @package UtfNormal
+ * @access private
+ */
+
+if( php_sapi_name() != 'cli' ) {
+       die( "Run me from the command line please.\n" );
+}
+
 /** */
 if( isset( $_SERVER['argv'] ) && in_array( '--icu', $_SERVER['argv'] ) ) {
        dl( 'php_utfnormal.so' );
@@ -9,22 +41,32 @@ if( isset( $_SERVER['argv'] ) && in_array( '--icu', $_SERVER['argv'] ) ) {
 require_once( 'PHPUnit.php' );
 require_once( 'UtfNormal.php' );
 
+/**
+ * @package UtfNormal
+ */
 class CleanUpTest extends PHPUnit_TestCase {
+       /**
+        * @param string $name ???
+        */
        function CleanUpTest( $name ) {
                $this->PHPUnit_TestCase( $name );
        }
 
+       /** @todo document */
        function setUp() {
        }
-       
+
+       /** @todo document */
        function tearDown() {
        }
-       
+
+       /** @todo document */
        function testAscii() {
                $text = 'This is plain ASCII text.';
                $this->assertEquals( $text, UtfNormal::cleanUp( $text ) );
        }
-       
+
+       /** @todo document */
        function testNull() {
                $text = "a \x00 null";
                $expect = "a \xef\xbf\xbd null";
@@ -32,19 +74,24 @@ class CleanUpTest extends PHPUnit_TestCase {
                        bin2hex( $expect ),
                        bin2hex( UtfNormal::cleanUp( $text ) ) );
        }
-       
+
+       /** @todo document */
        function testLatin() {
                $text = "L'\xc3\xa9cole";
                $this->assertEquals( $text, UtfNormal::cleanUp( $text ) );
        }
-       
+
+       /** @todo document */
        function testLatinNormal() {
                $text = "L'e\xcc\x81cole";
                $expect = "L'\xc3\xa9cole";
                $this->assertEquals( $expect, UtfNormal::cleanUp( $text ) );
        }
-       
-       # This test is *very* expensive!
+
+       /**
+        * This test is *very* expensive!
+        * @todo document
+        */
        function XtestAllChars() {
                $rep = UTF8_REPLACEMENT;
                global $utfCanonicalComp, $utfCanonicalDecomp;
@@ -76,14 +123,16 @@ class CleanUpTest extends PHPUnit_TestCase {
                        }
                }
        }
-       
+
+       /** @todo document */
        function testAllBytes() {
                $this->doTestBytes( '', '' );
                $this->doTestBytes( 'x', '' );
                $this->doTestBytes( '', 'x' );
                $this->doTestBytes( 'x', 'x' );
        }
-       
+
+       /** @todo document */
        function doTestBytes( $head, $tail ) {
                for( $i = 0x0; $i < 256; $i++ ) {
                        $char = $head . chr( $i ) . $tail;
@@ -108,14 +157,18 @@ class CleanUpTest extends PHPUnit_TestCase {
                        }
                }
        }
-       
+
+       /** @todo document */
        function testDoubleBytes() {
                $this->doTestDoubleBytes( '', '' );
                $this->doTestDoubleBytes( 'x', '' );
                $this->doTestDoubleBytes( '', 'x' );
                $this->doTestDoubleBytes( 'x', 'x' );
        }
-       
+
+       /**
+        * @todo document
+        */
        function doTestDoubleBytes( $head, $tail ) {
                for( $first = 0xc0; $first < 0x100; $first++ ) {
                        for( $second = 0x80; $second < 0x100; $second++ ) {
@@ -151,13 +204,15 @@ class CleanUpTest extends PHPUnit_TestCase {
                }
        }
 
+       /** @todo document */
        function testTripleBytes() {
                $this->doTestTripleBytes( '', '' );
                $this->doTestTripleBytes( 'x', '' );
                $this->doTestTripleBytes( '', 'x' );
                $this->doTestTripleBytes( 'x', 'x' );
        }
-       
+
+       /** @todo document */
        function doTestTripleBytes( $head, $tail ) {
                for( $first = 0xc0; $first < 0x100; $first++ ) {
                        for( $second = 0x80; $second < 0x100; $second++ ) {
@@ -222,7 +277,8 @@ class CleanUpTest extends PHPUnit_TestCase {
                        }
                }
        }
-       
+
+       /** @todo document */   
        function testChunkRegression() {
                # Check for regression against a chunking bug
                $text   = "\x46\x55\xb8" .
@@ -245,6 +301,7 @@ class CleanUpTest extends PHPUnit_TestCase {
                        bin2hex( UtfNormal::cleanUp( $text ) ) );
        }
 
+       /** @todo document */
        function testInterposeRegression() {
                $text   = "\x4e\x30" .
                          "\xb1" .              # bad tail
@@ -278,7 +335,8 @@ class CleanUpTest extends PHPUnit_TestCase {
                        bin2hex( $expect ),
                        bin2hex( UtfNormal::cleanUp( $text ) ) );
        }
-       
+
+       /** @todo document */   
        function testOverlongRegression() {
                $text   = "\x67" .
                          "\x1a" . # forbidden ascii
@@ -302,7 +360,8 @@ class CleanUpTest extends PHPUnit_TestCase {
                        bin2hex( $expect ),
                        bin2hex( UtfNormal::cleanUp( $text ) ) );
        }
-       
+
+       /** @todo document */   
        function testSurrogateRegression() {
                $text   = "\xed\xb4\x96" . # surrogate 0xDD16
                          "\x83" . # bad tail
@@ -316,7 +375,8 @@ class CleanUpTest extends PHPUnit_TestCase {
                        bin2hex( $expect ),
                        bin2hex( UtfNormal::cleanUp( $text ) ) );
        }
-       
+
+       /** @todo document */
        function testBomRegression() {
                $text   = "\xef\xbf\xbe" . # U+FFFE, illegal char
                          "\xb2" . # bad tail
@@ -331,6 +391,7 @@ class CleanUpTest extends PHPUnit_TestCase {
                        bin2hex( UtfNormal::cleanUp( $text ) ) );
        }
 
+       /** @todo document */
        function testForbiddenRegression() {
                $text   = "\xef\xbf\xbf"; # U+FFFF, illegal char
                $expect = "\xef\xbf\xbd";
@@ -338,6 +399,16 @@ class CleanUpTest extends PHPUnit_TestCase {
                        bin2hex( $expect ),
                        bin2hex( UtfNormal::cleanUp( $text ) ) );
        }
+
+       /** @todo document */
+       function testHangulRegression() {
+               $text = "\xed\x9c\xaf" . # Hangul char
+                               "\xe1\x87\x81";  # followed by another final jamo
+               $expect = $text;         # Should *not* change.
+               $this->assertEquals(
+                       bin2hex( $expect ),
+                       bin2hex( UtfNormal::cleanUp( $text ) ) );
+       }
 }
 
 
@@ -345,4 +416,8 @@ $suite =& new PHPUnit_TestSuite( 'CleanUpTest' );
 $result = PHPUnit::run( $suite );
 echo $result->toString();
 
+if( !$result->wasSuccessful() ) {
+       exit( -1 );
+}
+exit( 0 );
 ?>
\ No newline at end of file