jenkins-bot has submitted this change and it was merged.
Change subject: Turn Utf8Test into a PHPUnit test case
......................................................................
Turn Utf8Test into a PHPUnit test case
Change-Id: I7e709f475a37a592fb3052f367894ebce32310f3
---
M includes/libs/normal/.gitignore
M includes/libs/normal/Makefile
D includes/libs/normal/Utf8Test.php
A tests/phpunit/data/normal/UTF-8-test.txt
A tests/phpunit/includes/libs/normal/Utf8Test.php
5 files changed, 123 insertions(+), 164 deletions(-)
Approvals:
Reedy: Looks good to me, approved
jenkins-bot: Verified
diff --git a/includes/libs/normal/.gitignore b/includes/libs/normal/.gitignore
index 0dea457..5af0afa 100644
--- a/includes/libs/normal/.gitignore
+++ b/includes/libs/normal/.gitignore
@@ -2,6 +2,5 @@
/DerivedNormalizationProps.txt
/NormalizationCorrections.txt
/NormalizationTest.txt
-/UTF-8-test.txt
/UnicodeData.txt
/testdata
diff --git a/includes/libs/normal/Makefile b/includes/libs/normal/Makefile
index 76cb68b..b00154d 100644
--- a/includes/libs/normal/Makefile
+++ b/includes/libs/normal/Makefile
@@ -21,11 +21,8 @@
UtfNormalData.inc : UtfNormalGenerate.php UtfNormalUtil.php UnicodeData.txt
CompositionExclusions.txt NormalizationCorrections.txt
DerivedNormalizationProps.txt
$(PHP) UtfNormalGenerate.php
-test : testutf8 UtfNormalTest.php UtfNormalData.inc NormalizationTest.txt
+test : UtfNormalTest.php UtfNormalData.inc NormalizationTest.txt
$(PHP) UtfNormalTest.php
-
-testutf8 : Utf8Test.php UTF-8-test.txt
- $(PHP) Utf8Test.php
bench : UtfNormalData.inc testdata/washington.txt testdata/berlin.txt
testdata/tokyo.txt testdata/young.txt testdata/bulgakov.txt
$(PHP) UtfNormalBench.php
@@ -58,9 +55,6 @@
UnicodeData.txt :
$(FETCH) $(BASE)/UnicodeData.txt
-
-UTF-8-test.txt :
- $(FETCH) http://www.cl.cam.ac.uk/~mgk25/ucs/examples/UTF-8-test.txt
testdata/berlin.txt :
mkdir -p testdata && wget -U MediaWiki/test -O testdata/berlin.txt
"http://de.wikipedia.org/w/index.php?title=Berlin&oldid=2775712&action=raw"
diff --git a/includes/libs/normal/Utf8Test.php
b/includes/libs/normal/Utf8Test.php
deleted file mode 100644
index f4acc1e..0000000
--- a/includes/libs/normal/Utf8Test.php
+++ /dev/null
@@ -1,156 +0,0 @@
-<?php
-/**
- * Runs the UTF-8 decoder test at:
- * http://www.cl.cam.ac.uk/~mgk25/ucs/examples/UTF-8-test.txt
- *
- * Copyright © 2004 Brion Vibber <[email protected]>
- * https://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
- */
-
-/** */
-
-if ( PHP_SAPI != 'cli' ) {
- die( "Run me from the command line please.\n" );
-}
-
-require_once 'UtfNormalDefines.php';
-require_once 'UtfNormalUtil.php';
-require_once 'UtfNormal.php';
-mb_internal_encoding( "utf-8" );
-
-$verbose = false;
-#$verbose = true;
-
-$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\n";
- exit( -1 );
-}
-
-$columns = 0;
-while ( false !== ( $line = fgets( $in ) ) ) {
- $matches = array();
- if ( preg_match( '/^(Here come the tests:\s*)\|$/', $line, $matches ) )
{
- $columns = strpos( $line, '|' );
- break;
- }
-}
-
-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\n";
- exit( -1 );
-}
-
-# print "$columns\n";
-
-$ignore = array(
- # These two lines actually seem to be corrupt
- '2.1.1', '2.2.1' );
-
-$exceptions = array(
- # Tests that should mark invalid characters due to using long
- # sequences beyond what is now considered legal.
- '2.1.5', '2.1.6', '2.2.4', '2.2.5', '2.2.6', '2.3.5',
-
- # Literal 0xffff, which is illegal
- '2.2.3' );
-
-$longTests = array(
- # These tests span multiple lines
- '3.1.9', '3.2.1', '3.2.2', '3.2.3', '3.2.4', '3.2.5',
- '3.4' );
-
-# These tests are not in proper subsections
-$sectionTests = array( '3.4' );
-
-$section = null;
-$test = '';
-$failed = 0;
-$success = 0;
-$total = 0;
-while ( false !== ( $line = fgets( $in ) ) ) {
- $matches = array();
- if ( preg_match( '/^(\d+)\s+(.*?)\s*\|/', $line, $matches ) ) {
- $section = $matches[1];
- print $line;
- continue;
- }
- if ( preg_match( '/^(\d+\.\d+\.\d+)\s*/', $line, $matches ) ) {
- $test = $matches[1];
-
- if ( in_array( $test, $ignore ) ) {
- continue;
- }
- if ( in_array( $test, $longTests ) ) {
- $line = fgets( $in );
-
- // @codingStandardsIgnoreStart
Generic.CodeAnalysis.ForLoopWithTestFunctionCall.NotAllowed
- for ( $line = fgets( $in ); !preg_match( '/^\s+\|/',
$line ); $line = fgets( $in ) ) {
- // @codingStandardsIgnoreEnd
-
- testLine( $test, $line, $total, $success,
$failed, $columns, $exceptions, $verbose );
- }
- } else {
- testLine( $test, $line, $total, $success, $failed,
$columns, $exceptions, $verbose );
- }
- }
-}
-
-if ( $failed ) {
- echo "\nFailed $failed tests.\n";
- echo "UTF-8 DECODER TEST FAILED\n";
- exit ( -1 );
-}
-
-echo "UTF-8 DECODER TEST SUCCESS!\n";
-exit ( 0 );
-
-function testLine( $test, $line, &$total, &$success, &$failed, $columns,
$exceptions, $verbose ) {
- $stripped = $line;
- UtfNormal::quickisNFCVerify( $stripped );
-
- $same = ( $line == $stripped );
- $len = mb_strlen( substr( $stripped, 0, strpos( $stripped, '|' ) ) );
- if ( $len == 0 ) {
- $len = strlen( substr( $stripped, 0, strpos( $stripped, '|' ) )
);
- }
-
- $ok = $same ^ ( $test >= 3 );
-
- $ok ^= in_array( $test, $exceptions );
-
- $ok &= ( $columns == $len );
-
- $total++;
- if ( $ok ) {
- $success++;
- } else {
- $failed++;
- }
-
- if ( $verbose || !$ok ) {
- print str_replace( "\n", "$len\n", $stripped );
- }
-}
diff --git a/tests/phpunit/data/normal/UTF-8-test.txt
b/tests/phpunit/data/normal/UTF-8-test.txt
new file mode 100644
index 0000000..abd16f7
--- /dev/null
+++ b/tests/phpunit/data/normal/UTF-8-test.txt
Binary files differ
diff --git a/tests/phpunit/includes/libs/normal/Utf8Test.php
b/tests/phpunit/includes/libs/normal/Utf8Test.php
new file mode 100644
index 0000000..86ae08e
--- /dev/null
+++ b/tests/phpunit/includes/libs/normal/Utf8Test.php
@@ -0,0 +1,122 @@
+<?php
+/**
+ * Runs the UTF-8 decoder test at:
+ * http://www.cl.cam.ac.uk/~mgk25/ucs/examples/UTF-8-test.txt
+ *
+ * Copyright © 2004 Brion Vibber <[email protected]>
+ * https://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
+ */
+
+class Utf8Test extends PHPUnit_Framework_TestCase {
+ public static function provideLines() {
+ global $IP;
+ $in = fopen( "$IP/tests/phpunit/data/normal/UTF-8-test.txt",
"rt" );
+
+ $columns = 0;
+ while ( false !== ( $line = fgets( $in ) ) ) {
+ $matches = array();
+ if ( preg_match( '/^(Here come the tests:\s*)\|$/',
$line, $matches ) ) {
+ $columns = strpos( $line, '|' );
+ break;
+ }
+ }
+
+ 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\n";
+ exit( -1 );
+ }
+
+
+ $ignore = array(
+ # These two lines actually seem to be corrupt
+ '2.1.1', '2.2.1' );
+
+ $exceptions = array(
+ # Tests that should mark invalid characters due to
using long
+ # sequences beyond what is now considered legal.
+ '2.1.5', '2.1.6', '2.2.4', '2.2.5', '2.2.6', '2.3.5',
+
+ # Literal 0xffff, which is illegal
+ '2.2.3' );
+
+ $longTests = array(
+ # These tests span multiple lines
+ '3.1.9', '3.2.1', '3.2.2', '3.2.3', '3.2.4', '3.2.5',
+ '3.4' );
+
+ $testCases = array();
+
+ $section = null;
+ while ( false !== ( $line = fgets( $in ) ) ) {
+ $matches = array();
+ if ( preg_match( '/^(\d+)\s+(.*?)\s*\|/', $line,
$matches ) ) {
+ continue;
+ }
+ if ( preg_match( '/^(\d+\.\d+\.\d+)\s*/', $line,
$matches ) ) {
+ $test = $matches[1];
+
+ if ( in_array( $test, $ignore ) ) {
+ continue;
+ }
+ if ( in_array( $test, $longTests ) ) {
+ fgets( $in );
+
+ // @codingStandardsIgnoreStart
Generic.CodeAnalysis.ForLoopWithTestFunctionCall.NotAllowed
+ for ( $line = fgets( $in );
!preg_match( '/^\s+\|/', $line ); $line = fgets( $in ) ) {
+ // @codingStandardsIgnoreEnd
+
+ $testCases[] = array( $test,
$line, $columns, $exceptions );
+ }
+ } else {
+ $testCases[] = array( $test, $line,
$columns, $exceptions );
+ }
+ }
+ }
+
+ return $testCases;
+ }
+
+
+ /**
+ * @dataProvider provideLines
+ */
+ function testLine( $test, $line, $columns, $exceptions ) {
+ $stripped = $line;
+ UtfNormal::quickisNFCVerify( $stripped );
+
+ $same = ( $line == $stripped );
+ $len = mb_strlen( substr( $stripped, 0, strpos( $stripped, '|'
) ) );
+ if ( $len == 0 ) {
+ $len = strlen( substr( $stripped, 0, strpos( $stripped,
'|' ) ) );
+ }
+
+ $ok = $same ^ ( $test >= 3 );
+
+ $ok ^= in_array( $test, $exceptions );
+
+ $ok &= ( $columns == $len );
+
+ $this->assertEquals( 1, $ok );
+ }
+
+}
--
To view, visit https://gerrit.wikimedia.org/r/183300
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I7e709f475a37a592fb3052f367894ebce32310f3
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Legoktm <[email protected]>
Gerrit-Reviewer: Reedy <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits