2 # Test annotation of sort keys
4 # Copyright (C) 2010-2016 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 .
"${srcdir=.}/tests/init.sh"; path_prepend_ .
/src
20 print_ver_
sort printf
22 number
() { cat -n |
sed 's/^ *//'; }
248 for type in n h g
; do
249 printf '1\n\n44\n33\n2\n' |
sort -s -k2$type --debug
250 printf '1\n\n44\n33\n2\n' |
sort -s -k1.3
$type --debug
251 printf '1\n\n44\n33\n2\n' |
sort -s -k1$type --debug
252 printf '2\n\n1\n' | number |
sort -s -k2g --debug
255 printf 'FEB\n\nJAN\n' |
sort -s -k1M --debug
256 printf 'FEB\n\nJAN\n' |
sort -s -k2,2M
--debug
257 printf 'FEB\nJAZZ\n\nJAN\n' |
sort -s -k1M --debug
258 printf 'FEB\nJAZZ\n\nJAN\n' | number |
sort -s -k2,2M
--debug
259 printf 'FEB\nJANZ\n\nJAN\n' |
sort -s -k1M --debug
260 printf 'FEB\nJANZ\n\nJAN\n' | number |
sort -s -k2,2M
--debug
262 printf ' 1.2ignore\n 1.1e4ignore\n' |
sort -s -g --debug
264 printf '\tb\n\t\ta\n' |
sort -s -d --debug # ignore = 1
266 printf 'a\n\n' |
sort -s -k2,2 --debug #lena = 0
268 printf 'b\na\n' |
sort -s -k1 --debug #otherwise key compare
270 printf -- '-0\n1\n-2\n--Mi-1\n-3\n-0\n' |
sort -s --debug -k1,1h
272 printf ' 1\n1\n' |
sort -b --debug
273 printf ' 1\n1\n' |
sort -sb --debug
274 printf ' 1\n1\n' |
sort --debug
276 # strnumcmp is a bit weird, so we don't match exactly
277 printf '2,5\n2.4\n' |
sort -s -k1n --debug
278 printf '2.,,3\n2.4\n' |
sort -s -k1n --debug
279 printf '2,,3\n2.4\n' |
sort -s -k1n --debug
281 # -z means we convert \0 to \n
282 env
printf '1a\x002b\x00' |
sort -s -n -z --debug
284 # Check that \0 and \t intermix.
285 printf '\0\ta\n' |
sort -s -k2b,2 --debug |
tr -d '\0'
287 # Check that key end before key start is not underlined
288 printf 'A\tchr10\nB\tchr1\n' |
sort -s -k2.4b
,2.3n
--debug
290 # Ensure that -b applied before -k offsets
291 printf '1 2\n1 3\n' |
sort -s -k1.2b
--debug
294 compare exp out || fail
=1
300 ________________________
304 _______________________
321 : ${LOCALE_FR_UTF8=none}
322 if test "$LOCALE_FR_UTF8" != "none"; then
324 echo ' 1²---++3 1,234 Mi' |
325 LC_ALL
=C
sort --debug -k2g -k1b,1
326 echo ' 1²---++3 1,234 Mi' |
327 LC_COLLATE
=$f LC_CTYPE
=$f LC_NUMERIC
=$f LC_MESSAGES
=C \
328 sort --debug -k2g -k1b,1
329 echo '+1234 1234Gi 1,234M' |
330 LC_COLLATE
=$f LC_CTYPE
=$f LC_NUMERIC
=$f LC_MESSAGES
=C \
331 sort --debug -k1,1n
-k1,1g \
332 -k1,1h
-k2,2n
-k2,2g
-k2,2h
-k3,3n
-k3,3g
-k3,3h
334 compare exp out || fail
=1