summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStuart Halloway <stu@thinkrelevance.com>2010-04-09 10:15:16 -0400
committerStuart Halloway <stu@thinkrelevance.com>2010-04-16 15:35:51 -0400
commitbfdd7769c2ce08715030535feb30f41056d12e0d (patch)
tree488af30e3e3d864f5b4f215e23b9597472e69b6c
parent23a424de3cb5131b74932406fb1e554cc3a1ba08 (diff)
re-extending
Signed-off-by: Stuart Halloway <stu@thinkrelevance.com>
-rw-r--r--test/clojure/test_clojure/protocols.clj21
1 files changed, 20 insertions, 1 deletions
diff --git a/test/clojure/test_clojure/protocols.clj b/test/clojure/test_clojure/protocols.clj
index 247d8fad..bfb680ea 100644
--- a/test/clojure/test_clojure/protocols.clj
+++ b/test/clojure/test_clojure/protocols.clj
@@ -110,8 +110,27 @@
{:foo identity})
(is (true? (satisfies? other/SimpleProtocol whatzit))))) )
+(deftest re-extending-test
+ (reload-example-protocols)
+ (deftype Whatzit [])
+ (extend
+ ::Whatzit
+ ExampleProtocol
+ {:foo (fn [_] "first foo")
+ :baz (fn [_] "first baz")})
+ (testing "if you re-extend, the old implementation is replaced (not merged!)"
+ (extend
+ ::Whatzit
+ ExampleProtocol
+ {:baz (fn [_] "second baz")
+ :bar (fn [_ _] "second bar")})
+ (let [whatzit (Whatzit)]
+ (is (thrown? IllegalArgumentException (foo whatzit)))
+ (is (= "second bar" (bar whatzit nil)))
+ (is (= "second baz" (baz whatzit))))))
+
;; todo
-;; what happens if you extend after implementing directly?
+;; what happens if you extend after implementing directly? Extend is ignored!!
;; investigate how nil-handling changes error handling
;; extend-type extend-protocol extend-class
;; maybe: find-protocol-impl find-protocol-method