Annotation of embedaddon/php/ext/mbstring/tests/mb_strrchr_variation3.phpt, revision 1.1

1.1     ! misho       1: --TEST--
        !             2: Test mb_strrchr() function : usage variation - different values for part
        !             3: --SKIPIF--
        !             4: <?php
        !             5: extension_loaded('mbstring') or die('skip');
        !             6: function_exists('mb_strrchr') or die("skip mb_strrchr() is not available in this build");
        !             7: ?>
        !             8: --FILE--
        !             9: <?php
        !            10: /* Prototype  : string mb_strrchr(string haystack, string needle[, bool part[, string encoding]])
        !            11:  * Description: Finds the last occurrence of a character in a string within another 
        !            12:  * Source code: ext/mbstring/mbstring.c
        !            13:  * Alias to functions: 
        !            14:  */
        !            15: 
        !            16: echo "*** Testing mb_strrchr() : usage variation ***\n";
        !            17: 
        !            18: // Define error handler
        !            19: function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) {
        !            20:        if (error_reporting() != 0) {
        !            21:                // report non-silenced errors
        !            22:                echo "Error: $err_no - $err_msg, $filename($linenum)\n";
        !            23:        }
        !            24: }
        !            25: set_error_handler('test_error_handler');
        !            26: 
        !            27: // Initialise function arguments not being substituted (if any)
        !            28: $haystack = b'string_val';
        !            29: $needle = b'_';
        !            30: $encoding = 'utf-8';
        !            31: 
        !            32: //get an unset variable
        !            33: $unset_var = 10;
        !            34: unset ($unset_var);
        !            35: 
        !            36: // define some classes
        !            37: class classWithToString
        !            38: {
        !            39:        public function __toString() {
        !            40:                return b"Class A object";
        !            41:        }
        !            42: }
        !            43: 
        !            44: class classWithoutToString
        !            45: {
        !            46: }
        !            47: 
        !            48: // heredoc string
        !            49: $heredoc = b<<<EOT
        !            50: hello world
        !            51: EOT;
        !            52: 
        !            53: // get a resource variable
        !            54: $fp = fopen(__FILE__, "r");
        !            55: 
        !            56: // add arrays
        !            57: $index_array = array (1, 2, 3);
        !            58: $assoc_array = array ('one' => 1, 'two' => 2);
        !            59: 
        !            60: //array of values to iterate over
        !            61: $inputs = array(
        !            62: 
        !            63:       // int data
        !            64:       'int 0' => 0,
        !            65:       'int 1' => 1,
        !            66:       'int 12345' => 12345,
        !            67:       'int -12345' => -2345,
        !            68: 
        !            69:       // float data
        !            70:       'float 10.5' => 10.5,
        !            71:       'float -10.5' => -10.5,
        !            72:       'float 12.3456789000e10' => 12.3456789000e10,
        !            73:       'float -12.3456789000e10' => -12.3456789000e10,
        !            74:       'float .5' => .5,
        !            75: 
        !            76:       // array data
        !            77:       'empty array' => array(),
        !            78:       'int indexed array' => $index_array,
        !            79:       'associative array' => $assoc_array,
        !            80:       'nested arrays' => array('foo', $index_array, $assoc_array),
        !            81: 
        !            82:       // null data
        !            83:       'uppercase NULL' => NULL,
        !            84:       'lowercase null' => null,
        !            85: 
        !            86:       // boolean data
        !            87:       'lowercase true' => true,
        !            88:       'lowercase false' =>false,
        !            89:       'uppercase TRUE' =>TRUE,
        !            90:       'uppercase FALSE' =>FALSE,
        !            91: 
        !            92:       // empty data
        !            93:       'empty string DQ' => "",
        !            94:       'empty string SQ' => '',
        !            95: 
        !            96:       // string data
        !            97:       'string DQ' => "string",
        !            98:       'string SQ' => 'string',
        !            99:       'mixed case string' => "sTrInG",
        !           100:       'heredoc' => $heredoc,
        !           101: 
        !           102:       // object data
        !           103:       'instance of classWithToString' => new classWithToString(),
        !           104:       'instance of classWithoutToString' => new classWithoutToString(),
        !           105: 
        !           106:       // undefined data
        !           107:       'undefined var' => @$undefined_var,
        !           108: 
        !           109:       // unset data
        !           110:       'unset var' => @$unset_var,
        !           111:       
        !           112:       // resource variable
        !           113:       'resource' => $fp      
        !           114: );
        !           115: 
        !           116: // loop through each element of the array for part
        !           117: 
        !           118: foreach($inputs as $key =>$value) {
        !           119:       echo "\n--$key--\n";
        !           120:       $res = mb_strrchr($haystack, $needle, $value, $encoding);
        !           121:       if ($res === false) {
        !           122:          var_dump($res);
        !           123:       }
        !           124:       else {
        !           125:          var_dump(bin2hex($res));
        !           126:       }      
        !           127: };
        !           128: 
        !           129: fclose($fp);
        !           130: 
        !           131: ?>
        !           132: ===DONE===
        !           133: --EXPECTF--
        !           134: *** Testing mb_strrchr() : usage variation ***
        !           135: 
        !           136: --int 0--
        !           137: string(8) "5f76616c"
        !           138: 
        !           139: --int 1--
        !           140: string(12) "737472696e67"
        !           141: 
        !           142: --int 12345--
        !           143: string(12) "737472696e67"
        !           144: 
        !           145: --int -12345--
        !           146: string(12) "737472696e67"
        !           147: 
        !           148: --float 10.5--
        !           149: string(12) "737472696e67"
        !           150: 
        !           151: --float -10.5--
        !           152: string(12) "737472696e67"
        !           153: 
        !           154: --float 12.3456789000e10--
        !           155: string(12) "737472696e67"
        !           156: 
        !           157: --float -12.3456789000e10--
        !           158: string(12) "737472696e67"
        !           159: 
        !           160: --float .5--
        !           161: string(12) "737472696e67"
        !           162: 
        !           163: --empty array--
        !           164: Error: 2 - mb_strrchr() expects parameter 3 to be boolean, array given, %s(%d)
        !           165: bool(false)
        !           166: 
        !           167: --int indexed array--
        !           168: Error: 2 - mb_strrchr() expects parameter 3 to be boolean, array given, %s(%d)
        !           169: bool(false)
        !           170: 
        !           171: --associative array--
        !           172: Error: 2 - mb_strrchr() expects parameter 3 to be boolean, array given, %s(%d)
        !           173: bool(false)
        !           174: 
        !           175: --nested arrays--
        !           176: Error: 2 - mb_strrchr() expects parameter 3 to be boolean, array given, %s(%d)
        !           177: bool(false)
        !           178: 
        !           179: --uppercase NULL--
        !           180: string(8) "5f76616c"
        !           181: 
        !           182: --lowercase null--
        !           183: string(8) "5f76616c"
        !           184: 
        !           185: --lowercase true--
        !           186: string(12) "737472696e67"
        !           187: 
        !           188: --lowercase false--
        !           189: string(8) "5f76616c"
        !           190: 
        !           191: --uppercase TRUE--
        !           192: string(12) "737472696e67"
        !           193: 
        !           194: --uppercase FALSE--
        !           195: string(8) "5f76616c"
        !           196: 
        !           197: --empty string DQ--
        !           198: string(8) "5f76616c"
        !           199: 
        !           200: --empty string SQ--
        !           201: string(8) "5f76616c"
        !           202: 
        !           203: --string DQ--
        !           204: string(12) "737472696e67"
        !           205: 
        !           206: --string SQ--
        !           207: string(12) "737472696e67"
        !           208: 
        !           209: --mixed case string--
        !           210: string(12) "737472696e67"
        !           211: 
        !           212: --heredoc--
        !           213: string(12) "737472696e67"
        !           214: 
        !           215: --instance of classWithToString--
        !           216: Error: 2 - mb_strrchr() expects parameter 3 to be boolean, object given, %s(%d)
        !           217: bool(false)
        !           218: 
        !           219: --instance of classWithoutToString--
        !           220: Error: 2 - mb_strrchr() expects parameter 3 to be boolean, object given, %s(%d)
        !           221: bool(false)
        !           222: 
        !           223: --undefined var--
        !           224: string(8) "5f76616c"
        !           225: 
        !           226: --unset var--
        !           227: string(8) "5f76616c"
        !           228: 
        !           229: --resource--
        !           230: Error: 2 - mb_strrchr() expects parameter 3 to be boolean, resource given, %s(%d)
        !           231: bool(false)
        !           232: ===DONE===

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