commit
c861756836
2 changed files with 19 additions and 0 deletions
|
|
@ -270,6 +270,13 @@
|
|||
(next-fn (afn structure))
|
||||
))
|
||||
|
||||
(defpath parser [parse-fn unparse-fn]
|
||||
(select* [this structure next-fn]
|
||||
(next-fn (parse-fn structure)))
|
||||
(transform* [this structure next-fn]
|
||||
(unparse-fn (next-fn (parse-fn structure)))
|
||||
))
|
||||
|
||||
(defn selected?
|
||||
"Filters the current value based on whether a selector finds anything.
|
||||
e.g. (selected? :vals ALL even?) keeps the current element only if an
|
||||
|
|
|
|||
|
|
@ -242,6 +242,18 @@
|
|||
(s/transform (s/view afn) identity i)
|
||||
)))
|
||||
|
||||
(defspec parser-test
|
||||
(for-all+
|
||||
[i gen/int
|
||||
afn (gen/elements [inc dec #(* % 2)])
|
||||
bfn (gen/elements [inc dec #(* % 2)])
|
||||
cfn (gen/elements [inc dec #(* % 2)])]
|
||||
(and (= (first (s/select (s/parser afn bfn) i))
|
||||
(afn i))
|
||||
(= (s/transform (s/parser afn bfn) cfn i)
|
||||
(-> i afn cfn bfn))
|
||||
)))
|
||||
|
||||
(deftest selected?-test
|
||||
(is (= [[1 3 5] [2 :a] [7 11 4 2 :a] [10 1 :a] []]
|
||||
(s/setval [s/ALL (s/selected? s/ALL even?) s/END]
|
||||
|
|
|
|||
Loading…
Reference in a new issue