2009-02-12 22:29:32 +00:00
|
|
|
<?php
|
|
|
|
|
2010-10-02 22:36:34 +00:00
|
|
|
require_once ( getenv( 'MW_INSTALL_PATH' ) !== false
|
|
|
|
? getenv( 'MW_INSTALL_PATH' ) . "/maintenance/commandLine.inc"
|
2009-02-12 22:29:32 +00:00
|
|
|
: dirname( __FILE__ ) . '/../../maintenance/commandLine.inc' );
|
|
|
|
require( 'Expr.php' );
|
2010-10-02 22:36:34 +00:00
|
|
|
|
2009-02-12 22:29:32 +00:00
|
|
|
$tests = file( 'exprTests.txt' );
|
|
|
|
|
|
|
|
$pass = $fail = 0;
|
|
|
|
|
|
|
|
// Each test is on one line. The test must always evaluate to '1'.
|
|
|
|
$parser = new ExprParser;
|
2010-10-02 22:36:34 +00:00
|
|
|
foreach ( $tests as $test ) {
|
|
|
|
$test = trim( $test );
|
2009-02-12 22:29:32 +00:00
|
|
|
if ( in_string( ';', $test ) )
|
2010-10-02 22:36:34 +00:00
|
|
|
list( $input, $expected ) = explode( ';', $test );
|
2009-02-12 22:29:32 +00:00
|
|
|
else {
|
|
|
|
$input = $test;
|
|
|
|
$expected = 1;
|
|
|
|
}
|
2010-10-02 22:36:34 +00:00
|
|
|
|
|
|
|
$expected = trim( $expected );
|
|
|
|
$input = trim( $input );
|
2009-02-12 22:29:32 +00:00
|
|
|
|
|
|
|
$result = $parser->doExpression( $input );
|
2010-10-02 22:36:34 +00:00
|
|
|
if ( $result != $expected ) {
|
2009-02-12 22:29:32 +00:00
|
|
|
print
|
|
|
|
"FAILING test -- $input
|
|
|
|
gave a final result of $result, instead of $expected.\n";
|
|
|
|
$fail++;
|
|
|
|
} else {
|
|
|
|
print "PASSED test $test\n";
|
|
|
|
$pass++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-10-02 22:36:34 +00:00
|
|
|
print "Passed $pass tests, failed $fail tests, out of a total of " . ( $pass + $fail ) . "\n";
|