|
47 | 47 | (deftest protocols-test
|
48 | 48 | (testing "protocol fns have useful metadata"
|
49 | 49 | (let [common-meta {:ns (find-ns 'clojure.test-clojure.protocols.examples)
|
50 |
| - :protocol #'ExampleProtocol}] |
51 |
| - (are [m f] (= (merge (quote m) common-meta) |
| 50 | + :protocol #'ExampleProtocol :tag nil}] |
| 51 | + (are [m f] (= (merge common-meta m) |
52 | 52 | (meta (var f)))
|
53 |
| - {:name foo :arglists ([a]) :doc "method with one arg"} foo |
54 |
| - {:name bar :arglists ([a b]) :doc "method with two args"} bar |
55 |
| - {:name baz :arglists ([a] [a b]) :doc "method with multiple arities" :tag String} baz |
56 |
| - {:name with-quux :arglists ([a]) :doc "method name with a hyphen"} with-quux))) |
| 53 | + {:name 'foo :arglists '([a]) :doc "method with one arg"} foo |
| 54 | + {:name 'bar :arglists '([a b]) :doc "method with two args"} bar |
| 55 | + {:name 'baz :arglists '([a] [a b]) :doc "method with multiple arities" :tag 'java.lang.String} baz |
| 56 | + {:name 'with-quux :arglists '([a]) :doc "method name with a hyphen"} with-quux))) |
57 | 57 | (testing "protocol fns throw IllegalArgumentException if no impl matches"
|
58 | 58 | (is (thrown-with-msg?
|
59 | 59 | IllegalArgumentException
|
|
682 | 682 | (reduce-kv #(assoc %1 %3 %2)
|
683 | 683 | {}
|
684 | 684 | (seq {:a 1 :b 2})))))
|
| 685 | + |
| 686 | +(defn aget-long-hinted ^long [x] (aget (longs-hinted x) 0)) |
| 687 | + |
| 688 | +(deftest test-longs-hinted-proto |
| 689 | + (is (= 1 |
| 690 | + (aget-long-hinted |
| 691 | + (reify LongsHintedProto |
| 692 | + (longs-hinted [_] (long-array [1]))))))) |
| 693 | + |
| 694 | +;; CLJ-1180 - resolve type hints in protocol methods |
| 695 | + |
| 696 | +(import 'clojure.lang.ISeq) |
| 697 | +(defprotocol P |
| 698 | + (^ISeq f [_])) |
| 699 | +(ns clojure.test-clojure.protocols.other |
| 700 | + (:use clojure.test)) |
| 701 | +(defn cf [val] |
| 702 | + (let [aseq (clojure.test-clojure.protocols/f val)] |
| 703 | + (count aseq))) |
| 704 | +(extend-protocol clojure.test-clojure.protocols/P String |
| 705 | + (f [s] (seq s))) |
| 706 | +(deftest test-resolve-type-hints-in-protocol-methods |
| 707 | + (is (= 4 (clojure.test-clojure.protocols/f "test")))) |
0 commit comments