diff options
author | Stuart Halloway <stu@thinkrelevance.com> | 2010-04-08 16:41:38 -0400 |
---|---|---|
committer | Stuart Halloway <stu@thinkrelevance.com> | 2010-04-16 15:35:51 -0400 |
commit | 23a424de3cb5131b74932406fb1e554cc3a1ba08 (patch) | |
tree | 3350b5ceec729871317ca07132466a820474714f | |
parent | 211ac9d3aa1bb53de7ca1cc5470e9a5fa2377b64 (diff) |
tests for extenders and satisifies?
Signed-off-by: Stuart Halloway <stu@thinkrelevance.com>
-rw-r--r-- | test/clojure/test_clojure/protocols.clj | 36 |
1 files changed, 35 insertions, 1 deletions
diff --git a/test/clojure/test_clojure/protocols.clj b/test/clojure/test_clojure/protocols.clj index 85abd195..247d8fad 100644 --- a/test/clojure/test_clojure/protocols.clj +++ b/test/clojure/test_clojure/protocols.clj @@ -81,5 +81,39 @@ {:foo identity}) (is (true? (extends? other/SimpleProtocol ::Whatzit))))) +(deftest extenders-test + (reload-example-protocols) + (testing "a fresh protocol has no extenders" + (is (nil? (extenders ExampleProtocol)))) + (testing "extending with no methods doesn't count!" + (deftype Something []) + (extend ::Something ExampleProtocol) + (is (nil? (extenders ExampleProtocol)))) + (testing "extending a protocol (and including an impl) adds an entry to extenders" + (deftype Whatzit []) + (extend ::Whatzit ExampleProtocol {:foo identity}) + (is (= [::Whatzit] (extenders ExampleProtocol))))) + +(deftest satisifies?-test + (reload-example-protocols) + (deftype Whatzit [] + ExampleProtocol) + (let [whatzit (Whatzit)] + (testing "returns nil if a type does not implement the protocol at all" + (is (nil? (satisfies? other/SimpleProtocol whatzit)))) + (testing "returns true if a type implements the protocol directly" + (is (true? (satisfies? ExampleProtocol whatzit)))) + (testing "returns true if a type explicitly extends protocol" + (extend + ::Whatzit + other/SimpleProtocol + {:foo identity}) + (is (true? (satisfies? other/SimpleProtocol whatzit))))) ) + +;; todo ;; what happens if you extend after implementing directly? -;; todo: investigate how nil-handling changes error handling +;; investigate how nil-handling changes error handling +;; extend-type extend-protocol extend-class +;; maybe: find-protocol-impl find-protocol-method +;; deftype, printable forms +;; reify, definterface |