mirror of
https://github.com/uutils/coreutils
synced 2025-01-07 10:49:09 +00:00
Clippy fixes in multiple crates
This commit is contained in:
parent
5a726e1ab3
commit
8458bf1387
10 changed files with 39 additions and 40 deletions
|
@ -51,7 +51,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
||||||
let p = Path::new(path);
|
let p = Path::new(path);
|
||||||
match p.parent() {
|
match p.parent() {
|
||||||
Some(d) => {
|
Some(d) => {
|
||||||
if d.components().next() == None {
|
if d.components().next().is_none() {
|
||||||
print!(".");
|
print!(".");
|
||||||
} else {
|
} else {
|
||||||
print_verbatim(d).unwrap();
|
print_verbatim(d).unwrap();
|
||||||
|
|
|
@ -510,7 +510,7 @@ impl<'a> WordSplit<'a> {
|
||||||
word_start = Some(os);
|
word_start = Some(os);
|
||||||
break;
|
break;
|
||||||
} else if c == '\t' {
|
} else if c == '\t' {
|
||||||
if beforetab == None {
|
if beforetab.is_none() {
|
||||||
beforetab = Some(aftertab);
|
beforetab = Some(aftertab);
|
||||||
aftertab = 0;
|
aftertab = 0;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -618,6 +618,7 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
#[cfg(target_os = "linux")]
|
#[cfg(target_os = "linux")]
|
||||||
fn test_arg_iterate_bad_encoding() {
|
fn test_arg_iterate_bad_encoding() {
|
||||||
|
#[allow(clippy::invalid_utf8_in_unchecked)]
|
||||||
let invalid = unsafe { std::str::from_utf8_unchecked(b"\x80\x81") };
|
let invalid = unsafe { std::str::from_utf8_unchecked(b"\x80\x81") };
|
||||||
// this arises from a conversion from OsString to &str
|
// this arises from a conversion from OsString to &str
|
||||||
assert!(
|
assert!(
|
||||||
|
|
|
@ -120,7 +120,7 @@ impl Uniq {
|
||||||
let mut i = 0;
|
let mut i = 0;
|
||||||
let mut char_indices = line.char_indices();
|
let mut char_indices = line.char_indices();
|
||||||
for _ in 0..skip_fields {
|
for _ in 0..skip_fields {
|
||||||
if char_indices.find(|(_, c)| !c.is_whitespace()) == None {
|
if char_indices.all(|(_, c)| c.is_whitespace()) {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
match char_indices.find(|(_, c)| c.is_whitespace()) {
|
match char_indices.find(|(_, c)| c.is_whitespace()) {
|
||||||
|
|
|
@ -162,7 +162,7 @@ pub fn contain(ranges: &[Range], n: usize) -> bool {
|
||||||
mod test {
|
mod test {
|
||||||
use super::{complement, Range};
|
use super::{complement, Range};
|
||||||
|
|
||||||
fn m(a: Vec<Range>, b: Vec<Range>) {
|
fn m(a: Vec<Range>, b: &[Range]) {
|
||||||
assert_eq!(Range::merge(a), b);
|
assert_eq!(Range::merge(a), b);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -173,18 +173,18 @@ mod test {
|
||||||
#[test]
|
#[test]
|
||||||
fn merging() {
|
fn merging() {
|
||||||
// Single element
|
// Single element
|
||||||
m(vec![r(1, 2)], vec![r(1, 2)]);
|
m(vec![r(1, 2)], &[r(1, 2)]);
|
||||||
|
|
||||||
// Disjoint in wrong order
|
// Disjoint in wrong order
|
||||||
m(vec![r(4, 5), r(1, 2)], vec![r(1, 2), r(4, 5)]);
|
m(vec![r(4, 5), r(1, 2)], &[r(1, 2), r(4, 5)]);
|
||||||
|
|
||||||
// Two elements must be merged
|
// Two elements must be merged
|
||||||
m(vec![r(1, 3), r(2, 4), r(6, 7)], vec![r(1, 4), r(6, 7)]);
|
m(vec![r(1, 3), r(2, 4), r(6, 7)], &[r(1, 4), r(6, 7)]);
|
||||||
|
|
||||||
// Two merges and a duplicate
|
// Two merges and a duplicate
|
||||||
m(
|
m(
|
||||||
vec![r(1, 3), r(6, 7), r(2, 4), r(6, 7)],
|
vec![r(1, 3), r(6, 7), r(2, 4), r(6, 7)],
|
||||||
vec![r(1, 4), r(6, 7)],
|
&[r(1, 4), r(6, 7)],
|
||||||
);
|
);
|
||||||
|
|
||||||
// One giant
|
// One giant
|
||||||
|
@ -196,19 +196,19 @@ mod test {
|
||||||
r(130, 140),
|
r(130, 140),
|
||||||
r(150, 160),
|
r(150, 160),
|
||||||
],
|
],
|
||||||
vec![r(10, 20), r(100, 200)],
|
&[r(10, 20), r(100, 200)],
|
||||||
);
|
);
|
||||||
|
|
||||||
// Last one joins the previous two
|
// Last one joins the previous two
|
||||||
m(vec![r(10, 20), r(30, 40), r(20, 30)], vec![r(10, 40)]);
|
m(vec![r(10, 20), r(30, 40), r(20, 30)], &[r(10, 40)]);
|
||||||
|
|
||||||
m(
|
m(
|
||||||
vec![r(10, 20), r(30, 40), r(50, 60), r(20, 30)],
|
vec![r(10, 20), r(30, 40), r(50, 60), r(20, 30)],
|
||||||
vec![r(10, 40), r(50, 60)],
|
&[r(10, 40), r(50, 60)],
|
||||||
);
|
);
|
||||||
|
|
||||||
// Merge adjacent ranges
|
// Merge adjacent ranges
|
||||||
m(vec![r(1, 3), r(4, 6)], vec![r(1, 6)])
|
m(vec![r(1, 3), r(4, 6)], &[r(1, 6)]);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
|
@ -241,6 +241,6 @@ mod tests {
|
||||||
"
|
"
|
||||||
),
|
),
|
||||||
"{} [some] [options]"
|
"{} [some] [options]"
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -73,7 +73,7 @@ fn test_cp_existing_target() {
|
||||||
assert_eq!(at.read(TEST_EXISTING_FILE), "Hello, World!\n");
|
assert_eq!(at.read(TEST_EXISTING_FILE), "Hello, World!\n");
|
||||||
|
|
||||||
// No backup should have been created
|
// No backup should have been created
|
||||||
assert!(!at.file_exists(&*format!("{}~", TEST_EXISTING_FILE)));
|
assert!(!at.file_exists(&format!("{}~", TEST_EXISTING_FILE)));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -344,7 +344,7 @@ fn test_cp_arg_backup() {
|
||||||
|
|
||||||
assert_eq!(at.read(TEST_HOW_ARE_YOU_SOURCE), "Hello, World!\n");
|
assert_eq!(at.read(TEST_HOW_ARE_YOU_SOURCE), "Hello, World!\n");
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
at.read(&*format!("{}~", TEST_HOW_ARE_YOU_SOURCE)),
|
at.read(&format!("{}~", TEST_HOW_ARE_YOU_SOURCE)),
|
||||||
"How are you?\n"
|
"How are you?\n"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -360,7 +360,7 @@ fn test_cp_arg_backup_with_other_args() {
|
||||||
|
|
||||||
assert_eq!(at.read(TEST_HOW_ARE_YOU_SOURCE), "Hello, World!\n");
|
assert_eq!(at.read(TEST_HOW_ARE_YOU_SOURCE), "Hello, World!\n");
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
at.read(&*format!("{}~", TEST_HOW_ARE_YOU_SOURCE)),
|
at.read(&format!("{}~", TEST_HOW_ARE_YOU_SOURCE)),
|
||||||
"How are you?\n"
|
"How are you?\n"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -376,7 +376,7 @@ fn test_cp_arg_backup_arg_first() {
|
||||||
|
|
||||||
assert_eq!(at.read(TEST_HOW_ARE_YOU_SOURCE), "Hello, World!\n");
|
assert_eq!(at.read(TEST_HOW_ARE_YOU_SOURCE), "Hello, World!\n");
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
at.read(&*format!("{}~", TEST_HOW_ARE_YOU_SOURCE)),
|
at.read(&format!("{}~", TEST_HOW_ARE_YOU_SOURCE)),
|
||||||
"How are you?\n"
|
"How are you?\n"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -394,7 +394,7 @@ fn test_cp_arg_suffix() {
|
||||||
|
|
||||||
assert_eq!(at.read(TEST_HOW_ARE_YOU_SOURCE), "Hello, World!\n");
|
assert_eq!(at.read(TEST_HOW_ARE_YOU_SOURCE), "Hello, World!\n");
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
at.read(&*format!("{}.bak", TEST_HOW_ARE_YOU_SOURCE)),
|
at.read(&format!("{}.bak", TEST_HOW_ARE_YOU_SOURCE)),
|
||||||
"How are you?\n"
|
"How are you?\n"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -412,7 +412,7 @@ fn test_cp_arg_suffix_hyphen_value() {
|
||||||
|
|
||||||
assert_eq!(at.read(TEST_HOW_ARE_YOU_SOURCE), "Hello, World!\n");
|
assert_eq!(at.read(TEST_HOW_ARE_YOU_SOURCE), "Hello, World!\n");
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
at.read(&*format!("{}-v", TEST_HOW_ARE_YOU_SOURCE)),
|
at.read(&format!("{}-v", TEST_HOW_ARE_YOU_SOURCE)),
|
||||||
"How are you?\n"
|
"How are you?\n"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -431,7 +431,7 @@ fn test_cp_custom_backup_suffix_via_env() {
|
||||||
|
|
||||||
assert_eq!(at.read(TEST_HOW_ARE_YOU_SOURCE), "Hello, World!\n");
|
assert_eq!(at.read(TEST_HOW_ARE_YOU_SOURCE), "Hello, World!\n");
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
at.read(&*format!("{}{}", TEST_HOW_ARE_YOU_SOURCE, suffix)),
|
at.read(&format!("{}{}", TEST_HOW_ARE_YOU_SOURCE, suffix)),
|
||||||
"How are you?\n"
|
"How are you?\n"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -448,7 +448,7 @@ fn test_cp_backup_numbered_with_t() {
|
||||||
|
|
||||||
assert_eq!(at.read(TEST_HOW_ARE_YOU_SOURCE), "Hello, World!\n");
|
assert_eq!(at.read(TEST_HOW_ARE_YOU_SOURCE), "Hello, World!\n");
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
at.read(&*format!("{}.~1~", TEST_HOW_ARE_YOU_SOURCE)),
|
at.read(&format!("{}.~1~", TEST_HOW_ARE_YOU_SOURCE)),
|
||||||
"How are you?\n"
|
"How are you?\n"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -465,7 +465,7 @@ fn test_cp_backup_numbered() {
|
||||||
|
|
||||||
assert_eq!(at.read(TEST_HOW_ARE_YOU_SOURCE), "Hello, World!\n");
|
assert_eq!(at.read(TEST_HOW_ARE_YOU_SOURCE), "Hello, World!\n");
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
at.read(&*format!("{}.~1~", TEST_HOW_ARE_YOU_SOURCE)),
|
at.read(&format!("{}.~1~", TEST_HOW_ARE_YOU_SOURCE)),
|
||||||
"How are you?\n"
|
"How are you?\n"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -482,7 +482,7 @@ fn test_cp_backup_existing() {
|
||||||
|
|
||||||
assert_eq!(at.read(TEST_HOW_ARE_YOU_SOURCE), "Hello, World!\n");
|
assert_eq!(at.read(TEST_HOW_ARE_YOU_SOURCE), "Hello, World!\n");
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
at.read(&*format!("{}~", TEST_HOW_ARE_YOU_SOURCE)),
|
at.read(&format!("{}~", TEST_HOW_ARE_YOU_SOURCE)),
|
||||||
"How are you?\n"
|
"How are you?\n"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -499,7 +499,7 @@ fn test_cp_backup_nil() {
|
||||||
|
|
||||||
assert_eq!(at.read(TEST_HOW_ARE_YOU_SOURCE), "Hello, World!\n");
|
assert_eq!(at.read(TEST_HOW_ARE_YOU_SOURCE), "Hello, World!\n");
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
at.read(&*format!("{}~", TEST_HOW_ARE_YOU_SOURCE)),
|
at.read(&format!("{}~", TEST_HOW_ARE_YOU_SOURCE)),
|
||||||
"How are you?\n"
|
"How are you?\n"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -507,7 +507,7 @@ fn test_cp_backup_nil() {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_cp_numbered_if_existing_backup_existing() {
|
fn test_cp_numbered_if_existing_backup_existing() {
|
||||||
let (at, mut ucmd) = at_and_ucmd!();
|
let (at, mut ucmd) = at_and_ucmd!();
|
||||||
let existing_backup = &*format!("{}.~1~", TEST_HOW_ARE_YOU_SOURCE);
|
let existing_backup = &format!("{}.~1~", TEST_HOW_ARE_YOU_SOURCE);
|
||||||
at.touch(existing_backup);
|
at.touch(existing_backup);
|
||||||
|
|
||||||
ucmd.arg("--backup=existing")
|
ucmd.arg("--backup=existing")
|
||||||
|
@ -519,7 +519,7 @@ fn test_cp_numbered_if_existing_backup_existing() {
|
||||||
assert!(at.file_exists(TEST_HOW_ARE_YOU_SOURCE));
|
assert!(at.file_exists(TEST_HOW_ARE_YOU_SOURCE));
|
||||||
assert!(at.file_exists(existing_backup));
|
assert!(at.file_exists(existing_backup));
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
at.read(&*format!("{}.~2~", TEST_HOW_ARE_YOU_SOURCE)),
|
at.read(&format!("{}.~2~", TEST_HOW_ARE_YOU_SOURCE)),
|
||||||
"How are you?\n"
|
"How are you?\n"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -527,7 +527,7 @@ fn test_cp_numbered_if_existing_backup_existing() {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_cp_numbered_if_existing_backup_nil() {
|
fn test_cp_numbered_if_existing_backup_nil() {
|
||||||
let (at, mut ucmd) = at_and_ucmd!();
|
let (at, mut ucmd) = at_and_ucmd!();
|
||||||
let existing_backup = &*format!("{}.~1~", TEST_HOW_ARE_YOU_SOURCE);
|
let existing_backup = &format!("{}.~1~", TEST_HOW_ARE_YOU_SOURCE);
|
||||||
|
|
||||||
at.touch(existing_backup);
|
at.touch(existing_backup);
|
||||||
ucmd.arg("--backup=nil")
|
ucmd.arg("--backup=nil")
|
||||||
|
@ -539,7 +539,7 @@ fn test_cp_numbered_if_existing_backup_nil() {
|
||||||
assert!(at.file_exists(TEST_HOW_ARE_YOU_SOURCE));
|
assert!(at.file_exists(TEST_HOW_ARE_YOU_SOURCE));
|
||||||
assert!(at.file_exists(existing_backup));
|
assert!(at.file_exists(existing_backup));
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
at.read(&*format!("{}.~2~", TEST_HOW_ARE_YOU_SOURCE)),
|
at.read(&format!("{}.~2~", TEST_HOW_ARE_YOU_SOURCE)),
|
||||||
"How are you?\n"
|
"How are you?\n"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -556,7 +556,7 @@ fn test_cp_backup_simple() {
|
||||||
|
|
||||||
assert_eq!(at.read(TEST_HOW_ARE_YOU_SOURCE), "Hello, World!\n");
|
assert_eq!(at.read(TEST_HOW_ARE_YOU_SOURCE), "Hello, World!\n");
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
at.read(&*format!("{}~", TEST_HOW_ARE_YOU_SOURCE)),
|
at.read(&format!("{}~", TEST_HOW_ARE_YOU_SOURCE)),
|
||||||
"How are you?\n"
|
"How are you?\n"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -591,7 +591,7 @@ fn test_cp_backup_never() {
|
||||||
|
|
||||||
assert_eq!(at.read(TEST_HOW_ARE_YOU_SOURCE), "Hello, World!\n");
|
assert_eq!(at.read(TEST_HOW_ARE_YOU_SOURCE), "Hello, World!\n");
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
at.read(&*format!("{}~", TEST_HOW_ARE_YOU_SOURCE)),
|
at.read(&format!("{}~", TEST_HOW_ARE_YOU_SOURCE)),
|
||||||
"How are you?\n"
|
"How are you?\n"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -996,7 +996,7 @@ fn test_install_backup_numbered_if_existing_backup_existing() {
|
||||||
assert!(at.file_exists(file_a));
|
assert!(at.file_exists(file_a));
|
||||||
assert!(at.file_exists(file_b));
|
assert!(at.file_exists(file_b));
|
||||||
assert!(at.file_exists(file_b_backup));
|
assert!(at.file_exists(file_b_backup));
|
||||||
assert!(at.file_exists(&*format!("{}.~2~", file_b)));
|
assert!(at.file_exists(&format!("{}.~2~", file_b)));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -1022,7 +1022,7 @@ fn test_install_backup_numbered_if_existing_backup_nil() {
|
||||||
assert!(at.file_exists(file_a));
|
assert!(at.file_exists(file_a));
|
||||||
assert!(at.file_exists(file_b));
|
assert!(at.file_exists(file_b));
|
||||||
assert!(at.file_exists(file_b_backup));
|
assert!(at.file_exists(file_b_backup));
|
||||||
assert!(at.file_exists(&*format!("{}.~2~", file_b)));
|
assert!(at.file_exists(&format!("{}.~2~", file_b)));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
|
@ -475,7 +475,7 @@ fn test_mv_numbered_if_existing_backup_existing() {
|
||||||
|
|
||||||
assert!(at.file_exists(file_b));
|
assert!(at.file_exists(file_b));
|
||||||
assert!(at.file_exists(file_b_backup));
|
assert!(at.file_exists(file_b_backup));
|
||||||
assert!(at.file_exists(&*format!("{}.~2~", file_b)));
|
assert!(at.file_exists(&format!("{}.~2~", file_b)));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -496,7 +496,7 @@ fn test_mv_numbered_if_existing_backup_nil() {
|
||||||
|
|
||||||
assert!(at.file_exists(file_b));
|
assert!(at.file_exists(file_b));
|
||||||
assert!(at.file_exists(file_b_backup));
|
assert!(at.file_exists(file_b_backup));
|
||||||
assert!(at.file_exists(&*format!("{}.~2~", file_b)));
|
assert!(at.file_exists(&format!("{}.~2~", file_b)));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
|
@ -257,14 +257,12 @@ fn test_filter() {
|
||||||
// assert all characters are 'i' / no character is not 'i'
|
// assert all characters are 'i' / no character is not 'i'
|
||||||
// (assert that command succeeded)
|
// (assert that command succeeded)
|
||||||
let glob = Glob::new(&at, ".", r"x[[:alpha:]][[:alpha:]]$");
|
let glob = Glob::new(&at, ".", r"x[[:alpha:]][[:alpha:]]$");
|
||||||
assert!(
|
assert!(!glob.collate().iter().any(|&c| {
|
||||||
glob.collate().iter().find(|&&c| {
|
// is not i
|
||||||
// is not i
|
c != (b'i')
|
||||||
c != (b'i')
|
|
||||||
// is not newline
|
// is not newline
|
||||||
&& c != (b'\n')
|
&& c != (b'\n')
|
||||||
}) == None
|
}));
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
Loading…
Reference in a new issue