eZ components PHP Cross Reference Developer Tools

Source: /Template/tests/scripts/permutation_whitespace_expression.php - 136 lines - 3645 bytes - Text - Print

   1  <?php
   2  
   3  require_once dirname( __FILE__ ) . "/permutation.php";
   4  
   5  // Writes to: regression_tests/expressions/correct/whitespace_usage_*.in
   6  
   7  $ws = alt( "", " \t", "\n" );
   8  $comment = alt( "/*c*/", "//c\n" );
   9  $wsComment = alt( clone $ws, clone $comment, clone $ws );
  10  $comments = alt( clone $ws, clone $comment/*, clone $wsComment*/ );
  11  
  12  $binOperators = alt( "+",
  13                       "-",
  14                       "*",
  15  //                     "/",
  16                       "%",
  17  
  18                       "==",
  19                       "===",
  20                       "!=",
  21                       "!==",
  22                       "<",
  23                       "<=",
  24                       ">",
  25                       ">=",
  26  
  27                       "&&",
  28                       "||",
  29  
  30                       "." );
  31  
  32  $binOperatorsSlash = alt( "/"
  33                            );
  34  
  35  $bins = perm( "5",
  36                alt( perm( clone $comments,
  37                           $binOperators,
  38                           clone $comments ),
  39                     perm( clone $comments,
  40                           $binOperatorsSlash,
  41                           " ",
  42                           $comments ) ),
  43                "5"
  44                );
  45  
  46  $main = perm( "[{",
  47                $bins,
  48                "}]\n"
  49                );
  50  
  51  $list = perm( "%num%:",
  52                $main
  53                );
  54  $dir = dirname( __FILE__ ) . "/../regression_tests/";
  55  
  56  $a = app( "expressions/correct/whitespace_usage_0001.in", $argv );
  57  
  58  $i = 1;
  59  $top = "";
  60  $topPHP = "";
  61  $phpCode = array( 1 => '' );
  62  $sendMap = array( 1 => false );
  63  
  64  // Invalid cases in PHP:
  65  // 5//*asdf*/5
  66  // 5. 5
  67  // 5 .5
  68  
  69  $block = 1;
  70  $a->output( $top );
  71  do
  72  {
  73      if ( $i > 1 &&
  74           ( ( $i - 1 ) % 50 ) == 0 )
  75      {
  76          $a->close();
  77          ++$block;
  78          $num2 = sprintf( "%04d", $block );
  79          $a->file = "expressions/correct/whitespace_usage_{$num2}.in";
  80          $phpCode[$block] = '';
  81          $a->output( $top );
  82      }
  83      $num = sprintf( "%04d", $i );
  84      $str = $list->generate();
  85      $binText = $bins->generate();
  86  
  87      // Some workarounds for strange PHP behaviour
  88      $binText = preg_replace( "#5\.([^5])#", "5 .\\1", $binText );
  89      $binText = preg_replace( "#([^5])\.5#", "\\1. 5", $binText );
  90  
  91      $str = str_replace( "%num%", $num, $str );
  92      $a->output( $str );
  93      if ( $main->index == 0 )
  94      {
  95          $phpCode[$block] .= ( "\$x = " . $binText . ";\n" .
  96                                "echo '$num:[', " );
  97          $phpCode[$block] .= "\$x, \"]\\n\";\n";
  98      }
  99      ++$i;
 100  } while ( $list->increase() );
 101  $a->close();
 102  
 103  if ( $a->outputToFile )
 104  {
 105      foreach ( $phpCode as $blockIndex => $phpCodeTmp )
 106      {
 107          $num2 = sprintf( "%04d", $blockIndex );
 108  
 109          $fileOut  = $dir . "expressions/correct/whitespace_usage_{$num2}.out";
 110          $filePHP  = $dir . "expressions/correct/whitespace_usage_{$num2}.php";
 111  
 112          $phpCodeTmp = ( "<?php\n// file: " . "expressions/correct/whitespace_usage.php" . "\n" .
 113                          $topPHP . $phpCodeTmp .
 114                          "?>" );
 115          $tmpFile = $a->store( $phpCodeTmp,
 116                                $filePHP );
 117          if ( $tmpFile !== false )
 118          {
 119              @system( "php -l $tmpFile >/dev/null", $status );
 120              if ( $status != 0 )
 121              {
 122                  throw new Exception( "The generated PHP file $tmpFile contains syntax errors" );
 123              }
 124  
 125              echo "php $tmpFile > $fileOut\n";
 126              @exec( "php $tmpFile > $fileOut", $shellOut, $status );
 127              if ( $status != 0 )
 128              {
 129                  throw new Exception( "The generated PHP file $tmpFile did not run properly" );
 130              }
 131              unlink( $tmpFile );
 132          }
 133      }
 134  }
 135  
 136  ?>

title

Description

title

Description

title

Description

title

title

Body