Annotation of embedaddon/php/ext/mbstring/tests/mb_substr_variation1.phpt, revision 1.1.1.1

1.1       misho       1: --TEST--
                      2: Test mb_substr() function : usage variations - pass unexpected arguments (including strings) in place of $str
                      3: --SKIPIF--
                      4: <?php
                      5: extension_loaded('mbstring') or die('skip');
                      6: function_exists('mb_substr') or die("skip mb_substr() is not available in this build");
                      7: ?>
                      8: --FILE--
                      9: <?php
                     10: /* Prototype  : string mb_substr(string $str, int $start [, int $length [, string $encoding]])
                     11:  * Description: Returns part of a string 
                     12:  * Source code: ext/mbstring/mbstring.c
                     13:  */
                     14: 
                     15: /*
                     16:  * Pass different data types as $str to mb_substr() to test behaviour
                     17:  */
                     18: 
                     19: echo "*** Testing mb_substr() : usage variations ***\n";
                     20: 
                     21: // Initialise function arguments not being substituted
                     22: $start = 0;
                     23: $length = 5;
                     24: 
                     25: //get an unset variable
                     26: $unset_var = 10;
                     27: unset ($unset_var);
                     28: 
                     29: // get a class
                     30: class classA
                     31: {
                     32:   public function __toString() {
                     33:     return "Class A object";
                     34:   }
                     35: }
                     36: 
                     37: // heredoc string
                     38: $heredoc = <<<EOT
                     39: hello world
                     40: EOT;
                     41: 
                     42: // get a resource variable
                     43: $fp = fopen(__FILE__, "r");
                     44: 
                     45: // unexpected values to be passed to $str argument
                     46: $inputs = array(
                     47: 
                     48:        // int data
                     49: /*1*/  0,
                     50:        1,
                     51:        12345,
                     52:        -2345,
                     53: 
                     54:        // float data
                     55: /*5*/  10.5,
                     56:        -10.5,
                     57:        12.3456789000e10,
                     58:        12.3456789000E-10,
                     59:        .5,
                     60: 
                     61:        // null data
                     62: /*10*/ NULL,
                     63:        null,
                     64: 
                     65:        // boolean data
                     66: /*12*/ true,
                     67:        false,
                     68:        TRUE,
                     69:        FALSE,
                     70:        
                     71:        // empty data
                     72: /*16*/ "",
                     73:        '',
                     74: 
                     75:        // string data
                     76: /*18*/ "string",
                     77:        'string',
                     78:        $heredoc,
                     79:        
                     80:        // object data
                     81: /*21*/ new classA(),
                     82: 
                     83:        // undefined data
                     84: /*22*/ @$undefined_var,
                     85: 
                     86:        // unset data
                     87: /*23*/ @$unset_var,
                     88: 
                     89:        // resource variable
                     90: /*24*/ $fp
                     91: );
                     92: 
                     93: // loop through each element of $inputs to check the behavior of mb_substr()
                     94: $iterator = 1;
                     95: foreach($inputs as $input) {
                     96:   echo "\n-- Iteration $iterator --\n";
                     97:   var_dump( mb_substr($input, $start, $length));
                     98:   $iterator++;
                     99: };
                    100: 
                    101: fclose($fp);
                    102: echo "Done";
                    103: ?>
                    104: --EXPECTF--
                    105: *** Testing mb_substr() : usage variations ***
                    106: 
                    107: -- Iteration 1 --
                    108: string(1) "0"
                    109: 
                    110: -- Iteration 2 --
                    111: string(1) "1"
                    112: 
                    113: -- Iteration 3 --
                    114: string(5) "12345"
                    115: 
                    116: -- Iteration 4 --
                    117: string(5) "-2345"
                    118: 
                    119: -- Iteration 5 --
                    120: string(4) "10.5"
                    121: 
                    122: -- Iteration 6 --
                    123: string(5) "-10.5"
                    124: 
                    125: -- Iteration 7 --
                    126: string(5) "12345"
                    127: 
                    128: -- Iteration 8 --
                    129: string(5) "1.234"
                    130: 
                    131: -- Iteration 9 --
                    132: string(3) "0.5"
                    133: 
                    134: -- Iteration 10 --
                    135: string(0) ""
                    136: 
                    137: -- Iteration 11 --
                    138: string(0) ""
                    139: 
                    140: -- Iteration 12 --
                    141: string(1) "1"
                    142: 
                    143: -- Iteration 13 --
                    144: string(0) ""
                    145: 
                    146: -- Iteration 14 --
                    147: string(1) "1"
                    148: 
                    149: -- Iteration 15 --
                    150: string(0) ""
                    151: 
                    152: -- Iteration 16 --
                    153: string(0) ""
                    154: 
                    155: -- Iteration 17 --
                    156: string(0) ""
                    157: 
                    158: -- Iteration 18 --
                    159: string(5) "strin"
                    160: 
                    161: -- Iteration 19 --
                    162: string(5) "strin"
                    163: 
                    164: -- Iteration 20 --
                    165: string(5) "hello"
                    166: 
                    167: -- Iteration 21 --
                    168: string(5) "Class"
                    169: 
                    170: -- Iteration 22 --
                    171: string(0) ""
                    172: 
                    173: -- Iteration 23 --
                    174: string(0) ""
                    175: 
                    176: -- Iteration 24 --
                    177: 
                    178: Warning: mb_substr() expects parameter 1 to be string, resource given in %s on line %d
                    179: NULL
                    180: Done
                    181: 

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