mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-29 12:07:46 +00:00
Sort: Implement stable sort, ignore non-printing, month sort dedup, auto parallel sort through rayon, zero terminated sort, check silent (#2008)
This commit is contained in:
parent
b26e12eaa4
commit
8474249e5f
35 changed files with 1442 additions and 213 deletions
|
@ -1,44 +1,82 @@
|
|||
use crate::common::util::*;
|
||||
|
||||
#[test]
|
||||
fn test_check_zero_terminated_failure() {
|
||||
new_ucmd!()
|
||||
.arg("-z")
|
||||
.arg("-c")
|
||||
.arg("zero-terminated.txt")
|
||||
.fails()
|
||||
.stdout_is("sort: disorder in line 0\n");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_check_zero_terminated_success() {
|
||||
new_ucmd!()
|
||||
.arg("-z")
|
||||
.arg("-c")
|
||||
.arg("zero-terminated.expected")
|
||||
.succeeds();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_random_shuffle_len() {
|
||||
// check whether output is the same length as the input
|
||||
const FILE: &'static str = "default_unsorted_ints.expected";
|
||||
let (at, _ucmd) = at_and_ucmd!();
|
||||
let result = new_ucmd!().arg("-R").arg(FILE).run().stdout;
|
||||
let expected = at.read(FILE);
|
||||
|
||||
assert_ne!(result, expected);
|
||||
assert_eq!(result.len(), expected.len());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_random_shuffle_contains_all_lines() {
|
||||
// check whether lines of input are all in output
|
||||
const FILE: &'static str = "default_unsorted_ints.expected";
|
||||
let (at, _ucmd) = at_and_ucmd!();
|
||||
let result = new_ucmd!().arg("-R").arg(FILE).run().stdout;
|
||||
let expected = at.read(FILE);
|
||||
let result_sorted = new_ucmd!().pipe_in(result.clone()).run().stdout;
|
||||
|
||||
assert_ne!(result, expected);
|
||||
assert_eq!(result_sorted, expected);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_random_shuffle_contains_two_runs_not_the_same() {
|
||||
// check to verify that two random shuffles are not equal; this has the
|
||||
// potential to fail in the unlikely event that random order is the same
|
||||
// as the starting order, or if both random sorts end up having the same order.
|
||||
const FILE: &'static str = "default_unsorted_ints.expected";
|
||||
let (at, _ucmd) = at_and_ucmd!();
|
||||
let result = new_ucmd!().arg("-R").arg(FILE).run().stdout;
|
||||
let expected = at.read(FILE);
|
||||
let unexpected = new_ucmd!().arg("-R").arg(FILE).run().stdout;
|
||||
|
||||
assert_ne!(result, expected);
|
||||
assert_ne!(result, unexpected);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_numeric_floats_and_ints() {
|
||||
for numeric_sort_param in vec!["-n", "--numeric-sort"] {
|
||||
let input = "1.444\n8.013\n1\n-8\n1.04\n-1";
|
||||
new_ucmd!()
|
||||
.arg(numeric_sort_param)
|
||||
.pipe_in(input)
|
||||
.succeeds()
|
||||
.stdout_only("-8\n-1\n1\n1.04\n1.444\n8.013\n");
|
||||
}
|
||||
test_helper("numeric_floats_and_ints", "-n");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_numeric_floats() {
|
||||
for numeric_sort_param in vec!["-n", "--numeric-sort"] {
|
||||
let input = "1.444\n8.013\n1.58590\n-8.90880\n1.040000000\n-.05";
|
||||
new_ucmd!()
|
||||
.arg(numeric_sort_param)
|
||||
.pipe_in(input)
|
||||
.succeeds()
|
||||
.stdout_only("-8.90880\n-.05\n1.040000000\n1.444\n1.58590\n8.013\n");
|
||||
}
|
||||
test_helper("numeric_floats", "-n");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_numeric_floats_with_nan() {
|
||||
for numeric_sort_param in vec!["-n", "--numeric-sort"] {
|
||||
let input = "1.444\n1.0/0.0\n1.58590\n-8.90880\n1.040000000\n-.05";
|
||||
new_ucmd!()
|
||||
.arg(numeric_sort_param)
|
||||
.pipe_in(input)
|
||||
.succeeds()
|
||||
.stdout_only("-8.90880\n-.05\n1.0/0.0\n1.040000000\n1.444\n1.58590\n");
|
||||
}
|
||||
test_helper("numeric_floats_with_nan", "-n");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_numeric_unfixed_floats() {
|
||||
test_helper("numeric_fixed_floats", "-n");
|
||||
test_helper("numeric_unfixed_floats", "-n");
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -53,26 +91,12 @@ fn test_numeric_unsorted_ints() {
|
|||
|
||||
#[test]
|
||||
fn test_human_block_sizes() {
|
||||
for human_numeric_sort_param in vec!["-h", "--human-numeric-sort"] {
|
||||
let input = "8981K\n909991M\n-8T\n21G\n0.8M";
|
||||
new_ucmd!()
|
||||
.arg(human_numeric_sort_param)
|
||||
.pipe_in(input)
|
||||
.succeeds()
|
||||
.stdout_only("-8T\n0.8M\n8981K\n21G\n909991M\n");
|
||||
}
|
||||
test_helper("human_block_sizes", "-h");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_month_default() {
|
||||
for month_sort_param in vec!["-M", "--month-sort"] {
|
||||
let input = "JAn\nMAY\n000may\nJun\nFeb";
|
||||
new_ucmd!()
|
||||
.arg(month_sort_param)
|
||||
.pipe_in(input)
|
||||
.succeeds()
|
||||
.stdout_only("000may\nJAn\nFeb\nMAY\nJun\n");
|
||||
}
|
||||
test_helper("month_default", "-M");
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -82,23 +106,12 @@ fn test_month_stable() {
|
|||
|
||||
#[test]
|
||||
fn test_default_unsorted_ints() {
|
||||
let input = "9\n1909888\n000\n1\n2";
|
||||
new_ucmd!()
|
||||
.pipe_in(input)
|
||||
.succeeds()
|
||||
.stdout_only("000\n1\n1909888\n2\n9\n");
|
||||
test_helper("default_unsorted_ints", "");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_numeric_unique_ints() {
|
||||
for numeric_unique_sort_param in vec!["-nu"] {
|
||||
let input = "9\n9\n8\n1\n";
|
||||
new_ucmd!()
|
||||
.arg(numeric_unique_sort_param)
|
||||
.pipe_in(input)
|
||||
.succeeds()
|
||||
.stdout_only("1\n8\n9\n");
|
||||
}
|
||||
test_helper("numeric_unsorted_ints_unique", "-nu");
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -116,6 +129,148 @@ fn test_dictionary_order() {
|
|||
test_helper("dictionary_order", "-d");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_dictionary_order2() {
|
||||
for non_dictionary_order2_param in vec!["-d"] {
|
||||
new_ucmd!()
|
||||
.pipe_in("a👦🏻aa b\naaaa b")
|
||||
.arg(non_dictionary_order2_param)
|
||||
.succeeds()
|
||||
.stdout_only("a👦🏻aa b\naaaa b\n");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_non_printing_chars() {
|
||||
for non_printing_chars_param in vec!["-i"] {
|
||||
new_ucmd!()
|
||||
.pipe_in("a👦🏻aa b\naaaa b")
|
||||
.arg(non_printing_chars_param)
|
||||
.succeeds()
|
||||
.stdout_only("aaaa b\na👦🏻aa b\n");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_exponents_positive_general_fixed() {
|
||||
for exponents_positive_general_param in vec!["-g"] {
|
||||
new_ucmd!()
|
||||
.pipe_in("100E6\n\n50e10\n+100000\n\n10000K78\n10E\n\n\n1000EDKLD\n\n\n100E6\n\n50e10\n+100000\n\n")
|
||||
.arg(exponents_positive_general_param)
|
||||
.succeeds()
|
||||
.stdout_only("\n\n\n\n\n\n\n\n10000K78\n1000EDKLD\n10E\n+100000\n+100000\n100E6\n100E6\n50e10\n50e10\n");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_exponents_positive_numeric() {
|
||||
test_helper("exponents-positive-numeric", "-n");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_months_dedup() {
|
||||
test_helper("months-dedup", "-Mu");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_mixed_floats_ints_chars_numeric() {
|
||||
test_helper("mixed_floats_ints_chars_numeric", "-n");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_mixed_floats_ints_chars_numeric_unique() {
|
||||
test_helper("mixed_floats_ints_chars_numeric_unique", "-nu");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_mixed_floats_ints_chars_numeric_reverse() {
|
||||
test_helper("mixed_floats_ints_chars_numeric_unique_reverse", "-nur");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_mixed_floats_ints_chars_numeric_stable() {
|
||||
test_helper("mixed_floats_ints_chars_numeric_stable", "-ns");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_numeric_floats_and_ints2() {
|
||||
for numeric_sort_param in vec!["-n", "--numeric-sort"] {
|
||||
let input = "1.444\n8.013\n1\n-8\n1.04\n-1";
|
||||
new_ucmd!()
|
||||
.arg(numeric_sort_param)
|
||||
.pipe_in(input)
|
||||
.succeeds()
|
||||
.stdout_only("-8\n-1\n1\n1.04\n1.444\n8.013\n");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_numeric_floats2() {
|
||||
for numeric_sort_param in vec!["-n", "--numeric-sort"] {
|
||||
let input = "1.444\n8.013\n1.58590\n-8.90880\n1.040000000\n-.05";
|
||||
new_ucmd!()
|
||||
.arg(numeric_sort_param)
|
||||
.pipe_in(input)
|
||||
.succeeds()
|
||||
.stdout_only("-8.90880\n-.05\n1.040000000\n1.444\n1.58590\n8.013\n");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_numeric_floats_with_nan2() {
|
||||
test_helper("numeric-floats-with-nan2", "-n");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_human_block_sizes2() {
|
||||
for human_numeric_sort_param in vec!["-h", "--human-numeric-sort"] {
|
||||
let input = "8981K\n909991M\n-8T\n21G\n0.8M";
|
||||
new_ucmd!()
|
||||
.arg(human_numeric_sort_param)
|
||||
.pipe_in(input)
|
||||
.succeeds()
|
||||
.stdout_only("-8T\n0.8M\n8981K\n21G\n909991M\n");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_month_default2() {
|
||||
for month_sort_param in vec!["-M", "--month-sort"] {
|
||||
let input = "JAn\nMAY\n000may\nJun\nFeb";
|
||||
new_ucmd!()
|
||||
.arg(month_sort_param)
|
||||
.pipe_in(input)
|
||||
.succeeds()
|
||||
.stdout_only("000may\nJAn\nFeb\nMAY\nJun\n");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_default_unsorted_ints2() {
|
||||
let input = "9\n1909888\n000\n1\n2";
|
||||
new_ucmd!()
|
||||
.pipe_in(input)
|
||||
.succeeds()
|
||||
.stdout_only("000\n1\n1909888\n2\n9\n");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_numeric_unique_ints2() {
|
||||
for numeric_unique_sort_param in vec!["-nu"] {
|
||||
let input = "9\n9\n8\n1\n";
|
||||
new_ucmd!()
|
||||
.arg(numeric_unique_sort_param)
|
||||
.pipe_in(input)
|
||||
.succeeds()
|
||||
.stdout_only("1\n8\n9\n");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_zero_terminated() {
|
||||
test_helper("zero-terminated", "-z");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_multiple_files() {
|
||||
new_ucmd!()
|
||||
|
@ -192,6 +347,15 @@ fn test_check() {
|
|||
.stdout_is("");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_check_silent() {
|
||||
new_ucmd!()
|
||||
.arg("-C")
|
||||
.arg("check_fail.txt")
|
||||
.fails()
|
||||
.stdout_is("");
|
||||
}
|
||||
|
||||
fn test_helper(file_name: &str, args: &str) {
|
||||
new_ucmd!()
|
||||
.arg(args)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue