Dehyphen improvements fixes #387

This commit is contained in:
Sean Corfield 2022-02-21 19:09:49 -08:00
parent 4bf76920ef
commit 803ff41dc0
3 changed files with 15 additions and 7 deletions

View file

@ -1,6 +1,7 @@
# Changes # Changes
* 2.2.next in progress * 2.2.next in progress
* Address [#387](https://github.com/seancorfield/honeysql/issues/387) by making the function simpler.
* Fix [#385](https://github.com/seancorfield/honeysql/issues/385) by quoting inlined UUIDs. * Fix [#385](https://github.com/seancorfield/honeysql/issues/385) by quoting inlined UUIDs.
* Address [#352](https://github.com/seancorfield/honeysql/issues/352) by treating `:'` as introducing a function name that should be formatted as a SQL entity (respects quoting, dot-splitting, etc). * Address [#352](https://github.com/seancorfield/honeysql/issues/352) by treating `:'` as introducing a function name that should be formatted as a SQL entity (respects quoting, dot-splitting, etc).

View file

@ -155,14 +155,11 @@
:cljs str/upper-case)) :cljs str/upper-case))
(defn- dehyphen (defn- dehyphen
"The loop/recur is because we might need to account for x-y-z in "Replace _embedded_ hyphens with spaces.
a string where the second - won't get replaced because the regex
already matched y. I'm sure there's a more efficent solution!" Hyphens at the start or end of a string should not be touched."
[s] [s]
(loop [s s prev nil] (str/replace s #"(\w)-(\w)" "$1 $2"))
(if (= s prev)
s
(recur (str/replace s #"(\w)-(\w)" "$1 $2") s))))
(defn- namespace-_ (defn- namespace-_
"Return the namespace portion of a symbol, with dashes converted." "Return the namespace portion of a symbol, with dashes converted."

View file

@ -866,3 +866,13 @@ ORDER BY id = ? DESC
(format {:select :foo :from :bar (format {:select :foo :from :bar
:offset 20} :offset 20}
{:dialect :sqlserver}))))) {:dialect :sqlserver})))))
(deftest sql-kw-test
(is (= "FETCH NEXT" (sut/sql-kw :fetch-next)))
(is (= "WHAT IS THIS" (sut/sql-kw :what-is-this)))
(is (= "FEE FIE FOE FUM" (sut/sql-kw :fee-fie-foe-fum)))
(is (= "-WHAT THE-" (sut/sql-kw :-what-the-)))
(is (= "fetch_next" (sut/sql-kw :'fetch-next)))
(is (= "what_is_this" (sut/sql-kw :'what-is-this)))
(is (= "fee_fie_foe_fum" (sut/sql-kw :'fee-fie-foe-fum)))
(is (= "_what_the_" (sut/sql-kw :'-what-the-))))