Return to collator_sort_with_sort_keys.phpt CVS log | Up to [ELWIX - Embedded LightWeight unIX -] / embedaddon / php / ext / intl / tests |
1.1 misho 1: --TEST--
2: sort_with_sort_keys()
3: --SKIPIF--
4: <?php if( !extension_loaded( 'intl' ) ) print 'skip'; ?>
1.1.1.2 ! misho 5: <?php if (version_compare(INTL_ICU_VERSION, '51.2') >= 0) die('skip for ICU < 51.2'); ?>
1.1 misho 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: */
19: function sort_arrays( $locale, $arrays )
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_with_sort_keys( $coll, $array );
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:
36: // Preppend test signature to output string
37: $md5 = md5( $res_dump );
38:
39: global $test_num;
40:
41: $res_str .= "\n\n".
42: "Test $test_num.$md5:" .
43: $res_dump;
44: ++$test_num;
45: }
46:
47: return $res_str;
48: }
49:
50:
51: function ut_main()
52: {
53: global $test_num;
54: $test_num = 1;
55: $res_str = '';
56:
57: // Sort an array in SORT_REGULAR mode using en_US locale.
58: $test_params = array(
59: array( 'abc', 'abd', 'aaa' ),
60: array( 'm' , '1' , '_' ),
61: array( 'a' , 'aaa', 'aa' ),
62: array( 'ba' , 'b' , 'ab' ),
63: array( 'e' , 'c' , 'a' ),
64: array( 'd' , '' , ' a' ),
65: array( 'd ' , 'f ' , ' a' ),
66: array( 'a' , null , '3' ),
67: array( 'y' , 'i' , 'k' )
68: );
69:
70: $res_str .= sort_arrays( 'en_US', $test_params );
71:
72: // Sort a non-ASCII array using ru_RU locale.
73: $test_params = array(
74: array( 'абг', 'абв', 'ааа', 'abc' ),
75: array( 'аа', 'ааа', 'а' )
76: );
77:
78: $res_str .= sort_arrays( 'ru_RU', $test_params );
79:
80: // Array with data for sorting.
81: $test_params = array(
82: array( 'y' , 'i' , 'k' )
83: );
84:
85: // Sort an array using Lithuanian locale.
86: $res_str .= sort_arrays( 'lt_LT', $test_params );
87:
88: return $res_str . "\n";
89: }
90:
91: include_once( 'ut_common.inc' );
92: ut_run();
93: ?>
94: --EXPECT--
95: Test 1.e8f1cd28133d79ecd660002f1c660d0e:
96: array (
97: 0 => 'aaa',
98: 1 => 'abc',
99: 2 => 'abd',
100: )
101: Result: true
102:
103: Test 2.c2ded12173dd2996927378cae37eb275:
104: array (
105: 0 => '_',
106: 1 => '1',
107: 2 => 'm',
108: )
109: Result: true
110:
111: Test 3.54071c968d71cb98c5d379145f8d7d38:
112: array (
113: 0 => 'a',
114: 1 => 'aa',
115: 2 => 'aaa',
116: )
117: Result: true
118:
119: Test 4.19abe63d6f6dfef65b0e3c9ab4826b07:
120: array (
121: 0 => 'ab',
122: 1 => 'b',
123: 2 => 'ba',
124: )
125: Result: true
126:
127: Test 5.9a8dc0a9bc771368c2f1fc3d02754610:
128: array (
129: 0 => 'a',
130: 1 => 'c',
131: 2 => 'e',
132: )
133: Result: true
134:
135: Test 6.923d65739c5219c634616ffd100a50e4:
136: array (
137: 0 => '',
138: 1 => ' a',
139: 2 => 'd',
140: )
141: Result: true
142:
143: Test 7.289bc2f28e87d3201ec9d7e8477ae1b0:
144: array (
145: 0 => ' a',
146: 1 => 'd ',
147: 2 => 'f ',
148: )
149: Result: true
150:
151: Test 8.de0fd958484f2377a645835d7fbcf124:
152: array (
153: 0 => NULL,
154: 1 => '3',
155: 2 => 'a',
156: )
157: Result: true
158:
159: Test 9.dd2b8f0adb37c45d528cad1a0cc0f361:
160: array (
161: 0 => 'i',
162: 1 => 'k',
163: 2 => 'y',
164: )
165: Result: true
166:
167: Test 10.ca0e38a2e3147dd97070f2128f140934:
168: array (
169: 0 => 'abc',
170: 1 => 'ааа',
171: 2 => 'абв',
172: 3 => 'абг',
173: )
174: Result: true
175:
176: Test 11.91480b10473a0c96a4cd6d88c23c577a:
177: array (
178: 0 => 'а',
179: 1 => 'аа',
180: 2 => 'ааа',
181: )
182: Result: true
183:
184: Test 12.fdd3fe3981476039164aa000bf9177f2:
185: array (
186: 0 => 'i',
187: 1 => 'y',
188: 2 => 'k',
189: )
190: Result: true