Annotation of embedaddon/php/ext/mbstring/tests/mb_stripos_basic.phpt, revision 1.1
1.1 ! misho 1: --TEST--
! 2: Test mb_stripos() function : basic functionality
! 3: --SKIPIF--
! 4: <?php
! 5: extension_loaded('mbstring') or die('skip');
! 6: function_exists('mb_stripos') or die("skip mb_stripos() is not available in this build");
! 7: ?>
! 8: --FILE--
! 9: <?php
! 10: /* Prototype : int mb_stripos(string haystack, string needle [, int offset [, string encoding]])
! 11: * Description: Finds position of first occurrence of a string within another, case insensitive
! 12: * Source code: ext/mbstring/mbstring.c
! 13: * Alias to functions:
! 14: */
! 15:
! 16: /*
! 17: * Test basic functionality of mb_stripos with ASCII and multibyte characters
! 18: */
! 19:
! 20: echo "*** Testing mb_stripos() : basic functionality***\n";
! 21:
! 22: mb_internal_encoding('UTF-8');
! 23:
! 24: //ascii strings
! 25: $ascii_haystacks = array(
! 26: b'abc defabc def',
! 27: b'ABC DEFABC DEF',
! 28: b'Abc dEFaBC Def',
! 29: );
! 30:
! 31: $ascii_needles = array(
! 32: // 4 good ones
! 33: b'DE',
! 34: b'de',
! 35: b'De',
! 36: b'dE',
! 37:
! 38: //flag a swap between good and bad
! 39: '!',
! 40:
! 41: // 4 bad ones
! 42: b'df',
! 43: b'Df',
! 44: b'dF',
! 45: b'DF'
! 46: );
! 47:
! 48: //greek strings in UTF-8
! 49: $greek_lower = base64_decode('zrHOss6zzrTOtc62zrfOuM65zrrOu868zr3Ovs6/z4DPgc+Dz4TPhc+Gz4fPiM+J');
! 50: $greek_upper = base64_decode('zpHOks6TzpTOlc6WzpfOmM6ZzprOm86czp3Ons6fzqDOoc6jzqTOpc6mzqfOqM6p');
! 51: $greek_mixed = base64_decode('zrHOss6TzpTOlc6WzpfOmM65zrrOu868zr3Ovs6fzqDOoc6jzqTOpc+Gz4fPiM+J');
! 52: $greek_haystacks = array($greek_lower, $greek_upper, $greek_mixed);
! 53:
! 54: $greek_nlower = base64_decode('zrzOvc6+zr8=');
! 55: $greek_nupper = base64_decode('zpzOnc6ezp8=');
! 56: $greek_nmixed1 = base64_decode('zpzOnc6+zr8=');
! 57: $greek_nmixed2 = base64_decode('zrzOvc6+zp8=');
! 58:
! 59: $greek_blower = base64_decode('zpzOns6f');
! 60: $greek_bupper = base64_decode('zrzOvs6/');
! 61: $greek_bmixed1 = base64_decode('zpzOvs6/');
! 62: $greek_bmixed2 = base64_decode('zrzOvs6f');
! 63: $greek_needles = array(
! 64: // 4 good ones
! 65: $greek_nlower, $greek_nupper, $greek_nmixed1, $greek_nmixed2,
! 66:
! 67: '!', // used to flag a swap between good and bad
! 68:
! 69: // 4 bad ones
! 70: $greek_blower, $greek_bupper, $greek_bmixed1, $greek_bmixed2,
! 71: );
! 72:
! 73: // try the basic options
! 74: echo "\n -- ASCII Strings, needle should be found --\n";
! 75: foreach ($ascii_needles as $needle) {
! 76: if ($needle == '!') {
! 77: echo "\n -- ASCII Strings, needle should not be found --\n";
! 78: }
! 79: else {
! 80: foreach ($ascii_haystacks as $haystack) {
! 81: var_dump(mb_stripos($haystack, $needle));
! 82: }
! 83: }
! 84: }
! 85:
! 86: echo "\n -- Greek Strings, needle should be found --\n";
! 87: foreach ($greek_needles as $needle) {
! 88: if ($needle == '!') {
! 89: echo "\n -- ASCII Strings, needle should not be found --\n";
! 90: }
! 91: else {
! 92: foreach ($greek_haystacks as $haystack) {
! 93: var_dump(mb_stripos($haystack, $needle));
! 94: }
! 95: }
! 96: }
! 97:
! 98: echo "Done";
! 99: ?>
! 100: --EXPECTF--
! 101: *** Testing mb_stripos() : basic functionality***
! 102:
! 103: -- ASCII Strings, needle should be found --
! 104: int(4)
! 105: int(4)
! 106: int(4)
! 107: int(4)
! 108: int(4)
! 109: int(4)
! 110: int(4)
! 111: int(4)
! 112: int(4)
! 113: int(4)
! 114: int(4)
! 115: int(4)
! 116:
! 117: -- ASCII Strings, needle should not be found --
! 118: bool(false)
! 119: bool(false)
! 120: bool(false)
! 121: bool(false)
! 122: bool(false)
! 123: bool(false)
! 124: bool(false)
! 125: bool(false)
! 126: bool(false)
! 127: bool(false)
! 128: bool(false)
! 129: bool(false)
! 130:
! 131: -- Greek Strings, needle should be found --
! 132: int(11)
! 133: int(11)
! 134: int(11)
! 135: int(11)
! 136: int(11)
! 137: int(11)
! 138: int(11)
! 139: int(11)
! 140: int(11)
! 141: int(11)
! 142: int(11)
! 143: int(11)
! 144:
! 145: -- ASCII Strings, needle should not be found --
! 146: bool(false)
! 147: bool(false)
! 148: bool(false)
! 149: bool(false)
! 150: bool(false)
! 151: bool(false)
! 152: bool(false)
! 153: bool(false)
! 154: bool(false)
! 155: bool(false)
! 156: bool(false)
! 157: bool(false)
! 158: Done
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>