-
-
Notifications
You must be signed in to change notification settings - Fork 73
Closed
Labels
Description
Today it's quite nasty to generate maps (with fixed keys and generator values) with optional keys. You have to either build on top of fixed_map/1 but it's a bit convolute to add keys optionally and make it shrink towards having no optional keys. I think it might be nice to have a good interface for this. We can't get inspiration from PropEr or QuickCheck because they don't support maps, and test.check only supports hash-map which is our fixed_map/1.
One idea could be to have optional_map/1 that mirrors fixed_map/1 but which shrinks by taking away key-value pairs as well, and then a structured map with optional keys could be built by doing
fixed = %{
name: string(:alphanumeric),
}
optional = %{
age: map(integer(), &abs/1),
}
map({fixed, optional}, fn {fixed_map, optional_map} -> Map.merge(fixed_map, optional_map) end)I am not sure this is a very elegant solution thought. Ideas? \cc @josevalim
Reactions are currently unavailable