Simple strings where possible (#27)

This commit is contained in:
Patrick Stevens
2025-07-30 09:06:15 +01:00
committed by GitHub
parent d21786ecd4
commit faacb4770c
6 changed files with 32 additions and 21 deletions

View File

@@ -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
}

View File

@@ -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""
}

View File

@@ -472,7 +472,7 @@ Sixth line""
let windowsLineEndings () =
expect {
snapshot @""down with line endings""
snapshot ""down with line endings""
return ""crlf""
}
"

View File

@@ -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
}
"

View File

@@ -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: Zerowidthspacetest"" // Contains U+200B
snapshot ""Updated: Zerowidthspacetest"" // Contains U+200B
return ""zwsp""
}
@@ -445,7 +445,7 @@ module MyModule =
let mathSymbols () =
expect {
snapshot @""Pretty vacuous, huh: ∀x∈, ∃y: + = 1 |x| 1""
snapshot ""Pretty vacuous, huh: ∀x∈, ∃y: + = 1 |x| 1""
return ""math""
}
"

View File

@@ -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"