Annotation of embedaddon/php/ext/tokenizer/tests/token_get_all_variation1.phpt, revision 1.1.1.2

1.1       misho       1: --TEST--
                      2: Test token_get_all() function : usage variations - unexpected values for 'source' argument
1.1.1.2 ! misho       3: --SKIPIF--
        !             4: <?php if (!extension_loaded("tokenizer")) print "skip"; ?>
1.1       misho       5: --FILE--
                      6: <?php
                      7: /* Prototype  : array token_get_all(string $source)
                      8:  * Description: splits the given source into an array of PHP languange tokens 
                      9:  * Source code: ext/tokenizer/tokenizer.c
                     10: */
                     11: 
                     12: /*
                     13:  * Passing different scalar/non-scalar values in place of 'source' argument
                     14:  *   It returns either T_INLINE_HTML by converting values into string or gives warning
                     15: */
                     16: 
                     17: echo "*** Testing token_get_all() : unexpected values for 'source' argument ***\n";
                     18: 
                     19: // get an unset variable
                     20: $unset_var = 10;
                     21: unset ($unset_var);
                     22: 
                     23: // class definition
                     24: class MyClass
                     25: {
                     26:   public function __toString()
                     27:   {
                     28:     return "object";
                     29:   }
                     30: }
                     31: 
                     32: // get resource
                     33: $fp = fopen(__FILE__, 'r');
                     34: 
                     35: // different scalar/nonscalar values for 'source'
                     36: $source_values = array(
                     37: 
                     38:        // int data
                     39: /*1*/  0,
                     40:        1,
                     41:        12345,
                     42:        -2345,
                     43: 
                     44:        // float data
                     45: /*5*/  10.5,
                     46:        -10.5,
                     47:        10.1234567e8,
                     48:        10.7654321E-8,
                     49:        .5,
                     50: 
                     51:        // array data
                     52: /*10*/ array(),
                     53:        array(0),
                     54:        array(1),
                     55:        array(1, 2),
                     56:        array('color' => 'red', 'item' => 'pen'),
                     57: 
                     58:        // null data
                     59: /*15*/ NULL,
                     60:        null,
                     61: 
                     62:        // boolean data
                     63: /*17*/ true,
                     64:        false,
                     65:        TRUE,
                     66:        FALSE,
                     67: 
                     68:        // empty string
                     69: /*21*/ "",
                     70:        '',
                     71: 
                     72:        // object data
                     73: /*23*/ new MyClass(),
                     74:  
                     75:        // resource data
                     76:        $fp,
                     77: 
                     78:        // undefined data
                     79:        @$undefined_var,
                     80: 
                     81:        // unset data
                     82: /*26*/ @$unset_var,
                     83: );
                     84: 
                     85: for($count = 0; $count < count($source_values); $count++) {
                     86:   echo "--Iteration ".($count + 1)." --\n";
                     87:   var_dump( token_get_all($source_values[$count]));
                     88: };
                     89: 
                     90: fclose($fp);
                     91: echo "Done"
                     92: ?>
                     93: --EXPECTF--
                     94: *** Testing token_get_all() : unexpected values for 'source' argument ***
                     95: --Iteration 1 --
                     96: array(1) {
                     97:   [0]=>
                     98:   array(3) {
                     99:     [0]=>
1.1.1.2 ! misho     100:     int(%d)
1.1       misho     101:     [1]=>
                    102:     string(1) "0"
                    103:     [2]=>
                    104:     int(1)
                    105:   }
                    106: }
                    107: --Iteration 2 --
                    108: array(1) {
                    109:   [0]=>
                    110:   array(3) {
                    111:     [0]=>
1.1.1.2 ! misho     112:     int(%d)
1.1       misho     113:     [1]=>
                    114:     string(1) "1"
                    115:     [2]=>
                    116:     int(1)
                    117:   }
                    118: }
                    119: --Iteration 3 --
                    120: array(1) {
                    121:   [0]=>
                    122:   array(3) {
                    123:     [0]=>
1.1.1.2 ! misho     124:     int(%d)
1.1       misho     125:     [1]=>
                    126:     string(5) "12345"
                    127:     [2]=>
                    128:     int(1)
                    129:   }
                    130: }
                    131: --Iteration 4 --
                    132: array(1) {
                    133:   [0]=>
                    134:   array(3) {
                    135:     [0]=>
1.1.1.2 ! misho     136:     int(%d)
1.1       misho     137:     [1]=>
                    138:     string(5) "-2345"
                    139:     [2]=>
                    140:     int(1)
                    141:   }
                    142: }
                    143: --Iteration 5 --
                    144: array(1) {
                    145:   [0]=>
                    146:   array(3) {
                    147:     [0]=>
1.1.1.2 ! misho     148:     int(%d)
1.1       misho     149:     [1]=>
                    150:     string(4) "10.5"
                    151:     [2]=>
                    152:     int(1)
                    153:   }
                    154: }
                    155: --Iteration 6 --
                    156: array(1) {
                    157:   [0]=>
                    158:   array(3) {
                    159:     [0]=>
1.1.1.2 ! misho     160:     int(%d)
1.1       misho     161:     [1]=>
                    162:     string(5) "-10.5"
                    163:     [2]=>
                    164:     int(1)
                    165:   }
                    166: }
                    167: --Iteration 7 --
                    168: array(1) {
                    169:   [0]=>
                    170:   array(3) {
                    171:     [0]=>
1.1.1.2 ! misho     172:     int(%d)
1.1       misho     173:     [1]=>
                    174:     string(10) "1012345670"
                    175:     [2]=>
                    176:     int(1)
                    177:   }
                    178: }
                    179: --Iteration 8 --
                    180: array(1) {
                    181:   [0]=>
                    182:   array(3) {
                    183:     [0]=>
1.1.1.2 ! misho     184:     int(%d)
1.1       misho     185:     [1]=>
                    186:     string(13) "1.07654321E-7"
                    187:     [2]=>
                    188:     int(1)
                    189:   }
                    190: }
                    191: --Iteration 9 --
                    192: array(1) {
                    193:   [0]=>
                    194:   array(3) {
                    195:     [0]=>
1.1.1.2 ! misho     196:     int(%d)
1.1       misho     197:     [1]=>
                    198:     string(3) "0.5"
                    199:     [2]=>
                    200:     int(1)
                    201:   }
                    202: }
                    203: --Iteration 10 --
                    204: 
                    205: Warning: token_get_all() expects parameter 1 to be string, array given in %s on line %d
                    206: NULL
                    207: --Iteration 11 --
                    208: 
                    209: Warning: token_get_all() expects parameter 1 to be string, array given in %s on line %d
                    210: NULL
                    211: --Iteration 12 --
                    212: 
                    213: Warning: token_get_all() expects parameter 1 to be string, array given in %s on line %d
                    214: NULL
                    215: --Iteration 13 --
                    216: 
                    217: Warning: token_get_all() expects parameter 1 to be string, array given in %s on line %d
                    218: NULL
                    219: --Iteration 14 --
                    220: 
                    221: Warning: token_get_all() expects parameter 1 to be string, array given in %s on line %d
                    222: NULL
                    223: --Iteration 15 --
                    224: array(0) {
                    225: }
                    226: --Iteration 16 --
                    227: array(0) {
                    228: }
                    229: --Iteration 17 --
                    230: array(1) {
                    231:   [0]=>
                    232:   array(3) {
                    233:     [0]=>
1.1.1.2 ! misho     234:     int(%d)
1.1       misho     235:     [1]=>
                    236:     string(1) "1"
                    237:     [2]=>
                    238:     int(1)
                    239:   }
                    240: }
                    241: --Iteration 18 --
                    242: array(0) {
                    243: }
                    244: --Iteration 19 --
                    245: array(1) {
                    246:   [0]=>
                    247:   array(3) {
                    248:     [0]=>
1.1.1.2 ! misho     249:     int(%d)
1.1       misho     250:     [1]=>
                    251:     string(1) "1"
                    252:     [2]=>
                    253:     int(1)
                    254:   }
                    255: }
                    256: --Iteration 20 --
                    257: array(0) {
                    258: }
                    259: --Iteration 21 --
                    260: array(0) {
                    261: }
                    262: --Iteration 22 --
                    263: array(0) {
                    264: }
                    265: --Iteration 23 --
                    266: array(1) {
                    267:   [0]=>
                    268:   array(3) {
                    269:     [0]=>
1.1.1.2 ! misho     270:     int(%d)
1.1       misho     271:     [1]=>
                    272:     string(6) "object"
                    273:     [2]=>
                    274:     int(1)
                    275:   }
                    276: }
                    277: --Iteration 24 --
                    278: 
                    279: Warning: token_get_all() expects parameter 1 to be string, resource given in %s on line %d
                    280: NULL
                    281: --Iteration 25 --
                    282: array(0) {
                    283: }
                    284: --Iteration 26 --
                    285: array(0) {
                    286: }
                    287: Done

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