Skip to content

Commit 6f5debe

Browse files
committed
Fix clippy::needless_range_loop, op_ref,assertions_on_constants, and add one test
1 parent f827d7b commit 6f5debe

File tree

3 files changed

+24
-9
lines changed

3 files changed

+24
-9
lines changed

file/split.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -151,11 +151,8 @@ impl OutputState {
151151

152152
fn write(&mut self, buf: &[u8]) -> io::Result<()> {
153153
match &mut self.outf {
154-
None => {
155-
assert!(false);
156-
Ok(())
157-
}
158154
Some(ref mut f) => f.write_all(buf),
155+
None => Ok(()),
159156
}
160157
}
161158

text/sort.rs

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -947,19 +947,26 @@ fn merge_files(paths: &mut Vec<Box<dyn Read>>, output_path: &Option<PathBuf>) ->
947947
///
948948
/// A vector of strings (`Vec<String>`) where consecutive empty strings are merged with the nearest non-empty string.
949949
///
950+
/// # Examples
951+
///
952+
/// ```
953+
/// let result = merge_empty_lines(vec!["line1", "line2", "", "", "", "lineN"]);
954+
/// assert_eq!(result, vec!["line1", "line2", " lineN"]);
955+
/// ```
956+
///
950957
fn merge_empty_lines(vec: Vec<&str>) -> Vec<String> {
951958
let mut empty_count = 0;
952959
let mut result = vec![];
953960

954-
for i in 0..vec.len() {
955-
if vec[i].is_empty() {
961+
for i in vec {
962+
if i.is_empty() {
956963
empty_count += 1;
957964
} else if empty_count > 0 {
958965
let spaces = " ".repeat(empty_count);
959-
result.push(format!("{}{}", spaces, vec[i]));
966+
result.push(format!("{}{}", spaces, i));
960967
empty_count = 0;
961968
} else {
962-
result.push(vec[i].to_string());
969+
result.push(i.to_string());
963970
}
964971
}
965972

@@ -1031,3 +1038,14 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
10311038

10321039
std::process::exit(exit_code)
10331040
}
1041+
1042+
#[cfg(test)]
1043+
mod tests {
1044+
use super::*;
1045+
1046+
#[test]
1047+
fn test_merge_empty_lines() {
1048+
let result = merge_empty_lines(vec!["line1", "line2", "", "", "", "lineN"]);
1049+
assert_eq!(result, vec!["line1", "line2", " lineN"]);
1050+
}
1051+
}

tree/ls.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1227,7 +1227,7 @@ fn process_single_dir(
12271227
let dir_parent = {
12281228
let mut comps = canonical_dir_path.as_inner().components();
12291229

1230-
let is_dot = dir_entry.file_name().to_bytes_with_nul() == &[b'.', 0];
1230+
let is_dot = dir_entry.file_name().to_bytes_with_nul() == [b'.', 0];
12311231

12321232
if !is_dot {
12331233
comps.next_back();

0 commit comments

Comments
 (0)