[new] Add value tests for non-comparable types
This commit is contained in:
parent
8d62dc2826
commit
f7bb2824ac
3 changed files with 39 additions and 39 deletions
|
|
@ -37,7 +37,9 @@
|
||||||
"-Xms1024m" "-Xmx2048m"
|
"-Xms1024m" "-Xmx2048m"
|
||||||
"-Dtaoensso.elide-deprecated=true"
|
"-Dtaoensso.elide-deprecated=true"
|
||||||
"-Dtaoensso.nippy.thaw-serializable-allowlist-base=base.1, base.2"
|
"-Dtaoensso.nippy.thaw-serializable-allowlist-base=base.1, base.2"
|
||||||
"-Dtaoensso.nippy.thaw-serializable-allowlist-add=add.1 , add.2"]
|
"-Dtaoensso.nippy.thaw-serializable-allowlist-add=add.1 , add.2"
|
||||||
|
#_"-Dtaoensso.nippy.target-release=320"
|
||||||
|
#_"-Dtaoensso.nippy.target-release=350"]
|
||||||
|
|
||||||
:global-vars
|
:global-vars
|
||||||
{*warn-on-reflection* true
|
{*warn-on-reflection* true
|
||||||
|
|
|
||||||
|
|
@ -197,11 +197,11 @@
|
||||||
15 [:byte-array-md [[:elements {:read 2}]]]
|
15 [:byte-array-md [[:elements {:read 2}]]]
|
||||||
2 [:byte-array-lg [[:elements {:read 4}]]]
|
2 [:byte-array-lg [[:elements {:read 4}]]]
|
||||||
|
|
||||||
108 [:long-array-lg [[:elements {:read 4}]]] ; Added v3.5.0 (YYYY-MM-DD)
|
|
||||||
109 [:int-array-lg [[:elements {:read 4}]]] ; Added v3.5.0 (YYYY-MM-DD)
|
109 [:int-array-lg [[:elements {:read 4}]]] ; Added v3.5.0 (YYYY-MM-DD)
|
||||||
|
108 [:long-array-lg [[:elements {:read 4}]]] ; Added v3.5.0 (YYYY-MM-DD)
|
||||||
|
|
||||||
116 [:double-array-lg [[:elements {:read 4}]]] ; Added v3.5.0 (YYYY-MM-DD)
|
|
||||||
117 [:float-array-lg [[:elements {:read 4}]]] ; Added v3.5.0 (YYYY-MM-DD)
|
117 [:float-array-lg [[:elements {:read 4}]]] ; Added v3.5.0 (YYYY-MM-DD)
|
||||||
|
116 [:double-array-lg [[:elements {:read 4}]]] ; Added v3.5.0 (YYYY-MM-DD)
|
||||||
|
|
||||||
107 [:string-array-lg [[:elements {:read 4}]]] ; Added v3.5.0 (YYYY-MM-DD)
|
107 [:string-array-lg [[:elements {:read 4}]]] ; Added v3.5.0 (YYYY-MM-DD)
|
||||||
115 [:object-array-lg [[:elements {:read 4}]]]
|
115 [:object-array-lg [[:elements {:read 4}]]]
|
||||||
|
|
@ -451,7 +451,7 @@
|
||||||
"A set of common safe class names to allow to be frozen using Java's
|
"A set of common safe class names to allow to be frozen using Java's
|
||||||
`Serializable` interface. PRs welcome for additions.
|
`Serializable` interface. PRs welcome for additions.
|
||||||
See also `*thaw-serializable-allowlist*`."
|
See also `*thaw-serializable-allowlist*`."
|
||||||
#{"[I" "[F" "[Z" "[B" "[C" "[D" "[S" "[J"
|
#{"[Z" "[B" "[S" "[I" "[J" "[F" "[D" "[C"
|
||||||
|
|
||||||
"java.lang.Throwable"
|
"java.lang.Throwable"
|
||||||
"java.lang.Exception"
|
"java.lang.Exception"
|
||||||
|
|
@ -1105,12 +1105,10 @@
|
||||||
(freezer (Class/forName "[Ljava.lang.Object;") nil true (write-array-lg out x (alength ^"[Ljava.lang.Object;" x) id-object-array-lg))
|
(freezer (Class/forName "[Ljava.lang.Object;") nil true (write-array-lg out x (alength ^"[Ljava.lang.Object;" x) id-object-array-lg))
|
||||||
|
|
||||||
(when (impl/target-release>= 350)
|
(when (impl/target-release>= 350)
|
||||||
(freezer (Class/forName "[J") nil true (write-array-lg out x (alength ^"[J" x) id-long-array-lg))
|
|
||||||
(freezer (Class/forName "[I") nil true (write-array-lg out x (alength ^"[I" x) id-int-array-lg))
|
(freezer (Class/forName "[I") nil true (write-array-lg out x (alength ^"[I" x) id-int-array-lg))
|
||||||
|
(freezer (Class/forName "[J") nil true (write-array-lg out x (alength ^"[J" x) id-long-array-lg))
|
||||||
(freezer (Class/forName "[D") nil true (write-array-lg out x (alength ^"[D" x) id-double-array-lg))
|
|
||||||
(freezer (Class/forName "[F") nil true (write-array-lg out x (alength ^"[F" x) id-float-array-lg))
|
(freezer (Class/forName "[F") nil true (write-array-lg out x (alength ^"[F" x) id-float-array-lg))
|
||||||
|
(freezer (Class/forName "[D") nil true (write-array-lg out x (alength ^"[D" x) id-double-array-lg))
|
||||||
(freezer (Class/forName "[Ljava.lang.String;") nil true (write-array-lg out x (alength ^"[Ljava.lang.String;" x) id-string-array-lg)))
|
(freezer (Class/forName "[Ljava.lang.String;") nil true (write-array-lg out x (alength ^"[Ljava.lang.String;" x) id-string-array-lg)))
|
||||||
|
|
||||||
(freezer PersistentQueue nil true (write-counted-coll out id-queue-lg x))
|
(freezer PersistentQueue nil true (write-counted-coll out id-queue-lg x))
|
||||||
|
|
@ -2009,7 +2007,7 @@
|
||||||
[{:keys [comparable?] :as opts}]
|
[{:keys [comparable?] :as opts}]
|
||||||
(let [rng (java.util.Random. 123456) ; Seeded for determinism
|
(let [rng (java.util.Random. 123456) ; Seeded for determinism
|
||||||
rand-nth (fn [coll] (nth coll (.nextInt rng (count coll))))
|
rand-nth (fn [coll] (nth coll (.nextInt rng (count coll))))
|
||||||
all
|
base
|
||||||
{:nil nil
|
{:nil nil
|
||||||
:true true
|
:true true
|
||||||
:false false
|
:false false
|
||||||
|
|
@ -2046,7 +2044,6 @@
|
||||||
#{{1 [:a :b] 2 [:c :d] 3 [:e :f]} [#{{[] ()}}] #{:a :b}}
|
#{{1 [:a :b] 2 [:c :d] 3 [:e :f]} [#{{[] ()}}] #{:a :b}}
|
||||||
[1 [1 2 [1 2 3 [1 2 3 4 [1 2 3 4 5 "ಬಾ ಇಲ್ಲಿ ಸಂಭವಿಸ"] {} #{} [] ()]]]]]
|
[1 [1 2 [1 2 3 [1 2 3 4 [1 2 3 4 5 "ಬಾ ಇಲ್ಲಿ ಸಂಭವಿಸ"] {} #{} [] ()]]]]]
|
||||||
|
|
||||||
:regex #"^(https?:)?//(www\?|\?)?"
|
|
||||||
:sorted-set (sorted-set 1 2 3 4 5)
|
:sorted-set (sorted-set 1 2 3 4 5)
|
||||||
:sorted-map (sorted-map :b 2 :a 1 :d 4 :c 3)
|
:sorted-map (sorted-map :b 2 :a 1 :d 4 :c 3)
|
||||||
:lazy-seq-empty (map identity ())
|
:lazy-seq-empty (map identity ())
|
||||||
|
|
@ -2054,25 +2051,10 @@
|
||||||
:queue (into clojure.lang.PersistentQueue/EMPTY [:a :b :c :d :e :f :g])
|
:queue (into clojure.lang.PersistentQueue/EMPTY [:a :b :c :d :e :f :g])
|
||||||
:queue-empty clojure.lang.PersistentQueue/EMPTY
|
:queue-empty clojure.lang.PersistentQueue/EMPTY
|
||||||
|
|
||||||
:uuid (java.util.UUID. 7232453380187312026 -7067939076204274491)
|
:uuid (java.util.UUID. 7232453380187312026 -7067939076204274491)
|
||||||
:uri (java.net.URI. "https://clojure.org")
|
:uri (java.net.URI. "https://clojure.org")
|
||||||
:defrecord (StressRecord. "data")
|
:defrecord (StressRecord. "data")
|
||||||
:deftype (StressType. "data")
|
:deftype (StressType. "data")
|
||||||
|
|
||||||
:bytes (byte-array [(byte 1) (byte 2) (byte 3)])
|
|
||||||
:objects (object-array [1 "two" {:data "data"}])
|
|
||||||
|
|
||||||
;; TODO (target-release>= 350)
|
|
||||||
;; :byte-array (byte-array [(byte 1) (byte 2) (byte 3) (byte 4)])
|
|
||||||
|
|
||||||
;; :long-array (long-array [1 2 3 4])
|
|
||||||
;; :int-array (int-array [1 2 3 4])
|
|
||||||
|
|
||||||
;; :double-array (double-array [1.5 2.5 3.5 4.5])
|
|
||||||
;; :float-array (float-array [1.5 2.5 3.5 4.5])
|
|
||||||
|
|
||||||
;; :object-array (object-array [1 "two" {:data "data"}])
|
|
||||||
;; :string-array (into-array String ["a" "b" "c"])
|
|
||||||
|
|
||||||
:util-date (java.util.Date. 1577884455500)
|
:util-date (java.util.Date. 1577884455500)
|
||||||
:sql-date (java.sql.Date. 1577884455500)
|
:sql-date (java.sql.Date. 1577884455500)
|
||||||
|
|
@ -2080,10 +2062,6 @@
|
||||||
:duration (enc/compile-if java.time.Duration (java.time.Duration/ofSeconds 100 100) ::skip)
|
:duration (enc/compile-if java.time.Duration (java.time.Duration/ofSeconds 100 100) ::skip)
|
||||||
:period (enc/compile-if java.time.Period (java.time.Period/of 1 1 1) ::skip)
|
:period (enc/compile-if java.time.Period (java.time.Period/of 1 1 1) ::skip)
|
||||||
|
|
||||||
:throwable (Throwable. "Msg")
|
|
||||||
:exception (Exception. "Msg")
|
|
||||||
:ex-info (ex-info "Msg" {:data "data"})
|
|
||||||
|
|
||||||
:many-longs (vec (repeatedly 512 #(rand-nth (range 10))))
|
:many-longs (vec (repeatedly 512 #(rand-nth (range 10))))
|
||||||
:many-doubles (vec (repeatedly 512 #(double (rand-nth (range 10)))))
|
:many-doubles (vec (repeatedly 512 #(double (rand-nth (range 10)))))
|
||||||
:many-strings (vec (repeatedly 512 #(rand-nth ["foo" "bar" "baz" "qux"])))
|
:many-strings (vec (repeatedly 512 #(rand-nth ["foo" "bar" "baz" "qux"])))
|
||||||
|
|
@ -2093,8 +2071,23 @@
|
||||||
(rand-nth ["foo" "bar" "baz" "qux" ]))))}]
|
(rand-nth ["foo" "bar" "baz" "qux" ]))))}]
|
||||||
|
|
||||||
(if comparable?
|
(if comparable?
|
||||||
(dissoc all :bytes :objects :throwable :exception :ex-info :regex)
|
base
|
||||||
(do all))))
|
(assoc base
|
||||||
|
:non-comparable
|
||||||
|
{:regex #"^(https?:)?//(www\?|\?)?"
|
||||||
|
:throwable (Throwable. "Msg")
|
||||||
|
:exception (Exception. "Msg")
|
||||||
|
:ex-info (ex-info "Msg" {:data "data"})
|
||||||
|
:arrays
|
||||||
|
{:boolean (boolean-array (mapv even? (range 32)))
|
||||||
|
:byte (byte-array (mapv byte (range 32)))
|
||||||
|
:short (short-array (mapv short (range 32)))
|
||||||
|
:int (int-array (mapv int (range 32)))
|
||||||
|
:long (long-array (mapv long (range 32)))
|
||||||
|
:float (float-array (mapv float (range 32)))
|
||||||
|
:double (double-array (mapv double (range 32)))
|
||||||
|
:char (char-array (mapv char (range 32)))
|
||||||
|
:object (object-array (mapv vector (range 32)))}}))))
|
||||||
|
|
||||||
(comment
|
(comment
|
||||||
[(= (stress-data {:comparable? true}) (stress-data {:comparable? true}))
|
[(= (stress-data {:comparable? true}) (stress-data {:comparable? true}))
|
||||||
|
|
|
||||||
|
|
@ -54,10 +54,6 @@
|
||||||
#(freeze % {:password [:salted "p"]}))
|
#(freeze % {:password [:salted "p"]}))
|
||||||
test-data)))
|
test-data)))
|
||||||
|
|
||||||
(let [d (nippy/stress-data {})]
|
|
||||||
[(is (= (vec (:bytes d)) ((comp vec thaw freeze) (:bytes d))))
|
|
||||||
(is (= (vec (:objects d)) ((comp vec thaw freeze) (:objects d))))])
|
|
||||||
|
|
||||||
(is (= test-data ((comp #(thaw % {:compressor nippy/lzma2-compressor})
|
(is (= test-data ((comp #(thaw % {:compressor nippy/lzma2-compressor})
|
||||||
#(freeze % {:compressor nippy/lzma2-compressor}))
|
#(freeze % {:compressor nippy/lzma2-compressor}))
|
||||||
test-data)))
|
test-data)))
|
||||||
|
|
@ -103,6 +99,15 @@
|
||||||
(is (= nil (meta (nippy/thaw (nippy/freeze (with-meta [] { 'b/c (fn [])})))))
|
(is (= nil (meta (nippy/thaw (nippy/freeze (with-meta [] { 'b/c (fn [])})))))
|
||||||
"Don't attach empty metadata")])
|
"Don't attach empty metadata")])
|
||||||
|
|
||||||
|
(let [d (nippy/stress-data {})]
|
||||||
|
[(is (= (vec (:bytes d)) ((comp vec thaw freeze) (:bytes d))))
|
||||||
|
(is (= (vec (:objects d)) ((comp vec thaw freeze) (:objects d))))])
|
||||||
|
|
||||||
|
(testing "Arrays"
|
||||||
|
(binding [nippy/*thaw-serializable-allowlist* nippy/default-freeze-serializable-allowlist]
|
||||||
|
(mapv (fn [[k aval]] (is (= (vec aval) (-> aval nippy/freeze nippy/thaw vec)) (name k)))
|
||||||
|
(get-in (nippy/stress-data {}) [:non-comparable :arrays]))))
|
||||||
|
|
||||||
(is (gen-test 1600 [gen-data] (= gen-data (thaw (freeze gen-data)))) "Generative")])
|
(is (gen-test 1600 [gen-data] (= gen-data (thaw (freeze gen-data)))) "Generative")])
|
||||||
|
|
||||||
;;;; Custom types & records
|
;;;; Custom types & records
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue