diff options
author | Stuart Halloway <stu@thinkrelevance.com> | 2010-04-08 16:05:33 -0400 |
---|---|---|
committer | Stuart Halloway <stu@thinkrelevance.com> | 2010-04-16 15:35:50 -0400 |
commit | 211ac9d3aa1bb53de7ca1cc5470e9a5fa2377b64 (patch) | |
tree | 734b2181201ec77ece58a35de480086350f1168f | |
parent | 166b94c666e30c04b6df7cbf95376d1dbee0cbe5 (diff) |
test plus hack to reload a protocol
Signed-off-by: Stuart Halloway <stu@thinkrelevance.com>
-rw-r--r-- | test/clojure/test_clojure/protocols.clj | 27 |
1 files changed, 25 insertions, 2 deletions
diff --git a/test/clojure/test_clojure/protocols.clj b/test/clojure/test_clojure/protocols.clj index 78905af4..85abd195 100644 --- a/test/clojure/test_clojure/protocols.clj +++ b/test/clojure/test_clojure/protocols.clj @@ -12,6 +12,17 @@ (:use clojure.test clojure.test-clojure.protocols.examples) (:require [clojure.test-clojure.protocols.more-examples :as other])) +;; temporary hack until I decide how to cleanly reload protocol +(defn reload-example-protocols + [] + (alter-var-root #'clojure.test-clojure.protocols.examples/ExampleProtocol + assoc :impls {}) + (alter-var-root #'clojure.test-clojure.protocols.more-examples/SimpleProtocol + assoc :impls {}) + (require :reload + 'clojure.test-clojure.protocols.examples + 'clojure.test-clojure.protocols.more-examples)) + (defn method-names "return sorted list of method names on a class" [c] @@ -55,8 +66,20 @@ {:foo (fn [this] (str "widget " (:name this)))}) (is (= "widget z" (foo (Widget "z")))))) - - +(deftest extends?-test + (reload-example-protocols) + (deftype Whatzit [] + ExampleProtocol) + (testing "returns nil if a type does not implement the protocol at all" + (is (nil? (extends? other/SimpleProtocol ::Whatzit)))) + (testing "returns nil if a type implements the protocol directly" ;; TBD false? + (is (nil? (extends? ExampleProtocol ::Whatzit)))) + (testing "returns true if a type explicitly extends protocol" + (extend + ::Whatzit + other/SimpleProtocol + {:foo identity}) + (is (true? (extends? other/SimpleProtocol ::Whatzit))))) ;; what happens if you extend after implementing directly? ;; todo: investigate how nil-handling changes error handling |