* Made it possible to configure the parser class being used, via $wgParserConf. * Moved defines from the top of Parser.php to either class constants or Defines.php * Added Parser_DiffTest, a differential parser class for regression testing * Added Parser_OldPP, a parser class which operates like the parser before this commit. I made one breaking change: a bugfix to avoid losing whitespace when adding MWTEMPLATESECTION markers. * Made internal tidy work with PHP 5 * Added the ability to supply a hook for template fetching via ParserOptions. This is handy for testing. * Updated parserTests.txt to account for the various breaking changes I made. Removed a few parser tests that no longer test for anything useful.
62 lines
1.5 KiB
PHP
62 lines
1.5 KiB
PHP
<?php
|
|
|
|
class Parser_DiffTest
|
|
{
|
|
var $parsers, $conf;
|
|
|
|
function __construct( $conf ) {
|
|
if ( !isset( $conf['parsers'] ) ) {
|
|
throw new MWException( __METHOD__ . ': no parsers specified' );
|
|
}
|
|
$this->conf = $conf;
|
|
}
|
|
|
|
function init() {
|
|
if ( !is_null( $this->parsers ) ) {
|
|
return;
|
|
}
|
|
foreach ( $this->conf['parsers'] as $i => $parserConf ) {
|
|
if ( !is_array( $parserConf ) ) {
|
|
$class = $parserConf;
|
|
$parserconf = array( 'class' => $parserConf );
|
|
} else {
|
|
$class = $parserConf['class'];
|
|
}
|
|
$this->parsers[$i] = new $class( $parserConf );
|
|
}
|
|
}
|
|
|
|
function __call( $name, $args ) {
|
|
$this->init();
|
|
$results = array();
|
|
$mismatch = false;
|
|
$lastResult = null;
|
|
$first = true;
|
|
foreach ( $this->parsers as $i => $parser ) {
|
|
$currentResult = call_user_func_array( array( &$this->parsers[$i], $name ), $args );
|
|
if ( $first ) {
|
|
$first = false;
|
|
} else {
|
|
if ( $lastResult !== $currentResult ) {
|
|
$mismatch = true;
|
|
}
|
|
}
|
|
$results[$i] = $currentResult;
|
|
$lastResult = $currentResult;
|
|
}
|
|
if ( $mismatch ) {
|
|
throw new MWException( "Parser_DiffTest: results mismatch on call to $name\n" .
|
|
'Arguments: ' . var_export( $args, true ) . "\n" .
|
|
'Results: ' . var_export( $results, true ) . "\n" );
|
|
}
|
|
return $lastResult;
|
|
}
|
|
|
|
function setFunctionHook( $id, $callback, $flags = 0 ) {
|
|
$this->init();
|
|
foreach ( $this->parsers as $i => $parser ) {
|
|
$parser->setFunctionHook( $id, $callback, $flags );
|
|
}
|
|
}
|
|
}
|
|
|