Skip to content

Commit f011684

Browse files
committed
ext/standard: Split sort tests that contain escape sequences
1 parent d8a63a3 commit f011684

12 files changed

+744
-1028
lines changed

ext/standard/tests/array/sort/arsort_variation5.phpt

+59-174
Original file line numberDiff line numberDiff line change
@@ -2,235 +2,120 @@
22
Test arsort() function : usage variations - sort strings
33
--FILE--
44
<?php
5-
/*
6-
* testing arsort() by providing different string arrays for $array argument with following flag values
7-
* flag value as default
8-
* SORT_REGULAR - compare items normally
9-
* SORT_STRING - compare items as strings
10-
*/
115

12-
echo "*** Testing arsort() : usage variations ***\n";
6+
$array = [
7+
"lemoN" => "lemoN",
8+
"Orange" => "Orange",
9+
"banana" => "banana",
10+
"apple" => "apple",
11+
"Test" => "Test",
12+
"TTTT" => "TTTT",
13+
"ttt" => "ttt",
14+
"ww" => "ww",
15+
"x" => "x",
16+
"X" => "X",
17+
"oraNGe" => "oraNGe",
18+
"BANANA" => "BANANA",
19+
];
1320

14-
$various_arrays = array (
15-
// group of escape sequences
16-
array ("null"=> null, "NULL" => NULL, "\a" => "\a", "\cx" => "\cx", "\e" => "\e",
17-
"\f" => "\f", "\n" =>"\n", "\r" => "\r", "\t" => "\t", "\xhh" => "\xhh",
18-
"\ddd" => "\ddd", "\v" => "\v"
19-
),
21+
echo "Default flag\n";
22+
$temp_array = $array;
23+
var_dump(arsort($temp_array)); // expecting : bool(true)
24+
var_dump($temp_array);
2025

21-
// array contains combination of capital/small letters
22-
array ('l' => "lemoN", 'O' => "Orange", 'b' => "banana", 'a' => "apple", 'Te' => "Test",
23-
'T' => "TTTT", 't' => "ttt", 'w' => "ww", 'x' => "x", 'X' => "X", 'o' => "oraNGe",
24-
'B' => "BANANA"
25-
)
26-
);
26+
echo "SORT_REGULAR\n";
27+
$temp_array = $array;
28+
var_dump(arsort($temp_array, SORT_REGULAR)); // expecting : bool(true)
29+
var_dump($temp_array);
2730

28-
$flags = array("SORT_REGULAR" => SORT_REGULAR, "SORT_STRING" => SORT_STRING);
31+
echo "SORT_STRING\n";
32+
$temp_array = $array;
33+
var_dump(arsort($temp_array, SORT_STRING)); // expecting : bool(true)
34+
var_dump($temp_array);
2935

