mirror of
https://github.com/uutils/coreutils
synced 2024-11-16 17:58:06 +00:00
Merge pull request #2522 from miDeb/sort/unique-check
sort: disallow equal lines for --check with --unique
This commit is contained in:
commit
897693c997
2 changed files with 21 additions and 3 deletions
|
@ -26,6 +26,13 @@ use std::{
|
|||
///
|
||||
/// The code we should exit with.
|
||||
pub fn check(path: &str, settings: &GlobalSettings) -> i32 {
|
||||
let max_allowed_cmp = if settings.unique {
|
||||
// If `unique` is enabled, the previous line must compare _less_ to the next one.
|
||||
Ordering::Less
|
||||
} else {
|
||||
// Otherwise, the line previous line must compare _less or equal_ to the next one.
|
||||
Ordering::Equal
|
||||
};
|
||||
let file = open(path);
|
||||
let (recycled_sender, recycled_receiver) = sync_channel(2);
|
||||
let (loaded_sender, loaded_receiver) = sync_channel(2);
|
||||
|
@ -53,7 +60,7 @@ pub fn check(path: &str, settings: &GlobalSettings) -> i32 {
|
|||
settings,
|
||||
prev_chunk.line_data(),
|
||||
chunk.line_data(),
|
||||
) == Ordering::Greater
|
||||
) > max_allowed_cmp
|
||||
{
|
||||
if !settings.check_silent {
|
||||
eprintln!("sort: {}:{}: disorder: {}", path, line_idx, new_first.line);
|
||||
|
@ -65,8 +72,7 @@ pub fn check(path: &str, settings: &GlobalSettings) -> i32 {
|
|||
|
||||
for (a, b) in chunk.lines().iter().tuple_windows() {
|
||||
line_idx += 1;
|
||||
if compare_by(a, b, settings, chunk.line_data(), chunk.line_data()) == Ordering::Greater
|
||||
{
|
||||
if compare_by(a, b, settings, chunk.line_data(), chunk.line_data()) > max_allowed_cmp {
|
||||
if !settings.check_silent {
|
||||
eprintln!("sort: {}:{}: disorder: {}", path, line_idx, b.line);
|
||||
}
|
||||
|
|
|
@ -796,6 +796,18 @@ fn test_check_silent() {
|
|||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_check_unique() {
|
||||
// Due to a clap bug the combination "-cu" does not work. "-c -u" works.
|
||||
// See https://github.com/clap-rs/clap/issues/2624
|
||||
new_ucmd!()
|
||||
.args(&["-c", "-u"])
|
||||
.pipe_in("A\nA\n")
|
||||
.fails()
|
||||
.code_is(1)
|
||||
.stderr_only("sort: -:2: disorder: A");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_dictionary_and_nonprinting_conflicts() {
|
||||
let conflicting_args = ["n", "h", "g", "M"];
|
||||
|
|
Loading…
Reference in a new issue