Annotation of embedaddon/php/tests/lang/023-1.inc, revision 1.1

1.1     ! misho       1: <html>
        !             2: <head>
        !             3: <?php
        !             4: /* the point of this file is to intensively test various aspects of
        !             5:  * the parser.  right now, each test focuses in one aspect only
        !             6:  * (e.g. variable aliasing, arithemtic operator, various control
        !             7:  * structures), while trying to combine code from other parts of the
        !             8:  * parser as well.
        !             9:  */
        !            10: ?>
        !            11: 
        !            12: *** Testing assignments and variable aliasing: ***<br>
        !            13: <?php 
        !            14:   /* This test tests assignments to variables using other variables as variable-names */
        !            15:   $a = "b"; 
        !            16:   $$a = "test"; 
        !            17:   $$$a = "blah"; 
        !            18:   ${$$$a}["associative arrays work too"] = "this is nifty";
        !            19: ?>
        !            20: This should read "blah": <?php echo "$test<br>\n"; ?>
        !            21: This should read "this is nifty": <?php echo $blah[$test="associative arrays work too"]."<br>\n"; ?>
        !            22: *************************************************<br>
        !            23: 
        !            24: *** Testing integer operators ***<br>
        !            25: <?php 
        !            26:   /* test just about any operator possible on $i and $j (ints) */
        !            27:   $i = 5;
        !            28:   $j = 3;
        !            29: ?>
        !            30: Correct result - 8:  <?php echo $i+$j; ?><br>
        !            31: Correct result - 8:  <?php echo $i+$j; ?><br>
        !            32: Correct result - 2:  <?php echo $i-$j; ?><br>
        !            33: Correct result - -2:  <?php echo $j-$i; ?><br>
        !            34: Correct result - 15:  <?php echo $i*$j; ?><br>
        !            35: Correct result - 15:  <?php echo $j*$i; ?><br>
        !            36: Correct result - 2:  <?php echo $i%$j; ?><br>
        !            37: Correct result - 3:  <?php echo $j%$i; ?><br>
        !            38: *********************************<br>
        !            39: 
        !            40: *** Testing real operators ***<br>
        !            41: <?php 
        !            42:   /* test just about any operator possible on $i and $j (floats) */
        !            43:   $i = 5.0;
        !            44:   $j = 3.0;
        !            45: ?>
        !            46: Correct result - 8:  <?php echo $i+$j; ?><br>
        !            47: Correct result - 8:  <?php echo $i+$j; ?><br>
        !            48: Correct result - 2:  <?php echo $i-$j; ?><br>
        !            49: Correct result - -2:  <?php echo $j-$i; ?><br>
        !            50: Correct result - 15:  <?php echo $i*$j; ?><br>
        !            51: Correct result - 15:  <?php echo $j*$i; ?><br>
        !            52: Correct result - 2:  <?php echo $i%$j; ?><br>
        !            53: Correct result - 3:  <?php echo $j%$i; ?><br>
        !            54: *********************************<br>
        !            55: 
        !            56: *** Testing if/elseif/else control ***<br>
        !            57: 
        !            58: <?php 
        !            59: /* sick if/elseif/else test by Andi :) */
        !            60: $a = 5;
        !            61: if ($a == "4") {
        !            62:        echo "This "." does "."  not "." work<br>\n";
        !            63: } elseif ($a == "5") {
        !            64:        echo "This "." works<br>\n";
        !            65:        $a = 6;
        !            66:        if ("andi" == ($test = "andi")) {
        !            67:                echo "this_still_works<br>\n";
        !            68:        } elseif (1) {
        !            69:                echo "should_not_print<br>\n";
        !            70:        } else {
        !            71:                echo "should_not_print<br>\n";
        !            72:        }
        !            73:         if (44 == 43) {
        !            74:                echo "should_not_print<br>\n";
        !            75:        } else {
        !            76:                echo "should_print<br>\n";
        !            77:        }
        !            78: } elseif ($a == 6) {
        !            79:        echo "this "."broken<br>\n";
        !            80:        if (0) {
        !            81:                echo "this_should_not_print<br>\n";
        !            82:        } else {
        !            83:                echo "TestingDanglingElse_This_Should_not_print<br>\n";
        !            84:        }
        !            85: } else {
        !            86:        echo "This "."does "." not"." work<br>\n";
        !            87: }
        !            88: ?>
        !            89: 
        !            90: 
        !            91: *** Seriously nested if's test ***<br>
        !            92: ** spelling correction by kluzz **
        !            93: <?php 
        !            94: /* yet another sick if/elseif/else test by Zeev */
        !            95: $i=$j=0;
        !            96: echo "Only two lines of text should follow:<br>\n";
        !            97: if (0) { /* this code is not supposed to be executed */
        !            98:   echo "hmm, this shouldn't be displayed #1<br>\n";
        !            99:   $j++;
        !           100:   if (1) {
        !           101:     $i 
        !           102: +=
        !           103:  $j;
        !           104:     if (0) {
        !           105:       $j = ++$i;
        !           106:       if (1) {
        !           107:         $j *= $i;
        !           108:         echo "damn, this shouldn't be displayed<br>\n";
        !           109:       } else {
        !           110:         $j /= $i;
        !           111:         ++$j;
        !           112:         echo "this shouldn't be displayed either<br>\n";
        !           113:       }
        !           114:     } elseif (1) {
        !           115:       $i++; $j++;
        !           116:       echo "this isn't supposed to be displayed<br>\n";
        !           117:     }
        !           118:   } elseif (0) {
        !           119:     $i++;
        !           120:     echo "this definitely shouldn't be displayed<br>\n";
        !           121:   } else {
        !           122:     --$j;
        !           123:     echo "and this too shouldn't be displayed<br>\n";
        !           124:     while ($j>0) {
        !           125:       $j--;
        !           126:     }
        !           127:   }
        !           128: } elseif (2-2) {  /* as long as 2-2==0, this isn't supposed to be executed either */
        !           129:   $i = ++$j;
        !           130:   echo "hmm, this shouldn't be displayed #2<br>\n";
        !           131:   if (1) { 
        !           132:     $j = ++$i;
        !           133:     if (0) {
        !           134:       $j = $i*2+$j*($i++);
        !           135:       if (1) {
        !           136:         $i++;
        !           137:         echo "damn, this shouldn't be displayed<br>\n";
        !           138:       } else {
        !           139:         $j++;
        !           140:         echo "this shouldn't be displayed either<br>\n";
        !           141:       }
        !           142:     } else if (1) {
        !           143:       ++$j;
        !           144:       echo "this isn't supposed to be displayed<br>\n";
        !           145:     }
        !           146:   } elseif (0) {
        !           147:     $j++;
        !           148:     echo "this definitely shouldn't be displayed<br>\n";
        !           149:   } else {
        !           150:     $i++;
        !           151:     echo "and this too shouldn't be displayed<br>\n";
        !           152:   }
        !           153: } else {
        !           154:   $j=$i++;  /* this should set $i to 1, but shouldn't change $j (it's assigned $i's previous values, zero) */
        !           155:   echo "this should be displayed. should be:  \$i=1, \$j=0.  is:  \$i=$i, \$j=$j<br>\n";
        !           156:   if (1) {
        !           157:     $j += ++$i;  /* ++$i --> $i==2,  $j += 2 --> $j==2 */
        !           158:     if (0) {
        !           159:       $j += 40;
        !           160:       if (1) {
        !           161:         $i += 50;
        !           162:         echo "damn, this shouldn't be displayed<br>\n";
        !           163:       } else {
        !           164:         $j += 20;
        !           165:         echo "this shouldn't be displayed either<br>\n";
        !           166:       }
        !           167:     } else if (1) {
        !           168:       $j *= $i;  /* $j *= 2  --> $j == 4 */
        !           169:       echo "this is supposed to be displayed. should be:  \$i=2, \$j=4.  is:  \$i=$i, \$j=$j<br>\n";
        !           170:       echo "3 loop iterations should follow:<br>\n";
        !           171:       while ($i<=$j) {
        !           172:         echo $i++." $j<br>\n";
        !           173:       }
        !           174:     }
        !           175:   } elseif (0) {
        !           176:     echo "this definitely shouldn't be displayed<br>\n";
        !           177:   } else {
        !           178:     echo "and this too shouldn't be displayed<br>\n";
        !           179:   }
        !           180:   echo "**********************************<br>\n";
        !           181: }
        !           182: ?>
        !           183: 
        !           184: *** C-style else-if's ***<br>
        !           185: <?php 
        !           186:   /* looks like without we even tried, C-style else-if structure works fine! */
        !           187:   if ($a=0) {
        !           188:     echo "This shouldn't be displayed<br>\n";
        !           189:   } else if ($a++) {
        !           190:     echo "This shouldn't be displayed either<br>\n";
        !           191:   } else if (--$a) {
        !           192:     echo "No, this neither<br>\n";
        !           193:   } else if (++$a) {
        !           194:     echo "This should be displayed<br>\n";
        !           195:   } else {
        !           196:     echo "This shouldn't be displayed at all<br>\n";
        !           197:   }
        !           198: ?>
        !           199: *************************<br>
        !           200: 
        !           201: *** WHILE tests ***<br>
        !           202: <?php 
        !           203: $i=0;
        !           204: $j=20;
        !           205: while ($i<(2*$j)) {
        !           206:   if ($i>$j) {
        !           207:     echo "$i is greater than $j<br>\n";
        !           208:   } else if ($i==$j) {
        !           209:     echo "$i equals $j<br>\n";
        !           210:   } else {
        !           211:     echo "$i is smaller than $j<br>\n";
        !           212:   }
        !           213:   $i++;
        !           214: }
        !           215: ?>
        !           216: *******************<br>
        !           217: 
        !           218: 
        !           219: *** Nested WHILEs ***<br>
        !           220: <?php 
        !           221: $arr_len=3;
        !           222: 
        !           223: $i=0;
        !           224: while ($i<$arr_len) {
        !           225:   $j=0;
        !           226:   while ($j<$arr_len) {
        !           227:     $k=0;
        !           228:     while ($k<$arr_len) {
        !           229:       ${"test$i$j"}[$k] = $i+$j+$k;
        !           230:       $k++;
        !           231:     }
        !           232:     $j++;
        !           233:   }
        !           234:   $i++;
        !           235: }
        !           236: 
        !           237: echo "Each array variable should be equal to the sum of its indices:<br>\n";
        !           238: 
        !           239: $i=0;
        !           240: while ($i<$arr_len) {
        !           241:   $j=0;
        !           242:   while ($j<$arr_len) {
        !           243:     $k=0;
        !           244:     while ($k<$arr_len) {
        !           245:       echo "\${test$i$j}[$k] = ".${"test$i$j"}[$k]."<br>\n";
        !           246:       $k++;
        !           247:     }
        !           248:     $j++;
        !           249:   }
        !           250:   $i++;
        !           251: }
        !           252: ?>
        !           253: *********************<br>
        !           254: 
        !           255: *** hash test... ***<br>
        !           256: <?php 
        !           257: /*
        !           258: $i=0;
        !           259: 
        !           260: while ($i<10000) {
        !           261:   $arr[$i]=$i;
        !           262:   $i++;
        !           263: }
        !           264: 
        !           265: $i=0;
        !           266: while ($i<10000) {
        !           267:   echo $arr[$i++]."<br>\n";
        !           268: }
        !           269: */
        !           270: echo "commented out...";
        !           271: ?>
        !           272: 
        !           273: **************************<br>
        !           274: 
        !           275: *** Hash resizing test ***<br>
        !           276: <?php 
        !           277: $i = 10;
        !           278: $a = 'b';
        !           279: while ($i > 0) {
        !           280:        $a = $a . 'a';
        !           281:        echo "$a<br>\n";
        !           282:        $resize[$a] = $i;
        !           283:        $i--;
        !           284: }
        !           285: $i = 10;
        !           286: $a = 'b';
        !           287: while ($i > 0) {
        !           288:        $a = $a . 'a';
        !           289:        echo "$a<br>\n";
        !           290:        echo $resize[$a]."<br>\n";
        !           291:        $i--;
        !           292: }
        !           293: ?>
        !           294: **************************<br>
        !           295: 
        !           296: 
        !           297: *** break/continue test ***<br>
        !           298: <?php 
        !           299: $i=0;
        !           300: 
        !           301: echo "\$i should go from 0 to 2<br>\n";
        !           302: while ($i<5) {
        !           303:   if ($i>2) {
        !           304:     break;
        !           305:   }
        !           306:   $j=0;
        !           307:   echo "\$j should go from 3 to 4, and \$q should go from 3 to 4<br>\n";
        !           308:   while ($j<5) {
        !           309:     if ($j<=2) {
        !           310:       $j++;
        !           311:       continue;
        !           312:     }
        !           313:     echo "  \$j=$j<br>\n";
        !           314:     for ($q=0; $q<=10; $q++) {
        !           315:       if ($q<3) {
        !           316:         continue;
        !           317:       }
        !           318:       if ($q>4) {
        !           319:         break;
        !           320:       }
        !           321:       echo "    \$q=$q<br>\n";
        !           322:     }
        !           323:     $j++;
        !           324:   }
        !           325:   $j=0;
        !           326:   echo "\$j should go from 0 to 2<br>\n";
        !           327:   while ($j<5) {
        !           328:     if ($j>2) {
        !           329:       $k=0;
        !           330:       echo "\$k should go from 0 to 2<br>\n";
        !           331:       while ($k<5) {
        !           332:         if ($k>2) {
        !           333:           break 2;
        !           334:         }
        !           335:         echo "    \$k=$k<br>\n";
        !           336:         $k++;
        !           337:       }
        !           338:     }
        !           339:     echo "  \$j=$j<br>\n";
        !           340:     $j++;
        !           341:   }
        !           342:   echo "\$i=$i<br>\n";
        !           343:   $i++;
        !           344: }
        !           345: ?>
        !           346: ***********************<br>
        !           347: 
        !           348: *** Nested file include test ***<br>
        !           349: <?php include("023-2.inc"); ?>
        !           350: ********************************<br>
        !           351: 
        !           352: <?php 
        !           353: {
        !           354:   echo "Tests completed.<br>\n";  # testing some PHP style comment...
        !           355: }
        !           356: ?>

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>