Add version comparison stuff to utils. Now test tagged-literals when Clojure version is sufficient.
This commit is contained in:
parent
d566ef1231
commit
1bcab7ede2
2 changed files with 52 additions and 38 deletions
|
|
@ -255,48 +255,50 @@
|
||||||
|
|
||||||
(def stress-data
|
(def stress-data
|
||||||
"Reference data used for tests & benchmarks."
|
"Reference data used for tests & benchmarks."
|
||||||
{;; Breaks reader, roundtrip equality
|
(let [support-tagged-literals?
|
||||||
:bytes (byte-array [(byte 1) (byte 2) (byte 3)])
|
(utils/version-sufficient? (clojure-version) "1.4.0")]
|
||||||
|
|
||||||
:nil nil
|
{;; Breaks reader, roundtrip equality
|
||||||
:boolean true
|
:bytes (byte-array [(byte 1) (byte 2) (byte 3)])
|
||||||
|
|
||||||
:char-utf8 \ಬ
|
:nil nil
|
||||||
:string-utf8 "ಬಾ ಇಲ್ಲಿ ಸಂಭವಿಸ"
|
:boolean true
|
||||||
:string-long (apply str (range 1000))
|
|
||||||
:keyword :keyword
|
|
||||||
:keyword-ns ::keyword
|
|
||||||
|
|
||||||
:list (list 1 2 3 4 5 (list 6 7 8 (list 9 10)))
|
:char-utf8 \ಬ
|
||||||
:list-quoted '(1 2 3 4 5 (6 7 8 (9 10)))
|
:string-utf8 "ಬಾ ಇಲ್ಲಿ ಸಂಭವಿಸ"
|
||||||
:list-empty (list)
|
:string-long (apply str (range 1000))
|
||||||
:vector [1 2 3 4 5 [6 7 8 [9 10]]]
|
:keyword :keyword
|
||||||
:vector-empty []
|
:keyword-ns ::keyword
|
||||||
:map {:a 1 :b 2 :c 3 :d {:e 4 :f {:g 5 :h 6 :i 7}}}
|
|
||||||
:map-empty {}
|
|
||||||
:set #{1 2 3 4 5 #{6 7 8 #{9 10}}}
|
|
||||||
:set-empty #{}
|
|
||||||
:meta (with-meta {:a :A} {:metakey :metaval})
|
|
||||||
|
|
||||||
;; Breaks reader
|
:list (list 1 2 3 4 5 (list 6 7 8 (list 9 10)))
|
||||||
:queue (-> (PersistentQueue/EMPTY) (conj :a :b :c :d :e :f :g))
|
:list-quoted '(1 2 3 4 5 (6 7 8 (9 10)))
|
||||||
:queue-empty (PersistentQueue/EMPTY)
|
:list-empty (list)
|
||||||
|
:vector [1 2 3 4 5 [6 7 8 [9 10]]]
|
||||||
|
:vector-empty []
|
||||||
|
:map {:a 1 :b 2 :c 3 :d {:e 4 :f {:g 5 :h 6 :i 7}}}
|
||||||
|
:map-empty {}
|
||||||
|
:set #{1 2 3 4 5 #{6 7 8 #{9 10}}}
|
||||||
|
:set-empty #{}
|
||||||
|
:meta (with-meta {:a :A} {:metakey :metaval})
|
||||||
|
|
||||||
:coll (repeatedly 1000 rand)
|
;; Breaks reader
|
||||||
|
:queue (-> (PersistentQueue/EMPTY) (conj :a :b :c :d :e :f :g))
|
||||||
|
:queue-empty (PersistentQueue/EMPTY)
|
||||||
|
|
||||||
:byte (byte 16)
|
:coll (repeatedly 1000 rand)
|
||||||
:short (short 42)
|
|
||||||
:integer (int 3)
|
|
||||||
:long (long 3)
|
|
||||||
:bigint (bigint 31415926535897932384626433832795)
|
|
||||||
|
|
||||||
:float (float 3.14)
|
:byte (byte 16)
|
||||||
:double (double 3.14)
|
:short (short 42)
|
||||||
:bigdec (bigdec 3.1415926535897932384626433832795)
|
:integer (int 3)
|
||||||
|
:long (long 3)
|
||||||
|
:bigint (bigint 31415926535897932384626433832795)
|
||||||
|
|
||||||
:ratio 22/7
|
:float (float 3.14)
|
||||||
|
:double (double 3.14)
|
||||||
|
:bigdec (bigdec 3.1415926535897932384626433832795)
|
||||||
|
|
||||||
;; Clojure 1.4+
|
:ratio 22/7
|
||||||
;; :tagged-uuid (java.util.UUID/randomUUID)
|
|
||||||
;; :tagged-date (java.util.Date.)
|
;; Clojure 1.4+
|
||||||
})
|
:tagged-uuid (when support-tagged-literals? (java.util.UUID/randomUUID))
|
||||||
|
:tagged-date (when support-tagged-literals? (java.util.Date.))}))
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
(ns taoensso.nippy.utils
|
(ns taoensso.nippy.utils
|
||||||
{:author "Peter Taoussanis"})
|
{:author "Peter Taoussanis"}
|
||||||
|
(:require [clojure.string :as str]))
|
||||||
|
|
||||||
(defmacro case-eval
|
(defmacro case-eval
|
||||||
"Like `case` but evaluates test constants for their compile-time value."
|
"Like `case` but evaluates test constants for their compile-time value."
|
||||||
|
|
@ -36,3 +37,14 @@
|
||||||
dorun))))]
|
dorun))))]
|
||||||
(if ~as-ms? (Math/round (/ nanosecs# 1000000.0)) nanosecs#))
|
(if ~as-ms? (Math/round (/ nanosecs# 1000000.0)) nanosecs#))
|
||||||
(catch Exception e# (str "DNF: " (.getMessage e#)))))
|
(catch Exception e# (str "DNF: " (.getMessage e#)))))
|
||||||
|
|
||||||
|
(defn version-compare
|
||||||
|
"Comparator for version strings like x.y.z, etc."
|
||||||
|
[x y]
|
||||||
|
(let [vals (fn [s] (vec (map #(Integer/parseInt %) (str/split s #"\."))))]
|
||||||
|
(compare (vals x) (vals y))))
|
||||||
|
|
||||||
|
(defn version-sufficient?
|
||||||
|
[version-str min-version-str]
|
||||||
|
(try (>= (version-compare version-str min-version-str) 0)
|
||||||
|
(catch Exception _ false)))
|
||||||
Loading…
Reference in a new issue