1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
|
#!/bin/sh
# Test annotation of sort keys
# Copyright (C) 2010 Free Software Foundation, Inc.
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
if test "$VERBOSE" = yes; then
set -x
sort --version
fi
. $srcdir/test-lib.sh
number() { cat -n | sed 's/^ *//'; }
cat <<\EOF > exp
1
^ no match for key
^ no match for key
44
^ no match for key
33
^ no match for key
2
^ no match for key
1
^ no match for key
^ no match for key
44
^ no match for key
33
^ no match for key
2
^ no match for key
^ no match for key
1
_
2
_
33
__
44
__
2>
^ no match for key
3>1
_
1>2
_
1
^ no match for key
^ no match for key
44
^ no match for key
33
^ no match for key
2
^ no match for key
1
^ no match for key
^ no match for key
44
^ no match for key
33
^ no match for key
2
^ no match for key
^ no match for key
1
_
2
_
33
__
44
__
2>
^ no match for key
3>1
_
1>2
_
1
^ no match for key
^ no match for key
44
^ no match for key
33
^ no match for key
2
^ no match for key
1
^ no match for key
^ no match for key
44
^ no match for key
33
^ no match for key
2
^ no match for key
^ no match for key
1
_
2
_
33
__
44
__
2>
^ no match for key
3>1
_
1>2
_
^ no match for key
JAN
___
FEB
___
FEB
^ no match for key
^ no match for key
JAN
^ no match for key
JAZZ
^ no match for key
^ no match for key
JAN
___
FEB
___
2>JAZZ
^ no match for key
3>
^ no match for key
4>JAN
___
1>FEB
___
^ no match for key
JANZ
___
JAN
___
FEB
___
3>
^ no match for key
2>JANZ
___
4>JAN
___
1>FEB
___
1.2ignore
___
1.1e4ignore
_____
>>a
___
>b
__
a
^ no match for key
^ no match for key
a
_
b
_
-3
__
-2
__
-0
__
--Mi-1
_
-0
__
1
_
1
_
__
1
_
_
1
_
1
_
1
__
1
_
2,5
_
2.4
___
2.,,3
__
2.4
___
2,,3
_
2.4
___
1a
_
2b
_
>a
_
EOF
(
for type in n h g; do
printf "1\n\n44\n33\n2\n" | sort -s -k2$type --debug
printf "1\n\n44\n33\n2\n" | sort -s -k1.3$type --debug
printf "1\n\n44\n33\n2\n" | sort -s -k1$type --debug
printf "2\n\n1\n" | number | sort -s -k2g --debug
done
printf "FEB\n\nJAN\n" | sort -s -k1M --debug
printf "FEB\n\nJAN\n" | sort -s -k2,2M --debug
printf "FEB\nJAZZ\n\nJAN\n" | sort -s -k1M --debug
printf "FEB\nJAZZ\n\nJAN\n" | number | sort -s -k2,2M --debug
printf "FEB\nJANZ\n\nJAN\n" | sort -s -k1M --debug
printf "FEB\nJANZ\n\nJAN\n" | number | sort -s -k2,2M --debug
printf " 1.2ignore\n 1.1e4ignore\n" | sort -s -g --debug
printf "\tb\n\t\ta\n" | sort -s -d --debug # ignore = 1
printf "a\n\n" | sort -s -k2,2 --debug #lena = 0
printf "b\na\n" | sort -s -k1 --debug #otherwise key compare
printf -- "-0\n1\n-2\n--Mi-1\n-3\n-0\n" | sort -s --debug -k1,1h
printf " 1\n1\n" | sort -b --debug
printf " 1\n1\n" | sort -sb --debug
printf " 1\n1\n" | sort --debug
# strnumcmp is a bit weird, so we don't match exactly
printf "2,5\n2.4\n" | sort -s -k1n --debug
printf "2.,,3\n2.4\n" | sort -s -k1n --debug
printf "2,,3\n2.4\n" | sort -s -k1n --debug
# -z means we convert \0 to \n
printf "1a\x002b\x00" | sort -s -n -z --debug
# Check that \0 and \t intermix.
printf "\0\ta\n" | sort -s -k2b,2 --debug | tr -d '\0'
) > out
compare out exp || fail=1
cat <<\EOF > exp
1²---++3 1,234 Mi
_
_________
________________________
1²---++3 1,234 Mi
_____
________
_______________________
+1234 1234Gi 1,234M
^ no match for key
_____
^ no match for key
____
____
_____
_____
_____
______
___________________
EOF
: ${LOCALE_FR_UTF8=none}
if test "$LOCALE_FR_UTF8" != "none"; then
(
echo " 1²---++3 1,234 Mi" |
LC_ALL=C sort --debug -k2g -k1b,1
echo " 1²---++3 1,234 Mi" |
LC_ALL=$LOCALE_FR_UTF8 sort --debug -k2g -k1b,1
echo "+1234 1234Gi 1,234M" |
LC_ALL=$LOCALE_FR_UTF8 sort --debug -k1,1n -k1,1g \
-k1,1h -k2,2n -k2,2g -k2,2h -k3,3n -k3,3g -k3,3h
) > out
compare out exp || fail=1
fi
Exit $fail
|