2 # Copyright (C) 2004 Brion Vibber <brion@pobox.com> 3 # http://www.mediawiki.org/ 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. 18 # http://www.gnu.org/copyleft/gpl.html 28 #define( 'PRETTY_UTF8', true ); 30 if(
defined(
'PRETTY_UTF8' ) ) {
31 function pretty( $string ) {
32 return preg_replace_callback(
35 return sprintf(
"%02X", ord($hit[1]));
44 function pretty( $string ) {
45 return trim( preg_replace_callback(
56 dl(
'php_utfnormal.so' );
59 require_once
'include/Unicode/UtfNormal.php';
61 if( php_sapi_name() !=
'cli' ) {
62 die(
"Run me from the command line please.\n" );
65 $in = fopen(
"NormalizationTest.txt",
"rt");
67 print
"Couldn't open NormalizationTest.txt -- can't run tests.\n";
68 print
"If necessary, manually download this file. It can be obtained at\n";
69 print
"http://www.unicode.org/Public/UNIDATA/NormalizationTest.txt";
80 while(
false !== ( $line = fgets(
$in ) ) ) {
82 if(
$data ===
'' )
continue;
84 if( preg_match(
'/@Part([\d])/',
$data, $matches ) ) {
85 if( $matches[1] > 0 ) {
88 print
"Part {$matches[1]}: $comment";
92 $columns = array_map(
"hexSequenceToUtf8", explode(
";",
$data ) );
101 # print "FAILED: $comment"; 103 if(
$total % 100 == 0 ) print
"$total ";
109 $in = fopen(
"UnicodeData.txt",
"rt" );
111 print
"Can't open UnicodeData.txt for reading.\n";
112 print
"If necessary, fetch this file from the internet:\n";
113 print
"http://www.unicode.org/Public/UNIDATA/UnicodeData.txt\n";
116 print
"Now testing invariants...\n";
117 while(
false !== ($line = fgets(
$in ) ) ) {
118 $cols = explode(
';', $line );
120 $desc = $cols[0] .
": " . $cols[1];
122 # Can't check NULL with the ICU plugin, as null bytes fail in C land. 123 # Skip other control characters, as we strip them for XML safety. 124 # Surrogates are illegal on their own or in UTF-8, ignore. 134 if(
$total % 100 == 0 ) print
"$total ";
142 print
"TEST SUCCEEDED!\n";
145 print
"TEST FAILED!\n";
155 print
"$success tests successful ($percSucc%)\n";
156 print
"$failure tests failed ($percFail%)\n\n";
172 if( $verbose && !
$result && !$reportFailure ) {
180 #$result = ($a === $b); 181 $result = (strcmp( $a, $b ) == 0);
187 print
" $ok $form c$col '$aa' $eq '$bb'\n";
227 $result =
verbosify( $c[4], $u->toNFKC( $c[3] ), 3,
'NFKC',
$verbose ) && $result;
228 $result =
verbosify( $c[4], $u->toNFKC( $c[4] ), 4,
'NFKC',
$verbose ) && $result;
229 $result =
verbosify( $c[4], $u->toNFKC( $c[5] ), 5,
'NFKC',
$verbose ) && $result;
236 $result =
verbosify( $c[5], $u->toNFKD( $c[3] ), 3,
'NFKD',
$verbose ) && $result;
237 $result =
verbosify( $c[5], $u->toNFKD( $c[4] ), 4,
'NFKD',
$verbose ) && $result;
238 $result =
verbosify( $c[5], $u->toNFKD( $c[5] ), 5,
'NFKD',
$verbose ) && $result;
244 $result =
verbosify( $char, $u->toNFD( $char ), 1,
'NFD', $reportFailure ) && $result;
245 $result =
verbosify( $char, $u->toNFKC( $char ), 1,
'NFKC', $reportFailure ) && $result;
246 $result =
verbosify( $char, $u->toNFKD( $char ), 1,
'NFKD', $reportFailure ) && $result;
247 $result =
verbosify( $char, $u->cleanUp( $char ), 1,
'cleanUp', $reportFailure ) && $result;
249 if( $verbose && !$result && !$reportFailure ) {
testNFD(&$u, $c, $comment, $verbose)
if((!isset($_SERVER['DOCUMENT_ROOT'])) OR(empty($_SERVER['DOCUMENT_ROOT']))) $_SERVER['DOCUMENT_ROOT']
codepointToUtf8( $codepoint)
Return UTF-8 sequence for a given Unicode code point.
const UTF8_SURROGATE_FIRST
testInvariant(&$u, $char, $desc, $reportFailure=false)
utf8ToCodepoint( $char)
Determine the Unicode codepoint of a single-character UTF-8 sequence.
testNormals(&$u, $c, $comment, $reportFailure=false)
testNFKC(&$u, $c, $comment, $verbose)
testNFC(&$u, $c, $comment, $verbose)
verbosify( $a, $b, $col, $form, $verbose)
reportResults(&$total, &$success, &$failure)
Create styles array
The data for the language used.
testNFKD(&$u, $c, $comment, $verbose)
if(php_sapi_name() !='cli') $in
const UTF8_SURROGATE_LAST
defined( 'APPLICATION_ENV')||define( 'APPLICATION_ENV'
testCleanUp(&$u, $c, $comment, $verbose)