|
119 | 119 | :pokemons
|
120 | 120 | (into #{}))))))
|
121 | 121 |
|
122 |
| - (testing "set manipulation" |
123 |
| - (are [term result] (= (r/run term conn) result) |
124 |
| - (r/set-insert [1 2 3] 3) [1 2 3] |
125 |
| - (r/set-insert [1 2 3] 4) [1 2 3 4] |
126 |
| - (r/set-union [1 2 3] [4 5 6]) [1 2 3 4 5 6] |
127 |
| - (r/set-union [1 2 3] [1 2 4]) [1 2 3 4] |
128 |
| - (r/set-intersection [1 2 3] [1 2 4]) [1 2] |
129 |
| - (r/set-intersection [1 2 3] [4 5 6]) [] |
130 |
| - (r/set-difference [1 2 3] [1 2 4]) [3] |
131 |
| - (r/set-difference [1 2 3] [4 5 6]) [1 2 3])) |
132 |
| - |
133 |
| - (testing "array manipulation" |
134 |
| - (are [term result] (= (r/run term conn) result) |
135 |
| - (r/append [1 2 3] 9) [1 2 3 9] |
136 |
| - (r/prepend [1 2 3] 9) [9 1 2 3] |
137 |
| - (r/difference [1 2 3 1 4 2] [1 2]) [3 4] |
138 |
| - (r/insert-at [1 2 3] 0 9) [9 1 2 3] |
139 |
| - (r/insert-at [1 2 3] 1 9) [1 9 2 3] |
140 |
| - (r/splice-at [1 2 3] 1 [8 9]) [1 8 9 2 3] |
141 |
| - (r/splice-at [1 2 3] 2 [8 9]) [1 2 8 9 3] |
142 |
| - (r/delete-at [1 2 3] 0) [2 3] |
143 |
| - (r/delete-at [1 2 3] 2) [1 2] |
144 |
| - (r/change-at [1 2 3] 0 9) [9 2 3] |
145 |
| - (r/change-at [1 2 3] 1 9) [1 9 3])) |
146 |
| - |
147 | 122 | (testing "selecting data"
|
148 | 123 | (is (= (set (r/run (r/table test-table) conn)) (set pokemons)))
|
149 | 124 | (is (= (r/run (-> (r/table test-table) (r/get 25)) conn) (first pokemons)))
|
|
227 | 202 |
|
228 | 203 | (deftest document-manipulation
|
229 | 204 | (with-open [conn (r/connect :db test-db)]
|
230 |
| - (r/run (-> (r/table test-table) (r/insert pokemons)) conn) |
231 |
| - (is (= {:national_no 25} |
232 |
| - (r/run (-> (r/table test-table) |
233 |
| - (r/get 25) |
234 |
| - (r/without [:type :name])) conn))))) |
| 205 | + (testing "pluck" |
| 206 | + (let [o {:a 1 :y 2} |
| 207 | + a [{:x 1 :y 2} |
| 208 | + {:x 3 :y 4}]] |
| 209 | + (are [term result] (= (r/run term conn) result) |
| 210 | + (r/pluck o :x) (select-keys o [:x]) |
| 211 | + (r/pluck o [:x :y]) (select-keys o [:x :y]) |
| 212 | + (r/pluck a :x) (map #(select-keys % [:x]) a) |
| 213 | + (r/pluck a [:x :y]) (map #(select-keys % [:x :y]) a)))) |
| 214 | + |
| 215 | + (testing "without" |
| 216 | + (r/run (-> (r/table test-table) (r/insert pokemons)) conn) |
| 217 | + (is (= {:national_no 25} |
| 218 | + (r/run (-> (r/table test-table) |
| 219 | + (r/get 25) |
| 220 | + (r/without [:type :name])) conn)))) |
| 221 | + |
| 222 | + (testing "array manipulation" |
| 223 | + (are [term result] (= (r/run term conn) result) |
| 224 | + (r/append [1 2 3] 9) [1 2 3 9] |
| 225 | + (r/prepend [1 2 3] 9) [9 1 2 3] |
| 226 | + (r/difference [1 2 3 1 4 2] [1 2]) [3 4] |
| 227 | + (r/insert-at [1 2 3] 0 9) [9 1 2 3] |
| 228 | + (r/insert-at [1 2 3] 1 9) [1 9 2 3] |
| 229 | + (r/splice-at [1 2 3] 1 [8 9]) [1 8 9 2 3] |
| 230 | + (r/splice-at [1 2 3] 2 [8 9]) [1 2 8 9 3] |
| 231 | + (r/delete-at [1 2 3] 0) [2 3] |
| 232 | + (r/delete-at [1 2 3] 2) [1 2] |
| 233 | + (r/change-at [1 2 3] 0 9) [9 2 3] |
| 234 | + (r/change-at [1 2 3] 1 9) [1 9 3])) |
235 | 235 |
|
236 |
| -(deftest string-manipulating |
| 236 | + (testing "set manipulation" |
| 237 | + (are [term result] (= (r/run term conn) result) |
| 238 | + (r/set-insert [1 2 3] 3) [1 2 3] |
| 239 | + (r/set-insert [1 2 3] 4) [1 2 3 4] |
| 240 | + (r/set-union [1 2 3] [4 5 6]) [1 2 3 4 5 6] |
| 241 | + (r/set-union [1 2 3] [1 2 4]) [1 2 3 4] |
| 242 | + (r/set-intersection [1 2 3] [1 2 4]) [1 2] |
| 243 | + (r/set-intersection [1 2 3] [4 5 6]) [] |
| 244 | + (r/set-difference [1 2 3] [1 2 4]) [3] |
| 245 | + (r/set-difference [1 2 3] [4 5 6]) [1 2 3])) |
| 246 | + |
| 247 | + (testing "has-fields" |
| 248 | + (let [o {:x 1 :y 2} |
| 249 | + a [{:x 1 :y 2} |
| 250 | + {:x 3 :z 4}]] |
| 251 | + (are [term result] (= (r/run term conn) result) |
| 252 | + (r/has-fields o :x) true |
| 253 | + (r/has-fields o :z) false |
| 254 | + (r/has-fields a :x) a |
| 255 | + (r/has-fields a :y) [(first a)]))) |
| 256 | + |
| 257 | + (testing "literal-values" |
| 258 | + (with-open [conn (r/connect)] |
| 259 | + (is (= (r/run (r/object :a 1) conn) {:a 1})) |
| 260 | + (is (= (r/run (r/keys (r/object :a 1)) conn) ["a"])) |
| 261 | + (is (= (r/run (r/values (r/object :a 1)) conn) [1])))))) |
| 262 | + |
| 263 | +(deftest string-manipulation |
237 | 264 | (with-open [conn (r/connect)]
|
238 | 265 | (are [term result] (= (r/run term conn) result)
|
239 | 266 | (r/match "pikachu" "^pika") {:str "pika" :start 0 :groups [] :end 4}
|
|
248 | 275 | (r/uuid "a") "d0333a3b-39b1-5201-b37a-7bfbf6542b5f")
|
249 | 276 | (is (instance? UUID (UUID/fromString (r/run (r/uuid) conn))))))
|
250 | 277 |
|
251 |
| -(deftest literal-values |
252 |
| - (with-open [conn (r/connect)] |
253 |
| - (is (= (r/run (r/object :a 1) conn) {:a 1})) |
254 |
| - (is (= (r/run (r/keys (r/object :a 1)) conn) ["a"])) |
255 |
| - (is (= (r/run (r/values (r/object :a 1)) conn) [1])))) |
256 |
| - |
257 | 278 | (deftest dates-and-times
|
258 | 279 | (with-open [conn (r/connect)]
|
259 | 280 | (is (< (-> (t/interval (r/run (r/now) conn) (t/now))
|
|
0 commit comments