Annotation of embedaddon/php/ext/standard/tests/strings/explode_variation1.phpt, revision 1.1
1.1 ! misho 1: --TEST--
! 2: Test explode() function : usage variations - test values for $delimiter argument
! 3: --FILE--
! 4: <?php
! 5:
! 6: /* Prototype : array explode ( string $delimiter , string $string [, int $limit ] )
! 7: * Description: Split a string by string.
! 8: * Source code: ext/standard/string.c
! 9: */
! 10:
! 11: echo "*** Testing explode() function: with unexpected inputs for 'delimiter' argument ***\n";
! 12:
! 13: //get an unset variable
! 14: $unset_var = 'string_val';
! 15: unset($unset_var);
! 16:
! 17: //defining a class
! 18: class sample {
! 19: public function __toString() {
! 20: return "sample object";
! 21: }
! 22: }
! 23:
! 24: //getting the resource
! 25: $file_handle = fopen(__FILE__, "r");
! 26:
! 27: // array with different values for $delimeter
! 28: $delimeters = array (
! 29:
! 30: // integer values
! 31: /*1*/ 0,
! 32: 1,
! 33: 255,
! 34: 256,
! 35: 2147483647,
! 36: -2147483648,
! 37:
! 38: // float values
! 39: /*7*/ 10.5,
! 40: -20.5,
! 41: 10.1234567e10,
! 42:
! 43: // array values
! 44: /*10*/ array(),
! 45: array(0),
! 46: array(1, 2),
! 47:
! 48: // boolean values
! 49: /*13*/ true,
! 50: false,
! 51: TRUE,
! 52: FALSE,
! 53:
! 54: // null values
! 55: /*17*/ NULL,
! 56: null,
! 57:
! 58: // objects
! 59: /*19*/ new sample(),
! 60:
! 61: // resource
! 62: /*20*/ $file_handle,
! 63:
! 64: // undefined variable
! 65: /*21*/ @$undefined_var,
! 66:
! 67: // unset variable
! 68: /*22*/ @$unset_var
! 69: );
! 70:
! 71: // loop through with each element of the $delimeters array to test explode() function
! 72: $count = 1;
! 73: $string = "piece1 piece2 piece3 piece4 piece5 piece6";
! 74: $limit = 5;
! 75: foreach($delimeters as $delimeter) {
! 76: echo "-- Iteration $count --\n";
! 77: var_dump( explode($delimeter, $string, $limit) );
! 78: $count ++;
! 79: }
! 80:
! 81: fclose($file_handle); //closing the file handle
! 82:
! 83: ?>
! 84: ===DONE===
! 85: --EXPECTF--
! 86: *** Testing explode() function: with unexpected inputs for 'delimiter' argument ***
! 87: -- Iteration 1 --
! 88: array(1) {
! 89: [0]=>
! 90: string(41) "piece1 piece2 piece3 piece4 piece5 piece6"
! 91: }
! 92: -- Iteration 2 --
! 93: array(2) {
! 94: [0]=>
! 95: string(5) "piece"
! 96: [1]=>
! 97: string(35) " piece2 piece3 piece4 piece5 piece6"
! 98: }
! 99: -- Iteration 3 --
! 100: array(1) {
! 101: [0]=>
! 102: string(41) "piece1 piece2 piece3 piece4 piece5 piece6"
! 103: }
! 104: -- Iteration 4 --
! 105: array(1) {
! 106: [0]=>
! 107: string(41) "piece1 piece2 piece3 piece4 piece5 piece6"
! 108: }
! 109: -- Iteration 5 --
! 110: array(1) {
! 111: [0]=>
! 112: string(41) "piece1 piece2 piece3 piece4 piece5 piece6"
! 113: }
! 114: -- Iteration 6 --
! 115: array(1) {
! 116: [0]=>
! 117: string(41) "piece1 piece2 piece3 piece4 piece5 piece6"
! 118: }
! 119: -- Iteration 7 --
! 120: array(1) {
! 121: [0]=>
! 122: string(41) "piece1 piece2 piece3 piece4 piece5 piece6"
! 123: }
! 124: -- Iteration 8 --
! 125: array(1) {
! 126: [0]=>
! 127: string(41) "piece1 piece2 piece3 piece4 piece5 piece6"
! 128: }
! 129: -- Iteration 9 --
! 130: array(1) {
! 131: [0]=>
! 132: string(41) "piece1 piece2 piece3 piece4 piece5 piece6"
! 133: }
! 134: -- Iteration 10 --
! 135:
! 136: Warning: explode() expects parameter 1 to be string, array given in %s on line %d
! 137: NULL
! 138: -- Iteration 11 --
! 139:
! 140: Warning: explode() expects parameter 1 to be string, array given in %s on line %d
! 141: NULL
! 142: -- Iteration 12 --
! 143:
! 144: Warning: explode() expects parameter 1 to be string, array given in %s on line %d
! 145: NULL
! 146: -- Iteration 13 --
! 147: array(2) {
! 148: [0]=>
! 149: string(5) "piece"
! 150: [1]=>
! 151: string(35) " piece2 piece3 piece4 piece5 piece6"
! 152: }
! 153: -- Iteration 14 --
! 154:
! 155: Warning: explode(): Empty delimiter in %s on line %d
! 156: bool(false)
! 157: -- Iteration 15 --
! 158: array(2) {
! 159: [0]=>
! 160: string(5) "piece"
! 161: [1]=>
! 162: string(35) " piece2 piece3 piece4 piece5 piece6"
! 163: }
! 164: -- Iteration 16 --
! 165:
! 166: Warning: explode(): Empty delimiter in %s on line %d
! 167: bool(false)
! 168: -- Iteration 17 --
! 169:
! 170: Warning: explode(): Empty delimiter in %s on line %d
! 171: bool(false)
! 172: -- Iteration 18 --
! 173:
! 174: Warning: explode(): Empty delimiter in %s on line %d
! 175: bool(false)
! 176: -- Iteration 19 --
! 177: array(1) {
! 178: [0]=>
! 179: string(41) "piece1 piece2 piece3 piece4 piece5 piece6"
! 180: }
! 181: -- Iteration 20 --
! 182:
! 183: Warning: explode() expects parameter 1 to be string, resource given in %s on line %d
! 184: NULL
! 185: -- Iteration 21 --
! 186:
! 187: Warning: explode(): Empty delimiter in %s on line %d
! 188: bool(false)
! 189: -- Iteration 22 --
! 190:
! 191: Warning: explode(): Empty delimiter in %s on line %d
! 192: bool(false)
! 193: ===DONE===
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>