Skip to content

Commit

Permalink
Generate Trivia for Enum cases - fixes fsprojects#572
Browse files Browse the repository at this point in the history
  • Loading branch information
theimowski committed Nov 28, 2019
1 parent beb5f7e commit 94d3144
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
33 changes: 33 additions & 0 deletions src/Fantomas.Tests/CommentTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,39 @@ open NUnit.Framework
open FsUnit
open Fantomas.Tests.TestHelper

[<Test>]
let ``comments on enums - https://github.com/fsprojects/fantomas/issues/572``() =
formatSourceString false """type A =
/// Doc for CaseA
| CaseA = 0
/// Doc for CaseB
| CaseB = 1
/// Doc for CaseC
| CaseC = 2""" config
|> should equal """type A =
/// Doc for CaseA
| CaseA = 0
/// Doc for CaseB
| CaseB = 1
/// Doc for CaseC
| CaseC = 2
"""
formatSourceString false """type A =
// Comment for CaseA
| CaseA = 0
// Comment for CaseB
| CaseB = 1
// Comment for CaseC
| CaseC = 2""" config
|> should equal """type A =
// Comment for CaseA
| CaseA = 0
// Comment for CaseB
| CaseB = 1
// Comment for CaseC
| CaseC = 2
"""

[<Test>]
let ``should keep sticky-to-the-left comments after nowarn directives``() =
formatSourceString false """#nowarn "51" // address-of operator can occur in the code""" config
Expand Down
1 change: 1 addition & 0 deletions src/Fantomas/CodePrinter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1741,6 +1741,7 @@ and genEnumCase astContext (EnumCase(ats, px, _, (_,r)) as node) =
!- ident.idText +> !- " = " +> genConst c r

genPreXmlDoc px
+> genTriviaBeforeClausePipe node.Range
+> ifElse astContext.HasVerticalBar sepBar sepNone
+> genOnelinerAttributes astContext ats
+> genCase
Expand Down

0 comments on commit 94d3144

Please sign in to comment.