From 2f7d5b75c48a9ab304b617aa16e6446d7bc27f56 Mon Sep 17 00:00:00 2001 From: Florian Verdonck Date: Fri, 2 Oct 2020 15:18:21 +0200 Subject: [PATCH] Add parenthesis for multiline SynPat.Tuple expression in SynBinding. Fixes #824. (#1183) --- src/Fantomas.Tests/TupleTests.fs | 55 ++++++++++++++++++++++++++++++++ src/Fantomas/CodePrinter.fs | 2 ++ 2 files changed, 57 insertions(+) diff --git a/src/Fantomas.Tests/TupleTests.fs b/src/Fantomas.Tests/TupleTests.fs index f06f394d42..915e4b01db 100644 --- a/src/Fantomas.Tests/TupleTests.fs +++ b/src/Fantomas.Tests/TupleTests.fs @@ -29,3 +29,58 @@ let ``multiline item in tuple - paren on its line`` () = then answerWhenTheConditionIsTrue else answerWhenTheConditionIsFalse)) """ + +[] +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 + + () +""" + +[] +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 + + () +""" diff --git a/src/Fantomas/CodePrinter.fs b/src/Fantomas/CodePrinter.fs index 8717664aef..c55b561f1c 100644 --- a/src/Fantomas/CodePrinter.fs +++ b/src/Fantomas/CodePrinter.fs @@ -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 =