Skip to content

Commit

Permalink
remove duplicate tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ikitommi committed Sep 3, 2023
1 parent b751c1d commit 1d0f512
Showing 1 changed file with 29 additions and 51 deletions.
80 changes: 29 additions & 51 deletions test/malli/core_test.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -292,25 +292,34 @@
(is (= [:and 'int? [:orn [:pos 'pos-int?] [:neg 'neg-int?]]] (m/form schema*))))

(testing "transforming :or"
(testing "first valid transformed branch is used"
(doseq [schema [[:or
[:map [:x keyword?]]
int?
[:map [:y keyword?]]
keyword?]
[:orn
[:äxy [:map [:x keyword?]]]
[:n int?]
[:yxy [:map [:y keyword?]]]
[:kw keyword?]]]]
(are [input result]
(= (m/decode schema input mt/string-transformer) result)

{:x "true", :y "true"} {:x :true, :y "true"}
{:x false, :y "true"} {:x false, :y :true}
{:x false, :y false} {:x false, :y false}
1 1
"kikka" :kikka)))
(let [math (mt/transformer {:name :math})
math-string [:string {:decode/math (partial str "math_")}]
math-kw-string [:and math-string [:any {:decode/math keyword}]]
bono-string [:string {:decode/math (partial str "such_")}]]

(testing "first successful branch is selected"
(is (= "math_1"
(m/decode math-string 1 math)
(m/decode [:and math-string] 1 math)
(m/decode [:or math-string] 1 math)
(m/decode [:or
math-kw-string
math-string
bono-string] 1 math)
(m/decode [:orn ["string" math-string]] 1 math)
(m/decode [:orn
["kw-math" math-kw-string]
["math" math-string]
["bono" bono-string]] 1 math))))

(testing "first branch value is selected as fallback, even if invalid"
(is (= :math_1
(m/decode [:or
math-kw-string
:string] 1 math)
(m/decode [:orn
["kw-math" math-kw-string]
["string" :string]] 1 math)))))

(testing "top-level transformations are retained"
(doseq [schema [[:or {:decode/string {:enter (fn [m] (update m :enter #(or % true)))
Expand All @@ -336,38 +345,7 @@
{:x "true", :enter "invalid"} {:x :true, :enter "invalid", :leave true} ;; first (fallback)
{:y "true"} {:y :true, :enter true, :leave true} ;; second
{:y "true", :leave "invalid"} {:y "true", :enter true, :leave "invalid"} ;; no match
{:x "true", :y "true"} {:x :true, :y "true", :enter true, :leave true}))) ;; first (fallback))

(testing "branch short-circuit"

(let [math (mt/transformer {:name :math})
math-string [:string {:decode/math (partial str "math_")}]
math-kw-string [:and math-string [:any {:decode/math keyword}]]
bono-string [:string {:decode/math (partial str "such_")}]]

(testing "first successful branch is selected"
(is (= "math_1"
(m/decode math-string 1 math)
(m/decode [:and math-string] 1 math)
(m/decode [:or math-string] 1 math)
(m/decode [:or
math-kw-string
math-string
bono-string] 1 math)
(m/decode [:orn ["string" math-string]] 1 math)
(m/decode [:orn
["kw-math" math-kw-string]
["math" math-string]
["bono" bono-string]] 1 math))))

(testing "first branch is selected, even if invalid"
(is (= :math_1
(m/decode [:or
math-kw-string
:string] 1 math)
(m/decode [:orn
["kw-math" math-kw-string]
["string" :string]] 1 math)))))))
{:x "true", :y "true"} {:x :true, :y "true", :enter true, :leave true})))) ;; first (fallback))

(testing "explain with branches"
(let [schema [:and pos-int? neg-int?]]
Expand Down

0 comments on commit 1d0f512

Please sign in to comment.