alexanderkiel / phrase

Clojure(Script) library for phrasing spec problems.
Eclipse Public License 1.0
289 stars 8 forks source link

Fail to match coll-of min-count predicate #30

Open avnersch opened 5 years ago

avnersch commented 5 years ago

Hi, Thanks a lot for this library!

I have defined the following spec:

(s/def ::colors (s/coll-of string? :kind vector? :min-count 1))

And the following phrasers:

(phrase/defphraser :default
                   [_ problem]
                   problem)

(phrase/defphraser #(clojure.core/<= min-count (clojure.core/count %) max-count)
                   [_ {:keys [val]} min-count max-count]
                   (str min-count))

When running phrase-first with the following input:

(phrase/phrase-first {} ::colors [])

I expect the 2nd phraser to be matched, but actually the default phraser is matched:

{:path [],
 :pred (clojure.core/<= 1 (clojure.core/count %) Integer/MAX_VALUE),
 :val [],
 :via [:my-project.schema/colors],
 :in [],
 :phrase.alpha/mappings {:x0 1},
 :phrase.alpha/via ()}

Any ideas what am I missing? Thanks!

johanatan commented 4 years ago

This is my min-count phraser (which works):

(defphraser (cljs.core/<= min (cljs.core/count %) 9007199254740991)
  [_ problem min]
  (problem->err problem "min-count" #(str "Must contain at least "
                                          (formatting/pluralize %1 min))))