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 shrinking private unions #567

Merged
merged 1 commit into from
May 4, 2021
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
6 changes: 3 additions & 3 deletions src/FsCheck/ReflectArbitrary.fs
Original file line number Diff line number Diff line change
Expand Up @@ -190,9 +190,9 @@ module internal ReflectArbitrary =
if Seq.isEmpty children then 0
elif Seq.exists ((=) t) children then 2
else 1
let info,_ = FSharpValue.GetUnionFields(o,t)
let makeCase = FSharpValue.PreComputeUnionConstructor info
let readCase = FSharpValue.PreComputeUnionReader info
let info,_ = FSharpValue.GetUnionFields(o,t,true)
let makeCase = FSharpValue.PreComputeUnionConstructor(info,true)
let readCase = FSharpValue.PreComputeUnionReader(info,true)
let childrenTypes = info.GetFields() |> Array.map ( fun x -> x.PropertyType )
let partitionCase t s0 (_,(_,children,make,_)) =
match unionSize t children with
Expand Down
8 changes: 8 additions & 0 deletions tests/FsCheck.Test/Arbitrary.fs
Original file line number Diff line number Diff line change
Expand Up @@ -692,12 +692,20 @@ module Arbitrary =
let ``Derive generator for private two value record``() =
generate<PrivateRecord> |> sample 10 |> ignore

[<Property>]
let ``Shrink for private two value record`` (DoNotShrink (value: PrivateRecord)) =
shrink value |> ignore

type PrivateUnion = private | Case1 | Case2 of string

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

[<Property>]
let ``Shrink for private two case union`` (DoNotShrink (value: PrivateUnion)) =
shrink value |> ignore

[<Fact>]
let ``should not crash on isCSharpDto issue #545``() =
try
Expand Down