Skip to content

Commit aacafb2

Browse files
condition: add a test
1 parent 739a0d9 commit aacafb2

File tree

1 file changed

+39
-29
lines changed

1 file changed

+39
-29
lines changed

test/active/clojure/condition_test.cljc

Lines changed: 39 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
(ns active.clojure.condition-test
2-
#?(:clj (:require [clojure.test :refer [deftest is]]
2+
#?(:clj (:require [clojure.test :refer [deftest is testing]]
33
[active.clojure.condition :as c])
4-
:cljs (:require [cljs.test :refer-macros [is deftest]]
4+
:cljs (:require [cljs.test :refer-macros [is deftest testing]]
55
[active.clojure.condition :as c :include-macros true])))
66

77
#?(:cljs
@@ -81,36 +81,46 @@
8181
(c2-b v5))))
8282

8383
(deftest condition-types
84-
(mapv
85-
(fn [[e pred?]]
86-
(is (pred? e))
87-
(try (throw e)
88-
(catch Throwable caught
89-
(is (= e caught)))))
90-
[[(c/make-message-condition "the message") c/message-condition?]
91-
[(c/make-warning) c/warning?]
92-
[(c/make-serious-condition) c/serious-condition?]
93-
[(c/make-error) c/error?]
94-
[(c/make-violation) c/violation?]
95-
[(c/make-assertion-violation) c/assertion-violation?]
96-
[(c/make-irritants-condition ["eins" "zwei"]) c/irritants-condition?]
97-
[(c/make-who-condition "them") c/who-condition?]]))
84+
(testing "condition types are recognized by their respective predicates"
85+
(mapv
86+
(fn [[e pred?]]
87+
(is (pred? e))
88+
(try (throw e)
89+
(catch Throwable caught
90+
(is (= e caught)))))
91+
[[(c/make-message-condition "the message") c/message-condition?]
92+
[(c/make-warning) c/warning?]
93+
[(c/make-serious-condition) c/serious-condition?]
94+
[(c/make-error) c/error?]
95+
[(c/make-violation) c/violation?]
96+
[(c/make-assertion-violation) c/assertion-violation?]
97+
[(c/make-irritants-condition ["eins" "zwei"]) c/irritants-condition?]
98+
[(c/make-who-condition "them") c/who-condition?]])))
9899

99100
(deftest guard-test
100-
(is (= :error
101+
(testing "can guard against conditions"
102+
(is (= :error
103+
(c/guard [con
104+
(c/error? con) :error
105+
(c/violation? con) :violation]
106+
(throw (c/make-error))))))
107+
(testing "unguarded conditions bubble up"
108+
(is (thrown? Throwable
109+
(c/guard [con
110+
(c/error? con) :error]
111+
(throw (c/make-violation))))))
112+
(testing ":else guards against unspecified conditions"
113+
(is (= :something-else
114+
(c/guard [con
115+
(c/violation? con) :violation
116+
:else :something-else]
117+
(throw (c/make-error))))))
118+
(testing "can use the binding in consequent"
119+
(is (c/message-condition?
101120
(c/guard [con
102-
(c/error? con) :error
103-
(c/violation? con) :violation]
104-
(throw (c/make-error)))))
105-
(is (thrown? Throwable
106-
(c/guard [con
107-
(c/error? con) :error]
108-
(throw (c/make-violation)))))
109-
(is (= :something-else
110-
(c/guard [con
111-
(c/violation? con) :violation
112-
:else :something-else]
113-
(throw (c/make-error))))))
121+
(c/message-condition? con) con
122+
:else :something-else]
123+
(throw (c/make-message-condition "the msg")))))))
114124

115125
#?(:clj
116126
(deftest java-throwables

0 commit comments

Comments
 (0)