Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

:altn can handle just one child entry when nested in sequence schema #945

Merged
merged 4 commits into from
Sep 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions src/malli/impl/regex.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -214,21 +214,21 @@

;;;; ## Alternation

(defn alt-validator [& ?krs]
(reduce (fn [acc ?kr]
(let [r (entry->regex acc), r* (entry->regex ?kr)]
(defn alt-validator [?kr & ?krs]
(reduce (fn [r ?kr]
(let [r* (entry->regex ?kr)]
(fn [driver regs pos coll k]
(park-validator! driver r* regs pos coll k) ; remember fallback
(park-validator! driver r regs pos coll k))))
?krs))
(entry->regex ?kr) ?krs))

(defn alt-explainer [& ?krs]
(reduce (fn [acc ?kr]
(let [r (entry->regex acc), r* (entry->regex ?kr)]
(defn alt-explainer [?kr & ?krs]
(reduce (fn [r ?kr]
(let [r* (entry->regex ?kr)]
(fn [driver regs pos coll k]
(park-explainer! driver r* regs pos coll k) ; remember fallback
(park-explainer! driver r regs pos coll k))))
?krs))
(entry->regex ?kr) ?krs))

(defn alt-parser [& rs]
(reduce (fn [r r*]
Expand Down Expand Up @@ -261,13 +261,13 @@
:malli.core/invalid)
:malli.core/invalid))))

(defn alt-transformer [& ?krs]
(reduce (fn [acc ?kr]
(let [r (entry->regex acc), r* (entry->regex ?kr)]
(defn alt-transformer [?kr & ?krs]
(reduce (fn [r ?kr]
(let [r* (entry->regex ?kr)]
(fn [driver regs coll* pos coll k]
(park-transformer! driver r* regs coll* pos coll k) ; remember fallback
(park-transformer! driver r regs coll* pos coll k))))
?krs))
(entry->regex ?kr) ?krs))

;;;; ## Option

Expand Down
10 changes: 10 additions & 0 deletions test/malli/core_test.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -2974,3 +2974,13 @@
[:i :int]]
input [1 2 3 4 5 6 7 8 9]]
(is (= input (->> input (m/parse schema) (m/unparse schema)))))))

(deftest -issue-937-test
(testing ":altn can handle just one child entry when nested"
(let [schema [:* [:altn [:a [:= :a]]]]
value [:a]]
(is (= true (m/validate schema value)))
(is (= nil (m/explain schema value)))
(is (= [[:a :a]] (m/parse schema value)))
(is (= value (m/unparse schema (m/parse schema value))))
(is (= value (m/decode schema value nil))))))