Skip to content

Commit d15cdd3

Browse files
committed
Minor fixes by Claude, add types test
1 parent 5d48edd commit d15cdd3

File tree

3 files changed

+82
-3
lines changed

3 files changed

+82
-3
lines changed

src/xitdb/db.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@
9999
^RandomAccessFile file (.get field core)]
100100
(.close file)))))
101101

102-
(defn read-history [db]
102+
(defn ^ReadArrayList read-history [^Database db]
103103
(ReadArrayList. (-> db .rootCursor)))
104104

105105
(defn history-index [xdb]

src/xitdb/hash_map.clj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@
2929
(operations/map-contains-key? rhm key))
3030

3131
(entryAt [this key]
32-
(let [v (.valAt this key nil)]
33-
(when-not (nil? v)
32+
(when (.containsKey this key)
33+
(let [v (.valAt this key nil)]
3434
(clojure.lang.MapEntry. key v))))
3535

3636
(assoc [this k v]

test/xitdb/data_types_test.clj

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
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

Comments
 (0)