diff --git a/src/taoensso/nippy.clj b/src/taoensso/nippy.clj index a14e473..65d0701 100644 --- a/src/taoensso/nippy.clj +++ b/src/taoensso/nippy.clj @@ -255,48 +255,50 @@ (def stress-data "Reference data used for tests & benchmarks." - {;; Breaks reader, roundtrip equality - :bytes (byte-array [(byte 1) (byte 2) (byte 3)]) + (let [support-tagged-literals? + (utils/version-sufficient? (clojure-version) "1.4.0")] - :nil nil - :boolean true + {;; Breaks reader, roundtrip equality + :bytes (byte-array [(byte 1) (byte 2) (byte 3)]) - :char-utf8 \ಬ - :string-utf8 "ಬಾ ಇಲ್ಲಿ ಸಂಭವಿಸ" - :string-long (apply str (range 1000)) - :keyword :keyword - :keyword-ns ::keyword + :nil nil + :boolean true - :list (list 1 2 3 4 5 (list 6 7 8 (list 9 10))) - :list-quoted '(1 2 3 4 5 (6 7 8 (9 10))) - :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}) + :char-utf8 \ಬ + :string-utf8 "ಬಾ ಇಲ್ಲಿ ಸಂಭವಿಸ" + :string-long (apply str (range 1000)) + :keyword :keyword + :keyword-ns ::keyword - ;; Breaks reader - :queue (-> (PersistentQueue/EMPTY) (conj :a :b :c :d :e :f :g)) - :queue-empty (PersistentQueue/EMPTY) + :list (list 1 2 3 4 5 (list 6 7 8 (list 9 10))) + :list-quoted '(1 2 3 4 5 (6 7 8 (9 10))) + :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) - :short (short 42) - :integer (int 3) - :long (long 3) - :bigint (bigint 31415926535897932384626433832795) + :coll (repeatedly 1000 rand) - :float (float 3.14) - :double (double 3.14) - :bigdec (bigdec 3.1415926535897932384626433832795) + :byte (byte 16) + :short (short 42) + :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+ - ;; :tagged-uuid (java.util.UUID/randomUUID) - ;; :tagged-date (java.util.Date.) - }) \ No newline at end of file + :ratio 22/7 + + ;; Clojure 1.4+ + :tagged-uuid (when support-tagged-literals? (java.util.UUID/randomUUID)) + :tagged-date (when support-tagged-literals? (java.util.Date.))})) \ No newline at end of file diff --git a/src/taoensso/nippy/utils.clj b/src/taoensso/nippy/utils.clj index fce02b6..b70941e 100644 --- a/src/taoensso/nippy/utils.clj +++ b/src/taoensso/nippy/utils.clj @@ -1,5 +1,6 @@ (ns taoensso.nippy.utils - {:author "Peter Taoussanis"}) + {:author "Peter Taoussanis"} + (:require [clojure.string :as str])) (defmacro case-eval "Like `case` but evaluates test constants for their compile-time value." @@ -35,4 +36,15 @@ (map deref) dorun))))] (if ~as-ms? (Math/round (/ nanosecs# 1000000.0)) nanosecs#)) - (catch Exception e# (str "DNF: " (.getMessage e#))))) \ No newline at end of file + (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))) \ No newline at end of file