Adding tests for expected behavior

This commit is contained in:
Andrii V. Mishkovskyi 2015-04-17 12:29:20 +02:00
parent 04f0447c92
commit 7160b4b1ad

View file

@ -24,7 +24,7 @@
;;(merge-where [:not= nil :b.bla]) ;;(merge-where [:not= nil :b.bla])
(group :f.a) (group :f.a)
(having [:< 0 :f.e]) (having [:< 0 :f.e])
(order-by [:b.baz :desc] :c.quux) (order-by [:b.baz :desc] :c.quux [:f.a :nulls-first])
(limit 50) (limit 50)
(offset 10)) (offset 10))
m2 {:select [:f.* :b.baz :c.quux [:b.bla :bla-bla] m2 {:select [:f.* :b.baz :c.quux [:b.bla :bla-bla]
@ -44,7 +44,7 @@
;;:merge-where [:not= nil :b.bla] ;;:merge-where [:not= nil :b.bla]
:group-by :f.a :group-by :f.a
:having [:< 0 :f.e] :having [:< 0 :f.e]
:order-by [[:b.baz :desc] :c.quux] :order-by [[:b.baz :desc] :c.quux [:f.a :nulls-first]]
:limit 50 :limit 50
:offset 10} :offset 10}
m3 (sql/build m2) m3 (sql/build m2)
@ -52,14 +52,14 @@
(testing "Various construction methods are consistent" (testing "Various construction methods are consistent"
(is (= m1 m3 m4))) (is (= m1 m3 m4)))
(testing "SQL data formats correctly" (testing "SQL data formats correctly"
(is (= ["SELECT DISTINCT f.*, b.baz, c.quux, b.bla AS bla_bla, now(), @x := 10 FROM foo f, baz b INNER JOIN draq ON f.b = draq.x LEFT JOIN clod c ON f.a = c.d RIGHT JOIN bock ON bock.z = c.e FULL JOIN beck ON beck.x = c.y WHERE ((f.a = ? AND b.baz <> ?) OR (1 < 2 AND 2 < 3) OR (f.e in (1, ?, 3)) OR f.e BETWEEN 10 AND 20) GROUP BY f.a HAVING 0 < f.e ORDER BY b.baz DESC, c.quux LIMIT 50 OFFSET 10 " (is (= ["SELECT DISTINCT f.*, b.baz, c.quux, b.bla AS bla_bla, now(), @x := 10 FROM foo f, baz b INNER JOIN draq ON f.b = draq.x LEFT JOIN clod c ON f.a = c.d RIGHT JOIN bock ON bock.z = c.e FULL JOIN beck ON beck.x = c.y WHERE ((f.a = ? AND b.baz <> ?) OR (1 < 2 AND 2 < 3) OR (f.e in (1, ?, 3)) OR f.e BETWEEN 10 AND 20) GROUP BY f.a HAVING 0 < f.e ORDER BY b.baz DESC, c.quux, f.a NULLS FIRST LIMIT 50 OFFSET 10 "
"bort" "gabba" 2] "bort" "gabba" 2]
(sql/format m1 {:param1 "gabba" :param2 2})))) (sql/format m1 {:param1 "gabba" :param2 2}))))
(testing "SQL data prints and reads correctly" (testing "SQL data prints and reads correctly"
(is (= m1 (read-string (pr-str m1))))) (is (= m1 (read-string (pr-str m1)))))
(testing "SQL data formats correctly with alternate param naming" (testing "SQL data formats correctly with alternate param naming"
(is (= (sql/format m1 :params {:param1 "gabba" :param2 2} :parameterizer :postgresql) (is (= (sql/format m1 :params {:param1 "gabba" :param2 2} :parameterizer :postgresql)
["SELECT DISTINCT f.*, b.baz, c.quux, b.bla AS bla_bla, now(), @x := 10 FROM foo f, baz b INNER JOIN draq ON f.b = draq.x LEFT JOIN clod c ON f.a = c.d RIGHT JOIN bock ON bock.z = c.e FULL JOIN beck ON beck.x = c.y WHERE ((f.a = $1 AND b.baz <> $2) OR (1 < 2 AND 2 < 3) OR (f.e in (1, $3, 3)) OR f.e BETWEEN 10 AND 20) GROUP BY f.a HAVING 0 < f.e ORDER BY b.baz DESC, c.quux LIMIT 50 OFFSET 10 " ["SELECT DISTINCT f.*, b.baz, c.quux, b.bla AS bla_bla, now(), @x := 10 FROM foo f, baz b INNER JOIN draq ON f.b = draq.x LEFT JOIN clod c ON f.a = c.d RIGHT JOIN bock ON bock.z = c.e FULL JOIN beck ON beck.x = c.y WHERE ((f.a = $1 AND b.baz <> $2) OR (1 < 2 AND 2 < 3) OR (f.e in (1, $3, 3)) OR f.e BETWEEN 10 AND 20) GROUP BY f.a HAVING 0 < f.e ORDER BY b.baz DESC, c.quux, f.a NULLS FIRST LIMIT 50 OFFSET 10 "
"bort" "gabba" 2]))))) "bort" "gabba" 2])))))
(deftest test-cast (deftest test-cast