3 # SUSv4 compliant sort tests.
4 # Copyright 2005, 2012 by Rob Landley <rob@landley.net>
6 [ -f testing.sh ] && . testing.sh
8 # The basic tests. These should work even with the small config.
10 testing "sort" "sort input" "a\nb\nc\n" "c\na\nb\n" ""
11 testing "#2" "sort input" "010\n1\n3\n" "3\n1\n010\n" ""
12 testing "stdin" "sort" "a\nb\nc\n" "" "b\na\nc\n"
13 testing "numeric" "sort -n input" "1\n3\n010\n" "3\n1\n010\n" ""
14 testing "reverse" "sort -r input" "wook\nwalrus\npoint\npabst\naargh\n" \
15 "point\nwook\npabst\naargh\nwalrus\n" ""
17 # These tests require the full option set.
20 # Longish chunk of data re-used by the next few tests. The expected output
21 # varies, but the input (this) is the same.
32 testing "one key" "sort -k4,4 input" \
40 # The numeric sort orders field 2, ignores field 3 (because numeric sort stops
41 # at the whitespace), then the global fallback sort does an alpha sort on
42 # the whole string (starting at the beginning of the line).
44 testing "key range with numeric option" "sort -k2,3n input" \
52 # Numeric sort on field 2 (again, ignore field 3 because it's numeric),
53 # then do a _reversed_ alpha sort on the whole line as a tiebreaker.
55 testing "key range with numeric option and global reverse" \
56 "sort -k2,3n -r input" \
64 # Reversed numeric sort on field 2 (numeric ignores field 3), then
65 # break ties with alpha sort on whole line.
67 testing "key range with multiple options" "sort -k2,3rn input" \
75 testing "key doesn't strip leading blanks, disables fallback global sort" \
76 "sort -n -k2 -t ' '" " a \n 1 \n 2 \n" "" " 2 \n 1 \n a \n"
78 # Test case contributed by Joey Hess:
80 testing "key edge case with -t" "sort -n -k4 -t/" \
81 "/usr/lib/finish-install.d/1
82 /usr/lib/finish-install.d/4
83 /usr/lib/prebaseconfig.d/2
84 /usr/lib/prebaseconfig.d/6
85 " "" "/usr/lib/finish-install.d/1
86 /usr/lib/prebaseconfig.d/2
87 /usr/lib/finish-install.d/4
88 /usr/lib/prebaseconfig.d/6
91 testing "-x" "sort -x" "010\na0\n 0c0\n" "" "a0\n010\n 0c0\n"
93 # Test that -f applies to key or fallback independently
95 testing "" "sort -k2,2f" "A b b\na B C\na B a\n" "" "a B a\nA b b\na B C\n"
96 testing "" "sort -k2,2" "a B C\na B a\nA b b\n" "" "a B a\nA b b\na B C\n"
97 testing "" "sort -f -k2,2" "A b b\na B C\na B a\n" "" "a B a\nA b b\na B C\n"
101 # not numbers < NaN < -infinity < numbers < +infinity
102 testing "-g" "sort -g" \
103 "bork\nNaN\n-inf\n0.4\n1.222\n01.37\n2.1\n+infinity\n" "" \
104 "01.37\n1.222\n2.1\n0.4\nNaN\nbork\n-inf\n+infinity\n"