mirror of
https://github.com/penpot/penpot.git
synced 2025-01-23 06:58:58 -05:00
🎉 Add tests for pointer map
This commit is contained in:
parent
aa9e125e31
commit
efb0ec46bf
2 changed files with 125 additions and 8 deletions
|
@ -36,13 +36,6 @@
|
|||
(let [obj (dissoc obj id)]
|
||||
(t/is (not (contains? obj id))))))
|
||||
|
||||
(t/testing "dissoc"
|
||||
(let [id (uuid/custom 0 1)
|
||||
obj (-> (omap/create) (assoc id {:foo 1}))]
|
||||
(t/is (contains? obj id))
|
||||
(let [obj (dissoc obj id)]
|
||||
(t/is (not (contains? obj id))))))
|
||||
|
||||
(t/testing "seq"
|
||||
(let [id (uuid/custom 0 1)
|
||||
obj (-> (omap/create) (assoc id 1))]
|
||||
|
@ -52,7 +45,7 @@
|
|||
(t/is (= (key entry) id))
|
||||
(t/is (= (val entry) 1)))))
|
||||
|
||||
(t/testing "const & count"
|
||||
(t/testing "cons & count"
|
||||
(let [obj (into (omap/create) [[uuid/zero 1]])]
|
||||
(t/is (contains? obj uuid/zero))
|
||||
(t/is (= 1 (count obj)))
|
||||
|
|
124
backend/test/app_tests/test_util_pointer_map.clj
Normal file
124
backend/test/app_tests/test_util_pointer_map.clj
Normal file
|
@ -0,0 +1,124 @@
|
|||
;; This Source Code Form is subject to the terms of the Mozilla Public
|
||||
;; License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
;;
|
||||
;; Copyright (c) KALEIDOS INC
|
||||
|
||||
(ns app-tests.test-util-pointer-map
|
||||
(:require
|
||||
[app-tests.test-helpers :as th]
|
||||
[app.common.spec :as us]
|
||||
[app.common.transit :as transit]
|
||||
[app.common.types.shape :as cts]
|
||||
[app.common.uuid :as uuid]
|
||||
[app.util.fressian :as fres]
|
||||
[app.util.pointer-map :as pmap]
|
||||
[clojure.pprint :refer [pprint]]
|
||||
[clojure.spec.alpha :as s]
|
||||
[clojure.test :as t]
|
||||
[clojure.test.check.clojure-test :refer [defspec]]
|
||||
[clojure.test.check.generators :as gen]
|
||||
[clojure.test.check.properties :as props]))
|
||||
|
||||
(t/deftest basic-operations
|
||||
(t/testing "assoc"
|
||||
(let [obj (-> (pmap/create) (assoc :a 1))]
|
||||
(t/is (contains? obj :a))
|
||||
(t/is (not (contains? obj :b)))
|
||||
(t/is (= 1 (count obj)))))
|
||||
|
||||
(t/testing "dissoc"
|
||||
(let [obj (pmap/wrap {:a 1 :b 2})]
|
||||
(t/is (contains? obj :a))
|
||||
(t/is (contains? obj :b))
|
||||
(let [obj (dissoc obj :a)]
|
||||
(t/is (not (contains? obj :a)))
|
||||
(t/is (contains? obj :b)))))
|
||||
|
||||
(t/testing "seq"
|
||||
(let [obj (pmap/wrap {:a 1 :b 2})
|
||||
s1 (first obj)]
|
||||
(t/is (= (key s1) :a))
|
||||
(t/is (= (val s1) 1))))
|
||||
|
||||
(t/testing "cons & count"
|
||||
(let [obj (into (pmap/create) [[:a 1]])]
|
||||
(t/is (contains? obj :a))
|
||||
(t/is (= 1 (count obj)))
|
||||
(t/is (pmap/pointer-map? obj))))
|
||||
|
||||
(t/testing "wrap"
|
||||
(let [obj1 (pmap/wrap {})
|
||||
tmp (pmap/create)
|
||||
obj2 (pmap/wrap tmp)]
|
||||
(t/is (pmap/pointer-map? obj1))
|
||||
(t/is (pmap/pointer-map? obj2))
|
||||
(t/is (identical? tmp obj2))
|
||||
(t/is (= 0 (count obj1)))
|
||||
(t/is (= 0 (count obj2)))))
|
||||
)
|
||||
|
||||
|
||||
(t/deftest internal-tracking
|
||||
(t/testing "simple tracking"
|
||||
(binding [pmap/*tracked* (atom {})]
|
||||
(let [obj (pmap/create)]
|
||||
(t/is (pmap/modified? obj))
|
||||
(t/is (uuid? (pmap/get-id obj)))
|
||||
(t/is (contains? @pmap/*tracked* (pmap/get-id obj)))
|
||||
(t/is (= 1 (count @pmap/*tracked*))))))
|
||||
|
||||
(t/testing "tracking modifying modified"
|
||||
(binding [pmap/*tracked* (atom {})]
|
||||
(let [obj1 (pmap/create)
|
||||
obj2 (assoc obj1 :a 1)]
|
||||
(t/is (pmap/modified? obj1))
|
||||
(t/is (not= obj1 obj2))
|
||||
(t/is (= 0 (count obj1)))
|
||||
(t/is (= 1 (count obj2)))
|
||||
(t/is (uuid? (pmap/get-id obj1)))
|
||||
(t/is (uuid? (pmap/get-id obj2)))
|
||||
(t/is (= (pmap/get-id obj2)
|
||||
(pmap/get-id obj1)))
|
||||
(t/is (= (hash (pmap/get-id obj2))
|
||||
(hash (pmap/get-id obj1))))
|
||||
(t/is (contains? @pmap/*tracked* (pmap/get-id obj2)))
|
||||
(t/is (= 1 (count @pmap/*tracked*))))))
|
||||
|
||||
(t/testing "tracking modifying not modified"
|
||||
(binding [pmap/*tracked* (atom {})
|
||||
pmap/*load-fn* (constantly {})]
|
||||
(let [obj1 (pmap/create uuid/zero {})
|
||||
obj2 (assoc obj1 :a 1)]
|
||||
(t/is (pmap/modified? obj2))
|
||||
(t/is (not (pmap/modified? obj1)))
|
||||
(t/is (not= obj1 obj2))
|
||||
(t/is (= 0 (count obj1)))
|
||||
(t/is (= 1 (count obj2)))
|
||||
(t/is (uuid? (pmap/get-id obj1)))
|
||||
(t/is (uuid? (pmap/get-id obj2)))
|
||||
(t/is (not= (pmap/get-id obj2)
|
||||
(pmap/get-id obj1)))
|
||||
(t/is (not= (hash (pmap/get-id obj2))
|
||||
(hash (pmap/get-id obj1))))
|
||||
(t/is (contains? @pmap/*tracked* (pmap/get-id obj1)))
|
||||
(t/is (contains? @pmap/*tracked* (pmap/get-id obj2)))
|
||||
(t/is (= 2 (count @pmap/*tracked*))))))
|
||||
|
||||
(t/testing "loading"
|
||||
(binding [pmap/*tracked* (atom {})
|
||||
pmap/*load-fn* (constantly {:a 1})]
|
||||
(let [obj1 (pmap/create uuid/zero {})]
|
||||
(t/is (not (pmap/modified? obj1)))
|
||||
(t/is (= 1 (count obj1)))
|
||||
(t/is (= uuid/zero (pmap/get-id obj1)))
|
||||
(t/is (contains? @pmap/*tracked* (pmap/get-id obj1)))
|
||||
(t/is (= 1 (count @pmap/*tracked*)))
|
||||
(t/is (contains? obj1 :a))
|
||||
(t/is (not (contains? obj1 :b)))
|
||||
(t/is (= 1 (get obj1 :a)))
|
||||
(t/is (= nil (get obj1 :b)))
|
||||
(t/is (= ::empty (get obj1 :b ::empty))))))
|
||||
|
||||
)
|
||||
|
Loading…
Add table
Reference in a new issue