mirror of
https://github.com/lsd-rs/lsd
synced 2024-12-14 06:02:36 +00:00
Add unit tests for unsorted flag
This commit is contained in:
parent
1e578bae4d
commit
60c7c4ac19
2 changed files with 64 additions and 0 deletions
|
@ -266,6 +266,16 @@ mod test_sort_column {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_from_arg_matches_unsorted() {
|
||||||
|
let argv = vec!["lsd", "--unsorted"];
|
||||||
|
let matches = app::build().get_matches_from_safe(argv).unwrap();
|
||||||
|
assert_eq!(
|
||||||
|
Some(SortColumn::None),
|
||||||
|
SortColumn::from_arg_matches(&matches)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_from_arg_matches_sort() {
|
fn test_from_arg_matches_sort() {
|
||||||
let argv = vec!["lsd", "--sort", "time"];
|
let argv = vec!["lsd", "--sort", "time"];
|
||||||
|
@ -295,6 +305,13 @@ mod test_sort_column {
|
||||||
Some(SortColumn::Version),
|
Some(SortColumn::Version),
|
||||||
SortColumn::from_arg_matches(&matches)
|
SortColumn::from_arg_matches(&matches)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
let argv = vec!["lsd", "--sort", "none"];
|
||||||
|
let matches = app::build().get_matches_from_safe(argv).unwrap();
|
||||||
|
assert_eq!(
|
||||||
|
Some(SortColumn::None),
|
||||||
|
SortColumn::from_arg_matches(&matches)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
47
src/sort.rs
47
src/sort.rs
|
@ -296,4 +296,51 @@ mod tests {
|
||||||
let sorter = assemble_sorters(&flags);
|
let sorter = assemble_sorters(&flags);
|
||||||
assert_eq!(by_meta(&sorter, &meta_b, &meta_c), Ordering::Less);
|
assert_eq!(by_meta(&sorter, &meta_b, &meta_c), Ordering::Less);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_sort_assemble_sorters_unsorted() {
|
||||||
|
let tmp_dir = tempdir().expect("failed to create temp dir");
|
||||||
|
|
||||||
|
// Create the file with rs extension;
|
||||||
|
let path_a = tmp_dir.path().join("aaa.aa");
|
||||||
|
File::create(&path_a).expect("failed to create file");
|
||||||
|
let meta_a = Meta::from_path(&path_a, false).expect("failed to get meta");
|
||||||
|
|
||||||
|
// Create the file with rs extension;
|
||||||
|
let path_b = tmp_dir.path().join("aaa");
|
||||||
|
create_dir(&path_b).expect("failed to create dir");
|
||||||
|
let meta_b = Meta::from_path(&path_b, false).expect("failed to get meta");
|
||||||
|
|
||||||
|
// Create the file with js extension;
|
||||||
|
let path_c = tmp_dir.path().join("zzz.zz");
|
||||||
|
File::create(&path_c).expect("failed to create file");
|
||||||
|
let meta_c = Meta::from_path(&path_c, false).expect("failed to get meta");
|
||||||
|
|
||||||
|
// Create the file with txt extension;
|
||||||
|
let path_d = tmp_dir.path().join("zzz");
|
||||||
|
create_dir(&path_d).expect("failed to create dir");
|
||||||
|
let meta_d = Meta::from_path(&path_d, false).expect("failed to get meta");
|
||||||
|
|
||||||
|
let mut flags = Flags::default();
|
||||||
|
flags.sorting.column = SortColumn::None;
|
||||||
|
|
||||||
|
// Sort by extension
|
||||||
|
let sorter = assemble_sorters(&flags);
|
||||||
|
assert_eq!(by_meta(&sorter, &meta_a, &meta_b), Ordering::Equal);
|
||||||
|
|
||||||
|
let sorter = assemble_sorters(&flags);
|
||||||
|
assert_eq!(by_meta(&sorter, &meta_a, &meta_c), Ordering::Equal);
|
||||||
|
|
||||||
|
let sorter = assemble_sorters(&flags);
|
||||||
|
assert_eq!(by_meta(&sorter, &meta_a, &meta_d), Ordering::Equal);
|
||||||
|
|
||||||
|
let sorter = assemble_sorters(&flags);
|
||||||
|
assert_eq!(by_meta(&sorter, &meta_b, &meta_c), Ordering::Equal);
|
||||||
|
|
||||||
|
let sorter = assemble_sorters(&flags);
|
||||||
|
assert_eq!(by_meta(&sorter, &meta_b, &meta_d), Ordering::Equal);
|
||||||
|
|
||||||
|
let sorter = assemble_sorters(&flags);
|
||||||
|
assert_eq!(by_meta(&sorter, &meta_c, &meta_d), Ordering::Equal);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue