summaryrefslogtreecommitdiffstats
path: root/tests/by-util/test_ls.rs
diff options
context:
space:
mode:
authorSylvestre Ledru <sylvestre@debian.org>2023-10-19 14:17:34 +0200
committerGitHub <noreply@github.com>2023-10-19 14:17:34 +0200
commitf971a69d69c57eed1fe31807cd069cfbdc923463 (patch)
tree30330e02b8a4d2b795f2668cb560cbf4d3a261c4 /tests/by-util/test_ls.rs
parent20cc68a29d56d55beca040f2e4964a01262017eb (diff)
ls --dired -R: fix the positions (#5341)
* move get_offset_from_previous_line into a specific function * dired: improve the -R support * dired: fix the display with subdir * ls --dired -R: fix the positions * ls --dired -R: verify also the SUBDIRED coordinate * ls --dired -R: add a long file name and fix a windows test * dired: always put dired first in the args + minor fixes Co-authored-by: Daniel Hofstetter <daniel.hofstetter@42dh.com> * ls: add cognitive_complexity to silent a warning --------- Co-authored-by: Daniel Hofstetter <daniel.hofstetter@42dh.com>
Diffstat (limited to 'tests/by-util/test_ls.rs')
-rw-r--r--tests/by-util/test_ls.rs102
1 files changed, 102 insertions, 0 deletions
diff --git a/tests/by-util/test_ls.rs b/tests/by-util/test_ls.rs
index 8b0032065..15893b0e2 100644
--- a/tests/by-util/test_ls.rs
+++ b/tests/by-util/test_ls.rs
@@ -3581,6 +3581,57 @@ fn test_ls_dired_recursive() {
}
#[test]
+fn test_ls_dired_recursive_multiple() {
+ let scene = TestScenario::new(util_name!());
+ let at = &scene.fixtures;
+
+ at.mkdir("d");
+ at.mkdir("d/d1");
+ at.mkdir("d/d2");
+ at.touch("d/d2/a");
+ at.touch("d/d2/c2");
+ at.touch("d/d1/f1");
+ at.touch("d/d1/file-long");
+
+ let mut cmd = scene.ucmd();
+ cmd.arg("--dired").arg("-l").arg("-R").arg("d");
+
+ let result = cmd.succeeds();
+
+ let output = result.stdout_str().to_string();
+ println!("Output:\n{}", output);
+
+ let dired_line = output
+ .lines()
+ .find(|&line| line.starts_with("//DIRED//"))
+ .unwrap();
+ let positions: Vec<usize> = dired_line
+ .split_whitespace()
+ .skip(1)
+ .map(|s| s.parse().unwrap())
+ .collect();
+ println!("Parsed byte positions: {:?}", positions);
+ assert_eq!(positions.len() % 2, 0); // Ensure there's an even number of positions
+
+ let filenames: Vec<String> = positions
+ .chunks(2)
+ .map(|chunk| {
+ let start_pos = chunk[0];
+ let end_pos = chunk[1];
+ let filename = String::from_utf8(output.as_bytes()[start_pos..=end_pos].to_vec())
+ .unwrap()
+ .trim()
+ .to_string();
+ println!("Extracted filename: {}", filename);
+ filename
+ })
+ .collect();
+
+ println!("Extracted filenames: {:?}", filenames);
+ assert_eq!(filenames, vec!["d1", "d2", "f1", "file-long", "a", "c2"]);
+}
+
+#[test]
fn test_ls_dired_simple() {
let scene = TestScenario::new(util_name!());
let at = &scene.fixtures;
@@ -3679,6 +3730,57 @@ fn test_ls_dired_complex() {
assert_eq!(filenames, vec!["a1", "a22", "a333", "a4444", "d"]);
}
+#[test]
+fn test_ls_subdired_complex() {
+ let scene = TestScenario::new(util_name!());
+ let at = &scene.fixtures;
+
+ at.mkdir("dir1");
+ at.mkdir("dir1/d");
+ at.mkdir("dir1/c2");
+ at.touch("dir1/a1");
+ at.touch("dir1/a22");
+ at.touch("dir1/a333");
+ at.touch("dir1/c2/a4444");
+
+ let mut cmd = scene.ucmd();
+ cmd.arg("--dired").arg("-l").arg("-R").arg("dir1");
+ let result = cmd.succeeds();
+
+ let output = result.stdout_str().to_string();
+ println!("Output:\n{}", output);
+
+ let dired_line = output
+ .lines()
+ .find(|&line| line.starts_with("//SUBDIRED//"))
+ .unwrap();
+ let positions: Vec<usize> = dired_line
+ .split_whitespace()
+ .skip(1)
+ .map(|s| s.parse().unwrap())
+ .collect();
+ println!("Parsed byte positions: {:?}", positions);
+ assert_eq!(positions.len() % 2, 0); // Ensure there's an even number of positions
+
+ let dirnames: Vec<String> = positions
+ .chunks(2)
+ .map(|chunk| {
+ let start_pos = chunk[0];
+ let end_pos = chunk[1];
+ let dirname =
+ String::from_utf8(output.as_bytes()[start_pos..end_pos].to_vec()).unwrap();
+ println!("Extracted dirname: {}", dirname);
+ dirname
+ })
+ .collect();
+
+ println!("Extracted dirnames: {:?}", dirnames);
+ #[cfg(unix)]
+ assert_eq!(dirnames, vec!["dir1", "dir1/c2", "dir1/d"]);
+ #[cfg(windows)]
+ assert_eq!(dirnames, vec!["dir1", "dir1\\c2", "dir1\\d"]);
+}
+
#[ignore = "issue #5396"]
#[test]
fn test_ls_cf_output_should_be_delimited_by_tab() {