tag patterns work with conforms? but not sample
OliverM opened this issue · 3 comments
Are some patterns not usable as generators? For example, I've a record that I can test for conformity but I can't seem to generate records when sampling:
(defrecord Person [fname lname])
(def person-record (map->Person {:fname "Test" :lname "Herbert"}))
(miner.herbert/conforms? '{:fname str :lname str} person-record) ;; true
(miner.herbert.generators/sample '{:fname str :lname str}) ;; generates sample maps
(miner.herbert.generators/sample
'(tag user/Person {:fname str :lname str})) ;; throws ArityException
Presumably the work-around here is to use maps instead of records. Are there other problematic patterns?
I'm having great fun getting to grips with Herbert by the way, thank you!
I need to think about what to do about generating records. Probably needs to be user extensible.
As you suggested, try using maps as a work-around. If you're using test.check you could 'fmap' the results into real records using the record's creator function (map->WHATEVER).
I need to document which other patterns that don't have generators. All the common patterns work, but there are issues with complex combinations, especially 'and' constraints. They are easy to test with conforms?, but hard to generate.
Just released 0.7.0-alpha2 which should fix the generator for (tag ...). For example, if you have a record my.ns.Rec with an :a field, you can generate using a pattern like (tag my.ns/Rec {:a int}).
It works perfectly, thank you!