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

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

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