Skip to content

Commit

Permalink
Remove IsFirstChild from ASTContext. (#1972)
Browse files Browse the repository at this point in the history
  • Loading branch information
nojaf authored Nov 19, 2021
1 parent 38e1555 commit 7c52602
Show file tree
Hide file tree
Showing 2 changed files with 236 additions and 40 deletions.
163 changes: 163 additions & 0 deletions src/Fantomas.Tests/AttributeTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -783,3 +783,166 @@ module Foo =
[<DllImport("Kernel32.dll", SetLastError = true)>]
extern bool GetFileInformationByHandleEx(IntPtr hFile, FILE_INFO_BY_HANDLE_CLASS infoClass, [<Out>] FILE_NAME_INFO& info, uint32 dwBufferSize)
"""

[<Test>]
let ``attribute on member of recursive type, 1918`` () =
formatSourceString
false
"""
type X = A
and Y = B
with
[<ExcludeFromCodeCoverage>]
member this.M() = true
"""
config
|> prepend newline
|> should
equal
"""
type X = A
and Y = B
with
[<ExcludeFromCodeCoverage>]
member this.M() = true
"""

[<Test>]
let ``attribute on second member defn, 1898`` () =
formatSourceString
false
"""
type Test1() =
member x.Test() = ()
and Test2() =
let someEvent = Event<EventHandler<int>, int>()
[<CLIEvent>]
member x.SomeEvent = someEvent.Publish
"""
config
|> prepend newline
|> should
equal
"""
type Test1() =
member x.Test() = ()
and Test2() =
let someEvent = Event<EventHandler<int>, int>()
[<CLIEvent>]
member x.SomeEvent = someEvent.Publish
"""

[<Test>]
let ``attributes on recursive discriminated union types, 1874`` () =
formatSourceString
false
"""
module test
open System.Diagnostics
type Correct =
| A of unit
[<DebuggerStepThrough>]
override this.ToString () = ""
[<DebuggerStepThrough>]
member this.f = ()
[<DebuggerStepThrough>]
static member this.f = ()
and Wrong =
| B of unit
[<DebuggerStepThrough>]
override this.ToString () = ""
[<DebuggerStepThrough>]
member this.f = ()
[<DebuggerStepThrough>]
static member this.f = ()
"""
config
|> prepend newline
|> should
equal
"""
module test
open System.Diagnostics
type Correct =
| A of unit
[<DebuggerStepThrough>]
override this.ToString() = ""
[<DebuggerStepThrough>]
member this.f = ()
[<DebuggerStepThrough>]
static member this.f = ()
and Wrong =
| B of unit
[<DebuggerStepThrough>]
override this.ToString() = ""
[<DebuggerStepThrough>]
member this.f = ()
[<DebuggerStepThrough>]
static member this.f = ()
"""

[<Test>]
let ``attribute on member of recursive record type, 1962`` () =
formatSourceString
false
"""
module Foo =
type Person = {
Name : string
FavoriteDog : Dog
} with
[<RequiresExplicitTypeArguments>]
static member doThing person =
()
and Dog = {
Name : string
FavoriteChewToy : string
} with
[<RequiresExplicitTypeArguments>]
static member doThing person =
()
"""
config
|> prepend newline
|> should
equal
"""
module Foo =
type Person =
{ Name: string
FavoriteDog: Dog }
[<RequiresExplicitTypeArguments>]
static member doThing person = ()
and Dog =
{ Name: string
FavoriteChewToy: string }
[<RequiresExplicitTypeArguments>]
static member doThing person = ()
"""
Loading

0 comments on commit 7c52602

Please sign in to comment.