mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-08-02 22:17:45 +00:00
sort: disallow equal lines for --check with --unique
This commit is contained in:
parent
6b73ddcd12
commit
095e53aed2
2 changed files with 21 additions and 3 deletions
|
@ -26,6 +26,13 @@ use std::{
|
||||||
///
|
///
|
||||||
/// The code we should exit with.
|
/// The code we should exit with.
|
||||||
pub fn check(path: &str, settings: &GlobalSettings) -> i32 {
|
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 file = open(path);
|
||||||
let (recycled_sender, recycled_receiver) = sync_channel(2);
|
let (recycled_sender, recycled_receiver) = sync_channel(2);
|
||||||
let (loaded_sender, loaded_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,
|
settings,
|
||||||
prev_chunk.line_data(),
|
prev_chunk.line_data(),
|
||||||
chunk.line_data(),
|
chunk.line_data(),
|
||||||
) == Ordering::Greater
|
) > max_allowed_cmp
|
||||||
{
|
{
|
||||||
if !settings.check_silent {
|
if !settings.check_silent {
|
||||||
eprintln!("sort: {}:{}: disorder: {}", path, line_idx, new_first.line);
|
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() {
|
for (a, b) in chunk.lines().iter().tuple_windows() {
|
||||||
line_idx += 1;
|
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 {
|
if !settings.check_silent {
|
||||||
eprintln!("sort: {}:{}: disorder: {}", path, line_idx, b.line);
|
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]
|
#[test]
|
||||||
fn test_dictionary_and_nonprinting_conflicts() {
|
fn test_dictionary_and_nonprinting_conflicts() {
|
||||||
let conflicting_args = ["n", "h", "g", "M"];
|
let conflicting_args = ["n", "h", "g", "M"];
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue