]> scripts.mit.edu Git - autoinstallsdev/mediawiki.git/blobdiff - includes/normal/Utf8Test.php
MediaWiki 1.17.0
[autoinstallsdev/mediawiki.git] / includes / normal / Utf8Test.php
index 8600d49da0c91eb2808828d8bb60a661530a51b0..53108bc4d0e29f7dc72bb7287f7d31c2a33ea385 100644 (file)
@@ -1,28 +1,28 @@
 <?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.,
-# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-# http://www.gnu.org/copyleft/gpl.html
-
 /**
  * Runs the UTF-8 decoder test at:
  * http://www.cl.cam.ac.uk/~mgk25/ucs/examples/UTF-8-test.txt
  *
- * @addtogroup UtfNormal
- * @access private
+ * Copyright © 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.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @file
+ * @ingroup UtfNormal
  */
 
 /** */
@@ -30,6 +30,7 @@ require_once 'UtfNormalUtil.php';
 require_once 'UtfNormal.php';
 mb_internal_encoding( "utf-8" );
 
+$verbose = false;
 #$verbose = true;
 if( php_sapi_name() != 'cli' ) {
        die( "Run me from the command line please.\n" );
@@ -39,7 +40,7 @@ $in = fopen( "UTF-8-test.txt", "rt" );
 if( !$in ) {
        print "Couldn't open UTF-8-test.txt -- can't run tests.\n";
        print "If necessary, manually download this file. It can be obtained at\n";
-       print "http://www.cl.cam.ac.uk/~mgk25/ucs/examples/UTF-8-test.txt";
+       print "http://www.cl.cam.ac.uk/~mgk25/ucs/examples/UTF-8-test.txt\n";
        exit(-1);
 }
 
@@ -55,7 +56,7 @@ while( false !== ( $line = fgets( $in ) ) ) {
 if( !$columns ) {
        print "Something seems to be wrong; couldn't extract line length.\n";
        print "Check that UTF-8-test.txt was downloaded correctly from\n";
-       print "http://www.cl.cam.ac.uk/~mgk25/ucs/examples/UTF-8-test.txt";
+       print "http://www.cl.cam.ac.uk/~mgk25/ucs/examples/UTF-8-test.txt\n";
        exit(-1);
 }
 
@@ -81,7 +82,7 @@ $longTests = array(
 # These tests are not in proper subsections
 $sectionTests = array( '3.4' );
 
-$section = NULL;
+$section = null;
 $test = '';
 $failed = 0;
 $success = 0;
@@ -102,10 +103,10 @@ while( false !== ( $line = fgets( $in ) ) ) {
                if( in_array( $test, $longTests ) ) {
                        $line = fgets( $in );
                        for( $line = fgets( $in ); !preg_match( '/^\s+\|/', $line ); $line = fgets( $in ) ) {
-                               testLine( $test, $line, $total, $success, $failed );
+                               testLine( $test, $line, $total, $success, $failed, $columns, $exceptions, $verbose );
                        }
                } else {
-                       testLine( $test, $line, $total, $success, $failed );
+                       testLine( $test, $line, $total, $success, $failed, $columns, $exceptions, $verbose );
                }
        }
 }
@@ -120,7 +121,7 @@ echo "UTF-8 DECODER TEST SUCCESS!\n";
 exit (0);
 
 
-function testLine( $test, $line, &$total, &$success, &$failed ) {
+function testLine( $test, $line, &$total, &$success, &$failed, $columns, $exceptions, $verbose ) {
        $stripped = $line;
        UtfNormal::quickisNFCVerify( $stripped );
 
@@ -130,10 +131,8 @@ function testLine( $test, $line, &$total, &$success, &$failed ) {
                $len = strlen( substr( $stripped, 0, strpos( $stripped, '|' ) ) );
        }
 
-       global $columns;
        $ok = $same ^ ($test >= 3 );
 
-       global $exceptions;
        $ok ^= in_array( $test, $exceptions );
 
        $ok &= ($columns == $len);
@@ -144,10 +143,8 @@ function testLine( $test, $line, &$total, &$success, &$failed ) {
        } else {
                $failed++;
        }
-       global $verbose;
+
        if( $verbose || !$ok ) {
                print str_replace( "\n", "$len\n", $stripped );
        }
 }
-
-