mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 19:47:45 +00:00
test_ls: Fix clippy warnings
This commit is contained in:
parent
259f18fcab
commit
741f065a12
1 changed files with 11 additions and 15 deletions
|
@ -432,10 +432,7 @@ fn test_ls_long_symlink_color() {
|
||||||
let mut result_lines = result
|
let mut result_lines = result
|
||||||
.stdout_str()
|
.stdout_str()
|
||||||
.lines()
|
.lines()
|
||||||
.filter_map(|line| match line.starts_with("lrwx") {
|
.filter(|line| line.starts_with("lrwx"))
|
||||||
true => Some(line),
|
|
||||||
false => None,
|
|
||||||
})
|
|
||||||
.enumerate();
|
.enumerate();
|
||||||
|
|
||||||
// For each enumerated line, we assert that the output of ls matches the expected output.
|
// For each enumerated line, we assert that the output of ls matches the expected output.
|
||||||
|
@ -455,14 +452,12 @@ fn test_ls_long_symlink_color() {
|
||||||
|
|
||||||
// We look up the Colors that are expected in `colors` using the ColorReferences
|
// We look up the Colors that are expected in `colors` using the ColorReferences
|
||||||
// stored in `expected_output`.
|
// stored in `expected_output`.
|
||||||
let expected_name_color = match expected_output[i].0 {
|
let expected_name_color = expected_output[i]
|
||||||
Some(color_reference) => Some(colors[color_reference[0]][color_reference[1]].as_str()),
|
.0
|
||||||
None => None,
|
.map(|color_reference| colors[color_reference[0]][color_reference[1]].as_str());
|
||||||
};
|
let expected_target_color = expected_output[i]
|
||||||
let expected_target_color = match expected_output[i].2 {
|
.2
|
||||||
Some(color_reference) => Some(colors[color_reference[0]][color_reference[1]].as_str()),
|
.map(|color_reference| colors[color_reference[0]][color_reference[1]].as_str());
|
||||||
None => None,
|
|
||||||
};
|
|
||||||
|
|
||||||
// This is the important part. The asserts inside assert_names_and_colors_are_equal
|
// This is the important part. The asserts inside assert_names_and_colors_are_equal
|
||||||
// will panic if the colors or names do not match the expected colors or names.
|
// will panic if the colors or names do not match the expected colors or names.
|
||||||
|
@ -470,11 +465,11 @@ fn test_ls_long_symlink_color() {
|
||||||
// don't expect any color here, as in `expected_output[2], or don't know what specific
|
// don't expect any color here, as in `expected_output[2], or don't know what specific
|
||||||
// color to expect yet, as in expected_output[0:1].
|
// color to expect yet, as in expected_output[0:1].
|
||||||
assert_names_and_colors_are_equal(
|
assert_names_and_colors_are_equal(
|
||||||
&matched_name_color,
|
matched_name_color,
|
||||||
expected_name_color,
|
expected_name_color,
|
||||||
&matched_name,
|
&matched_name,
|
||||||
expected_output[i].1,
|
expected_output[i].1,
|
||||||
&matched_target_color,
|
matched_target_color,
|
||||||
expected_target_color,
|
expected_target_color,
|
||||||
&matched_target,
|
&matched_target,
|
||||||
expected_output[i].3,
|
expected_output[i].3,
|
||||||
|
@ -505,6 +500,7 @@ fn test_ls_long_symlink_color() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(clippy::too_many_arguments)]
|
||||||
fn assert_names_and_colors_are_equal(
|
fn assert_names_and_colors_are_equal(
|
||||||
name_color: &str,
|
name_color: &str,
|
||||||
expected_name_color: Option<&str>,
|
expected_name_color: Option<&str>,
|
||||||
|
@ -530,7 +526,7 @@ fn test_ls_long_symlink_color() {
|
||||||
|
|
||||||
fn capture_colored_string(input: &str) -> (Color, Name) {
|
fn capture_colored_string(input: &str) -> (Color, Name) {
|
||||||
let colored_name = Regex::new(r"\x1b\[([0-9;]+)m(.+)\x1b\[0m").unwrap();
|
let colored_name = Regex::new(r"\x1b\[([0-9;]+)m(.+)\x1b\[0m").unwrap();
|
||||||
match colored_name.captures(&input) {
|
match colored_name.captures(input) {
|
||||||
Some(captures) => (
|
Some(captures) => (
|
||||||
captures.get(1).unwrap().as_str().to_string(),
|
captures.get(1).unwrap().as_str().to_string(),
|
||||||
captures.get(2).unwrap().as_str().to_string(),
|
captures.get(2).unwrap().as_str().to_string(),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue