Skip to content

Commit

Permalink
Add parenthesis for multiline SynPat.Tuple expression in SynBinding. F…
Browse files Browse the repository at this point in the history
  • Loading branch information
nojaf committed Oct 2, 2020
1 parent a241023 commit 3ad4c6d
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
55 changes: 55 additions & 0 deletions src/Fantomas.Tests/TupleTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,58 @@ let ``multiline item in tuple - paren on its line`` () =
then answerWhenTheConditionIsTrue
else answerWhenTheConditionIsFalse))
"""

[<Test>]
let ``multiline SynPat.Tuple should have parenthesis, 824`` () =
formatSourceString false """
namespace GWallet.Backend.Tests
module Foo =
let someOtherFunc () =
let var1withAVeryLongLongLongLongLongLongName, var2withAVeryLongLongLongLongLongLongName =
someFunc 1, someFunc 2
()
""" { config with MaxLineLength = 80 }
|> prepend newline
|> should equal """
namespace GWallet.Backend.Tests
module Foo =
let someOtherFunc () =
let (var1withAVeryLongLongLongLongLongLongName,
var2withAVeryLongLongLongLongLongLongName) =
someFunc 1, someFunc 2
()
"""

[<Test>]
let ``multiline SynPat.Tuple with existing parenthesis should not add additional parenthesis`` () =
formatSourceString false """
namespace GWallet.Backend.Tests
module Foo =
let someOtherFunc () =
let (var1withAVeryLongLongLongLongLongLongName,
var2withAVeryLongLongLongLongLongLongName) =
someFunc 1, someFunc 2
()
""" { config with MaxLineLength = 80 }
|> prepend newline
|> should equal """
namespace GWallet.Backend.Tests
module Foo =
let someOtherFunc () =
let (var1withAVeryLongLongLongLongLongLongName,
var2withAVeryLongLongLongLongLongLongName) =
someFunc 1, someFunc 2
()
"""
2 changes: 2 additions & 0 deletions src/Fantomas/CodePrinter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -681,6 +681,8 @@ and genLetBinding astContext pref b =
genPatWithReturnType ao s ps tpso (Some t) astContext
| _, PatLongIdent (ao, s, ps, tpso) when (List.length ps > 1) ->
genPatWithReturnType ao s ps tpso None astContext
| _, PatTuple _ ->
expressionFitsOnRestOfLine (genPat astContext p) (sepOpenT +> genPat astContext p +> sepCloseT)
| _ -> genPat astContext p

let genAttr =
Expand Down

0 comments on commit 3ad4c6d

Please sign in to comment.