Skip to content

Commit

Permalink
Added further tests for marker protocols as defined in CLJ-966
Browse files Browse the repository at this point in the history
Signed-off-by: Stuart Halloway <stu@thinkrelevance.com>
  • Loading branch information
fogus authored and stuarthalloway committed Aug 18, 2012
1 parent 2bc8b1f commit 7a36ea0
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
26 changes: 23 additions & 3 deletions test/clojure/test_clojure/protocols.clj
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,29 @@
(eval '(defprotocol Elusive (new-method [x])))
(is (= :new-method (eval '(new-method (reify Elusive (new-method [x] :new-method))))))
(is (fails-with-cause? IllegalArgumentException #"No method of interface: .*\.Elusive found for function: old-method of protocol: Elusive \(The protocol method may have been defined before and removed\.\)"
(eval '(old-method (reify Elusive (new-method [x] :new-method)))))))
(testing "you can define a marker protocol"
(is (= '() (method-names clojure.test_clojure.protocols.examples.MarkerProtocol)))))
(eval '(old-method (reify Elusive (new-method [x] :new-method))))))))

(deftype HasMarkers []
ExampleProtocol
(foo [this] "foo")
MarkerProtocol
MarkerProtocol2)

(deftype WillGetMarker []
ExampleProtocol
(foo [this] "foo"))

(extend-type WillGetMarker MarkerProtocol)

(deftest marker-tests
(testing "That a marker protocol has no methods"
(is (= '() (method-names clojure.test_clojure.protocols.examples.MarkerProtocol))))
(testing "That types with markers are reportedly satifying them."
(let [hm (HasMarkers.)
wgm (WillGetMarker.)]
(is (satisfies? MarkerProtocol hm))
(is (satisfies? MarkerProtocol2 hm))
(is (satisfies? MarkerProtocol wgm)))))

(deftype ExtendTestWidget [name])
(deftype HasProtocolInline []
Expand Down
2 changes: 2 additions & 0 deletions test/clojure/test_clojure/protocols/examples.clj
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
(defprotocol MarkerProtocol
"a protocol with no methods")

(defprotocol MarkerProtocol2)

(definterface ExampleInterface
(hinted [^int i])
(hinted [^String s]))
Expand Down

0 comments on commit 7a36ea0

Please sign in to comment.