28 if( PHP_SAPI !=
'cli' ) {
29 die(
"Run me from the command line please.\n" );
33 #define( 'PRETTY_UTF8', true );
35 if( defined(
'PRETTY_UTF8' ) ) {
36 function pretty( $string ) {
37 return strtoupper( bin2hex( $string ) );
45 function pretty( $string ) {
50 if( isset( $_SERVER[
'argv'] ) && in_array(
'--icu', $_SERVER[
'argv'] ) ) {
51 dl(
'php_utfnormal.so' );
54 require_once
'UtfNormalDefines.php';
55 require_once
'UtfNormalUtil.php';
56 require_once
'UtfNormal.php';
58 $in = fopen(
"NormalizationTest.txt",
"rt");
60 print
"Couldn't open NormalizationTest.txt -- can't run tests.\n";
61 print
"If necessary, manually download this file. It can be obtained at\n";
62 print
"http://www.unicode.org/Public/UNIDATA/NormalizationTest.txt";
73 while(
false !== (
$line = fgets(
$in ) ) ) {
75 if( $data ===
'' )
continue;
77 if( preg_match(
'/@Part([\d])/', $data,
$matches ) ) {
81 print
"Part {$matches[1]}: $comment";
85 $columns = array_map(
"hexSequenceToUtf8", explode(
";", $data ) );
94 # print "FAILED: $comment";
96 if(
$total % 100 == 0 ) print
"$total ";
102 $in = fopen(
"UnicodeData.txt",
"rt" );
104 print
"Can't open UnicodeData.txt for reading.\n";
105 print
"If necessary, fetch this file from the internet:\n";
106 print
"http://www.unicode.org/Public/UNIDATA/UnicodeData.txt\n";
109 print
"Now testing invariants...\n";
110 while(
false !== (
$line = fgets(
$in ) ) ) {
111 $cols = explode(
';',
$line );
113 $desc = $cols[0] .
": " . $cols[1];
115 # Can't check NULL with the ICU plugin, as null bytes fail in C land.
116 # Skip other control characters, as we strip them for XML safety.
117 # Surrogates are illegal on their own or in UTF-8, ignore.
127 if(
$total % 100 == 0 ) print
"$total ";
135 print
"TEST SUCCEEDED!\n";
138 print
"TEST FAILED!\n";
148 print
"$success tests successful ($percSucc%)\n";
149 print
"$failure tests failed ($percFail%)\n\n";
172 #$result = ($a === $b);
173 $result = (strcmp( $a, $b ) == 0);
179 print
" $ok $form c$col '$aa' $eq '$bb'\n";