2# Copyright (C) 2004 Brion Vibber <brion@pobox.com> 
    5# This program is free software; you can redistribute it and/or modify 
    6# it under the terms of the GNU General Public License as published by 
    7# the Free Software Foundation; either version 2 of the License, or 
    8# (at your option) any later version. 
   10# This program is distributed in the hope that it will be useful, 
   11# but WITHOUT ANY WARRANTY; without even the implied warranty of 
   12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 
   13# GNU General Public License for more details. 
   15# You should have received a copy of the GNU General Public License along 
   16# with this program; if not, write to the Free Software Foundation, Inc., 
   17# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 
   29require_once 
'include/Unicode/UtfNormal.php';
 
   30mb_internal_encoding( 
"utf-8" );
 
   33if( php_sapi_name() != 
'cli' ) {
 
   34        die( 
"Run me from the command line please.\n" );
 
   37$in = fopen( 
"UTF-8-test.txt", 
"rt" );
 
   39        print "Couldn't open UTF-8-test.txt -- can't run tests.\n";
 
   40        print "If necessary, manually download this file. It can be obtained at\n";
 
   41        print "http://www.cl.cam.ac.uk/~mgk25/ucs/examples/UTF-8-test.txt";
 
   46while( 
false !== ( $line = fgets( 
$in ) ) ) {
 
   48        if( preg_match( 
'/^(Here come the tests:\s*)\|$/', $line, $matches ) ) {
 
   55        print "Something seems to be wrong; couldn't extract line length.\n";
 
   56        print "Check that UTF-8-test.txt was downloaded correctly from\n";
 
   57        print "http://www.cl.cam.ac.uk/~mgk25/ucs/examples/UTF-8-test.txt";
 
   64        # These two lines actually seem to be corrupt
 
   68        # Tests that should mark invalid characters due to 
using long 
   69        # sequences beyond what is now considered legal.
 
   70        '2.1.5', 
'2.1.6', 
'2.2.4', 
'2.2.5', 
'2.2.6', 
'2.3.5',
 
   72        # Literal 0xffff, which is illegal
 
   76        # These tests span multiple lines
 
   77        '3.1.9', 
'3.2.1', 
'3.2.2', 
'3.2.3', 
'3.2.4', 
'3.2.5',
 
   80# These tests are not in proper subsections 
   88while( 
false !== ( $line = fgets( 
$in ) ) ) {
 
   90        if( preg_match( 
'/^(\d+)\s+(.*?)\s*\|/', $line, $matches ) ) {
 
   95        if( preg_match( 
'/^(\d+\.\d+\.\d+)\s*/', $line, $matches ) ) {
 
  102                        $line = fgets( 
$in );
 
  103                        for( $line = fgets( 
$in ); !preg_match( 
'/^\s+\|/', $line ); $line = fgets( 
$in ) ) {
 
  113        echo 
"\nFailed $failed tests.\n";
 
  114        echo 
"UTF-8 DECODER TEST FAILED\n";
 
  118echo 
"UTF-8 DECODER TEST SUCCESS!\n";
 
  124        UtfNormal::quickisNFCVerify( $stripped );
 
  126        $same = ( $line == $stripped );
 
  127        $len = mb_strlen( substr( $stripped, 0, strpos( $stripped, 
'|' ) ) );
 
  129                $len = strlen( substr( $stripped, 0, strpos( $stripped, 
'|' ) ) );
 
  148                print str_replace( 
"\n", 
"$len\n", $stripped );
 
testLine( $test, $line, &$total, &$success, &$failed)
if(php_sapi_name() !='cli') $in
while(false !==($line=fgets($in))) if(! $columns) $ignore
An exception for terminatinating execution or to throw for unit testing.