Annotation of embedaddon/php/ext/standard/tests/array/sort_variation5.phpt, revision 1.1
1.1 ! misho 1: --TEST--
! 2: Test sort() function : usage variations - sort strings
! 3: --SKIPIF--
! 4: <?php
! 5: if (substr(PHP_OS, 0, 3) == 'WIN') {
! 6: die("skip Output tested contains chars that are not shown the same on windows concole (ESC and co)");
! 7: }
! 8: --FILE--
! 9: <?php
! 10: /* Prototype : bool sort ( array &$array [, int $sort_flags] )
! 11: * Description: This function sorts an array.
! 12: Elements will be arranged from lowest to highest when this function has completed.
! 13: * Source code: ext/standard/array.c
! 14: */
! 15:
! 16: /*
! 17: * testing sort() by providing different string arrays for $array argument with following flag values
! 18: * flag value as defualt
! 19: * SORT_REGULAR - compare items normally
! 20: * SORT_STRING - compare items as strings
! 21: */
! 22:
! 23: echo "*** Testing sort() : usage variations ***\n";
! 24:
! 25: $various_arrays = array (
! 26: // group of escape sequences
! 27: array(null, NULL, "\a", "\cx", "\e", "\f", "\n", "\r", "\t", "\xhh", "\ddd", "\v"),
! 28:
! 29: // array contains combination of capital/small letters
! 30: array("lemoN", "Orange", "banana", "apple", "Test", "TTTT", "ttt", "ww", "x", "X", "oraNGe", "BANANA")
! 31: );
! 32:
! 33: $flags = array("SORT_REGULAR" => SORT_REGULAR, "SORT_STRING" => SORT_STRING);
! 34:
! 35: $count = 1;
! 36: echo "\n-- Testing sort() by supplying various string arrays --\n";
! 37:
! 38: // loop through to test sort() with different arrays
! 39: foreach ($various_arrays as $array) {
! 40: echo "\n-- Iteration $count --\n";
! 41:
! 42: echo "- With Default sort flag -\n";
! 43: $temp_array = $array;
! 44: var_dump(sort($temp_array) ); // expecting : bool(true)
! 45: var_dump($temp_array);
! 46:
! 47: // loop through $flags array and setting all possible flag values
! 48: foreach($flags as $key => $flag){
! 49: echo "- Sort flag = $key -\n";
! 50: $temp_array = $array;
! 51: var_dump(sort($temp_array, $flag) ); // expecting : bool(true)
! 52: var_dump($temp_array);
! 53: }
! 54: $count++;
! 55: }
! 56:
! 57: echo "Done\n";
! 58: ?>
! 59: --EXPECTF--
! 60: *** Testing sort() : usage variations ***
! 61:
! 62: -- Testing sort() by supplying various string arrays --
! 63:
! 64: -- Iteration 1 --
! 65: - With Default sort flag -
! 66: bool(true)
! 67: array(12) {
! 68: [0]=>
! 69: NULL
! 70: [1]=>
! 71: NULL
! 72: [2]=>
! 73: string(1) " "
! 74: [3]=>
! 75: string(1) "
! 76: "
! 77: [4]=>
! 78: string(1) ""
! 79: [5]=>
! 80: string(1) ""
! 81: [6]=>
! 82: string(1) "
! 83: "
! 84: [7]=>
! 85: string(2) "\a"
! 86: [8]=>
! 87: string(3) "\cx"
! 88: [9]=>
! 89: string(4) "\ddd"
! 90: [10]=>
! 91: string(2) "\e"
! 92: [11]=>
! 93: string(4) "\xhh"
! 94: }
! 95: - Sort flag = SORT_REGULAR -
! 96: bool(true)
! 97: array(12) {
! 98: [0]=>
! 99: NULL
! 100: [1]=>
! 101: NULL
! 102: [2]=>
! 103: string(1) " "
! 104: [3]=>
! 105: string(1) "
! 106: "
! 107: [4]=>
! 108: string(1) ""
! 109: [5]=>
! 110: string(1) ""
! 111: [6]=>
! 112: string(1) "
! 113: "
! 114: [7]=>
! 115: string(2) "\a"
! 116: [8]=>
! 117: string(3) "\cx"
! 118: [9]=>
! 119: string(4) "\ddd"
! 120: [10]=>
! 121: string(2) "\e"
! 122: [11]=>
! 123: string(4) "\xhh"
! 124: }
! 125: - Sort flag = SORT_STRING -
! 126: bool(true)
! 127: array(12) {
! 128: [0]=>
! 129: NULL
! 130: [1]=>
! 131: NULL
! 132: [2]=>
! 133: string(1) " "
! 134: [3]=>
! 135: string(1) "
! 136: "
! 137: [4]=>
! 138: string(1) ""
! 139: [5]=>
! 140: string(1) ""
! 141: [6]=>
! 142: string(1) "
! 143: "
! 144: [7]=>
! 145: string(2) "\a"
! 146: [8]=>
! 147: string(3) "\cx"
! 148: [9]=>
! 149: string(4) "\ddd"
! 150: [10]=>
! 151: string(2) "\e"
! 152: [11]=>
! 153: string(4) "\xhh"
! 154: }
! 155:
! 156: -- Iteration 2 --
! 157: - With Default sort flag -
! 158: bool(true)
! 159: array(12) {
! 160: [0]=>
! 161: string(6) "BANANA"
! 162: [1]=>
! 163: string(6) "Orange"
! 164: [2]=>
! 165: string(4) "TTTT"
! 166: [3]=>
! 167: string(4) "Test"
! 168: [4]=>
! 169: string(1) "X"
! 170: [5]=>
! 171: string(5) "apple"
! 172: [6]=>
! 173: string(6) "banana"
! 174: [7]=>
! 175: string(5) "lemoN"
! 176: [8]=>
! 177: string(6) "oraNGe"
! 178: [9]=>
! 179: string(3) "ttt"
! 180: [10]=>
! 181: string(2) "ww"
! 182: [11]=>
! 183: string(1) "x"
! 184: }
! 185: - Sort flag = SORT_REGULAR -
! 186: bool(true)
! 187: array(12) {
! 188: [0]=>
! 189: string(6) "BANANA"
! 190: [1]=>
! 191: string(6) "Orange"
! 192: [2]=>
! 193: string(4) "TTTT"
! 194: [3]=>
! 195: string(4) "Test"
! 196: [4]=>
! 197: string(1) "X"
! 198: [5]=>
! 199: string(5) "apple"
! 200: [6]=>
! 201: string(6) "banana"
! 202: [7]=>
! 203: string(5) "lemoN"
! 204: [8]=>
! 205: string(6) "oraNGe"
! 206: [9]=>
! 207: string(3) "ttt"
! 208: [10]=>
! 209: string(2) "ww"
! 210: [11]=>
! 211: string(1) "x"
! 212: }
! 213: - Sort flag = SORT_STRING -
! 214: bool(true)
! 215: array(12) {
! 216: [0]=>
! 217: string(6) "BANANA"
! 218: [1]=>
! 219: string(6) "Orange"
! 220: [2]=>
! 221: string(4) "TTTT"
! 222: [3]=>
! 223: string(4) "Test"
! 224: [4]=>
! 225: string(1) "X"
! 226: [5]=>
! 227: string(5) "apple"
! 228: [6]=>
! 229: string(6) "banana"
! 230: [7]=>
! 231: string(5) "lemoN"
! 232: [8]=>
! 233: string(6) "oraNGe"
! 234: [9]=>
! 235: string(3) "ttt"
! 236: [10]=>
! 237: string(2) "ww"
! 238: [11]=>
! 239: string(1) "x"
! 240: }
! 241: Done
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>