|
124 | 124 |
|
125 | 125 | (deftest eval-key-test |
126 | 126 | (testing "eval promise" |
127 | | - (is (match? 3 (applicative/eval-key test-env :c)))) |
| 127 | + (is (match? 3 (applicative/eval-key test-env :c {::applicative/context promesa/context})))) |
128 | 128 | (testing "async works" |
129 | | - (let [[time-ns result] (criterium/time-body (applicative/eval-key test-env+delay :d))] |
| 129 | + (let [[time-ns result] (criterium/time-body (applicative/eval-key test-env+delay :d {::applicative/context promesa/context}))] |
130 | 130 | (is (match? {:a 3 :b 6 :c 9} result)) |
131 | 131 | (is (match? (matchers/within-delta 100000000 1000000000) time-ns)))) |
132 | 132 | (testing "tricky example" |
133 | | - (is (match? 4 (applicative/eval-key tricky-example :z))))) |
| 133 | + (is (match? 4 (applicative/eval-key tricky-example :z {::applicative/context promesa/context}))))) |
134 | 134 |
|
135 | 135 | (deftest eval-key-test-core-async |
136 | 136 | (testing "eval promise" |
|
150 | 150 | (is (match? {:a {::data/value 2} |
151 | 151 | :b {::data/value 1} |
152 | 152 | :c {::data/value 3}} |
153 | | - (applicative/eval test-env :c)))) |
| 153 | + (applicative/eval test-env :c {::applicative/context promesa/context})))) |
154 | 154 | (testing "tricky example" |
155 | 155 | (is (match? {:x (data/value 1) |
156 | 156 | :y (data/value 2) |
|
160 | 160 | :w (data/value 4) |
161 | 161 | :z {::data/type :leaf |
162 | 162 | ::data/inputs #{:w}}} |
163 | | - (applicative/eval tricky-example :w))))) |
| 163 | + (applicative/eval tricky-example :w {::applicative/context promesa/context}))))) |
164 | 164 |
|
165 | 165 | (deftest eval-env-with-sequence |
166 | 166 | (testing "async response is equal to sync response" |
167 | 167 | (is (match? (-> (core/resolve :b env-with-sequence) (get :b) ::data/value) |
168 | | - (applicative/eval-key env-with-sequence :b)))) |
| 168 | + (applicative/eval-key env-with-sequence :b {::applicative/context promesa/context})))) |
169 | 169 | (testing "sync=async for sequence with nil values" |
170 | 170 | (is (match? (-> (core/resolve :b env+sequence-with-nil-values) (get :b) ::data/value) |
171 | | - (applicative/eval-key env+sequence-with-nil-values :b)))) |
| 171 | + (applicative/eval-key env+sequence-with-nil-values :b {::applicative/context promesa/context})))) |
172 | 172 | (testing "sync=async for sequence returning nil values" |
173 | 173 | (is (match? (-> (core/resolve :b env+sequence-returning-nil-values) (get :b) ::data/value) |
174 | | - (applicative/eval-key env+sequence-returning-nil-values :b)))) |
| 174 | + (applicative/eval-key env+sequence-returning-nil-values :b {::applicative/context promesa/context})))) |
175 | 175 | (testing "async version takes a third of the time of sync version |
176 | 176 | (runtime diff is 2 sec, within a tolerance of 3ms" |
177 | 177 | (let [[nanosec-sync _] (criterium/time-body (core/resolve :c env-with-sequence+delay-sync)) |
178 | | - [nanosec-async _] (criterium/time-body (applicative/eval-key env-with-sequence+delay :c))] |
| 178 | + [nanosec-async _] (criterium/time-body (applicative/eval-key env-with-sequence+delay :c {::applicative/context promesa/context}))] |
179 | 179 | (is (match? (matchers/within-delta 8000000 2000000000) |
180 | 180 | (- nanosec-sync nanosec-async))))) |
181 | 181 | (testing "Actually computes the correct answers" |
182 | | - (is (match? [2 3 4] (applicative/eval-key env-with-sequence+delay :c)))) |
| 182 | + (is (match? [2 3 4] (applicative/eval-key env-with-sequence+delay :c {::applicative/context promesa/context})))) |
183 | 183 | (testing "resolve closure sequence" |
184 | 184 | (is (= [2 4 6] |
185 | | - (applicative/eval-key env-with-closure-sequence :y))))) |
| 185 | + (applicative/eval-key env-with-closure-sequence :y {::applicative/context promesa/context}))))) |
186 | 186 |
|
187 | 187 | (deftest schema-test |
188 | 188 | (let [env-with-schema {:a (>value 2) |
|
192 | 192 | :b (>value 1) |
193 | 193 | :c (yielding-schema (>leaf (+ ?a ?b)) s/Bool)}] |
194 | 194 | (testing "it should not fail" |
195 | | - (is (match? 3 (applicative/eval-key env-with-schema :c {::applicative/fvalidate schema/fvalidate})))) |
| 195 | + (is (match? 3 (applicative/eval-key env-with-schema :c {::applicative/context promesa/context |
| 196 | + ::applicative/fvalidate schema/fvalidate})))) |
196 | 197 | (testing "returns ex-info when schema is selected as fvalidate, and schema fn validation is enabled" |
197 | 198 | (is (thrown-match? clojure.lang.ExceptionInfo |
198 | 199 | {:type :schema.core/error |
199 | 200 | :schema java.lang.Boolean |
200 | 201 | :value 3} |
201 | 202 | (ex-data |
202 | 203 | (s/with-fn-validation |
203 | | - (applicative/eval-key env-with-failing-schema :c {::applicative/fvalidate schema/fvalidate})))))) |
| 204 | + (applicative/eval-key env-with-failing-schema :c {::applicative/context promesa/context |
| 205 | + ::applicative/fvalidate schema/fvalidate})))))) |
204 | 206 | (testing "doesn't validate when validation is disabled" |
205 | | - (is (match? 3 (applicative/eval-key env-with-failing-schema :c {::applicative/fvalidate schema/fvalidate})))))) |
| 207 | + (is (match? 3 (applicative/eval-key env-with-failing-schema :c {::applicative/context promesa/context |
| 208 | + ::applicative/fvalidate schema/fvalidate})))))) |
206 | 209 |
|
207 | 210 | (deftest synchronous-applicative-test |
208 | 211 | (let [simple-env {:a (>value 2) |
|
0 commit comments