Compare commits

...

1 Commits

Author SHA1 Message Date
Elena Torro
9c63b831c1 🐛 Support original casing for boolean property values 2025-11-19 12:37:11 +01:00
2 changed files with 29 additions and 11 deletions

View File

@@ -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))))

View File

@@ -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))))