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

Multiline pattern proof of concept. #2645

Closed
wants to merge 8 commits into from
Closed
Original file line number Diff line number Diff line change
Expand Up @@ -1009,7 +1009,7 @@ let ``record destructuring in let binding`` () =
printfn "Last Name: %s" ln
printfn "Age: %i" age
"""
config
{ config with MaxLineLength = 50 }
|> prepend newline
|> should
equal
Expand Down
21 changes: 11 additions & 10 deletions src/Fantomas.Core.Tests/CrampedMultilineBracketStyleTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1453,7 +1453,7 @@ let internal sepSemi (ctx: Context) =
| true, true -> str " ; "
<| ctx
"""
config
{ config with MaxLineLength = 80 }
|> prepend newline
|> should
equal
Expand Down Expand Up @@ -1578,7 +1578,7 @@ match entities with
Type = Elephant } ] -> ()
| _ -> ()
"""
config
{ config with MaxLineLength = 40 }
|> prepend newline
|> should
equal
Expand Down Expand Up @@ -1607,7 +1607,7 @@ match entities with
Type = Elephant } ] -> ()
| _ -> ()
"""
config
{ config with MaxLineLength = 40 }
|> prepend newline
|> should
equal
Expand Down Expand Up @@ -1636,18 +1636,19 @@ match entities with
Type = Elephant } |] -> ()
| _ -> ()
"""
config
{ config with MaxLineLength = 40 }
|> prepend newline
|> should
equal
"""
match entities with
| [| { Key = "0031ff53-e59b-49e3-8e0f-53f72a3890d1"
Type = Elephant }
{ Key = "0031ff53-e59b-49e3-8e0f-53f72a3890d2"
Type = Elephant }
{ Key = "0031ff53-e59b-49e3-8e0f-53f72a3890d3"
Type = Elephant } |] -> ()
| [|
{ Key = "0031ff53-e59b-49e3-8e0f-53f72a3890d1"
Type = Elephant }
{ Key = "0031ff53-e59b-49e3-8e0f-53f72a3890d2"
Type = Elephant }
{ Key = "0031ff53-e59b-49e3-8e0f-53f72a3890d3"
Type = Elephant } |] -> ()
| _ -> ()
"""

Expand Down
2 changes: 2 additions & 0 deletions src/Fantomas.Core.Tests/Fantomas.Core.Tests.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@
<Compile Include="CursorTests.fs" />
<Compile Include="MultipleDefineCombinationsTests.fs" />
<Compile Include="ParenthesesTests.fs" />
<Compile Include="MultilinePatterns.fs" />
<Compile Include="MultilineNamedExpressions.fs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Fantomas.Core\Fantomas.Core.fsproj" />
Expand Down
2 changes: 1 addition & 1 deletion src/Fantomas.Core.Tests/LambdaTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1108,7 +1108,7 @@ let g =
revisionNumber = r
processName = pn } -> p, r, pn)
"""
config
{ config with MaxLineLength = 60 }
|> prepend newline
|> should
equal
Expand Down
72 changes: 72 additions & 0 deletions src/Fantomas.Core.Tests/MultilineNamedExpressions.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
module Fantomas.Core.Tests.MultilineNamedExpressions

open NUnit.Framework
open FsUnit
open Fantomas.Core
open Fantomas.Core.Tests.TestHelpers

[<Test>]
let ``single named item expression`` () =
formatSourceString
false
"""
let x =
ParsedInput.ImplFile(
ParsedImplFileInput(
contents =
[ SynModuleOrNamespace.SynModuleOrNamespace(
decls =
[ a
//
b ]
) ]
)
)
"""
{ config with MaxLineLength = 80 }
|> prepend newline
|> should
equal
"""
let x =
ParsedInput.ImplFile(
ParsedImplFileInput(contents = [
SynModuleOrNamespace.SynModuleOrNamespace(decls = [
a
//
b
])
])
)
"""

// TODO: there is currently no check whether `(a =` fits on the remainder of the line.

[<Test>]
let ``multiline long identifier in named argument function call`` () =
formatSourceString
false
"""
XXXXXXXXXXXXXXXX
// Some comment
.YYYYYYYYYYYYYY
.ZZZZZZZZZZZZZZZ(
a =
try b () with ex -> c
)
"""
config
|> prepend newline
|> should
equal
"""
XXXXXXXXXXXXXXXX
// Some comment
.YYYYYYYYYYYYYY
.ZZZZZZZZZZZZZZZ(a =
try
b ()
with ex ->
c
)
"""
Loading