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

WIP keep \t escaped inside strings #1697

Merged
merged 2 commits into from
May 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions src/Fantomas.Tests/SynConstTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -301,13 +301,11 @@ let ``hex escape in string literal should be preserved, 1508`` () =
formatSourceString
false
"""let hexEscape = "\x00"
let controlEscapes = "\a \b \f \v"
"""
config
|> should
equal
"""let hexEscape = "\x00"
let controlEscapes = "\a \b \f \v"
"""

[<Test>]
Expand Down Expand Up @@ -519,3 +517,27 @@ __SOURCE_DIRECTORY__
"""
__SOURCE_DIRECTORY__
"""

[<Test>]
let ``escape sequences in strings are preserved`` () =
formatSourceString
false
"""let alert = "Hello\aWorld"
let backspace = "Hello\bWorld"
let formFeed = "Hello\fWorld"
let newline = "Hello\nWorld"
let carriageReturn = "Hello\rWorld"
let tab = "Hello\tWorld"
let verticalTab = "Hello\vWorld"
"""
config
|> should
equal
"""let alert = "Hello\aWorld"
let backspace = "Hello\bWorld"
let formFeed = "Hello\fWorld"
let newline = "Hello\nWorld"
let carriageReturn = "Hello\rWorld"
let tab = "Hello\tWorld"
let verticalTab = "Hello\vWorld"
"""
2 changes: 1 addition & 1 deletion src/Fantomas/TokenParser.fs
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ let private (|InterpStringEndOrPartToken|_|) token =
None

let escapedCharacterRegex =
System.Text.RegularExpressions.Regex("(\\\\(a|b|f|n|r|u|v|x|'|\\\"|\\\\))+")
System.Text.RegularExpressions.Regex("(\\\\(a|b|f|n|r|t|u|v|x|'|\\\"|\\\\))+")

let rec private (|EndOfInterpolatedString|_|) tokens =
match tokens with
Expand Down