Skip to content

Commit

Permalink
Adjust snapshot formatting tests (mitsuhiko#561)
Browse files Browse the repository at this point in the history
These are not actually needed for multiline strings...
  • Loading branch information
max-sixty authored Aug 12, 2024
1 parent 32f75e7 commit 9132d04
Showing 1 changed file with 20 additions and 17 deletions.
37 changes: 20 additions & 17 deletions insta/src/snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -527,9 +527,10 @@ impl SnapshotContents {
let contents = &self.0;
let mut out = String::new();

// We don't technically need to escape on newlines, but it reduces diffs
let is_escape = contents.contains(['\\', '"', '\n']);
// Escape the string if needed, with `r#`, using with 1 more `#` than
// the maximum number of existing contiguous `#`.
let is_escape = contents.contains(&['\n', '\\', '"'][..]);
let delimiter = if is_escape {
let max_contiguous_hash = contents
.split(|c| c != '#')
Expand Down Expand Up @@ -754,32 +755,34 @@ a
b"[1..];
assert_eq!(
SnapshotContents(t.to_string()).to_inline(0),
"r#\"
r##"r#"
a
b
\"#"
"#"##
);

let t = &"
a
b"[1..];
assert_eq!(
SnapshotContents(t.to_string()).to_inline(4),
"r#\"
SnapshotContents(
"a
b"
.to_string()
)
.to_inline(4),
r##"r#"
a
b
\"#"
"#"##
);

let t = &"
a
b"[1..];
assert_eq!(
SnapshotContents(t.to_string()).to_inline(0),
"r#\"
r##"r#"
a
b
\"#"
"#"##
);

let t = &"
Expand All @@ -788,21 +791,21 @@ a
b"[1..];
assert_eq!(
SnapshotContents(t.to_string()).to_inline(4),
"r#\"
r##"r#"
a
b
\"#"
"#"##
);

let t = &"
ab
"[1..];
assert_eq!(
SnapshotContents(t.to_string()).to_inline(0),
"r#\"
r##"r#"
ab
\"#"
"#"##
);

let t = "ab";
Expand All @@ -814,12 +817,12 @@ fn test_snapshot_contents_hashes() {
let t = "a###b";
assert_eq!(SnapshotContents(t.to_string()).to_inline(0), r#""a###b""#);

let t = "a\n###b";
let t = "a\n\\###b";
assert_eq!(
SnapshotContents(t.to_string()).to_inline(0),
r#####"r####"
a
###b
\###b
"####"#####
);
}
Expand Down

0 comments on commit 9132d04

Please sign in to comment.