summaryrefslogtreecommitdiff
path: root/tests/misc/sort
diff options
context:
space:
mode:
authorMichael Speer <knomenet@gmail.com>2009-04-27 14:51:29 +0100
committerPádraig Brady <P@draigBrady.com>2009-05-26 14:49:17 +0100
commit159faba1376ffd5a46fe4bbc780d85dd3e502cea (patch)
tree26c0be6ee86af0609569bdc7af0999e03b1e2b3e /tests/misc/sort
parentc45c51fe97193898f3909dcf5e4c0e117ab239a2 (diff)
downloadcoreutils-159faba1376ffd5a46fe4bbc780d85dd3e502cea.tar.xz
sort: new --human-numeric-sort option to sort KiB MB etc.
* NEWS: Document the new option * doc/coreutils.texi (sort invocation): ditto * src/sort.c (main): handle the new --human-numeric-sort option (-h). (human_numcompare): A new function to compare SI and IEC suffixes before falling back to the standard --numeric comparison. (find_unit_order): A new helper function to find the order of magnitude of a number string as determined by its suffix. (check_mixed_SI_IEC): A new helper function to exit with error if both SI and IEC suffixes are presented. * tests/misc/sort: Add 8 tests to test the new functionality. * THANKS: Update
Diffstat (limited to 'tests/misc/sort')
-rwxr-xr-xtests/misc/sort18
1 files changed, 18 insertions, 0 deletions
diff --git a/tests/misc/sort b/tests/misc/sort
index c5a2d7492..ae3bd8e49 100755
--- a/tests/misc/sort
+++ b/tests/misc/sort
@@ -54,6 +54,24 @@ my @Tests =
["n11a", '-s -n -k1,1', {IN=>".01a\n.010\n"}, {OUT=>".01a\n.010\n"}],
["n11b", '-s -n -k1,1', {IN=>".010\n.01a\n"}, {OUT=>".010\n.01a\n"}],
+# human readable suffixes
+["h1", '-h', {IN=>"Y\nZ\nE\nP\nT\nG\nM\nK\n"},
+ {OUT=>"K\nM\nG\nT\nP\nE\nZ\nY\n"}],
+["h2", '-h', {IN=>"1M\n-2G\n-3K"}, {OUT=>"-2G\n-3K\n1M\n"}],
+["h3", '-h', {IN=>"1Mi\n1M\n"}, {OUT=>""}, {EXIT=>2},
+ {ERR=>"$prog: both SI and IEC prefixes present on units\n"}],
+# decimal at end => ignore suffix
+["h4", '-h', {IN=>"1.E\n2.M\n"}, {OUT=>"1.E\n2.M\n"}],
+# double decimal => ignore suffix
+["h5", '-h', {IN=>"1..2E\n2..2M\n"}, {OUT=>"1..2E\n2..2M\n"}],
+# illustrate misordering of ambiguous abbreviations
+["h6", '-h', {IN=>"1GiB\n1030MiB\n"}, {OUT=>"1030MiB\n1GiB\n"}],
+# check option incompatibility
+["h7", '-hn', {IN=>""}, {OUT=>""}, {EXIT=>2},
+ {ERR=>"$prog: options `-hn' are incompatible\n"}],
+# check key processing
+["h8", '-n -k2,2h', {IN=>"1 1E\n2 2M\n"}, {OUT=>"2 2M\n1 1E\n"}],
+
["01a", '', {IN=>"A\nB\nC\n"}, {OUT=>"A\nB\nC\n"}],
#
["02a", '-c', {IN=>"A\nB\nC\n"}, {OUT=>''}],