diff --git a/WoofWare.Expect.Test/TestSnapshotFinding/TestCommentsAndSpacing.fs b/WoofWare.Expect.Test/TestSnapshotFinding/TestCommentsAndSpacing.fs index b4e1314..45fc7fd 100644 --- a/WoofWare.Expect.Test/TestSnapshotFinding/TestCommentsAndSpacing.fs +++ b/WoofWare.Expect.Test/TestSnapshotFinding/TestCommentsAndSpacing.fs @@ -34,7 +34,7 @@ module MyModule = expect { snapshot (* first comment *) (* second comment *) (* third comment on new line *) - @""updated after many comments"" + ""updated after many comments"" return 123 } @@ -100,7 +100,7 @@ module MyModule = let nestedComments () = expect { - snapshot (* outer (* inner *) comment *) @""updated after nested comments"" + snapshot (* outer (* inner *) comment *) ""updated after nested comments"" return ""nested"" } @@ -165,7 +165,7 @@ module MyModule = let commentWithSpecialChars () = expect { - snapshot (* comment with ""quotes"" and \ backslash *) @""updated after weird comment"" + snapshot (* comment with ""quotes"" and \ backslash *) ""updated after weird comment"" return ""special"" } @@ -233,7 +233,7 @@ module MyModule = snapshot - @""updated after spaces"" + ""updated after spaces"" return ""whitespace"" } @@ -301,7 +301,7 @@ module MyModule = expect { snapshotJson (* comment 1 *) (* comment 2 *) - (* comment 3 *) @""updated after comments"" + (* comment 3 *) ""updated after comments"" return 123 } diff --git a/WoofWare.Expect.Test/TestSnapshotFinding/TestEdgeCases.fs b/WoofWare.Expect.Test/TestSnapshotFinding/TestEdgeCases.fs index 8e25332..a5389f0 100644 --- a/WoofWare.Expect.Test/TestSnapshotFinding/TestEdgeCases.fs +++ b/WoofWare.Expect.Test/TestSnapshotFinding/TestEdgeCases.fs @@ -31,7 +31,7 @@ open WoofWare.Expect module MyModule = let emptyString () = expect { - snapshot @""now has content"" + snapshot ""now has content"" return """" } @@ -121,7 +121,7 @@ module MyModule = let emptyVerbatim () = expect { - snapshot @""now has content"" + snapshot ""now has content"" return """" } @@ -211,7 +211,7 @@ module MyModule = let emptyTripleQuote () = expect { - snapshot @""now has content"" + snapshot ""now has content"" return """" } @@ -301,7 +301,7 @@ module MyModule = let onlyWhitespace () = expect { - snapshot @""now has content"" + snapshot ""now has content"" return ""whitespace"" } @@ -575,7 +575,7 @@ module MyModule = let veryLongLine () = expect { snapshot - @""this line is short though"" + ""this line is short though"" return ""long line"" } diff --git a/WoofWare.Expect.Test/TestSnapshotFinding/TestMultilineComplex.fs b/WoofWare.Expect.Test/TestSnapshotFinding/TestMultilineComplex.fs index ea254fc..e0e57a0 100644 --- a/WoofWare.Expect.Test/TestSnapshotFinding/TestMultilineComplex.fs +++ b/WoofWare.Expect.Test/TestSnapshotFinding/TestMultilineComplex.fs @@ -472,7 +472,7 @@ Sixth line"" let windowsLineEndings () = expect { - snapshot @""down with line endings"" + snapshot ""down with line endings"" return ""crlf"" } " diff --git a/WoofWare.Expect.Test/TestSnapshotFinding/TestSnapshotFinding.fs b/WoofWare.Expect.Test/TestSnapshotFinding/TestSnapshotFinding.fs index 66f4ced..0c2d3e8 100644 --- a/WoofWare.Expect.Test/TestSnapshotFinding/TestSnapshotFinding.fs +++ b/WoofWare.Expect.Test/TestSnapshotFinding/TestSnapshotFinding.fs @@ -32,7 +32,7 @@ open WoofWare.Expect module MyModule = let foo () = expect { - snapshot @""replacement"" + snapshot ""replacement"" return 123 } " @@ -81,7 +81,7 @@ open WoofWare.Expect module MyModule = let foo () = expect { - snapshot @""replacement"" + snapshot ""replacement"" return 123 } " diff --git a/WoofWare.Expect.Test/TestSnapshotFinding/TestUnicodeCharacters.fs b/WoofWare.Expect.Test/TestSnapshotFinding/TestUnicodeCharacters.fs index 1171fa8..729d960 100644 --- a/WoofWare.Expect.Test/TestSnapshotFinding/TestUnicodeCharacters.fs +++ b/WoofWare.Expect.Test/TestSnapshotFinding/TestUnicodeCharacters.fs @@ -31,7 +31,7 @@ open WoofWare.Expect module MyModule = let emoji () = expect { - snapshot @""Updated with 🚀🌟✨ more emoji!"" + snapshot ""Updated with 🚀🌟✨ more emoji!"" return 123 } @@ -172,7 +172,7 @@ module MyModule = let arabicRTL () = expect { - snapshot @""Updated Arabic: مرحبا بالعالم"" + snapshot ""Updated Arabic: مرحبا بالعالم"" return ""rtl test"" } @@ -241,7 +241,7 @@ module MyModule = let combiningCharacters () = expect { // Combining diacritics: e + ́ = é - snapshot @""updated test with combining: é and ä!"" + snapshot ""updated test with combining: é and ä!"" return ""combining"" } @@ -309,7 +309,7 @@ module MyModule = let mixedScripts () = expect { - snapshotJson @""Updated mixed: English, русский, 日本語, العربية, emoji 🚀"" + snapshotJson ""Updated mixed: English, русский, 日本語, العربية, emoji 🚀"" return [ ""multilingual"" ] } @@ -377,7 +377,7 @@ module MyModule = let zeroWidthChars () = expect { - snapshot @""Updated: Zero​width​space​test"" // Contains U+200B + snapshot ""Updated: Zero​width​space​test"" // Contains U+200B return ""zwsp"" } @@ -445,7 +445,7 @@ module MyModule = let mathSymbols () = expect { - snapshot @""Pretty vacuous, huh: ∀x∈ℝ, ∃y: x² + y² = 1 ⟹ |x| ≤ 1"" + snapshot ""Pretty vacuous, huh: ∀x∈ℝ, ∃y: x² + y² = 1 ⟹ |x| ≤ 1"" return ""math"" } " diff --git a/WoofWare.Expect/SnapshotUpdate.fs b/WoofWare.Expect/SnapshotUpdate.fs index 0a9e667..37bd0ed 100644 --- a/WoofWare.Expect/SnapshotUpdate.fs +++ b/WoofWare.Expect/SnapshotUpdate.fs @@ -203,11 +203,22 @@ module internal SnapshotUpdate = ) ) + let internal stringLiteral (content : string) = + if + (content.IndexOf '\n' < 0) + && (content.IndexOf '\\' < 0) + && (content.IndexOf '"' < 0) + then + // simple case where there's no escaping + "\"" + content + "\"" + else + "@\"" + content.Replace ("\"", "\"\"") + "\"" + /// Update the snapshot string with a new value; this doesn't edit the file on disk, but /// instead returns the new contents. /// We always write single-quoted @-strings for simplicity. let private updateSnapshot (lines : string[]) (info : StringLiteralInfo) (newContent : string) : string[] = - let newString = "@\"" + newContent.Replace ("\"", "\"\"") + "\"" + let newString = stringLiteral newContent if info.StartLine = info.EndLine then // Single line update @@ -230,7 +241,7 @@ module internal SnapshotUpdate = let newLines = if newContent.IndexOf '\n' >= 0 then - let split = newContent.Replace("\"", "\"\"").Split ('\n') + let split = newContent.Replace("\"", "\"\"").Split '\n' match split with | [||] -> failwith "expected contents from split string"