|
| 1 | +(ns xitdb.data-types-test |
| 2 | + (:require |
| 3 | + [clojure.test :refer :all] |
| 4 | + [xitdb.test-utils :as tu :refer [with-db]])) |
| 5 | + |
| 6 | + |
| 7 | +(deftest KeywordsAndStrings |
| 8 | + (testing "Should correctly handle key and string keys and values" |
| 9 | + (with-db [db (tu/test-db)] |
| 10 | + (reset! db {:foo "foo" |
| 11 | + "foo" "more-foo" |
| 12 | + ":foo" :foo}) |
| 13 | + (is (= {:foo "foo" |
| 14 | + "foo" "more-foo" |
| 15 | + ":foo" :foo} @db)) |
| 16 | + (swap! db dissoc "foo" ":foo") |
| 17 | + (is (= {:foo "foo"} @db)) |
| 18 | + (swap! db dissoc :foo) |
| 19 | + (is (= {} @db))))) |
| 20 | + |
| 21 | +(deftest KeywordsAndStringsInSets |
| 22 | + (testing "Should correctly handle keywords and strings in sets" |
| 23 | + (with-db [db (tu/test-db)] |
| 24 | + (reset! db #{:foo "foo" ":foo"}) |
| 25 | + (is (= #{:foo "foo" ":foo"} @db)) |
| 26 | + |
| 27 | + (swap! db conj :bar) |
| 28 | + (is (= #{:foo "foo" ":foo" :bar} @db)) |
| 29 | + |
| 30 | + (swap! db disj :foo ":foo") |
| 31 | + (is (= #{"foo" :bar} @db)) |
| 32 | + |
| 33 | + (swap! db disj "foo") |
| 34 | + (is (= #{:bar} @db))))) |
| 35 | + |
| 36 | +(deftest KeywordsAndStringsInVectors |
| 37 | + (testing "Should correctly handle keywords and strings in vectors" |
| 38 | + (with-db [db (tu/test-db)] |
| 39 | + (reset! db [:foo "foo" ":foo"]) |
| 40 | + (is (= [:foo "foo" ":foo"] @db)) |
| 41 | + |
| 42 | + (swap! db conj :bar) |
| 43 | + (is (= [:foo "foo" ":foo" :bar] @db)) |
| 44 | + |
| 45 | + (swap! db assoc 0 "changed") |
| 46 | + (is (= ["changed" "foo" ":foo" :bar] @db)) |
| 47 | + |
| 48 | + (swap! db #(into [] (remove #{":foo"} %))) |
| 49 | + (is (= ["changed" "foo" :bar] @db))))) |
| 50 | + |
| 51 | +(deftest KeywordsAndStringsInLists |
| 52 | + (testing "Should correctly handle keywords and strings in lists" |
| 53 | + (with-db [db (tu/test-db)] |
| 54 | + (reset! db '(:foo "foo" ":foo")) |
| 55 | + (is (= '(:foo "foo" ":foo") @db)) |
| 56 | + |
| 57 | + (swap! db conj :bar) |
| 58 | + (is (= '(:bar :foo "foo" ":foo") @db))))) |
| 59 | + |
| 60 | +(deftest NilValuesInMaps |
| 61 | + (testing "Should correctly handle nil values and distinguish from missing keys" |
| 62 | + (with-db [db (tu/test-db)] |
| 63 | + ;; Test nil values vs missing keys |
| 64 | + (reset! db {:existing-key nil :other-key "value"}) |
| 65 | + (is (contains? @db :existing-key)) |
| 66 | + (is (= nil (get @db :existing-key))) |
| 67 | + (is (= nil (get @db :missing-key))) |
| 68 | + (is (not (contains? @db :missing-key))) |
| 69 | + |
| 70 | + ;; Test entryAt with nil values |
| 71 | + (is (= [:existing-key nil] (find @db :existing-key))) |
| 72 | + (is (= nil (find @db :missing-key))) |
| 73 | + |
| 74 | + ;; Test nil as a key |
| 75 | + (reset! db {nil "nil-value" :other "other-value"}) |
| 76 | + (is (contains? @db nil)) |
| 77 | + (is (= "nil-value" (get @db nil))) |
| 78 | + (is (= [nil "nil-value"] (find @db nil)))))) |
| 79 | + |
0 commit comments