11 | 11 |
itertools = "0.9"
|
12 | 12 |
semver = "0.9.0"
|
13 | 13 |
uucore = { version=">=0.0.8", package="uucore", path="../../uucore", features=["fs"] }
|
14 | |
Index: coreutils/src/uu/sort/src/sort.rs
|
15 | |
===================================================================
|
16 | |
--- coreutils.orig/src/uu/sort/src/sort.rs
|
17 | |
+++ coreutils/src/uu/sort/src/sort.rs
|
|
14 |
diff --git b/src/uu/sort/src/sort.rs a/src/uu/sort/src/sort.rs
|
|
15 |
index 6c29ad98..8e79ff94 100644
|
|
16 |
--- b/src/uu/sort/src/sort.rs
|
|
17 |
+++ a/src/uu/sort/src/sort.rs
|
18 | 18 |
@@ -1,7 +1,6 @@
|
19 | 19 |
// * This file is part of the uutils coreutils package.
|
20 | 20 |
// *
|
|
41 | 41 |
use uucore::fs::is_stdin_interactive; // for Iterator::dedup()
|
42 | 42 |
|
43 | 43 |
static NAME: &str = "sort";
|
44 | |
@@ -39,18 +34,16 @@ static OPT_DICTIONARY_ORDER: &str = "dic
|
|
44 |
@@ -39,18 +34,16 @@ static OPT_DICTIONARY_ORDER: &str = "dictionary-order";
|
45 | 45 |
static OPT_MERGE: &str = "merge";
|
46 | 46 |
static OPT_CHECK: &str = "check";
|
47 | 47 |
static OPT_IGNORE_CASE: &str = "ignore-case";
|
|
102 | 102 |
With no FILE, or when FILE is -, read standard input.",
|
103 | 103 |
NAME, VERSION
|
104 | 104 |
)
|
105 | |
@@ -237,12 +229,6 @@ pub fn uumain(args: impl uucore::Args) -
|
|
105 |
@@ -236,12 +228,6 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
|
|
106 |
.long(OPT_IGNORE_CASE)
|
106 | 107 |
.help("fold lower case to upper case characters"),
|
107 | 108 |
)
|
108 | |
.arg(
|
|
109 |
- .arg(
|
109 | 110 |
- Arg::with_name(OPT_IGNORE_BLANKS)
|
110 | 111 |
- .short("b")
|
111 | 112 |
- .long(OPT_IGNORE_BLANKS)
|
112 | 113 |
- .help("ignore leading blanks when finding sort keys in each line"),
|
113 | 114 |
- )
|
114 | |
- .arg(
|
|
115 |
.arg(
|
115 | 116 |
Arg::with_name(OPT_OUTPUT)
|
116 | 117 |
.short("o")
|
117 | |
.long(OPT_OUTPUT)
|
118 | |
@@ -251,12 +237,6 @@ pub fn uumain(args: impl uucore::Args) -
|
|
118 |
@@ -250,12 +236,6 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
|
|
119 |
.takes_value(true)
|
119 | 120 |
.value_name("FILENAME"),
|
120 | 121 |
)
|
121 | |
.arg(
|
|
122 |
- .arg(
|
122 | 123 |
- Arg::with_name(OPT_RANDOM)
|
123 | 124 |
- .short("R")
|
124 | 125 |
- .long(OPT_RANDOM)
|
125 | 126 |
- .help("shuffle in random order"),
|
126 | 127 |
- )
|
127 | |
- .arg(
|
|
128 |
.arg(
|
128 | 129 |
Arg::with_name(OPT_REVERSE)
|
129 | 130 |
.short("r")
|
130 | |
.long(OPT_REVERSE)
|
131 | |
@@ -305,20 +285,11 @@ pub fn uumain(args: impl uucore::Args) -
|
|
131 |
@@ -305,20 +285,11 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
|
132 | 132 |
settings.transform_fns.push(|s| s.to_uppercase());
|
133 | 133 |
}
|
134 | 134 |
|
|
149 | 149 |
//let mut files = matches.free;
|
150 | 150 |
if files.is_empty() {
|
151 | 151 |
/* if no file, default to stdin */
|
152 | |
@@ -342,10 +313,10 @@ pub fn uumain(args: impl uucore::Args) -
|
|
152 |
@@ -342,10 +313,10 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
|
153 | 153 |
}
|
154 | 154 |
}
|
155 | 155 |
|
|
162 | 162 |
let mut lines = Vec::new();
|
163 | 163 |
let mut file_merger = FileMerger::new(&settings);
|
164 | 164 |
|
165 | |
@@ -380,13 +351,6 @@ fn exec(files: Vec<String>, settings: &m
|
|
165 |
@@ -380,13 +351,6 @@ fn exec(files: Vec<String>, settings: &mut Settings) -> i32 {
|
166 | 166 |
} else {
|
167 | 167 |
print_sorted(file_merger, &settings.outfile)
|
168 | 168 |
}
|
|
176 | 176 |
} else if settings.unique {
|
177 | 177 |
print_sorted(lines.iter().dedup(), &settings.outfile)
|
178 | 178 |
} else {
|
179 | |
@@ -455,11 +419,7 @@ fn compare_by(a: &str, b: &str, settings
|
|
179 |
@@ -455,11 +419,7 @@ fn compare_by(a: &str, b: &str, settings: &Settings) -> Ordering {
|
180 | 180 |
};
|
181 | 181 |
|
182 | 182 |
for compare_fn in &settings.compare_fns {
|
|
189 | 189 |
if cmp != Ordering::Equal {
|
190 | 190 |
if settings.reverse {
|
191 | 191 |
return cmp.reverse();
|
192 | |
@@ -471,60 +431,36 @@ fn compare_by(a: &str, b: &str, settings
|
|
192 |
@@ -471,60 +431,36 @@ fn compare_by(a: &str, b: &str, settings: &Settings) -> Ordering {
|
193 | 193 |
Ordering::Equal
|
194 | 194 |
}
|
195 | 195 |
|
|
236 | 236 |
- Ok(a) if a.is_nan() => std::f64::NEG_INFINITY,
|
237 | 237 |
- Ok(a) => a,
|
238 | 238 |
- Err(_) => std::f64::NEG_INFINITY,
|
239 | |
- }
|
240 | 239 |
+ match a.split_whitespace().next() {
|
241 | 240 |
+ None => std::f64::NEG_INFINITY,
|
242 | 241 |
+ Some(sa) => match sa.parse::<f64>() {
|
|
244 | 243 |
+ Ok(a) => a,
|
245 | 244 |
+ Err(_) => std::f64::NEG_INFINITY,
|
246 | 245 |
+ },
|
247 | |
+}
|
248 | |
+
|
|
246 |
}
|
|
247 |
}
|
|
248 |
|
|
249 |
-/// Compares two floats, with errors and non-numerics assumed to be -inf.
|
|
250 |
-/// Stops coercing at the first non-numeric char.
|
249 | 251 |
+fn default_compare(a: &str, b: &str) -> Ordering {
|
250 | 252 |
+ a.cmp(b)
|
251 | |
}
|
252 | |
|
253 | |
-/// Compares two floats, with errors and non-numerics assumed to be -inf.
|
254 | |
-/// Stops coercing at the first non-numeric char.
|
|
253 |
+}
|
|
254 |
+
|
255 | 255 |
+/// Compares two floating point numbers, with errors being assumed to be -inf.
|
256 | 256 |
+/// Stops coercing at the first whitespace char, so 1e2 will parse as 100 but
|
257 | 257 |
+/// 1,000 will parse as -inf.
|
258 | 258 |
fn numeric_compare(a: &str, b: &str) -> Ordering {
|
259 | 259 |
#![allow(clippy::comparison_chain)]
|
260 | |
|
|
260 |
-
|
261 | 261 |
- let sa = get_leading_number(a);
|
262 | 262 |
- let sb = get_leading_number(b);
|
263 | 263 |
-
|
|
272 | 272 |
if fa > fb {
|
273 | 273 |
Ordering::Greater
|
274 | 274 |
} else if fa < fb {
|
275 | |
@@ -535,10 +471,10 @@ fn numeric_compare(a: &str, b: &str) ->
|
|
275 |
@@ -535,10 +471,10 @@ fn numeric_compare(a: &str, b: &str) -> Ordering {
|
276 | 276 |
}
|
277 | 277 |
|
278 | 278 |
fn human_numeric_convert(a: &str) -> f64 {
|
|
287 | 287 |
'K' => 1000f64,
|
288 | 288 |
'M' => 1E6,
|
289 | 289 |
'G' => 1E9,
|
290 | |
@@ -565,30 +501,6 @@ fn human_numeric_size_compare(a: &str, b
|
|
290 |
@@ -565,30 +501,6 @@ fn human_numeric_size_compare(a: &str, b: &str) -> Ordering {
|
291 | 291 |
}
|
292 | 292 |
}
|
293 | 293 |
|
|
318 | 318 |
#[derive(Eq, Ord, PartialEq, PartialOrd)]
|
319 | 319 |
enum Month {
|
320 | 320 |
Unknown,
|
321 | |
@@ -694,65 +606,3 @@ fn open(path: &str) -> Option<(Box<dyn R
|
|
321 |
@@ -694,65 +606,3 @@ fn open(path: &str) -> Option<(Box<dyn Read>, bool)> {
|
322 | 322 |
}
|
323 | 323 |
}
|
324 | 324 |
}
|
|
384 | 384 |
- assert_eq!(Ordering::Equal, random_shuffle(a, b, c));
|
385 | 385 |
- }
|
386 | 386 |
-}
|
387 | |
Index: coreutils/tests/by-util/test_sort.rs
|
388 | |
===================================================================
|
389 | |
--- coreutils.orig/tests/by-util/test_sort.rs
|
390 | |
+++ coreutils/tests/by-util/test_sort.rs
|
391 | |
@@ -2,43 +2,22 @@ use crate::common::util::*;
|
392 | |
|
393 | |
#[test]
|
394 | |
fn test_numeric_floats_and_ints() {
|
395 | |
- for numeric_sort_param in vec!["-n", "--numeric-sort"] {
|
396 | |
- let input = "1.444\n8.013\n1\n-8\n1.04\n-1";
|
397 | |
- new_ucmd!()
|
398 | |
- .arg(numeric_sort_param)
|
399 | |
- .pipe_in(input)
|
400 | |
- .succeeds()
|
401 | |
- .stdout_only("-8\n-1\n1\n1.04\n1.444\n8.013\n");
|
402 | |
- }
|
403 | |
+ test_helper("numeric_floats_and_ints", "-n");
|
404 | |
}
|
405 | |
|
406 | |
#[test]
|
407 | |
fn test_numeric_floats() {
|
408 | |
- for numeric_sort_param in vec!["-n", "--numeric-sort"] {
|
409 | |
- let input = "1.444\n8.013\n1.58590\n-8.90880\n1.040000000\n-.05";
|
410 | |
- new_ucmd!()
|
411 | |
- .arg(numeric_sort_param)
|
412 | |
- .pipe_in(input)
|
413 | |
- .succeeds()
|
414 | |
- .stdout_only("-8.90880\n-.05\n1.040000000\n1.444\n1.58590\n8.013\n");
|
415 | |
- }
|
416 | |
+ test_helper("numeric_floats", "-n");
|
417 | |
}
|
418 | |
|
419 | |
#[test]
|
420 | |
fn test_numeric_floats_with_nan() {
|
421 | |
- for numeric_sort_param in vec!["-n", "--numeric-sort"] {
|
422 | |
- let input = "1.444\n1.0/0.0\n1.58590\n-8.90880\n1.040000000\n-.05";
|
423 | |
- new_ucmd!()
|
424 | |
- .arg(numeric_sort_param)
|
425 | |
- .pipe_in(input)
|
426 | |
- .succeeds()
|
427 | |
- .stdout_only("-8.90880\n-.05\n1.0/0.0\n1.040000000\n1.444\n1.58590\n");
|
428 | |
- }
|
429 | |
+ test_helper("numeric_floats_with_nan", "-n");
|
430 | |
}
|
431 | |
|
432 | |
#[test]
|
433 | |
fn test_numeric_unfixed_floats() {
|
434 | |
- test_helper("numeric_fixed_floats", "-n");
|
435 | |
+ test_helper("numeric_unfixed_floats", "-n");
|
436 | |
}
|
437 | |
|
438 | |
#[test]
|
439 | |
@@ -53,26 +32,12 @@ fn test_numeric_unsorted_ints() {
|
440 | |
|
441 | |
#[test]
|
442 | |
fn test_human_block_sizes() {
|
443 | |
- for human_numeric_sort_param in vec!["-h", "--human-numeric-sort"] {
|
444 | |
- let input = "8981K\n909991M\n-8T\n21G\n0.8M";
|
445 | |
- new_ucmd!()
|
446 | |
- .arg(human_numeric_sort_param)
|
447 | |
- .pipe_in(input)
|
448 | |
- .succeeds()
|
449 | |
- .stdout_only("-8T\n0.8M\n8981K\n21G\n909991M\n");
|
450 | |
- }
|
451 | |
+ test_helper("human_block_sizes", "-h");
|
452 | |
}
|
453 | |
|
454 | |
#[test]
|
455 | |
fn test_month_default() {
|
456 | |
- for month_sort_param in vec!["-M", "--month-sort"] {
|
457 | |
- let input = "JAn\nMAY\n000may\nJun\nFeb";
|
458 | |
- new_ucmd!()
|
459 | |
- .arg(month_sort_param)
|
460 | |
- .pipe_in(input)
|
461 | |
- .succeeds()
|
462 | |
- .stdout_only("000may\nJAn\nFeb\nMAY\nJun\n");
|
463 | |
- }
|
464 | |
+ test_helper("month_default", "-M");
|
465 | |
}
|
466 | |
|
467 | |
#[test]
|
468 | |
@@ -82,23 +47,12 @@ fn test_month_stable() {
|
469 | |
|
470 | |
#[test]
|
471 | |
fn test_default_unsorted_ints() {
|
472 | |
- let input = "9\n1909888\n000\n1\n2";
|
473 | |
- new_ucmd!()
|
474 | |
- .pipe_in(input)
|
475 | |
- .succeeds()
|
476 | |
- .stdout_only("000\n1\n1909888\n2\n9\n");
|
477 | |
+ test_helper("default_unsorted_ints", "");
|
478 | |
}
|
479 | |
|
480 | |
#[test]
|
481 | |
fn test_numeric_unique_ints() {
|
482 | |
- for numeric_unique_sort_param in vec!["-nu"] {
|
483 | |
- let input = "9\n9\n8\n1\n";
|
484 | |
- new_ucmd!()
|
485 | |
- .arg(numeric_unique_sort_param)
|
486 | |
- .pipe_in(input)
|
487 | |
- .succeeds()
|
488 | |
- .stdout_only("1\n8\n9\n");
|
489 | |
- }
|
490 | |
+ test_helper("numeric_unsorted_ints_unique", "-nu");
|
491 | |
}
|
492 | |
|
493 | |
#[test]
|