elm-explorations / elm-explorations/test
It should be easier to fuzz nested data structures.
- Dominant language
- Elm
- Stars
- 244
- Forks
- 40
- Avg merge
- 1d 23h
- Merged PRs (30d)
- 2
Description
I'm in the midst of putting the finishing touches on a csv-encoding library before releasing it, and as part of that want a fuzzer for this type:
```elm
type alias Csv =
{ headers : List String
, records : List (List String)
}
```
The obvious way to do this would be something like:
```elm
csvFuzzer =
Fuzz.map2 Csv
(Fuzz.list Fuzz.string)
(Fuzz.list (Fuzz.list Fuzz.string))
```
But this generates huge inputs, enough so that a simple test of "encode then decode gives the same result" takes >5 min on my laptop.
So I went about trying to write a custom fuzzer that generates more reasonably sized inputs. I've got something written that shrinks `headers` using `Shrink.list Shrink.string` and something that shrinks `records` using `Shrink.list (Shrink.list Shrink.string)`, and I have no idea how to combine them. If the LazyList module were exposed I could just concatenate the lists, but I have no idea how to do this with the exposed API.
There are a few possible takeaways from this experience:
* There are some gaps in the API for combining shrinkers
* You really shouldn't have to go to the trouble of writing custom generators and shrinkers just to get a smaller version of an existing fuzzer. Maybe something like #89 would help with this.
* It's awkward that a shrinker returns a type that isn't actually exposed anywhere, and thus can't be worked with.
What I would really have liked to write is something like this fuzzer:
```elm
csvFuzzer =
Fuzz.map2 Csv
(Fuzz.list Fuzz.string)
(Fuzz.list (Fuzz.smaller (Fuzz.list Fuzz.string))
```
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.