diff --git a/CHANGELOG.md b/CHANGELOG.md index 6b268a3..4b7173c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ # Changes * 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. * 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). diff --git a/src/honey/sql.cljc b/src/honey/sql.cljc index a3441d3..95d4b7d 100644 --- a/src/honey/sql.cljc +++ b/src/honey/sql.cljc @@ -155,14 +155,11 @@ :cljs str/upper-case)) (defn- dehyphen - "The loop/recur is because we might need to account for x-y-z in - a string where the second - won't get replaced because the regex - already matched y. I'm sure there's a more efficent solution!" + "Replace _embedded_ hyphens with spaces. + + Hyphens at the start or end of a string should not be touched." [s] - (loop [s s prev nil] - (if (= s prev) - s - (recur (str/replace s #"(\w)-(\w)" "$1 $2") s)))) + (str/replace s #"(\w)-(\w)" "$1 $2")) (defn- namespace-_ "Return the namespace portion of a symbol, with dashes converted." diff --git a/test/honey/sql_test.cljc b/test/honey/sql_test.cljc index 0abe446..6170cd6 100644 --- a/test/honey/sql_test.cljc +++ b/test/honey/sql_test.cljc @@ -866,3 +866,13 @@ ORDER BY id = ? DESC (format {:select :foo :from :bar :offset 20} {: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-))))