Index: trunk/phase3/tests/testHelpers.inc |
— | — | @@ -356,6 +356,7 @@ |
357 | 357 | private $index = 0; |
358 | 358 | private $test; |
359 | 359 | private $section = null; /** String|null: current test section being analyzed */ |
| 360 | + private $sectionData = array(); |
360 | 361 | private $lineNum; |
361 | 362 | private $eof; |
362 | 363 | |
— | — | @@ -410,8 +411,7 @@ |
411 | 412 | } |
412 | 413 | |
413 | 414 | function readNextTest() { |
414 | | - $data = array(); |
415 | | - $this->section = null; |
| 415 | + $this->clearSection(); |
416 | 416 | |
417 | 417 | while ( false !== ( $line = fgets( $this->fh ) ) ) { |
418 | 418 | $this->lineNum++; |
— | — | @@ -421,21 +421,20 @@ |
422 | 422 | $this->section = strtolower( $matches[1] ); |
423 | 423 | |
424 | 424 | if ( $this->section == 'endarticle' ) { |
425 | | - $this->checkSection( $data, 'text' ); |
426 | | - $this->checkSection( $data, 'article' ); |
| 425 | + $this->checkSection( 'text' ); |
| 426 | + $this->checkSection( 'article' ); |
427 | 427 | |
428 | | - $this->parserTest->addArticle( ParserTest::chomp( $data['article'] ), $data['text'], $this->lineNum ); |
| 428 | + $this->parserTest->addArticle( ParserTest::chomp( $this->sectionData['article'] ), $this->sectionData['text'], $this->lineNum ); |
429 | 429 | |
430 | | - $data = array(); |
431 | | - $this->section = null; |
| 430 | + $this->clearSection(); |
432 | 431 | |
433 | 432 | continue; |
434 | 433 | } |
435 | 434 | |
436 | 435 | if ( $this->section == 'endhooks' ) { |
437 | | - $this->checkSection( $data, 'hooks' ); |
| 436 | + $this->checkSection( 'hooks' ); |
438 | 437 | |
439 | | - foreach ( explode( "\n", $data['hooks'] ) as $line ) { |
| 438 | + foreach ( explode( "\n", $this->sectionData['hooks'] ) as $line ) { |
440 | 439 | $line = trim( $line ); |
441 | 440 | |
442 | 441 | if ( $line ) { |
— | — | @@ -445,16 +444,15 @@ |
446 | 445 | } |
447 | 446 | } |
448 | 447 | |
449 | | - $data = array(); |
450 | | - $this->section = null; |
| 448 | + $this->clearSection(); |
451 | 449 | |
452 | 450 | continue; |
453 | 451 | } |
454 | 452 | |
455 | 453 | if ( $this->section == 'endfunctionhooks' ) { |
456 | | - $this->checkSection( $data, 'functionhooks' ); |
| 454 | + $this->checkSection( 'functionhooks' ); |
457 | 455 | |
458 | | - foreach ( explode( "\n", $data['functionhooks'] ) as $line ) { |
| 456 | + foreach ( explode( "\n", $this->sectionData['functionhooks'] ) as $line ) { |
459 | 457 | $line = trim( $line ); |
460 | 458 | |
461 | 459 | if ( $line ) { |
— | — | @@ -464,55 +462,53 @@ |
465 | 463 | } |
466 | 464 | } |
467 | 465 | |
468 | | - $data = array(); |
469 | | - $this->section = null; |
| 466 | + $this->clearSection(); |
470 | 467 | |
471 | 468 | continue; |
472 | 469 | } |
473 | 470 | |
474 | 471 | if ( $this->section == 'end' ) { |
475 | | - $this->checkSection( $data, 'test' ); |
476 | | - $this->checkSection( $data, 'input' ); |
477 | | - $this->checkSection( $data, 'result' ); |
| 472 | + $this->checkSection( 'test' ); |
| 473 | + $this->checkSection( 'input' ); |
| 474 | + $this->checkSection( 'result' ); |
478 | 475 | |
479 | | - if ( !isset( $data['options'] ) ) { |
480 | | - $data['options'] = ''; |
| 476 | + if ( !isset( $this->sectionData['options'] ) ) { |
| 477 | + $this->sectionData['options'] = ''; |
481 | 478 | } |
482 | 479 | |
483 | | - if ( !isset( $data['config'] ) ) |
484 | | - $data['config'] = ''; |
| 480 | + if ( !isset( $this->sectionData['config'] ) ) |
| 481 | + $this->sectionData['config'] = ''; |
485 | 482 | |
486 | | - if ( ( ( preg_match( '/\\bdisabled\\b/i', $data['options'] ) && !$this->parserTest->runDisabled ) |
487 | | - || !preg_match( "/" . $this->parserTest->regex . "/i", $data['test'] ) ) ) { |
| 483 | + if ( ( ( preg_match( '/\\bdisabled\\b/i', $this->sectionData['options'] ) && !$this->parserTest->runDisabled ) |
| 484 | + || !preg_match( "/" . $this->parserTest->regex . "/i", $this->sectionData['test'] ) ) ) { |
488 | 485 | # disabled test |
489 | | - $data = array(); |
490 | | - $this->section = null; |
| 486 | + $this->clearSection(); |
491 | 487 | |
492 | 488 | continue; |
493 | 489 | } |
494 | 490 | |
495 | 491 | $this->test = array( |
496 | | - 'test' => ParserTest::chomp( $data['test'] ), |
497 | | - 'input' => ParserTest::chomp( $data['input'] ), |
498 | | - 'result' => ParserTest::chomp( $data['result'] ), |
499 | | - 'options' => ParserTest::chomp( $data['options'] ), |
500 | | - 'config' => ParserTest::chomp( $data['config'] ), |
| 492 | + 'test' => ParserTest::chomp( $this->sectionData['test'] ), |
| 493 | + 'input' => ParserTest::chomp( $this->sectionData['input'] ), |
| 494 | + 'result' => ParserTest::chomp( $this->sectionData['result'] ), |
| 495 | + 'options' => ParserTest::chomp( $this->sectionData['options'] ), |
| 496 | + 'config' => ParserTest::chomp( $this->sectionData['config'] ), |
501 | 497 | ); |
502 | 498 | |
503 | 499 | return true; |
504 | 500 | } |
505 | 501 | |
506 | | - if ( isset ( $data[$this->section] ) ) { |
| 502 | + if ( isset ( $this->sectionData[$this->section] ) ) { |
507 | 503 | throw new MWException( "duplicate section '$section' at line {$this->lineNum} of $this->file\n" ); |
508 | 504 | } |
509 | 505 | |
510 | | - $data[$this->section] = ''; |
| 506 | + $this->sectionData[$this->section] = ''; |
511 | 507 | |
512 | 508 | continue; |
513 | 509 | } |
514 | 510 | |
515 | 511 | if ( $this->section ) { |
516 | | - $data[$this->section] .= $line; |
| 512 | + $this->sectionData[$this->section] .= $line; |
517 | 513 | } |
518 | 514 | } |
519 | 515 | |
— | — | @@ -520,22 +516,29 @@ |
521 | 517 | } |
522 | 518 | |
523 | 519 | |
| 520 | + /** |
| 521 | + * Clear section name and its data |
| 522 | + */ |
| 523 | + private function clearSection() { |
| 524 | + $this->sectionData = array(); |
| 525 | + $this->section = null; |
| 526 | + |
| 527 | + } |
524 | 528 | |
525 | 529 | /** |
526 | | - * Verify the first parameter array ($data) has a value for the second |
527 | | - * parameter key name ($token). |
| 530 | + * Verify the current section data has some value for the given token |
| 531 | + * name (first parameter). |
528 | 532 | * Throw an exception if it is not set, referencing current section |
529 | 533 | * and adding the current file name and line number |
530 | 534 | * |
531 | | - * @param $data Array: an array of parser test data. See readNextTest() |
532 | 535 | * @param $token String: expected token that should have been mentionned before closing this section |
533 | 536 | */ |
534 | | - private function checkSection( $data, $token ) { |
| 537 | + private function checkSection( $token ) { |
535 | 538 | if( is_null( $this->section ) ) { |
536 | | - throw new MWException( __METHOD__ . " could not verify a null section!\n" ); |
| 539 | + throw new MWException( __METHOD__ . " can not verify a null section!\n" ); |
537 | 540 | } |
538 | 541 | |
539 | | - if( !isset($data[$token]) ) { |
| 542 | + if( !isset($this->sectionData[$token]) ) { |
540 | 543 | throw new MWException( sprintf( |
541 | 544 | "'%s' without '%s' at line %s of %s\n", |
542 | 545 | $this->section, |