Convert more RCFs to tests
This commit is contained in:
parent
b6d6d2c4f4
commit
1dc0447244
2 changed files with 39 additions and 1 deletions
|
|
@ -249,7 +249,6 @@
|
|||
(reset! default-dialect (get dialects dialect :ansi)))
|
||||
|
||||
(comment
|
||||
format
|
||||
(format-expr [:= :id 1])
|
||||
(format-expr [:+ :id 1])
|
||||
(format-expr [:+ 1 [:+ 1 :quux]])
|
||||
|
|
|
|||
|
|
@ -9,3 +9,42 @@
|
|||
(is (= ["SELECT * FROM `table` WHERE `id` = ?" 1]
|
||||
(#'sut/sql-format {:select [:*] :from [:table] :where [:= :id 1]}
|
||||
{:dialect :mysql}))))
|
||||
|
||||
(deftest expr-tests
|
||||
(is (= ["id = ?" 1]
|
||||
(#'sut/format-expr [:= :id 1])))
|
||||
(is (= ["id + ?" 1]
|
||||
(#'sut/format-expr [:+ :id 1])))
|
||||
(is (= ["? + (? + quux)" 1 1]
|
||||
(#'sut/format-expr [:+ 1 [:+ 1 :quux]])))
|
||||
(is (= ["FOO(BAR(? + G(abc)), F(?, quux))" 2 1]
|
||||
(#'sut/format-expr [:foo [:bar [:+ 2 [:g :abc]]] [:f 1 :quux]])))
|
||||
(is (= ["id"]
|
||||
(#'sut/format-expr :id)))
|
||||
(is (= ["?" 1]
|
||||
(#'sut/format-expr 1)))
|
||||
(is (= ["INTERVAL ? DAYS" 30]
|
||||
(#'sut/format-expr [:interval 30 :days]))))
|
||||
|
||||
(deftest where-test
|
||||
(#'sut/format-where :where [:= :id 1]))
|
||||
|
||||
(deftest general-tests
|
||||
(is (= ["SELECT * FROM \"table\" WHERE \"id\" = ?" 1]
|
||||
(#'sut/sql-format {:select [:*] :from [:table] :where [:= :id 1]} {})))
|
||||
(is (= ["SELECT \"t\".* FROM \"table\" AS \"t\" WHERE \"id\" = ?" 1]
|
||||
(#'sut/sql-format {:select [:t.*] :from [[:table :t]] :where [:= :id 1]} {})))
|
||||
(is (= ["SELECT * FROM \"table\" GROUP BY \"foo\", \"bar\""]
|
||||
(#'sut/sql-format {:select [:*] :from [:table] :group-by [:foo :bar]} {})))
|
||||
(is (= ["SELECT * FROM \"table\" GROUP BY DATE(\"bar\")"]
|
||||
(#'sut/sql-format {:select [:*] :from [:table] :group-by [[:date :bar]]} {})))
|
||||
(is (= ["SELECT * FROM \"table\" ORDER BY \"foo\" DESC, \"bar\" ASC"]
|
||||
(#'sut/sql-format {:select [:*] :from [:table] :order-by [[:foo :desc] :bar]} {})))
|
||||
(is (= ["SELECT * FROM \"table\" ORDER BY DATE(\"expiry\") DESC, \"bar\" ASC"]
|
||||
(#'sut/sql-format {:select [:*] :from [:table] :order-by [[[:date :expiry] :desc] :bar]} {})))
|
||||
(is (= ["SELECT * FROM \"table\" WHERE DATE_ADD(\"expiry\", INTERVAL ? DAYS) < NOW()" 30]
|
||||
(#'sut/sql-format {:select [:*] :from [:table] :where [:< [:date_add :expiry [:interval 30 :days]] [:now]]} {})))
|
||||
(is (= ["SELECT * FROM `table` WHERE `id` = ?" 1]
|
||||
(#'sut/sql-format {:select [:*] :from [:table] :where [:= :id 1]} {:dialect :mysql})))
|
||||
(is (= ["SELECT * FROM \"table\" WHERE \"id\" IN (?,?,?,?)" 1 2 3 4]
|
||||
(#'sut/sql-format {:select [:*] :from [:table] :where [:in :id [1 2 3 4]]} {}))))
|
||||
|
|
|
|||
Loading…
Reference in a new issue