File tree Expand file tree Collapse file tree 2 files changed +29
-1
lines changed Expand file tree Collapse file tree 2 files changed +29
-1
lines changed Original file line number Diff line number Diff line change 153153#?(:cljs (defn- pr-writer-schema [obj writer opts]
154154 (-pr-writer (-form ^Schema obj) writer opts)))
155155
156- (defrecord Tag [key value])
156+ (defrecord Tag [key value]
157+ clojure.lang.Indexed
158+ (nth [_ i]
159+ (case (long i)
160+ 0 key
161+ 1 value
162+ (let [message " wrong tag index" ]
163+ (throw
164+ #?(:clj (new IndexOutOfBoundsException message)
165+ :cljs (new js/Error message))))))
166+ (nth [_ i not-found]
167+ (case (long i)
168+ 0 key
169+ 1 value
170+ not-found)))
157171
158172(defn tag
159173 " A tagged value, used eg. for results of `parse` for `:orn` schemas."
Original file line number Diff line number Diff line change 12361236
12371237 (is (true ? (m/validate (over-the-wire schema) valid1)))
12381238
1239+ (testing " tag nth support"
1240+ (let [tag (m/parse schema valid1)
1241+ [k v x] tag]
1242+ (is (= :sized k))
1243+ (is (= valid1 v))
1244+ (is (nil? x))
1245+ (try
1246+ (nth tag 99 )
1247+ (is false " should throw" )
1248+ (catch #?(:clj IndexOutOfBoundsException
1249+ :cljs js/Error) e
1250+ (is (= " wrong tag index"
1251+ (ex-message e)))))))
1252+
12391253 (testing " ast"
12401254 (is (= {:type :multi ,
12411255 :keys {:sized {:order 0 ,
You can’t perform that action at this time.
0 commit comments