-
Notifications
You must be signed in to change notification settings - Fork 8
Open
Description
Hello, I am missing how to phrase a coll-of
. Consider the following:
(ns grape.phrase-test
(:require [clojure.test :refer [deftest is are testing]]
[clojure.spec.alpha :as s]
[phrase.alpha :as phrase]))
(s/def ::just-int int?)
(phrase/defphraser int? [_ _] "Expected an integer (1)")
; this passes
(deftest simplest-possible-spec-for-phrase
(is (= "val: 1.0 fails spec: :grape.phrase-test/just-int predicate: int?\n"
(s/explain-str ::just-int 1.0)))
(is (= "Expected an integer (1)"
(phrase/phrase-first {} ::just-int 1.0))))
(s/def ::coll-of-ints (s/coll-of int?))
(phrase/defphraser coll? [_ _] "Expected a collection (2)")
(deftest coll-of-ints-fail-pred-int
; this passes
(is (= "In: [0] val: :a fails spec: :grape.phrase-test/coll-of-ints predicate: int?\n"
(s/explain-str ::coll-of-ints [:a])))
; this fails with `nil`
(is (= "Expected an integer (1)" (phrase/phrase-first {} ::coll-of-ints [:a]))))
; this passes
(deftest coll-of-ints-fail-pred-coll
(is (= "val: :a fails spec: :grape.phrase-test/coll-of-ints predicate: coll?\n"
(s/explain-str ::coll-of-ints :a)))
(is (= "Expected a collection (2)" (phrase/phrase-first {} ::coll-of-ints :a))))
Tests simplest-possible-spec-for-phrase
and coll-of-ints-fail-pred-coll
pass as expected. On the other hand, test coll-of-ints-fail-pred-int
fails, phrase-first
returns nil
instead of "Expected an integer (1)"
. What am I missing ?
Metadata
Metadata
Assignees
Labels
No labels