File tree Expand file tree Collapse file tree 2 files changed +28
-1
lines changed
Expand file tree Collapse file tree 2 files changed +28
-1
lines changed Original file line number Diff line number Diff line change 8787 (.iterator ^Iterable (map auto-get-choice m)))
8888
8989 Iterable
90- (iterator [this] (.iterator ^Iterable (.seq this))))
90+ (iterator [this]
91+ (if-let [xs (.seq this)]
92+ (.iterator ^Iterable xs)
93+ (.iterator {}))))
9194
9295(defn unwrap
9396 " If `m` is a [[Choice]] or [[ChoiceMap]], returns `m` stripped of its wrappers.
Original file line number Diff line number Diff line change 22 (:refer-clojure :exclude [empty empty?])
33 (:require [clojure.core :as clojure]
44 [clojure.test :refer [deftest is]]
5+ [clojure.test.check.generators :as gen]
6+ [com.gfredericks.test.chuck.clojure-test :refer [checking]]
57 [gen.choice-map :as choice-map]
68 [gen.dynamic.choice-map :as dynamic.choice-map]))
79
10+ (def gen-choice-map
11+ (comp (partial gen/fmap dynamic.choice-map/choice-map)
12+ gen/map))
13+
814(deftest choice
915 (is (dynamic.choice-map/choice? (dynamic.choice-map/choice nil )))
1016 (is (dynamic.choice-map/choice? #gen/choice nil ))
3036 (is (clojure/empty? #gen/choice-map {}))
3137 #_ {:clj-kondo/ignore [:not-empty? ]}
3238 (is (not (clojure/empty? #gen/choice-map {:x 0 }))))
39+
40+ (defn iterable-seq [^Iterable iter]
41+ (when (.hasNext iter)
42+ (lazy-seq
43+ (cons (.next iter)
44+ (iterable-seq iter)))))
45+
46+ (deftest interface-tests
47+ (checking " Interface tests for choice maps"
48+ [m (gen-choice-map gen/keyword gen/any-equatable)]
49+ (is (= (seq m)
50+ (iterable-seq
51+ (.iterator ^Iterable m)))
52+ " iterator impl matches seq" )
53+
54+ (is (= m (dynamic.choice-map/choice-map
55+ (zipmap (keys m) (vals m))))
56+ " keys and vals work correctly" )))
You can’t perform that action at this time.
0 commit comments