extractParserTests.php 921 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. #!/usr/bin/env php
  2. <?php
  3. $lines = file( dirname( __FILE__ ) . '/parserTests.txt' );
  4. $lineCount = count( $lines );
  5. $test = null;
  6. $testNr = 0;
  7. for ( $nr = 0; $nr < $lineCount; ++$nr )
  8. {
  9. switch ( trim( $lines[$nr] ) )
  10. {
  11. case '!! test':
  12. $test = sprintf( 's_%03d_%s.txt',
  13. ++$testNr,
  14. preg_replace( '([^0-9a-zA-Z]+)', '_', trim( $lines[$nr + 1] ) )
  15. );
  16. break;
  17. case '!! input':
  18. if ( $test !== null )
  19. {
  20. $fp = fopen( $test, 'w' );
  21. ++$nr;
  22. while ( ( trim( $lines[$nr] ) !== '!! result' ) &&
  23. ( trim( $lines[$nr] ) !== '!! end' ) )
  24. {
  25. fwrite( $fp, $lines[$nr++] );
  26. }
  27. fclose( $fp );
  28. }
  29. $test = null;
  30. break;
  31. }
  32. }
  33. ?>