Annotation of embedaddon/php/ext/standard/tests/array/natcasesort_variation11.phpt, revision 1.1.1.1
1.1 misho 1: --TEST--
2: Test natcasesort() function : usage variations - Different array keys
3: --FILE--
4: <?php
5: /* Prototype : bool natcasesort(array &$array_arg)
6: * Description: Sort an array using case-insensitive natural sort
7: * Source code: ext/standard/array.c
8: */
9:
10: /*
11: * Pass arrays where the keys are different data types to test behaviour of natcasesort()
12: */
13:
14: echo "*** Testing natcasesort() : usage variations ***\n";
15:
16: //get an unset variable
17: $unset_var = 10;
18: unset ($unset_var);
19:
20: // heredoc string
21: $heredoc = <<<EOT
22: hello world
23: EOT;
24:
25: // arrays with keys as different data types to be passed as $array_arg
26: $inputs = array(
27:
28: // int data
29: /*1*/ 'int' => array(
30: 0 => 'zero',
31: 1 => 'one',
32: 12345 => 'positive',
33: -2345 => 'negative',
34: ),
35:
36: // float data
37: /*2*/ 'float' => array(
38: 10.5 => 'positive',
39: -10.5 => 'negative',
40: .5 => 'half',
41: ),
42:
43: /*3*/ 'extreme floats' => array(
44: 12.3456789000e6 => 'large',
45: 12.3456789000E-10 => 'small',
46: ),
47:
48: // null data
49: /*4*/ 'null uppercase' => array(
50: NULL => 'null 1',
51: ),
52:
53: /*5*/ 'null lowercase' => array(
54: null => 'null 2',
55: ),
56:
57: // boolean data
58: /*6*/ 'bool lowercase' => array(
59: true => 'lowert',
60: false => 'lowerf',
61: ),
62:
63: /*7*/ 'bool uppercase' => array(
64: TRUE => 'uppert',
65: FALSE => 'upperf',
66: ),
67:
68: // empty data
69: /*8*/ 'empty double quotes' => array(
70: "" => 'emptyd',
71: ),
72:
73: /*9*/ 'empty single quotes' => array(
74: '' => 'emptys',
75: ),
76:
77: // string data
78: /*10*/ 'string' => array(
79: "stringd" => 'stringd',
80: 'strings' => 'strings',
81: $heredoc => 'stringh',
82: ),
83:
84: // undefined data
85: /*11*/ 'undefined' => array(
86: @$undefined_var => 'undefined',
87: ),
88:
89: // unset data
90: /*12*/ 'unset' => array(
91: @$unset_var => 'unset',
92: ),
93:
94: // duplicate values
95: /*13*/ 'duplicate' => array(
96: 'foo' => 'bar',
97: 'baz' => 'bar',
98: 'hello' => 'world'
99: ),
100:
101: );
102:
103: // loop through each element of $inputs to check the behavior of natcasesort()
104: $iterator = 1;
105: foreach($inputs as $input) {
106: echo "\n-- Iteration $iterator --\n";
107: var_dump( natcasesort($input) );
108: var_dump($input);
109: $iterator++;
110: };
111:
112: echo "Done";
113: ?>
114:
115: --EXPECTF--
116: *** Testing natcasesort() : usage variations ***
117:
118: -- Iteration 1 --
119: bool(true)
120: array(4) {
121: [-2345]=>
122: string(8) "negative"
123: [1]=>
124: string(3) "one"
125: [12345]=>
126: string(8) "positive"
127: [0]=>
128: string(4) "zero"
129: }
130:
131: -- Iteration 2 --
132: bool(true)
133: array(3) {
134: [0]=>
135: string(4) "half"
136: [-10]=>
137: string(8) "negative"
138: [10]=>
139: string(8) "positive"
140: }
141:
142: -- Iteration 3 --
143: bool(true)
144: array(2) {
145: [12345678]=>
146: string(5) "large"
147: [0]=>
148: string(5) "small"
149: }
150:
151: -- Iteration 4 --
152: bool(true)
153: array(1) {
154: [""]=>
155: string(6) "null 1"
156: }
157:
158: -- Iteration 5 --
159: bool(true)
160: array(1) {
161: [""]=>
162: string(6) "null 2"
163: }
164:
165: -- Iteration 6 --
166: bool(true)
167: array(2) {
168: [0]=>
169: string(6) "lowerf"
170: [1]=>
171: string(6) "lowert"
172: }
173:
174: -- Iteration 7 --
175: bool(true)
176: array(2) {
177: [0]=>
178: string(6) "upperf"
179: [1]=>
180: string(6) "uppert"
181: }
182:
183: -- Iteration 8 --
184: bool(true)
185: array(1) {
186: [""]=>
187: string(6) "emptyd"
188: }
189:
190: -- Iteration 9 --
191: bool(true)
192: array(1) {
193: [""]=>
194: string(6) "emptys"
195: }
196:
197: -- Iteration 10 --
198: bool(true)
199: array(3) {
200: ["stringd"]=>
201: string(7) "stringd"
202: ["hello world"]=>
203: string(7) "stringh"
204: ["strings"]=>
205: string(7) "strings"
206: }
207:
208: -- Iteration 11 --
209: bool(true)
210: array(1) {
211: [""]=>
212: string(9) "undefined"
213: }
214:
215: -- Iteration 12 --
216: bool(true)
217: array(1) {
218: [""]=>
219: string(5) "unset"
220: }
221:
222: -- Iteration 13 --
223: bool(true)
224: array(3) {
225: ["foo"]=>
226: string(3) "bar"
227: ["baz"]=>
228: string(3) "bar"
229: ["hello"]=>
230: string(5) "world"
231: }
232: Done
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>