mardi 15 août 2017

Force FsCheck to generate NonEmptyString for discriminating union fields of type string

I'm trying to achieve the following behaviour with FsCheck: I'd like to create a generator that will generate a instance of MyUnion type, with every string field being non-null/empty.

type MyNestedUnion =
    | X of string
    | Y of int * string

type MyUnion =
    | A of int * int * string * string
    | B of MyNestedUnion

My 'real' type is much larger/deeper than the MyUnion, and FsCheck is able to generate a instance without any problem, but the string fields of the union cases are sometimes empty. (For example it might generate B (Y (123, "")))

Perhaps there's some obvious way of combining FsCheck's NonEmptyString and its support for generating arbitrary union types that I'm missing?

Any tips/pointers in the right direction greatly appreciated.

Thanks!

Aucun commentaire:

Enregistrer un commentaire