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

Use inline block format also for strings of form "foo\n" #225

Merged
merged 1 commit into from Apr 27, 2022
Merged
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
14 changes: 12 additions & 2 deletions src/snapshot.rs
Expand Up @@ -317,12 +317,12 @@ impl SnapshotContents {
pub fn to_inline(&self, indentation: usize) -> String {
let contents = &self.0;
let mut out = String::new();
let is_escape = contents.lines().count() > 1 || contents.contains(&['\\', '"'][..]);
let is_escape = contents.contains(&['\n', '\\', '"'][..]);

out.push_str(if is_escape { "r###\"" } else { "\"" });
// if we have more than one line we want to change into the block
// representation mode
if contents.lines().count() > 1 {
if contents.contains('\n') {
out.extend(
contents
.lines()
Expand Down Expand Up @@ -512,6 +512,16 @@ b"[1..];
\"###"
);

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

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