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

1.1       misho       1: --TEST--
                      2: Test mb_strpos() function : usage variations - Pass different integers as $offset argument
                      3: --SKIPIF--
                      4: <?php
                      5: extension_loaded('mbstring') or die('skip');
                      6: function_exists('mb_strpos') or die("skip mb_strpos() is not available in this build");
                      7: ?>
                      8: --FILE--
                      9: <?php
                     10: /* Prototype  : int mb_strpos(string $haystack, string $needle [, int $offset [, string $encoding]])
                     11:  * Description: Find position of first occurrence of a string within another 
                     12:  * Source code: ext/mbstring/mbstring.c
                     13:  */
                     14: 
                     15: /*
                     16:  * Test how mb_strpos() behaves when passed different integers as $offset argument
                     17:  * The character length of $string_ascii and $string_mb is the same, 
                     18:  * and the needle appears at the same positions in both strings
                     19:  */
                     20: 
                     21: mb_internal_encoding('UTF-8');
                     22: 
                     23: echo "*** Testing mb_strpos() : usage variations ***\n";
                     24: 
                     25: $string_ascii = b'+Is an English string'; //21 chars
                     26: $needle_ascii = b'g';
                     27: 
                     28: $string_mb = base64_decode('5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CCMDEyMzTvvJXvvJbvvJfvvJjvvJnjgII='); //21 chars
                     29: $needle_mb = base64_decode('44CC');
                     30: 
                     31: /*
                     32:  * Loop through integers as multiples of ten for $offset argument
                     33:  * mb_strpos should not be able to accept negative values as $offset.
                     34:  * 60 is larger than *BYTE* count for $string_mb
                     35:  */
                     36: for ($i = -10; $i <= 60; $i += 10) {
                     37:        echo "\n**-- Offset is: $i --**\n";
                     38:        echo "-- ASCII String --\n";
                     39:        var_dump(mb_strpos($string_ascii, $needle_ascii, $i));
                     40:        echo "--Multibyte String --\n";
                     41:        var_dump(mb_strpos($string_mb, $needle_mb, $i, 'UTF-8'));
                     42: }
                     43: 
                     44: echo "Done";
                     45: ?>
                     46: 
                     47: --EXPECTF--
                     48: *** Testing mb_strpos() : usage variations ***
                     49: 
                     50: **-- Offset is: -10 --**
                     51: -- ASCII String --
                     52: 
                     53: Warning: mb_strpos(): Offset not contained in string in %s on line %d
                     54: bool(false)
                     55: --Multibyte String --
                     56: 
                     57: Warning: mb_strpos(): Offset not contained in string in %s on line %d
                     58: bool(false)
                     59: 
                     60: **-- Offset is: 0 --**
                     61: -- ASCII String --
                     62: int(9)
                     63: --Multibyte String --
                     64: int(9)
                     65: 
                     66: **-- Offset is: 10 --**
                     67: -- ASCII String --
                     68: int(20)
                     69: --Multibyte String --
                     70: int(20)
                     71: 
                     72: **-- Offset is: 20 --**
                     73: -- ASCII String --
                     74: int(20)
                     75: --Multibyte String --
                     76: int(20)
                     77: 
                     78: **-- Offset is: 30 --**
                     79: -- ASCII String --
                     80: 
                     81: Warning: mb_strpos(): Offset not contained in string in %s on line %d
                     82: bool(false)
                     83: --Multibyte String --
                     84: 
                     85: Warning: mb_strpos(): Offset not contained in string in %s on line %d
                     86: bool(false)
                     87: 
                     88: **-- Offset is: 40 --**
                     89: -- ASCII String --
                     90: 
                     91: Warning: mb_strpos(): Offset not contained in string in %s on line %d
                     92: bool(false)
                     93: --Multibyte String --
                     94: 
                     95: Warning: mb_strpos(): Offset not contained in string in %s on line %d
                     96: bool(false)
                     97: 
                     98: **-- Offset is: 50 --**
                     99: -- ASCII String --
                    100: 
                    101: Warning: mb_strpos(): Offset not contained in string in %s on line %d
                    102: bool(false)
                    103: --Multibyte String --
                    104: 
                    105: Warning: mb_strpos(): Offset not contained in string in %s on line %d
                    106: bool(false)
                    107: 
                    108: **-- Offset is: 60 --**
                    109: -- ASCII String --
                    110: 
                    111: Warning: mb_strpos(): Offset not contained in string in %s on line %d
                    112: bool(false)
                    113: --Multibyte String --
                    114: 
                    115: Warning: mb_strpos(): Offset not contained in string in %s on line %d
                    116: bool(false)
                    117: Done

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