mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-30 20:47:46 +00:00
Merge pull request #2264 from miDeb/sort-sort-flag
sort: support --sort flag and check for conflicts
This commit is contained in:
commit
b175534a97
2 changed files with 202 additions and 115 deletions
|
@ -1,18 +1,20 @@
|
|||
use crate::common::util::*;
|
||||
|
||||
fn test_helper(file_name: &str, args: &str) {
|
||||
new_ucmd!()
|
||||
.arg(format!("{}.txt", file_name))
|
||||
.args(&args.split(' ').collect::<Vec<&str>>())
|
||||
.succeeds()
|
||||
.stdout_is_fixture(format!("{}.expected", file_name));
|
||||
fn test_helper(file_name: &str, possible_args: &[&str]) {
|
||||
for args in possible_args {
|
||||
new_ucmd!()
|
||||
.arg(format!("{}.txt", file_name))
|
||||
.args(&args.split(' ').collect::<Vec<&str>>())
|
||||
.succeeds()
|
||||
.stdout_is_fixture(format!("{}.expected", file_name));
|
||||
|
||||
new_ucmd!()
|
||||
.arg(format!("{}.txt", file_name))
|
||||
.arg("--debug")
|
||||
.args(&args.split(' ').collect::<Vec<&str>>())
|
||||
.succeeds()
|
||||
.stdout_is_fixture(format!("{}.expected.debug", file_name));
|
||||
new_ucmd!()
|
||||
.arg(format!("{}.txt", file_name))
|
||||
.arg("--debug")
|
||||
.args(&args.split(' ').collect::<Vec<&str>>())
|
||||
.succeeds()
|
||||
.stdout_is_fixture(format!("{}.expected.debug", file_name));
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -71,7 +73,7 @@ fn test_extsort_zero_terminated() {
|
|||
|
||||
#[test]
|
||||
fn test_months_whitespace() {
|
||||
test_helper("months-whitespace", "-M");
|
||||
test_helper("months-whitespace", &["-M", "--month-sort", "--sort=month"]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -85,7 +87,10 @@ fn test_version_empty_lines() {
|
|||
|
||||
#[test]
|
||||
fn test_human_numeric_whitespace() {
|
||||
test_helper("human-numeric-whitespace", "-h");
|
||||
test_helper(
|
||||
"human-numeric-whitespace",
|
||||
&["-h", "--human-numeric-sort", "--sort=human-numeric"],
|
||||
);
|
||||
}
|
||||
|
||||
// This tests where serde often fails when reading back JSON
|
||||
|
@ -102,12 +107,18 @@ fn test_extsort_as64_bailout() {
|
|||
|
||||
#[test]
|
||||
fn test_multiple_decimals_general() {
|
||||
test_helper("multiple_decimals_general", "-g")
|
||||
test_helper(
|
||||
"multiple_decimals_general",
|
||||
&["-g", "--general-numeric-sort", "--sort=general-numeric"],
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_multiple_decimals_numeric() {
|
||||
test_helper("multiple_decimals_numeric", "-n")
|
||||
test_helper(
|
||||
"multiple_decimals_numeric",
|
||||
&["-n", "--numeric-sort", "--sort=numeric"],
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -186,72 +197,93 @@ fn test_random_shuffle_contains_two_runs_not_the_same() {
|
|||
|
||||
#[test]
|
||||
fn test_numeric_floats_and_ints() {
|
||||
test_helper("numeric_floats_and_ints", "-n");
|
||||
test_helper(
|
||||
"numeric_floats_and_ints",
|
||||
&["-n", "--numeric-sort", "--sort=numeric"],
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_numeric_floats() {
|
||||
test_helper("numeric_floats", "-n");
|
||||
test_helper(
|
||||
"numeric_floats",
|
||||
&["-n", "--numeric-sort", "--sort=numeric"],
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_numeric_floats_with_nan() {
|
||||
test_helper("numeric_floats_with_nan", "-n");
|
||||
test_helper(
|
||||
"numeric_floats_with_nan",
|
||||
&["-n", "--numeric-sort", "--sort=numeric"],
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_numeric_unfixed_floats() {
|
||||
test_helper("numeric_unfixed_floats", "-n");
|
||||
test_helper(
|
||||
"numeric_unfixed_floats",
|
||||
&["-n", "--numeric-sort", "--sort=numeric"],
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_numeric_fixed_floats() {
|
||||
test_helper("numeric_fixed_floats", "-n");
|
||||
test_helper(
|
||||
"numeric_fixed_floats",
|
||||
&["-n", "--numeric-sort", "--sort=numeric"],
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_numeric_unsorted_ints() {
|
||||
test_helper("numeric_unsorted_ints", "-n");
|
||||
test_helper(
|
||||
"numeric_unsorted_ints",
|
||||
&["-n", "--numeric-sort", "--sort=numeric"],
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_human_block_sizes() {
|
||||
test_helper("human_block_sizes", "-h");
|
||||
test_helper(
|
||||
"human_block_sizes",
|
||||
&["-h", "--human-numeric-sort", "--sort=human-numeric"],
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_month_default() {
|
||||
test_helper("month_default", "-M");
|
||||
test_helper("month_default", &["-M", "--month-sort", "--sort=month"]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_month_stable() {
|
||||
test_helper("month_stable", "-Ms");
|
||||
test_helper("month_stable", &["-Ms"]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_default_unsorted_ints() {
|
||||
test_helper("default_unsorted_ints", "");
|
||||
test_helper("default_unsorted_ints", &[""]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_numeric_unique_ints() {
|
||||
test_helper("numeric_unsorted_ints_unique", "-nu");
|
||||
test_helper("numeric_unsorted_ints_unique", &["-nu"]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_version() {
|
||||
test_helper("version", "-V");
|
||||
test_helper("version", &["-V"]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_ignore_case() {
|
||||
test_helper("ignore_case", "-f");
|
||||
test_helper("ignore_case", &["-f"]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_dictionary_order() {
|
||||
test_helper("dictionary_order", "-d");
|
||||
test_helper("dictionary_order", &["-d"]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -278,47 +310,53 @@ fn test_non_printing_chars() {
|
|||
|
||||
#[test]
|
||||
fn test_exponents_positive_general_fixed() {
|
||||
test_helper("exponents_general", "-g");
|
||||
test_helper("exponents_general", &["-g"]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_exponents_positive_numeric() {
|
||||
test_helper("exponents-positive-numeric", "-n");
|
||||
test_helper(
|
||||
"exponents-positive-numeric",
|
||||
&["-n", "--numeric-sort", "--sort=numeric"],
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_months_dedup() {
|
||||
test_helper("months-dedup", "-Mu");
|
||||
test_helper("months-dedup", &["-Mu"]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_mixed_floats_ints_chars_numeric() {
|
||||
test_helper("mixed_floats_ints_chars_numeric", "-n");
|
||||
test_helper(
|
||||
"mixed_floats_ints_chars_numeric",
|
||||
&["-n", "--numeric-sort", "--sort=numeric"],
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_mixed_floats_ints_chars_numeric_unique() {
|
||||
test_helper("mixed_floats_ints_chars_numeric_unique", "-nu");
|
||||
test_helper("mixed_floats_ints_chars_numeric_unique", &["-nu"]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_words_unique() {
|
||||
test_helper("words_unique", "-u");
|
||||
test_helper("words_unique", &["-u"]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_numeric_unique() {
|
||||
test_helper("numeric_unique", "-nu");
|
||||
test_helper("numeric_unique", &["-nu"]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_mixed_floats_ints_chars_numeric_reverse() {
|
||||
test_helper("mixed_floats_ints_chars_numeric_unique_reverse", "-nur");
|
||||
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_helper("mixed_floats_ints_chars_numeric_stable", &["-ns"]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -347,12 +385,15 @@ fn test_numeric_floats2() {
|
|||
|
||||
#[test]
|
||||
fn test_numeric_floats_with_nan2() {
|
||||
test_helper("numeric-floats-with-nan2", "-n");
|
||||
test_helper(
|
||||
"numeric-floats-with-nan2",
|
||||
&["-n", "--numeric-sort", "--sort=numeric"],
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_human_block_sizes2() {
|
||||
for human_numeric_sort_param in vec!["-h", "--human-numeric-sort"] {
|
||||
for human_numeric_sort_param in &["-h", "--human-numeric-sort", "--sort=human-numeric"] {
|
||||
let input = "8981K\n909991M\n-8T\n21G\n0.8M";
|
||||
new_ucmd!()
|
||||
.arg(human_numeric_sort_param)
|
||||
|
@ -364,7 +405,7 @@ fn test_human_block_sizes2() {
|
|||
|
||||
#[test]
|
||||
fn test_month_default2() {
|
||||
for month_sort_param in vec!["-M", "--month-sort"] {
|
||||
for month_sort_param in &["-M", "--month-sort", "--sort=month"] {
|
||||
let input = "JAn\nMAY\n000may\nJun\nFeb";
|
||||
new_ucmd!()
|
||||
.arg(month_sort_param)
|
||||
|
@ -397,32 +438,32 @@ fn test_numeric_unique_ints2() {
|
|||
|
||||
#[test]
|
||||
fn test_keys_open_ended() {
|
||||
test_helper("keys_open_ended", "-k 2.3");
|
||||
test_helper("keys_open_ended", &["-k 2.3"]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_keys_closed_range() {
|
||||
test_helper("keys_closed_range", "-k 2.2,2.2");
|
||||
test_helper("keys_closed_range", &["-k 2.2,2.2"]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_keys_multiple_ranges() {
|
||||
test_helper("keys_multiple_ranges", "-k 2,2 -k 3,3");
|
||||
test_helper("keys_multiple_ranges", &["-k 2,2 -k 3,3"]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_keys_no_field_match() {
|
||||
test_helper("keys_no_field_match", "-k 4,4");
|
||||
test_helper("keys_no_field_match", &["-k 4,4"]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_keys_no_char_match() {
|
||||
test_helper("keys_no_char_match", "-k 1.2");
|
||||
test_helper("keys_no_char_match", &["-k 1.2"]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_keys_custom_separator() {
|
||||
test_helper("keys_custom_separator", "-k 2.2,2.2 -t x");
|
||||
test_helper("keys_custom_separator", &["-k 2.2,2.2 -t x"]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -534,7 +575,7 @@ aaaa
|
|||
|
||||
#[test]
|
||||
fn test_zero_terminated() {
|
||||
test_helper("zero-terminated", "-z");
|
||||
test_helper("zero-terminated", &["-z"]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue