gen.attrsOf: attrsets with generated keys #4
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Missing
gen.attrsOf lenRange keyGen valueGen(a map with generated keys), the attrset counterpart ofgen.listOf.Where it was needed
jsonschema2nix generates values for JSON Schema maps (
additionalProperties). Only the number of keys can vary today; the keys come from a fixed list:So a property over maps never sees a key that matches
propertyNames/patternPropertiespatterns, a key that collides with a declared property name, or more than two entries, and shrinking cannot drop individual keys, only shorten the prefix.Suggested shape
gen.attrsOf lenRange keyGen valueGen, deduplicating keys, shrinking by removing entries (likelistOf) and by shrinking each key and value.gen.attrsWith keys valueGenfor a subset of a known key list, shrinking toward fewer keys.Plan
Hedgehog
Gen.mapretries on duplicate keys; Hypothesisdictionariesand fast-checkdictionarydrop them. nixcheck has no discard machinery yet, so start with drop-duplicates:listToAttrskeeps the first occurrence (verified), so the result is deterministic; the entry count can be below the drawn length, same as Hypothesis. Document it. Switch to retrying once #9 (gen.filter/ discards) exists.attrsWith keys valueGen=bind (subsequence keys) (ks: record (genAttrs ks valueGen)), withgen.subsequencefrom #11 (each key kept by aboolthat shrinkstrue -> false, so the attrset shrinks toward{ }).Shrinking individual keys is limited by
listOfonly dropping a suffix; #13 (chunk-removal list shrinking) fixes that for lists and attrsets at once.Implemented in
e7270a3, pushed to main.