eZ components PHP Cross Reference Developer Tools

Source: /Template/tests/scripts/permutation_expressions_bin_operators.php - 212 lines - 5867 bytes - Text - Print

   1  <?php
   2  
   3  require_once dirname( __FILE__ ) . "/permutation.php";
   4  
   5  // Writes to: regression_tests/expressions/correct/binary_operators_*.in
   6  
   7  $binOperators = alt( "+",
   8                       "-",
   9                       "*",
  10                       "/",
  11                       "%",
  12  
  13                       "==",
  14                       "===",
  15                       "!=",
  16                       "!==",
  17                       "<",
  18                       "<=",
  19                       ">",
  20                       ">=",
  21  
  22                       "&&",
  23                       "||",
  24  
  25                       "." );
  26  $binOperators2 = clone $binOperators;
  27  $binOperators3 = clone $binOperators;
  28  $binOperators4 = clone $binOperators;
  29  
  30  $objectOperators = alt( "->" );
  31  
  32  $constValues = alt( "5",
  33                      "-\$foo"
  34                      );
  35  
  36  $bin = perm( clone $constValues,
  37               " ",
  38               $binOperators2,
  39               " ",
  40               clone $constValues );
  41  
  42  $object = perm( "\$obj",
  43                  " ",
  44                  $objectOperators,
  45                  " ",
  46                  "foo"
  47                  );
  48  
  49  $array = perm( "\$arr['foo']"
  50                 );
  51  
  52  $bin2 = perm( // clone $constValues,
  53                "\$foo",
  54                " ",
  55                $binOperators3,
  56                " ",
  57  //              clone $constValues
  58                5
  59                );
  60  
  61  $comboLeft = alt( clone $bin2,
  62                    $object,
  63                    $array );
  64  
  65  $binCombination = perm( alt( "( ",
  66                               "!( " ),
  67                          $comboLeft,
  68                          " ) ",
  69                          $binOperators4,
  70                          " ",
  71                          clone $constValues
  72  //                     clone $bin2
  73                          );
  74  
  75  $bins = alt( $bin,
  76               $binCombination
  77               );
  78  
  79  $main = alt( perm( "[{debug_dump( ",
  80                     $bins,
  81                     " )}]\n" )
  82               );
  83  
  84  $list = perm( "%num%:",
  85                $main
  86                );
  87  
  88  // special tests
  89  // $a == $b == $c (should produce proper PHP code ) => ($a == $b) == $c
  90  // $a = $b = $c (should produce proper PHP code) $a = ($b = $c)
  91  
  92  $dir = dirname( __FILE__ ) . "/../regression_tests/";
  93  
  94  $a = app( "expressions/correct/binary_operators_0001.in", $argv );
  95  
  96  $objCode = ( "if ( !class_exists( 'ezcTemplateTestBinOpMyClass', false ) )\n" .
  97               "{\n" .
  98               "  class ezcTemplateTestBinOpMyClass\n" .
  99               "  {\n" .
 100               "    public \$foo = 301;\n" .
 101               "  }\n" .
 102               "}\n" .
 103               "\$obj = new ezcTemplateTestBinOpMyClass();\n" );
 104  $objCodeSend = ( $objCode .
 105                   "\$v = new ezcTemplateVariableCollection();\n" .
 106                   "\$v->obj = \$obj;\n" .
 107                   "return \$v;\n" );
 108  
 109  
 110  $i = 1;
 111  $topObj = "{use \$obj}\n";
 112  $top = "{var \$foo = 42, \$bar = 101, \$bar2 = 201, \$arr = array( 'foo' => 401 )}\n";
 113  $topPHP = "\$foo = 42; \$bar = 101; \$bar2 = 201; \$arr = array( 'foo' => 401 );\n";
 114  $phpCode = array( 1 => '' );
 115  $sendMap = array( 1 => false );
 116  
 117  $block = 1;
 118  $a->output( $top );
 119  do
 120  {
 121      if ( $i > 1 &&
 122           ( ( $i - 1 ) % 32 ) == 0 )
 123      {
 124          $a->close();
 125          ++$block;
 126          $sendMap[$block] = $comboLeft->index == 1;
 127          $needUse = $sendMap[$block];
 128          $num2 = sprintf( "%04d", $block );
 129          $a->file = "expressions/correct/binary_operators_{$num2}.in";
 130          $phpCode[$block] = '';
 131          if ( $needUse )
 132          {
 133              $a->output( $topObj );
 134          }
 135          $a->output( $top );
 136      }
 137      $num = sprintf( "%04d", $i );
 138      $str = $list->generate();
 139      $str = str_replace( "%num%", $num, $str );
 140      $willBeFloat = false;
 141      if ( $binOperators2->index == 3 ||
 142           $binOperators3->index == 3 ||
 143           $binOperators4->index == 3 )
 144      {
 145          $willBeFloat = true;
 146      }
 147      if ( $willBeFloat )
 148      {
 149          $str = str_replace( "debug_dump(", "str_number(", $str );
 150          $str = str_replace( ")}", ", 2, ',', '' )}", $str );
 151      }
 152      $a->output( $str );
 153      if ( $main->index == 0 )
 154      {
 155          $phpCode[$block] .= ( "\$x = " . $bins->generate() . ";\n" .
 156                                "echo '$num:[', " );
 157          if ( $willBeFloat )
 158          {
 159              $phpCode[$block] .= "number_format( \$x, 2, ',', '' ), \"]\\n\";\n";
 160          }
 161          else
 162          {
 163              $phpCode[$block] .= "var_export( \$x, true ), \"]\\n\";\n";
 164          }
 165      }
 166      ++$i;
 167  } while ( $list->increase() );
 168  $a->close();
 169  
 170  if ( $a->outputToFile )
 171  {
 172      foreach ( $phpCode as $blockIndex => $phpCodeTmp )
 173      {
 174          $num2 = sprintf( "%04d", $blockIndex );
 175  
 176          $fileOut  = $dir . "expressions/correct/binary_operators_{$num2}.out";
 177          $filePHP  = $dir . "expressions/correct/binary_operators_{$num2}.php";
 178          $fileSend = $dir . "expressions/correct/binary_operators_{$num2}.send";
 179  
 180          if ( $sendMap[$blockIndex] )
 181          {
 182              // $comboLeft
 183              $a->store( "<?php\n" .
 184                         $objCodeSend . "\n?>",
 185                         $fileSend );
 186          }
 187          $phpCodeTmp = ( "<?php\n// file: " . "expressions/correct/binary_operators.php" . "\n" .
 188                       $objCode .
 189                       $topPHP . $phpCodeTmp .
 190                       "?>" );
 191          $tmpFile = $a->store( $phpCodeTmp,
 192                                $filePHP );
 193          if ( $tmpFile !== false )
 194          {
 195              @system( "php -l $tmpFile >/dev/null", $status );
 196              if ( $status != 0 )
 197              {
 198                  throw new Exception( "The generated PHP file $tmpFile contains syntax errors" );
 199              }
 200  
 201              echo "php $tmpFile > $fileOut\n";
 202              @exec( "php $tmpFile > $fileOut", $shellOut, $status );
 203              if ( $status != 0 )
 204              {
 205                  throw new Exception( "The generated PHP file $tmpFile did not run properly" );
 206              }
 207              unlink( $tmpFile );
 208          }
 209      }
 210  }
 211  
 212  ?>

title

Description

title

Description

title

Description

title

title

Body