Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
avnersch opened this issue Feb 9, 2019 · 1 comment
Open

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

avnersch opened this issue Feb 9, 2019 · 1 comment

Comments

@avnersch
Copy link

avnersch commented Feb 9, 2019

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
Copy link

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))))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants