Skip to content

Commit

Permalink
Merge pull request #234 from nojaf/fix-192
Browse files Browse the repository at this point in the history
Fix 192
  • Loading branch information
dungpa authored Mar 16, 2018
2 parents 8e5b97d + 93c6cff commit 7b133fa
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 10 deletions.
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

0 comments on commit 7b133fa

Please sign in to comment.