Closed cloojure closed 2 years ago
Sample code
(ns tst.demo.issue (:use tupelo.core tupelo.test) (:require [schema.core :as s] )) (dotest (is= 5 (s/validate s/Int 5)) (throws? (s/validate s/Int nil)). ; s/validate throws on failure (nil value) (is= 5 (s/validate (s/maybe s/Int) 5)) (is= nil (s/validate (s/maybe s/Int) nil)) ; s/maybe allows nil values to succedd (is= [] (s/validate [s/Int] [])) (is= [5] (s/validate [s/Int] [5])) (is= nil (s/validate [s/Int] nil)) ; ***** does not throw for nil values, even w/o s/maybe! ***** (is= [] (s/validate (s/maybe [s/Int]) [])) (is= [5] (s/validate (s/maybe [s/Int]) [5])) (is= nil (s/validate (s/maybe [s/Int]) nil)) ; behaves as expected )
In the 3rd block of tests, s/validate should throw for the value nil and the schema [s/Int]
s/validate
nil
[s/Int]
The above demo code was build using my favorite template project:
Hi, I believe this is by design, nil is an empty sequence in Clojure (in addition to being null and "falsey")
Sample code
In the 3rd block of tests,
s/validate
should throw for the valuenil
and the schema[s/Int]
The above demo code was build using my favorite template project: