Annotation of embedaddon/php/ext/mbstring/tests/mb_strpos.phpt, revision 1.1
1.1 ! misho 1: --TEST--
! 2: mb_strpos()
! 3: --SKIPIF--
! 4: <?php extension_loaded('mbstring') or die('skip mbstring not available'); ?>
! 5: --FILE--
! 6: <?php
! 7: // TODO: Add more encodings
! 8:
! 9: //$debug=true;
! 10: ini_set('include_path','.');
! 11: include_once('common.inc');
! 12:
! 13:
! 14: // Test string
! 15: $euc_jp = b'0123この文字列は日本語です。EUC-JPを使っています。0123日本語は面倒臭い。';
! 16:
! 17: // EUC-JP - With encoding parameter
! 18: mb_internal_encoding('UTF-8') or print("mb_internal_encoding() failed\n");
! 19:
! 20: echo "== POSITIVE OFFSET ==\n";
! 21: print mb_strpos($euc_jp, b'日本語', 0, 'EUC-JP') . "\n";
! 22: print mb_strpos($euc_jp, b'0', 0, 'EUC-JP') . "\n";
! 23: print mb_strpos($euc_jp, 3, 0, 'EUC-JP') . "\n";
! 24: print mb_strpos($euc_jp, 0, 0, 'EUC-JP') . "\n";
! 25: print mb_strpos($euc_jp, b'日本語', 15, 'EUC-JP') . "\n";
! 26: print mb_strpos($euc_jp, b'0', 15, 'EUC-JP') . "\n";
! 27: print mb_strpos($euc_jp, 3, 15, 'EUC-JP') . "\n";
! 28: print mb_strpos($euc_jp, 0, 15, 'EUC-JP') . "\n";
! 29:
! 30: // Negative offset
! 31: // Note: PHP Warning - offset is negative.
! 32: // Note: For offset(-15). It does not return position of latter string. (ie the same result as -50)
! 33: echo "== NEGATIVE OFFSET ==\n";
! 34: $r = mb_strpos($euc_jp, b'日本語', -15, 'EUC-JP');
! 35: ($r === FALSE) ? print "OK_NEGATIVE_OFFSET\n" : print "NG_NEGATIVE_OFFSET\n";
! 36: $r = mb_strpos($euc_jp, b'0', -15, 'EUC-JP');
! 37: ($r === FALSE) ? print "OK_NEGATIVE_OFFSET\n" : print "NG_NEGATIVE_OFFSET\n";
! 38: $r = mb_strpos($euc_jp, 3, -15, 'EUC-JP');
! 39: ($r === FALSE) ? print "OK_NEGATIVE_OFFSET\n" : print "NG_NEGATIVE_OFFSET\n";
! 40: $r = mb_strpos($euc_jp, 0, -15, 'EUC-JP');
! 41: ($r === FALSE) ? print "OK_NEGATIVE_OFFSET\n" : print "NG_NEGATIVE_OFFSET\n";
! 42: $r = mb_strpos($euc_jp, b'日本語', -50, 'EUC-JP');
! 43: ($r === FALSE) ? print "OK_NEGATIVE_OFFSET\n" : print "NG_NEGATIVE_OFFSET\n";
! 44: $r = mb_strpos($euc_jp, b'0', -50, 'EUC-JP');
! 45: ($r === FALSE) ? print "OK_NEGATIVE_OFFSET\n" : print "NG_NEGATIVE_OFFSET\n";
! 46: $r = mb_strpos($euc_jp, 3, -50, 'EUC-JP');
! 47: ($r === FALSE) ? print "OK_NEGATIVE_OFFSET\n" : print "NG_NEGATIVE_OFFSET\n";
! 48: $r = mb_strpos($euc_jp, 0, -50, 'EUC-JP');
! 49: ($r === FALSE) ? print "OK_NEGATIVE_OFFSET\n" : print "NG_NEGATIVE_OFFSET\n";
! 50:
! 51: // Out of range - should return false
! 52: print ("== OUT OF RANGE ==\n");
! 53: $r = mb_strpos($euc_jp, b'日本語', 40, 'EUC-JP');
! 54: ($r === FALSE) ? print "OK_OUT_RANGE\n" : print "NG_OUT_RANGE\n";
! 55: $r = mb_strpos($euc_jp, b'0', 40, 'EUC-JP');
! 56: ($r === FALSE) ? print "OK_OUT_RANGE\n" : print "NG_OUT_RANGE\n";
! 57: $r = mb_strpos($euc_jp, 3, 40, 'EUC-JP');
! 58: ($r === FALSE) ? print "OK_OUT_RANGE\n" : print "NG_OUT_RANGE\n";
! 59: $r = mb_strpos($euc_jp, 0, 40, 'EUC-JP');
! 60: ($r === FALSE) ? print "OK_OUT_RANGE\n" : print "NG_OUT_RANGE\n";
! 61: // Note: Returned NULL string
! 62: // echo gettype($r). ' val '. $r ."\n";
! 63:
! 64:
! 65: // Non-existent
! 66: echo "== NON-EXISTENT ==\n";
! 67: $r = mb_strpos($euc_jp, b'韓国語', 0, 'EUC-JP');
! 68: ($r === FALSE) ? print "OK_STR\n" : print "NG_STR\n";
! 69: $r = mb_strpos($euc_jp, b"\n", 0, 'EUC-JP');
! 70: ($r === FALSE) ? print "OK_NEWLINE\n" : print "NG_NEWLINE\n";
! 71:
! 72:
! 73: // EUC-JP - No encoding parameter
! 74: echo "== NO ENCODING PARAMETER ==\n";
! 75: mb_internal_encoding('EUC-JP') or print("mb_internal_encoding() failed\n");
! 76:
! 77: print mb_strpos($euc_jp, b'日本語', 0) . "\n";
! 78: print mb_strpos($euc_jp, b'0', 0) . "\n";
! 79: print mb_strpos($euc_jp, 3, 0) . "\n";
! 80: print mb_strpos($euc_jp, 0, 0) . "\n";
! 81:
! 82: $r = mb_strpos($euc_jp, b'韓国語', 0);
! 83: ($r === FALSE) ? print "OK_STR\n" : print "NG_STR\n";
! 84: $r = mb_strpos($euc_jp, b"\n", 0);
! 85: ($r === FALSE) ? print "OK_NEWLINE\n" : print "NG_NEWLINE\n";
! 86:
! 87: // EUC-JP - No offset and encoding parameter
! 88: echo "== NO OFFSET AND ENCODING PARAMETER ==\n";
! 89: mb_internal_encoding('EUC-JP') or print("mb_internal_encoding() failed\n");
! 90:
! 91: print mb_strpos($euc_jp, b'日本語') . "\n";
! 92: print mb_strpos($euc_jp, b'0') . "\n";
! 93: print mb_strpos($euc_jp, 3) . "\n";
! 94: print mb_strpos($euc_jp, 0) . "\n";
! 95:
! 96: $r = mb_strpos($euc_jp, b'韓国語');
! 97: ($r === FALSE) ? print "OK_STR\n" : print "NG_STR\n";
! 98: $r = mb_strpos($euc_jp, b"\n");
! 99: ($r === FALSE) ? print "OK_NEWLINE\n" : print "NG_NEWLINE\n";
! 100:
! 101:
! 102: // Invalid Parameters
! 103: echo "== INVALID PARAMETER TEST ==\n";
! 104:
! 105: $r = mb_strpos($euc_jp,'','EUC-JP');
! 106: ($r === FALSE) ? print("OK_NULL\n") : print("NG_NULL\n");
! 107: $r = mb_strpos($euc_jp, $t_ary, 'EUC-JP');
! 108: ($r === FALSE) ? print("OK_ARRAY\n") : print("NG_ARRAY\n");
! 109: $r = mb_strpos($euc_jp, $t_obj, 'EUC-JP');
! 110: ($r === FALSE) ? print("OK_OBJECT\n") : print("NG_OBJECT\n");
! 111: $r = mb_strpos($euc_jp, $t_obj, 'BAD_ENCODING');
! 112: ($r === FALSE) ? print("OK_BAD_ENCODING\n") : print("NG_BAD_ENCODING\n");
! 113:
! 114:
! 115: ?>
! 116:
! 117: --EXPECT--
! 118: == POSITIVE OFFSET ==
! 119: 10
! 120: 0
! 121: 3
! 122: 0
! 123: 34
! 124: 30
! 125: 33
! 126: 30
! 127: == NEGATIVE OFFSET ==
! 128: ERR: Warning
! 129: OK_NEGATIVE_OFFSET
! 130: ERR: Warning
! 131: OK_NEGATIVE_OFFSET
! 132: ERR: Warning
! 133: OK_NEGATIVE_OFFSET
! 134: ERR: Warning
! 135: OK_NEGATIVE_OFFSET
! 136: ERR: Warning
! 137: OK_NEGATIVE_OFFSET
! 138: ERR: Warning
! 139: OK_NEGATIVE_OFFSET
! 140: ERR: Warning
! 141: OK_NEGATIVE_OFFSET
! 142: ERR: Warning
! 143: OK_NEGATIVE_OFFSET
! 144: == OUT OF RANGE ==
! 145: OK_OUT_RANGE
! 146: OK_OUT_RANGE
! 147: OK_OUT_RANGE
! 148: OK_OUT_RANGE
! 149: == NON-EXISTENT ==
! 150: OK_STR
! 151: OK_NEWLINE
! 152: == NO ENCODING PARAMETER ==
! 153: 10
! 154: 0
! 155: 3
! 156: 0
! 157: OK_STR
! 158: OK_NEWLINE
! 159: == NO OFFSET AND ENCODING PARAMETER ==
! 160: 10
! 161: 0
! 162: 3
! 163: 0
! 164: OK_STR
! 165: OK_NEWLINE
! 166: == INVALID PARAMETER TEST ==
! 167: ERR: Warning
! 168: OK_NULL
! 169: ERR: Warning
! 170: OK_ARRAY
! 171: ERR: Warning
! 172: OK_OBJECT
! 173: ERR: Warning
! 174: OK_BAD_ENCODING
! 175:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>