From 5449c23edef86917aaceb7980e97b68fa6981edd Mon Sep 17 00:00:00 2001 From: Sean Corfield Date: Fri, 25 Sep 2020 16:39:50 -0700 Subject: [PATCH] Clarify tests Annotate parameterizer tests as known failures. Create inline versions of :parameterizer :none tests. --- test/honey/sql_test.cljc | 67 ++++++++++++++++++++++++++++++---------- 1 file changed, 51 insertions(+), 16 deletions(-) diff --git a/test/honey/sql_test.cljc b/test/honey/sql_test.cljc index 1dd95ad..24e37c1 100644 --- a/test/honey/sql_test.cljc +++ b/test/honey/sql_test.cljc @@ -231,14 +231,14 @@ ["WITH bar (spam, eggs) AS (VALUES (?, ?), (?, ?), (?, ?)) SELECT foo FROM bar1 UNION ALL SELECT foo FROM bar2" 1 2 3 4 5 6]))) (deftest parameterizer-none - (testing "array parameter" + (testing "array parameter -- fail: parameterizer" (is (= (format {:insert-into :foo :columns [:baz] :values [[[:array [1 2 3 4]]]]} {:parameterizer :none}) ["INSERT INTO foo (baz) VALUES (ARRAY[1, 2, 3, 4])"]))) - (testing "union complex values" + (testing "union complex values -- fail: parameterizer" (is (= (format {:union [{:select [:foo] :from [:bar1]} {:select [:foo] :from [:bar2]}] :with [[[:bar {:columns [:spam :eggs]}] @@ -246,26 +246,61 @@ {:parameterizer :none}) ["WITH bar (spam, eggs) AS (VALUES (1, 2), (3, 4), (5, 6)) SELECT foo FROM bar1 UNION SELECT foo FROM bar2"])))) -(deftest where-and - (testing "should ignore a nil predicate" - (is (= (format {:where [:and [:= :foo "foo"] [:= :bar "bar"] nil]} - {:parameterizer :postgresql}) - ["WHERE (foo = $1 AND bar = $2)" "foo" "bar"])))) +(deftest inline-was-parameterizer-none + (testing "array parameter" + (is (= (format {:insert-into :foo + :columns [:baz] + :values [[[:array (mapv vector + (repeat :inline) + [1 2 3 4])]]]}) + ["INSERT INTO foo (baz) VALUES (ARRAY[1, 2, 3, 4])"]))) + (testing "union complex values" + (is (= (format {:union [{:select [:foo] :from [:bar1]} + {:select [:foo] :from [:bar2]}] + :with [[[:bar {:columns [:spam :eggs]}] + {:values (mapv #(mapv vector (repeat :inline) %) + [[1 2] [3 4] [5 6]])}]]}) + ["WITH bar (spam, eggs) AS (VALUES (1, 2), (3, 4), (5, 6)) SELECT foo FROM bar1 UNION SELECT foo FROM bar2"])))) #_(defmethod parameterize :single-quote [_ value pname] (str \' value \')) #_(defmethod parameterize :mysql-fill [_ value pname] "?") -(deftest customized-parameterizer - (testing "should fill param with single quote" - (is (= (format {:where [:and [:= :foo "foo"] [:= :bar "bar"] nil]} - {:parameterizer :single-quote}) - ["WHERE (foo = 'foo' AND bar = 'bar')" "foo" "bar"]))) +(deftest former-parameterizer-tests-where-and + (testing "should ignore a nil predicate -- fail: postgresql parameterizer" + (is (= (format {:where [:and + [:= :foo "foo"] + [:= :bar "bar"] + nil + [:= :quux "quux"]]} + {:parameterizer :postgresql}) + ["WHERE (foo = ?) AND (bar = $2) AND (quux = $3)" "foo" "bar" "quux"]))) + ;; this is _almost_ what :inline should be doing: + #_(testing "should fill param with single quote" + (is (= (format {:where [:and + [:= :foo "foo"] + [:= :bar "bar"] + nil + [:= :quux "quux"]]} + {:parameterizer :single-quote}) + ["WHERE (foo = 'foo') AND (bar = 'bar') AND (quux = 'quux')" "foo" "bar" "quux"]))) + (testing "should inline params with single quote" + (is (= (format {:where [:and + [:= :foo [:inline "foo"]] + [:= :bar [:inline "bar"]] + nil + [:= :quux [:inline "quux"]]]}) + ["WHERE (foo = 'foo') AND (bar = 'bar') AND (quux = 'quux')"]))) + ;; this is the normal behavior -- not a custom parameterizer! (testing "should fill param with ?" - (is (= (format {:where [:and [:= :foo "foo"] [:= :bar "bar"] nil]} - {:parameterizer :mysql-fill}) - ["WHERE (foo = ? AND bar = ?)" "foo" "bar"])))) - + (is (= (format {:where [:and + [:= :foo "foo"] + [:= :bar "bar"] + nil + [:= :quux "quux"]]} + ;; this never did anything useful: + #_{:parameterizer :mysql-fill}) + ["WHERE (foo = ?) AND (bar = ?) AND (quux = ?)" "foo" "bar" "quux"])))) (deftest set-before-from ; issue 235 (is (=