|
53 | 53 | (is (= "#function[custom-print-cljs-2812]" (pr-str map))) |
54 | 54 | ;; Restore basic native types so that test summary output looks correct |
55 | 55 | (extend-protocol IPrintWithWriter |
| 56 | + object |
| 57 | + (-pr-writer [obj writer _] |
| 58 | + (write-all writer (str obj))) |
56 | 59 | boolean |
57 | 60 | (-pr-writer [obj writer _] |
58 | 61 | (write-all writer (str obj))) |
|
70 | 73 | (let [empty-array (empty #js [1 2 3])] |
71 | 74 | (is (and (array? empty-array) |
72 | 75 | (empty? empty-array))))) |
| 76 | + |
| 77 | +(defn test-map-entry [x] (when (map-entry? x) (-key x))) |
| 78 | +(defn test-coll [x] (when (coll? x) (-conj x 1))) |
| 79 | +(defn test-set [x] (when (set? x) (-disjoin x 1))) |
| 80 | +(defn test-associative [x] (when (associative? x) (-assoc x 1 2))) |
| 81 | +(defn test-find [x] (when (ifind? x) (-find x 1))) |
| 82 | +(defn test-sorted [x] (when (sorted? x) (-sorted-seq x true))) |
| 83 | +(defn test-map [x] (when (map? x) (-dissoc x 1))) |
| 84 | +(defn test-vector [x] (when (vector? x) (-assoc-n x 1 2))) |
| 85 | +(defn test-chunked-seq [x] (when (chunked-seq? x) (-chunked-first x))) |
| 86 | +(defn test-ifn [x] (when (ifn? x) (-invoke x))) |
| 87 | +(defn test-reversible [x] (when (reversible? x) (-rseq x))) |
| 88 | +(defn test-iterable [x] (when (iterable? x) (-iterator x))) |
| 89 | +(defn test-cloneable [x] (when (cloneable? x) (-clone x))) |
| 90 | +(defn test-counted [x] (when (counted? x) (-count x))) |
| 91 | +(defn test-indexed [x] (when (indexed? x) (-nth x 0))) |
| 92 | +(defn test-seqable [x] (when (seqable? x) (-seq x))) |
| 93 | +(defn test-reduceable [x] (when (reduceable? x) (-reduce x inc))) |
| 94 | + |
| 95 | +(deftest test-extend-to-protocols |
| 96 | + (extend-type string IMapEntry (-key [_] :a)) |
| 97 | + (is (nil? (test-map-entry "a"))) |
| 98 | + (extend-type string ICollection (-conj [_ _] :b)) |
| 99 | + (is (= :b (test-coll "a"))) |
| 100 | + (extend-type string ISet (-disjoin [_ _] :c)) |
| 101 | + (is (= :c (test-set "a"))) |
| 102 | + (extend-type string IAssociative (-assoc [_ _ _] :d)) |
| 103 | + (is (= :d (test-associative "a"))) |
| 104 | + (extend-type string IFind (-find [_ _] :e)) |
| 105 | + (is (= :e (test-find "a"))) |
| 106 | + (extend-type string ISorted (-sorted-seq [_ _] :f)) |
| 107 | + (is (= :f (test-sorted "a"))) |
| 108 | + (extend-type string IMap (-dissoc [_ _] :g)) |
| 109 | + (is (= :g (test-map "a"))) |
| 110 | + (extend-type string IVector (-assoc-n [_ _ _] :h)) |
| 111 | + (is (= :h (test-vector "a"))) |
| 112 | + (extend-type string IChunkedSeq (-chunked-first [_] :i)) |
| 113 | + (is (nil? (test-chunked-seq "a"))) |
| 114 | + (extend-type string IFn (-invoke [_] :j)) |
| 115 | + (is (= :j (test-ifn "a"))) |
| 116 | + (extend-type string IReversible (-rseq [_] :k)) |
| 117 | + (is (= :k (test-reversible "a"))) |
| 118 | + (extend-type string IIterable (-iterator [_] :l)) |
| 119 | + (is (= :l (test-iterable "a"))) |
| 120 | + (extend-type string ICloneable (-clone [_] :m)) |
| 121 | + (is (= :m (test-cloneable "a"))) |
| 122 | + (extend-type string ICounted (-count [_] :n)) |
| 123 | + (is (= :n (test-counted "a"))) |
| 124 | + (extend-type string IIndexed (-nth [_] :o)) |
| 125 | + (is (= :o (test-indexed "a"))) |
| 126 | + (extend-type number ISeqable (-seq [_] :p)) |
| 127 | + (is (= :p (test-seqable 1))) |
| 128 | + (extend-type string IReduce (-reduce [_ _] :q)) |
| 129 | + (is (= :q (test-reduceable "a")))) |
0 commit comments