sort: -h now handles comparisons such as 6000K vs 5M and 5MiB vs 5MB
[coreutils/ericb.git] / tests / misc / sort-debug-keys
blob89f8b9b7dbeb525485b03bcec0517166ea034c61
1 #!/bin/sh
2 # Test annotation of sort keys
4 # Copyright (C) 2010 Free Software Foundation, Inc.
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 if test "$VERBOSE" = yes; then
20 set -x
21 sort --version
24 . $srcdir/test-lib.sh
26 number() { cat -n | sed 's/^ *//'; }
28 cat <<\EOF > exp
30 ^ no match for key
32 ^ no match for key
34 ^ no match for key
36 ^ no match for key
38 ^ no match for key
40 ^ no match for key
42 ^ no match for key
44 ^ no match for key
46 ^ no match for key
48 ^ no match for key
50 ^ no match for key
60 ^ no match for key
61 3>1
63 1>2
66 ^ no match for key
68 ^ no match for key
70 ^ no match for key
72 ^ no match for key
74 ^ no match for key
76 ^ no match for key
78 ^ no match for key
80 ^ no match for key
82 ^ no match for key
84 ^ no match for key
86 ^ no match for key
96 ^ no match for key
97 3>1
99 1>2
102 ^ no match for key
104 ^ no match for key
106 ^ no match for key
108 ^ no match for key
110 ^ no match for key
112 ^ no match for key
114 ^ no match for key
116 ^ no match for key
118 ^ no match for key
120 ^ no match for key
122 ^ no match for key
132 ^ no match for key
138 ^ no match for key
144 ^ no match for key
146 ^ no match for key
148 ^ no match for key
149 JAZZ
150 ^ no match for key
152 ^ no match for key
157 2>JAZZ
158 ^ no match for key
160 ^ no match for key
161 4>JAN
163 1>FEB
166 ^ no match for key
167 JANZ
174 ^ no match for key
175 2>JANZ
177 4>JAN
179 1>FEB
181 1.2ignore
183 1.1e4ignore
184 _____
190 ^ no match for key
192 ^ no match for key
203 --Mi-1
227 2.,,3
231 2,,3
242 for type in n h g; do
243 printf "1\n\n44\n33\n2\n" | sort -s -k2$type --debug
244 printf "1\n\n44\n33\n2\n" | sort -s -k1.3$type --debug
245 printf "1\n\n44\n33\n2\n" | sort -s -k1$type --debug
246 printf "2\n\n1\n" | number | sort -s -k2g --debug
247 done
249 printf "FEB\n\nJAN\n" | sort -s -k1M --debug
250 printf "FEB\n\nJAN\n" | sort -s -k2,2M --debug
251 printf "FEB\nJAZZ\n\nJAN\n" | sort -s -k1M --debug
252 printf "FEB\nJAZZ\n\nJAN\n" | number | sort -s -k2,2M --debug
253 printf "FEB\nJANZ\n\nJAN\n" | sort -s -k1M --debug
254 printf "FEB\nJANZ\n\nJAN\n" | number | sort -s -k2,2M --debug
256 printf " 1.2ignore\n 1.1e4ignore\n" | sort -s -g --debug
258 printf "\tb\n\t\ta\n" | sort -s -d --debug # ignore = 1
260 printf "a\n\n" | sort -s -k2,2 --debug #lena = 0
262 printf "b\na\n" | sort -s -k1 --debug #otherwise key compare
264 printf -- "-0\n1\n-2\n--Mi-1\n-3\n-0\n" | sort -s --debug -k1,1h
266 printf " 1\n1\n" | sort -b --debug
267 printf " 1\n1\n" | sort -sb --debug
268 printf " 1\n1\n" | sort --debug
270 # strnumcmp is a bit weird, so we don't match exactly
271 printf "2,5\n2.4\n" | sort -s -k1n --debug
272 printf "2.,,3\n2.4\n" | sort -s -k1n --debug
273 printf "2,,3\n2.4\n" | sort -s -k1n --debug
275 # -z means we convert \0 to \n
276 printf "1a\x002b\x00" | sort -s -n -z --debug
277 ) > out
279 compare out exp || fail=1
281 cat <<\EOF > exp
282 1²---++3 1,234 Mi
284 _________
285 ________________________
286 1²---++3 1,234 Mi
287 _____
288 ________
289 _______________________
290 +1234 1234Gi 1,234M
291 ^ no match for key
292 _____
293 ^ no match for key
294 ____
295 ____
296 ______
297 _____
298 _____
299 ______
300 ___________________
303 : ${LOCALE_FR_UTF8=none}
304 if test "$LOCALE_FR_UTF8" != "none"; then
306 echo " 1²---++3 1,234 Mi" |
307 LC_ALL=C sort --debug -k2g -k1b,1
308 echo " 1²---++3 1,234 Mi" |
309 LC_ALL=$LOCALE_FR_UTF8 sort --debug -k2g -k1b,1
310 echo "+1234 1234Gi 1,234M" |
311 LC_ALL=$LOCALE_FR_UTF8 sort --debug -k1,1n -k1,1g \
312 -k1,1h -k2,2n -k2,2g -k2,2h -k3,3n -k3,3g -k3,3h
313 ) > out
314 compare out exp || fail=1
317 Exit $fail