2024-09-22 01:12:10 +00:00
|
|
|
;; copyright (c) 2022-2024 sean corfield, all rights reserved
|
2022-03-26 04:48:00 +00:00
|
|
|
|
2022-04-23 22:40:47 +00:00
|
|
|
(ns honey.sql.pg-ops-test
|
2022-03-26 04:48:00 +00:00
|
|
|
(:require [clojure.test :refer [deftest is testing]]
|
|
|
|
|
[honey.sql :as sql]
|
2022-04-23 22:40:47 +00:00
|
|
|
[honey.sql.pg-ops :as sut]))
|
2022-03-26 04:48:00 +00:00
|
|
|
|
|
|
|
|
(deftest pg-op-tests
|
|
|
|
|
(testing "built-in ops"
|
|
|
|
|
(is (= ["SELECT a || b AS x"]
|
|
|
|
|
(sql/format {:select [[[:|| :a :b] :x]]})))
|
|
|
|
|
(is (= ["SELECT a - b AS x"]
|
|
|
|
|
(sql/format {:select [[[:- :a :b] :x]]}))))
|
|
|
|
|
(testing "writable ops"
|
|
|
|
|
(is (= ["SELECT a -> b AS x"]
|
|
|
|
|
(sql/format {:select [[[:-> :a :b] :x]]})))
|
|
|
|
|
(is (= ["SELECT a ->> b AS x"]
|
|
|
|
|
(sql/format {:select [[[:->> :a :b] :x]]})))
|
|
|
|
|
(is (= ["SELECT a #> b AS x"]
|
|
|
|
|
(sql/format {:select [[[:#> :a :b] :x]]})))
|
|
|
|
|
(is (= ["SELECT a #>> b AS x"]
|
|
|
|
|
(sql/format {:select [[[:#>> :a :b] :x]]})))
|
2024-04-04 16:43:59 +00:00
|
|
|
(is (= ["SELECT a ?? b AS x"]
|
2022-03-26 04:48:00 +00:00
|
|
|
(sql/format {:select [[[:? :a :b] :x]]})))
|
2024-04-04 16:43:59 +00:00
|
|
|
(is (= ["SELECT a ??| b AS x"]
|
2022-03-26 04:48:00 +00:00
|
|
|
(sql/format {:select [[[:?| :a :b] :x]]})))
|
2024-04-04 16:43:59 +00:00
|
|
|
(is (= ["SELECT a ??& b AS x"]
|
2022-03-26 04:48:00 +00:00
|
|
|
(sql/format {:select [[[:?& :a :b] :x]]})))
|
|
|
|
|
(is (= ["SELECT a #- b AS x"]
|
|
|
|
|
(sql/format {:select [[[:#- :a :b] :x]]}))))
|
|
|
|
|
(testing "named ops"
|
|
|
|
|
(is (= ["SELECT a @> b AS x"]
|
|
|
|
|
(sql/format {:select [[[sut/at> :a :b] :x]]})))
|
|
|
|
|
(is (= ["SELECT a <@ b AS x"]
|
|
|
|
|
(sql/format {:select [[[sut/<at :a :b] :x]]})))
|
2024-04-04 16:43:59 +00:00
|
|
|
(is (= ["SELECT a @?? b AS x"]
|
2022-03-26 04:48:00 +00:00
|
|
|
(sql/format {:select [[[sut/at? :a :b] :x]]})))
|
|
|
|
|
(is (= ["SELECT a @@ b AS x"]
|
2022-03-26 15:28:24 +00:00
|
|
|
(sql/format {:select [[[sut/atat :a :b] :x]]}))))
|
|
|
|
|
(testing "variadic ops"
|
|
|
|
|
(is (= ["SELECT a -> b -> c AS x"]
|
2022-03-26 15:33:05 +00:00
|
|
|
(sql/format {:select [[[:-> :a :b :c] :x]]})))
|
|
|
|
|
(is (= ["SELECT a || b || c AS x"]
|
|
|
|
|
(sql/format {:select [[[:|| :a :b :c] :x]]})))))
|