xref: /PHP-5.4/ext/intl/tests/collator_sort.phpt (revision 42685040)
1--TEST--
2sort()
3--SKIPIF--
4<?php if( !extension_loaded( 'intl' ) ) print 'skip'; ?>
5<?php if (version_compare(INTL_ICU_VERSION, '51.2') >=  0) die('skip for ICU < 51.2'); ?>
6--FILE--
7<?php
8
9/*
10 * Sort arrays using various locales.
11 */
12
13
14$test_num = 1;
15
16/*
17 * Sort arrays in the given list using specified locale.
18 */
19function sort_arrays( $locale, $arrays, $sort_flag = Collator::SORT_REGULAR )
20{
21    $res_str = '';
22
23    $coll = ut_coll_create( $locale );
24
25    foreach( $arrays as $array )
26    {
27        // Sort array values
28        $res_val = ut_coll_sort( $coll, $array, $sort_flag );
29
30        // Concatenate the sorted array and function result
31        // with output string.
32        $res_dump = "\n" . dump( $array ) .
33                    "\n Result: " . dump( $res_val );
34
35		// Preppend test signature to output string
36        $md5 = md5( $res_dump );
37
38        global $test_num;
39
40        $res_str .= "\n\n".
41                    "Test $test_num.$md5:" .
42                    $res_dump;
43        ++$test_num;
44    }
45
46    return $res_str;
47}
48
49function ut_main()
50{
51    global $test_num;
52    $test_num = 1;
53    $res_str = '';
54
55    // Sort an array in SORT_REGULAR mode using en_US locale.
56    $test_params = array(
57        array( 'abc', 'abd', 'aaa' ),
58        array( 'm'  , '1'  , '_'   ),
59        array( 'a'  , 'aaa', 'aa'  ),
60        array( 'ba' , 'b'  , 'ab'  ),
61        array( 'e'  , 'c'  , 'a'   ),
62        array( '100', '25' , '36'  ),
63        array( 5    , '30' , 2     ),
64        array( 'd'  , ''   , ' a'  ),
65        array( 'd ' , 'f ' , ' a'  ),
66        array( 'a'  , null , '3'   ),
67        array( 'y'  , 'k'  , 'i' )
68    );
69
70    $res_str .= sort_arrays( 'en_US', $test_params );
71
72    $test_params = array(
73        array( '100', '25' , '36'  ),
74        array( 5    , '30' , 2     ),
75        array( 'd'  , ''   , ' a'  ),
76        array( 'y'  , 'k'  , 'i' )
77    );
78
79    // Sort in en_US locale with SORT_STRING flag
80    $res_str .= sort_arrays( 'en_US', $test_params, Collator::SORT_STRING );
81
82
83    // Sort a non-ASCII array using ru_RU locale.
84    $test_params = array(
85        array( 'абг', 'абв', 'ааа', 'abc' ),
86        array( 'аа', 'ааа' , 'а' )
87    );
88
89    $res_str .= sort_arrays( 'ru_RU', $test_params );
90
91    // Sort an array using Lithuanian locale.
92    $test_params = array(
93        array( 'y'  , 'k'  , 'i' )
94    );
95
96    $res_str .= sort_arrays( 'lt_LT', $test_params );
97
98    return $res_str;
99}
100
101include_once( 'ut_common.inc' );
102ut_run();
103?>
104--EXPECT--
105Test 1.e8f1cd28133d79ecd660002f1c660d0e:
106array (
107  0 => 'aaa',
108  1 => 'abc',
109  2 => 'abd',
110)
111 Result: true
112
113Test 2.c2ded12173dd2996927378cae37eb275:
114array (
115  0 => '_',
116  1 => '1',
117  2 => 'm',
118)
119 Result: true
120
121Test 3.54071c968d71cb98c5d379145f8d7d38:
122array (
123  0 => 'a',
124  1 => 'aa',
125  2 => 'aaa',
126)
127 Result: true
128
129Test 4.19abe63d6f6dfef65b0e3c9ab4826b07:
130array (
131  0 => 'ab',
132  1 => 'b',
133  2 => 'ba',
134)
135 Result: true
136
137Test 5.9a8dc0a9bc771368c2f1fc3d02754610:
138array (
139  0 => 'a',
140  1 => 'c',
141  2 => 'e',
142)
143 Result: true
144
145Test 6.ab530b060e5e54a65bfb8b9f8fc61870:
146array (
147  0 => '25',
148  1 => '36',
149  2 => '100',
150)
151 Result: true
152
153Test 7.0718dd838509017bded2ed307a6e785f:
154array (
155  0 => 2,
156  1 => 5,
157  2 => '30',
158)
159 Result: true
160
161Test 8.923d65739c5219c634616ffd100a50e4:
162array (
163  0 => '',
164  1 => ' a',
165  2 => 'd',
166)
167 Result: true
168
169Test 9.289bc2f28e87d3201ec9d7e8477ae1b0:
170array (
171  0 => ' a',
172  1 => 'd ',
173  2 => 'f ',
174)
175 Result: true
176
177Test 10.de0fd958484f2377a645835d7fbcf124:
178array (
179  0 => NULL,
180  1 => '3',
181  2 => 'a',
182)
183 Result: true
184
185Test 11.dd2b8f0adb37c45d528cad1a0cc0f361:
186array (
187  0 => 'i',
188  1 => 'k',
189  2 => 'y',
190)
191 Result: true
192
193Test 12.1e6b4d6f7df9d4580317634ea46d8208:
194array (
195  0 => '100',
196  1 => '25',
197  2 => '36',
198)
199 Result: true
200
201Test 13.cec115dc9850b98dfbdf102efa09e61b:
202array (
203  0 => 2,
204  1 => '30',
205  2 => 5,
206)
207 Result: true
208
209Test 14.923d65739c5219c634616ffd100a50e4:
210array (
211  0 => '',
212  1 => ' a',
213  2 => 'd',
214)
215 Result: true
216
217Test 15.dd2b8f0adb37c45d528cad1a0cc0f361:
218array (
219  0 => 'i',
220  1 => 'k',
221  2 => 'y',
222)
223 Result: true
224
225Test 16.ca0e38a2e3147dd97070f2128f140934:
226array (
227  0 => 'abc',
228  1 => 'ааа',
229  2 => 'абв',
230  3 => 'абг',
231)
232 Result: true
233
234Test 17.91480b10473a0c96a4cd6d88c23c577a:
235array (
236  0 => 'а',
237  1 => 'аа',
238  2 => 'ааа',
239)
240 Result: true
241
242Test 18.fdd3fe3981476039164aa000bf9177f2:
243array (
244  0 => 'i',
245  1 => 'y',
246  2 => 'k',
247)
248 Result: true
249