Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion src/options/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -338,11 +338,35 @@ mod tests {
);
}

#[test]
fn deduce_sort_field_new() {
assert_eq!(
mock_cli(vec!["--sort", "new"]).get_one::<SortField>("sort"),
Some(&SortField::ModifiedAge)
);
}

#[test]
fn deduce_sort_field_newest() {
assert_eq!(
mock_cli(vec!["--sort", "newest"]).get_one::<SortField>("sort"),
Some(&SortField::ModifiedAge)
);
}

#[test]
fn deduce_sort_field_old() {
assert_eq!(
mock_cli(vec!["--sort", "old"]).get_one::<SortField>("sort"),
Some(&SortField::ModifiedAge)
Some(&SortField::ModifiedDate)
);
}

#[test]
fn deduce_sort_field_oldest() {
assert_eq!(
mock_cli(vec!["--sort", "oldest"]).get_one::<SortField>("sort"),
Some(&SortField::ModifiedDate)
);
}

Expand Down
8 changes: 3 additions & 5 deletions src/options/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,15 +231,13 @@ impl ValueEnum for SortField {
Self::Size => PossibleValue::new("size"),
Self::Extension(SortCase::AaBbCc) => PossibleValue::new("ext").alias("extension"),
Self::Extension(SortCase::ABCabc) => PossibleValue::new("Ext").alias("Extension"),
// “new” sorts oldest at the top and newest at the bottom; “old” sorts newest at the
// top and oldest at the bottom. I think this is the right way round to do this:
// “size” puts the smallest at the top and the largest at the bottom, doesn’t it?
// “old” sorts oldest at the top and newest at the bottom.
Self::ModifiedDate => {
PossibleValue::new("date").aliases(vec!["time", "mod", "modified", "new", "newest"])
PossibleValue::new("date").aliases(vec!["time", "mod", "modified", "old", "oldest"])
}
// Similarly, “age” means that files with the least age (the newest files) get sorted
// at the top, and files with the most age (the oldest) at the bottom.
Self::ModifiedAge => PossibleValue::new("age").aliases(vec!["old", "oldest"]),
Self::ModifiedAge => PossibleValue::new("age").aliases(vec!["new", "newest"]),
Self::ChangedDate => PossibleValue::new("changed").alias("ch"),
Self::AccessedDate => PossibleValue::new("accessed").alias("acc"),
Self::CreatedDate => PossibleValue::new("created").alias("cr"),
Expand Down
Loading