Skip to content

Commit

Permalink
Put match inside match on the next line. Fixes #1400. (#1459)
Browse files Browse the repository at this point in the history
  • Loading branch information
nojaf committed Feb 19, 2021
1 parent 872950f commit 38a10dd
Show file tree
Hide file tree
Showing 2 changed files with 138 additions and 0 deletions.
120 changes: 120 additions & 0 deletions src/Fantomas.Tests/PatternMatchingTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1267,3 +1267,123 @@ let private formatResponse<'options> () =
| Error err -> return sendInternalError (err)
}
"""

[<Test>]
let ``match inside match expression, 1400`` () =
formatSourceString
false
"""
let u = ""
match
match u with
| null -> ""
| s -> s
with
| "" -> x
| _ -> failwith ""
"""
config
|> prepend newline
|> should
equal
"""
let u = ""
match
match u with
| null -> ""
| s -> s
with
| "" -> x
| _ -> failwith ""
"""

[<Test>]
let ``match bang inside match expression`` () =
formatSourceString
false
"""
let u = ""
match
match! u with
| null -> ""
| s -> s
with
| "" -> x
| _ -> failwith ""
"""
config
|> prepend newline
|> should
equal
"""
let u = ""
match
match! u with
| null -> ""
| s -> s
with
| "" -> x
| _ -> failwith ""
"""

[<Test>]
let ``match inside match bang expression`` () =
formatSourceString
false
"""
let u = ""
match!
match u with
| null -> ""
| s -> s
with
| "" -> x
| _ -> failwith ""
"""
config
|> prepend newline
|> should
equal
"""
let u = ""
match!
match u with
| null -> ""
| s -> s
with
| "" -> x
| _ -> failwith ""
"""

[<Test>]
let ``match bang inside match bang expression`` () =
formatSourceString
false
"""
let u = ""
match!
match! u with
| null -> ""
| s -> s
with
| "" -> x
| _ -> failwith ""
"""
config
|> prepend newline
|> should
equal
"""
let u = ""
match!
match! u with
| null -> ""
| s -> s
with
| "" -> x
| _ -> failwith ""
"""
18 changes: 18 additions & 0 deletions src/Fantomas/CodePrinter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1592,6 +1592,15 @@ and genExpr astContext synExpr ctx =
+> tokN withRange WITH (!- "with")
+> unindent)
ctx
| Match _
| MatchBang _ ->
(indent
+> sepNln
+> genExpr astContext e
+> sepNln
+> tokN withRange WITH (!- "with")
+> unindent)
ctx
| _ ->
atCurrentColumnIndent
(genExpr astContext e
Expand Down Expand Up @@ -1621,6 +1630,15 @@ and genExpr astContext synExpr ctx =
+> tokN withRange WITH (!- "with")
+> unindent)
ctx
| Match _
| MatchBang _ ->
(indent
+> sepNln
+> genExpr astContext e
+> sepNln
+> tokN withRange WITH (!- "with")
+> unindent)
ctx
| _ ->
atCurrentColumnIndent
(genExpr astContext e
Expand Down

0 comments on commit 38a10dd

Please sign in to comment.