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,6 +255,9 @@
|
||||||
|
|
||||||
(def stress-data
|
(def stress-data
|
||||||
"Reference data used for tests & benchmarks."
|
"Reference data used for tests & benchmarks."
|
||||||
|
(let [support-tagged-literals?
|
||||||
|
(utils/version-sufficient? (clojure-version) "1.4.0")]
|
||||||
|
|
||||||
{;; Breaks reader, roundtrip equality
|
{;; Breaks reader, roundtrip equality
|
||||||
:bytes (byte-array [(byte 1) (byte 2) (byte 3)])
|
:bytes (byte-array [(byte 1) (byte 2) (byte 3)])
|
||||||
|
|
||||||
|
|
@ -297,6 +300,5 @@
|
||||||
:ratio 22/7
|
:ratio 22/7
|
||||||
|
|
||||||
;; Clojure 1.4+
|
;; Clojure 1.4+
|
||||||
;; :tagged-uuid (java.util.UUID/randomUUID)
|
:tagged-uuid (when support-tagged-literals? (java.util.UUID/randomUUID))
|
||||||
;; :tagged-date (java.util.Date.)
|
: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