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

Fix 192 #234

Merged
merged 3 commits into from
Mar 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/Fantomas.Tests/FunctionDefinitionTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -267,8 +267,7 @@ let f = fun x -> match x with X (x) -> x
""" config
|> prepend newline
|> should equal """
type U =
| X of int
type U = X of int

let f =
fun x ->
Expand Down
3 changes: 1 addition & 2 deletions src/Fantomas.Tests/RecordTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,7 @@ type rate2 = Rate of float<GBP/SGD*USD>
type rate =
{ Rate : float<GBP * SGD / USD> }

type rate2 =
| Rate of float<GBP / SGD * USD>
type rate2 = Rate of float<GBP / SGD * USD>
"""

[<Test>]
Expand Down
3 changes: 1 addition & 2 deletions src/Fantomas.Tests/TypeDeclarationTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -532,8 +532,7 @@ type Delegate3 = delegate of int -> (int -> int)

type Delegate4 = delegate of int -> int -> int

type U =
| U of (int * int)
type U = U of (int * int)
"""

[<Test>]
Expand Down
41 changes: 39 additions & 2 deletions src/Fantomas.Tests/UnionTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,7 @@ let main argv =
| _ -> 0""" config
|> prepend newline
|> should equal """
type TestUnion =
| Test of A : int * B : int
type TestUnion = Test of A : int * B : int

[<EntryPoint>]
let main argv =
Expand All @@ -154,4 +153,42 @@ type uColor =

let col3 =
Microsoft.FSharp.Core.LanguagePrimitives.EnumOfValue<uint32, uColor>(2u)
"""

[<Test>]
let ``Single case DUs on same line`` () =
formatSourceString false """
type CustomerId =
| CustomerId of int
""" config
|> prepend newline
|> should equal """
type CustomerId = CustomerId of int
"""

[<Test>]
let ``Single case DU with private access modifier`` () =
formatSourceString false """
type CustomerId =
private
| CustomerId of int
""" config
|> prepend newline
|> should equal """
type CustomerId = private CustomerId of int
"""

[<Test>]
let ``Single case DU with member should be on a newline`` () =
formatSourceString false """
type CustomerId =
| CustomerId of int
member this.Test() =
printfn "%A" this
""" config
|> prepend newline
|> should equal """
type CustomerId =
| CustomerId of int
member this.Test() = printfn "%A" this
"""
13 changes: 11 additions & 2 deletions src/Fantomas/CodePrinter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -690,9 +690,18 @@ and genTypeDefn astContext (TypeDef(ats, px, ao, tds, tcs, tdr, ms, s)) =
+> unindent

| Simple(TDSRUnion(ao', xs)) ->
let unionCases =
match xs with
| [] -> id
| [x] when List.isEmpty ms ->
indent +> sepSpace +> opt sepSpace ao' genAccess
+> genUnionCase { astContext with HasVerticalBar = false } x
| xs ->
indent +> sepNln +> opt sepNln ao' genAccess
+> col sepNln xs (genUnionCase { astContext with HasVerticalBar = true })

typeName +> sepEq
+> indent +> sepNln +> opt sepNln ao' genAccess
+> col sepNln xs (genUnionCase { astContext with HasVerticalBar = true })
+> unionCases
+> genMemberDefnList { astContext with IsInterface = false } ms
+> unindent

Expand Down