mirror of
https://github.com/penpot/penpot.git
synced 2026-01-04 12:28:52 -05:00
Compare commits
1 Commits
develop
...
elenatorro
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9c63b831c1 |
@@ -309,18 +309,22 @@
|
||||
"Transforms a variant-name (its properties values) into a standard name:
|
||||
the real name of the shape joined by the properties values separated by '/'"
|
||||
[variant]
|
||||
(cpn/merge-path-item (:name variant) (str/replace (:variant-name variant) #", " " / ")))
|
||||
(cpn/merge-path-item (str/lower (:name variant)) (str/lower (str/replace (:variant-name variant) #", " " / "))))
|
||||
|
||||
(defn find-boolean-pair
|
||||
"Given a vector, return the map from 'bool-values' that contains both as keys.
|
||||
Returns nil if none match."
|
||||
[v]
|
||||
"Given a vector, return the map from 'bool-values' (case-insensitive) that contains both as keys.
|
||||
Returns nil if none match."
|
||||
[vector]
|
||||
(let [bool-values [{"on" true "off" false}
|
||||
{"yes" true "no" false}
|
||||
{"true" true "false" false}]]
|
||||
(when (= (count v) 2)
|
||||
(some (fn [b]
|
||||
(when (and (contains? b (first v))
|
||||
(contains? b (last v)))
|
||||
b))
|
||||
|
||||
(when (= (count vector) 2)
|
||||
(some (fn [bool-value]
|
||||
(let [v1 (str/lower (first vector))
|
||||
v2 (str/lower (second vector))]
|
||||
(when (and (contains? bool-value v1)
|
||||
(contains? bool-value v2))
|
||||
{(first vector) (bool-value v1)
|
||||
(second vector) (bool-value v2)})))
|
||||
bool-values))))
|
||||
|
||||
@@ -162,10 +162,24 @@
|
||||
|
||||
|
||||
(t/deftest find-boolean-pair
|
||||
(t/testing "find-boolean-pair"
|
||||
(t/testing "find-boolean-pair basic cases"
|
||||
(t/is (= (ctv/find-boolean-pair ["off" "on"]) {"on" true "off" false}))
|
||||
(t/is (= (ctv/find-boolean-pair ["on" "off"]) {"on" true "off" false}))
|
||||
(t/is (= (ctv/find-boolean-pair ["off" "on" "other"]) nil))
|
||||
(t/is (= (ctv/find-boolean-pair ["yes" "no"]) {"yes" true "no" false}))
|
||||
(t/is (= (ctv/find-boolean-pair ["false" "true"]) {"true" true "false" false}))
|
||||
(t/is (= (ctv/find-boolean-pair ["hello" "bye"]) nil))))
|
||||
(t/is (= (ctv/find-boolean-pair ["hello" "bye"]) nil)))
|
||||
|
||||
(t/testing "find-boolean-pair with original casing"
|
||||
(t/is (= (ctv/find-boolean-pair ["tRue" "faLse"]) {"tRue" true "faLse" false}))
|
||||
(t/is (= (ctv/find-boolean-pair ["ON" "OFF"]) {"ON" true "OFF" false}))
|
||||
(t/is (= (ctv/find-boolean-pair ["YeS" "nO"]) {"YeS" true "nO" false})))
|
||||
|
||||
(t/testing "find-boolean-pair with reversed order and mixed case"
|
||||
(t/is (= (ctv/find-boolean-pair ["FaLsE" "TrUe"]) {"TrUe" true "FaLsE" false}))
|
||||
(t/is (= (ctv/find-boolean-pair ["No" "Yes"]) {"Yes" true "No" false})))
|
||||
|
||||
(t/testing "find-boolean-pair with invalid input"
|
||||
(t/is (= (ctv/find-boolean-pair ["yes"]) nil))
|
||||
(t/is (= (ctv/find-boolean-pair ["true" "false" "extra"]) nil))
|
||||
(t/is (= (ctv/find-boolean-pair ["maybe" "nope"]) nil))))
|
||||
|
||||
Reference in New Issue
Block a user