summaryrefslogtreecommitdiffstats
path: root/tests/by-util/test_ls.rs
diff options
context:
space:
mode:
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() {