From 9567d8ceca4ac9d5fe634fa5c79e63f78bbe772e Mon Sep 17 00:00:00 2001 From: Will Acton Date: Sun, 4 Aug 2024 09:33:02 -0700 Subject: [PATCH] refer clojure.test vars --- test/pyramid/core_test.cljc | 940 +++++++++++++++++------------------ test/pyramid/pull_test.cljc | 196 ++++---- test/pyramid/query_test.cljc | 214 ++++---- 3 files changed, 675 insertions(+), 675 deletions(-) diff --git a/test/pyramid/core_test.cljc b/test/pyramid/core_test.cljc index 404bccc..5f72c2b 100644 --- a/test/pyramid/core_test.cljc +++ b/test/pyramid/core_test.cljc @@ -1,119 +1,119 @@ (ns pyramid.core-test (:require + [clojure.test :refer [deftest is testing]] [pyramid.core :as p] - [pyramid.ident :as ident] - [clojure.test :as t])) - - -(t/deftest normalization - (t/is (= {:person/id {0 {:person/id 0}}} - (p/db [{:person/id 0}])) - "a single entity") - (t/is (= {:person/id {0 {:person/id 0 - :person/name "asdf"} - 1 {:person/id 1 - :person/name "jkl"}}} - (p/db [{:person/id 0 - :person/name "asdf"} - {:person/id 1 - :person/name "jkl"}])) - "multiple entities with attributes") - (t/is (= {:person/id {0 {:person/id 0 + [pyramid.ident :as ident])) + + +(deftest normalization + (is (= {:person/id {0 {:person/id 0}}} + (p/db [{:person/id 0}])) + "a single entity") + (is (= {:person/id {0 {:person/id 0 + :person/name "asdf"} + 1 {:person/id 1 + :person/name "jkl"}}} + (p/db [{:person/id 0 + :person/name "asdf"} + {:person/id 1 + :person/name "jkl"}])) + "multiple entities with attributes") + (is (= {:person/id {0 {:person/id 0 + :person/name "asdf"} + 1 {:person/id 1 + :person/name "jkl"}} + :people [[:person/id 0] + [:person/id 1]]} + (p/db [{:people [{:person/id 0 :person/name "asdf"} - 1 {:person/id 1 - :person/name "jkl"}} - :people [[:person/id 0] - [:person/id 1]]} - (p/db [{:people [{:person/id 0 - :person/name "asdf"} - {:person/id 1 - :person/name "jkl"}]}])) - "nested under a key") - (t/is (= {:person/id {0 {:person/id 0 - :some-data {1 "hello" - 3 "world"}}}} - (p/db [{:person/id 0 - :some-data {1 "hello" - 3 "world"}}])) - "Map with numbers as keys") - (t/is (= {:a/id {1 {:a/id 1 - :b [{:c [:d/id 1]}]}} - :d/id {1 {:d/id 1 - :d/txt "a"}}} - (p/db [{:a/id 1 - :b [{:c {:d/id 1 - :d/txt "a"}}]}])) - "Collections of non-entities still get normalized") - (t/is (= {:person/id {0 {:person/id 0 - :person/name "Bill" - :person/friends [{:person/name "Bob"} - [:person/id 2]]} - 2 {:person/id 2 - :person/name "Alice"}}} - (p/db [{:person/id 0 - :person/name "Bill" - :person/friends [{:person/name "Bob"} - {:person/name "Alice" - :person/id 2}]}])) - "heterogeneous collections") - (t/is (= {:person/id - {123 - {:person/id 123, - :person/name "Will", - :contact {:phone "000-000-0001"}, - :best-friend [:person/id 456], - :friends - [[:person/id 9001] - [:person/id 456] - [:person/id 789] - [:person/id 1000]]}, - 456 - {:person/id 456, - :person/name "Jose", - :account/email "asdf@jkl", - :best-friend [:person/id 123]}, - 9001 #:person{:id 9001, :name "Georgia"}, - 789 #:person{:id 789, :name "Frank"}, - 1000 #:person{:id 1000, :name "Robert"}}} - (p/db [{:person/id 123 - :person/name "Will" - :contact {:phone "000-000-0001"} - :best-friend - {:person/id 456 - :person/name "Jose" - :account/email "asdf@jkl"} - :friends - [{:person/id 9001 - :person/name "Georgia"} - {:person/id 456 - :person/name "Jose"} - {:person/id 789 - :person/name "Frank"} - {:person/id 1000 - :person/name "Robert"}]} + {:person/id 1 + :person/name "jkl"}]}])) + "nested under a key") + (is (= {:person/id {0 {:person/id 0 + :some-data {1 "hello" + 3 "world"}}}} + (p/db [{:person/id 0 + :some-data {1 "hello" + 3 "world"}}])) + "Map with numbers as keys") + (is (= {:a/id {1 {:a/id 1 + :b [{:c [:d/id 1]}]}} + :d/id {1 {:d/id 1 + :d/txt "a"}}} + (p/db [{:a/id 1 + :b [{:c {:d/id 1 + :d/txt "a"}}]}])) + "Collections of non-entities still get normalized") + (is (= {:person/id {0 {:person/id 0 + :person/name "Bill" + :person/friends [{:person/name "Bob"} + [:person/id 2]]} + 2 {:person/id 2 + :person/name "Alice"}}} + (p/db [{:person/id 0 + :person/name "Bill" + :person/friends [{:person/name "Bob"} + {:person/name "Alice" + :person/id 2}]}])) + "heterogeneous collections") + (is (= {:person/id + {123 + {:person/id 123, + :person/name "Will", + :contact {:phone "000-000-0001"}, + :best-friend [:person/id 456], + :friends + [[:person/id 9001] + [:person/id 456] + [:person/id 789] + [:person/id 1000]]}, + 456 + {:person/id 456, + :person/name "Jose", + :account/email "asdf@jkl", + :best-friend [:person/id 123]}, + 9001 #:person{:id 9001, :name "Georgia"}, + 789 #:person{:id 789, :name "Frank"}, + 1000 #:person{:id 1000, :name "Robert"}}} + (p/db [{:person/id 123 + :person/name "Will" + :contact {:phone "000-000-0001"} + :best-friend + {:person/id 456 + :person/name "Jose" + :account/email "asdf@jkl"} + :friends + [{:person/id 9001 + :person/name "Georgia"} {:person/id 456 - :best-friend {:person/id 123}}])) - "refs")) - - -(t/deftest non-entities - (t/is (= {:foo ["bar"]} (p/db [{:foo ["bar"]}]))) - (t/is (= {:person/id {0 {:person/id 0 - :foo ["bar"]}}} - (p/db [{:person/id 0 - :foo ["bar"]}])))) - - -(t/deftest custom-schema - (t/is (= {:color {"red" {:color "red" :hex "#ff0000"}}} - (p/db [{:color "red" :hex "#ff0000"}] - (ident/by-keys :color))) - "ident/by-keys") - (t/is (= {:color {"red" {:color "red" :hex "#ff0000"}}} - (p/db [^{:db/ident :color} - {:color "red" :hex "#ff0000"}])) - "local schema") - (t/testing "complex schema" + :person/name "Jose"} + {:person/id 789 + :person/name "Frank"} + {:person/id 1000 + :person/name "Robert"}]} + {:person/id 456 + :best-friend {:person/id 123}}])) + "refs")) + + +(deftest non-entities + (is (= {:foo ["bar"]} (p/db [{:foo ["bar"]}]))) + (is (= {:person/id {0 {:person/id 0 + :foo ["bar"]}}} + (p/db [{:person/id 0 + :foo ["bar"]}])))) + + +(deftest custom-schema + (is (= {:color {"red" {:color "red" :hex "#ff0000"}}} + (p/db [{:color "red" :hex "#ff0000"}] + (ident/by-keys :color))) + "ident/by-keys") + (is (= {:color {"red" {:color "red" :hex "#ff0000"}}} + (p/db [^{:db/ident :color} + {:color "red" :hex "#ff0000"}])) + "local schema") + (testing "complex schema" (let [db (p/db [{:type "person" :id "1234" :purchases [{:type "item" @@ -126,54 +126,54 @@ (let [{:keys [type id]} entity] (when (and (some? type) (some? id)) [(keyword type "id") id]))))] - (t/is (= {:person/id - {"1234" {:type "person", :id "1234", :purchases [[:item/id "1234"]]}}, - :item/id - {"1234" {:type "item", :id "1234"}, "5678" {:type "item", :id "5678"}}, - :type "foo", - :id "bar"} - db) - "correctly identifies entities") - (t/is (= {[:person/id "1234"] - {:type "person", :id "1234", :purchases [{:type "item", :id "1234"}]}} - (p/pull db [{[:person/id "1234"] [:type :id {:purchases [:type :id]}]}])) - "pull")))) - - -(t/deftest add - (t/is (= {:person/id {0 {:person/id 0}}} - (p/add {} {:person/id 0}))) - (t/is (= {:person/id {0 {:person/id 0 :person/name "Gill"} - 1 {:person/id 1}}} - (p/add - {} - {:person/id 0 :person/name "Alice"} - {:person/id 1} - {:person/id 0 :person/name "Gill"})))) - - -(t/deftest add-report - (t/is (= {:db {:person/id {0 {:person/id 0}}} - :entities #{[:person/id 0]} - :indices #{}} - (p/add-report {} {:person/id 0}))) - (t/is (= {:db {:person/id {0 {:person/id 0 + (is (= {:person/id + {"1234" {:type "person", :id "1234", :purchases [[:item/id "1234"]]}}, + :item/id + {"1234" {:type "item", :id "1234"}, "5678" {:type "item", :id "5678"}}, + :type "foo", + :id "bar"} + db) + "correctly identifies entities") + (is (= {[:person/id "1234"] + {:type "person", :id "1234", :purchases [{:type "item", :id "1234"}]}} + (p/pull db [{[:person/id "1234"] [:type :id {:purchases [:type :id]}]}])) + "pull")))) + + +(deftest add + (is (= {:person/id {0 {:person/id 0}}} + (p/add {} {:person/id 0}))) + (is (= {:person/id {0 {:person/id 0 :person/name "Gill"} + 1 {:person/id 1}}} + (p/add + {} + {:person/id 0 :person/name "Alice"} + {:person/id 1} + {:person/id 0 :person/name "Gill"})))) + + +(deftest add-report + (is (= {:db {:person/id {0 {:person/id 0}}} + :entities #{[:person/id 0]} + :indices #{}} + (p/add-report {} {:person/id 0}))) + (is (= {:db {:person/id {0 {:person/id 0 + :person/name "Gill" + :best-friend [:person/id 1]} + 1 {:person/id 1 + :person/name "Uma"}} + :me [:person/id 0]} + :entities #{[:person/id 0] + [:person/id 1]} + :indices #{:me}} + (p/add-report {} {:me {:person/id 0 :person/name "Gill" - :best-friend [:person/id 1]} - 1 {:person/id 1 - :person/name "Uma"}} - :me [:person/id 0]} - :entities #{[:person/id 0] - [:person/id 1]} - :indices #{:me}} - (p/add-report {} {:me {:person/id 0 - :person/name "Gill" - :best-friend {:person/id 1 - :person/name "Uma"}}}))) - #_(t/is (= {:db {:person/id {0 {:person/id 0 :person/name "Gill"} - 1 {:person/id 1}}} - :entities #{{:person/id 0 :person/name "Gill"} - {:person/id 1}}} + :best-friend {:person/id 1 + :person/name "Uma"}}}))) + #_(is (= {:db {:person/id {0 {:person/id 0 :person/name "Gill"} + 1 {:person/id 1}}} + :entities #{{:person/id 0 :person/name "Gill"} + {:person/id 1}}} (p/add-report {} {:person/id 0} @@ -184,13 +184,13 @@ (defrecord Thing [a b c]) -(t/deftest records - (t/is (= (->Thing "foo" "bar" "baz") - (-> [{:id 0 - :thing (->Thing "foo" "bar" "baz")}] - (p/db) - (get-in [:id 0 :thing])))) - #_(t/is (= (->Thing "foo" "bar" "baz") +(deftest records + (is (= (->Thing "foo" "bar" "baz") + (-> [{:id 0 + :thing (->Thing "foo" "bar" "baz")}] + (p/db) + (get-in [:id 0 :thing])))) + #_(is (= (->Thing "foo" "bar" "baz") (-> [{:id 0 :thing (->Thing "foo" "bar" "baz")}] (p/db) @@ -215,83 +215,83 @@ (p/db [data])) -(t/deftest pull - (t/is (= #:people{:all [{:person/id 0} {:person/id 1}]} - (p/pull db [:people/all])) - "simple key") - (t/is (= {:people/all [{:person/name "Alice" - :person/id 0} - {:person/name "Bob" - :person/id 1}]} - (p/pull db [{:people/all [:person/name :person/id]}])) - "basic join + prop") - (t/is (= #:people{:all [{:person/name "Alice" - :person/id 0 - :best-friend #:person{:name "Bob", :id 1 :age 23}} - #:person{:name "Bob", :id 1}]} - (p/pull db [#:people{:all [:person/name :person/id :best-friend]}])) - "join + prop + join ref lookup") - (t/is (= #:people{:all [{:person/name "Alice" - :person/id 0 - :best-friend #:person{:name "Bob"}} - #:person{:name "Bob", :id 1}]} - (p/pull db [#:people{:all [:person/name - :person/id - {:best-friend [:person/name]}]}])) - "join + prop, ref as prop resolver") - (t/is (= {[:person/id 1] #:person{:id 1, :name "Bob", :age 23}} - (p/pull db [[:person/id 1]])) - "ident acts as ref lookup") - (t/is (= {[:person/id 0] {:person/id 0 - :person/name "Alice" - :person/age 25 - :best-friend {:person/id 1} - :person/favorites #:favorite{:ice-cream "vanilla"}}} - (p/pull db [[:person/id 0]])) - "ident does not resolve nested refs") - (t/is (= {[:person/id 0] #:person{:id 0 - :name "Alice" - :favorites #:favorite{:ice-cream "vanilla"}}} - (p/pull db [{[:person/id 0] [:person/id - :person/name - :person/favorites]}])) - "join on ident") - (t/is (= {:people/all [{:person/name "Alice" - :person/id 0 - :best-friend #:person{:name "Bob", :id 1 :age 23}} - #:person{:name "Bob", :id 1}] - [:person/id 1] #:person{:age 23}} - (p/pull db [{:people/all [:person/name :person/id :best-friend]} - {[:person/id 1] [:person/age]}])) - "multiple joins") - - (t/testing "includes params" - (t/is (= #:people{:all [#:person{:name "Bob", :id 1}]} - (p/pull (-> db - (p/add {'(:people/all {:with "params"}) [[:person/id 1]]})) - '[{(:people/all {:with "params"}) - [:person/name :person/id]}]))) - (t/is (= '{:person/foo {:person/id 1 - :person/name "Bob"}} - (p/pull (-> db - (p/add {'(:person/foo {:person/id 2}) - {:person/id 1}})) - '[{(:person/foo {:person/id 2}) - [:person/name :person/id]}])) - "params that include an entity-looking thing should not be normalized") - (t/is (= {} - (p/pull db '[([:person/id 1] {:with "params"})]))) - (t/is (= {} - (p/pull db '[{(:people/all {:with "params"}) - [:person/name :person/id]}])))) - - (t/testing "union" +(deftest pull + (is (= #:people{:all [{:person/id 0} {:person/id 1}]} + (p/pull db [:people/all])) + "simple key") + (is (= {:people/all [{:person/name "Alice" + :person/id 0} + {:person/name "Bob" + :person/id 1}]} + (p/pull db [{:people/all [:person/name :person/id]}])) + "basic join + prop") + (is (= #:people{:all [{:person/name "Alice" + :person/id 0 + :best-friend #:person{:name "Bob", :id 1 :age 23}} + #:person{:name "Bob", :id 1}]} + (p/pull db [#:people{:all [:person/name :person/id :best-friend]}])) + "join + prop + join ref lookup") + (is (= #:people{:all [{:person/name "Alice" + :person/id 0 + :best-friend #:person{:name "Bob"}} + #:person{:name "Bob", :id 1}]} + (p/pull db [#:people{:all [:person/name + :person/id + {:best-friend [:person/name]}]}])) + "join + prop, ref as prop resolver") + (is (= {[:person/id 1] #:person{:id 1, :name "Bob", :age 23}} + (p/pull db [[:person/id 1]])) + "ident acts as ref lookup") + (is (= {[:person/id 0] {:person/id 0 + :person/name "Alice" + :person/age 25 + :best-friend {:person/id 1} + :person/favorites #:favorite{:ice-cream "vanilla"}}} + (p/pull db [[:person/id 0]])) + "ident does not resolve nested refs") + (is (= {[:person/id 0] #:person{:id 0 + :name "Alice" + :favorites #:favorite{:ice-cream "vanilla"}}} + (p/pull db [{[:person/id 0] [:person/id + :person/name + :person/favorites]}])) + "join on ident") + (is (= {:people/all [{:person/name "Alice" + :person/id 0 + :best-friend #:person{:name "Bob", :id 1 :age 23}} + #:person{:name "Bob", :id 1}] + [:person/id 1] #:person{:age 23}} + (p/pull db [{:people/all [:person/name :person/id :best-friend]} + {[:person/id 1] [:person/age]}])) + "multiple joins") + + (testing "includes params" + (is (= #:people{:all [#:person{:name "Bob", :id 1}]} + (p/pull (-> db + (p/add {'(:people/all {:with "params"}) [[:person/id 1]]})) + '[{(:people/all {:with "params"}) + [:person/name :person/id]}]))) + (is (= '{:person/foo {:person/id 1 + :person/name "Bob"}} + (p/pull (-> db + (p/add {'(:person/foo {:person/id 2}) + {:person/id 1}})) + '[{(:person/foo {:person/id 2}) + [:person/name :person/id]}])) + "params that include an entity-looking thing should not be normalized") + (is (= {} + (p/pull db '[([:person/id 1] {:with "params"})]))) + (is (= {} + (p/pull db '[{(:people/all {:with "params"}) + [:person/name :person/id]}])))) + + (testing "union" (let [data {:foo {:bar/id 2 :asdf 123 :jkl 456 :qux 789}} db (p/db [data]) query [{:foo {:bar/id [:bar/id :asdf :jkl] :baz/id [:baz/id :arst :nei]}}]] - (t/is (= {:foo {:bar/id 2 :asdf 123 :jkl 456}} - (p/pull db query)))) + (is (= {:foo {:bar/id 2 :asdf 123 :jkl 456}} + (p/pull db query)))) (let [data {:chat/entries [{:message/id 0 :message/text "foo" @@ -320,80 +320,80 @@ [:photo/id :photo/url :photo/width :photo/height :chat.entry/timestamp] :asdf/jkl [:asdf/jkl]}}]] - (t/is (= #:chat{:entries [{:message/id 0 - :message/text "foo" - :chat.entry/timestamp "1234"} - {:message/id 1 - :message/text "bar" - :chat.entry/timestamp "1235"} - {:audio/id 0 - :audio/url "audio://asdf.jkl" - :audio/duration 1234 - :chat.entry/timestamp "4567"} - {:photo/id 0 - :photo/url "photo://asdf_10x10.jkl" - :photo/width 10 - :photo/height 10 - :chat.entry/timestamp "7890"}]} - (p/pull db1 query))))) - - (t/testing "not found" - (t/is (= {} (p/pull {} [:foo]))) - (t/is (= {} (p/pull {} [:foo :bar :baz]))) - (t/is (= {} (p/pull {} [:foo {:bar [:asdf]} :baz]))) - - (t/is (= {:foo "bar"} - (p/pull {:foo "bar"} [:foo {:bar [:asdf]} :baz]))) - (t/is (= {:bar {:asdf 123}} - (p/pull - {:bar {:asdf 123}} - [:foo {:bar [:asdf :jkl]} :baz]))) - (t/is (= {:bar {}} - (p/pull - (p/db [{:bar {:bar/id 0}} - {:bar/id 0 - :qwerty 1234}]) - [:foo {:bar [:asdf :jkl]} :baz]))) - (t/is (= {:bar {:asdf "jkl"}} - (p/pull - (p/db [{:bar {:bar/id 0}} - {:bar/id 0 - :asdf "jkl"}]) - [:foo {:bar [:asdf :jkl]} :baz]))) - (t/is (= {:bar {}} - (p/pull - (p/db [{:bar {:bar/id 0}} - {:bar/id 1 - :asdf "jkl"}]) - [:foo {:bar [:asdf :jkl]} :baz]))) - - (t/is (= {:foo [{:bar/id 1 - :bar/name "asdf"} - {:baz/id 1 - :baz/name "jkl"}]} - (p/pull - (p/db [{:foo [{:bar/id 1 - :bar/name "asdf"} - {:baz/id 1 - :baz/name "jkl"}]}]) - [{:foo {:bar/id [:bar/id :bar/name] - :baz/id [:baz/id :baz/name]}}]))) - - (t/is (= {:foo [{:bar/id 1 - :bar/name "asdf"} - {:bar/id 2} - {:baz/id 1 - :baz/name "jkl"}]} - (p/pull - (p/db [{:foo [{:bar/id 1 - :bar/name "asdf"} - {:bar/id 2} - {:baz/id 1 - :baz/name "jkl"}]}]) - [{:foo {:bar/id [:bar/id :bar/name] - :baz/id [:baz/id :baz/name]}}])))) - - (t/testing "bounded recursion" + (is (= #:chat{:entries [{:message/id 0 + :message/text "foo" + :chat.entry/timestamp "1234"} + {:message/id 1 + :message/text "bar" + :chat.entry/timestamp "1235"} + {:audio/id 0 + :audio/url "audio://asdf.jkl" + :audio/duration 1234 + :chat.entry/timestamp "4567"} + {:photo/id 0 + :photo/url "photo://asdf_10x10.jkl" + :photo/width 10 + :photo/height 10 + :chat.entry/timestamp "7890"}]} + (p/pull db1 query))))) + + (testing "not found" + (is (= {} (p/pull {} [:foo]))) + (is (= {} (p/pull {} [:foo :bar :baz]))) + (is (= {} (p/pull {} [:foo {:bar [:asdf]} :baz]))) + + (is (= {:foo "bar"} + (p/pull {:foo "bar"} [:foo {:bar [:asdf]} :baz]))) + (is (= {:bar {:asdf 123}} + (p/pull + {:bar {:asdf 123}} + [:foo {:bar [:asdf :jkl]} :baz]))) + (is (= {:bar {}} + (p/pull + (p/db [{:bar {:bar/id 0}} + {:bar/id 0 + :qwerty 1234}]) + [:foo {:bar [:asdf :jkl]} :baz]))) + (is (= {:bar {:asdf "jkl"}} + (p/pull + (p/db [{:bar {:bar/id 0}} + {:bar/id 0 + :asdf "jkl"}]) + [:foo {:bar [:asdf :jkl]} :baz]))) + (is (= {:bar {}} + (p/pull + (p/db [{:bar {:bar/id 0}} + {:bar/id 1 + :asdf "jkl"}]) + [:foo {:bar [:asdf :jkl]} :baz]))) + + (is (= {:foo [{:bar/id 1 + :bar/name "asdf"} + {:baz/id 1 + :baz/name "jkl"}]} + (p/pull + (p/db [{:foo [{:bar/id 1 + :bar/name "asdf"} + {:baz/id 1 + :baz/name "jkl"}]}]) + [{:foo {:bar/id [:bar/id :bar/name] + :baz/id [:baz/id :baz/name]}}]))) + + (is (= {:foo [{:bar/id 1 + :bar/name "asdf"} + {:bar/id 2} + {:baz/id 1 + :baz/name "jkl"}]} + (p/pull + (p/db [{:foo [{:bar/id 1 + :bar/name "asdf"} + {:bar/id 2} + {:baz/id 1 + :baz/name "jkl"}]}]) + [{:foo {:bar/id [:bar/id :bar/name] + :baz/id [:baz/id :baz/name]}}])))) + + (testing "bounded recursion" (let [data {:entries {:entry/id "foo" :entry/folders @@ -407,62 +407,62 @@ :entry/folders [{:entry/id "uiop"}]}]}]}} db (p/db [data])] - (t/is (= {:entries - {:entry/id "foo" + (is (= {:entries + {:entry/id "foo" + :entry/folders + []}} + (p/pull db '[{:entries [:entry/id + {:entry/folders 0}]}]))) + (is (= {:entries + {:entry/id "foo" + :entry/folders + [{:entry/id "bar"} + {:entry/id "baz" + :entry/folders []}]}} + (p/pull db '[{:entries [:entry/id + {:entry/folders 1}]}]))) + (is (= {:entries + {:entry/id "foo" + :entry/folders + [{:entry/id "bar"} + {:entry/id "baz" :entry/folders - []}} - (p/pull db '[{:entries [:entry/id - {:entry/folders 0}]}]))) - (t/is (= {:entries - {:entry/id "foo" - :entry/folders - [{:entry/id "bar"} - {:entry/id "baz" - :entry/folders []}]}} - (p/pull db '[{:entries [:entry/id - {:entry/folders 1}]}]))) - (t/is (= {:entries - {:entry/id "foo" + [{:entry/id "asdf" + :entry/folders []} + {:entry/id "jkl" + :entry/folders []}]}]}} + (p/pull db '[{:entries [:entry/id + {:entry/folders 2}]}]))) + (is (= {:entries + {:entry/id "foo" + :entry/folders + [{:entry/id "bar"} + {:entry/id "baz" :entry/folders - [{:entry/id "bar"} - {:entry/id "baz" + [{:entry/id "asdf" :entry/folders - [{:entry/id "asdf" - :entry/folders []} - {:entry/id "jkl" - :entry/folders []}]}]}} - (p/pull db '[{:entries [:entry/id - {:entry/folders 2}]}]))) - (t/is (= {:entries - {:entry/id "foo" - :entry/folders - [{:entry/id "bar"} - {:entry/id "baz" + [{:entry/id "qwerty"}]} + {:entry/id "jkl" :entry/folders - [{:entry/id "asdf" - :entry/folders - [{:entry/id "qwerty"}]} - {:entry/id "jkl" - :entry/folders - [{:entry/id "uiop"}]}]}]}} - (p/pull db '[{:entries [:entry/id - {:entry/folders 3}]}]))) - (t/is (= {:entries - {:entry/id "foo" + [{:entry/id "uiop"}]}]}]}} + (p/pull db '[{:entries [:entry/id + {:entry/folders 3}]}]))) + (is (= {:entries + {:entry/id "foo" + :entry/folders + [{:entry/id "bar"} + {:entry/id "baz" :entry/folders - [{:entry/id "bar"} - {:entry/id "baz" + [{:entry/id "asdf" :entry/folders - [{:entry/id "asdf" - :entry/folders - [{:entry/id "qwerty"}]} - {:entry/id "jkl" - :entry/folders - [{:entry/id "uiop"}]}]}]}} - (p/pull db '[{:entries [:entry/id - {:entry/folders 10}]}]))))) + [{:entry/id "qwerty"}]} + {:entry/id "jkl" + :entry/folders + [{:entry/id "uiop"}]}]}]}} + (p/pull db '[{:entries [:entry/id + {:entry/folders 10}]}]))))) - (t/testing "infinite recursion" + (testing "infinite recursion" (let [data {:entries {:entry/id "foo" :entry/folders @@ -476,22 +476,22 @@ :entry/folders [{:entry/id "uiop"}]}]}]}} db (p/db [data])] - (t/is (= data - (p/pull db '[{:entries [:entry/id - {:entry/folders ...}]}]))))) - - (t/testing "query metadata" - (t/is (-> db - (p/pull ^:foo []) - (meta) - (:foo)) - "root") - (t/is (-> db - (p/pull [^:foo {[:person/id 0] [:person/name]}]) - (get [:person/id 0]) - (meta) - (:foo)) - "join") + (is (= data + (p/pull db '[{:entries [:entry/id + {:entry/folders ...}]}]))))) + + (testing "query metadata" + (is (-> db + (p/pull ^:foo []) + (meta) + (:foo)) + "root") + (is (-> db + (p/pull [^:foo {[:person/id 0] [:person/name]}]) + (get [:person/id 0]) + (meta) + (:foo)) + "join") (let [data {:chat/entries [{:message/id 0 :message/text "foo" @@ -522,98 +522,98 @@ :asdf/jkl [:asdf/jkl]}}] result (p/pull db1 query)] - (t/is (= #:chat{:entries [{:message/id 0 - :message/text "foo" - :chat.entry/timestamp "1234"} - {:message/id 1 - :message/text "bar" - :chat.entry/timestamp "1235"} - {:audio/id 0 - :audio/url "audio://asdf.jkl" - :audio/duration 1234 - :chat.entry/timestamp "4567"} - {:photo/id 0 - :photo/url "photo://asdf_10x10.jkl" - :photo/width 10 - :photo/height 10 - :chat.entry/timestamp "7890"}]} - result)) - (t/is (-> result meta :foo)) - (t/is (every? #(:bar (meta %)) (get result :chat/entries))))) - (t/testing "dangling entities" - (t/is (= {[:id 0] {:friends [{:id 1} {:id 2}]}} - (p/pull - {:id {0 {:id 0 :name "asdf" :friends [[:id 1] [:id 2]]} - 1 {:id 1 :name "jkl"}}} - [{[:id 0] [:friends]}])) - "dangling entity shows up in queries that do not select any props") - (t/is (= {[:id 0] {:friends [{:id 1, :name "jkl"} {:id 2}]}} - (p/pull - {:id {0 {:id 0 :name "asdf" :friends [[:id 1] [:id 2]]} - 1 {:id 1 :name "jkl"}}} - [{[:id 0] [{:friends [:id :name]}]}])) - "dangling entity shows up in queries that include ID") - (t/is (= {[:id 0] {:friends [{:name "jkl"}]}} - (p/pull - {:id {0 {:id 0 :name "asdf" :friends [[:id 1] [:id 2]]} - 1 {:id 1 :name "jkl"}}} - [{[:id 0] [{:friends [:name]}]}])) - "dangling entity does not show up in queries that do not include ID"))) - - -(t/deftest pull-report - (t/is (= {:data {:people/all [{:person/name "Alice"} - {:person/name "Bob"}]} - :entities #{[:person/id 0] [:person/id 1]} - :indices #{:people/all}} - (p/pull-report db [{:people/all [:person/name]}])) - "basic join + prop") - (t/is (= {:data #:people{:all [{:person/name "Alice" - :best-friend #:person{:name "Bob", :id 1 :age 23}} - #:person{:name "Bob"}]} - :entities #{[:person/id 0] [:person/id 1]} - :indices #{:people/all}} - (p/pull-report db [#:people{:all [:person/name :best-friend]}])) - "join + prop + join ref lookup") - (t/is (= {:data {[:person/id 1] #:person{:id 1, :name "Bob", :age 23}} - :entities #{[:person/id 1]} - :indices #{}} - (p/pull-report db [[:person/id 1]])) - "ident acts as ref lookup") - (t/is (= {:data {[:person/id 0] {:person/id 0 - :person/name "Alice" - :person/age 25 - :best-friend {:person/id 1} - :person/favorites #:favorite{:ice-cream "vanilla"}}} - :entities #{[:person/id 0]} - :indices #{}} - (p/pull-report db [[:person/id 0]])) - "ident does not resolve nested refs")) - - -(t/deftest delete - (t/is (= {:people/all [[:person/id 0]] - :person/id {0 {:person/id 0 - :person/name "Alice" - :person/age 25 - :person/favorites #:favorite{:ice-cream "vanilla"}}}} - (p/delete db [:person/id 1]))) - (t/is (= (-> {} - (p/delete [:person/id 1]) - (p/add {:person/id 1 :person/name "Alice"})) - {:person/id {1 {:person/id 1 :person/name "Alice"}}}))) - - - -(t/deftest data->query - (t/is (= [:a] - (p/data->query {:a 42}))) - (t/is (= [{:a [:b]}] - (p/data->query {:a {:b 42}}))) - (t/is (= [{:a [:b :c]}] - (p/data->query {:a [{:b 42} {:c :d}]}))) - (t/is (= [{[:a 42] [:b]}] - (p/data->query {[:a 42] {:b 33}})))) + (is (= #:chat{:entries [{:message/id 0 + :message/text "foo" + :chat.entry/timestamp "1234"} + {:message/id 1 + :message/text "bar" + :chat.entry/timestamp "1235"} + {:audio/id 0 + :audio/url "audio://asdf.jkl" + :audio/duration 1234 + :chat.entry/timestamp "4567"} + {:photo/id 0 + :photo/url "photo://asdf_10x10.jkl" + :photo/width 10 + :photo/height 10 + :chat.entry/timestamp "7890"}]} + result)) + (is (-> result meta :foo)) + (is (every? #(:bar (meta %)) (get result :chat/entries))))) + (testing "dangling entities" + (is (= {[:id 0] {:friends [{:id 1} {:id 2}]}} + (p/pull + {:id {0 {:id 0 :name "asdf" :friends [[:id 1] [:id 2]]} + 1 {:id 1 :name "jkl"}}} + [{[:id 0] [:friends]}])) + "dangling entity shows up in queries that do not select any props") + (is (= {[:id 0] {:friends [{:id 1, :name "jkl"} {:id 2}]}} + (p/pull + {:id {0 {:id 0 :name "asdf" :friends [[:id 1] [:id 2]]} + 1 {:id 1 :name "jkl"}}} + [{[:id 0] [{:friends [:id :name]}]}])) + "dangling entity shows up in queries that include ID") + (is (= {[:id 0] {:friends [{:name "jkl"}]}} + (p/pull + {:id {0 {:id 0 :name "asdf" :friends [[:id 1] [:id 2]]} + 1 {:id 1 :name "jkl"}}} + [{[:id 0] [{:friends [:name]}]}])) + "dangling entity does not show up in queries that do not include ID"))) + + +(deftest pull-report + (is (= {:data {:people/all [{:person/name "Alice"} + {:person/name "Bob"}]} + :entities #{[:person/id 0] [:person/id 1]} + :indices #{:people/all}} + (p/pull-report db [{:people/all [:person/name]}])) + "basic join + prop") + (is (= {:data #:people{:all [{:person/name "Alice" + :best-friend #:person{:name "Bob", :id 1 :age 23}} + #:person{:name "Bob"}]} + :entities #{[:person/id 0] [:person/id 1]} + :indices #{:people/all}} + (p/pull-report db [#:people{:all [:person/name :best-friend]}])) + "join + prop + join ref lookup") + (is (= {:data {[:person/id 1] #:person{:id 1, :name "Bob", :age 23}} + :entities #{[:person/id 1]} + :indices #{}} + (p/pull-report db [[:person/id 1]])) + "ident acts as ref lookup") + (is (= {:data {[:person/id 0] {:person/id 0 + :person/name "Alice" + :person/age 25 + :best-friend {:person/id 1} + :person/favorites #:favorite{:ice-cream "vanilla"}}} + :entities #{[:person/id 0]} + :indices #{}} + (p/pull-report db [[:person/id 0]])) + "ident does not resolve nested refs")) + + +(deftest delete + (is (= {:people/all [[:person/id 0]] + :person/id {0 {:person/id 0 + :person/name "Alice" + :person/age 25 + :person/favorites #:favorite{:ice-cream "vanilla"}}}} + (p/delete db [:person/id 1]))) + (is (= (-> {} + (p/delete [:person/id 1]) + (p/add {:person/id 1 :person/name "Alice"})) + {:person/id {1 {:person/id 1 :person/name "Alice"}}}))) + + + +(deftest data->query + (is (= [:a] + (p/data->query {:a 42}))) + (is (= [{:a [:b]}] + (p/data->query {:a {:b 42}}))) + (is (= [{:a [:b :c]}] + (p/data->query {:a [{:b 42} {:c :d}]}))) + (is (= [{[:a 42] [:b]}] + (p/data->query {[:a 42] {:b 33}})))) (comment - (t/run-tests)) + (clojure.test/run-tests)) diff --git a/test/pyramid/pull_test.cljc b/test/pyramid/pull_test.cljc index 5bd6239..1c58773 100644 --- a/test/pyramid/pull_test.cljc +++ b/test/pyramid/pull_test.cljc @@ -1,6 +1,6 @@ (ns pyramid.pull-test (:require - [clojure.test :as t] + [clojure.test :refer [deftest is testing]] [pyramid.pull :as p])) @@ -9,37 +9,37 @@ [:id i])) -(t/deftest many-entities - (t/is (= (set entities) - (:entities - (trampoline - p/pull-report - {:id (into - {} - (map #(vector - (second %) - (hash-map (first %) (second %)))) - entities) - :all (vec entities)} - [{:all [:id]}]))))) - - -(t/deftest list-order - (t/is (= - '({:thing {:id 1}} {:thing {:id 2}} {:thing {:id 3}}), - (let [db {:id {1 {:id 1} - 2 {:id 2} - 3 {:id 3} - 9 {:id 9 - :my-list '({:thing [:id 1]} - {:thing [:id 2]} - {:thing [:id 3]})}}} - query [{[:id 9] [:id {:my-list [{:thing [:id]}]}]}]] - (-> (trampoline p/pull-report db query) - (get-in [:data [:id 9] :my-list])))))) - - -(t/deftest heterogeneous-colls +(deftest many-entities + (is (= (set entities) + (:entities + (trampoline + p/pull-report + {:id (into + {} + (map #(vector + (second %) + (hash-map (first %) (second %)))) + entities) + :all (vec entities)} + [{:all [:id]}]))))) + + +(deftest list-order + (is (= + '({:thing {:id 1}} {:thing {:id 2}} {:thing {:id 3}}), + (let [db {:id {1 {:id 1} + 2 {:id 2} + 3 {:id 3} + 9 {:id 9 + :my-list '({:thing [:id 1]} + {:thing [:id 2]} + {:thing [:id 3]})}}} + query [{[:id 9] [:id {:my-list [{:thing [:id]}]}]}]] + (-> (trampoline p/pull-report db query) + (get-in [:data [:id 9] :my-list])))))) + + +(deftest heterogeneous-colls (let [db {:person/id {0 {:person/id 0 :person/name "Bill" :person/friends [{:person/name "Bob"} @@ -47,7 +47,7 @@ 2 {:person/id 2 :person/name "Alice"}}} query [{[:person/id 0] [:person/name {:person/friends [:person/name]}]}]] - (t/is + (is (= {[:person/id 0] {:person/name "Bill" :person/friends [{:person/name "Bob"} {:person/name "Alice"}]}} @@ -65,99 +65,99 @@ (deftype Opaque [result]) -(t/deftest visitors - (t/testing "simple join" +(deftest visitors + (testing "simple join" (let [query [{:foo (visit [:bar :baz])}] data {:foo {:bar 123 :baz 456}}] - (t/is (= {:foo (->Visited - [:bar :baz] - {:bar 123 :baz 456})} - (:data (trampoline p/pull-report data query))) - "single item")) + (is (= {:foo (->Visited + [:bar :baz] + {:bar 123 :baz 456})} + (:data (trampoline p/pull-report data query))) + "single item")) (let [query [{:foo (visit [:bar :baz])}] data {:foo [{:bar 123 :baz 456} {:bar 789 :baz "qux"}]}] - (t/is (= {:foo (->Visited - [:bar :baz] - [{:bar 123 :baz 456} {:bar 789 :baz "qux"}])} - (:data (trampoline p/pull-report data query))) - "multiple items"))) - (t/testing "nested join" + (is (= {:foo (->Visited + [:bar :baz] + [{:bar 123 :baz 456} {:bar 789 :baz "qux"}])} + (:data (trampoline p/pull-report data query))) + "multiple items"))) + (testing "nested join" (let [query [{:foo (visit [{:bar [:baz]}])}] data {:foo {:bar {:baz 123}}}] - (t/is (= {:foo (->Visited - [{:bar [:baz]}] - {:bar {:baz 123}})} - (:data (trampoline p/pull-report data query)))))) - (t/testing "nested visitors" + (is (= {:foo (->Visited + [{:bar [:baz]}] + {:bar {:baz 123}})} + (:data (trampoline p/pull-report data query)))))) + (testing "nested visitors" (let [query [{:foo (visit [{:bar (visit [:baz])}])}] data {:foo [{:bar {:baz 123}} {:bar {:baz 456}}]}] - (t/is (= {:foo (->Visited - [{:bar (visit [:baz])}] - [{:bar (->Visited - [:baz] - {:baz 123})} - {:bar (->Visited - [:baz] - {:baz 456})}])} - (:data (trampoline p/pull-report data query)))))) - (t/testing "union" + (is (= {:foo (->Visited + [{:bar (visit [:baz])}] + [{:bar (->Visited + [:baz] + {:baz 123})} + {:bar (->Visited + [:baz] + {:baz 456})}])} + (:data (trampoline p/pull-report data query)))))) + (testing "union" (let [query [{:foo (visit {:bar [:bar :asdf :jkl] :baz [:baz :arst :nei] :qux [:qux :qwfp :luy]})}] data {:foo {:bar 2 :asdf 123 :jkl 456}}] - (t/is (= {:foo (->Visited {:bar [:bar :asdf :jkl] - :baz [:baz :arst :nei] - :qux [:qux :qwfp :luy]} - {:bar 2 :asdf 123 :jkl 456})} - (:data (trampoline p/pull-report data query))) - "whole union in visitor")) + (is (= {:foo (->Visited {:bar [:bar :asdf :jkl] + :baz [:baz :arst :nei] + :qux [:qux :qwfp :luy]} + {:bar 2 :asdf 123 :jkl 456})} + (:data (trampoline p/pull-report data query))) + "whole union in visitor")) (let [query [{:foo {:bar (visit [:bar :asdf :jkl]) :baz (visit [:baz :arst :nei]) :qux [:qux :qwfp :luy]}}] data {:foo {:bar 2 :asdf 123 :jkl 456}}] - (t/is (= {:foo (->Visited [:bar :asdf :jkl] - {:bar 2 :asdf 123 :jkl 456})} - (:data (trampoline p/pull-report data query))) - "single item union entry")) + (is (= {:foo (->Visited [:bar :asdf :jkl] + {:bar 2 :asdf 123 :jkl 456})} + (:data (trampoline p/pull-report data query))) + "single item union entry")) (let [query [{:foo {:bar (visit [:bar :asdf :jkl]) :baz (visit [:baz :arst :nei]) :qux [:qux :qwfp :luy]}}] data {:foo [{:qux 1 :qwfp 123 :luy 456} {:bar 2 :asdf 123 :jkl 456} {:baz 3 :arst 123 :nei 457}]}] - (t/is (= {:foo [{:qux 1 :qwfp 123 :luy 456} - (->Visited [:bar :asdf :jkl] - {:bar 2 :asdf 123 :jkl 456}) - (->Visited [:baz :arst :nei] - {:baz 3 :arst 123 :nei 457})]} - (:data (trampoline p/pull-report data query))) - "vector union entry") - (t/is (= {:foo [{:qux 1 :qwfp 123 :luy 456} - (->Visited [:bar :asdf :jkl] - {:bar 2 :asdf 123 :jkl 456}) - (->Visited [:baz :arst :nei] - {:baz 3 :arst 123 :nei 457})]} - (:data (trampoline p/pull-report (update data :foo seq) query))) - "seq union entry"))) - (t/testing "opaque transform" + (is (= {:foo [{:qux 1 :qwfp 123 :luy 456} + (->Visited [:bar :asdf :jkl] + {:bar 2 :asdf 123 :jkl 456}) + (->Visited [:baz :arst :nei] + {:baz 3 :arst 123 :nei 457})]} + (:data (trampoline p/pull-report data query))) + "vector union entry") + (is (= {:foo [{:qux 1 :qwfp 123 :luy 456} + (->Visited [:bar :asdf :jkl] + {:bar 2 :asdf 123 :jkl 456}) + (->Visited [:baz :arst :nei] + {:baz 3 :arst 123 :nei 457})]} + (:data (trampoline p/pull-report (update data :foo seq) query))) + "seq union entry"))) + (testing "opaque transform" (let [query [{:foo ^{:visitor #(->Opaque %2)} [{:bar ^{:visitor #(->Opaque %2)} [:baz]}]}] data {:foo {:bar {:baz 123}}}] - (t/is (instance? - Opaque - (-> (trampoline p/pull-report data query) - (:data) - (:foo)))) - (t/is (instance? - Opaque - (-> (trampoline p/pull-report data query) - (:data) - (:foo) - (.-result) - (:bar))))))) + (is (instance? + Opaque + (-> (trampoline p/pull-report data query) + (:data) + (:foo)))) + (is (instance? + Opaque + (-> (trampoline p/pull-report data query) + (:data) + (:foo) + (.-result) + (:bar))))))) diff --git a/test/pyramid/query_test.cljc b/test/pyramid/query_test.cljc index 73ebbed..6b2c3ba 100644 --- a/test/pyramid/query_test.cljc +++ b/test/pyramid/query_test.cljc @@ -1,8 +1,8 @@ (ns pyramid.query-test (:require + [clojure.test :refer [deftest is]] [pyramid.core :as core] - [pyramid.query :as p.q :refer [q]] - [clojure.test :as t])) + [pyramid.query :as p.q :refer [q]])) (def db @@ -28,122 +28,122 @@ :asdf "jkl"}) -(t/deftest joins - (t/is (= '([42] [84] [128]) - (q '[:find ?jkl - :where - [?e :person/id "1011"] - [?e :meta ?meta] - [?meta :asdf ^:many ?asdf] - [?asdf :jkl ?jkl]] - db)) - "map entities") +(deftest joins + (is (= '([42] [84] [128]) + (q '[:find ?jkl + :where + [?e :person/id "1011"] + [?e :meta ?meta] + [?meta :asdf ^:many ?asdf] + [?asdf :jkl ?jkl]] + db)) + "map entities") - (t/is (= '(["123"] ["456"] ["789"] ["1011"]) - (q '[:find ?id - :where - [?e :person/id ?id]] - db))) + (is (= '(["123"] ["456"] ["789"] ["1011"]) + (q '[:find ?id + :where + [?e :person/id ?id]] + db))) - (t/is (= '(["123" "foo"] ["456" "bar"] ["789" "baz"]) - (q '[:find ?id ?name - :where - [?e :person/id ?id] - [?e :person/name ?name]] - db))) + (is (= '(["123" "foo"] ["456" "bar"] ["789" "baz"]) + (q '[:find ?id ?name + :where + [?e :person/id ?id] + [?e :person/name ?name]] + db))) - (t/is (= '(["123" "foo" [:person/id "789"]]) - (q '[:find ?id ?name ?friend - :where - [?e :person/id ?id] - [?e :person/name ?name] - [?e :person/best-friend ?friend]] - db))) + (is (= '(["123" "foo" [:person/id "789"]]) + (q '[:find ?id ?name ?friend + :where + [?e :person/id ?id] + [?e :person/name ?name] + [?e :person/best-friend ?friend]] + db))) - (t/is (= '(["foo" "baz"]) - (q '[:find ?name ?friend-name - :where - [?e :person/name ?name] - [?e :person/best-friend ?friend] - [?friend :person/name ?friend-name]] - db))) + (is (= '(["foo" "baz"]) + (q '[:find ?name ?friend-name + :where + [?e :person/name ?name] + [?e :person/best-friend ?friend] + [?friend :person/name ?friend-name]] + db))) - (t/is (= '() - (q '[:find ?id - :where - [?e :person/name "asdf"] - [?e :person/id ?id]] - db)) - "not found") + (is (= '() + (q '[:find ?id + :where + [?e :person/name "asdf"] + [?e :person/id ?id]] + db)) + "not found") - (t/is (= '(["123" "foo"]) - (q '[:find ?id ?name - :in $ ?name - :where - [?e :person/name ?name] - [?e :person/id ?id]] - db - "foo")) - "join on :in") + (is (= '(["123" "foo"]) + (q '[:find ?id ?name + :in $ ?name + :where + [?e :person/name ?name] + [?e :person/id ?id]] + db + "foo")) + "join on :in") - (t/is (= '(["foo" "bar"] - ["foo" "baz"] - ["bar" "foo"] - ["bar" "baz"] - ["baz" "foo"] - ["baz" "bar"]) - (q '[:find ?name ?friend-name - :where - [?e :person/name ?name] - [?e :person/friends ^:many ?friend] - [?friend :person/name ?friend-name]] - db)) - "multiple cardinality value") + (is (= '(["foo" "bar"] + ["foo" "baz"] + ["bar" "foo"] + ["bar" "baz"] + ["baz" "foo"] + ["baz" "bar"]) + (q '[:find ?name ?friend-name + :where + [?e :person/name ?name] + [?e :person/friends ^:many ?friend] + [?friend :person/name ?friend-name]] + db)) + "multiple cardinality value") - (t/is (= '(["123" "foo"] - ["456" "bar"]) - (q '[:find ?id ?name - :in $ ^:many ?name - :where - [?e :person/name ?name] - [?e :person/id ?id]] - db - ["foo" "bar"])) - "multi cardinality join on :in") + (is (= '(["123" "foo"] + ["456" "bar"]) + (q '[:find ?id ?name + :in $ ^:many ?name + :where + [?e :person/name ?name] + [?e :person/id ?id]] + db + ["foo" "bar"])) + "multi cardinality join on :in") - (t/is (= '(["foo" "foo"] - ["foo" "bar"] - ["foo" "baz"] - ["bar" "foo"] - ["bar" "bar"] - ["bar" "baz"] - ["baz" "foo"] - ["baz" "bar"] - ["baz" "baz"]) - (q '[:find ?name1 ?name2 - :where - [?e1 :person/name ?name1] - [?e2 :person/name ?name2]] - db)) - "cross product")) + (is (= '(["foo" "foo"] + ["foo" "bar"] + ["foo" "baz"] + ["bar" "foo"] + ["bar" "bar"] + ["bar" "baz"] + ["baz" "foo"] + ["baz" "bar"] + ["baz" "baz"]) + (q '[:find ?name1 ?name2 + :where + [?e1 :person/name ?name1] + [?e2 :person/name ?name2]] + db)) + "cross product")) -(t/deftest query-map - (t/is (= [[42]] - (q '[:find ?baz - :where - [[:foo] :bar ?bar] - [?bar :baz ?baz]] - {:foo {:bar {:baz 42}}}))) - (t/is (= [[:foo {:bar {:baz {:asdf 42}}}] - [:bar {:baz {:asdf 42}}] - [:baz {:asdf 42}] - [:asdf 42]] - (q '[:find ?a ?v - :where - [?e ?a ?v]] - {:foo {:bar {:baz {:asdf 42}}}}))) - (t/is (= [[{:asdf "jkl"}] [{:asdf "qwerty"}] [{:asdf "uiop"}]] +(deftest query-map + (is (= [[42]] + (q '[:find ?baz + :where + [[:foo] :bar ?bar] + [?bar :baz ?baz]] + {:foo {:bar {:baz 42}}}))) + (is (= [[:foo {:bar {:baz {:asdf 42}}}] + [:bar {:baz {:asdf 42}}] + [:baz {:asdf 42}] + [:asdf 42]] + (q '[:find ?a ?v + :where + [?e ?a ?v]] + {:foo {:bar {:baz {:asdf 42}}}}))) + (is (= [[{:asdf "jkl"}] [{:asdf "qwerty"}] [{:asdf "uiop"}]] (q '[:find ?bar :where [[:foo] :bar ^:many ?bar]