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

Allow reflector to derive generator for unions with a private constructor #186

Merged
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
2 changes: 1 addition & 1 deletion src/FsCheck/Reflect.fs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ module internal Reflect =
// ||| BindingFlags.NonPublic ||| BindingFlags.Public

let isRecordType (ty : Type) = FSharpType.IsRecord(ty, true) //recordFieldBindingFlags)
let isUnionType ty = FSharpType.IsUnion ty
let isUnionType ty = FSharpType.IsUnion(ty, true)
let isTupleType ty = FSharpType.IsTuple ty
let getPublicCtors (ty: Type) = ty.GetTypeInfo().DeclaredConstructors |> Seq.filter (fun c -> c.IsPublic)
let isCSharpRecordType (ty: Type) =
Expand Down
11 changes: 11 additions & 0 deletions tests/FsCheck.Test/Arbitrary.fs
Original file line number Diff line number Diff line change
Expand Up @@ -413,3 +413,14 @@ module Arbitrary =
let ``Derive generator for concrete class with one constructor with two parameters``() =
generate<FakeRecord> |> sample 10 |> ignore

type PrivateRecord = private { a: int; b: string }

[<Fact>]
let ``Derive generator for private two value record``() =
generate<PrivateRecord> |> sample 10 |> ignore

type PrivateUnion = private | Case1 | Case2 of string

[<Fact>]
let ``Derive generator for private two case union``() =
generate<PrivateUnion> |> sample 10 |> ignore