30-
$count = 1;
31-
echo "\n-- Testing arsort() by supplying various string arrays --\n";
32-
33-
// loop through to test arsort() with different arrays
34-
foreach ($various_arrays as $array) {
35-
echo "\n-- Iteration $count --\n";
36-
37-
echo "- With default sort_flag -\n";
38-
$temp_array = $array;
39-
var_dump(arsort($temp_array) ); // expecting : bool(true)
40-
var_dump($temp_array);
41-
42-
// loop through $flags array and setting all possible flag values
43-
foreach($flags as $key => $flag){
44-
echo "- Sort_flag = $key -\n";
45-
$temp_array = $array;
46-
var_dump(arsort($temp_array, $flag) ); // expecting : bool(true)
47-
var_dump($temp_array);
48-
}
49-
$count++;
50-
}
51-
52-
echo "Done\n";
5336
?>
5437
--EXPECT--
55-
*** Testing arsort() : usage variations ***
56-
57-
-- Testing arsort() by supplying various string arrays --
58-
59-
-- Iteration 1 --
60-
- With default sort_flag -
61-
bool(true)
62-
array(12) {
63-
["\xhh"]=>
64-
string(4) "\xhh"
65-
["\ddd"]=>
66-
string(4) "\ddd"
67-
["\cx"]=>
68-
string(3) "\cx"
69-
["\a"]=>
70-
string(2) "\a"
71-
[""]=>
72-
string(1) ""
73-
[""]=>
74-
string(1) ""
75-
[""]=>
76-
string(1) ""
77-
[""]=>
78-
string(1) ""
79-
["
80-
"]=>
81-
string(1) "
82-
"
83-
[" "]=>
84-
string(1) " "
85-
["null"]=>
86-
NULL
87-
["NULL"]=>
88-
NULL
89-
}
90-
- Sort_flag = SORT_REGULAR -
91-
bool(true)
92-
array(12) {
93-
["\xhh"]=>
94-
string(4) "\xhh"
95-
["\ddd"]=>
96-
string(4) "\ddd"
97-
["\cx"]=>
98-
string(3) "\cx"
99-
["\a"]=>
100-
string(2) "\a"
101-
[""]=>
102-
string(1) ""
103-
[""]=>
104-
string(1) ""
105-
[""]=>
106-
string(1) ""
107-
[""]=>
108-
string(1) ""
109-
["
110-
"]=>
111-
string(1) "
112-
"
113-
[" "]=>
114-
string(1) " "
115-
["null"]=>
116-
NULL
117-
["NULL"]=>
118-
NULL
119-
}
120-
- Sort_flag = SORT_STRING -
121-
bool(true)
122-
array(12) {
123-
["\xhh"]=>
124-
string(4) "\xhh"
125-
["\ddd"]=>
126-
string(4) "\ddd"
127-
["\cx"]=>
128-
string(3) "\cx"
129-
["\a"]=>
130-
string(2) "\a"
131-
[""]=>
132-
string(1) ""
133-
[""]=>
134-
string(1) ""
135-
[""]=>
136-
string(1) ""
137-
[""]=>
138-
string(1) ""
139-
["
140-
"]=>
141-
string(1) "
142-
"
143-
[" "]=>
144-
string(1) " "
145-
["null"]=>
146-
NULL
147-
["NULL"]=>
148-
NULL
149-
}
150-
151-
-- Iteration 2 --
152-
- With default sort_flag -
38+
Default flag
15339
bool(true)
15440
array(12) {
15541
["x"]=>
15642
string(1) "x"
157-
["w"]=>
43+
["ww"]=>
15844
string(2) "ww"
159-
["t"]=>
45+
["ttt"]=>
16046
string(3) "ttt"
161-
["o"]=>
47+
["oraNGe"]=>
16248
string(6) "oraNGe"
163-
["l"]=>
49+
["lemoN"]=>
16450
string(5) "lemoN"
165-
["b"]=>
51+
["banana"]=>
16652
string(6) "banana"
167-
["a"]=>
53+
["apple"]=>
16854
string(5) "apple"
16955
["X"]=>
17056
string(1) "X"
171-
["Te"]=>
57+
["Test"]=>
17258
string(4) "Test"
173-
["T"]=>
59+
["TTTT"]=>
17460
string(4) "TTTT"
175-
["O"]=>
61+
["Orange"]=>
17662
string(6) "Orange"
177-
["B"]=>
63+
["BANANA"]=>
17864
string(6) "BANANA"
17965
}
180-
- Sort_flag = SORT_REGULAR -
66+
SORT_REGULAR
18167
bool(true)
18268
array(12) {
18369
["x"]=>
18470
string(1) "x"
185-
["w"]=>
71+
["ww"]=>
18672
string(2) "ww"
187-
["t"]=>
73+
["ttt"]=>
18874
string(3) "ttt"
189-
["o"]=>
75+
["oraNGe"]=>
19076
string(6) "oraNGe"
191-
["l"]=>
77+
["lemoN"]=>
19278
string(5) "lemoN"
193-
["b"]=>
79+
["banana"]=>
19480
string(6) "banana"
195-
["a"]=>
81+
["apple"]=>
19682
string(5) "apple"
19783
["X"]=>
19884
string(1) "X"
199-
["Te"]=>
85+
["Test"]=>
20086
string(4) "Test"
201-
["T"]=>
87+
["TTTT"]=>
20288
string(4) "TTTT"
203-
["O"]=>
89+
["Orange"]=>
20490
string(6) "Orange"
205-
["B"]=>
91+
["BANANA"]=>
20692
string(6) "BANANA"
20793
}
208-
- Sort_flag = SORT_STRING -
94+
SORT_STRING
20995
bool(true)
21096
array(12) {
21197
["x"]=>
21298
string(1) "x"
213-
["w"]=>
99+
["ww"]=>
214100
string(2) "ww"
215-
["t"]=>
101+
["ttt"]=>
216102
string(3) "ttt"
217-
["o"]=>
103+
["oraNGe"]=>
218104
string(6) "oraNGe"
219-
["l"]=>
105+
["lemoN"]=>
220106
string(5) "lemoN"
221-
["b"]=>
107+
["banana"]=>
222108
string(6) "banana"
223-
["a"]=>
109+
["apple"]=>
224110
string(5) "apple"
225111
["X"]=>
226112
string(1) "X"
227-
["Te"]=>
113+
["Test"]=>
228114
string(4) "Test"
229-
["T"]=>
115+
["TTTT"]=>
230116
string(4) "TTTT"
231-
["O"]=>
117+
["Orange"]=>
232118
string(6) "Orange"
233-
["B"]=>
119+
["BANANA"]=>
234120
string(6) "BANANA"
235121
}
236-
Done
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
--TEST--
2+
Test arsort() function: sorting escape sequences
3+
--FILE--
4+
<?php
5+
6+
const EXPECTED_RESULT = [
7+
"\xhh" => "\xhh",
8+
"\ddd" => "\ddd",
9+
"\cx" => "\cx",
10+
"\a" => "\a",
11+
"\e" => "\e",
12+
"\r" => "\r",
13+
"\f" => "\f",
14+
"\v" => "\v",
15+
"\n" => "\n",
16+
"\t" => "\t",
17+
null => null,
18+
];
19+
20+
$array = [
21+
null => null,
22+
"\a" => "\a",
23+
"\cx" => "\cx",
24+
"\e" => "\e",
25+
"\f" => "\f",
26+
"\n" => "\n",
27+
"\r" => "\r",
28+
"\t" => "\t",
29+
"\xhh" => "\xhh",
30+
"\ddd" => "\ddd",
31+
"\v" => "\v",
32+
];
33+
34+
echo "Default flag\n";
35+
$temp_array = $array;
36+
var_dump(arsort($temp_array)); // expecting : bool(true)
37+
var_dump($temp_array === EXPECTED_RESULT);
38+
39+
echo "SORT_REGULAR\n";
40+
$temp_array = $array;
41+
var_dump(arsort($temp_array, SORT_REGULAR)); // expecting : bool(true)
42+
var_dump($temp_array === EXPECTED_RESULT);
43+
44+
echo "SORT_STRING\n";
45+
$temp_array = $array;
46+
var_dump(arsort($temp_array, SORT_STRING)); // expecting : bool(true)
47+
var_dump($temp_array === EXPECTED_RESULT);
48+
49+
?>
50+
--EXPECT--
51+
Default flag
52+
bool(true)
53+
bool(true)
54+
SORT_REGULAR
55+
bool(true)
56+
bool(true)
57+
SORT_STRING
58+
bool(true)
59+
bool(true)

0 commit comments

Comments
 (0)