Skip to content

Commit

Permalink
Sort snapshot containers (#413)
Browse files Browse the repository at this point in the history
  • Loading branch information
mitsuhiko authored Oct 9, 2023
1 parent 57252ed commit c0dc693
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
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

0 comments on commit c0dc693

Please sign in to comment.