|
1 | 1 | (ns active.clojure.condition-test
|
2 |
| - #?(:clj (:require [clojure.test :refer [deftest is]] |
| 2 | + #?(:clj (:require [clojure.test :refer [deftest is testing]] |
3 | 3 | [active.clojure.condition :as c])
|
4 |
| - :cljs (:require [cljs.test :refer-macros [is deftest]] |
| 4 | + :cljs (:require [cljs.test :refer-macros [is deftest testing]] |
5 | 5 | [active.clojure.condition :as c :include-macros true])))
|
6 | 6 |
|
7 | 7 | #?(:cljs
|
|
81 | 81 | (c2-b v5))))
|
82 | 82 |
|
83 | 83 | (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?]]))) |
98 | 99 |
|
99 | 100 | (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? |
101 | 120 | (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"))))))) |
114 | 124 |
|
115 | 125 | #?(:clj
|
116 | 126 | (deftest java-throwables
|
|
0 commit comments