Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sort snapshot containers #413

Merged
merged 2 commits into from
Oct 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ All notable changes to insta and cargo-insta are documented here.

## 1.34.0

- Fixed handling of `--manifest-path` with regards to virtual workspaces. (#409)
- Snapshots are now sorted in the UI on review. (#413)
- Re-organized repository to move `cargo-insta` into a workspace. (#410)
- Fixed handling of `--manifest-path` with regards to virtual workspaces. (#409)

## 1.33.0

Expand Down
1 change: 1 addition & 0 deletions cargo-insta/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,7 @@ fn load_snapshot_containers<'a>(
snapshot_containers.push((snapshot_container?, None));
}
}
snapshot_containers.sort_by(|a, b| a.0.snapshot_sort_key().cmp(&b.0.snapshot_sort_key()));
Ok((snapshot_containers, roots))
}

Expand Down
14 changes: 14 additions & 0 deletions cargo-insta/src/container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,20 @@ impl SnapshotContainer {
}
}

pub(crate) fn snapshot_sort_key(&self) -> impl Ord + '_ {
let path = self
.snapshot_path
.file_name()
.and_then(|x| x.to_str())
.unwrap_or_default();
let mut pieces = path.rsplitn(2, '-');
if let Some(num_suffix) = pieces.next().and_then(|x| x.parse::<i64>().ok()) {
(pieces.next().unwrap_or(""), num_suffix)
} else {
(path, 0)
}
}

pub(crate) fn len(&self) -> usize {
self.snapshots.len()
}
Expand Down