Skip to content

Commit 132ea44

Browse files
committed
Fixed :fn with-condition in the describe function. Added tests.
1 parent 483359f commit 132ea44

File tree

4 files changed

+29
-3
lines changed

4 files changed

+29
-3
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ Versions prior to v0.1.0 are considered experimental, their API may change.
77

88
## [Unreleased]
99

10+
### Fixed
11+
- :fn with-condition in the `describe` function.
12+
Updated the minimap model to reflect that with-condition is valid for the :fn nodes.
1013

1114
## [0.0.6] - 2020-08-09
1215
## [0.0.5] - 2020-08-09

src/minimallist/core.cljc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,9 @@
197197
(defn- -describe
198198
[context model data]
199199
(case (:type model)
200-
:fn {:valid? ((:fn model) data)
200+
:fn {:valid? (and ((:fn model) data)
201+
(implies (contains? model :condition-model)
202+
(:valid? (-describe context (:condition-model model) data))))
201203
:desc data}
202204
:enum {:valid? (contains? (:values model) data)
203205
:desc data}

src/minimallist/minimap.cljc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55
;; A model of the model format accepted by Minimallist's functions.
66
;; Use it to validate your models when you have problems which you don't understand, just in case.
77
(def minimap-model
8-
(h/let ['model (h/alt [:fn (h/map [:type (h/val :fn)]
9-
[:fn (h/fn fn?)])]
8+
(h/let ['model (h/alt [:fn (-> (h/map [:type (h/val :fn)]
9+
[:fn (h/fn fn?)])
10+
(h/with-optional-entries [:condition-model (h/ref 'model)]))]
1011
[:enum (h/map [:type (h/val :enum)]
1112
[:values (h/set-of (h/fn any?))])]
1213
[:and-or (h/map [:type (h/enum #{:and :or})]

test/minimallist/core_test.cljc

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,16 @@
4040
[1]
4141
[2]
4242

43+
(-> (h/fn int?)
44+
(h/with-condition (h/fn odd?)))
45+
[1]
46+
[2]
47+
48+
(-> (h/fn symbol?)
49+
(h/with-condition (h/fn (complement #{'if 'val}))))
50+
['a]
51+
['if]
52+
4353
;; enum
4454
(h/enum #{1 "2" :3})
4555
[1 "2" :3]
@@ -252,6 +262,16 @@
252262
[1 1
253263
2 :invalid]
254264

265+
(-> (h/fn int?)
266+
(h/with-condition (h/fn odd?)))
267+
[1 1
268+
2 :invalid]
269+
270+
(-> (h/fn symbol?)
271+
(h/with-condition (h/fn (complement #{'if 'val}))))
272+
['a 'a
273+
'if :invalid]
274+
255275
;; enum
256276
(h/enum #{1 "2" false nil})
257277
[1 1

0 commit comments

Comments
 (0)