fix #380 by accounting for vars

This commit is contained in:
Sean Corfield 2022-01-21 13:05:15 -08:00
parent 30209b6cc7
commit 139de6f56c
3 changed files with 9 additions and 3 deletions

View file

@ -1,5 +1,8 @@
# Changes
* 2.2.next in progress
* Fix #380 by correcting test for function type in `register-clause!`.
* 2.2.858 -- 2022-01-20
* Address #377 by adding `honey.sql/map=` to convert a hash map into an equality condition (for a `WHERE` clause).
* Address #351 by adding a `:cache` option to `honey.sql/format` (for Clojure only, not ClojureScript).

View file

@ -1466,7 +1466,7 @@
f (if (keyword? k)
(get @clause-format k)
formatter)]
(when-not (and f (fn? f))
(when-not (and f (or (fn? f) (and (var? f) (fn? (deref f)))) )
(throw (ex-info "The formatter must be a function or existing clause"
{:type (type formatter)})))
(swap! base-clause-order add-clause-before clause before)
@ -1487,7 +1487,7 @@
f (if (keyword? k)
(get @special-syntax k)
formatter)]
(when-not (and f (fn? f))
(when-not (and f (or (fn? f) (and (var? f) (fn? (deref f)))))
(throw (ex-info "The formatter must be a function or existing fn name"
{:type (type formatter)})))
(swap! special-syntax assoc function f))))

View file

@ -722,7 +722,6 @@ ORDER BY id = ? DESC
(is (:disallowed (ex-data e))))))))
;; should not produce: ["SELECT foo, bar FROM mytable ORDER BY foo; select * from users"]
(deftest issue-319-test
(testing "that registering a clause is idempotent"
(is (= ["FOO"]
@ -731,6 +730,10 @@ ORDER BY id = ? DESC
(sut/register-clause! :foo (constantly ["FOO"]) nil)
(format {:foo []}))))))
(deftest issue-380-test
(testing "that registering a clause by name works"
(is (map? (sut/register-clause! :qualify :having :window)))))
(deftest issue-321-linting
(testing "empty IN is ignored by default"
(is (= ["WHERE x IN ()"]