diff --git a/src/Fantomas.Tests/CastTests.fs b/src/Fantomas.Tests/CastTests.fs new file mode 100644 index 0000000000..8b5b05e884 --- /dev/null +++ b/src/Fantomas.Tests/CastTests.fs @@ -0,0 +1,53 @@ +module Fantomas.Tests.CastTests + +open NUnit.Framework +open FsUnit +open Fantomas.Tests.TestHelper + +[] +let ``multiline downcast expression, `` () = + formatSourceString false """ +longMethodName + longArgument + longArgument2 +:?> List +""" + { config with + MaxLineLength = 30 + SpaceBeforeUppercaseInvocation = true + SpaceBeforeColon = true + SpaceBeforeSemicolon = true + AlignFunctionSignatureToIndentation = true + AlternativeLongMemberDefinitions = true + DisableElmishSyntax = true } + |> prepend newline + |> should equal """ +longMethodName + longArgument + longArgument2 +:?> List +""" + +[] +let ``multiline upcast expression, `` () = + formatSourceString false """ +longMethodName + longArgument + longArgument2 +:> List +""" + { config with + MaxLineLength = 30 + SpaceBeforeUppercaseInvocation = true + SpaceBeforeColon = true + SpaceBeforeSemicolon = true + AlignFunctionSignatureToIndentation = true + AlternativeLongMemberDefinitions = true + DisableElmishSyntax = true } + |> prepend newline + |> should equal """ +longMethodName + longArgument + longArgument2 +:> List +""" diff --git a/src/Fantomas.Tests/ComputationExpressionTests.fs b/src/Fantomas.Tests/ComputationExpressionTests.fs index 86e3c1b444..2c1363b1e4 100644 --- a/src/Fantomas.Tests/ComputationExpressionTests.fs +++ b/src/Fantomas.Tests/ComputationExpressionTests.fs @@ -1519,7 +1519,8 @@ let sendPushNotifications = subscriptions s.Origin s.Endpoint - } :> Task) + } + :> Task) |> Task.WhenAll) """ diff --git a/src/Fantomas.Tests/Fantomas.Tests.fsproj b/src/Fantomas.Tests/Fantomas.Tests.fsproj index e54c4e4a23..2fac715b53 100644 --- a/src/Fantomas.Tests/Fantomas.Tests.fsproj +++ b/src/Fantomas.Tests/Fantomas.Tests.fsproj @@ -79,6 +79,7 @@ + diff --git a/src/Fantomas/CodePrinter.fs b/src/Fantomas/CodePrinter.fs index 56801a7499..ccf1bffd13 100644 --- a/src/Fantomas/CodePrinter.fs +++ b/src/Fantomas/CodePrinter.fs @@ -1357,11 +1357,25 @@ and genExpr astContext synExpr ctx = +> ifElse (hasParenthesis e) sepNone sepSpace +> genExpr astContext e | TypedExpr (Downcast, e, t) -> - genExpr astContext e -- " :?> " - +> genType astContext false t + let shortExpr = + genExpr astContext e -- " :?> " + +> genType astContext false t + + let longExpr = + genExpr astContext e +> sepNln -- ":?> " + +> genType astContext false t + + expressionFitsOnRestOfLine shortExpr longExpr | TypedExpr (Upcast, e, t) -> - genExpr astContext e -- " :> " - +> genType astContext false t + let shortExpr = + genExpr astContext e -- " :> " + +> genType astContext false t + + let longExpr = + genExpr astContext e +> sepNln -- ":> " + +> genType astContext false t + + expressionFitsOnRestOfLine shortExpr longExpr | TypedExpr (Typed, e, t) -> genExpr astContext e +> sepColon