Skip to content

Commit

Permalink
Fix require_full_match
Browse files Browse the repository at this point in the history
This fixes the issues in mitsuhiko#477, stacked on mitsuhiko#483.

It's possible I've still missed something -- I realize that there are plenty of areas I'm still unsure about in the repo. Possibly some slower integration tests with sample projects would be worthwhile; though they don't make for the nimblest of tests...
  • Loading branch information
max-sixty committed May 3, 2024
1 parent 66aff45 commit 34810b5
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions insta/src/snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,8 @@ impl PendingInlineSnapshot {
pub struct MetaData {
/// The source file (relative to workspace root).
pub(crate) source: Option<String>,
/// The source line if available.
/// The source line, if available. This is used by pending snapshots, but trimmed
/// before writing to the final `.snap` files in ['MetaData::trim_for_persistence'].
pub(crate) assertion_line: Option<u32>,
/// Optional human readable (non formatted) snapshot description.
pub(crate) description: Option<String>,
Expand Down Expand Up @@ -246,7 +247,8 @@ impl MetaData {
Content::Struct("MetaData", fields)
}

/// Trims the metadata for persistence.
/// Trims the metadata of fields that we don't save to `.snap` files; we
/// only use for display while reviewing
fn trim_for_persistence(&self) -> Cow<'_, MetaData> {
if self.assertion_line.is_some() {
let mut rv = self.clone();
Expand Down Expand Up @@ -422,7 +424,8 @@ impl Snapshot {

/// Snapshot contents _and_ metadata match another snapshot's.
pub fn matches_fully(&self, other: &Snapshot) -> bool {
self.matches(other) && self.metadata == other.metadata
self.matches(other)
&& self.metadata.trim_for_persistence() == other.metadata.trim_for_persistence()
}

/// The snapshot contents as a &str
Expand Down

0 comments on commit 34810b5

Please sign in to comment.