leanovate / gopter

GOlang Property TestER
MIT License
599 stars 40 forks source link

Add StrictStruct/StrictStructPtr. #77

Closed coventry closed 3 years ago

coventry commented 3 years ago

These behave the same as Struct/StructPtr, except that they panic unless the keys in the gens map exactly match the fields on rt (i.e. gens must specify generators for all fields.)

If passed an extra true argument, they allow gens to leave generators for some fields unspecified. They still panic unless the keys in gens all correspond to fields on rt. In this case, the generated values will have the zero value for any field which is left unspecified in gens.

coventry commented 3 years ago

That would have been my expectation, too, but there's a test which explicitly checks that a key which doesn't match fields is silently ignored. I can see arguments for it going either way, especially now that the liberal version is in widespread use.

coventry commented 3 years ago

Oh, and thanks for testing it!

untoldwind commented 3 years ago

Looks good, but I think I will refactor the use of pkg/errors so that the base library does not have transient dependencies